Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-23 04:01:30 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-23 04:22:22 +0300
commit64b4b719ebd5201d27aa25d7fa2d765eabded9b0 (patch)
treec6e1147f3b81b90193d3acaa0df3f8c5c93db328
parentac53291e1ff79144ca41d63b0787bfe04da21677 (diff)
Cleanup: style, use braces for imbuf
-rw-r--r--source/blender/imbuf/intern/allocimbuf.c3
-rw-r--r--source/blender/imbuf/intern/anim_movie.c66
-rw-r--r--source/blender/imbuf/intern/bmp.c18
-rw-r--r--source/blender/imbuf/intern/cache.c42
-rw-r--r--source/blender/imbuf/intern/cineon/cineon_dpx.c24
-rw-r--r--source/blender/imbuf/intern/cineon/cineonlib.c66
-rw-r--r--source/blender/imbuf/intern/cineon/dpxlib.c102
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.c348
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.h42
-rw-r--r--source/blender/imbuf/intern/cineon/logmemfile.c27
-rw-r--r--source/blender/imbuf/intern/colormanagement.c222
-rw-r--r--source/blender/imbuf/intern/dds/BlockDXT.cpp3
-rw-r--r--source/blender/imbuf/intern/dds/ColorBlock.cpp18
-rw-r--r--source/blender/imbuf/intern/dds/DirectDrawSurface.cpp171
-rw-r--r--source/blender/imbuf/intern/dds/FlipDXT.cpp9
-rw-r--r--source/blender/imbuf/intern/dds/Image.cpp3
-rw-r--r--source/blender/imbuf/intern/dds/Image.h4
-rw-r--r--source/blender/imbuf/intern/dds/PixelFormat.h2
-rw-r--r--source/blender/imbuf/intern/dds/dds_api.cpp30
-rw-r--r--source/blender/imbuf/intern/divers.c99
-rw-r--r--source/blender/imbuf/intern/filetype.c12
-rw-r--r--source/blender/imbuf/intern/filter.c93
-rw-r--r--source/blender/imbuf/intern/imageprocess.c36
-rw-r--r--source/blender/imbuf/intern/indexer.c6
-rw-r--r--source/blender/imbuf/intern/iris.c54
-rw-r--r--source/blender/imbuf/intern/jp2.c24
-rw-r--r--source/blender/imbuf/intern/jpeg.c24
-rw-r--r--source/blender/imbuf/intern/moviecache.c54
-rw-r--r--source/blender/imbuf/intern/oiio/openimageio_api.cpp35
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp160
-rw-r--r--source/blender/imbuf/intern/png.c54
-rw-r--r--source/blender/imbuf/intern/radiance_hdr.c45
-rw-r--r--source/blender/imbuf/intern/readimage.c57
-rw-r--r--source/blender/imbuf/intern/rectop.c123
-rw-r--r--source/blender/imbuf/intern/rotate.c6
-rw-r--r--source/blender/imbuf/intern/scaling.c180
-rw-r--r--source/blender/imbuf/intern/stereoimbuf.c24
-rw-r--r--source/blender/imbuf/intern/targa.c162
-rw-r--r--source/blender/imbuf/intern/thumbs.c9
-rw-r--r--source/blender/imbuf/intern/tiff.c123
-rw-r--r--source/blender/imbuf/intern/util.c60
-rw-r--r--source/blender/imbuf/intern/writeimage.c3
42 files changed, 1760 insertions, 883 deletions
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index ae8ddce0338..76304b33a6f 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -597,8 +597,9 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1)
tbuf.encodedbuffer = ibuf2->encodedbuffer;
tbuf.zbuf = ibuf2->zbuf;
tbuf.zbuf_float = ibuf2->zbuf_float;
- for (a = 0; a < IMB_MIPMAP_LEVELS; a++)
+ for (a = 0; a < IMB_MIPMAP_LEVELS; a++) {
tbuf.mipmap[a] = NULL;
+ }
tbuf.dds_data.data = NULL;
/* set malloc flag */
diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index aa1d63394ff..4ef4e15d1c9 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -124,8 +124,9 @@ static int an_stringdec(const char *string, char *head, char *tail, unsigned sho
nume = len;
for (i = len - 1; i >= 0; i--) {
- if (string[i] == PATHSEPARATOR)
+ if (string[i] == PATHSEPARATOR) {
break;
+ }
if (isdigit(string[i])) {
if (found) {
nums = i;
@@ -137,8 +138,9 @@ static int an_stringdec(const char *string, char *head, char *tail, unsigned sho
}
}
else {
- if (found)
+ if (found) {
break;
+ }
}
}
if (found) {
@@ -167,10 +169,12 @@ static void free_anim_avi(struct anim *anim)
int i;
# endif
- if (anim == NULL)
+ if (anim == NULL) {
return;
- if (anim->avi == NULL)
+ }
+ if (anim->avi == NULL) {
return;
+ }
AVI_close(anim->avi);
MEM_freeN(anim->avi);
@@ -227,16 +231,18 @@ void IMB_free_anim(struct anim *anim)
void IMB_close_anim(struct anim *anim)
{
- if (anim == NULL)
+ if (anim == NULL) {
return;
+ }
IMB_free_anim(anim);
}
void IMB_close_anim_proxies(struct anim *anim)
{
- if (anim == NULL)
+ if (anim == NULL) {
return;
+ }
IMB_free_indices(anim);
}
@@ -253,8 +259,9 @@ struct IDProperty *IMB_anim_load_metadata(struct anim *anim)
while (true) {
entry = av_dict_get(anim->pFormatCtx->metadata, "", entry, AV_DICT_IGNORE_SUFFIX);
- if (entry == NULL)
+ if (entry == NULL) {
break;
+ }
/* Delay creation of the property group until there is actual metadata to put in there. */
IMB_metadata_ensure(&anim->metadata);
@@ -503,8 +510,9 @@ static int startffmpeg(struct anim *anim)
const int *inv_table;
# endif
- if (anim == NULL)
+ if (anim == NULL) {
return (-1);
+ }
streamcount = anim->streamindex;
@@ -971,14 +979,16 @@ static int match_format(const char *name, AVFormatContext *pFormatCtx)
const char *names = pFormatCtx->iformat->name;
- if (!name || !names)
+ if (!name || !names) {
return 0;
+ }
namelen = strlen(name);
while ((p = strchr(names, ','))) {
len = MAX2(p - names, namelen);
- if (!BLI_strncasecmp(name, names, len))
+ if (!BLI_strncasecmp(name, names, len)) {
return 1;
+ }
names = p + 1;
}
return !BLI_strcasecmp(name, names);
@@ -1015,8 +1025,9 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ
int new_frame_index = 0; /* To quiet gcc barking... */
int old_frame_index = 0; /* To quiet gcc barking... */
- if (anim == NULL)
+ if (anim == NULL) {
return (0);
+ }
av_log(anim->pFormatCtx, AV_LOG_DEBUG, "FETCH: pos=%d\n", position);
@@ -1178,8 +1189,9 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ
static void free_anim_ffmpeg(struct anim *anim)
{
- if (anim == NULL)
+ if (anim == NULL) {
return;
+ }
if (anim->pCodecCtx) {
avcodec_close(anim->pCodecCtx);
@@ -1222,8 +1234,9 @@ static ImBuf *anim_getnew(struct anim *anim)
{
struct ImBuf *ibuf = NULL;
- if (anim == NULL)
+ if (anim == NULL) {
return (NULL);
+ }
free_anim_movie(anim);
@@ -1235,8 +1248,9 @@ static ImBuf *anim_getnew(struct anim *anim)
free_anim_ffmpeg(anim);
#endif
- if (anim->curtype != 0)
+ if (anim->curtype != 0) {
return (NULL);
+ }
anim->curtype = imb_get_anim_type(anim->name);
switch (anim->curtype) {
@@ -1248,8 +1262,9 @@ static ImBuf *anim_getnew(struct anim *anim)
}
break;
case ANIM_MOVIE:
- if (startmovie(anim))
+ if (startmovie(anim)) {
return (NULL);
+ }
ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); /* fake */
break;
#ifdef WITH_AVI
@@ -1263,8 +1278,9 @@ static ImBuf *anim_getnew(struct anim *anim)
#endif
#ifdef WITH_FFMPEG
case ANIM_FFMPEG:
- if (startffmpeg(anim))
+ if (startffmpeg(anim)) {
return (0);
+ }
ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0);
break;
#endif
@@ -1296,8 +1312,9 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim,
unsigned short digits;
int pic;
int filter_y;
- if (anim == NULL)
+ if (anim == NULL) {
return (NULL);
+ }
filter_y = (anim->ib_flags & IB_animdeinterlace);
@@ -1312,10 +1329,12 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim,
ibuf = NULL;
}
- if (position < 0)
+ if (position < 0) {
return (NULL);
- if (position >= anim->duration)
+ }
+ if (position >= anim->duration) {
return (NULL);
+ }
}
else {
struct anim *proxy = IMB_anim_open_proxy(anim, preview_size);
@@ -1347,23 +1366,26 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim,
#ifdef WITH_AVI
case ANIM_AVI:
ibuf = avi_fetchibuf(anim, position);
- if (ibuf)
+ if (ibuf) {
anim->curposition = position;
+ }
break;
#endif
#ifdef WITH_FFMPEG
case ANIM_FFMPEG:
ibuf = ffmpeg_fetchibuf(anim, position, tc);
- if (ibuf)
+ if (ibuf) {
anim->curposition = position;
+ }
filter_y = 0; /* done internally */
break;
#endif
}
if (ibuf) {
- if (filter_y)
+ if (filter_y) {
IMB_filtery(ibuf);
+ }
BLI_snprintf(ibuf->name, sizeof(ibuf->name), "%s.%04d", anim->name, anim->curposition + 1);
}
return (ibuf);
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index b43b13ff282..ae3ac624e3b 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -125,8 +125,9 @@ struct ImBuf *imb_bmp_decode(const unsigned char *mem,
(void)size; /* unused */
- if (checkbmp(mem) == 0)
+ if (checkbmp(mem) == 0) {
return (NULL);
+ }
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -310,8 +311,9 @@ int imb_savebmp(struct ImBuf *ibuf, const char *name, int flags)
data = (uchar *)ibuf->rect;
ofile = BLI_fopen(name, "wb");
- if (!ofile)
+ if (!ofile) {
return 0;
+ }
putShortLSB(19778, ofile); /* "BM" */
putIntLSB(bytesize + BMP_FILEHEADER_SIZE + sizeof(infoheader), ofile); /* Total file size */
@@ -335,17 +337,21 @@ int imb_savebmp(struct ImBuf *ibuf, const char *name, int flags)
for (size_t y = 0; y < ibuf->y; y++) {
for (size_t x = 0; x < ibuf->x; x++) {
ptr = (x + y * ibuf->x) * 4;
- if (putc(data[ptr + 2], ofile) == EOF)
+ if (putc(data[ptr + 2], ofile) == EOF) {
return 0;
- if (putc(data[ptr + 1], ofile) == EOF)
+ }
+ if (putc(data[ptr + 1], ofile) == EOF) {
return 0;
- if (putc(data[ptr], ofile) == EOF)
+ }
+ if (putc(data[ptr], ofile) == EOF) {
return 0;
+ }
}
/* add padding here */
for (size_t t = 0; t < extrabytes; t++) {
- if (putc(0, ofile) == EOF)
+ if (putc(0, ofile) == EOF) {
return 0;
+ }
}
}
if (ofile) {
diff --git a/source/blender/imbuf/intern/cache.c b/source/blender/imbuf/intern/cache.c
index e6244364ba8..01c588daedd 100644
--- a/source/blender/imbuf/intern/cache.c
+++ b/source/blender/imbuf/intern/cache.c
@@ -155,8 +155,9 @@ void imb_tile_cache_tile_free(ImBuf *ibuf, int tx, int ty)
if (gtile) {
/* in case another thread is loading this */
- while (gtile->loading)
+ while (gtile->loading) {
;
+ }
BLI_ghash_remove(GLOBAL_CACHE.tilehash, gtile, NULL, NULL);
BLI_remlink(&GLOBAL_CACHE.tiles, gtile);
@@ -209,17 +210,21 @@ void imb_tile_cache_exit(void)
int a;
if (GLOBAL_CACHE.initialized) {
- for (gtile = GLOBAL_CACHE.tiles.first; gtile; gtile = gtile->next)
+ for (gtile = GLOBAL_CACHE.tiles.first; gtile; gtile = gtile->next) {
imb_global_cache_tile_unload(gtile);
+ }
- for (a = 0; a < GLOBAL_CACHE.totthread; a++)
+ for (a = 0; a < GLOBAL_CACHE.totthread; a++) {
imb_thread_cache_exit(&GLOBAL_CACHE.thread_cache[a]);
+ }
- if (GLOBAL_CACHE.memarena)
+ if (GLOBAL_CACHE.memarena) {
BLI_memarena_free(GLOBAL_CACHE.memarena);
+ }
- if (GLOBAL_CACHE.tilehash)
+ if (GLOBAL_CACHE.tilehash) {
BLI_ghash_free(GLOBAL_CACHE.tilehash, NULL, NULL);
+ }
BLI_mutex_end(&GLOBAL_CACHE.mutex);
@@ -236,8 +241,9 @@ void IMB_tile_cache_params(int totthread, int maxmem)
totthread++;
/* lazy initialize cache */
- if (GLOBAL_CACHE.totthread == totthread && GLOBAL_CACHE.maxmem == maxmem)
+ if (GLOBAL_CACHE.totthread == totthread && GLOBAL_CACHE.maxmem == maxmem) {
return;
+ }
imb_tile_cache_exit();
@@ -252,8 +258,9 @@ void IMB_tile_cache_params(int totthread, int maxmem)
GLOBAL_CACHE.maxmem = maxmem * 1024 * 1024;
GLOBAL_CACHE.totthread = totthread;
- for (a = 0; a < totthread; a++)
+ for (a = 0; a < totthread; a++) {
imb_thread_cache_init(&GLOBAL_CACHE.thread_cache[a]);
+ }
BLI_mutex_init(&GLOBAL_CACHE.mutex);
}
@@ -269,8 +276,9 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf,
BLI_mutex_lock(&GLOBAL_CACHE.mutex);
- if (replacetile)
+ if (replacetile) {
replacetile->refcount--;
+ }
/* find tile in global cache */
lookuptile.ibuf = ibuf;
@@ -286,8 +294,9 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf,
BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
- while (gtile->loading)
+ while (gtile->loading) {
;
+ }
}
else {
/* not found, let's load it from disk */
@@ -295,9 +304,11 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf,
/* first check if we hit the memory limit */
if (GLOBAL_CACHE.maxmem && GLOBAL_CACHE.totmem > GLOBAL_CACHE.maxmem) {
/* find an existing tile to unload */
- for (gtile = GLOBAL_CACHE.tiles.last; gtile; gtile = gtile->prev)
- if (gtile->refcount == 0 && gtile->loading == 0)
+ for (gtile = GLOBAL_CACHE.tiles.last; gtile; gtile = gtile->prev) {
+ if (gtile->refcount == 0 && gtile->loading == 0) {
break;
+ }
+ }
}
if (gtile) {
@@ -312,8 +323,9 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf,
gtile = GLOBAL_CACHE.unused.first;
BLI_remlink(&GLOBAL_CACHE.unused, gtile);
}
- else
+ else {
gtile = BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImGlobalTile));
+ }
}
/* setup new tile */
@@ -355,8 +367,9 @@ static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache,
/* test if it is already in our thread local cache */
if ((ttile = cache->tiles.first)) {
/* check last used tile before going to hash */
- if (ttile->ibuf == ibuf && ttile->tx == tx && ttile->ty == ty)
+ if (ttile->ibuf == ibuf && ttile->tx == tx && ttile->ty == ty) {
return ibuf->tiles[toffs];
+ }
/* find tile in hash */
lookuptile.ibuf = ibuf;
@@ -419,8 +432,9 @@ void IMB_tiles_to_rect(ImBuf *ibuf)
mipbuf->mall |= IB_rect;
mipbuf->flags |= IB_rect;
}
- else
+ else {
break;
+ }
}
for (ty = 0; ty < mipbuf->ytiles; ty++) {
diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c
index 8f3829ee91e..77c04fd3358 100644
--- a/source/blender/imbuf/intern/cineon/cineon_dpx.c
+++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c
@@ -77,8 +77,9 @@ static struct ImBuf *imb_load_dpx_cineon(const unsigned char *mem,
logImageClose(image);
ibuf->ftype = use_cineon ? IMB_FTYPE_CINEON : IMB_FTYPE_DPX;
- if (flags & IB_alphamode_detect)
+ if (flags & IB_alphamode_detect) {
ibuf->flags |= IB_alphamode_premul;
+ }
return ibuf;
}
@@ -104,14 +105,18 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon
return 0;
}
- if (ibuf->foptions.flag & CINEON_10BIT)
+ if (ibuf->foptions.flag & CINEON_10BIT) {
bitspersample = 10;
- else if (ibuf->foptions.flag & CINEON_12BIT)
+ }
+ else if (ibuf->foptions.flag & CINEON_12BIT) {
bitspersample = 12;
- else if (ibuf->foptions.flag & CINEON_16BIT)
+ }
+ else if (ibuf->foptions.flag & CINEON_16BIT) {
bitspersample = 16;
- else
+ }
+ else {
bitspersample = 8;
+ }
logImage = logImageCreate(filename,
use_cineon,
@@ -149,8 +154,9 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon
MEM_freeN(fbuf);
}
else {
- if (ibuf->rect == NULL)
+ if (ibuf->rect == NULL) {
IMB_rect_from_float(ibuf);
+ }
fbuf = (float *)MEM_mallocN(ibuf->x * ibuf->y * 4 * sizeof(float),
"fbuf in imb_save_dpx_cineon");
@@ -192,8 +198,9 @@ ImBuf *imb_load_cineon(const unsigned char *mem,
int flags,
char colorspace[IM_MAX_SPACE])
{
- if (imb_is_cineon(mem))
+ if (imb_is_cineon(mem)) {
return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
+ }
return NULL;
}
@@ -212,7 +219,8 @@ ImBuf *imb_load_dpx(const unsigned char *mem,
int flags,
char colorspace[IM_MAX_SPACE])
{
- if (imb_is_dpx(mem))
+ if (imb_is_dpx(mem)) {
return imb_load_dpx_cineon(mem, size, 0, flags, colorspace);
+ }
return NULL;
}
diff --git a/source/blender/imbuf/intern/cineon/cineonlib.c b/source/blender/imbuf/intern/cineon/cineonlib.c
index 79f419e747c..63014919dfb 100644
--- a/source/blender/imbuf/intern/cineon/cineonlib.c
+++ b/source/blender/imbuf/intern/cineon/cineonlib.c
@@ -146,8 +146,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
unsigned int dataOffset;
if (cineon == NULL) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Failed to malloc cineon file structure.\n");
+ }
return NULL;
}
@@ -161,8 +162,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
/* byteStuff is then the filename */
cineon->file = BLI_fopen(filename, "rb");
if (cineon->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Failed to open file \"%s\".\n", filename);
+ }
logImageClose(cineon);
return NULL;
}
@@ -178,8 +180,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
}
if (logimage_fread(&header, sizeof(header), 1, cineon) == 0) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Not enough data for header in \"%s\".\n", byteStuff);
+ }
logImageClose(cineon);
return NULL;
}
@@ -187,13 +190,15 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
/* endianness determination */
if (header.fileHeader.magic_num == swap_uint(CINEON_FILE_MAGIC, 1)) {
cineon->isMSB = 1;
- if (verbose)
+ if (verbose) {
printf("Cineon: File is MSB.\n");
+ }
}
else if (header.fileHeader.magic_num == CINEON_FILE_MAGIC) {
cineon->isMSB = 0;
- if (verbose)
+ if (verbose) {
printf("Cineon: File is LSB.\n");
+ }
}
else {
if (verbose) {
@@ -209,8 +214,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
cineon->height = swap_uint(header.imageHeader.element[0].lines_per_image, cineon->isMSB);
if (cineon->width == 0 || cineon->height == 0) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Wrong image dimension: %dx%d\n", cineon->width, cineon->height);
+ }
logImageClose(cineon);
return NULL;
}
@@ -218,13 +224,16 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
cineon->depth = header.imageHeader.elements_per_image;
cineon->srcFormat = format_Cineon;
- if (header.imageHeader.interleave == 0)
+ if (header.imageHeader.interleave == 0) {
cineon->numElements = 1;
- else if (header.imageHeader.interleave == 2)
+ }
+ else if (header.imageHeader.interleave == 2) {
cineon->numElements = header.imageHeader.elements_per_image;
+ }
else {
- if (verbose)
+ if (verbose) {
printf("Cineon: Data interleave not supported: %d\n", header.imageHeader.interleave);
+ }
logImageClose(cineon);
return NULL;
}
@@ -255,8 +264,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
}
}
else {
- if (verbose)
+ if (verbose) {
printf("Cineon: Cineon image depth unsupported: %d\n", cineon->depth);
+ }
logImageClose(cineon);
return NULL;
}
@@ -290,28 +300,34 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
default:
/* Not supported */
- if (verbose)
+ if (verbose) {
printf("Cineon: packing unsupported: %d\n", header.imageHeader.packing);
+ }
logImageClose(cineon);
return NULL;
}
- if (cineon->element[i].refLowData == CINEON_UNDEFINED_U32)
+ if (cineon->element[i].refLowData == CINEON_UNDEFINED_U32) {
cineon->element[i].refLowData = 0;
+ }
- if (cineon->element[i].refHighData == CINEON_UNDEFINED_U32)
+ if (cineon->element[i].refHighData == CINEON_UNDEFINED_U32) {
cineon->element[i].refHighData = (unsigned int)cineon->element[i].maxValue;
+ }
if (cineon->element[i].refLowQuantity == CINEON_UNDEFINED_R32 ||
- isnan(cineon->element[i].refLowQuantity))
+ isnan(cineon->element[i].refLowQuantity)) {
cineon->element[i].refLowQuantity = 0.0f;
+ }
if (cineon->element[i].refHighQuantity == CINEON_UNDEFINED_R32 ||
isnan(cineon->element[i].refHighQuantity)) {
- if (cineon->element[i].transfer == transfer_PrintingDensity)
+ if (cineon->element[i].transfer == transfer_PrintingDensity) {
cineon->element[i].refHighQuantity = 2.048f;
- else
+ }
+ else {
cineon->element[i].refHighQuantity = cineon->element[i].maxValue;
+ }
}
cineon->element[i].dataOffset = dataOffset;
@@ -357,15 +373,17 @@ LogImageFile *cineonCreate(
LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
if (cineon == NULL) {
- if (verbose)
+ if (verbose) {
printf("cineon: Failed to malloc cineon file structure.\n");
+ }
return NULL;
}
/* Only 10 bits Cineon are supported */
if (bitsPerSample != 10) {
- if (verbose)
+ if (verbose) {
printf("cineon: Only 10 bits Cineon are supported.\n");
+ }
logImageClose(cineon);
return NULL;
}
@@ -391,15 +409,18 @@ LogImageFile *cineonCreate(
cineon->gamma = 1.7f;
shortFilename = strrchr(filename, '/');
- if (shortFilename == NULL)
+ if (shortFilename == NULL) {
shortFilename = filename;
- else
+ }
+ else {
shortFilename++;
+ }
cineon->file = BLI_fopen(filename, "wb");
if (cineon->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("cineon: Couldn't open file %s\n", filename);
+ }
logImageClose(cineon);
return NULL;
}
@@ -407,8 +428,9 @@ LogImageFile *cineonCreate(
fillCineonMainHeader(cineon, &header, shortFilename, creator);
if (fwrite(&header, sizeof(header), 1, cineon->file) == 0) {
- if (verbose)
+ if (verbose) {
printf("cineon: Couldn't write image header\n");
+ }
logImageClose(cineon);
return NULL;
}
diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c
index 8c0cd88f256..00d59643967 100644
--- a/source/blender/imbuf/intern/cineon/dpxlib.c
+++ b/source/blender/imbuf/intern/cineon/dpxlib.c
@@ -143,8 +143,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
int i;
if (dpx == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Failed to malloc dpx file structure.\n");
+ }
return NULL;
}
@@ -158,8 +159,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
/* byteStuff is then the filename */
dpx->file = BLI_fopen(filename, "rb");
if (dpx->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Failed to open file \"%s\".\n", filename);
+ }
logImageClose(dpx);
return NULL;
}
@@ -175,8 +177,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
}
if (logimage_fread(&header, sizeof(header), 1, dpx) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Not enough data for header in \"%s\".\n", byteStuff);
+ }
logImageClose(dpx);
return NULL;
}
@@ -184,13 +187,15 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
/* endianness determination */
if (header.fileHeader.magic_num == swap_uint(DPX_FILE_MAGIC, 1)) {
dpx->isMSB = 1;
- if (verbose)
+ if (verbose) {
printf("DPX: File is MSB.\n");
+ }
}
else if (header.fileHeader.magic_num == DPX_FILE_MAGIC) {
dpx->isMSB = 0;
- if (verbose)
+ if (verbose) {
printf("DPX: File is LSB.\n");
+ }
}
else {
if (verbose) {
@@ -204,8 +209,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
dpx->numElements = swap_ushort(header.imageHeader.elements_per_image, dpx->isMSB);
size_t max_elements = sizeof(header.imageHeader.element) / sizeof(header.imageHeader.element[0]);
if (dpx->numElements == 0 || dpx->numElements >= max_elements) {
- if (verbose)
+ if (verbose) {
printf("DPX: Wrong number of elements: %d\n", dpx->numElements);
+ }
logImageClose(dpx);
return NULL;
}
@@ -214,8 +220,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
dpx->height = swap_uint(header.imageHeader.lines_per_element, dpx->isMSB);
if (dpx->width == 0 || dpx->height == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Wrong image dimension: %dx%d\n", dpx->width, dpx->height);
+ }
logImageClose(dpx);
return NULL;
}
@@ -262,8 +269,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
}
if (dpx->depth == 0 || dpx->depth > 4) {
- if (verbose)
+ if (verbose) {
printf("DPX: Unsupported image depth: %d\n", dpx->depth);
+ }
logImageClose(dpx);
return NULL;
}
@@ -272,10 +280,11 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
if (dpx->element[i].bitsPerSample != 1 && dpx->element[i].bitsPerSample != 8 &&
dpx->element[i].bitsPerSample != 10 && dpx->element[i].bitsPerSample != 12 &&
dpx->element[i].bitsPerSample != 16) {
- if (verbose)
+ if (verbose) {
printf("DPX: Unsupported bitsPerSample for elements %d: %d\n",
i,
dpx->element[i].bitsPerSample);
+ }
logImageClose(dpx);
return NULL;
}
@@ -284,20 +293,23 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
dpx->element[i].packing = swap_ushort(header.imageHeader.element[i].packing, dpx->isMSB);
if (dpx->element[i].packing > 2) {
- if (verbose)
+ if (verbose) {
printf("DPX: Unsupported packing for element %d: %d\n", i, dpx->element[i].packing);
+ }
logImageClose(dpx);
return NULL;
}
/* Sometimes, the offset is not set correctly in the header */
dpx->element[i].dataOffset = swap_uint(header.imageHeader.element[i].data_offset, dpx->isMSB);
- if (dpx->element[i].dataOffset == 0 && dpx->numElements == 1)
+ if (dpx->element[i].dataOffset == 0 && dpx->numElements == 1) {
dpx->element[i].dataOffset = swap_uint(header.fileHeader.offset, dpx->isMSB);
+ }
if (dpx->element[i].dataOffset == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Image header is corrupted.\n");
+ }
logImageClose(dpx);
return NULL;
}
@@ -321,23 +333,28 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
case descriptor_RGB:
case descriptor_RGBA:
case descriptor_ABGR:
- if (dpx->element[i].refLowData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refLowData == DPX_UNDEFINED_U32) {
dpx->element[i].refLowData = 0;
+ }
- if (dpx->element[i].refHighData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refHighData == DPX_UNDEFINED_U32) {
dpx->element[i].refHighData = (unsigned int)dpx->element[i].maxValue;
+ }
if (dpx->element[i].refLowQuantity == DPX_UNDEFINED_R32 ||
- isnan(dpx->element[i].refLowQuantity))
+ isnan(dpx->element[i].refLowQuantity)) {
dpx->element[i].refLowQuantity = 0.0f;
+ }
if (dpx->element[i].refHighQuantity == DPX_UNDEFINED_R32 ||
isnan(dpx->element[i].refHighQuantity)) {
if (dpx->element[i].transfer == transfer_PrintingDensity ||
- dpx->element[i].transfer == transfer_Logarithmic)
+ dpx->element[i].transfer == transfer_Logarithmic) {
dpx->element[i].refHighQuantity = 2.048f;
- else
+ }
+ else {
dpx->element[i].refHighQuantity = dpx->element[i].maxValue;
+ }
}
break;
@@ -348,19 +365,23 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
case descriptor_CbYCr:
case descriptor_CbYACrYA:
case descriptor_CbYCrA:
- if (dpx->element[i].refLowData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refLowData == DPX_UNDEFINED_U32) {
dpx->element[i].refLowData = 16.0f / 255.0f * dpx->element[i].maxValue;
+ }
- if (dpx->element[i].refHighData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refHighData == DPX_UNDEFINED_U32) {
dpx->element[i].refHighData = 235.0f / 255.0f * dpx->element[i].maxValue;
+ }
if (dpx->element[i].refLowQuantity == DPX_UNDEFINED_R32 ||
- isnan(dpx->element[i].refLowQuantity))
+ isnan(dpx->element[i].refLowQuantity)) {
dpx->element[i].refLowQuantity = 0.0f;
+ }
if (dpx->element[i].refHighQuantity == DPX_UNDEFINED_R32 ||
- isnan(dpx->element[i].refHighQuantity))
+ isnan(dpx->element[i].refHighQuantity)) {
dpx->element[i].refHighQuantity = 0.7f;
+ }
break;
@@ -425,8 +446,9 @@ LogImageFile *dpxCreate(const char *filename,
LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
if (dpx == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Failed to malloc dpx file structure.\n");
+ }
return NULL;
}
@@ -451,8 +473,9 @@ LogImageFile *dpxCreate(const char *filename,
break;
default:
- if (verbose)
+ if (verbose) {
printf("DPX: bitsPerSample not supported: %d\n", bitsPerSample);
+ }
logImageClose(dpx);
return NULL;
}
@@ -481,32 +504,41 @@ LogImageFile *dpxCreate(const char *filename,
dpx->element[0].refLowData = 0;
dpx->element[0].refHighData = dpx->element[0].maxValue;
- if (referenceWhite > 0)
+ if (referenceWhite > 0) {
dpx->referenceWhite = referenceWhite;
- else
+ }
+ else {
dpx->referenceWhite = 685.0f / 1023.0f * dpx->element[0].maxValue;
+ }
- if (referenceBlack > 0)
+ if (referenceBlack > 0) {
dpx->referenceBlack = referenceBlack;
- else
+ }
+ else {
dpx->referenceBlack = 95.0f / 1023.0f * dpx->element[0].maxValue;
+ }
- if (gamma > 0.0f)
+ if (gamma > 0.0f) {
dpx->gamma = gamma;
- else
+ }
+ else {
dpx->gamma = 1.7f;
+ }
shortFilename = strrchr(filename, '/');
- if (shortFilename == NULL)
+ if (shortFilename == NULL) {
shortFilename = filename;
- else
+ }
+ else {
shortFilename++;
+ }
dpx->file = BLI_fopen(filename, "wb");
if (dpx->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Couldn't open file %s\n", filename);
+ }
logImageClose(dpx);
return NULL;
}
@@ -514,8 +546,9 @@ LogImageFile *dpxCreate(const char *filename,
fillDpxMainHeader(dpx, &header, shortFilename, creator);
if (fwrite(&header, sizeof(header), 1, dpx->file) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Couldn't write image header\n");
+ }
logImageClose(dpx);
return NULL;
}
@@ -524,8 +557,9 @@ LogImageFile *dpxCreate(const char *filename,
* 6044 = 8092 - sizeof(DpxMainHeader) */
memset(&pad, 0, 6044);
if (fwrite(&pad, 6044, 1, dpx->file) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Couldn't write image header\n");
+ }
logImageClose(dpx);
return NULL;
}
diff --git a/source/blender/imbuf/intern/cineon/logImageCore.c b/source/blender/imbuf/intern/cineon/logImageCore.c
index 2169665cf78..5d1623374d4 100644
--- a/source/blender/imbuf/intern/cineon/logImageCore.c
+++ b/source/blender/imbuf/intern/cineon/logImageCore.c
@@ -105,8 +105,9 @@ LogImageFile *logImageOpenFromFile(const char *filename, int cineon)
(void)cineon;
- if (f == NULL)
+ if (f == NULL) {
return NULL;
+ }
if (fread(&magicNum, sizeof(unsigned int), 1, f) != 1) {
fclose(f);
@@ -115,20 +116,24 @@ LogImageFile *logImageOpenFromFile(const char *filename, int cineon)
fclose(f);
- if (logImageIsDpx(&magicNum))
+ if (logImageIsDpx(&magicNum)) {
return dpxOpen((const unsigned char *)filename, 0, 0);
- else if (logImageIsCineon(&magicNum))
+ }
+ else if (logImageIsCineon(&magicNum)) {
return cineonOpen((const unsigned char *)filename, 0, 0);
+ }
return NULL;
}
LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int size)
{
- if (logImageIsDpx(buffer))
+ if (logImageIsDpx(buffer)) {
return dpxOpen(buffer, 1, size);
- else if (logImageIsCineon(buffer))
+ }
+ else if (logImageIsCineon(buffer)) {
return cineonOpen(buffer, 1, size);
+ }
return NULL;
}
@@ -146,9 +151,10 @@ LogImageFile *logImageCreate(const char *filename,
const char *creator)
{
/* referenceWhite, referenceBlack and gamma values are only supported for DPX file */
- if (cineon)
+ if (cineon) {
return cineonCreate(filename, width, height, bitsPerSample, creator);
- else
+ }
+ else {
return dpxCreate(filename,
width,
height,
@@ -159,6 +165,7 @@ LogImageFile *logImageCreate(const char *filename,
referenceBlack,
gamma,
creator);
+ }
return NULL;
}
@@ -196,16 +203,20 @@ size_t getRowLength(size_t width, LogImageElement logElement)
return ((width * logElement.depth - 1) / 4 + 1) * 4;
case 10:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return ((width * logElement.depth * 10 - 1) / 32 + 1) * 4;
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return ((width * logElement.depth - 1) / 3 + 1) * 4;
+ }
break;
case 12:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return ((width * logElement.depth * 12 - 1) / 32 + 1) * 4;
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return width * logElement.depth * 2;
+ }
break;
case 16:
return width * logElement.depth * 2;
@@ -224,8 +235,9 @@ int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
elementData = (float *)imb_alloc_pixels(
logImage->width, logImage->height, logImage->depth, sizeof(float), __func__);
- if (elementData == NULL)
+ if (elementData == NULL) {
return 1;
+ }
if (convertRGBAToLogElement(
data, elementData, logImage, logImage->element[0], dataIsLinearRGB) != 0) {
@@ -266,19 +278,22 @@ static int logImageSetData8(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned char *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
memset(row, 0, rowLength);
for (size_t y = 0; y < logImage->height; y++) {
- for (size_t x = 0; x < logImage->width * logImage->depth; x++)
+ for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
row[x] = (unsigned char)float_uint(data[y * logImage->width * logImage->depth + x], 255);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Error while writing file.\n");
+ }
MEM_freeN(row);
return 1;
}
@@ -295,8 +310,9 @@ static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned int *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
@@ -316,8 +332,9 @@ static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement,
offset = 22;
}
}
- if (pixel != 0)
+ if (pixel != 0) {
row[index] = swap_uint(pixel, logImage->isMSB);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
if (verbose) {
@@ -338,20 +355,23 @@ static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned short *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
for (size_t y = 0; y < logImage->height; y++) {
- for (size_t x = 0; x < logImage->width * logImage->depth; x++)
+ for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
row[x] = swap_ushort(
((unsigned short)float_uint(data[y * logImage->width * logImage->depth + x], 4095)) << 4,
logImage->isMSB);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Error while writing file.\n");
+ }
MEM_freeN(row);
return 1;
}
@@ -367,20 +387,23 @@ static int logImageSetData16(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned short *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
for (size_t y = 0; y < logImage->height; y++) {
- for (size_t x = 0; x < logImage->width * logImage->depth; x++)
+ for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
row[x] = swap_ushort(
(unsigned short)float_uint(data[y * logImage->width * logImage->depth + x], 65535),
logImage->isMSB);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Error while writing file.\n");
+ }
MEM_freeN(row);
return 1;
}
@@ -416,28 +439,35 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
elementData[i] = imb_alloc_pixels(
logImage->width, logImage->height, logImage->element[i].depth, sizeof(float), __func__);
if (elementData[i] == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate memory for elementData[%d]\n.", i);
- for (j = 0; j < i; j++)
- if (elementData[j] != NULL)
+ }
+ for (j = 0; j < i; j++) {
+ if (elementData[j] != NULL) {
MEM_freeN(elementData[j]);
+ }
+ }
return 1;
}
elementData_ptr[i] = elementData[i];
/* Load data */
if (logImageElementGetData(logImage, logImage->element[i], elementData[i]) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot read elementData[%d]\n.", i);
- for (j = 0; j < i; j++)
- if (elementData[j] != NULL)
+ }
+ for (j = 0; j < i; j++) {
+ if (elementData[j] != NULL) {
MEM_freeN(elementData[j]);
+ }
+ }
return 1;
}
}
- if (logImage->element[i].descriptor == descriptor_Alpha)
+ if (logImage->element[i].descriptor == descriptor_Alpha) {
hasAlpha = 1;
+ }
}
/* only one element, easy case, no need to do anything */
@@ -461,28 +491,34 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
switch (logImage->element[i].descriptor) {
case descriptor_Red:
case descriptor_RGB:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_RGB;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_RGBA;
+ }
sortedElementData[0] = i;
break;
case descriptor_Green:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_RGB;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_RGBA;
+ }
sortedElementData[1] = i;
break;
case descriptor_Blue:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_RGB;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_RGBA;
+ }
sortedElementData[2] = i;
break;
@@ -493,57 +529,77 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
break;
case descriptor_Luminance:
- if (mergedElement.descriptor == -1)
- if (hasAlpha == 0)
+ if (mergedElement.descriptor == -1) {
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_Luminance;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_YA;
+ }
+ }
else if (mergedElement.descriptor == descriptor_Chrominance) {
- if (mergedElement.depth == 2)
+ if (mergedElement.depth == 2) {
mergedElement.descriptor = descriptor_CbYCrY;
- else if (mergedElement.depth == 3)
- if (hasAlpha == 0)
+ }
+ else if (mergedElement.depth == 3) {
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_CbYCr;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_CbYACrYA;
- else if (mergedElement.depth == 4)
+ }
+ }
+ else if (mergedElement.depth == 4) {
mergedElement.descriptor = descriptor_CbYCrA;
+ }
}
/* Y component always in 1 except if it's alone or with alpha */
- if (mergedElement.depth == 1 || (mergedElement.depth == 2 && hasAlpha == 1))
+ if (mergedElement.depth == 1 || (mergedElement.depth == 2 && hasAlpha == 1)) {
sortedElementData[0] = i;
- else
+ }
+ else {
sortedElementData[1] = i;
+ }
break;
case descriptor_Chrominance:
- if (mergedElement.descriptor == -1)
+ if (mergedElement.descriptor == -1) {
mergedElement.descriptor = descriptor_Chrominance;
+ }
else if (mergedElement.descriptor == descriptor_Luminance) {
- if (mergedElement.depth == 2)
+ if (mergedElement.depth == 2) {
mergedElement.descriptor = descriptor_CbYCrY;
- else if (mergedElement.depth == 3)
- if (hasAlpha == 0)
+ }
+ else if (mergedElement.depth == 3) {
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_CbYCr;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_CbYACrYA;
- else if (mergedElement.depth == 4)
+ }
+ }
+ else if (mergedElement.depth == 4) {
mergedElement.descriptor = descriptor_CbYCrA;
+ }
}
/* Cb and Cr always in 0 or 2 */
- if (sortedElementData[0] == -1)
+ if (sortedElementData[0] == -1) {
sortedElementData[0] = i;
- else
+ }
+ else {
sortedElementData[2] = i;
+ }
break;
case descriptor_CbYCr:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_CbYCr;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_CbYCrA;
+ }
sortedElementData[0] = i;
break;
@@ -568,25 +624,32 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
mergedData = (float *)imb_alloc_pixels(
logImage->width, logImage->height, mergedElement.depth, sizeof(float), __func__);
if (mergedData == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate mergedData.\n");
- for (i = 0; i < logImage->numElements; i++)
- if (elementData[i] != NULL)
+ }
+ for (i = 0; i < logImage->numElements; i++) {
+ if (elementData[i] != NULL) {
MEM_freeN(elementData[i]);
+ }
+ }
return 1;
}
sampleIndex = 0;
while (sampleIndex < logImage->width * logImage->height * mergedElement.depth) {
- for (i = 0; i < logImage->numElements; i++)
- for (j = 0; j < logImage->element[sortedElementData[i]].depth; j++)
+ for (i = 0; i < logImage->numElements; i++) {
+ for (j = 0; j < logImage->element[sortedElementData[i]].depth; j++) {
mergedData[sampleIndex++] = *(elementData_ptr[sortedElementData[i]]++);
+ }
+ }
}
/* Done with elements data, clean-up */
- for (i = 0; i < logImage->numElements; i++)
- if (elementData[i] != NULL)
+ for (i = 0; i < logImage->numElements; i++) {
+ if (elementData[i] != NULL) {
MEM_freeN(elementData[i]);
+ }
+ }
returnValue = convertLogElementToRGBA(
mergedData, data, logImage, mergedElement, dataIsLinearRGB);
@@ -605,17 +668,21 @@ static int logImageElementGetData(LogImageFile *logImage, LogImageElement logEle
return logImageElementGetData8(logImage, logElement, data);
case 10:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return logImageElementGetData10Packed(logImage, logElement, data);
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return logImageElementGetData10(logImage, logElement, data);
+ }
break;
case 12:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return logImageElementGetData12Packed(logImage, logElement, data);
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return logImageElementGetData12(logImage, logElement, data);
+ }
break;
case 16:
@@ -631,8 +698,9 @@ static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logEl
/* seek at the right place */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
@@ -640,14 +708,16 @@ static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logEl
for (size_t y = 0; y < logImage->height; y++) {
for (size_t x = 0; x < logImage->width * logElement.depth; x += 32) {
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
- for (int offset = 0; offset < 32 && x + offset < logImage->width; offset++)
+ for (int offset = 0; offset < 32 && x + offset < logImage->width; offset++) {
data[y * logImage->width * logElement.depth + x + offset] = (float)((pixel >> offset) &
0x01);
+ }
}
}
return 0;
@@ -662,15 +732,17 @@ static int logImageElementGetData8(LogImageFile *logImage, LogImageElement logEl
for (size_t y = 0; y < logImage->height; y++) {
/* 8 bits are 32-bits padded so we need to seek at each row */
if (logimage_fseek(logImage, logElement.dataOffset + y * rowLength, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", (int)(logElement.dataOffset + y * rowLength));
+ }
return 1;
}
for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
if (logimage_read_uchar(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
data[y * logImage->width * logElement.depth + x] = (float)pixel / 255.0f;
@@ -687,8 +759,9 @@ static int logImageElementGetData10(LogImageFile *logImage,
/* seek to data */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
@@ -698,14 +771,17 @@ static int logImageElementGetData10(LogImageFile *logImage,
for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
/* we need to read the next long */
if (offset >= 30) {
- if (logElement.packing == 1)
+ if (logElement.packing == 1) {
offset = 2;
- else if (logElement.packing == 2)
+ }
+ else if (logElement.packing == 2) {
offset = 0;
+ }
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -722,14 +798,17 @@ static int logImageElementGetData10(LogImageFile *logImage,
for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
/* we need to read the next long */
if (offset < 0) {
- if (logElement.packing == 1)
+ if (logElement.packing == 1) {
offset = 22;
- else if (logElement.packing == 2)
+ }
+ else if (logElement.packing == 2) {
offset = 20;
+ }
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -755,9 +834,10 @@ static int logImageElementGetData10Packed(LogImageFile *logImage,
for (size_t y = 0; y < logImage->height; y++) {
/* seek to data */
if (logimage_fseek(logImage, y * rowLength + logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %u\n",
(unsigned int)(y * rowLength + logElement.dataOffset));
+ }
return 1;
}
@@ -784,8 +864,9 @@ static int logImageElementGetData10Packed(LogImageFile *logImage,
if (offset == 0) {
/* we need to read the next long */
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -808,8 +889,9 @@ static int logImageElementGetData12(LogImageFile *logImage,
/* seek to data */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
@@ -818,16 +900,19 @@ static int logImageElementGetData12(LogImageFile *logImage,
for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
if (logimage_read_ushort(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_ushort(pixel, logImage->isMSB);
- if (logElement.packing == 1) /* padded to the right */
+ if (logElement.packing == 1) { /* padded to the right */
data[sampleIndex] = (float)(pixel >> 4) / 4095.0f;
- else if (logElement.packing == 2) /* padded to the left */
+ }
+ else if (logElement.packing == 2) { /* padded to the left */
data[sampleIndex] = (float)pixel / 4095.0f;
+ }
}
return 0;
}
@@ -843,9 +928,10 @@ static int logImageElementGetData12Packed(LogImageFile *logImage,
for (size_t y = 0; y < logImage->height; y++) {
/* seek to data */
if (logimage_fseek(logImage, y * rowLength + logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %u\n",
(unsigned int)(y * rowLength + logElement.dataOffset));
+ }
return 1;
}
@@ -872,8 +958,9 @@ static int logImageElementGetData12Packed(LogImageFile *logImage,
if (offset == 0) {
/* we need to read the next long */
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -896,15 +983,17 @@ static int logImageElementGetData16(LogImageFile *logImage,
/* seek to data */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
if (logimage_read_ushort(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_ushort(pixel, logImage->isMSB);
@@ -999,11 +1088,12 @@ static float *getLinToLogLut(LogImageFile *logImage, LogImageElement logElement)
negativeFilmGamma * logImage->gamma / 1.7f));
offset = gain - logElement.maxValue;
- for (i = 0; i < lutsize; i++)
+ for (i = 0; i < lutsize; i++) {
lut[i] = (logImage->referenceWhite +
log10f(powf((i + offset) / gain, 1.7f / logImage->gamma)) /
(step / negativeFilmGamma)) /
logElement.maxValue;
+ }
return lut;
}
@@ -1040,18 +1130,21 @@ static float *getLogToLinLut(LogImageFile *logImage, LogImageElement logElement)
kneeGain = (logElement.maxValue - kneeOffset) / powf(5 * softClip, softClip / 100);
for (i = 0; i < lutsize; i++) {
- if (i < logImage->referenceBlack)
+ if (i < logImage->referenceBlack) {
lut[i] = 0.0f;
- else if (i > breakPoint)
+ }
+ else if (i > breakPoint) {
lut[i] = (powf(i - breakPoint, softClip / 100) * kneeGain + kneeOffset) /
logElement.maxValue;
- else
+ }
+ else {
lut[i] = (powf(10,
((float)i - logImage->referenceWhite) * step / negativeFilmGamma *
logImage->gamma / 1.7f) *
gain -
offset) /
logElement.maxValue;
+ }
}
return lut;
@@ -1067,10 +1160,12 @@ static float *getLinToSrgbLut(LogImageElement logElement)
for (i = 0; i < lutsize; i++) {
col = (float)i / logElement.maxValue;
- if (col < 0.0031308f)
+ if (col < 0.0031308f) {
lut[i] = (col < 0.0f) ? 0.0f : col * 12.92f;
- else
+ }
+ else {
lut[i] = 1.055f * powf(col, 1.0f / 2.4f) - 0.055f;
+ }
}
return lut;
@@ -1086,10 +1181,12 @@ static float *getSrgbToLinLut(LogImageElement logElement)
for (i = 0; i < lutsize; i++) {
col = (float)i / logElement.maxValue;
- if (col < 0.04045f)
+ if (col < 0.04045f) {
lut[i] = (col < 0.0f) ? 0.0f : col * (1.0f / 12.92f);
- else
+ }
+ else {
lut[i] = powf((col + 0.055f) * (1.0f / 1.055f), 2.4f);
+ }
}
return lut;
@@ -1123,10 +1220,12 @@ static int convertRGBA_RGB(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
*(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1141,8 +1240,9 @@ static int convertRGBA_RGB(float *src,
}
default:
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
+ }
return 1;
}
}
@@ -1175,10 +1275,12 @@ static int convertRGB_RGBA(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
*(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1193,8 +1295,9 @@ static int convertRGB_RGBA(float *src,
}
default:
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
+ }
return 1;
}
}
@@ -1220,10 +1323,12 @@ static int convertRGBA_RGBA(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
*(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1270,10 +1375,12 @@ static int convertABGR_RGBA(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
src_ptr += 4;
@@ -1304,8 +1411,9 @@ static int convertCbYCr_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1335,8 +1443,9 @@ static int convertCbYCrA_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1367,8 +1476,9 @@ static int convertCbYCrY_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1418,8 +1528,9 @@ static int convertCbYACrYA_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1471,8 +1582,9 @@ static int convertLuminance_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1496,8 +1608,9 @@ static int convertYA_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1561,8 +1674,9 @@ static int convertLogElementToRGBA(
return 1;
}
- if (rvalue == 1)
+ if (rvalue == 1) {
return 1;
+ }
else if (dstIsLinearRGB) {
/* convert data from sRGB to Linear RGB via lut */
float *lut = getSrgbToLinLut(logElement);
@@ -1594,8 +1708,9 @@ static int convertRGBAToLogElement(
/* we need to convert src to sRGB */
srgbSrc = (float *)imb_alloc_pixels(
logImage->width, logImage->height, 4, sizeof(float), __func__);
- if (srgbSrc == NULL)
+ if (srgbSrc == NULL) {
return 1;
+ }
memcpy(srgbSrc, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
srgbSrc_ptr = srgbSrc;
@@ -1611,8 +1726,9 @@ static int convertRGBAToLogElement(
}
MEM_freeN(lut);
}
- else
+ else {
srgbSrc = src;
+ }
/* Convert linear RGBA data in src to format described by logElement in dst */
switch (logElement.descriptor) {
diff --git a/source/blender/imbuf/intern/cineon/logImageCore.h b/source/blender/imbuf/intern/cineon/logImageCore.h
index 3f09effa839..80e32ffe77e 100644
--- a/source/blender/imbuf/intern/cineon/logImageCore.h
+++ b/source/blender/imbuf/intern/cineon/logImageCore.h
@@ -213,18 +213,22 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
{
- if (swap != 0)
+ if (swap != 0) {
return (x >> 8) | (x << 8);
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
{
- if (swap != 0)
+ if (swap != 0) {
return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE float swap_float(float x, int swap)
@@ -242,40 +246,50 @@ BLI_INLINE float swap_float(float x, int swap)
dat2.b[3] = dat1.b[0];
return dat2.f;
}
- else
+ else {
return x;
+ }
}
/* Other */
BLI_INLINE unsigned int clamp_uint(unsigned int x, unsigned int low, unsigned int high)
{
- if (x > high)
+ if (x > high) {
return high;
- else if (x < low)
+ }
+ else if (x < low) {
return low;
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE float clamp_float(float x, float low, float high)
{
- if (x > high)
+ if (x > high) {
return high;
- else if (x < low)
+ }
+ else if (x < low) {
return low;
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE unsigned int float_uint(float value, unsigned int max)
{
- if (value < 0.0f)
+ if (value < 0.0f) {
return 0;
- else if (value > (1.0f - 0.5f / (float)max))
+ }
+ else if (value > (1.0f - 0.5f / (float)max)) {
return max;
- else
+ }
+ else {
return (unsigned int)(((float)max * value) + 0.5f);
+ }
}
#ifdef __cplusplus
diff --git a/source/blender/imbuf/intern/cineon/logmemfile.c b/source/blender/imbuf/intern/cineon/logmemfile.c
index d7ab2855ea3..91351d309de 100644
--- a/source/blender/imbuf/intern/cineon/logmemfile.c
+++ b/source/blender/imbuf/intern/cineon/logmemfile.c
@@ -31,23 +31,27 @@
int logimage_fseek(LogImageFile *logFile, intptr_t offset, int origin)
{
- if (logFile->file)
+ if (logFile->file) {
fseek(logFile->file, offset, origin);
+ }
else { /* we're seeking in memory */
if (origin == SEEK_SET) {
- if (offset > logFile->memBufferSize)
+ if (offset > logFile->memBufferSize) {
return 1;
+ }
logFile->memCursor = logFile->memBuffer + offset;
}
else if (origin == SEEK_END) {
- if (offset > logFile->memBufferSize)
+ if (offset > logFile->memBufferSize) {
return 1;
+ }
logFile->memCursor = (logFile->memBuffer + logFile->memBufferSize) - offset;
}
else if (origin == SEEK_CUR) {
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + offset > logFile->memBufferSize)
+ if (pos + offset > logFile->memBufferSize) {
return 1;
+ }
logFile->memCursor += offset;
}
@@ -57,8 +61,9 @@ int logimage_fseek(LogImageFile *logFile, intptr_t offset, int origin)
int logimage_fwrite(void *buffer, size_t size, unsigned int count, LogImageFile *logFile)
{
- if (logFile->file)
+ if (logFile->file) {
return fwrite(buffer, size, count, logFile->file);
+ }
else { /* we're writing to memory */
/* do nothing as this isn't supported yet */
return count;
@@ -81,8 +86,9 @@ int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile *
total_size = size * count;
}
- if (total_size != 0)
+ if (total_size != 0) {
memcpy(buf, logFile->memCursor, total_size);
+ }
return count;
}
@@ -91,8 +97,9 @@ int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile *
int logimage_read_uchar(unsigned char *x, LogImageFile *logFile)
{
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + sizeof(unsigned char) > logFile->memBufferSize)
+ if (pos + sizeof(unsigned char) > logFile->memBufferSize) {
return 1;
+ }
*x = *(unsigned char *)logFile->memCursor;
logFile->memCursor += sizeof(unsigned char);
@@ -102,8 +109,9 @@ int logimage_read_uchar(unsigned char *x, LogImageFile *logFile)
int logimage_read_ushort(unsigned short *x, LogImageFile *logFile)
{
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + sizeof(unsigned short) > logFile->memBufferSize)
+ if (pos + sizeof(unsigned short) > logFile->memBufferSize) {
return 1;
+ }
*x = *(unsigned short *)logFile->memCursor;
logFile->memCursor += sizeof(unsigned short);
@@ -113,8 +121,9 @@ int logimage_read_ushort(unsigned short *x, LogImageFile *logFile)
int logimage_read_uint(unsigned int *x, LogImageFile *logFile)
{
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + sizeof(unsigned int) > logFile->memBufferSize)
+ if (pos + sizeof(unsigned int) > logFile->memBufferSize) {
return 1;
+ }
*x = *(unsigned int *)logFile->memCursor;
logFile->memCursor += sizeof(unsigned int);
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index 46c08afe201..f31d4ede693 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -233,16 +233,18 @@ typedef struct ColormanageCache {
static struct MovieCache *colormanage_moviecache_get(const ImBuf *ibuf)
{
- if (!ibuf->colormanage_cache)
+ if (!ibuf->colormanage_cache) {
return NULL;
+ }
return ibuf->colormanage_cache->moviecache;
}
static ColormanageCacheData *colormanage_cachedata_get(const ImBuf *ibuf)
{
- if (!ibuf->colormanage_cache)
+ if (!ibuf->colormanage_cache) {
return NULL;
+ }
return ibuf->colormanage_cache->data;
}
@@ -266,8 +268,9 @@ static bool colormanage_hashcmp(const void *av, const void *bv)
static struct MovieCache *colormanage_moviecache_ensure(ImBuf *ibuf)
{
- if (!ibuf->colormanage_cache)
+ if (!ibuf->colormanage_cache) {
ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage cache");
+ }
if (!ibuf->colormanage_cache->moviecache) {
struct MovieCache *moviecache;
@@ -285,8 +288,9 @@ static struct MovieCache *colormanage_moviecache_ensure(ImBuf *ibuf)
static void colormanage_cachedata_set(ImBuf *ibuf, ColormanageCacheData *data)
{
- if (!ibuf->colormanage_cache)
+ if (!ibuf->colormanage_cache) {
ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage cache");
+ }
ibuf->colormanage_cache->data = data;
}
@@ -461,8 +465,9 @@ static void colormanage_role_color_space_name_get(OCIO_ConstConfigRcPtr *config,
ociocs = OCIO_configGetColorSpace(config, role);
- if (!ociocs && backup_role)
+ if (!ociocs && backup_role) {
ociocs = OCIO_configGetColorSpace(config, backup_role);
+ }
if (ociocs) {
const char *name = OCIO_colorSpaceGetName(ociocs);
@@ -585,11 +590,13 @@ static void colormanage_free_config(void)
ColorSpace *colorspace_next = colorspace->next;
/* free precomputer processors */
- if (colorspace->to_scene_linear)
+ if (colorspace->to_scene_linear) {
OCIO_processorRelease((OCIO_ConstProcessorRcPtr *)colorspace->to_scene_linear);
+ }
- if (colorspace->from_scene_linear)
+ if (colorspace->from_scene_linear) {
OCIO_processorRelease((OCIO_ConstProcessorRcPtr *)colorspace->from_scene_linear);
+ }
/* free color space itself */
MEM_freeN(colorspace);
@@ -605,11 +612,13 @@ static void colormanage_free_config(void)
ColorManagedDisplay *display_next = display->next;
/* free precomputer processors */
- if (display->to_scene_linear)
+ if (display->to_scene_linear) {
OCIO_processorRelease((OCIO_ConstProcessorRcPtr *)display->to_scene_linear);
+ }
- if (display->from_scene_linear)
+ if (display->from_scene_linear) {
OCIO_processorRelease((OCIO_ConstProcessorRcPtr *)display->from_scene_linear);
+ }
/* free list of views */
BLI_freelistN(&display->views);
@@ -700,26 +709,33 @@ void colormanagement_init(void)
void colormanagement_exit(void)
{
- if (global_glsl_state.processor)
+ if (global_glsl_state.processor) {
OCIO_processorRelease(global_glsl_state.processor);
+ }
- if (global_glsl_state.curve_mapping)
+ if (global_glsl_state.curve_mapping) {
curvemapping_free(global_glsl_state.curve_mapping);
+ }
- if (global_glsl_state.curve_mapping_settings.lut)
+ if (global_glsl_state.curve_mapping_settings.lut) {
MEM_freeN(global_glsl_state.curve_mapping_settings.lut);
+ }
- if (global_glsl_state.ocio_glsl_state)
+ if (global_glsl_state.ocio_glsl_state) {
OCIO_freeOGLState(global_glsl_state.ocio_glsl_state);
+ }
- if (global_glsl_state.transform_ocio_glsl_state)
+ if (global_glsl_state.transform_ocio_glsl_state) {
OCIO_freeOGLState(global_glsl_state.transform_ocio_glsl_state);
+ }
- if (global_color_picking_state.processor_to)
+ if (global_color_picking_state.processor_to) {
OCIO_processorRelease(global_color_picking_state.processor_to);
+ }
- if (global_color_picking_state.processor_from)
+ if (global_color_picking_state.processor_from) {
OCIO_processorRelease(global_color_picking_state.processor_from);
+ }
memset(&global_glsl_state, 0, sizeof(global_glsl_state));
memset(&global_color_picking_state, 0, sizeof(global_color_picking_state));
@@ -767,8 +783,9 @@ void IMB_colormanagement_display_settings_from_ctx(
*display_settings_r = &scene->display_settings;
if (sima && sima->image) {
- if ((sima->image->flag & IMA_VIEW_AS_RENDER) == 0)
+ if ((sima->image->flag & IMA_VIEW_AS_RENDER) == 0) {
*view_settings_r = NULL;
+ }
}
}
@@ -796,8 +813,9 @@ static ColorSpace *display_transform_get_colorspace(
const char *colorspace_name = IMB_colormanagement_get_display_colorspace_name(view_settings,
display_settings);
- if (colorspace_name)
+ if (colorspace_name) {
return colormanage_colorspace_get_named(colorspace_name);
+ }
return NULL;
}
@@ -1038,8 +1056,9 @@ void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace)
if (ibuf->rect_float) {
const char *to_colorspace = global_role_scene_linear;
- if (ibuf->rect)
+ if (ibuf->rect) {
imb_freerectImBuf(ibuf);
+ }
IMB_colormanagement_transform(
ibuf->rect_float, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, to_colorspace, true);
@@ -1085,13 +1104,15 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
if (view_settings->view_transform[0] == '\0') {
display = colormanage_display_get_named(display_settings->display_device);
- if (display)
+ if (display) {
default_view = colormanage_view_get_default(display);
+ }
- if (default_view)
+ if (default_view) {
BLI_strncpy(view_settings->view_transform,
default_view->name,
sizeof(view_settings->view_transform));
+ }
}
else {
ColorManagedView *view = colormanage_view_get_named(view_settings->view_transform);
@@ -1099,8 +1120,9 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
if (!view) {
display = colormanage_display_get_named(display_settings->display_device);
- if (display)
+ if (display) {
default_view = colormanage_view_get_default(display);
+ }
if (default_view) {
printf("Color management: %s view \"%s\" not found, setting default \"%s\".\n",
@@ -1224,13 +1246,15 @@ void IMB_colormanagement_validate_settings(const ColorManagedDisplaySettings *di
for (view_link = display->views.first; view_link; view_link = view_link->next) {
ColorManagedView *view = view_link->data;
- if (STREQ(view->name, view_settings->view_transform))
+ if (STREQ(view->name, view_settings->view_transform)) {
break;
+ }
}
- if (view_link == NULL && default_view)
+ if (view_link == NULL && default_view) {
BLI_strncpy(
view_settings->view_transform, default_view->name, sizeof(view_settings->view_transform));
+ }
}
const char *IMB_colormanagement_role_colorspace_name_get(int role)
@@ -1261,10 +1285,12 @@ void IMB_colormanagement_check_is_data(ImBuf *ibuf, const char *name)
{
ColorSpace *colorspace = colormanage_colorspace_get_named(name);
- if (colorspace && colorspace->is_data)
+ if (colorspace && colorspace->is_data) {
ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
- else
+ }
+ else {
ibuf->colormanage_flag &= ~IMB_COLORMANAGE_IS_DATA;
+ }
}
void IMB_colormanagement_assign_float_colorspace(ImBuf *ibuf, const char *name)
@@ -1273,10 +1299,12 @@ void IMB_colormanagement_assign_float_colorspace(ImBuf *ibuf, const char *name)
ibuf->float_colorspace = colorspace;
- if (colorspace && colorspace->is_data)
+ if (colorspace && colorspace->is_data) {
ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
- else
+ }
+ else {
ibuf->colormanage_flag &= ~IMB_COLORMANAGE_IS_DATA;
+ }
}
void IMB_colormanagement_assign_rect_colorspace(ImBuf *ibuf, const char *name)
@@ -1285,10 +1313,12 @@ void IMB_colormanagement_assign_rect_colorspace(ImBuf *ibuf, const char *name)
ibuf->rect_colorspace = colorspace;
- if (colorspace && colorspace->is_data)
+ if (colorspace && colorspace->is_data) {
ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
- else
+ }
+ else {
ibuf->colormanage_flag &= ~IMB_COLORMANAGE_IS_DATA;
+ }
}
const char *IMB_colormanagement_get_float_colorspace(ImBuf *ibuf)
@@ -1369,17 +1399,21 @@ static void display_buffer_init_handle(void *handle_v,
handle->cm_processor = init_data->cm_processor;
- if (init_data->buffer)
+ if (init_data->buffer) {
handle->buffer = init_data->buffer + offset;
+ }
- if (init_data->byte_buffer)
+ if (init_data->byte_buffer) {
handle->byte_buffer = init_data->byte_buffer + offset;
+ }
- if (init_data->display_buffer)
+ if (init_data->display_buffer) {
handle->display_buffer = init_data->display_buffer + offset;
+ }
- if (init_data->display_buffer_byte)
+ if (init_data->display_buffer_byte) {
handle->display_buffer_byte = init_data->display_buffer_byte + display_buffer_byte_offset;
+ }
handle->width = ibuf->x;
@@ -1620,8 +1654,9 @@ static bool is_ibuf_rect_in_display_space(ImBuf *ibuf,
return false;
}
- if (to_colorspace && STREQ(from_colorspace, to_colorspace))
+ if (to_colorspace && STREQ(from_colorspace, to_colorspace)) {
return true;
+ }
}
return false;
@@ -1646,8 +1681,9 @@ static void colormanage_display_buffer_process_ex(
skip_transform = is_ibuf_rect_in_display_space(ibuf, view_settings, display_settings);
}
- if (skip_transform == false)
+ if (skip_transform == false) {
cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings);
+ }
display_buffer_apply_threaded(ibuf,
ibuf->rect_float,
@@ -1656,8 +1692,9 @@ static void colormanage_display_buffer_process_ex(
display_buffer_byte,
cm_processor);
- if (cm_processor)
+ if (cm_processor) {
IMB_colormanagement_processor_free(cm_processor);
+ }
}
static void colormanage_display_buffer_process(ImBuf *ibuf,
@@ -1988,8 +2025,9 @@ void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], ColorSpac
processor = colorspace_to_scene_linear_processor(colorspace);
- if (processor)
+ if (processor) {
OCIO_processorApplyRGB(processor, pixel);
+ }
}
/* same as above, but converts colors in opposite direction */
@@ -2005,8 +2043,9 @@ void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], ColorSpac
processor = colorspace_from_scene_linear_processor(colorspace);
- if (processor)
+ if (processor) {
OCIO_processorApplyRGB(processor, pixel);
+ }
}
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4],
@@ -2024,10 +2063,12 @@ void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4],
processor = colorspace_to_scene_linear_processor(colorspace);
if (processor) {
- if (predivide)
+ if (predivide) {
OCIO_processorApplyRGBA_predivide(processor, pixel);
- else
+ }
+ else {
OCIO_processorApplyRGBA(processor, pixel);
+ }
}
}
@@ -2059,10 +2100,12 @@ void IMB_colormanagement_colorspace_to_scene_linear(float *buffer,
(size_t)channels * sizeof(float),
(size_t)channels * sizeof(float) * width);
- if (predivide)
+ if (predivide) {
OCIO_processorApply_predivide(processor, img);
- else
+ }
+ else {
OCIO_processorApply(processor, img);
+ }
OCIO_PackedImageDescRelease(img);
}
@@ -2148,8 +2191,9 @@ void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], ColorManaged
processor = display_from_scene_linear_processor(display);
- if (processor)
+ if (processor) {
OCIO_processorApplyRGB(processor, pixel);
+ }
}
/* same as above, but converts color in opposite direction */
@@ -2159,8 +2203,9 @@ void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], ColorManaged
processor = display_to_scene_linear_processor(display);
- if (processor)
+ if (processor) {
OCIO_processorApplyRGB(processor, pixel);
+ }
}
void IMB_colormanagement_pixel_to_display_space_v4(
@@ -2199,8 +2244,9 @@ static void colormanagement_imbuf_make_display_space(
const ColorManagedDisplaySettings *display_settings,
bool make_byte)
{
- if (!ibuf->rect && make_byte)
+ if (!ibuf->rect && make_byte) {
imb_addrectImBuf(ibuf);
+ }
colormanage_display_buffer_process_ex(
ibuf, ibuf->rect_float, (unsigned char *)ibuf->rect, view_settings, display_settings);
@@ -2316,8 +2362,9 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf,
*/
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->save && type->ftype(type, colormanaged_ibuf)) {
- if ((type->flag & IM_FTYPE_FLOAT) == 0)
+ if ((type->flag & IM_FTYPE_FLOAT) == 0) {
make_byte = true;
+ }
break;
}
@@ -2400,8 +2447,9 @@ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf,
*cache_handle = NULL;
- if (!ibuf->x || !ibuf->y)
+ if (!ibuf->x || !ibuf->y) {
return NULL;
+ }
if (view_settings) {
applied_view_settings = view_settings;
@@ -2417,8 +2465,9 @@ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf,
* let's just use if
*/
if (ibuf->rect_float == NULL && ibuf->rect_colorspace && ibuf->channels == 4) {
- if (is_ibuf_rect_in_display_space(ibuf, applied_view_settings, display_settings))
+ if (is_ibuf_rect_in_display_space(ibuf, applied_view_settings, display_settings)) {
return (unsigned char *)ibuf->rect;
+ }
}
colormanage_view_settings_to_cache(ibuf, &cache_view_settings, applied_view_settings);
@@ -2558,8 +2607,9 @@ ColorManagedDisplay *colormanage_display_get_default(void)
{
const char *display_name = colormanage_display_get_default_name();
- if (display_name[0] == '\0')
+ if (display_name[0] == '\0') {
return NULL;
+ }
return colormanage_display_get_named(display_name);
}
@@ -2591,8 +2641,9 @@ ColorManagedDisplay *colormanage_display_get_named(const char *name)
ColorManagedDisplay *display;
for (display = global_displays.first; display; display = display->next) {
- if (STREQ(display->name, name))
+ if (STREQ(display->name, name)) {
return display;
+ }
}
return NULL;
@@ -2645,8 +2696,9 @@ ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name)
const char *IMB_colormanagement_display_get_none_name(void)
{
- if (colormanage_display_get_named("None") != NULL)
+ if (colormanage_display_get_named("None") != NULL) {
return "None";
+ }
return colormanage_display_get_default_name();
}
@@ -2675,8 +2727,9 @@ ColorManagedView *colormanage_view_get_default(const ColorManagedDisplay *displa
{
const char *name = colormanage_view_get_default_name(display);
- if (!name || name[0] == '\0')
+ if (!name || name[0] == '\0') {
return NULL;
+ }
return colormanage_view_get_named(name);
}
@@ -2702,8 +2755,9 @@ ColorManagedView *colormanage_view_get_named(const char *name)
ColorManagedView *view;
for (view = global_views.first; view; view = view->next) {
- if (STREQ(view->name, name))
+ if (STREQ(view->name, name)) {
return view;
+ }
}
return NULL;
@@ -2758,11 +2812,13 @@ const char *IMB_colormanagement_view_get_default_name(const char *display_name)
ColorManagedDisplay *display = colormanage_display_get_named(display_name);
ColorManagedView *view = NULL;
- if (display)
+ if (display) {
view = colormanage_view_get_default(display);
+ }
- if (view)
+ if (view) {
return view->name;
+ }
return NULL;
}
@@ -2811,16 +2867,19 @@ ColorSpace *colormanage_colorspace_add(const char *name,
colorspace->is_data = is_data;
for (prev_space = global_colorspaces.first; prev_space; prev_space = prev_space->next) {
- if (BLI_strcasecmp(prev_space->name, colorspace->name) > 0)
+ if (BLI_strcasecmp(prev_space->name, colorspace->name) > 0) {
break;
+ }
prev_space->index = counter++;
}
- if (!prev_space)
+ if (!prev_space) {
BLI_addtail(&global_colorspaces, colorspace);
- else
+ }
+ else {
BLI_insertlinkbefore(&global_colorspaces, prev_space, colorspace);
+ }
colorspace->index = counter++;
for (; prev_space; prev_space = prev_space->next) {
@@ -2837,8 +2896,9 @@ ColorSpace *colormanage_colorspace_get_named(const char *name)
ColorSpace *colorspace;
for (colorspace = global_colorspaces.first; colorspace; colorspace = colorspace->next) {
- if (STREQ(colorspace->name, name))
+ if (STREQ(colorspace->name, name)) {
return colorspace;
+ }
}
return NULL;
@@ -3070,8 +3130,9 @@ void IMB_colormanagement_colorspace_items_add(EnumPropertyItem **items, int *tot
for (colorspace = global_colorspaces.first; colorspace; colorspace = colorspace->next) {
EnumPropertyItem item;
- if (!colorspace->is_invertible)
+ if (!colorspace->is_invertible) {
continue;
+ }
item.value = colorspace->index;
item.name = colorspace->name;
@@ -3127,8 +3188,9 @@ static void partial_buffer_update_rect(ImBuf *ibuf,
* (this is only needed to apply dither, in other cases we'll convert
* byte buffer to display directly)
*/
- if (!cm_processor)
+ if (!cm_processor) {
channels = 4;
+ }
display_buffer_float = MEM_callocN((size_t)channels * width * height * sizeof(float),
"display buffer for dither");
@@ -3502,8 +3564,9 @@ ColormanageProcessor *IMB_colormanagement_display_processor_new(
}
display_space = display_transform_get_colorspace(applied_view_settings, display_settings);
- if (display_space)
+ if (display_space) {
cm_processor->is_data_result = display_space->is_data;
+ }
cm_processor->processor = create_display_buffer_processor(applied_view_settings->look,
applied_view_settings->view_transform,
@@ -3538,30 +3601,36 @@ ColormanageProcessor *IMB_colormanagement_colorspace_processor_new(const char *f
void IMB_colormanagement_processor_apply_v4(ColormanageProcessor *cm_processor, float pixel[4])
{
- if (cm_processor->curve_mapping)
+ if (cm_processor->curve_mapping) {
curvemapping_evaluate_premulRGBF(cm_processor->curve_mapping, pixel, pixel);
+ }
- if (cm_processor->processor)
+ if (cm_processor->processor) {
OCIO_processorApplyRGBA(cm_processor->processor, pixel);
+ }
}
void IMB_colormanagement_processor_apply_v4_predivide(ColormanageProcessor *cm_processor,
float pixel[4])
{
- if (cm_processor->curve_mapping)
+ if (cm_processor->curve_mapping) {
curvemapping_evaluate_premulRGBF(cm_processor->curve_mapping, pixel, pixel);
+ }
- if (cm_processor->processor)
+ if (cm_processor->processor) {
OCIO_processorApplyRGBA_predivide(cm_processor->processor, pixel);
+ }
}
void IMB_colormanagement_processor_apply_v3(ColormanageProcessor *cm_processor, float pixel[3])
{
- if (cm_processor->curve_mapping)
+ if (cm_processor->curve_mapping) {
curvemapping_evaluate_premulRGBF(cm_processor->curve_mapping, pixel, pixel);
+ }
- if (cm_processor->processor)
+ if (cm_processor->processor) {
OCIO_processorApplyRGB(cm_processor->processor, pixel);
+ }
}
void IMB_colormanagement_processor_apply_pixel(struct ColormanageProcessor *cm_processor,
@@ -3617,10 +3686,12 @@ void IMB_colormanagement_processor_apply(ColormanageProcessor *cm_processor,
(size_t)channels * sizeof(float),
(size_t)channels * sizeof(float) * width);
- if (predivide)
+ if (predivide) {
OCIO_processorApply_predivide(cm_processor->processor, img);
- else
+ }
+ else {
OCIO_processorApply(cm_processor->processor, img);
+ }
OCIO_PackedImageDescRelease(img);
}
@@ -3646,10 +3717,12 @@ void IMB_colormanagement_processor_apply_byte(
void IMB_colormanagement_processor_free(ColormanageProcessor *cm_processor)
{
- if (cm_processor->curve_mapping)
+ if (cm_processor->curve_mapping) {
curvemapping_free(cm_processor->curve_mapping);
- if (cm_processor->processor)
+ }
+ if (cm_processor->processor) {
OCIO_processorRelease(cm_processor->processor);
+ }
MEM_freeN(cm_processor);
}
@@ -3764,8 +3837,9 @@ static void update_glsl_display_processor(const ColorManagedViewSettings *view_s
}
/* Free old processor, if any. */
- if (global_glsl_state.processor)
+ if (global_glsl_state.processor) {
OCIO_processorRelease(global_glsl_state.processor);
+ }
/* We're using display OCIO processor, no RGB curves yet. */
global_glsl_state.processor = create_display_buffer_processor(global_glsl_state.look,
diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp
index f960faee1ab..b1ca6221753 100644
--- a/source/blender/imbuf/intern/dds/BlockDXT.cpp
+++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp
@@ -610,8 +610,9 @@ void mem_read(Stream &mem, BlockDXT1 &block)
void mem_read(Stream &mem, AlphaBlockDXT3 &block)
{
- for (unsigned int i = 0; i < 4; i++)
+ for (unsigned int i = 0; i < 4; i++) {
mem_read(mem, block.row[i]);
+ }
}
void mem_read(Stream &mem, BlockDXT3 &block)
diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp
index c392ef351ff..581d740c97c 100644
--- a/source/blender/imbuf/intern/dds/ColorBlock.cpp
+++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp
@@ -130,16 +130,21 @@ void ColorBlock::init(uint w, uint h, const float *data, uint x, uint y)
static inline uint8 component(Color32 c, uint i)
{
- if (i == 0)
+ if (i == 0) {
return c.r;
- if (i == 1)
+ }
+ if (i == 1) {
return c.g;
- if (i == 2)
+ }
+ if (i == 2) {
return c.b;
- if (i == 3)
+ }
+ if (i == 3) {
return c.a;
- if (i == 4)
+ }
+ if (i == 4) {
return 0xFF;
+ }
return 0;
}
@@ -238,8 +243,9 @@ Color32 ColorBlock::averageColor() const
bool ColorBlock::hasAlpha() const
{
for (uint i = 0; i < 16; i++) {
- if (m_color[i].a != 255)
+ if (m_color[i].a != 255) {
return true;
+ }
}
return false;
}
diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
index 89fe3bf5f25..abe8a0c1883 100644
--- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
+++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
@@ -479,8 +479,9 @@ void mem_read(Stream &mem, DDSHeader &header)
mem_read(mem, header.pitch);
mem_read(mem, header.depth);
mem_read(mem, header.mipmapcount);
- for (uint i = 0; i < 11; i++)
+ for (uint i = 0; i < 11; i++) {
mem_read(mem, header.reserved[i]);
+ }
mem_read(mem, header.pf);
mem_read(mem, header.caps);
mem_read(mem, header.notused);
@@ -550,8 +551,9 @@ DDSHeader::DDSHeader()
this->pitch = 0;
this->depth = 0;
this->mipmapcount = 0;
- for (uint i = 0; i < 11; i++)
+ for (uint i = 0; i < 11; i++) {
this->reserved[i] = 0;
+ }
// Store version information on the reserved header attributes.
this->reserved[9] = FOURCC_NVTT;
@@ -747,26 +749,32 @@ void DDSHeader::setDX10Format(uint format)
void DDSHeader::setNormalFlag(bool b)
{
- if (b)
+ if (b) {
this->pf.flags |= DDPF_NORMAL;
- else
+ }
+ else {
this->pf.flags &= ~DDPF_NORMAL;
+ }
}
void DDSHeader::setSrgbFlag(bool b)
{
- if (b)
+ if (b) {
this->pf.flags |= DDPF_SRGB;
- else
+ }
+ else {
this->pf.flags &= ~DDPF_SRGB;
+ }
}
void DDSHeader::setHasAlphaFlag(bool b)
{
- if (b)
+ if (b) {
this->pf.flags |= DDPF_ALPHAPIXELS;
- else
+ }
+ else {
this->pf.flags &= ~DDPF_ALPHAPIXELS;
+ }
}
void DDSHeader::setUserVersion(int version)
@@ -868,8 +876,9 @@ DirectDrawSurface::DirectDrawSurface(unsigned char *mem, uint size) : stream(mem
// some ATI2 compressed normal maps do not have their
// normal flag set, so force it here (the original nvtt don't do
// this, but the decompressor has a -forcenormal flag)
- if (header.pf.fourcc == FOURCC_ATI2)
+ if (header.pf.fourcc == FOURCC_ATI2) {
header.setNormalFlag(true);
+ }
}
DirectDrawSurface::~DirectDrawSurface()
@@ -975,10 +984,12 @@ bool DirectDrawSurface::hasAlpha() const
uint DirectDrawSurface::mipmapCount() const
{
- if (header.flags & DDSD_MIPMAPCOUNT)
+ if (header.flags & DDSD_MIPMAPCOUNT) {
return header.mipmapcount;
- else
+ }
+ else {
return 1;
+ }
}
uint DirectDrawSurface::fourCC() const
@@ -988,26 +999,32 @@ uint DirectDrawSurface::fourCC() const
uint DirectDrawSurface::width() const
{
- if (header.flags & DDSD_WIDTH)
+ if (header.flags & DDSD_WIDTH) {
return header.width;
- else
+ }
+ else {
return 1;
+ }
}
uint DirectDrawSurface::height() const
{
- if (header.flags & DDSD_HEIGHT)
+ if (header.flags & DDSD_HEIGHT) {
return header.height;
- else
+ }
+ else {
return 1;
+ }
}
uint DirectDrawSurface::depth() const
{
- if (header.flags & DDSD_DEPTH)
+ if (header.flags & DDSD_DEPTH) {
return header.depth;
- else
+ }
+ else {
return 1;
+ }
}
bool DirectDrawSurface::isTexture1D() const
@@ -1196,8 +1213,9 @@ static Color32 buildNormal(uint8 x, uint8 y)
float nx = 2 * (x / 255.0f) - 1;
float ny = 2 * (y / 255.0f) - 1;
float nz = 0.0f;
- if (1 - nx * nx - ny * ny > 0)
+ if (1 - nx * nx - ny * ny > 0) {
nz = sqrt(1 - nx * nx - ny * ny);
+ }
uint8 z = CLAMP(int(255.0f * (nz + 1) / 2.0f), 0, 255);
return Color32(x, y, z);
@@ -1209,16 +1227,21 @@ void DirectDrawSurface::readBlock(ColorBlock *rgba)
// Map DX10 block formats to fourcc codes.
if (header.hasDX10Header()) {
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM)
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM) {
fourcc = FOURCC_DXT1;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM) {
fourcc = FOURCC_DXT3;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC3_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC3_UNORM) {
fourcc = FOURCC_DXT5;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC4_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC4_UNORM) {
fourcc = FOURCC_ATI1;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC5_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC5_UNORM) {
fourcc = FOURCC_ATI2;
+ }
}
if (fourcc == FOURCC_DXT1) {
@@ -1307,8 +1330,8 @@ uint DirectDrawSurface::blockSize() const
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
return 16;
- };
- };
+ }
+ }
// Not a block image.
return 0;
@@ -1341,7 +1364,7 @@ uint DirectDrawSurface::mipmapSize(uint mipmap) const
else {
printf("DDS: mipmap format not supported\n");
return (0);
- };
+ }
}
uint DirectDrawSurface::faceSize() const
@@ -1378,56 +1401,77 @@ uint DirectDrawSurface::offset(const uint face, const uint mipmap)
void DirectDrawSurface::printInfo() const
{
printf("Flags: 0x%.8X\n", header.flags);
- if (header.flags & DDSD_CAPS)
+ if (header.flags & DDSD_CAPS) {
printf("\tDDSD_CAPS\n");
- if (header.flags & DDSD_PIXELFORMAT)
+ }
+ if (header.flags & DDSD_PIXELFORMAT) {
printf("\tDDSD_PIXELFORMAT\n");
- if (header.flags & DDSD_WIDTH)
+ }
+ if (header.flags & DDSD_WIDTH) {
printf("\tDDSD_WIDTH\n");
- if (header.flags & DDSD_HEIGHT)
+ }
+ if (header.flags & DDSD_HEIGHT) {
printf("\tDDSD_HEIGHT\n");
- if (header.flags & DDSD_DEPTH)
+ }
+ if (header.flags & DDSD_DEPTH) {
printf("\tDDSD_DEPTH\n");
- if (header.flags & DDSD_PITCH)
+ }
+ if (header.flags & DDSD_PITCH) {
printf("\tDDSD_PITCH\n");
- if (header.flags & DDSD_LINEARSIZE)
+ }
+ if (header.flags & DDSD_LINEARSIZE) {
printf("\tDDSD_LINEARSIZE\n");
- if (header.flags & DDSD_MIPMAPCOUNT)
+ }
+ if (header.flags & DDSD_MIPMAPCOUNT) {
printf("\tDDSD_MIPMAPCOUNT\n");
+ }
printf("Height: %u\n", header.height);
printf("Width: %u\n", header.width);
printf("Depth: %u\n", header.depth);
- if (header.flags & DDSD_PITCH)
+ if (header.flags & DDSD_PITCH) {
printf("Pitch: %u\n", header.pitch);
- else if (header.flags & DDSD_LINEARSIZE)
+ }
+ else if (header.flags & DDSD_LINEARSIZE) {
printf("Linear size: %u\n", header.pitch);
+ }
printf("Mipmap count: %u\n", header.mipmapcount);
printf("Pixel Format:\n");
printf("\tFlags: 0x%.8X\n", header.pf.flags);
- if (header.pf.flags & DDPF_RGB)
+ if (header.pf.flags & DDPF_RGB) {
printf("\t\tDDPF_RGB\n");
- if (header.pf.flags & DDPF_LUMINANCE)
+ }
+ if (header.pf.flags & DDPF_LUMINANCE) {
printf("\t\tDDPF_LUMINANCE\n");
- if (header.pf.flags & DDPF_FOURCC)
+ }
+ if (header.pf.flags & DDPF_FOURCC) {
printf("\t\tDDPF_FOURCC\n");
- if (header.pf.flags & DDPF_ALPHAPIXELS)
+ }
+ if (header.pf.flags & DDPF_ALPHAPIXELS) {
printf("\t\tDDPF_ALPHAPIXELS\n");
- if (header.pf.flags & DDPF_ALPHA)
+ }
+ if (header.pf.flags & DDPF_ALPHA) {
printf("\t\tDDPF_ALPHA\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED1)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED1) {
printf("\t\tDDPF_PALETTEINDEXED1\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED2)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED2) {
printf("\t\tDDPF_PALETTEINDEXED2\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED4)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED4) {
printf("\t\tDDPF_PALETTEINDEXED4\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED8)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED8) {
printf("\t\tDDPF_PALETTEINDEXED8\n");
- if (header.pf.flags & DDPF_ALPHAPREMULT)
+ }
+ if (header.pf.flags & DDPF_ALPHAPREMULT) {
printf("\t\tDDPF_ALPHAPREMULT\n");
- if (header.pf.flags & DDPF_NORMAL)
+ }
+ if (header.pf.flags & DDPF_NORMAL) {
printf("\t\tDDPF_NORMAL\n");
+ }
if (header.pf.fourcc != 0) {
// Display fourcc code even when DDPF_FOURCC flag not set.
@@ -1458,33 +1502,44 @@ void DirectDrawSurface::printInfo() const
printf("Caps:\n");
printf("\tCaps 1: 0x%.8X\n", header.caps.caps1);
- if (header.caps.caps1 & DDSCAPS_COMPLEX)
+ if (header.caps.caps1 & DDSCAPS_COMPLEX) {
printf("\t\tDDSCAPS_COMPLEX\n");
- if (header.caps.caps1 & DDSCAPS_TEXTURE)
+ }
+ if (header.caps.caps1 & DDSCAPS_TEXTURE) {
printf("\t\tDDSCAPS_TEXTURE\n");
- if (header.caps.caps1 & DDSCAPS_MIPMAP)
+ }
+ if (header.caps.caps1 & DDSCAPS_MIPMAP) {
printf("\t\tDDSCAPS_MIPMAP\n");
+ }
printf("\tCaps 2: 0x%.8X\n", header.caps.caps2);
- if (header.caps.caps2 & DDSCAPS2_VOLUME)
+ if (header.caps.caps2 & DDSCAPS2_VOLUME) {
printf("\t\tDDSCAPS2_VOLUME\n");
+ }
else if (header.caps.caps2 & DDSCAPS2_CUBEMAP) {
printf("\t\tDDSCAPS2_CUBEMAP\n");
- if ((header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) == DDSCAPS2_CUBEMAP_ALL_FACES)
+ if ((header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) == DDSCAPS2_CUBEMAP_ALL_FACES) {
printf("\t\tDDSCAPS2_CUBEMAP_ALL_FACES\n");
+ }
else {
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX)
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX) {
printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEX\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX) {
printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEX\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY) {
printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEY\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY) {
printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEY\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ) {
printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEZ\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ) {
printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEZ\n");
+ }
}
}
diff --git a/source/blender/imbuf/intern/dds/FlipDXT.cpp b/source/blender/imbuf/intern/dds/FlipDXT.cpp
index 0660d5ce5cc..cf228cea3ea 100644
--- a/source/blender/imbuf/intern/dds/FlipDXT.cpp
+++ b/source/blender/imbuf/intern/dds/FlipDXT.cpp
@@ -173,11 +173,13 @@ int FlipDXTCImage(
unsigned int width, unsigned int height, unsigned int levels, int fourcc, uint8_t *data)
{
// must have valid dimensions
- if (width == 0 || height == 0)
+ if (width == 0 || height == 0) {
return 0;
+ }
// height must be a power-of-two
- if ((height & (height - 1)) != 0)
+ if ((height & (height - 1)) != 0) {
return 0;
+ }
FlipBlockFunction full_block_function;
FlipBlockFunction half_block_function;
@@ -223,8 +225,9 @@ int FlipDXTCImage(
}
else {
// flip each block.
- for (unsigned int i = 0; i < blocks; ++i)
+ for (unsigned int i = 0; i < blocks; ++i) {
full_block_function(data + i * block_bytes);
+ }
// swap each block line in the first half of the image with the
// corresponding one in the second half.
diff --git a/source/blender/imbuf/intern/dds/Image.cpp b/source/blender/imbuf/intern/dds/Image.cpp
index 6f0fff75818..d08a61a5a60 100644
--- a/source/blender/imbuf/intern/dds/Image.cpp
+++ b/source/blender/imbuf/intern/dds/Image.cpp
@@ -51,8 +51,9 @@ void Image::allocate(uint w, uint h)
void Image::free()
{
- if (m_data)
+ if (m_data) {
delete[] m_data;
+ }
m_data = NULL;
}
diff --git a/source/blender/imbuf/intern/dds/Image.h b/source/blender/imbuf/intern/dds/Image.h
index b6191b7e96c..1aa60ef48ca 100644
--- a/source/blender/imbuf/intern/dds/Image.h
+++ b/source/blender/imbuf/intern/dds/Image.h
@@ -30,8 +30,8 @@
#ifndef __IMAGE_H__
#define __IMAGE_H__
-#include <Common.h>
-#include <Color.h>
+#include "Common.h"
+#include "Color.h"
/// 32 bit RGBA image.
class Image {
diff --git a/source/blender/imbuf/intern/dds/PixelFormat.h b/source/blender/imbuf/intern/dds/PixelFormat.h
index ba487afdfc1..e63b17c89e5 100644
--- a/source/blender/imbuf/intern/dds/PixelFormat.h
+++ b/source/blender/imbuf/intern/dds/PixelFormat.h
@@ -51,7 +51,7 @@
#ifndef __PIXELFORMAT_H__
#define __PIXELFORMAT_H__
-#include <Common.h>
+#include "Common.h"
namespace PixelFormat {
diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp
index 6a76e231e37..098b695b8a3 100644
--- a/source/blender/imbuf/intern/dds/dds_api.cpp
+++ b/source/blender/imbuf/intern/dds/dds_api.cpp
@@ -49,10 +49,12 @@ int imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/)
return (0); /* todo: finish this function */
/* check image buffer */
- if (ibuf == 0)
+ if (ibuf == 0) {
return (0);
- if (ibuf->rect == 0)
+ }
+ if (ibuf->rect == 0) {
return (0);
+ }
/* open file for writing */
std::ofstream fildes;
@@ -76,11 +78,13 @@ int imb_is_a_dds(const unsigned char *mem) // note: use at most first 32 bytes
{
/* heuristic check to see if mem contains a DDS file */
/* header.fourcc == FOURCC_DDS */
- if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' '))
+ if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' ')) {
return (0);
+ }
/* header.size == 124 */
- if ((mem[4] != 124) || mem[5] || mem[6] || mem[7])
+ if ((mem[4] != 124) || mem[5] || mem[6] || mem[7]) {
return (0);
+ }
return (1);
}
@@ -106,14 +110,16 @@ struct ImBuf *imb_load_dds(const unsigned char *mem,
*/
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
- if (!imb_is_a_dds(mem))
+ if (!imb_is_a_dds(mem)) {
return (0);
+ }
/* check if DDS is valid and supported */
if (!dds.isValid()) {
/* no need to print error here, just testing if it is a DDS */
- if (flags & IB_test)
+ if (flags & IB_test) {
return (0);
+ }
printf("DDS: not valid; header follows\n");
dds.printInfo();
@@ -144,18 +150,21 @@ struct ImBuf *imb_load_dds(const unsigned char *mem,
}
}
ibuf = IMB_allocImBuf(dds.width(), dds.height(), bits_per_pixel, 0);
- if (ibuf == 0)
+ if (ibuf == 0) {
return (0); /* memory allocation failed */
+ }
ibuf->ftype = IMB_FTYPE_DDS;
ibuf->dds_data.fourcc = dds.fourCC();
ibuf->dds_data.nummipmaps = dds.mipmapCount();
if ((flags & IB_test) == 0) {
- if (!imb_addrectImBuf(ibuf))
+ if (!imb_addrectImBuf(ibuf)) {
return (ibuf);
- if (ibuf->rect == 0)
+ }
+ if (ibuf->rect == 0) {
return (ibuf);
+ }
rect = ibuf->rect;
cp[3] = 0xff; /* default alpha if alpha channel is not present */
@@ -165,8 +174,9 @@ struct ImBuf *imb_load_dds(const unsigned char *mem,
cp[0] = pixel.r; /* set R component of col */
cp[1] = pixel.g; /* set G component of col */
cp[2] = pixel.b; /* set B component of col */
- if (dds.hasAlpha())
+ if (dds.hasAlpha()) {
cp[3] = pixel.a; /* set A component of col */
+ }
rect[i] = col;
}
diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c
index 535d2e95122..e4845e56c46 100644
--- a/source/blender/imbuf/intern/divers.c
+++ b/source/blender/imbuf/intern/divers.c
@@ -119,8 +119,9 @@ void IMB_buffer_byte_from_float(uchar *rect_to,
BLI_assert(profile_to != IB_PROFILE_NONE);
BLI_assert(profile_from != IB_PROFILE_NONE);
- if (dither)
+ if (dither) {
di = create_dither_context(dither);
+ }
for (y = 0; y < height; y++) {
float t = y * inv_height;
@@ -130,8 +131,9 @@ void IMB_buffer_byte_from_float(uchar *rect_to,
const float *from = rect_from + ((size_t)stride_from) * y;
uchar *to = rect_to + ((size_t)stride_to) * y * 4;
- for (x = 0; x < width; x++, from++, to += 4)
+ for (x = 0; x < width; x++, from++, to += 4) {
to[0] = to[1] = to[2] = to[3] = unit_float_to_uchar_clamp(from[0]);
+ }
}
else if (channels_from == 3) {
/* RGB input */
@@ -178,8 +180,9 @@ void IMB_buffer_byte_from_float(uchar *rect_to,
}
}
else if (dither) {
- for (x = 0; x < width; x++, from += 4, to += 4)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
float_to_byte_dither_v4(to, from, di, (float)x * inv_width, t);
+ }
}
else if (predivide) {
for (x = 0; x < width; x++, from += 4, to += 4) {
@@ -188,8 +191,9 @@ void IMB_buffer_byte_from_float(uchar *rect_to,
}
}
else {
- for (x = 0; x < width; x++, from += 4, to += 4)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
rgba_float_to_uchar(to, from);
+ }
}
}
else if (profile_to == IB_PROFILE_SRGB) {
@@ -254,8 +258,9 @@ void IMB_buffer_byte_from_float(uchar *rect_to,
}
}
- if (dither)
+ if (dither) {
clear_dither_context(di);
+ }
}
/* float to byte pixels, output 4-channel RGBA */
@@ -274,8 +279,9 @@ void IMB_buffer_byte_from_float_mask(uchar *rect_to,
DitherContext *di = NULL;
float inv_width = 1.0f / width, inv_height = 1.0f / height;
- if (dither)
+ if (dither) {
di = create_dither_context(dither);
+ }
for (y = 0; y < height; y++) {
float t = y * inv_height;
@@ -285,9 +291,11 @@ void IMB_buffer_byte_from_float_mask(uchar *rect_to,
const float *from = rect_from + ((size_t)stride_from) * y;
uchar *to = rect_to + ((size_t)stride_to) * y * 4;
- for (x = 0; x < width; x++, from++, to += 4)
- if (*mask++ == FILTER_MASK_USED)
+ for (x = 0; x < width; x++, from++, to += 4) {
+ if (*mask++ == FILTER_MASK_USED) {
to[0] = to[1] = to[2] = to[3] = unit_float_to_uchar_clamp(from[0]);
+ }
+ }
}
else if (channels_from == 3) {
/* RGB input */
@@ -317,9 +325,11 @@ void IMB_buffer_byte_from_float_mask(uchar *rect_to,
}
}
else if (dither) {
- for (x = 0; x < width; x++, from += 4, to += 4)
- if (*mask++ == FILTER_MASK_USED)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
+ if (*mask++ == FILTER_MASK_USED) {
float_to_byte_dither_v4(to, from, di, (float)x * inv_width, t);
+ }
+ }
}
else if (predivide) {
for (x = 0; x < width; x++, from += 4, to += 4) {
@@ -330,15 +340,18 @@ void IMB_buffer_byte_from_float_mask(uchar *rect_to,
}
}
else {
- for (x = 0; x < width; x++, from += 4, to += 4)
- if (*mask++ == FILTER_MASK_USED)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
+ if (*mask++ == FILTER_MASK_USED) {
rgba_float_to_uchar(to, from);
+ }
+ }
}
}
}
- if (dither)
+ if (dither) {
clear_dither_context(di);
+ }
}
/* byte to float pixels, input and output 4-channel RGBA */
@@ -366,8 +379,9 @@ void IMB_buffer_float_from_byte(float *rect_to,
if (profile_to == profile_from) {
/* no color space conversion */
- for (x = 0; x < width; x++, from += 4, to += 4)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
rgba_uchar_to_float(to, from);
+ }
}
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert sRGB to linear */
@@ -424,8 +438,9 @@ void IMB_buffer_float_from_float(float *rect_to,
const float *from = rect_from + ((size_t)stride_from) * y;
float *to = rect_to + ((size_t)stride_to) * y * 4;
- for (x = 0; x < width; x++, from++, to += 4)
+ for (x = 0; x < width; x++, from++, to += 4) {
to[0] = to[1] = to[2] = to[3] = from[0];
+ }
}
}
else if (channels_from == 3) {
@@ -470,23 +485,27 @@ void IMB_buffer_float_from_float(float *rect_to,
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert to sRGB to linear */
if (predivide) {
- for (x = 0; x < width; x++, from += 4, to += 4)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
srgb_to_linearrgb_predivide_v4(to, from);
+ }
}
else {
- for (x = 0; x < width; x++, from += 4, to += 4)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
srgb_to_linearrgb_v4(to, from);
+ }
}
}
else if (profile_to == IB_PROFILE_SRGB) {
/* convert from linear to sRGB */
if (predivide) {
- for (x = 0; x < width; x++, from += 4, to += 4)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
linearrgb_to_srgb_predivide_v4(to, from);
+ }
}
else {
- for (x = 0; x < width; x++, from += 4, to += 4)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
linearrgb_to_srgb_v4(to, from);
+ }
}
}
}
@@ -580,9 +599,11 @@ void IMB_buffer_float_from_float_mask(float *rect_to,
const float *from = rect_from + ((size_t)stride_from) * y;
float *to = rect_to + ((size_t)stride_to) * y * 4;
- for (x = 0; x < width; x++, from++, to += 4)
- if (*mask++ == FILTER_MASK_USED)
+ for (x = 0; x < width; x++, from++, to += 4) {
+ if (*mask++ == FILTER_MASK_USED) {
to[0] = to[1] = to[2] = to[3] = from[0];
+ }
+ }
}
}
else if (channels_from == 3) {
@@ -605,9 +626,11 @@ void IMB_buffer_float_from_float_mask(float *rect_to,
const float *from = rect_from + ((size_t)stride_from) * y * 4;
float *to = rect_to + ((size_t)stride_to) * y * 4;
- for (x = 0; x < width; x++, from += 4, to += 4)
- if (*mask++ == FILTER_MASK_USED)
+ for (x = 0; x < width; x++, from += 4, to += 4) {
+ if (*mask++ == FILTER_MASK_USED) {
copy_v4_v4(to, from);
+ }
+ }
}
}
}
@@ -684,19 +707,23 @@ void IMB_rect_from_float(ImBuf *ibuf)
const char *from_colorspace;
/* verify we have a float buffer */
- if (ibuf->rect_float == NULL)
+ if (ibuf->rect_float == NULL) {
return;
+ }
/* create byte rect if it didn't exist yet */
if (ibuf->rect == NULL) {
- if (imb_addrectImBuf(ibuf) == 0)
+ if (imb_addrectImBuf(ibuf) == 0) {
return;
+ }
}
- if (ibuf->float_colorspace == NULL)
+ if (ibuf->float_colorspace == NULL) {
from_colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR);
- else
+ }
+ else {
from_colorspace = ibuf->float_colorspace->name;
+ }
buffer = MEM_dupallocN(ibuf->rect_float);
@@ -812,12 +839,14 @@ void IMB_partial_rect_from_float(
uchar *rect_byte;
/* verify we have a float buffer */
- if (ibuf->rect_float == NULL || buffer == NULL)
+ if (ibuf->rect_float == NULL || buffer == NULL) {
return;
+ }
/* create byte rect if it didn't exist yet */
- if (ibuf->rect == NULL)
+ if (ibuf->rect == NULL) {
imb_addrectImBuf(ibuf);
+ }
/* do conversion */
rect_float = ibuf->rect_float + (x + ((size_t)y) * ibuf->x) * ibuf->channels;
@@ -846,8 +875,9 @@ void IMB_float_from_rect(ImBuf *ibuf)
float *rect_float;
/* verify if we byte and float buffers */
- if (ibuf->rect == NULL)
+ if (ibuf->rect == NULL) {
return;
+ }
/* allocate float buffer outside of image buffer,
* so work-in-progress color space conversion doesn't
@@ -863,8 +893,9 @@ void IMB_float_from_rect(ImBuf *ibuf)
rect_float = MEM_mapallocN(size, "IMB_float_from_rect");
- if (rect_float == NULL)
+ if (rect_float == NULL) {
return;
+ }
}
/* first, create float buffer in non-linear space */
@@ -902,13 +933,15 @@ void IMB_color_to_bw(ImBuf *ibuf)
size_t i;
if (rct_fl) {
- for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, rct_fl += 4)
+ for (i = ((size_t)ibuf->x) * ibuf->y; i > 0; i--, rct_fl += 4) {
rct_fl[0] = rct_fl[1] = rct_fl[2] = IMB_colormanagement_get_luminance(rct_fl);
+ }
}
if (rct) {
- for (i = ((size_t)ibuf->x * ibuf->y); i > 0; i--, rct += 4)
+ for (i = ((size_t)ibuf->x * ibuf->y); i > 0; i--, rct += 4) {
rct[0] = rct[1] = rct[2] = IMB_colormanagement_get_luminance_byte(rct);
+ }
}
}
diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c
index 7056e901f65..d1b3bf21e23 100644
--- a/source/blender/imbuf/intern/filetype.c
+++ b/source/blender/imbuf/intern/filetype.c
@@ -231,16 +231,20 @@ void imb_filetypes_init(void)
{
const ImFileType *type;
- for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++)
- if (type->init)
+ for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
+ if (type->init) {
type->init();
+ }
+ }
}
void imb_filetypes_exit(void)
{
const ImFileType *type;
- for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++)
- if (type->exit)
+ for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
+ if (type->exit) {
type->exit();
+ }
+ }
}
diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c
index f41c831cf85..49e1a66886d 100644
--- a/source/blender/imbuf/intern/filter.c
+++ b/source/blender/imbuf/intern/filter.c
@@ -129,8 +129,9 @@ void IMB_filtery(struct ImBuf *ibuf)
for (; x > 0; x--) {
if (point) {
- if (ibuf->planes > 24)
+ if (ibuf->planes > 24) {
filtcolum(point, y, skip);
+ }
point++;
filtcolum(point, y, skip);
point++;
@@ -140,8 +141,9 @@ void IMB_filtery(struct ImBuf *ibuf)
point++;
}
if (pointf) {
- if (ibuf->planes > 24)
+ if (ibuf->planes > 24) {
filtcolumf(pointf, y, skip);
+ }
pointf++;
filtcolumf(pointf, y, skip);
pointf++;
@@ -168,8 +170,9 @@ void imb_filterx(struct ImBuf *ibuf)
for (; y > 0; y--) {
if (point) {
- if (ibuf->planes > 24)
+ if (ibuf->planes > 24) {
filtrow(point, x);
+ }
point++;
filtrow(point, x);
point++;
@@ -179,8 +182,9 @@ void imb_filterx(struct ImBuf *ibuf)
point += skip;
}
if (pointf) {
- if (ibuf->planes > 24)
+ if (ibuf->planes > 24) {
filtrowf(pointf, x);
+ }
pointf++;
filtrowf(pointf, x);
pointf++;
@@ -331,10 +335,12 @@ void IMB_mask_filter_extend(char *mask, int width, int height)
row1 = (char *)(temprect + (y - 2) * rowlen);
row2 = row1 + rowlen;
row3 = row2 + rowlen;
- if (y == 1)
+ if (y == 1) {
row1 = row2;
- else if (y == height)
+ }
+ else if (y == height) {
row3 = row2;
+ }
for (x = 0; x < rowlen; x++) {
if (mask[((y - 1) * rowlen) + x] == 0) {
@@ -385,10 +391,12 @@ void IMB_mask_clear(ImBuf *ibuf, char *mask, int val)
static int filter_make_index(const int x, const int y, const int w, const int h)
{
- if (x < 0 || x >= w || y < 0 || y >= h)
+ if (x < 0 || x >= w || y < 0 || y >= h) {
return -1; /* return bad index */
- else
+ }
+ else {
return y * w + x;
+ }
}
static int check_pixel_assigned(
@@ -484,18 +492,21 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
if (check_pixel_assigned(srcbuf, srcmask, tmpindex, depth, is_float)) {
if (is_float) {
- for (c = 0; c < depth; c++)
+ for (c = 0; c < depth; c++) {
tmp[c] = ((const float *)srcbuf)[depth * tmpindex + c];
+ }
}
else {
- for (c = 0; c < depth; c++)
+ for (c = 0; c < depth; c++) {
tmp[c] = (float)((const unsigned char *)srcbuf)[depth * tmpindex + c];
+ }
}
wsum += weight[k];
- for (c = 0; c < depth; c++)
+ for (c = 0; c < depth; c++) {
acc[c] += weight[k] * tmp[c];
+ }
}
}
k++;
@@ -503,12 +514,14 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
}
if (wsum != 0) {
- for (c = 0; c < depth; c++)
+ for (c = 0; c < depth; c++) {
acc[c] /= wsum;
+ }
if (is_float) {
- for (c = 0; c < depth; c++)
+ for (c = 0; c < depth; c++) {
((float *)dstbuf)[depth * index + c] = acc[c];
+ }
}
else {
for (c = 0; c < depth; c++) {
@@ -517,8 +530,9 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
}
}
- if (dstmask != NULL)
+ if (dstmask != NULL) {
dstmask[index] = FILTER_MASK_MARGIN; /* assigned */
+ }
cannot_early_out = 1;
}
}
@@ -535,8 +549,9 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
/* free memory */
MEM_freeN(dstbuf);
- if (dstmask != NULL)
+ if (dstmask != NULL) {
MEM_freeN(dstmask);
+ }
}
/* threadsafe version, only recreates existing maps */
@@ -557,17 +572,20 @@ void IMB_remakemipmap(ImBuf *ibuf, int use_filter)
imb_onehalf_no_alloc(ibuf->mipmap[curmap], nbuf);
IMB_freeImBuf(nbuf);
}
- else
+ else {
imb_onehalf_no_alloc(ibuf->mipmap[curmap], hbuf);
+ }
}
ibuf->miptot = curmap + 2;
hbuf = ibuf->mipmap[curmap];
- if (hbuf)
+ if (hbuf) {
hbuf->miplevel = curmap + 1;
+ }
- if (!hbuf || (hbuf->x <= 2 && hbuf->y <= 2))
+ if (!hbuf || (hbuf->x <= 2 && hbuf->y <= 2)) {
break;
+ }
curmap++;
}
@@ -582,8 +600,9 @@ void IMB_makemipmap(ImBuf *ibuf, int use_filter)
imb_freemipmapImBuf(ibuf);
/* no mipmap for non RGBA images */
- if (ibuf->rect_float && ibuf->channels < 4)
+ if (ibuf->rect_float && ibuf->channels < 4) {
return;
+ }
ibuf->miptot = 1;
@@ -594,15 +613,17 @@ void IMB_makemipmap(ImBuf *ibuf, int use_filter)
ibuf->mipmap[curmap] = IMB_onehalf(nbuf);
IMB_freeImBuf(nbuf);
}
- else
+ else {
ibuf->mipmap[curmap] = IMB_onehalf(hbuf);
+ }
ibuf->miptot = curmap + 2;
hbuf = ibuf->mipmap[curmap];
hbuf->miplevel = curmap + 1;
- if (hbuf->x < 2 && hbuf->y < 2)
+ if (hbuf->x < 2 && hbuf->y < 2) {
break;
+ }
curmap++;
}
@@ -622,9 +643,11 @@ void IMB_premultiply_rect(unsigned int *rect, char planes, int w, int h)
if (planes == 24) { /* put alpha at 255 */
cp = (char *)(rect);
- for (y = 0; y < h; y++)
- for (x = 0; x < w; x++, cp += 4)
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++, cp += 4) {
cp[3] = 255;
+ }
+ }
}
else {
cp = (char *)(rect);
@@ -660,14 +683,17 @@ void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h)
void IMB_premultiply_alpha(ImBuf *ibuf)
{
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return;
+ }
- if (ibuf->rect)
+ if (ibuf->rect) {
IMB_premultiply_rect(ibuf->rect, ibuf->planes, ibuf->x, ibuf->y);
+ }
- if (ibuf->rect_float)
+ if (ibuf->rect_float) {
IMB_premultiply_rect_float(ibuf->rect_float, ibuf->channels, ibuf->x, ibuf->y);
+ }
}
void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h)
@@ -679,9 +705,11 @@ void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h)
if (planes == 24) { /* put alpha at 255 */
cp = (char *)(rect);
- for (y = 0; y < h; y++)
- for (x = 0; x < w; x++, cp += 4)
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++, cp += 4) {
cp[3] = 255;
+ }
+ }
}
else {
cp = (char *)(rect);
@@ -717,12 +745,15 @@ void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h)
void IMB_unpremultiply_alpha(ImBuf *ibuf)
{
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return;
+ }
- if (ibuf->rect)
+ if (ibuf->rect) {
IMB_unpremultiply_rect(ibuf->rect, ibuf->planes, ibuf->x, ibuf->y);
+ }
- if (ibuf->rect_float)
+ if (ibuf->rect_float) {
IMB_unpremultiply_rect_float(ibuf->rect_float, ibuf->channels, ibuf->x, ibuf->y);
+ }
}
diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c
index 02a93d7fa5c..1f180d0d9c1 100644
--- a/source/blender/imbuf/intern/imageprocess.c
+++ b/source/blender/imbuf/intern/imageprocess.c
@@ -79,11 +79,13 @@ static void pixel_from_buffer(struct ImBuf *ibuf, unsigned char **outI, float **
{
size_t offset = ((size_t)ibuf->x) * y * 4 + 4 * x;
- if (ibuf->rect)
+ if (ibuf->rect) {
*outI = (unsigned char *)ibuf->rect + offset;
+ }
- if (ibuf->rect_float)
+ if (ibuf->rect_float) {
*outF = ibuf->rect_float + offset;
+ }
}
/* BICUBIC Interpolation */
@@ -154,15 +156,19 @@ void bilinear_interpolation_color_wrap(
}
/* wrap interpolation pixels - main difference from bilinear_interpolation_color */
- if (x1 < 0)
+ if (x1 < 0) {
x1 = in->x + x1;
- if (y1 < 0)
+ }
+ if (y1 < 0) {
y1 = in->y + y1;
+ }
- if (x2 >= in->x)
+ if (x2 >= in->x) {
x2 = x2 - in->x;
- if (y2 >= in->y)
+ }
+ if (y2 >= in->y) {
y2 = y2 - in->y;
+ }
a = u - floorf(u);
b = v - floorf(v);
@@ -236,10 +242,12 @@ void nearest_interpolation_color(
/* sample area entirely outside image? */
if (x1 < 0 || x1 > in->x - 1 || y1 < 0 || y1 > in->y - 1) {
- if (outI)
+ if (outI) {
outI[0] = outI[1] = outI[2] = outI[3] = 0;
- if (outF)
+ }
+ if (outF) {
outF[0] = outF[1] = outF[2] = outF[3] = 0.0f;
+ }
return;
}
@@ -292,10 +300,12 @@ void nearest_interpolation_color_wrap(
y = y % in->y;
/* wrap interpolation pixels - main difference from nearest_interpolation_color */
- if (x < 0)
+ if (x < 0) {
x += in->x;
- if (y < 0)
+ }
+ if (y < 0) {
y += in->y;
+ }
dataI = (unsigned char *)in->rect + ((size_t)in->x) * y * 4 + 4 * x;
if (outI) {
@@ -362,10 +372,12 @@ void IMB_processor_apply_threaded(
int lines_per_current_task;
void *handle = ((char *)handles) + handle_size * i;
- if (i < total_tasks - 1)
+ if (i < total_tasks - 1) {
lines_per_current_task = lines_per_task;
- else
+ }
+ else {
lines_per_current_task = buffer_lines - start_line;
+ }
init_handle(handle, start_line, lines_per_current_task, init_customdata);
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c
index 3ce168fd37f..e343faa7dc8 100644
--- a/source/blender/imbuf/intern/indexer.c
+++ b/source/blender/imbuf/intern/indexer.c
@@ -867,8 +867,9 @@ static void index_rebuild_ffmpeg_proc_decoded_frame(FFmpegIndexBuilderContext *c
if (context->tcs_in_use & tc_types[i]) {
int tc_frameno = context->frameno;
- if (tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS)
+ if (tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS) {
tc_frameno = context->frameno_gapless;
+ }
IMB_index_builder_proc_frame(context->indexer[i],
curr_packet->data,
@@ -1201,8 +1202,9 @@ IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
#endif
}
- if (context)
+ if (context) {
context->anim_type = anim->curtype;
+ }
return context;
diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c
index ee1a6b57c26..4b23443933a 100644
--- a/source/blender/imbuf/intern/iris.c
+++ b/source/blender/imbuf/intern/iris.c
@@ -221,10 +221,12 @@ static void test_endian_zbuf(struct ImBuf *ibuf)
int len;
int *zval;
- if (BIG_LONG(1) == 1)
+ if (BIG_LONG(1) == 1) {
return;
- if (ibuf->zbuf == NULL)
+ }
+ if (ibuf->zbuf == NULL) {
return;
+ }
len = ibuf->x * ibuf->y;
zval = ibuf->zbuf;
@@ -299,8 +301,9 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
if (flags & IB_test) {
ibuf = IMB_allocImBuf(image.xsize, image.ysize, 8 * image.zsize, 0);
- if (ibuf)
+ if (ibuf) {
ibuf->ftype = IMB_FTYPE_IMAGIC;
+ }
return (ibuf);
}
@@ -334,8 +337,9 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
}
cur = starttab[y + z * ysize];
}
- if (badorder)
+ if (badorder) {
break;
+ }
}
if (bpp == 1) {
@@ -344,8 +348,9 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
if (!ibuf) {
goto fail_rle;
}
- if (ibuf->planes > 32)
+ if (ibuf->planes > 32) {
ibuf->planes = 32;
+ }
base = ibuf->rect;
zbase = (uint *)ibuf->zbuf;
@@ -458,8 +463,9 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
if (!ibuf) {
goto fail_uncompressed;
}
- if (ibuf->planes > 32)
+ if (ibuf->planes > 32) {
ibuf->planes = 32;
+ }
base = ibuf->rect;
zbase = (uint *)ibuf->zbuf;
@@ -469,10 +475,12 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
for (size_t z = 0; z < zsize; z++) {
- if (z < 4)
+ if (z < 4) {
lptr = base;
- else if (z < 8)
+ }
+ else if (z < 8) {
lptr = zbase;
+ }
for (size_t y = 0; y < ysize; y++) {
const uchar *rledat_next = rledat + xsize;
@@ -640,8 +648,9 @@ static int expandrow2(
pixel = (iptr[0] << 8) | (iptr[1] << 0);
iptr = iptr_next;
- if (!(count = (pixel & 0x7f)))
+ if (!(count = (pixel & 0x7f))) {
return false;
+ }
const float *optr_next = optr + count;
EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next);
if (pixel & 0x80) {
@@ -725,8 +734,9 @@ static int expandrow(
EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next);
pixel = *iptr;
iptr = iptr_next;
- if (!(count = (pixel & 0x7f)))
+ if (!(count = (pixel & 0x7f))) {
return false;
+ }
const uchar *optr_next = optr + ((int)count * 4);
EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next);
@@ -809,8 +819,9 @@ static int output_iris(uint *lptr, int xsize, int ysize, int zsize, const char *
goodwrite = 1;
outf = BLI_fopen(name, "wb");
- if (!outf)
+ if (!outf) {
return 0;
+ }
tablen = ysize * zsize * sizeof(int);
@@ -824,10 +835,12 @@ static int output_iris(uint *lptr, int xsize, int ysize, int zsize, const char *
memset(image, 0, sizeof(IMAGE));
image->imagic = IMAGIC;
image->type = RLE(1);
- if (zsize > 1)
+ if (zsize > 1) {
image->dim = 3;
- else
+ }
+ else {
image->dim = 2;
+ }
image->xsize = xsize;
image->ysize = ysize;
image->zsize = zsize;
@@ -862,8 +875,9 @@ static int output_iris(uint *lptr, int xsize, int ysize, int zsize, const char *
pos += len;
}
lptr += xsize;
- if (zptr)
+ if (zptr) {
zptr += xsize;
+ }
}
fseek(outf, HEADER_SIZE, SEEK_SET);
@@ -875,8 +889,9 @@ static int output_iris(uint *lptr, int xsize, int ysize, int zsize, const char *
MEM_freeN(rlebuf);
MEM_freeN(lumbuf);
fclose(outf);
- if (goodwrite)
+ if (goodwrite) {
return 1;
+ }
else {
fprintf(stderr, "output_iris: not enough space for image!!\n");
return 0;
@@ -909,8 +924,9 @@ static int compressrow(uchar *lbuf, uchar *rlebuf, int z, int cnt)
while (iptr < ibufend) {
sptr = iptr;
iptr += 8;
- while ((iptr < ibufend) && ((iptr[-8] != iptr[-4]) || (iptr[-4] != iptr[0])))
+ while ((iptr < ibufend) && ((iptr[-8] != iptr[-4]) || (iptr[-4] != iptr[0]))) {
iptr += 4;
+ }
iptr -= 8;
count = (iptr - sptr) / 4;
while (count) {
@@ -939,8 +955,9 @@ static int compressrow(uchar *lbuf, uchar *rlebuf, int z, int cnt)
sptr = iptr;
cc = *iptr;
iptr += 4;
- while ((iptr < ibufend) && (*iptr == cc))
+ while ((iptr < ibufend) && (*iptr == cc)) {
iptr += 4;
+ }
count = (iptr - sptr) / 4;
while (count) {
todo = count > 126 ? 126 : count;
@@ -959,8 +976,9 @@ int imb_saveiris(struct ImBuf *ibuf, const char *name, int flags)
int ret;
zsize = (ibuf->planes + 7) >> 3;
- if (flags & IB_zbuf && ibuf->zbuf != NULL)
+ if (flags & IB_zbuf && ibuf->zbuf != NULL) {
zsize = 8;
+ }
IMB_convert_rgba_to_abgr(ibuf);
test_endian_zbuf(ibuf);
diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c
index bfbe4260f5f..49437e77d8e 100644
--- a/source/blender/imbuf/intern/jp2.c
+++ b/source/blender/imbuf/intern/jp2.c
@@ -435,17 +435,20 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream,
}
i = image->numcomps;
- if (i > 4)
+ if (i > 4) {
i = 4;
+ }
while (i) {
i--;
- if (image->comps[i].prec > 8)
+ if (image->comps[i].prec > 8) {
use_float = true;
+ }
- if (image->comps[i].sgnd)
+ if (image->comps[i].sgnd) {
signed_offsets[i] = 1 << (image->comps[i].prec - 1);
+ }
/* only needed for float images but dosnt hurt to calc this */
float_divs[i] = (1 << image->comps[i].prec) - 1;
@@ -850,8 +853,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
if (ibuf->foptions.flag & JP2_CINE) {
- if (ibuf->x == 4096 || ibuf->y == 2160)
+ if (ibuf->x == 4096 || ibuf->y == 2160) {
parameters->cp_cinema = OPJ_CINEMA4K_24;
+ }
else {
if (ibuf->foptions.flag & JP2_CINE_48FPS) {
parameters->cp_cinema = OPJ_CINEMA2K_48;
@@ -876,12 +880,15 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
/* Get settings from the imbuf */
color_space = (ibuf->foptions.flag & JP2_YCC) ? OPJ_CLRSPC_SYCC : OPJ_CLRSPC_SRGB;
- if (ibuf->foptions.flag & JP2_16BIT)
+ if (ibuf->foptions.flag & JP2_16BIT) {
prec = 16;
- else if (ibuf->foptions.flag & JP2_12BIT)
+ }
+ else if (ibuf->foptions.flag & JP2_12BIT) {
prec = 12;
- else
+ }
+ else {
prec = 8;
+ }
/* 32bit images == alpha channel */
/* grayscale not supported yet */
@@ -1181,8 +1188,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
cinema_setup_encoder(parameters, image, &img_fol);
}
- if (img_fol.rates)
+ if (img_fol.rates) {
MEM_freeN(img_fol.rates);
+ }
return image;
}
diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c
index a09f83e9b92..0822c069755 100644
--- a/source/blender/imbuf/intern/jpeg.c
+++ b/source/blender/imbuf/intern/jpeg.c
@@ -59,8 +59,9 @@ static uchar ibuf_quality;
int imb_is_a_jpeg(const unsigned char *mem)
{
- if ((mem[0] == 0xFF) && (mem[1] == 0xD8))
+ if ((mem[0] == 0xFF) && (mem[1] == 0xD8)) {
return 1;
+ }
return 0;
}
@@ -279,8 +280,9 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla
y = cinfo->image_height;
depth = cinfo->num_components;
- if (cinfo->jpeg_color_space == JCS_YCCK)
+ if (cinfo->jpeg_color_space == JCS_YCCK) {
cinfo->out_color_space = JCS_CMYK;
+ }
jpeg_start_decompress(cinfo);
@@ -341,8 +343,9 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla
marker = cinfo->marker_list;
while (marker) {
- if (marker->marker != JPEG_COM)
+ if (marker->marker != JPEG_COM) {
goto next_stamp_marker;
+ }
/*
* JPEG marker strings are not null-terminated,
@@ -426,8 +429,9 @@ ImBuf *imb_load_jpeg(const unsigned char *buffer,
struct my_error_mgr jerr;
ImBuf *ibuf;
- if (!imb_is_a_jpeg(buffer))
+ if (!imb_is_a_jpeg(buffer)) {
return NULL;
+ }
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -554,10 +558,12 @@ static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct I
int quality;
quality = ibuf->foptions.quality;
- if (quality <= 0)
+ if (quality <= 0) {
quality = jpeg_default_quality;
- if (quality > 100)
+ }
+ if (quality > 100) {
quality = 100;
+ }
jpeg_create_compress(cinfo);
jpeg_stdio_dest(cinfo, outfile);
@@ -566,8 +572,9 @@ static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct I
cinfo->image_height = ibuf->y;
cinfo->in_color_space = JCS_RGB;
- if (ibuf->planes == 8)
+ if (ibuf->planes == 8) {
cinfo->in_color_space = JCS_GRAYSCALE;
+ }
#if 0
/* just write RGBA as RGB,
* unsupported feature only confuses other s/w */
@@ -606,8 +613,9 @@ static int save_stdjpeg(const char *name, struct ImBuf *ibuf)
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr;
- if ((outfile = BLI_fopen(name, "wb")) == NULL)
+ if ((outfile = BLI_fopen(name, "wb")) == NULL) {
return 0;
+ }
cinfo->err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = jpeg_error;
diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c
index fe6909b0f3f..4424e5548ca 100644
--- a/source/blender/imbuf/intern/moviecache.c
+++ b/source/blender/imbuf/intern/moviecache.c
@@ -151,8 +151,9 @@ static void check_unused_keys(MovieCache *cache)
PRINT("%s: cache '%s' remove item %p without buffer\n", __func__, cache->name, item);
}
- if (remove)
+ if (remove) {
BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree);
+ }
}
}
@@ -205,18 +206,21 @@ static size_t IMB_get_size_in_memory(ImBuf *ibuf)
size += sizeof(ImBuf);
- if (ibuf->rect)
+ if (ibuf->rect) {
channel_size += sizeof(char);
+ }
- if (ibuf->rect_float)
+ if (ibuf->rect_float) {
channel_size += sizeof(float);
+ }
size += channel_size * ibuf->x * ibuf->y * ibuf->channels;
if (ibuf->miptot) {
for (a = 0; a < ibuf->miptot; a++) {
- if (ibuf->mipmap[a])
+ if (ibuf->mipmap[a]) {
size += IMB_get_size_in_memory(ibuf->mipmap[a]);
+ }
}
}
@@ -232,8 +236,9 @@ static size_t get_item_size(void *p)
size_t size = sizeof(MovieCacheItem);
MovieCacheItem *item = (MovieCacheItem *)p;
- if (item->ibuf)
+ if (item->ibuf) {
size += IMB_get_size_in_memory(item->ibuf);
+ }
return size;
}
@@ -285,8 +290,9 @@ void IMB_moviecache_init(void)
void IMB_moviecache_destruct(void)
{
- if (limitor)
+ if (limitor) {
delete_MEM_CacheLimiter(limitor);
+ }
}
MovieCache *IMB_moviecache_create(const char *name,
@@ -338,8 +344,9 @@ static void do_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf, boo
MovieCacheKey *key;
MovieCacheItem *item;
- if (!limitor)
+ if (!limitor) {
IMB_moviecache_init();
+ }
IMB_refImBuf(ibuf);
@@ -367,8 +374,9 @@ static void do_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf, boo
memcpy(cache->last_userkey, userkey, cache->keysize);
}
- if (need_lock)
+ if (need_lock) {
BLI_mutex_lock(&limitor_lock);
+ }
item->c_handle = MEM_CacheLimiter_insert(limitor, item);
@@ -376,8 +384,9 @@ static void do_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf, boo
MEM_CacheLimiter_enforce_limits(limitor);
MEM_CacheLimiter_unref(item->c_handle);
- if (need_lock)
+ if (need_lock) {
BLI_mutex_unlock(&limitor_lock);
+ }
/* cache limiter can't remove unused keys which points to destroyed values */
check_unused_keys(cache);
@@ -460,11 +469,13 @@ void IMB_moviecache_free(MovieCache *cache)
BLI_mempool_destroy(cache->items_pool);
BLI_mempool_destroy(cache->userkeys_pool);
- if (cache->points)
+ if (cache->points) {
MEM_freeN(cache->points);
+ }
- if (cache->last_userkey)
+ if (cache->last_userkey) {
MEM_freeN(cache->last_userkey);
+ }
MEM_freeN(cache);
}
@@ -500,12 +511,14 @@ void IMB_moviecache_get_cache_segments(
*totseg_r = 0;
*points_r = NULL;
- if (!cache->getdatafp)
+ if (!cache->getdatafp) {
return;
+ }
if (cache->proxy != proxy || cache->render_flags != render_flags) {
- if (cache->points)
+ if (cache->points) {
MEM_freeN(cache->points);
+ }
cache->points = NULL;
}
@@ -529,8 +542,9 @@ void IMB_moviecache_get_cache_segments(
if (item->ibuf) {
cache->getdatafp(key->userkey, &framenr, &curproxy, &curflags);
- if (curproxy == proxy && curflags == render_flags)
+ if (curproxy == proxy && curflags == render_flags) {
frames[a++] = framenr;
+ }
}
}
@@ -538,11 +552,13 @@ void IMB_moviecache_get_cache_segments(
/* count */
for (a = 0; a < totframe; a++) {
- if (a && frames[a] - frames[a - 1] != 1)
+ if (a && frames[a] - frames[a - 1] != 1) {
totseg++;
+ }
- if (a == totframe - 1)
+ if (a == totframe - 1) {
totseg++;
+ }
}
if (totseg) {
@@ -552,16 +568,18 @@ void IMB_moviecache_get_cache_segments(
/* fill */
for (a = 0, b = 0; a < totframe; a++) {
- if (a == 0)
+ if (a == 0) {
points[b++] = frames[a];
+ }
if (a && frames[a] - frames[a - 1] != 1) {
points[b++] = frames[a - 1];
points[b++] = frames[a];
}
- if (a == totframe - 1)
+ if (a == totframe - 1) {
points[b++] = frames[a];
+ }
}
*totseg_r = totseg;
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
index 5f6af67c60d..32079e4f290 100644
--- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp
+++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
@@ -29,7 +29,7 @@
// NOTE: Keep first, BLI_path_util conflicts with OIIO's format.
#include <memory>
-#include <openimageio_api.h>
+#include "openimageio_api.h"
#include <OpenImageIO/imageio.h>
extern "C" {
@@ -98,16 +98,18 @@ static ImBuf *imb_oiio_load_image(
std::cerr << __func__ << ": ImageInput::read_image() failed:" << std::endl
<< in->geterror() << std::endl;
- if (ibuf)
+ if (ibuf) {
IMB_freeImBuf(ibuf);
+ }
return NULL;
}
}
catch (const std::exception &exc) {
std::cerr << exc.what() << std::endl;
- if (ibuf)
+ if (ibuf) {
IMB_freeImBuf(ibuf);
+ }
return NULL;
}
@@ -136,16 +138,18 @@ static ImBuf *imb_oiio_load_image_float(
std::cerr << __func__ << ": ImageInput::read_image() failed:" << std::endl
<< in->geterror() << std::endl;
- if (ibuf)
+ if (ibuf) {
IMB_freeImBuf(ibuf);
+ }
return NULL;
}
}
catch (const std::exception &exc) {
std::cerr << exc.what() << std::endl;
- if (ibuf)
+ if (ibuf) {
IMB_freeImBuf(ibuf);
+ }
return NULL;
}
@@ -194,8 +198,9 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
char file_colorspace[IM_MAX_SPACE];
/* load image from file through OIIO */
- if (imb_is_a_photoshop(filename) == 0)
+ if (imb_is_a_photoshop(filename) == 0) {
return (NULL);
+ }
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -219,12 +224,14 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
BLI_strncpy(file_colorspace, ics.c_str(), IM_MAX_SPACE);
/* only use colorspaces exis */
- if (colormanage_colorspace_get_named(file_colorspace))
+ if (colormanage_colorspace_get_named(file_colorspace)) {
strcpy(colorspace, file_colorspace);
- else
+ }
+ else {
std::cerr << __func__ << ": The embed colorspace (\"" << file_colorspace
<< "\") not supported in existent OCIO configuration file. Fallback "
<< "to system default colorspace (\"" << colorspace << "\")." << std::endl;
+ }
width = spec.width;
height = spec.height;
@@ -241,17 +248,20 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
return NULL;
}
- if (is_float)
+ if (is_float) {
ibuf = imb_oiio_load_image_float(in.get(), width, height, components, flags, is_alpha);
- else
+ }
+ else {
ibuf = imb_oiio_load_image(in.get(), width, height, components, flags, is_alpha);
+ }
if (in) {
in->close();
}
- if (!ibuf)
+ if (!ibuf) {
return NULL;
+ }
/* ImBuf always needs 4 channels */
ibuf->ftype = IMB_FTYPE_PSD;
@@ -263,8 +273,9 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
}
catch (const std::exception &exc) {
std::cerr << exc.what() << std::endl;
- if (ibuf)
+ if (ibuf) {
IMB_freeImBuf(ibuf);
+ }
return NULL;
}
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index fb38e1e01c8..31649330e11 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -135,8 +135,9 @@ class IMemStream : public Imf::IStream {
_exrpos += n;
return true;
}
- else
+ else {
return false;
+ }
}
virtual Int64 tellg()
@@ -174,14 +175,16 @@ class IFileStream : public Imf::IStream {
ifs.open(filename, std::ios_base::binary);
#endif
- if (!ifs)
+ if (!ifs) {
Iex::throwErrnoExc();
+ }
}
virtual bool read(char c[], int n)
{
- if (!ifs)
+ if (!ifs) {
throw Iex::InputExc("Unexpected end of file.");
+ }
errno = 0;
ifs.read(c, n);
@@ -208,8 +211,9 @@ class IFileStream : public Imf::IStream {
bool check_error()
{
if (!ifs) {
- if (errno)
+ if (errno) {
Iex::throwErrnoExc();
+ }
return false;
}
@@ -277,8 +281,9 @@ class OFileStream : public OStream {
ofs.open(filename, std::ios_base::binary);
#endif
- if (!ofs)
+ if (!ofs) {
Iex::throwErrnoExc();
+ }
}
virtual void write(const char c[], int n)
@@ -303,8 +308,9 @@ class OFileStream : public OStream {
void check_error()
{
if (!ofs) {
- if (errno)
+ if (errno) {
Iex::throwErrnoExc();
+ }
throw Iex::ErrnoExc("File output failed.");
}
@@ -387,8 +393,9 @@ static void openexr_header_metadata(Header *header, struct ImBuf *ibuf)
}
}
- if (ibuf->ppm[0] > 0.0)
+ if (ibuf->ppm[0] > 0.0) {
addXDensity(*header, ibuf->ppm[0] / 39.3700787); /* 1 meter = 39.3700787 inches */
+ }
}
static void openexr_header_metadata_callback(void *data,
@@ -419,18 +426,23 @@ static bool imb_save_openexr_half(ImBuf *ibuf, const char *name, const int flags
header.channels().insert("R", Channel(HALF));
header.channels().insert("G", Channel(HALF));
header.channels().insert("B", Channel(HALF));
- if (is_alpha)
+ if (is_alpha) {
header.channels().insert("A", Channel(HALF));
- if (is_zbuf) // z we do as float always
+ }
+ if (is_zbuf) {
+ /* z we do as float always */
header.channels().insert("Z", Channel(Imf::FLOAT));
+ }
FrameBuffer frameBuffer;
/* manually create ofstream, so we can handle utf-8 filepaths on windows */
- if (flags & IB_mem)
+ if (flags & IB_mem) {
file_stream = new OMemStream(ibuf);
- else
+ }
+ else {
file_stream = new OFileStream(name);
+ }
OutputFile file(*file_stream, header);
/* we store first everything in half array */
@@ -521,18 +533,22 @@ static bool imb_save_openexr_float(ImBuf *ibuf, const char *name, const int flag
header.channels().insert("R", Channel(Imf::FLOAT));
header.channels().insert("G", Channel(Imf::FLOAT));
header.channels().insert("B", Channel(Imf::FLOAT));
- if (is_alpha)
+ if (is_alpha) {
header.channels().insert("A", Channel(Imf::FLOAT));
- if (is_zbuf)
+ }
+ if (is_zbuf) {
header.channels().insert("Z", Channel(Imf::FLOAT));
+ }
FrameBuffer frameBuffer;
/* manually create ofstream, so we can handle utf-8 filepaths on windows */
- if (flags & IB_mem)
+ if (flags & IB_mem) {
file_stream = new OMemStream(ibuf);
- else
+ }
+ else {
file_stream = new OFileStream(name);
+ }
OutputFile file(*file_stream, header);
int xstride = sizeof(float) * channels;
@@ -581,14 +597,17 @@ int imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags)
ibuf->encodedsize = 0;
}
- if (ibuf->foptions.flag & OPENEXR_HALF)
+ if (ibuf->foptions.flag & OPENEXR_HALF) {
return (int)imb_save_openexr_half(ibuf, name, flags);
+ }
else {
/* when no float rect, we save as half (16 bits is sufficient) */
- if (ibuf->rect_float == NULL)
+ if (ibuf->rect_float == NULL) {
return (int)imb_save_openexr_half(ibuf, name, flags);
- else
+ }
+ else {
return (int)imb_save_openexr_float(ibuf, name, flags);
+ }
}
}
@@ -700,10 +719,12 @@ static int imb_exr_get_multiView_id(StringVector &views, const std::string &name
{
int count = 0;
for (StringVector::const_iterator i = views.begin(); count < views.size(); ++i) {
- if (name == *i)
+ if (name == *i) {
return count;
- else
+ }
+ else {
count++;
+ }
}
/* no views or wrong name */
@@ -715,19 +736,22 @@ static void imb_exr_get_views(MultiPartInputFile &file, StringVector &views)
if (exr_has_multipart_file(file) == false) {
if (exr_has_multiview(file)) {
StringVector sv = multiView(file.header(0));
- for (StringVector::const_iterator i = sv.begin(); i != sv.end(); ++i)
+ for (StringVector::const_iterator i = sv.begin(); i != sv.end(); ++i) {
views.push_back(*i);
+ }
}
}
else {
for (int p = 0; p < file.parts(); p++) {
std::string view = "";
- if (file.header(p).hasView())
+ if (file.header(p).hasView()) {
view = file.header(p).view();
+ }
- if (imb_exr_get_multiView_id(views, view) == -1)
+ if (imb_exr_get_multiView_id(views, view) == -1) {
views.push_back(view);
+ }
}
}
}
@@ -845,11 +869,13 @@ int IMB_exr_begin_write(void *handle,
imb_exr_type_by_channels(
header.channels(), *data->multiView, &is_singlelayer, &is_multilayer, &is_multiview);
- if (is_multilayer)
+ if (is_multilayer) {
header.insert("BlenderMultiChannel", StringAttribute("Blender V2.55.1 and newer"));
+ }
- if (is_multiview)
+ if (is_multiview) {
addMultiView(header, *data->multiView);
+ }
/* avoid crash/abort when we don't have permission to write here */
/* manually create ofstream, so we can handle utf-8 filepaths on windows */
@@ -1033,8 +1059,9 @@ float *IMB_exr_channel_rect(void *handle,
BLI_snprintf(name, sizeof(name), "%s.%s", lay, pass);
}
- else
+ else {
BLI_strncpy(name, passname, EXR_TOT_MAXNAME - 1);
+ }
/* name has to be unique, thus it's a combination of layer, pass, view, and channel */
if (layname && layname[0] != '\0') {
@@ -1050,8 +1077,9 @@ float *IMB_exr_channel_rect(void *handle,
echan = (ExrChannel *)BLI_findstring(&data->channels, name, offsetof(ExrChannel, name));
- if (echan)
+ if (echan) {
return echan->rect;
+ }
return NULL;
}
@@ -1061,8 +1089,9 @@ void IMB_exr_clear_channels(void *handle)
ExrHandle *data = (ExrHandle *)handle;
ExrChannel *chan;
- for (chan = (ExrChannel *)data->channels.first; chan; chan = chan->next)
+ for (chan = (ExrChannel *)data->channels.first; chan; chan = chan->next) {
delete chan->m;
+ }
BLI_freelistN(&data->channels);
}
@@ -1147,8 +1176,9 @@ void IMB_exrtile_write_channels(
/* eventually we can make the parts' channels to include
* only the current view TODO */
- if (strcmp(viewname, echan->m->view.c_str()) != 0)
+ if (strcmp(viewname, echan->m->view.c_str()) != 0) {
continue;
+ }
exr_printf("%d %-6s %-22s \"%s\"\n",
echan->m->part_number,
@@ -1238,8 +1268,9 @@ void IMB_exr_read_channels(void *handle)
frameBuffer.insert(echan->m->internal_name,
Slice(Imf::FLOAT, (char *)rect, xstride, ystride));
}
- else
+ else {
printf("warning, channel with no rect set %s\n", echan->m->internal_name.c_str());
+ }
}
/* Read pixels. */
@@ -1331,9 +1362,11 @@ void IMB_exr_close(void *handle)
BLI_freelistN(&data->channels);
for (lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) {
- for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next)
- if (pass->rect)
+ for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) {
+ if (pass->rect) {
MEM_freeN(pass->rect);
+ }
+ }
BLI_freelistN(&lay->passes);
}
BLI_freelistN(&data->layers);
@@ -1372,12 +1405,15 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa
echan->chan_id = name[0];
layname[0] = '\0';
- if (ELEM(name[0], 'R', 'G', 'B', 'A'))
+ if (ELEM(name[0], 'R', 'G', 'B', 'A')) {
strcpy(passname, "Combined");
- else if (name[0] == 'Z')
+ }
+ else if (name[0] == 'Z') {
strcpy(passname, "Depth");
- else
+ }
+ else {
strcpy(passname, name);
+ }
return 1;
}
@@ -1448,10 +1484,12 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa
end -= len + 1; /* +1 to skip '.' separator */
/* all preceding tokens combined as layer name */
- if (end > name)
+ if (end > name) {
BLI_strncpy(layname, name, (int)(end - name) + 1);
- else
+ }
+ else {
layname[0] = '\0';
+ }
return 1;
}
@@ -1476,10 +1514,12 @@ static ExrPass *imb_exr_get_pass(ListBase *lb, char *passname)
if (pass == NULL) {
pass = (ExrPass *)MEM_callocN(sizeof(ExrPass), "exr pass");
- if (STREQ(passname, "Combined"))
+ if (STREQ(passname, "Combined")) {
BLI_addhead(lb, pass);
- else
+ }
+ else {
BLI_addtail(lb, pass);
+ }
}
BLI_strncpy(pass->name, passname, EXR_LAY_MAXNAME);
@@ -1547,8 +1587,9 @@ static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
BLI_strncpy(pass->view, view, sizeof(pass->view));
BLI_strncpy(pass->internal_name, internal_name, EXR_PASS_MAXNAME);
- if (pass->totchan >= EXR_PASS_MAXCHAN)
+ if (pass->totchan >= EXR_PASS_MAXCHAN) {
break;
+ }
}
}
if (echan) {
@@ -1652,8 +1693,9 @@ static void exr_print_filecontents(MultiPartInputFile &file)
else if (numparts > 1) {
printf("OpenEXR-load: MultiPart file\n");
for (int i = 0; i < numparts; i++) {
- if (file.header(i).hasView())
+ if (file.header(i).hasView()) {
printf("OpenEXR-load: Part %d: view = \"%s\"\n", i, file.header(i).view().c_str());
+ }
}
}
@@ -1723,8 +1765,9 @@ static bool imb_exr_is_multilayer_file(MultiPartInputFile &file)
/* will not include empty layer names */
channels.layers(layerNames);
- if (layerNames.size() > 1)
+ if (layerNames.size() > 1) {
return true;
+ }
if (layerNames.size()) {
/* if layerNames is not empty, it means at least one layer is non-empty,
@@ -1738,8 +1781,9 @@ static bool imb_exr_is_multilayer_file(MultiPartInputFile &file)
std::string layerName = i.name();
size_t pos = layerName.rfind('.');
- if (pos == std::string::npos)
+ if (pos == std::string::npos) {
return true;
+ }
}
}
@@ -1778,8 +1822,8 @@ static void imb_exr_type_by_channels(ChannelList &channels,
* that's what we do here: test whether there're empty layer names together
* with non-empty ones in the file
*/
- for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); i++)
- for (std::set<string>::iterator i = layerNames.begin(); i != layerNames.end(); i++)
+ for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); i++) {
+ for (std::set<string>::iterator i = layerNames.begin(); i != layerNames.end(); i++) {
/* see if any layername differs from a viewname */
if (imb_exr_get_multiView_id(views, *i) == -1) {
std::string layerName = *i;
@@ -1791,6 +1835,8 @@ static void imb_exr_type_by_channels(ChannelList &channels,
return;
}
}
+ }
+ }
}
else {
*r_singlelayer = true;
@@ -1821,14 +1867,17 @@ static bool imb_exr_is_multi(MultiPartInputFile &file)
{
/* Multipart files are treated as multilayer in blender -
* even if they are single layer openexr with multiview. */
- if (exr_has_multipart_file(file))
+ if (exr_has_multipart_file(file)) {
return true;
+ }
- if (exr_has_multiview(file))
+ if (exr_has_multiview(file)) {
return true;
+ }
- if (imb_exr_is_multilayer_file(file))
+ if (imb_exr_is_multilayer_file(file)) {
return true;
+ }
return false;
}
@@ -1848,8 +1897,9 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem,
IMemStream *membuf = NULL;
MultiPartInputFile *file = NULL;
- if (imb_is_a_openexr(mem) == 0)
+ if (imb_is_a_openexr(mem) == 0) {
return (NULL);
+ }
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
@@ -1866,8 +1916,9 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem,
//printf("OpenEXR-load: image data window %d %d %d %d\n",
// dw.min.x, dw.min.y, dw.max.x, dw.max.y);
- if (0) // debug
+ if (0) { // debug
exr_print_filecontents(*file);
+ }
is_multi = imb_exr_is_multi(*file);
@@ -1976,8 +2027,9 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem,
//
// Disabling this because the sequencer frees immediate.
//
- // if (flag & IM_rect)
+ // if (flag & IM_rect) {
// IMB_rect_from_float(ibuf);
+ // }
if (!has_rgb && has_luma) {
size_t a;
@@ -2011,15 +2063,17 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem,
delete file;
}
- if (flags & IB_alphamode_detect)
+ if (flags & IB_alphamode_detect) {
ibuf->flags |= IB_alphamode_premul;
+ }
}
return (ibuf);
}
catch (const std::exception &exc) {
std::cerr << exc.what() << std::endl;
- if (ibuf)
+ if (ibuf) {
IMB_freeImBuf(ibuf);
+ }
delete file;
delete membuf;
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index 3adc29222e3..68504f5c0dc 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -154,8 +154,9 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
}
/* for prints */
- if (flags & IB_mem)
+ if (flags & IB_mem) {
name = "<memory>";
+ }
bytesperpixel = (ibuf->planes + 7) >> 3;
if ((bytesperpixel > 4) || (bytesperpixel == 2)) {
@@ -184,10 +185,12 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
/* copy image data */
num_bytes = ((size_t)ibuf->x) * ibuf->y * bytesperpixel;
- if (is_16bit)
+ if (is_16bit) {
pixels16 = MEM_mallocN(num_bytes * sizeof(unsigned short), "png 16bit pixels");
- else
+ }
+ else {
pixels = MEM_mallocN(num_bytes * sizeof(unsigned char), "png 8bit pixels");
+ }
if (pixels == NULL && pixels16 == NULL) {
png_destroy_write_struct(&png_ptr, &info_ptr);
@@ -378,10 +381,12 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
fp = BLI_fopen(name, "wb");
if (!fp) {
png_destroy_write_struct(&png_ptr, &info_ptr);
- if (pixels)
+ if (pixels) {
MEM_freeN(pixels);
- if (pixels16)
+ }
+ if (pixels16) {
MEM_freeN(pixels16);
+ }
printf("imb_savepng: Cannot open file for writing: '%s'\n", name);
return 0;
}
@@ -457,10 +462,12 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
if (row_pointers == NULL) {
printf("imb_savepng: Cannot allocate row-pointers array for file '%s'\n", name);
png_destroy_write_struct(&png_ptr, &info_ptr);
- if (pixels)
+ if (pixels) {
MEM_freeN(pixels);
- if (pixels16)
+ }
+ if (pixels16) {
MEM_freeN(pixels16);
+ }
if (fp) {
fclose(fp);
}
@@ -489,10 +496,12 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
png_write_end(png_ptr, info_ptr);
/* clean up */
- if (pixels)
+ if (pixels) {
MEM_freeN(pixels);
- if (pixels16)
+ }
+ if (pixels16) {
MEM_freeN(pixels16);
+ }
MEM_freeN(row_pointers);
png_destroy_write_struct(&png_ptr, &info_ptr);
@@ -538,8 +547,9 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors
float *to_float;
unsigned int channels;
- if (imb_is_a_png(mem) == 0)
+ if (imb_is_a_png(mem) == 0) {
return (NULL);
+ }
/* both 8 and 16 bit PNGs are default to standard byte colorspace */
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -567,14 +577,18 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
- if (pixels)
+ if (pixels) {
MEM_freeN(pixels);
- if (pixels16)
+ }
+ if (pixels16) {
MEM_freeN(pixels16);
- if (row_pointers)
+ }
+ if (row_pointers) {
MEM_freeN(row_pointers);
- if (ibuf)
+ }
+ if (ibuf) {
IMB_freeImBuf(ibuf);
+ }
return NULL;
}
@@ -618,8 +632,9 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors
if (ibuf) {
ibuf->ftype = IMB_FTYPE_PNG;
- if (bit_depth == 16)
+ if (bit_depth == 16) {
ibuf->foptions.flag |= PNG_16BIT;
+ }
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pHYs)) {
int unit_type;
@@ -791,12 +806,15 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors
}
/* clean up */
- if (pixels)
+ if (pixels) {
MEM_freeN(pixels);
- if (pixels16)
+ }
+ if (pixels16) {
MEM_freeN(pixels16);
- if (row_pointers)
+ }
+ if (row_pointers) {
MEM_freeN(row_pointers);
+ }
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
return (ibuf);
diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c
index 238f58b7834..d44ce1ac269 100644
--- a/source/blender/imbuf/intern/radiance_hdr.c
+++ b/source/blender/imbuf/intern/radiance_hdr.c
@@ -180,10 +180,12 @@ static void FLOAT2RGBE(fCOLOR fcol, RGBE rgbe)
{
int e;
float d = (fcol[RED] > fcol[GRN]) ? fcol[RED] : fcol[GRN];
- if (fcol[BLU] > d)
+ if (fcol[BLU] > d) {
d = fcol[BLU];
- if (d <= 1e-32f)
+ }
+ if (d <= 1e-32f) {
rgbe[RED] = rgbe[GRN] = rgbe[BLU] = rgbe[EXP] = 0;
+ }
else {
d = (float)frexp(d, &e) * 256.0f / d;
rgbe[RED] = (unsigned char)(fcol[RED] * d);
@@ -201,8 +203,9 @@ int imb_is_a_hdr(const unsigned char *buf)
/* update: actually, the 'RADIANCE' part is just an optional program name,
* the magic word is really only the '#?' part */
//if (strstr((char *)buf, "#?RADIANCE")) return 1;
- if (strstr((char *)buf, "#?"))
+ if (strstr((char *)buf, "#?")) {
return 1;
+ }
// if (strstr((char *)buf, "32-bit_rle_rgbe")) return 1;
return 0;
}
@@ -246,18 +249,21 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
ptr = (unsigned char *)strchr((char *)&mem[x + 1], '\n');
ptr++;
- if (flags & IB_test)
+ if (flags & IB_test) {
ibuf = IMB_allocImBuf(width, height, 32, 0);
- else
+ }
+ else {
ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect) | IB_rectfloat);
+ }
if (UNLIKELY(ibuf == NULL)) {
return NULL;
}
ibuf->ftype = IMB_FTYPE_RADHDR;
- if (flags & IB_alphamode_detect)
+ if (flags & IB_alphamode_detect) {
ibuf->flags |= IB_alphamode_premul;
+ }
if (flags & IB_test) {
return ibuf;
@@ -284,8 +290,9 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
}
}
MEM_freeN(sline);
- if (oriY[0] == '-')
+ if (oriY[0] == '-') {
IMB_flipy(ibuf);
+ }
if (flags & IB_rect) {
IMB_rect_from_float(ibuf);
@@ -346,10 +353,12 @@ static int fwritecolrs(FILE *file, int width, int channels, unsigned char *ibufs
for (beg = j; beg < width; beg += cnt) {
for (cnt = 1; (cnt < 127) && ((beg + cnt) < width) &&
(rgbe_scan[beg + cnt][i] == rgbe_scan[beg][i]);
- cnt++)
+ cnt++) {
;
- if (cnt >= MINRUN)
+ }
+ if (cnt >= MINRUN) {
break; /* long enough */
+ }
}
if (((beg - j) > 1) && ((beg - j) < MINRUN)) {
c2 = j + 1;
@@ -363,11 +372,13 @@ static int fwritecolrs(FILE *file, int width, int channels, unsigned char *ibufs
}
}
while (j < beg) { /* write out non-run */
- if ((c2 = beg - j) > 128)
+ if ((c2 = beg - j) > 128) {
c2 = 128;
+ }
putc((unsigned char)(c2), file);
- while (c2--)
+ while (c2--) {
putc(rgbe_scan[j++][i], file);
+ }
}
if (cnt >= MINRUN) { /* write out run */
putc((unsigned char)(128 + cnt), file);
@@ -412,10 +423,12 @@ int imb_savehdr(struct ImBuf *ibuf, const char *name, int flags)
writeHeader(file, width, height);
- if (ibuf->rect)
+ if (ibuf->rect) {
cp = (unsigned char *)ibuf->rect + ibuf->channels * (height - 1) * width;
- if (ibuf->rect_float)
+ }
+ if (ibuf->rect_float) {
fp = ibuf->rect_float + ibuf->channels * (height - 1) * width;
+ }
for (size_t y = 0; y < height; y++) {
if (fwritecolrs(file, width, ibuf->channels, cp, fp) < 0) {
@@ -423,10 +436,12 @@ int imb_savehdr(struct ImBuf *ibuf, const char *name, int flags)
printf("HDR write error\n");
return 0;
}
- if (cp)
+ if (cp) {
cp -= ibuf->channels * width;
- if (fp)
+ }
+ if (fp) {
fp -= ibuf->channels * width;
+ }
}
fclose(file);
diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c
index 34bae007979..e1df5c63093 100644
--- a/source/blender/imbuf/intern/readimage.c
+++ b/source/blender/imbuf/intern/readimage.c
@@ -62,10 +62,12 @@ static void imb_handle_alpha(ImBuf *ibuf,
BLI_strncpy(colorspace, effective_colorspace, IM_MAX_SPACE);
}
- if (flags & IB_alphamode_detect)
+ if (flags & IB_alphamode_detect) {
alpha_flags = ibuf->flags & IB_alphamode_premul;
- else
+ }
+ else {
alpha_flags = flags & IB_alphamode_premul;
+ }
if (flags & IB_ignore_alpha) {
IMB_rectfill_alpha(ibuf, 1.0f);
@@ -109,8 +111,9 @@ ImBuf *IMB_ibImageFromMemory(const unsigned char *mem,
return NULL;
}
- if (colorspace)
+ if (colorspace) {
BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace));
+ }
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->load) {
@@ -122,8 +125,9 @@ ImBuf *IMB_ibImageFromMemory(const unsigned char *mem,
}
}
- if ((flags & IB_test) == 0)
+ if ((flags & IB_test) == 0) {
fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr);
+ }
return NULL;
}
@@ -137,8 +141,9 @@ static ImBuf *IMB_ibImageFromFile(const char *filepath,
const ImFileType *type;
char effective_colorspace[IM_MAX_SPACE] = "";
- if (colorspace)
+ if (colorspace) {
BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace));
+ }
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->load_filepath) {
@@ -150,8 +155,9 @@ static ImBuf *IMB_ibImageFromFile(const char *filepath,
}
}
- if ((flags & IB_test) == 0)
+ if ((flags & IB_test) == 0) {
fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr);
+ }
return NULL;
}
@@ -169,11 +175,13 @@ ImBuf *IMB_loadifffile(
unsigned char *mem;
size_t size;
- if (file == -1)
+ if (file == -1) {
return NULL;
+ }
- if (imb_is_filepath_format(filepath))
+ if (imb_is_filepath_format(filepath)) {
return IMB_ibImageFromFile(filepath, flags, colorspace, descr);
+ }
size = BLI_file_descriptor_size(file);
@@ -189,8 +197,9 @@ ImBuf *IMB_loadifffile(
ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr);
imb_mmap_lock();
- if (munmap(mem, size))
+ if (munmap(mem, size)) {
fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr);
+ }
imb_mmap_unlock();
return ibuf;
@@ -201,11 +210,13 @@ static void imb_cache_filename(char *filename, const char *name, int flags)
/* read .tx instead if it exists and is not older */
if (flags & IB_tilecache) {
BLI_strncpy(filename, name, IMB_FILENAME_SIZE);
- if (!BLI_path_extension_replace(filename, IMB_FILENAME_SIZE, ".tx"))
+ if (!BLI_path_extension_replace(filename, IMB_FILENAME_SIZE, ".tx")) {
return;
+ }
- if (BLI_file_older(name, filename))
+ if (BLI_file_older(name, filename)) {
return;
+ }
}
BLI_strncpy(filename, name, IMB_FILENAME_SIZE);
@@ -222,16 +233,18 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_S
imb_cache_filename(filepath_tx, filepath, flags);
file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0);
- if (file == -1)
+ if (file == -1) {
return NULL;
+ }
ibuf = IMB_loadifffile(file, filepath, flags, colorspace, filepath_tx);
if (ibuf) {
BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name));
BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename));
- for (a = 1; a < ibuf->miptot; a++)
+ for (a = 1; a < ibuf->miptot; a++) {
BLI_strncpy(ibuf->mipmap[a - 1]->cachename, filepath_tx, sizeof(ibuf->cachename));
+ }
}
close(file);
@@ -251,8 +264,9 @@ ImBuf *IMB_testiffname(const char *filepath, int flags)
imb_cache_filename(filepath_tx, filepath, flags);
file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0);
- if (file == -1)
+ if (file == -1) {
return NULL;
+ }
ibuf = IMB_loadifffile(file, filepath, flags | IB_test | IB_multilayer, colorspace, filepath_tx);
@@ -272,8 +286,9 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int
unsigned char *mem;
size_t size;
- if (file == -1)
+ if (file == -1) {
return;
+ }
size = BLI_file_descriptor_size(file);
@@ -286,13 +301,16 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int
return;
}
- for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++)
- if (type->load_tile && type->ftype(type, ibuf))
+ for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
+ if (type->load_tile && type->ftype(type, ibuf)) {
type->load_tile(ibuf, mem, size, tx, ty, rect);
+ }
+ }
imb_mmap_lock();
- if (munmap(mem, size))
+ if (munmap(mem, size)) {
fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename);
+ }
imb_mmap_unlock();
}
@@ -301,8 +319,9 @@ void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect)
int file;
file = BLI_open(ibuf->cachename, O_BINARY | O_RDONLY, 0);
- if (file == -1)
+ if (file == -1) {
return;
+ }
imb_loadtilefile(ibuf, file, tx, ty, rect);
diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c
index a069e79b337..25390b73737 100644
--- a/source/blender/imbuf/intern/rectop.c
+++ b/source/blender/imbuf/intern/rectop.c
@@ -220,8 +220,9 @@ void IMB_rectclip(ImBuf *dbuf,
{
int tmp;
- if (dbuf == NULL)
+ if (dbuf == NULL) {
return;
+ }
if (*destx < 0) {
*srcx -= *destx;
@@ -245,19 +246,23 @@ void IMB_rectclip(ImBuf *dbuf,
}
tmp = dbuf->x - *destx;
- if (*width > tmp)
+ if (*width > tmp) {
*width = tmp;
+ }
tmp = dbuf->y - *desty;
- if (*height > tmp)
+ if (*height > tmp) {
*height = tmp;
+ }
if (sbuf) {
tmp = sbuf->x - *srcx;
- if (*width > tmp)
+ if (*width > tmp) {
*width = tmp;
+ }
tmp = sbuf->y - *srcy;
- if (*height > tmp)
+ if (*height > tmp) {
*height = tmp;
+ }
}
if ((*height <= 0) || (*width <= 0)) {
@@ -280,8 +285,9 @@ static void imb_rectclip3(ImBuf *dbuf,
{
int tmp;
- if (dbuf == NULL)
+ if (dbuf == NULL) {
return;
+ }
if (*destx < 0) {
*srcx -= *destx;
@@ -322,28 +328,34 @@ static void imb_rectclip3(ImBuf *dbuf,
}
tmp = dbuf->x - *destx;
- if (*width > tmp)
+ if (*width > tmp) {
*width = tmp;
+ }
tmp = dbuf->y - *desty;
- if (*height > tmp)
+ if (*height > tmp) {
*height = tmp;
+ }
if (obuf) {
tmp = obuf->x - *origx;
- if (*width > tmp)
+ if (*width > tmp) {
*width = tmp;
+ }
tmp = obuf->y - *origy;
- if (*height > tmp)
+ if (*height > tmp) {
*height = tmp;
+ }
}
if (sbuf) {
tmp = sbuf->x - *srcx;
- if (*width > tmp)
+ if (*width > tmp) {
*width = tmp;
+ }
tmp = sbuf->y - *srcy;
- if (*height > tmp)
+ if (*height > tmp) {
*height = tmp;
+ }
}
if ((*height <= 0) || (*width <= 0)) {
@@ -408,17 +420,21 @@ void IMB_rectblend(ImBuf *dbuf,
IMB_blend_func func = NULL;
IMB_blend_func_float func_float = NULL;
- if (dbuf == NULL || obuf == NULL)
+ if (dbuf == NULL || obuf == NULL) {
return;
+ }
imb_rectclip3(dbuf, obuf, sbuf, &destx, &desty, &origx, &origy, &srcx, &srcy, &width, &height);
- if (width == 0 || height == 0)
+ if (width == 0 || height == 0) {
return;
- if (sbuf && sbuf->channels != 4)
+ }
+ if (sbuf && sbuf->channels != 4) {
return;
- if (dbuf->channels != 4)
+ }
+ if (dbuf->channels != 4) {
return;
+ }
do_char = (sbuf && sbuf->rect && dbuf->rect && obuf->rect);
do_float = (sbuf && sbuf->rect_float && dbuf->rect_float && obuf->rect_float);
@@ -432,24 +448,29 @@ void IMB_rectblend(ImBuf *dbuf,
orectf = obuf->rect_float + (((size_t)origy) * obuf->x + origx) * 4;
}
- if (dmaskrect)
+ if (dmaskrect) {
dmaskrect += ((size_t)origy) * obuf->x + origx;
+ }
destskip = dbuf->x;
origskip = obuf->x;
if (sbuf) {
- if (do_char)
+ if (do_char) {
srect = sbuf->rect + ((size_t)srcy) * sbuf->x + srcx;
- if (do_float)
+ }
+ if (do_float) {
srectf = sbuf->rect_float + (((size_t)srcy) * sbuf->x + srcx) * 4;
+ }
srcskip = sbuf->x;
- if (cmaskrect)
+ if (cmaskrect) {
cmaskrect += ((size_t)srcy) * sbuf->x + srcx;
+ }
- if (texmaskrect)
+ if (texmaskrect) {
texmaskrect += ((size_t)srcy) * sbuf->x + srcx;
+ }
}
else {
srect = drect;
@@ -509,8 +530,9 @@ void IMB_rectblend(ImBuf *dbuf,
if (do_char) {
dr = drect;
sr = srect;
- for (x = width; x > 0; x--, dr++, sr++)
+ for (x = width; x > 0; x--, dr++, sr++) {
((char *)dr)[3] = ((char *)sr)[3];
+ }
drect += destskip;
srect += srcskip;
}
@@ -518,8 +540,9 @@ void IMB_rectblend(ImBuf *dbuf,
if (do_float) {
drf = drectf;
srf = srectf;
- for (x = width; x > 0; x--, drf += 4, srf += 4)
+ for (x = width; x > 0; x--, drf += 4, srf += 4) {
drf[3] = srf[3];
+ }
drectf += destskip * 4;
srectf += srcskip * 4;
}
@@ -647,16 +670,19 @@ void IMB_rectblend(ImBuf *dbuf,
unsigned char *src = (unsigned char *)sr;
float mask_lim = mask_max * (*cmr);
- if (texmaskrect)
+ if (texmaskrect) {
mask_lim *= ((*tmr++) / 65535.0f);
+ }
if (src[3] && mask_lim) {
float mask;
- if (accumulate)
+ if (accumulate) {
mask = *dmr + mask_lim;
- else
+ }
+ else {
mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
+ }
mask = min_ff(mask, 65535.0);
@@ -689,8 +715,9 @@ void IMB_rectblend(ImBuf *dbuf,
unsigned char *src = (unsigned char *)sr;
float mask = (float)mask_max * ((float)(*cmr));
- if (texmaskrect)
+ if (texmaskrect) {
mask *= ((float)(*tmr++) / 65535.0f);
+ }
mask = min_ff(mask, 65535.0);
@@ -715,14 +742,16 @@ void IMB_rectblend(ImBuf *dbuf,
}
cmaskrect += srcskip;
- if (texmaskrect)
+ if (texmaskrect) {
texmaskrect += srcskip;
+ }
}
else {
/* regular blending */
for (x = width; x > 0; x--, dr++, or ++, sr++) {
- if (((unsigned char *)sr)[3])
+ if (((unsigned char *)sr)[3]) {
func((unsigned char *)dr, (unsigned char *) or, (unsigned char *)sr);
+ }
}
}
@@ -747,16 +776,19 @@ void IMB_rectblend(ImBuf *dbuf,
for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4, dmr++, cmr++) {
float mask_lim = mask_max * (*cmr);
- if (texmaskrect)
+ if (texmaskrect) {
mask_lim *= ((*tmr++) / 65535.0f);
+ }
if (srf[3] && mask_lim) {
float mask;
- if (accumulate)
+ if (accumulate) {
mask = min_ff(*dmr + mask_lim, 65535.0);
- else
+ }
+ else {
mask = *dmr + mask_lim - (*dmr * (*cmr / 65535.0f));
+ }
mask = min_ff(mask, 65535.0);
@@ -781,8 +813,9 @@ void IMB_rectblend(ImBuf *dbuf,
for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4, cmr++) {
float mask = (float)mask_max * ((float)(*cmr));
- if (texmaskrect)
+ if (texmaskrect) {
mask *= ((float)(*tmr++) / 65535.0f);
+ }
mask = min_ff(mask, 65535.0);
@@ -800,14 +833,16 @@ void IMB_rectblend(ImBuf *dbuf,
}
cmaskrect += srcskip;
- if (texmaskrect)
+ if (texmaskrect) {
texmaskrect += srcskip;
+ }
}
else {
/* regular blending */
for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4) {
- if (srf[3] != 0)
+ if (srf[3] != 0) {
func_float(drf, orf, srf);
+ }
}
}
@@ -926,8 +961,9 @@ void IMB_rectfill(ImBuf *drect, const float col[4])
ccol[3] = (int)(col[3] * 255);
num = drect->x * drect->y;
- for (; num > 0; num--)
+ for (; num > 0; num--) {
*rrect++ = *((unsigned int *)ccol);
+ }
}
if (drect->rect_float) {
@@ -958,8 +994,9 @@ void buf_rectfill_area(unsigned char *rect,
float a; /* alpha */
float ai; /* alpha inverted */
float aich; /* alpha, inverted, ai/255.0 - Convert char to float at the same time */
- if ((!rect && !rectf) || (!col) || col[3] == 0.0f)
+ if ((!rect && !rectf) || (!col) || col[3] == 0.0f) {
return;
+ }
/* sanity checks for coords */
CLAMP(x1, 0, width);
@@ -967,12 +1004,15 @@ void buf_rectfill_area(unsigned char *rect,
CLAMP(y1, 0, height);
CLAMP(y2, 0, height);
- if (x1 > x2)
+ if (x1 > x2) {
SWAP(int, x1, x2);
- if (y1 > y2)
+ }
+ if (y1 > y2) {
SWAP(int, y1, y2);
- if (x1 == x2 || y1 == y2)
+ }
+ if (x1 == x2 || y1 == y2) {
return;
+ }
a = col[3];
ai = 1 - a;
@@ -1058,8 +1098,9 @@ void IMB_rectfill_area(ImBuf *ibuf,
int y2,
struct ColorManagedDisplay *display)
{
- if (!ibuf)
+ if (!ibuf) {
return;
+ }
buf_rectfill_area((unsigned char *)ibuf->rect,
ibuf->rect_float,
ibuf->x,
diff --git a/source/blender/imbuf/intern/rotate.c b/source/blender/imbuf/intern/rotate.c
index 2b200abc852..e387901aaab 100644
--- a/source/blender/imbuf/intern/rotate.c
+++ b/source/blender/imbuf/intern/rotate.c
@@ -34,8 +34,9 @@ void IMB_flipy(struct ImBuf *ibuf)
{
int x, y;
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return;
+ }
if (ibuf->rect) {
unsigned int *top, *bottom, *line;
@@ -89,8 +90,9 @@ void IMB_flipx(struct ImBuf *ibuf)
int x, y, xr, xl, yi;
float px_f[4];
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return;
+ }
x = ibuf->x;
y = ibuf->y;
diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c
index 14b2ded73e0..28557277d72 100644
--- a/source/blender/imbuf/intern/scaling.c
+++ b/source/blender/imbuf/intern/scaling.c
@@ -85,10 +85,12 @@ static void imb_half_x_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
*(destf++) = 0.5f * rf;
}
}
- if (do_rect)
+ if (do_rect) {
_p1 += (ibuf1->x << 2);
- if (do_float)
+ }
+ if (do_float) {
_p1f += (ibuf1->x << 2);
+ }
}
}
@@ -96,17 +98,21 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
- if (ibuf1 == NULL)
+ if (ibuf1 == NULL) {
return (NULL);
- if (ibuf1->rect == NULL && ibuf1->rect_float == NULL)
+ }
+ if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return (NULL);
+ }
- if (ibuf1->x <= 1)
+ if (ibuf1->x <= 1) {
return (IMB_dupImBuf(ibuf1));
+ }
ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, ibuf1->y, ibuf1->planes, ibuf1->flags);
- if (ibuf2 == NULL)
+ if (ibuf2 == NULL) {
return (NULL);
+ }
imb_half_x_no_alloc(ibuf2, ibuf1);
@@ -119,17 +125,20 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1)
int *p1, *dest, i, col, do_rect, do_float;
float *p1f, *destf;
- if (ibuf1 == NULL)
+ if (ibuf1 == NULL) {
return (NULL);
- if (ibuf1->rect == NULL && ibuf1->rect_float == NULL)
+ }
+ if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return (NULL);
+ }
do_rect = (ibuf1->rect != NULL);
do_float = (ibuf1->rect_float != NULL);
ibuf2 = IMB_allocImBuf(2 * ibuf1->x, ibuf1->y, ibuf1->planes, ibuf1->flags);
- if (ibuf2 == NULL)
+ if (ibuf2 == NULL) {
return (NULL);
+ }
p1 = (int *)ibuf1->rect;
dest = (int *)ibuf2->rect;
@@ -159,10 +168,12 @@ struct ImBuf *IMB_double_x(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
- if (ibuf1 == NULL)
+ if (ibuf1 == NULL) {
return (NULL);
- if (ibuf1->rect == NULL && ibuf1->rect_float == NULL)
+ }
+ if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return (NULL);
+ }
ibuf2 = IMB_double_fast_x(ibuf1);
@@ -228,10 +239,12 @@ static void imb_half_y_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
*(destf++) = 0.5f * rf;
}
}
- if (do_rect)
+ if (do_rect) {
_p1 += (ibuf1->x << 3);
- if (do_float)
+ }
+ if (do_float) {
_p1f += (ibuf1->x << 3);
+ }
}
}
@@ -239,17 +252,21 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
- if (ibuf1 == NULL)
+ if (ibuf1 == NULL) {
return (NULL);
- if (ibuf1->rect == NULL && ibuf1->rect_float == NULL)
+ }
+ if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return (NULL);
+ }
- if (ibuf1->y <= 1)
+ if (ibuf1->y <= 1) {
return (IMB_dupImBuf(ibuf1));
+ }
ibuf2 = IMB_allocImBuf(ibuf1->x, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
- if (ibuf2 == NULL)
+ if (ibuf2 == NULL) {
return (NULL);
+ }
imb_half_y_no_alloc(ibuf2, ibuf1);
@@ -264,17 +281,20 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1)
int x, y;
int do_rect, do_float;
- if (ibuf1 == NULL)
+ if (ibuf1 == NULL) {
return (NULL);
- if (ibuf1->rect == NULL && ibuf1->rect_float == NULL)
+ }
+ if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return (NULL);
+ }
do_rect = (ibuf1->rect != NULL);
do_float = (ibuf1->rect_float != NULL);
ibuf2 = IMB_allocImBuf(ibuf1->x, 2 * ibuf1->y, ibuf1->planes, ibuf1->flags);
- if (ibuf2 == NULL)
+ if (ibuf2 == NULL) {
return (NULL);
+ }
p1 = (int *)ibuf1->rect;
dest1 = (int *)ibuf2->rect;
@@ -284,14 +304,16 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1)
for (y = ibuf1->y; y > 0; y--) {
if (do_rect) {
dest2 = dest1 + ibuf2->x;
- for (x = ibuf2->x; x > 0; x--)
+ for (x = ibuf2->x; x > 0; x--) {
*dest1++ = *dest2++ = *p1++;
+ }
dest1 = dest2;
}
if (do_float) {
dest2f = dest1f + (4 * ibuf2->x);
- for (x = ibuf2->x * 4; x > 0; x--)
+ for (x = ibuf2->x * 4; x > 0; x--) {
*dest1f++ = *dest2f++ = *p1f++;
+ }
dest1f = dest2f;
}
}
@@ -303,10 +325,12 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
- if (ibuf1 == NULL)
+ if (ibuf1 == NULL) {
return (NULL);
- if (ibuf1->rect == NULL)
+ }
+ if (ibuf1->rect == NULL) {
return (NULL);
+ }
ibuf2 = IMB_double_fast_y(ibuf1);
@@ -394,8 +418,9 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
dest += 4;
}
cp1 = cp2;
- if (ibuf1->x & 1)
+ if (ibuf1->x & 1) {
cp1 += 4;
+ }
}
}
@@ -416,8 +441,9 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
destf += 4;
}
p1f = p2f;
- if (ibuf1->x & 1)
+ if (ibuf1->x & 1) {
p1f += 4;
+ }
}
}
}
@@ -426,19 +452,24 @@ ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
- if (ibuf1 == NULL)
+ if (ibuf1 == NULL) {
return (NULL);
- if (ibuf1->rect == NULL && ibuf1->rect_float == NULL)
+ }
+ if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return (NULL);
+ }
- if (ibuf1->x <= 1)
+ if (ibuf1->x <= 1) {
return (IMB_half_y(ibuf1));
- if (ibuf1->y <= 1)
+ }
+ if (ibuf1->y <= 1) {
return (IMB_half_x(ibuf1));
+ }
ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
- if (ibuf2 == NULL)
+ if (ibuf2 == NULL) {
return (NULL);
+ }
imb_onehalf_no_alloc(ibuf2, ibuf1);
@@ -891,19 +922,22 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
nval[0] = nval[1] = nval[2] = nval[3] = 0.0f;
nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f;
- if (!do_rect && !do_float)
+ if (!do_rect && !do_float) {
return (ibuf);
+ }
if (do_rect) {
_newrect = MEM_mallocN(newx * ibuf->y * sizeof(uchar) * 4, "scaledownx");
- if (_newrect == NULL)
+ if (_newrect == NULL) {
return (ibuf);
+ }
}
if (do_float) {
_newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaledownxf");
if (_newrectf == NULL) {
- if (_newrect)
+ if (_newrect) {
MEM_freeN(_newrect);
+ }
return (ibuf);
}
}
@@ -1029,19 +1063,22 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
nval[0] = nval[1] = nval[2] = nval[3] = 0.0f;
nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f;
- if (!do_rect && !do_float)
+ if (!do_rect && !do_float) {
return (ibuf);
+ }
if (do_rect) {
_newrect = MEM_mallocN(newy * ibuf->x * sizeof(uchar) * 4, "scaledowny");
- if (_newrect == NULL)
+ if (_newrect == NULL) {
return (ibuf);
+ }
}
if (do_float) {
_newrectf = MEM_mallocN(newy * ibuf->x * sizeof(float) * 4, "scaledownyf");
if (_newrectf == NULL) {
- if (_newrect)
+ if (_newrect) {
MEM_freeN(_newrect);
+ }
return (ibuf);
}
}
@@ -1172,23 +1209,27 @@ static ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
val_g = nval_g = diff_g = val_r = nval_r = diff_r = 0;
val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0;
val_gf = nval_gf = diff_gf = val_rf = nval_rf = diff_rf = 0;
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return (NULL);
- if (ibuf->rect == NULL && ibuf->rect_float == NULL)
+ }
+ if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
return (ibuf);
+ }
if (ibuf->rect) {
do_rect = true;
_newrect = MEM_mallocN(newx * ibuf->y * sizeof(int), "scaleupx");
- if (_newrect == NULL)
+ if (_newrect == NULL) {
return (ibuf);
+ }
}
if (ibuf->rect_float) {
do_float = true;
_newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaleupxf");
if (_newrectf == NULL) {
- if (_newrect)
+ if (_newrect) {
MEM_freeN(_newrect);
+ }
return (ibuf);
}
}
@@ -1344,23 +1385,27 @@ static ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
val_g = nval_g = diff_g = val_r = nval_r = diff_r = 0;
val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0;
val_gf = nval_gf = diff_gf = val_rf = nval_rf = diff_rf = 0;
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return (NULL);
- if (ibuf->rect == NULL && ibuf->rect_float == NULL)
+ }
+ if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
return (ibuf);
+ }
if (ibuf->rect) {
do_rect = true;
_newrect = MEM_mallocN(ibuf->x * newy * sizeof(int), "scaleupy");
- if (_newrect == NULL)
+ if (_newrect == NULL) {
return (ibuf);
+ }
}
if (ibuf->rect_float) {
do_float = true;
_newrectf = MEM_mallocN(ibuf->x * newy * sizeof(float) * 4, "scaleupyf");
if (_newrectf == NULL) {
- if (_newrect)
+ if (_newrect) {
MEM_freeN(_newrect);
+ }
return (ibuf);
}
}
@@ -1573,10 +1618,12 @@ static void scalefast_Z_ImBuf(ImBuf *ibuf, int newx, int newy)
*/
bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
{
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return false;
- if (ibuf->rect == NULL && ibuf->rect_float == NULL)
+ }
+ if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
return false;
+ }
if (newx == ibuf->x && newy == ibuf->y) {
return false;
@@ -1592,14 +1639,18 @@ bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
return true;
}
- if (newx && (newx < ibuf->x))
+ if (newx && (newx < ibuf->x)) {
scaledownx(ibuf, newx);
- if (newy && (newy < ibuf->y))
+ }
+ if (newy && (newy < ibuf->y)) {
scaledowny(ibuf, newy);
- if (newx && (newx > ibuf->x))
+ }
+ if (newx && (newx > ibuf->x)) {
scaleupx(ibuf, newx);
- if (newy && (newy > ibuf->y))
+ }
+ if (newy && (newy > ibuf->y)) {
scaleupy(ibuf, newy);
+ }
return true;
}
@@ -1626,30 +1677,37 @@ bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy
_newrectf = NULL;
newrectf = NULL;
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return false;
- if (ibuf->rect)
+ }
+ if (ibuf->rect) {
do_rect = true;
- if (ibuf->rect_float)
+ }
+ if (ibuf->rect_float) {
do_float = true;
- if (do_rect == false && do_float == false)
+ }
+ if (do_rect == false && do_float == false) {
return false;
+ }
- if (newx == ibuf->x && newy == ibuf->y)
+ if (newx == ibuf->x && newy == ibuf->y) {
return false;
+ }
if (do_rect) {
_newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf");
- if (_newrect == NULL)
+ if (_newrect == NULL) {
return false;
+ }
newrect = _newrect;
}
if (do_float) {
_newrectf = MEM_mallocN(newx * newy * sizeof(float) * 4, "scalefastimbuf f");
if (_newrectf == NULL) {
- if (_newrect)
+ if (_newrect) {
MEM_freeN(_newrect);
+ }
return false;
}
newrectf = _newrectf;
@@ -1786,13 +1844,15 @@ void IMB_scaleImBuf_threaded(ImBuf *ibuf, unsigned int newx, unsigned int newy)
init_data.newx = newx;
init_data.newy = newy;
- if (ibuf->rect)
+ if (ibuf->rect) {
init_data.byte_buffer = MEM_mallocN(4 * newx * newy * sizeof(char),
"threaded scale byte buffer");
+ }
- if (ibuf->rect_float)
+ if (ibuf->rect_float) {
init_data.float_buffer = MEM_mallocN(ibuf->channels * newx * newy * sizeof(float),
"threaded scale float buffer");
+ }
/* actual scaling threads */
IMB_processor_apply_threaded(
diff --git a/source/blender/imbuf/intern/stereoimbuf.c b/source/blender/imbuf/intern/stereoimbuf.c
index 30356fd4e4e..44c311eba9d 100644
--- a/source/blender/imbuf/intern/stereoimbuf.c
+++ b/source/blender/imbuf/intern/stereoimbuf.c
@@ -573,11 +573,13 @@ static void imb_stereo3d_squeeze_ImBuf(ImBuf *ibuf,
const size_t x,
const size_t y)
{
- if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false)
+ if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false) {
return;
+ }
- if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0)
+ if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0) {
return;
+ }
IMB_scaleImBuf_threaded(ibuf, x, y);
}
@@ -587,11 +589,13 @@ static void imb_stereo3d_unsqueeze_ImBuf(ImBuf *ibuf,
const size_t x,
const size_t y)
{
- if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false)
+ if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false) {
return;
+ }
- if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0)
+ if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0) {
return;
+ }
IMB_scaleImBuf_threaded(ibuf, x, y);
}
@@ -602,11 +606,13 @@ static void imb_stereo3d_squeeze_rectf(
ImBuf *ibuf;
size_t width, height;
- if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false)
+ if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false) {
return;
+ }
- if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0)
+ if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0) {
return;
+ }
/* creates temporary imbuf to store the rectf */
IMB_stereo3d_write_dimensions(s3d->display_mode, false, x, y, &width, &height);
@@ -634,11 +640,13 @@ static void imb_stereo3d_squeeze_rect(
ImBuf *ibuf;
size_t width, height;
- if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false)
+ if (ELEM(s3d->display_mode, S3D_DISPLAY_SIDEBYSIDE, S3D_DISPLAY_TOPBOTTOM) == false) {
return;
+ }
- if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0)
+ if ((s3d->flag & S3D_SQUEEZED_FRAME) == 0) {
return;
+ }
/* creates temporary imbuf to store the rectf */
IMB_stereo3d_write_dimensions(s3d->display_mode, false, x, y, &width, &height);
diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c
index c80e3a0c07d..f7b7df52e46 100644
--- a/source/blender/imbuf/intern/targa.c
+++ b/source/blender/imbuf/intern/targa.c
@@ -67,8 +67,9 @@ static int tga_out1(unsigned int data, FILE *file)
uchar *p;
p = (uchar *)&data;
- if (putc(p[0], file) == EOF)
+ if (putc(p[0], file) == EOF) {
return EOF;
+ }
return ~EOF;
}
@@ -77,10 +78,12 @@ static int tga_out2(unsigned int data, FILE *file)
uchar *p;
p = (uchar *)&data;
- if (putc(p[0], file) == EOF)
+ if (putc(p[0], file) == EOF) {
return EOF;
- if (putc(p[1], file) == EOF)
+ }
+ if (putc(p[1], file) == EOF) {
return EOF;
+ }
return ~EOF;
}
@@ -89,12 +92,15 @@ static int tga_out3(unsigned int data, FILE *file)
uchar *p;
p = (uchar *)&data;
- if (putc(p[2], file) == EOF)
+ if (putc(p[2], file) == EOF) {
return EOF;
- if (putc(p[1], file) == EOF)
+ }
+ if (putc(p[1], file) == EOF) {
return EOF;
- if (putc(p[0], file) == EOF)
+ }
+ if (putc(p[0], file) == EOF) {
return EOF;
+ }
return ~EOF;
}
@@ -104,14 +110,18 @@ static int tga_out4(unsigned int data, FILE *file)
p = (uchar *)&data;
/* order = bgra */
- if (putc(p[2], file) == EOF)
+ if (putc(p[2], file) == EOF) {
return EOF;
- if (putc(p[1], file) == EOF)
+ }
+ if (putc(p[1], file) == EOF) {
return EOF;
- if (putc(p[0], file) == EOF)
+ }
+ if (putc(p[0], file) == EOF) {
return EOF;
- if (putc(p[3], file) == EOF)
+ }
+ if (putc(p[3], file) == EOF) {
return EOF;
+ }
return ~EOF;
}
@@ -143,22 +153,26 @@ static bool makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE
copy = rect - rectstart;
copy--;
- if (bytes)
+ if (bytes) {
copy -= 2;
+ }
temp = rect;
rect = rectstart;
while (copy) {
last = copy;
- if (copy >= 128)
+ if (copy >= 128) {
last = 128;
+ }
copy -= last;
- if (fputc(last - 1, file) == EOF)
+ if (fputc(last - 1, file) == EOF) {
return 0;
+ }
do {
- if (out(*rect++, file) == EOF)
+ if (out(*rect++, file) == EOF) {
return 0;
+ }
} while (--last != 0);
}
rectstart = rect;
@@ -169,8 +183,9 @@ static bool makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE
}
else {
while (*rect++ == this) { /* seek for first different byte */
- if (--bytes == 0)
+ if (--bytes == 0) {
break; /* oor end of line */
+ }
}
rect--;
copy = rect - rectstart;
@@ -180,21 +195,25 @@ static bool makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE
while (copy) {
if (copy > 128) {
- if (fputc(255, file) == EOF)
+ if (fputc(255, file) == EOF) {
return 0;
+ }
copy -= 128;
}
else {
if (copy == 1) {
- if (fputc(0, file) == EOF)
+ if (fputc(0, file) == EOF) {
return 0;
+ }
}
- else if (fputc(127 + copy, file) == EOF)
+ else if (fputc(127 + copy, file) == EOF) {
return 0;
+ }
copy = 0;
}
- if (out(last, file) == EOF)
+ if (out(last, file) == EOF) {
return 0;
+ }
}
copy = 1;
}
@@ -208,18 +227,21 @@ static bool dumptarga(struct ImBuf *ibuf, FILE *file)
int size;
uchar *rect;
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return 0;
- if (ibuf->rect == NULL)
+ }
+ if (ibuf->rect == NULL) {
return 0;
+ }
size = ibuf->x * ibuf->y;
rect = (uchar *)ibuf->rect;
if (ibuf->planes <= 8) {
while (size > 0) {
- if (putc(*rect, file) == EOF)
+ if (putc(*rect, file) == EOF) {
return 0;
+ }
size--;
rect += 4;
}
@@ -227,8 +249,9 @@ static bool dumptarga(struct ImBuf *ibuf, FILE *file)
else if (ibuf->planes <= 16) {
while (size > 0) {
putc(rect[0], file);
- if (putc(rect[1], file) == EOF)
+ if (putc(rect[1], file) == EOF) {
return 0;
+ }
size--;
rect += 4;
}
@@ -237,8 +260,9 @@ static bool dumptarga(struct ImBuf *ibuf, FILE *file)
while (size > 0) {
putc(rect[2], file);
putc(rect[1], file);
- if (putc(rect[0], file) == EOF)
+ if (putc(rect[0], file) == EOF) {
return 0;
+ }
size--;
rect += 4;
}
@@ -248,8 +272,9 @@ static bool dumptarga(struct ImBuf *ibuf, FILE *file)
putc(rect[2], file);
putc(rect[1], file);
putc(rect[0], file);
- if (putc(rect[3], file) == EOF)
+ if (putc(rect[3], file) == EOF) {
return 0;
+ }
size--;
rect += 4;
}
@@ -277,8 +302,9 @@ int imb_savetarga(struct ImBuf *ibuf, const char *name, int flags)
buf[2] = 11;
}
- if (ibuf->foptions.flag & RAWTGA)
+ if (ibuf->foptions.flag & RAWTGA) {
buf[2] &= ~8;
+ }
buf[8] = 0;
buf[9] = 0;
@@ -296,8 +322,9 @@ int imb_savetarga(struct ImBuf *ibuf, const char *name, int flags)
buf[17] |= 0x08;
}
fildes = BLI_fopen(name, "wb");
- if (!fildes)
+ if (!fildes) {
return 0;
+ }
if (fwrite(buf, 1, 18, fildes) != 18) {
fclose(fildes);
@@ -344,8 +371,9 @@ static int checktarga(TARGA *tga, const unsigned char *mem)
tga->pixsize = mem[16];
tga->imgdes = mem[17];
- if (tga->maptyp > 1)
+ if (tga->maptyp > 1) {
return 0;
+ }
switch (tga->imgtyp) {
case 1: /* raw cmap */
case 2: /* raw rgb */
@@ -357,16 +385,21 @@ static int checktarga(TARGA *tga, const unsigned char *mem)
default:
return 0;
}
- if (tga->mapsize && tga->mapbits > 32)
+ if (tga->mapsize && tga->mapbits > 32) {
return 0;
- if (tga->xsize <= 0)
+ }
+ if (tga->xsize <= 0) {
return 0;
- if (tga->ysize <= 0)
+ }
+ if (tga->ysize <= 0) {
return 0;
- if (tga->pixsize > 32)
+ }
+ if (tga->pixsize > 32) {
return 0;
- if (tga->pixsize == 0)
+ }
+ if (tga->pixsize == 0) {
return 0;
+ }
return 1;
}
@@ -400,10 +433,12 @@ static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem
unsigned int *rect;
uchar *cp = (uchar *)&col;
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return;
- if (ibuf->rect == NULL)
+ }
+ if (ibuf->rect == NULL) {
return;
+ }
size = ibuf->x * ibuf->y;
rect = ibuf->rect;
@@ -415,8 +450,9 @@ static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem
while (size > 0) {
count = *mem++;
- if (mem > mem_end)
+ if (mem > mem_end) {
goto partial_load;
+ }
if (count >= 128) {
/*if (count == 128) printf("TARGA: 128 in file !\n");*/
@@ -495,12 +531,14 @@ static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem
*rect++ = col;
count--;
- if (mem > mem_end)
+ if (mem > mem_end) {
goto partial_load;
+ }
}
- if (mem > mem_end)
+ if (mem > mem_end) {
goto partial_load;
+ }
}
}
}
@@ -520,10 +558,12 @@ static void ldtarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_siz
unsigned int *rect;
uchar *cp = (uchar *)&col;
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return;
- if (ibuf->rect == NULL)
+ }
+ if (ibuf->rect == NULL) {
return;
+ }
size = ibuf->x * ibuf->y;
rect = ibuf->rect;
@@ -533,8 +573,9 @@ static void ldtarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_siz
cp[1] = cp[2] = 0;
while (size > 0) {
- if (mem > mem_end)
+ if (mem > mem_end) {
goto partial_load;
+ }
if (psize & 2) {
if (psize & 1) {
@@ -592,16 +633,20 @@ ImBuf *imb_loadtarga(const unsigned char *mem,
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
- if (flags & IB_test)
+ if (flags & IB_test) {
ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, tga.pixsize, 0);
- else
+ }
+ else {
ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, (tga.pixsize + 0x7) & ~0x7, IB_rect);
+ }
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return NULL;
+ }
ibuf->ftype = IMB_FTYPE_TGA;
- if (tga.imgtyp < 4)
+ if (tga.imgtyp < 4) {
ibuf->foptions.flag |= RAWTGA;
+ }
mem = mem + 18 + tga.numid;
cp[0] = 0xff;
@@ -669,26 +714,34 @@ ImBuf *imb_loadtarga(const unsigned char *mem,
case 1:
case 2:
case 3:
- if (tga.pixsize <= 8)
+ if (tga.pixsize <= 8) {
ldtarga(ibuf, mem, mem_size, 0);
- else if (tga.pixsize <= 16)
+ }
+ else if (tga.pixsize <= 16) {
ldtarga(ibuf, mem, mem_size, 1);
- else if (tga.pixsize <= 24)
+ }
+ else if (tga.pixsize <= 24) {
ldtarga(ibuf, mem, mem_size, 2);
- else if (tga.pixsize <= 32)
+ }
+ else if (tga.pixsize <= 32) {
ldtarga(ibuf, mem, mem_size, 3);
+ }
break;
case 9:
case 10:
case 11:
- if (tga.pixsize <= 8)
+ if (tga.pixsize <= 8) {
decodetarga(ibuf, mem, mem_size, 0);
- else if (tga.pixsize <= 16)
+ }
+ else if (tga.pixsize <= 16) {
decodetarga(ibuf, mem, mem_size, 1);
- else if (tga.pixsize <= 24)
+ }
+ else if (tga.pixsize <= 24) {
decodetarga(ibuf, mem, mem_size, 2);
- else if (tga.pixsize <= 32)
+ }
+ else if (tga.pixsize <= 32) {
decodetarga(ibuf, mem, mem_size, 3);
+ }
break;
}
@@ -744,8 +797,9 @@ ImBuf *imb_loadtarga(const unsigned char *mem,
IMB_flipy(ibuf);
}
- if (ibuf->rect)
+ if (ibuf->rect) {
IMB_convert_rgba_to_abgr(ibuf);
+ }
return ibuf;
}
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index afbc0f0a5c4..06b8019a24d 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -99,8 +99,9 @@ static bool get_thumb_dir(char *dir, ThumbSize size)
# else
const char *home = BLI_getenv("HOME");
# endif
- if (!home)
+ if (!home) {
return 0;
+ }
s += BLI_strncpy_rlen(s, home, FILE_MAX);
# ifdef USE_FREEDESKTOP
@@ -452,8 +453,9 @@ static ImBuf *thumb_create_ex(const char *file_path,
}
if (size == THB_FAIL) {
img = IMB_allocImBuf(1, 1, 32, IB_rect | IB_metadata);
- if (!img)
+ if (!img) {
return NULL;
+ }
}
else {
if (ELEM(source, THB_SOURCE_IMAGE, THB_SOURCE_BLEND, THB_SOURCE_FONT)) {
@@ -500,8 +502,9 @@ static ImBuf *thumb_create_ex(const char *file_path,
BLI_snprintf(mtime, sizeof(mtime), "%ld", (long int)info.st_mtime);
}
}
- if (!img)
+ if (!img) {
return NULL;
+ }
if (img->x > img->y) {
scaledx = (float)tsize;
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index 1f2b63a3749..fc0a643fade 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -122,17 +122,21 @@ static tsize_t imb_tiff_ReadProc(thandle_t handle, tdata_t data, tsize_t n)
/* find the actual number of bytes to read (copy) */
nCopy = n;
- if ((tsize_t)mfile->offset >= mfile->size)
+ if ((tsize_t)mfile->offset >= mfile->size) {
nRemaining = 0;
- else
+ }
+ else {
nRemaining = mfile->size - mfile->offset;
+ }
- if (nCopy > nRemaining)
+ if (nCopy > nRemaining) {
nCopy = nRemaining;
+ }
/* on EOF, return immediately and read (copy) nothing */
- if (nCopy <= 0)
+ if (nCopy <= 0) {
return (0);
+ }
/* all set -> do the read (copy) */
srcAddr = (void *)(&(mfile->mem[mfile->offset]));
@@ -330,15 +334,17 @@ static void scanline_separate_16bit(float *rectf,
int chan)
{
int i;
- for (i = 0; i < scanline_w; i++)
+ for (i = 0; i < scanline_w; i++) {
rectf[i * 4 + chan] = sbuf[i] / 65535.0;
+ }
}
static void scanline_separate_32bit(float *rectf, const float *fbuf, int scanline_w, int chan)
{
int i;
- for (i = 0; i < scanline_w; i++)
+ for (i = 0; i < scanline_w; i++) {
rectf[i * 4 + chan] = fbuf[i];
+ }
}
static void imb_read_tiff_resolution(ImBuf *ibuf, TIFF *image)
@@ -453,21 +459,27 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image)
size_t ib_offset = (size_t)ibuf->x * 4 * ((size_t)ibuf->y - ((size_t)row + 1));
if (bitspersample == 32) {
- if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
+ if (chan == 3 && spp == 3) { /* fill alpha if only RGB TIFF */
copy_vn_fl(fbuf, ibuf->x, 1.0f);
- else if (chan >= spp) /* for grayscale, duplicate first channel into G and B */
+ }
+ else if (chan >= spp) { /* for grayscale, duplicate first channel into G and B */
success |= TIFFReadScanline(image, fbuf, row, 0);
- else
+ }
+ else {
success |= TIFFReadScanline(image, fbuf, row, chan);
+ }
scanline_separate_32bit(tmpibuf->rect_float + ib_offset, fbuf, ibuf->x, chan);
}
else if (bitspersample == 16) {
- if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */
+ if (chan == 3 && spp == 3) { /* fill alpha if only RGB TIFF */
copy_vn_ushort(sbuf, ibuf->x, 65535);
- else if (chan >= spp) /* for grayscale, duplicate first channel into G and B */
+ }
+ else if (chan >= spp) { /* for grayscale, duplicate first channel into G and B */
success |= TIFFReadScanline(image, fbuf, row, 0);
- else
+ }
+ else {
success |= TIFFReadScanline(image, sbuf, row, chan);
+ }
scanline_separate_16bit(tmpibuf->rect_float + ib_offset, sbuf, ibuf->x, chan);
}
}
@@ -476,15 +488,19 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image)
if (success) {
/* Code seems to be not needed for 16 bits tif, on PPC G5 OSX (ton) */
- if (bitspersample < 16)
- if (ENDIAN_ORDER == B_ENDIAN)
+ if (bitspersample < 16) {
+ if (ENDIAN_ORDER == B_ENDIAN) {
IMB_convert_rgba_to_abgr(tmpibuf);
+ }
+ }
/* assign rect last */
- if (tmpibuf->rect_float)
+ if (tmpibuf->rect_float) {
ibuf->rect_float = tmpibuf->rect_float;
- else
+ }
+ else {
ibuf->rect = tmpibuf->rect;
+ }
ibuf->mall |= ib_flag;
ibuf->flags |= ib_flag;
@@ -492,10 +508,12 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image)
}
cleanup:
- if (bitspersample == 32)
+ if (bitspersample == 32) {
_TIFFfree(fbuf);
- else if (bitspersample == 16)
+ }
+ else if (bitspersample == 16) {
_TIFFfree(sbuf);
+ }
IMB_freeImBuf(tmpibuf);
@@ -504,8 +522,9 @@ cleanup:
void imb_inittiff(void)
{
- if (!(G.debug & G_DEBUG))
+ if (!(G.debug & G_DEBUG)) {
TIFFSetErrorHandler(NULL);
+ }
}
/**
@@ -537,8 +556,9 @@ ImBuf *imb_loadtiff(const unsigned char *mem,
fprintf(stderr, "imb_loadtiff: size < IMB_TIFF_NCB\n");
return NULL;
}
- if (imb_is_a_tiff(mem) == 0)
+ if (imb_is_a_tiff(mem) == 0) {
return NULL;
+ }
/* both 8 and 16 bit PNGs are default to standard byte colorspace */
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -599,8 +619,9 @@ ImBuf *imb_loadtiff(const unsigned char *mem,
/* create empty mipmap levels in advance */
for (level = 0; level < numlevel; level++) {
- if (!TIFFSetDirectory(image, level))
+ if (!TIFFSetDirectory(image, level)) {
break;
+ }
if (level > 0) {
width = (width > 1) ? width / 2 : 1;
@@ -611,8 +632,9 @@ ImBuf *imb_loadtiff(const unsigned char *mem,
hbuf->ftype = ibuf->ftype;
ibuf->mipmap[level - 1] = hbuf;
}
- else
+ else {
hbuf = ibuf;
+ }
hbuf->flags |= IB_tilecache;
@@ -666,25 +688,29 @@ void imb_loadtiletiff(
/* tiff pixels are bottom to top, tiles are top to bottom */
if (TIFFReadRGBATile(
image, tx * ibuf->tilex, (ibuf->ytiles - 1 - ty) * ibuf->tiley, rect) == 1) {
- if (ibuf->tiley > ibuf->y)
+ if (ibuf->tiley > ibuf->y) {
memmove(rect,
rect + ibuf->tilex * (ibuf->tiley - ibuf->y),
sizeof(int) * ibuf->tilex * ibuf->y);
+ }
}
- else
+ else {
printf("imb_loadtiff: failed to read tiff tile at mipmap level %d\n", ibuf->miplevel);
+ }
}
}
- else
+ else {
printf("imb_loadtiff: mipmap level %d has unexpected size %ux%u instead of %dx%d\n",
ibuf->miplevel,
width,
height,
ibuf->x,
ibuf->y);
+ }
}
- else
+ else {
printf("imb_loadtiff: could not find mipmap level %d\n", ibuf->miplevel);
+ }
/* close the client layer interface to the in-memory file */
TIFFClose(image);
@@ -731,17 +757,22 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
return (0);
}
- if ((ibuf->foptions.flag & TIF_16BIT) && ibuf->rect_float)
+ if ((ibuf->foptions.flag & TIF_16BIT) && ibuf->rect_float) {
bitspersample = 16;
- else
+ }
+ else {
bitspersample = 8;
+ }
- if (ibuf->foptions.flag & TIF_COMPRESS_DEFLATE)
+ if (ibuf->foptions.flag & TIF_COMPRESS_DEFLATE) {
compress_mode = COMPRESSION_DEFLATE;
- else if (ibuf->foptions.flag & TIF_COMPRESS_LZW)
+ }
+ else if (ibuf->foptions.flag & TIF_COMPRESS_LZW) {
compress_mode = COMPRESSION_LZW;
- else if (ibuf->foptions.flag & TIF_COMPRESS_PACKBITS)
+ }
+ else if (ibuf->foptions.flag & TIF_COMPRESS_PACKBITS) {
compress_mode = COMPRESSION_PACKBITS;
+ }
/* open TIFF file for writing */
if (flags & IB_mem) {
@@ -768,10 +799,12 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
/* allocate array for pixel data */
npixels = ibuf->x * ibuf->y;
- if (bitspersample == 16)
+ if (bitspersample == 16) {
pixels16 = (unsigned short *)_TIFFmalloc(npixels * samplesperpixel * sizeof(unsigned short));
- else
+ }
+ else {
pixels = (unsigned char *)_TIFFmalloc(npixels * samplesperpixel * sizeof(unsigned char));
+ }
if (pixels == NULL && pixels16 == NULL) {
fprintf(stderr, "imb_savetiff: could not allocate pixels array.\n");
@@ -796,10 +829,12 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
if (samplesperpixel == 4) {
unsigned short extraSampleTypes[1];
- if (bitspersample == 16)
+ if (bitspersample == 16) {
extraSampleTypes[0] = EXTRASAMPLE_ASSOCALPHA;
- else
+ }
+ else {
extraSampleTypes[0] = EXTRASAMPLE_UNASSALPHA;
+ }
/* RGBA images */
TIFFSetField(image, TIFFTAG_EXTRASAMPLES, 1, extraSampleTypes);
@@ -856,12 +891,14 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
rgb[3] = 1.0f;
}
- for (i = 0; i < samplesperpixel; i++, to_i++)
+ for (i = 0; i < samplesperpixel; i++, to_i++) {
to16[to_i] = unit_float_to_ushort_clamp(rgb[i]);
+ }
}
else {
- for (i = 0; i < samplesperpixel; i++, to_i++, from_i++)
+ for (i = 0; i < samplesperpixel; i++, to_i++, from_i++) {
to[to_i] = from[from_i];
+ }
}
}
}
@@ -892,18 +929,22 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
-1) {
fprintf(stderr, "imb_savetiff: Could not write encoded TIFF.\n");
TIFFClose(image);
- if (pixels)
+ if (pixels) {
_TIFFfree(pixels);
- if (pixels16)
+ }
+ if (pixels16) {
_TIFFfree(pixels16);
+ }
return (1);
}
/* close the TIFF file */
TIFFClose(image);
- if (pixels)
+ if (pixels) {
_TIFFfree(pixels);
- if (pixels16)
+ }
+ if (pixels16) {
_TIFFfree(pixels16);
+ }
return (1);
}
diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c
index 50aaa16c3fe..1126a93148d 100644
--- a/source/blender/imbuf/intern/util.c
+++ b/source/blender/imbuf/intern/util.c
@@ -126,16 +126,20 @@ int IMB_ispic_type(const char *name)
BLI_assert(!BLI_path_is_rel(name));
- if (UTIL_DEBUG)
+ if (UTIL_DEBUG) {
printf("%s: loading %s\n", __func__, name);
+ }
- if (BLI_stat(name, &st) == -1)
+ if (BLI_stat(name, &st) == -1) {
return false;
- if (((st.st_mode) & S_IFMT) != S_IFREG)
+ }
+ if (((st.st_mode) & S_IFMT) != S_IFREG) {
return false;
+ }
- if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) == -1)
+ if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) == -1) {
return false;
+ }
memset(buf, 0, sizeof(buf));
if (read(fp, buf, HEADER_SIZE) <= 0) {
@@ -146,8 +150,9 @@ int IMB_ispic_type(const char *name)
close(fp);
/* XXX move this exception */
- if ((BIG_LONG(((int *)buf)[0]) & 0xfffffff0) == 0xffd8ffe0)
+ if ((BIG_LONG(((int *)buf)[0]) & 0xfffffff0) == 0xffd8ffe0) {
return IMB_FTYPE_JPG;
+ }
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->is_a) {
@@ -223,8 +228,9 @@ void IMB_ffmpeg_init(void)
ffmpeg_last_error[0] = '\0';
- if (G.debug & G_DEBUG_FFMPEG)
+ if (G.debug & G_DEBUG_FFMPEG) {
av_log_set_level(AV_LOG_DEBUG);
+ }
/* set own callback which could store last error to report to UI */
av_log_set_callback(ffmpeg_log_callback);
@@ -259,20 +265,23 @@ static int isffmpeg(const char *filename)
}
if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) != 0) {
- if (UTIL_DEBUG)
+ if (UTIL_DEBUG) {
fprintf(stderr, "isffmpeg: av_open_input_file failed\n");
+ }
return 0;
}
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
- if (UTIL_DEBUG)
+ if (UTIL_DEBUG) {
fprintf(stderr, "isffmpeg: avformat_find_stream_info failed\n");
+ }
avformat_close_input(&pFormatCtx);
return 0;
}
- if (UTIL_DEBUG)
+ if (UTIL_DEBUG) {
av_dump_format(pFormatCtx, 0, filename, 0);
+ }
/* Find the first video stream */
videoStream = -1;
@@ -316,40 +325,51 @@ int imb_get_anim_type(const char *name)
BLI_assert(!BLI_path_is_rel(name));
- if (UTIL_DEBUG)
+ if (UTIL_DEBUG) {
printf("%s: %s\n", __func__, name);
+ }
#ifndef _WIN32
# ifdef WITH_FFMPEG
/* stat test below fails on large files > 4GB */
- if (isffmpeg(name))
+ if (isffmpeg(name)) {
return (ANIM_FFMPEG);
+ }
# endif
- if (BLI_stat(name, &st) == -1)
+ if (BLI_stat(name, &st) == -1) {
return (0);
- if (((st.st_mode) & S_IFMT) != S_IFREG)
+ }
+ if (((st.st_mode) & S_IFMT) != S_IFREG) {
return (0);
+ }
- if (isavi(name))
+ if (isavi(name)) {
return (ANIM_AVI);
+ }
- if (ismovie(name))
+ if (ismovie(name)) {
return (ANIM_MOVIE);
+ }
#else
- if (BLI_stat(name, &st) == -1)
+ if (BLI_stat(name, &st) == -1) {
return (0);
- if (((st.st_mode) & S_IFMT) != S_IFREG)
+ }
+ if (((st.st_mode) & S_IFMT) != S_IFREG) {
return (0);
+ }
- if (ismovie(name))
+ if (ismovie(name)) {
return (ANIM_MOVIE);
+ }
# ifdef WITH_FFMPEG
- if (isffmpeg(name))
+ if (isffmpeg(name)) {
return (ANIM_FFMPEG);
+ }
# endif
- if (isavi(name))
+ if (isavi(name)) {
return (ANIM_AVI);
+ }
#endif
type = IMB_ispic(name);
if (type) {
diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c
index e93df7b73ba..ac3961faf49 100644
--- a/source/blender/imbuf/intern/writeimage.c
+++ b/source/blender/imbuf/intern/writeimage.c
@@ -49,8 +49,9 @@ short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags)
BLI_assert(!BLI_path_is_rel(name));
- if (ibuf == NULL)
+ if (ibuf == NULL) {
return (false);
+ }
ibuf->flags = flags;
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {