diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-03-24 10:38:07 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-03-24 10:38:07 +0400 |
commit | ab4a2aaf4a4b2b4e416aa1f113b30362cbe0dec3 (patch) | |
tree | 81af4c18519181490074508dbe9a8d515eab634f /source/blender/imbuf | |
parent | 5a90ea77bc1333efe4e1e54984a080550ed3f707 (diff) |
style cleanup: follow style guide for formatting of if/for/while loops, and else if's
Diffstat (limited to 'source/blender/imbuf')
32 files changed, 878 insertions, 754 deletions
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index d85251a8ccb..2cfdd7bc324 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -51,8 +51,8 @@ void imb_freemipmapImBuf(ImBuf *ibuf) { int a; - for(a=1; a<ibuf->miptot; a++) { - if(ibuf->mipmap[a-1]) + for (a=1; a<ibuf->miptot; a++) { + if (ibuf->mipmap[a-1]) IMB_freeImBuf(ibuf->mipmap[a-1]); ibuf->mipmap[a-1]= NULL; } @@ -63,9 +63,9 @@ void imb_freemipmapImBuf(ImBuf *ibuf) /* any free rect frees mipmaps to be sure, creation is in render on first request */ void imb_freerectfloatImBuf(ImBuf *ibuf) { - if(ibuf==NULL) return; + if (ibuf==NULL) return; - if(ibuf->rect_float && (ibuf->mall & IB_rectfloat)) { + if (ibuf->rect_float && (ibuf->mall & IB_rectfloat)) { MEM_freeN(ibuf->rect_float); ibuf->rect_float=NULL; } @@ -79,9 +79,9 @@ void imb_freerectfloatImBuf(ImBuf *ibuf) /* any free rect frees mipmaps to be sure, creation is in render on first request */ void imb_freerectImBuf(ImBuf *ibuf) { - if(ibuf==NULL) return; + if (ibuf==NULL) return; - if(ibuf->rect && (ibuf->mall & IB_rect)) + if (ibuf->rect && (ibuf->mall & IB_rect)) MEM_freeN(ibuf->rect); ibuf->rect= NULL; @@ -94,12 +94,12 @@ void imb_freetilesImBuf(ImBuf *ibuf) { int tx, ty; - if(ibuf==NULL) return; + if (ibuf==NULL) return; - if(ibuf->tiles && (ibuf->mall & IB_tiles)) { - for(ty=0; ty<ibuf->ytiles; ty++) { - for(tx=0; tx<ibuf->xtiles; tx++) { - if(ibuf->tiles[ibuf->xtiles*ty + tx]) { + if (ibuf->tiles && (ibuf->mall & IB_tiles)) { + for (ty=0; ty<ibuf->ytiles; ty++) { + for (tx=0; tx<ibuf->xtiles; tx++) { + if (ibuf->tiles[ibuf->xtiles*ty + tx]) { imb_tile_cache_tile_free(ibuf, tx, ty); MEM_freeN(ibuf->tiles[ibuf->xtiles*ty + tx]); } @@ -115,9 +115,9 @@ void imb_freetilesImBuf(ImBuf *ibuf) static void freeencodedbufferImBuf(ImBuf *ibuf) { - if(ibuf==NULL) return; + if (ibuf==NULL) return; - if(ibuf->encodedbuffer && (ibuf->mall & IB_mem)) + if (ibuf->encodedbuffer && (ibuf->mall & IB_mem)) MEM_freeN(ibuf->encodedbuffer); ibuf->encodedbuffer = NULL; @@ -128,9 +128,9 @@ static void freeencodedbufferImBuf(ImBuf *ibuf) void IMB_freezbufImBuf(ImBuf *ibuf) { - if(ibuf==NULL) return; + if (ibuf==NULL) return; - if(ibuf->zbuf && (ibuf->mall & IB_zbuf)) + if (ibuf->zbuf && (ibuf->mall & IB_zbuf)) MEM_freeN(ibuf->zbuf); ibuf->zbuf= NULL; @@ -139,9 +139,9 @@ void IMB_freezbufImBuf(ImBuf *ibuf) void IMB_freezbuffloatImBuf(ImBuf *ibuf) { - if(ibuf==NULL) return; + if (ibuf==NULL) return; - if(ibuf->zbuf_float && (ibuf->mall & IB_zbuffloat)) + if (ibuf->zbuf_float && (ibuf->mall & IB_zbuffloat)) MEM_freeN(ibuf->zbuf_float); ibuf->zbuf_float= NULL; @@ -150,8 +150,8 @@ void IMB_freezbuffloatImBuf(ImBuf *ibuf) void IMB_freeImBuf(ImBuf *ibuf) { - if(ibuf) { - if(ibuf->refcounter > 0) { + if (ibuf) { + if (ibuf->refcounter > 0) { ibuf->refcounter--; } else { @@ -189,12 +189,12 @@ short addzbufImBuf(ImBuf *ibuf) { int size; - if(ibuf==NULL) return FALSE; + if (ibuf==NULL) return FALSE; IMB_freezbufImBuf(ibuf); size = ibuf->x *ibuf->y *sizeof(unsigned int); - if((ibuf->zbuf = MEM_mapallocN(size, "addzbufImBuf"))) { + if ((ibuf->zbuf = MEM_mapallocN(size, "addzbufImBuf"))) { ibuf->mall |= IB_zbuf; ibuf->flags |= IB_zbuf; return TRUE; @@ -207,12 +207,12 @@ short addzbuffloatImBuf(ImBuf *ibuf) { int size; - if(ibuf==NULL) return FALSE; + if (ibuf==NULL) return FALSE; IMB_freezbuffloatImBuf(ibuf); size = ibuf->x *ibuf->y *sizeof(float); - if((ibuf->zbuf_float = MEM_mapallocN(size, "addzbuffloatImBuf"))) { + if ((ibuf->zbuf_float = MEM_mapallocN(size, "addzbuffloatImBuf"))) { ibuf->mall |= IB_zbuffloat; ibuf->flags |= IB_zbuffloat; return TRUE; @@ -224,16 +224,16 @@ short addzbuffloatImBuf(ImBuf *ibuf) short imb_addencodedbufferImBuf(ImBuf *ibuf) { - if(ibuf==NULL) return FALSE; + if (ibuf==NULL) return FALSE; freeencodedbufferImBuf(ibuf); - if(ibuf->encodedbuffersize == 0) + if (ibuf->encodedbuffersize == 0) ibuf->encodedbuffersize = 10000; ibuf->encodedsize = 0; - if((ibuf->encodedbuffer = MEM_mallocN(ibuf->encodedbuffersize, "addencodedbufferImBuf"))) { + if ((ibuf->encodedbuffer = MEM_mallocN(ibuf->encodedbuffersize, "addencodedbufferImBuf"))) { ibuf->mall |= IB_mem; ibuf->flags |= IB_mem; return TRUE; @@ -248,22 +248,23 @@ short imb_enlargeencodedbufferImBuf(ImBuf *ibuf) unsigned int newsize, encodedsize; void *newbuffer; - if(ibuf==NULL) return FALSE; + if (ibuf==NULL) return FALSE; - if(ibuf->encodedbuffersize < ibuf->encodedsize) { + if (ibuf->encodedbuffersize < ibuf->encodedsize) { printf("imb_enlargeencodedbufferImBuf: error in parameters\n"); return FALSE; } newsize = 2 *ibuf->encodedbuffersize; - if(newsize < 10000) newsize = 10000; + if (newsize < 10000) newsize = 10000; newbuffer = MEM_mallocN(newsize, "enlargeencodedbufferImBuf"); - if(newbuffer == NULL) return FALSE; + if (newbuffer == NULL) return FALSE; - if(ibuf->encodedbuffer) { + if (ibuf->encodedbuffer) { memcpy(newbuffer, ibuf->encodedbuffer, ibuf->encodedsize); - } else { + } + else { ibuf->encodedsize = 0; } @@ -284,16 +285,16 @@ short imb_addrectfloatImBuf(ImBuf *ibuf) { int size; - if(ibuf==NULL) return FALSE; + if (ibuf==NULL) return FALSE; - if(ibuf->rect_float) + if (ibuf->rect_float) imb_freerectfloatImBuf(ibuf); /* frees mipmap too, hrm */ size = ibuf->x *ibuf->y; size = size *4 *sizeof(float); ibuf->channels= 4; - if((ibuf->rect_float = MEM_mapallocN(size, "imb_addrectfloatImBuf"))) { + if ((ibuf->rect_float = MEM_mapallocN(size, "imb_addrectfloatImBuf"))) { ibuf->mall |= IB_rectfloat; ibuf->flags |= IB_rectfloat; return TRUE; @@ -307,20 +308,20 @@ short imb_addrectImBuf(ImBuf *ibuf) { int size; - if(ibuf==NULL) return FALSE; + if (ibuf==NULL) return FALSE; /* don't call imb_freerectImBuf, it frees mipmaps, this call is used only too give float buffers display */ - if(ibuf->rect && (ibuf->mall & IB_rect)) + if (ibuf->rect && (ibuf->mall & IB_rect)) MEM_freeN(ibuf->rect); ibuf->rect= NULL; size = ibuf->x*ibuf->y; size = size*sizeof(unsigned int); - if((ibuf->rect = MEM_mapallocN(size, "imb_addrectImBuf"))) { + if ((ibuf->rect = MEM_mapallocN(size, "imb_addrectImBuf"))) { ibuf->mall |= IB_rect; ibuf->flags |= IB_rect; - if(ibuf->planes > 32) return (addzbufImBuf(ibuf)); + if (ibuf->planes > 32) return (addzbufImBuf(ibuf)); else return TRUE; } @@ -329,10 +330,10 @@ short imb_addrectImBuf(ImBuf *ibuf) short imb_addtilesImBuf(ImBuf *ibuf) { - if(ibuf==NULL) return FALSE; + if (ibuf==NULL) return FALSE; - if(!ibuf->tiles) - if((ibuf->tiles = MEM_callocN(sizeof(unsigned int*)*ibuf->xtiles*ibuf->ytiles, "imb_tiles"))) + if (!ibuf->tiles) + if ((ibuf->tiles = MEM_callocN(sizeof(unsigned int*)*ibuf->xtiles*ibuf->ytiles, "imb_tiles"))) ibuf->mall |= IB_tiles; return (ibuf->tiles != NULL); @@ -344,7 +345,7 @@ ImBuf *IMB_allocImBuf(unsigned int x, unsigned int y, uchar planes, unsigned int ibuf = MEM_callocN(sizeof(ImBuf), "ImBuf_struct"); - if(ibuf) { + if (ibuf) { ibuf->x= x; ibuf->y= y; ibuf->planes= planes; @@ -352,29 +353,29 @@ ImBuf *IMB_allocImBuf(unsigned int x, unsigned int y, uchar planes, unsigned int ibuf->channels= 4; /* float option, is set to other values when buffers get assigned */ ibuf->ppm[0]= ibuf->ppm[1]= 150.0 / 0.0254; /* 150dpi -> pixels-per-meter */ - if(flags & IB_rect) { - if(imb_addrectImBuf(ibuf)==FALSE) { + if (flags & IB_rect) { + if (imb_addrectImBuf(ibuf)==FALSE) { IMB_freeImBuf(ibuf); return NULL; } } - if(flags & IB_rectfloat) { - if(imb_addrectfloatImBuf(ibuf)==FALSE) { + if (flags & IB_rectfloat) { + if (imb_addrectfloatImBuf(ibuf)==FALSE) { IMB_freeImBuf(ibuf); return NULL; } } - if(flags & IB_zbuf) { - if(addzbufImBuf(ibuf)==FALSE) { + if (flags & IB_zbuf) { + if (addzbufImBuf(ibuf)==FALSE) { IMB_freeImBuf(ibuf); return NULL; } } - if(flags & IB_zbuffloat) { - if(addzbuffloatImBuf(ibuf)==FALSE) { + if (flags & IB_zbuffloat) { + if (addzbuffloatImBuf(ibuf)==FALSE) { IMB_freeImBuf(ibuf); return NULL; } @@ -390,27 +391,27 @@ ImBuf *IMB_dupImBuf(ImBuf *ibuf1) int flags = 0; int a, x, y; - if(ibuf1 == NULL) return NULL; + if (ibuf1 == NULL) return NULL; - if(ibuf1->rect) flags |= IB_rect; - if(ibuf1->rect_float) flags |= IB_rectfloat; + if (ibuf1->rect) flags |= IB_rect; + if (ibuf1->rect_float) flags |= IB_rectfloat; x = ibuf1->x; y = ibuf1->y; - if(ibuf1->flags & IB_fields) y *= 2; + if (ibuf1->flags & IB_fields) y *= 2; ibuf2 = IMB_allocImBuf(x, y, ibuf1->planes, flags); - if(ibuf2 == NULL) return NULL; + if (ibuf2 == NULL) return NULL; - if(flags & IB_rect) + if (flags & IB_rect) memcpy(ibuf2->rect, ibuf1->rect, x *y *sizeof(int)); - if(flags & IB_rectfloat) + if (flags & IB_rectfloat) memcpy(ibuf2->rect_float, ibuf1->rect_float, ibuf1->channels *x *y *sizeof(float)); - if(ibuf1->encodedbuffer) { + if (ibuf1->encodedbuffer) { ibuf2->encodedbuffersize = ibuf1->encodedbuffersize; - if(imb_addencodedbufferImBuf(ibuf2) == FALSE) { + if (imb_addencodedbufferImBuf(ibuf2) == FALSE) { IMB_freeImBuf(ibuf2); return NULL; } @@ -427,7 +428,7 @@ ImBuf *IMB_dupImBuf(ImBuf *ibuf1) tbuf.encodedbuffer = ibuf2->encodedbuffer; tbuf.zbuf= NULL; tbuf.zbuf_float= NULL; - for(a=0; a<IB_MIPMAP_LEVELS; a++) + for (a=0; a<IB_MIPMAP_LEVELS; a++) tbuf.mipmap[a]= NULL; // set malloc flag @@ -464,7 +465,7 @@ static MEM_CacheLimiterC **get_imbuf_cache_limiter(void) { static MEM_CacheLimiterC *c = NULL; - if(!c) + if (!c) c = new_MEM_CacheLimiter(imbuf_cache_destructor, NULL); return &c; diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 2719f2e296b..5ef783fe968 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -135,21 +135,23 @@ static int an_stringdec(const char *string, char* head, char *tail, unsigned sho len=strlen(string); nume = len; - for(i=len-1;i>=0;i--){ + for (i=len-1;i>=0;i--) { if (string[i]==PATHSEPERATOR) break; if (isdigit(string[i])) { - if (found){ + if (found) { nums=i; - } else{ + } + else { nume=i; nums=i; found=TRUE; } - } else{ + } + else { if (found) break; } } - if (found){ + if (found) { strcpy(tail ,&string[nume+1]); strcpy(head, string); head[nums]= '\0'; @@ -188,7 +190,7 @@ static void free_anim_avi (struct anim *anim) anim->pgf = NULL; } - for (i = 0; i < anim->avistreams; i++){ + for (i = 0; i < anim->avistreams; i++) { AVIStreamRelease(anim->pavi[i]); } anim->avistreams = 0; @@ -315,7 +317,8 @@ static int startavi (struct anim *anim) lpbi = (LPBITMAPINFOHEADER)abFormat; anim->avi->header->Height = lpbi->biHeight; anim->avi->header->Width = lpbi->biWidth; - } else { + } + else { FIXCC(avis.fccHandler); FIXCC(avis.fccType); printf("Can't find AVI decoder for type : %4.4hs/%4.4hs\n", @@ -333,11 +336,13 @@ static int startavi (struct anim *anim) // if ((anim->avistreams == 0) || (firstvideo == -1)) { avierror = AVI_ERROR_FORMAT; - } else { + } + else { avierror = AVI_ERROR_NONE; anim->firstvideo = firstvideo; } - } else { + } + else { AVIFileExit(); } } @@ -386,7 +391,8 @@ static ImBuf * avi_fetchibuf (struct anim *anim, int position) //Oh brother... } } - } else { + } + else { #else if (1) { #endif @@ -442,11 +448,11 @@ static int startffmpeg(struct anim * anim) do_init_ffmpeg(); - if(av_open_input_file(&pFormatCtx, anim->name, NULL, 0, NULL)!=0) { + if (av_open_input_file(&pFormatCtx, anim->name, NULL, 0, NULL)!=0) { return -1; } - if(av_find_stream_info(pFormatCtx)<0) { + if (av_find_stream_info(pFormatCtx)<0) { av_close_input_file(pFormatCtx); return -1; } @@ -457,7 +463,7 @@ static int startffmpeg(struct anim * anim) /* Find the video stream */ videoStream = -1; - for(i = 0; i < pFormatCtx->nb_streams; i++) + for (i = 0; i < pFormatCtx->nb_streams; i++) if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (streamcount > 0) { @@ -468,7 +474,7 @@ static int startffmpeg(struct anim * anim) break; } - if(videoStream==-1) { + if (videoStream==-1) { av_close_input_file(pFormatCtx); return -1; } @@ -477,14 +483,14 @@ static int startffmpeg(struct anim * anim) /* Find the decoder for the video stream */ pCodec = avcodec_find_decoder(pCodecCtx->codec_id); - if(pCodec == NULL) { + if (pCodec == NULL) { av_close_input_file(pFormatCtx); return -1; } pCodecCtx->workaround_bugs = 1; - if(avcodec_open(pCodecCtx, pCodec) < 0) { + if (avcodec_open(pCodecCtx, pCodec) < 0) { av_close_input_file(pFormatCtx); return -1; } @@ -554,7 +560,8 @@ static int startffmpeg(struct anim * anim) if (pCodecCtx->has_b_frames) { anim->preseek = 25; /* FIXME: detect gopsize ... */ - } else { + } + else { anim->preseek = 0; } @@ -588,7 +595,7 @@ static int startffmpeg(struct anim * anim) srcRange = srcRange || anim->pCodecCtx->color_range == AVCOL_RANGE_JPEG; inv_table = sws_getCoefficients(anim->pCodecCtx->colorspace); - if(sws_setColorspaceDetails(anim->img_convert_ctx, (int *)inv_table, srcRange, + if (sws_setColorspaceDetails(anim->img_convert_ctx, (int *)inv_table, srcRange, table, dstRange, brightness, contrast, saturation)) { printf("Warning: Could not set libswscale colorspace details.\n"); @@ -623,7 +630,7 @@ static void ffmpeg_postprocess(struct anim * anim) /* This means the data wasnt read properly, * this check stops crashing */ if (input->data[0]==0 && input->data[1]==0 - && input->data[2]==0 && input->data[3]==0){ + && input->data[2]==0 && input->data[3]==0) { fprintf(stderr, "ffmpeg_fetchibuf: " "data not read properly...\n"); return; @@ -646,7 +653,8 @@ static void ffmpeg_postprocess(struct anim * anim) anim->pCodecCtx->height) < 0) { filter_y = TRUE; - } else { + } + else { input = anim->pFrameDeinterlaced; } } @@ -701,7 +709,8 @@ static void ffmpeg_postprocess(struct anim * anim) } top -= 8 * w; } - } else { + } + else { int * dstStride = anim->pFrameRGB->linesize; uint8_t** dst = anim->pFrameRGB->data; int dstStride2[4] = { -dstStride[0], 0, 0, 0 }; @@ -735,7 +744,7 @@ static int ffmpeg_decode_video_frame(struct anim * anim) anim->next_packet.stream_index = -1; } - while((rval = av_read_frame(anim->pFormatCtx, &anim->next_packet)) >= 0) { + while ((rval = av_read_frame(anim->pFormatCtx, &anim->next_packet)) >= 0) { av_log(anim->pFormatCtx, AV_LOG_DEBUG, "%sREAD: strID=%d (VID: %d) dts=%lld pts=%lld " @@ -821,7 +830,8 @@ static void ffmpeg_decode_video_frame_scan( if (anim->next_pts == pts_to_search) { av_log(anim->pFormatCtx, AV_LOG_DEBUG, "SCAN HAPPY: we found our PTS!\n"); - } else { + } + else { av_log(anim->pFormatCtx, AV_LOG_ERROR, "SCAN UNHAPPY: PTS not matched!\n"); } @@ -900,7 +910,8 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position, tc_index, anim->curposition); pts_to_search = IMB_indexer_get_pts( tc_index, new_frame_index); - } else { + } + else { pts_to_search = (long long) floor(((double) position) / pts_time_base / frame_rate + 0.5); @@ -917,7 +928,7 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position, (long long int)pts_to_search,pts_time_base, frame_rate, st_time); if (anim->last_frame && - anim->last_pts <= pts_to_search && anim->next_pts > pts_to_search){ + anim->last_pts <= pts_to_search && anim->next_pts > pts_to_search) { av_log(anim->pFormatCtx, AV_LOG_DEBUG, "FETCH: frame repeat: last: %lld next: %lld\n", (long long int)anim->last_pts, @@ -935,7 +946,8 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position, "FETCH: within preseek interval (no index)\n"); ffmpeg_decode_video_frame_scan(anim, pts_to_search); - } else if (tc_index && + } + else if (tc_index && IMB_indexer_can_scan(tc_index, old_frame_index, new_frame_index)) { @@ -944,7 +956,8 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position, "(index tells us)\n"); ffmpeg_decode_video_frame_scan(anim, pts_to_search); - } else if (position != anim->curposition + 1) { + } + else if (position != anim->curposition + 1) { long long pos; int ret; @@ -969,14 +982,16 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position, -1, pos, AVSEEK_FLAG_BYTE); av_update_cur_dts(anim->pFormatCtx, v_st, dts); - } else { + } + else { av_log(anim->pFormatCtx, AV_LOG_DEBUG, "... using DTS pos\n"); ret = av_seek_frame(anim->pFormatCtx, anim->videoStream, dts, AVSEEK_FLAG_BACKWARD); } - } else { + } + else { pos = (long long) (position - anim->preseek) * AV_TIME_BASE / frame_rate; @@ -1021,10 +1036,12 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position, if (ret >= 0) { ffmpeg_decode_video_frame_scan(anim, pts_to_search); } - } else if (position == 0 && anim->curposition == -1) { + } + else if (position == 0 && anim->curposition == -1) { /* first frame without seeking special case... */ ffmpeg_decode_video_frame(anim); - } else { + } + else { av_log(anim->pFormatCtx, AV_LOG_DEBUG, "FETCH: no seek necessary, just continue...\n"); } diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index 1e13f5d913b..768aa518742 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -78,7 +78,8 @@ static int checkbmp(unsigned char *mem) if ((mem[0] == 'B') && (mem[1] == 'M')) { /* skip fileheader */ mem += BMP_FILEHEADER_SIZE; - } else { + } + else { } /* for systems where an int needs to be 4 bytes aligned */ @@ -138,7 +139,8 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags) if (flags & IB_test) { ibuf = IMB_allocImBuf(x, y, depth, 0); - } else { + } + else { ibuf = IMB_allocImBuf(x, y, depth, IB_rect); bmp = mem + skip; rect = (unsigned char *) ibuf->rect; @@ -154,7 +156,8 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags) rect += 4; bmp += 2; } - } else if (depth == 24) { + } + else if (depth == 24) { for (i = y; i > 0; i--) { int j; for (j = x ; j > 0; j--) { @@ -168,7 +171,8 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags) /* for 24-bit images, rows are padded to multiples of 4 */ bmp += x % 4; } - } else if (depth == 32) { + } + else if (depth == 32) { for (i = x * y; i > 0; i--) { rect[0] = bmp[2]; rect[1] = bmp[1]; diff --git a/source/blender/imbuf/intern/cache.c b/source/blender/imbuf/intern/cache.c index 3bac570da4e..ba9b118d185 100644 --- a/source/blender/imbuf/intern/cache.c +++ b/source/blender/imbuf/intern/cache.c @@ -106,8 +106,8 @@ static int imb_global_tile_cmp(const void *a_p, const void *b_p) const ImGlobalTile *a= a_p; const ImGlobalTile *b= b_p; - if(a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; - else if(a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; + if (a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; + else if (a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; else return 1; } @@ -123,8 +123,8 @@ static int imb_thread_tile_cmp(const void *a_p, const void *b_p) const ImThreadTile *a= a_p; const ImThreadTile *b= b_p; - if(a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; - else if(a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; + if (a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; + else if (a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; else return 1; } @@ -164,9 +164,9 @@ void imb_tile_cache_tile_free(ImBuf *ibuf, int tx, int ty) lookuptile.ty = ty; gtile= BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile); - if(gtile) { + if (gtile) { /* in case another thread is loading this */ - while(gtile->loading) + while (gtile->loading) ; BLI_ghash_remove(GLOBAL_CACHE.tilehash, gtile, NULL, NULL); @@ -189,7 +189,7 @@ static void imb_thread_cache_init(ImThreadTileCache *cache) cache->tilehash= BLI_ghash_new(imb_thread_tile_hash, imb_thread_tile_cmp, "imb_thread_cache_init gh"); /* pre-allocate all thread local tiles in unused list */ - for(a=0; a<IB_THREAD_CACHE_SIZE; a++) { + for (a=0; a<IB_THREAD_CACHE_SIZE; a++) { ttile= BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImThreadTile)); BLI_addtail(&cache->unused, ttile); } @@ -218,17 +218,17 @@ void imb_tile_cache_exit(void) ImGlobalTile *gtile; int a; - if(GLOBAL_CACHE.initialized) { - for(gtile=GLOBAL_CACHE.tiles.first; gtile; gtile=gtile->next) + if (GLOBAL_CACHE.initialized) { + 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); @@ -246,7 +246,7 @@ 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(); @@ -261,7 +261,7 @@ 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); @@ -275,7 +275,7 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl BLI_mutex_lock(&GLOBAL_CACHE.mutex); - if(replacetile) + if (replacetile) replacetile->refcount--; /* find tile in global cache */ @@ -284,7 +284,7 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl lookuptile.ty = ty; gtile= BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile); - if(gtile) { + if (gtile) { /* found tile. however it may be in the process of being loaded * by another thread, in that case we do stupid busy loop waiting * for the other thread to load the tile */ @@ -292,21 +292,21 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl BLI_mutex_unlock(&GLOBAL_CACHE.mutex); - while(gtile->loading) + while (gtile->loading) ; } else { /* not found, let's load it from disk */ /* first check if we hit the memory limit */ - if(GLOBAL_CACHE.maxmem && GLOBAL_CACHE.totmem > GLOBAL_CACHE.maxmem) { + 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) { + if (gtile) { /* found a tile to unload */ imb_global_cache_tile_unload(gtile); BLI_ghash_remove(GLOBAL_CACHE.tilehash, gtile, NULL, NULL); @@ -314,7 +314,7 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl } else { /* allocate a new tile or reuse unused */ - if(GLOBAL_CACHE.unused.first) { + if (GLOBAL_CACHE.unused.first) { gtile= GLOBAL_CACHE.unused.first; BLI_remlink(&GLOBAL_CACHE.unused, gtile); } @@ -356,9 +356,9 @@ static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf * int toffs= ibuf->xtiles*ty + tx; /* test if it is already in our thread local cache */ - if((ttile=cache->tiles.first)) { + 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 */ @@ -366,7 +366,7 @@ static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf * lookuptile.tx = tx; lookuptile.ty = ty; - if((ttile=BLI_ghash_lookup(cache->tilehash, &lookuptile))) { + if ((ttile=BLI_ghash_lookup(cache->tilehash, &lookuptile))) { BLI_remlink(&cache->tiles, ttile); BLI_addhead(&cache->tiles, ttile); @@ -375,7 +375,7 @@ static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf * } /* not found, have to do slow lookup in global cache */ - if(cache->unused.first == NULL) { + if (cache->unused.first == NULL) { ttile= cache->tiles.last; replacetile= ttile->global; BLI_remlink(&cache->tiles, ttile); @@ -412,12 +412,12 @@ void IMB_tiles_to_rect(ImBuf *ibuf) unsigned int *to, *from; int a, tx, ty, y, w, h; - for(a=0; a<ibuf->miptot; a++) { + for (a=0; a<ibuf->miptot; a++) { mipbuf= IMB_getmipmap(ibuf, a); /* don't call imb_addrectImBuf, it frees all mipmaps */ - if(!mipbuf->rect) { - if((mipbuf->rect = MEM_mapallocN(ibuf->x*ibuf->y*sizeof(unsigned int), "imb_addrectImBuf"))) { + if (!mipbuf->rect) { + if ((mipbuf->rect = MEM_mapallocN(ibuf->x*ibuf->y*sizeof(unsigned int), "imb_addrectImBuf"))) { mipbuf->mall |= IB_rect; mipbuf->flags |= IB_rect; } @@ -425,8 +425,8 @@ void IMB_tiles_to_rect(ImBuf *ibuf) break; } - for(ty=0; ty<mipbuf->ytiles; ty++) { - for(tx=0; tx<mipbuf->xtiles; tx++) { + for (ty=0; ty<mipbuf->ytiles; ty++) { + for (tx=0; tx<mipbuf->xtiles; tx++) { /* acquire tile through cache, this assumes cache is initialized, * which it is always now but it's a weak assumption ... */ gtile= imb_global_cache_get_tile(mipbuf, tx, ty, NULL); @@ -439,7 +439,7 @@ void IMB_tiles_to_rect(ImBuf *ibuf) w= (tx == mipbuf->xtiles-1)? mipbuf->x - tx*mipbuf->tilex: mipbuf->tilex; h= (ty == mipbuf->ytiles-1)? mipbuf->y - ty*mipbuf->tiley: mipbuf->tiley; - for(y=0; y<h; y++) { + for (y=0; y<h; y++) { memcpy(to, from, sizeof(unsigned int)*w); from += mipbuf->tilex; to += mipbuf->x; diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c index af964bb2bb3..c1222d3cea3 100644 --- a/source/blender/imbuf/intern/cineon/cineon_dpx.c +++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c @@ -154,7 +154,7 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon if (!logImage) return 0; - if(logImageSetByteConversion(logImage, &conversion)==0) { + if (logImageSetByteConversion(logImage, &conversion)==0) { printf("error setting args\n"); } @@ -184,7 +184,7 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon MEM_freeN(line); - if(is_alloc) { + if (is_alloc) { MEM_freeN(fbuf); } @@ -204,7 +204,7 @@ int imb_is_cineon(unsigned char *buf) ImBuf *imb_loadcineon(unsigned char *mem, size_t size, int flags) { - if(imb_is_cineon(mem)) + if (imb_is_cineon(mem)) return imb_load_dpx_cineon(mem, 1, size, flags); return NULL; } @@ -221,7 +221,7 @@ int imb_is_dpx(unsigned char *buf) ImBuf *imb_loaddpx(unsigned char *mem, size_t size, int flags) { - if(imb_is_dpx(mem)) + if (imb_is_dpx(mem)) return imb_load_dpx_cineon(mem, 0, size, flags); return NULL; } diff --git a/source/blender/imbuf/intern/cineon/cineonlib.c b/source/blender/imbuf/intern/cineon/cineonlib.c index a10d8c67051..ae9f8e0fe97 100644 --- a/source/blender/imbuf/intern/cineon/cineonlib.c +++ b/source/blender/imbuf/intern/cineon/cineonlib.c @@ -136,7 +136,8 @@ fillCineonImageInfo(CineonFile* cineon, CineonImageInformation* imageInfo) { if (cineon->depth == 1) { fillCineonChannelInfo(cineon, &imageInfo->channel[0], 0); - } else if (cineon->depth == 3) { + } + else if (cineon->depth == 3) { fillCineonChannelInfo(cineon, &imageInfo->channel[0], 1); fillCineonChannelInfo(cineon, &imageInfo->channel[1], 2); fillCineonChannelInfo(cineon, &imageInfo->channel[2], 3); @@ -215,7 +216,8 @@ dumpCineonFormatInfo(CineonFormatInformation* formatInfo) { d_printf("Packing %d,", formatInfo->packing); if (formatInfo->packing & 0x80) { d_printf(" multi pixel,"); - } else { + } + else { d_printf(" single pixel,"); } switch (formatInfo->packing & 0x7F) { @@ -231,13 +233,15 @@ dumpCineonFormatInfo(CineonFormatInformation* formatInfo) { d_printf("Sign %d,", formatInfo->signage); if (formatInfo->signage) { d_printf(" signed\n"); - } else { + } + else { d_printf(" unsigned\n"); } d_printf("Sense %d,", formatInfo->signage); if (formatInfo->signage) { d_printf(" negative\n"); - } else { + } + else { d_printf(" positive\n"); } d_printf("End of line padding %ld\n", (intptr_t)ntohl(formatInfo->line_padding)); @@ -362,7 +366,7 @@ cineonGetRowBytes(CineonFile* cineon, unsigned short* row, int y) { /* extract required pixels */ for (pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) { - if(cineon->params.doLogarithm) + if (cineon->params.doLogarithm) row[pixelIndex] = cineon->lut10_16[cineon->pixelBuffer[pixelIndex]]; else row[pixelIndex] = cineon->pixelBuffer[pixelIndex] << 6; @@ -381,7 +385,7 @@ cineonSetRowBytes(CineonFile* cineon, const unsigned short* row, int y) { /* put new pixels into pixelBuffer */ for (pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) { - if(cineon->params.doLogarithm) + if (cineon->params.doLogarithm) cineon->pixelBuffer[pixelIndex] = cineon->lut16_16[row[pixelIndex]]; else cineon->pixelBuffer[pixelIndex] = row[pixelIndex] >> 6; @@ -604,7 +608,8 @@ int cineonIsMemFileCineon(unsigned char *mem) if (num != ntohl(CINEON_FILE_MAGIC)) { return 0; - } else return 1; + } + else return 1; } CineonFile* @@ -763,7 +768,8 @@ cineonCreate(const char* filename, int width, int height, int depth) { shortFilename = strrchr(filename, '/'); if (shortFilename == 0) { shortFilename = filename; - } else { + } + else { ++shortFilename; } diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c index 01177b01178..c9b9901a495 100644 --- a/source/blender/imbuf/intern/cineon/dpxlib.c +++ b/source/blender/imbuf/intern/cineon/dpxlib.c @@ -142,7 +142,8 @@ fillDpxImageInfo( if (dpx->depth == 1) { fillDpxChannelInfo(dpx, &imageInfo->channel[0], 0); - } else if (dpx->depth == 3) { + } + else if (dpx->depth == 3) { fillDpxChannelInfo(dpx, &imageInfo->channel[0], 50); } } @@ -270,7 +271,8 @@ dpxGetRowBytes(DpxFile* dpx, unsigned short* row, int y) { dpx->pixelBuffer[pixelIndex+2] = t & 0x3ff; pixelIndex += 3; } - } else /* if (dpx->depth == 3) */ { + } + else /* if (dpx->depth == 3) */ { for (longIndex = 0; longIndex < readLongs; ++longIndex) { unsigned int t = ntohl(dpx->lineBuffer[longIndex]); t = t >> 2; @@ -286,7 +288,7 @@ dpxGetRowBytes(DpxFile* dpx, unsigned short* row, int y) { /* extract required pixels */ for (pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) { - if(dpx->params.doLogarithm) + if (dpx->params.doLogarithm) row[pixelIndex] = dpx->lut10_16[dpx->pixelBuffer[pixelIndex]]; else row[pixelIndex] = dpx->pixelBuffer[pixelIndex] << 6; @@ -329,7 +331,7 @@ dpxSetRowBytes(DpxFile* dpx, const unsigned short* row, int y) { /* put new pixels into pixelBuffer */ for (pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) { - if(dpx->params.doLogarithm) + if (dpx->params.doLogarithm) dpx->pixelBuffer[dpx->pixelBufferUsed + pixelIndex] = dpx->lut16_16[row[pixelIndex]]; else dpx->pixelBuffer[dpx->pixelBufferUsed + pixelIndex] = row[pixelIndex] >> 6; @@ -351,7 +353,8 @@ dpxSetRowBytes(DpxFile* dpx, const unsigned short* row, int y) { dpx->lineBuffer[longIndex] = htonl(t); pixelIndex += 3; } - } else { + } + else { for (longIndex = 0; longIndex < writeLongs; ++longIndex) { unsigned int t = dpx->pixelBuffer[pixelIndex+2] << 2 | (dpx->pixelBuffer[pixelIndex+1] << 12) | @@ -411,7 +414,8 @@ intern_dpxOpen(int mode, const char* bytestuff, int bufsize) { dpx->membuffer = 0; dpx->memcursor = 0; dpx->membuffersize = 0; - } else if (mode == LFMEMFILE) { + } + else if (mode == LFMEMFILE) { dpx->membuffer = (unsigned char *)bytestuff; dpx->memcursor = (unsigned char *)bytestuff; dpx->membuffersize = bufsize; @@ -625,7 +629,8 @@ dpxCreate(const char* filename, int width, int height, int depth) { shortFilename = strrchr(filename, '/'); if (shortFilename == 0) { shortFilename = filename; - } else { + } + else { ++shortFilename; } initDpxMainHeader(dpx, &header, shortFilename); diff --git a/source/blender/imbuf/intern/cineon/logImageLib.c b/source/blender/imbuf/intern/cineon/logImageLib.c index dc50d93bf18..f97df005fc8 100644 --- a/source/blender/imbuf/intern/cineon/logImageLib.c +++ b/source/blender/imbuf/intern/cineon/logImageLib.c @@ -56,7 +56,8 @@ logImageOpen(const char* filename, int cineon) { if (cineon) { return cineonOpen(filename); - } else { + } + else { return dpxOpen(filename); } return 0; @@ -67,7 +68,8 @@ logImageOpenFromMem(unsigned char *buffer, unsigned int size, int cineon) { if (cineon) { return cineonOpenFromMem(buffer, size); - } else { + } + else { return dpxOpenFromMem(buffer, size); } return 0; @@ -78,7 +80,8 @@ logImageCreate(const char* filename, int cineon, int width, int height, int dept { if (cineon) { return cineonCreate(filename, width, height, depth); - } else { + } + else { return dpxCreate(filename, width, height, depth); } return 0; @@ -171,7 +174,8 @@ logImageDump(const char* filename) #if 0 cineonDump(filename); #endif - } else if (magic == ntohl(DPX_FILE_MAGIC)) { + } + else if (magic == ntohl(DPX_FILE_MAGIC)) { dpxDump(filename); } } diff --git a/source/blender/imbuf/intern/cineon/logmemfile.c b/source/blender/imbuf/intern/cineon/logmemfile.c index 289dd0357a4..3db4241cc14 100644 --- a/source/blender/imbuf/intern/cineon/logmemfile.c +++ b/source/blender/imbuf/intern/cineon/logmemfile.c @@ -39,10 +39,12 @@ int logimage_fseek(void* logfile, intptr_t offsett, int origin) if (origin==SEEK_SET) { if (offset > file->membuffersize) return 1; file->memcursor = file->membuffer + offset; - } else if (origin==SEEK_END) { + } + else if (origin==SEEK_END) { if (offset > file->membuffersize) return 1; file->memcursor = (file->membuffer + file->membuffersize) - offset; - } else if (origin==SEEK_CUR) { + } + else if (origin==SEEK_CUR) { uintptr_t pos = (uintptr_t)file->membuffer - (uintptr_t)file->memcursor; if (pos + offset > file->membuffersize) return 1; if (pos < 0) return 1; diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index bd9b32e77f4..8f8c6311b30 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -118,7 +118,7 @@ DitherContext *create_dither_context(int w, float factor) di->error_buf= MEM_callocN(4*(w+1)*sizeof(int), "dithering error"); di->e= di->error_buf; - for(i=0; i<4; ++i) + for (i=0; i<4; ++i) di->v[i]= di->v0[i]= di->v1[i]= 1024.0f*(BLI_frand()-0.5f); return di; @@ -134,7 +134,7 @@ static void dither_finish_row(DitherContext *di) { int i; - for(i=0; i<4; i++) + for (i=0; i<4; i++) di->v[i]= di->v0[i]= di->v1[i] = 0; di->e= di->error_buf; @@ -200,114 +200,114 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, BLI_assert(profile_from != IB_PROFILE_NONE); BLI_init_srgb_conversion(); - if(dither) + if (dither) di= create_dither_context(width, dither); - for(y = 0; y < height; y++) { - if(channels_from == 1) { + for (y = 0; y < height; y++) { + if (channels_from == 1) { /* single channel input */ const float *from = rect_from + stride_from*y; uchar *to = rect_to + 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] = FTOCHAR(from[0]); } - else if(channels_from == 3) { + else if (channels_from == 3) { /* RGB input */ const float *from = rect_from + stride_from*y*3; uchar *to = rect_to + stride_to*y*4; - if(profile_to == profile_from) { + if (profile_to == profile_from) { /* no color space conversion */ - for(x = 0; x < width; x++, from+=3, to+=4) { + for (x = 0; x < width; x++, from+=3, to+=4) { rgb_float_to_uchar(to, from); to[3] = 255; } } - else if(profile_to == IB_PROFILE_SRGB) { + else if (profile_to == IB_PROFILE_SRGB) { /* convert from linear to sRGB */ - for(x = 0; x < width; x++, from+=3, to+=4) { + for (x = 0; x < width; x++, from+=3, to+=4) { linearrgb_to_srgb_v3_v3(tmp, from); rgb_float_to_uchar(to, tmp); to[3] = 255; } } - else if(profile_to == IB_PROFILE_LINEAR_RGB) { + else if (profile_to == IB_PROFILE_LINEAR_RGB) { /* convert from sRGB to linear */ - for(x = 0; x < width; x++, from+=3, to+=4) { + for (x = 0; x < width; x++, from+=3, to+=4) { srgb_to_linearrgb_v3_v3(tmp, from); rgb_float_to_uchar(to, tmp); to[3] = 255; } } } - else if(channels_from == 4) { + else if (channels_from == 4) { /* RGBA input */ const float *from = rect_from + stride_from*y*4; uchar *to = rect_to + stride_to*y*4; - if(profile_to == profile_from) { + if (profile_to == profile_from) { /* no color space conversion */ - if(dither) { - for(x = 0; x < width; x++, from+=4, to+=4) + if (dither) { + for (x = 0; x < width; x++, from+=4, to+=4) float_to_byte_dither_v4(to, from, di); } 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) { + else if (profile_to == IB_PROFILE_SRGB) { /* convert from linear to sRGB */ unsigned short us[4]; - if(dither && predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) { + if (dither && predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { linearrgb_to_srgb_ushort4_predivide(us, from); ushort_to_byte_dither_v4(to, us, di); } } - else if(dither) { - for(x = 0; x < width; x++, from+=4, to+=4) { + else if (dither) { + for (x = 0; x < width; x++, from+=4, to+=4) { linearrgb_to_srgb_ushort4(us, from); ushort_to_byte_dither_v4(to, us, di); } } - else if(predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) { + else if (predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { linearrgb_to_srgb_ushort4_predivide(us, from); ushort_to_byte_v4(to, us); } } else { - for(x = 0; x < width; x++, from+=4, to+=4) { + for (x = 0; x < width; x++, from+=4, to+=4) { linearrgb_to_srgb_ushort4(us, from); ushort_to_byte_v4(to, us); } } } - else if(profile_to == IB_PROFILE_LINEAR_RGB) { + else if (profile_to == IB_PROFILE_LINEAR_RGB) { /* convert from sRGB to linear */ - if(dither && predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) { + if (dither && predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { srgb_to_linearrgb_predivide_v4(tmp, from); float_to_byte_dither_v4(to, tmp, di); } } - else if(dither) { - for(x = 0; x < width; x++, from+=4, to+=4) { + else if (dither) { + for (x = 0; x < width; x++, from+=4, to+=4) { srgb_to_linearrgb_v4(tmp, from); float_to_byte_dither_v4(to, tmp, di); } } - else if(predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) { + else if (predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { srgb_to_linearrgb_predivide_v4(tmp, from); rgba_float_to_uchar(to, tmp); } } 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(tmp, from); rgba_float_to_uchar(to, tmp); } @@ -315,11 +315,11 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, } } - if(dither) + if (dither) dither_finish_row(di); } - if(dither) + if (dither) clear_dither_context(di); } @@ -338,38 +338,38 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from, BLI_init_srgb_conversion(); /* RGBA input */ - for(y = 0; y < height; y++) { + for (y = 0; y < height; y++) { const uchar *from = rect_from + stride_from*y*4; float *to = rect_to + stride_to*y*4; - if(profile_to == profile_from) { + 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) { + else if (profile_to == IB_PROFILE_LINEAR_RGB) { /* convert sRGB to linear */ - if(predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) { + if (predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { srgb_to_linearrgb_uchar4_predivide(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_uchar4(to, from); } } } - else if(profile_to == IB_PROFILE_SRGB) { + else if (profile_to == IB_PROFILE_SRGB) { /* convert linear to sRGB */ - if(predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) { + if (predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { rgba_uchar_to_float(tmp, from); linearrgb_to_srgb_predivide_v4(to, tmp); } } else { - for(x = 0; x < width; x++, from+=4, to+=4) { + for (x = 0; x < width; x++, from+=4, to+=4) { rgba_uchar_to_float(tmp, from); linearrgb_to_srgb_v4(to, tmp); } @@ -389,74 +389,74 @@ void IMB_buffer_float_from_float(float *rect_to, const float *rect_from, BLI_assert(profile_to != IB_PROFILE_NONE); BLI_assert(profile_from != IB_PROFILE_NONE); - if(channels_from==1) { + if (channels_from==1) { /* single channel input */ - for(y = 0; y < height; y++) { + for (y = 0; y < height; y++) { const float *from = rect_from + stride_from*y; float *to = rect_to + 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) { + else if (channels_from == 3) { /* RGB input */ - for(y = 0; y < height; y++) { + for (y = 0; y < height; y++) { const float *from = rect_from + stride_from*y*3; float *to = rect_to + stride_to*y*4; - if(profile_to == profile_from) { + if (profile_to == profile_from) { /* no color space conversion */ - for(x = 0; x < width; x++, from+=3, to+=4) { + for (x = 0; x < width; x++, from+=3, to+=4) { copy_v3_v3(to, from); to[3] = 1.0f; } } - else if(profile_to == IB_PROFILE_LINEAR_RGB) { + else if (profile_to == IB_PROFILE_LINEAR_RGB) { /* convert from sRGB to linear */ - for(x = 0; x < width; x++, from+=3, to+=4) { + for (x = 0; x < width; x++, from+=3, to+=4) { srgb_to_linearrgb_v3_v3(to, from); to[3] = 1.0f; } } - else if(profile_to == IB_PROFILE_SRGB) { + else if (profile_to == IB_PROFILE_SRGB) { /* convert from linear to sRGB */ - for(x = 0; x < width; x++, from+=3, to+=4) { + for (x = 0; x < width; x++, from+=3, to+=4) { linearrgb_to_srgb_v3_v3(to, from); to[3] = 1.0f; } } } } - else if(channels_from == 4) { + else if (channels_from == 4) { /* RGBA input */ - for(y = 0; y < height; y++) { + for (y = 0; y < height; y++) { const float *from = rect_from + stride_from*y*4; float *to = rect_to + stride_to*y*4; - if(profile_to == profile_from) { + if (profile_to == profile_from) { /* same profile, copy */ memcpy(to, from, sizeof(float)*4*width); } - else if(profile_to == IB_PROFILE_LINEAR_RGB) { + 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) + if (predivide) { + 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) { + else if (profile_to == IB_PROFILE_SRGB) { /* convert from linear to sRGB */ - if(predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) + if (predivide) { + 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); } } @@ -477,42 +477,42 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from, BLI_assert(profile_from != IB_PROFILE_NONE); /* always RGBA input */ - for(y = 0; y < height; y++) { + for (y = 0; y < height; y++) { const uchar *from = rect_from + stride_from*y*4; uchar *to = rect_to + stride_to*y*4; - if(profile_to == profile_from) { + if (profile_to == profile_from) { /* same profile, copy */ memcpy(to, from, sizeof(uchar)*4*width); } - else if(profile_to == IB_PROFILE_LINEAR_RGB) { + 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) { + if (predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { rgba_uchar_to_float(tmp, from); srgb_to_linearrgb_predivide_v4(tmp, tmp); rgba_float_to_uchar(to, tmp); } } else { - for(x = 0; x < width; x++, from+=4, to+=4) { + for (x = 0; x < width; x++, from+=4, to+=4) { rgba_uchar_to_float(tmp, from); srgb_to_linearrgb_v4(tmp, tmp); rgba_float_to_uchar(to, tmp); } } } - else if(profile_to == IB_PROFILE_SRGB) { + else if (profile_to == IB_PROFILE_SRGB) { /* convert from linear to sRGB */ - if(predivide) { - for(x = 0; x < width; x++, from+=4, to+=4) { + if (predivide) { + for (x = 0; x < width; x++, from+=4, to+=4) { rgba_uchar_to_float(tmp, from); linearrgb_to_srgb_predivide_v4(tmp, tmp); rgba_float_to_uchar(to, tmp); } } else { - for(x = 0; x < width; x++, from+=4, to+=4) { + for (x = 0; x < width; x++, from+=4, to+=4) { rgba_uchar_to_float(tmp, from); linearrgb_to_srgb_v4(tmp, tmp); rgba_float_to_uchar(to, tmp); @@ -530,17 +530,17 @@ void IMB_rect_from_float(ImBuf *ibuf) int profile_from; /* 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 (ibuf->rect==NULL) imb_addrectImBuf(ibuf); /* determine profiles */ - if(ibuf->profile == IB_PROFILE_LINEAR_RGB) + if (ibuf->profile == IB_PROFILE_LINEAR_RGB) profile_from = IB_PROFILE_LINEAR_RGB; - else if(ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) + else if (ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) profile_from = IB_PROFILE_SRGB; else BLI_assert(0); @@ -563,17 +563,17 @@ void IMB_partial_rect_from_float(ImBuf *ibuf, float *buffer, int x, int y, int w int profile_from; /* 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); /* determine profiles */ - if(ibuf->profile == IB_PROFILE_LINEAR_RGB) + if (ibuf->profile == IB_PROFILE_LINEAR_RGB) profile_from = IB_PROFILE_LINEAR_RGB; - else if(ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) + else if (ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) profile_from = IB_PROFILE_SRGB; else BLI_assert(0); @@ -600,15 +600,15 @@ void IMB_float_from_rect(ImBuf *ibuf) int profile_from; /* verify if we byte and float buffers */ - if(ibuf->rect==NULL) + if (ibuf->rect==NULL) return; - if(ibuf->rect_float==NULL) - if(imb_addrectfloatImBuf(ibuf) == 0) + if (ibuf->rect_float==NULL) + if (imb_addrectfloatImBuf(ibuf) == 0) return; /* determine profiles */ - if(ibuf->profile == IB_PROFILE_NONE) + if (ibuf->profile == IB_PROFILE_NONE) profile_from = IB_PROFILE_LINEAR_RGB; else profile_from = IB_PROFILE_SRGB; @@ -624,7 +624,7 @@ void IMB_float_from_rect_simple(ImBuf *ibuf) { int predivide= (ibuf->flags & IB_cm_predivide); - if(ibuf->rect_float==NULL) + if (ibuf->rect_float==NULL) imb_addrectfloatImBuf(ibuf); IMB_buffer_float_from_byte(ibuf->rect_float, (uchar*)ibuf->rect, @@ -637,22 +637,22 @@ void IMB_convert_profile(ImBuf *ibuf, int profile) int predivide= (ibuf->flags & IB_cm_predivide); int profile_from, profile_to; - if(ibuf->profile == profile) + if (ibuf->profile == profile) return; /* determine profiles */ - if(ibuf->profile == IB_PROFILE_LINEAR_RGB) + if (ibuf->profile == IB_PROFILE_LINEAR_RGB) profile_from = IB_PROFILE_LINEAR_RGB; - else if(ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) + else if (ELEM(ibuf->profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) profile_from = IB_PROFILE_SRGB; else { BLI_assert(0); profile_from = IB_PROFILE_SRGB; /* dummy, should never happen */ } - if(profile == IB_PROFILE_LINEAR_RGB) + if (profile == IB_PROFILE_LINEAR_RGB) profile_to = IB_PROFILE_LINEAR_RGB; - else if(ELEM(profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) + else if (ELEM(profile, IB_PROFILE_SRGB, IB_PROFILE_NONE)) profile_to = IB_PROFILE_SRGB; else { BLI_assert(0); @@ -660,13 +660,13 @@ void IMB_convert_profile(ImBuf *ibuf, int profile) } /* do conversion */ - if(ibuf->rect_float) { + if (ibuf->rect_float) { IMB_buffer_float_from_float(ibuf->rect_float, ibuf->rect_float, 4, profile_to, profile_from, predivide, ibuf->x, ibuf->y, ibuf->x, ibuf->x); } - if(ibuf->rect) { + if (ibuf->rect) { IMB_buffer_byte_from_byte((uchar*)ibuf->rect, (uchar*)ibuf->rect, profile_to, profile_from, predivide, ibuf->x, ibuf->y, ibuf->x, ibuf->x); @@ -684,21 +684,21 @@ float *IMB_float_profile_ensure(ImBuf *ibuf, int profile, int *alloc) int profile_from, profile_to; /* determine profiles */ - if(ibuf->profile == IB_PROFILE_NONE) + if (ibuf->profile == IB_PROFILE_NONE) profile_from = IB_PROFILE_LINEAR_RGB; else profile_from = IB_PROFILE_SRGB; - if(profile == IB_PROFILE_NONE) + if (profile == IB_PROFILE_NONE) profile_to = IB_PROFILE_LINEAR_RGB; else profile_to = IB_PROFILE_SRGB; - if(profile_from == profile_to) { + if (profile_from == profile_to) { /* simple case, just allocate the buffer and return */ *alloc= 0; - if(ibuf->rect_float == NULL) + if (ibuf->rect_float == NULL) IMB_float_from_rect(ibuf); return ibuf->rect_float; @@ -708,7 +708,7 @@ float *IMB_float_profile_ensure(ImBuf *ibuf, int profile, int *alloc) float *fbuf= MEM_mallocN(ibuf->x * ibuf->y * sizeof(float) * 4, "IMB_float_profile_ensure"); *alloc= 1; - if(ibuf->rect_float == NULL) { + if (ibuf->rect_float == NULL) { IMB_buffer_float_from_byte(fbuf, (uchar*)ibuf->rect, profile_to, profile_from, predivide, ibuf->x, ibuf->y, ibuf->x, ibuf->x); @@ -732,13 +732,13 @@ void IMB_color_to_bw(ImBuf *ibuf) uchar *rct= (uchar*)ibuf->rect; int i; - if(rctf) { - for(i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) + if (rctf) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) rctf[0]= rctf[1]= rctf[2]= rgb_to_grayscale(rctf); } - if(rct) { - for(i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) + if (rct) { + for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) rct[0]= rct[1]= rct[2]= rgb_to_grayscale_byte(rct); } } @@ -746,7 +746,7 @@ void IMB_color_to_bw(ImBuf *ibuf) void IMB_buffer_float_clamp(float *buf, int width, int height) { int i, total = width*height*4; - for(i = 0; i < total; i++){ + for (i = 0; i < total; i++) { buf[i] = MIN2(1.0, buf[i]); } } @@ -760,7 +760,7 @@ void IMB_saturation(ImBuf * ibuf, float sat) float *rctf= ibuf->rect_float; float hsv[3]; - if(rct) { + if (rct) { float rgb[3]; for (i = ibuf->x * ibuf->y; i > 0; i--, rct+=4) { rgb_uchar_to_float(rgb, rct); @@ -770,7 +770,7 @@ void IMB_saturation(ImBuf * ibuf, float sat) } } - if(rctf) { + if (rctf) { for (i = ibuf->x * ibuf->y; i > 0; i--, rctf+=4) { rgb_to_hsv(rctf[0], rctf[1], rctf[2], hsv, hsv+1, hsv+2); hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rctf, rctf+1, rctf+2); diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c index c03736f4b0a..9ece4bd9f6d 100644 --- a/source/blender/imbuf/intern/filetype.c +++ b/source/blender/imbuf/intern/filetype.c @@ -94,8 +94,8 @@ void imb_filetypes_init(void) { ImFileType *type; - for(type=IMB_FILE_TYPES; type->is_a; type++) - if(type->init) + for (type=IMB_FILE_TYPES; type->is_a; type++) + if (type->init) type->init(); } @@ -103,8 +103,8 @@ void imb_filetypes_exit(void) { ImFileType *type; - for(type=IMB_FILE_TYPES; type->is_a; type++) - if(type->exit) + for (type=IMB_FILE_TYPES; type->is_a; type++) + if (type->exit) type->exit(); } diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 0d821126492..a93f47db9a3 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -54,10 +54,10 @@ static void filtrow(unsigned char *point, int x) { unsigned int c1,c2,c3,error; - if (x>1){ + if (x>1) { c1 = c2 = *point; error = 2; - for(x--;x>0;x--){ + for (x--;x>0;x--) { c3 = point[4]; c1 += (c2<<1) + c3 + error; error = c1 & 3; @@ -74,9 +74,9 @@ static void filtrowf(float *point, int x) { float c1,c2,c3; - if (x>1){ + if (x>1) { c1 = c2 = *point; - for(x--;x>0;x--){ + for (x--;x>0;x--) { c3 = point[4]; c1 += (c2 * 2) + c3; *point = 0.25f*c1; @@ -95,11 +95,11 @@ static void filtcolum(unsigned char *point, int y, int skip) unsigned int c1,c2,c3,error; unsigned char *point2; - if (y>1){ + if (y>1) { c1 = c2 = *point; point2 = point; error = 2; - for(y--;y>0;y--){ + for (y--;y>0;y--) { point2 += skip; c3 = *point2; c1 += (c2<<1) + c3 +error; @@ -117,10 +117,10 @@ static void filtcolumf(float *point, int y, int skip) { float c1,c2,c3, *point2; - if (y>1){ + if (y>1) { c1 = c2 = *point; point2 = point; - for(y--;y>0;y--){ + for (y--;y>0;y--) { point2 += skip; c3 = *point2; c1 += (c2 * 2) + c3; @@ -146,7 +146,7 @@ void IMB_filtery(struct ImBuf *ibuf) y = ibuf->y; skip = x<<2; - for (;x>0;x--){ + for (;x>0;x--) { if (point) { if (ibuf->planes > 24) filtcolum(point,y,skip); point++; @@ -184,7 +184,7 @@ void imb_filterx(struct ImBuf *ibuf) y = ibuf->y; skip = (x<<2) - 3; - for (;y>0;y--){ + for (;y>0;y--) { if (point) { if (ibuf->planes > 24) filtrow(point,x); point++; @@ -216,7 +216,7 @@ void IMB_filterN(ImBuf *out, ImBuf *in) rowlen= in->x; - for(y=0; y<in->y; y++) { + for (y=0; y<in->y; y++) { /* setup rows */ row2= (char*)(in->rect + y*rowlen); row1= (y == 0)? row2: row2 - 4*rowlen; @@ -224,8 +224,8 @@ void IMB_filterN(ImBuf *out, ImBuf *in) cp= (char *)(out->rect + y*rowlen); - for(x=0; x<rowlen; x++) { - if(x == 0) { + for (x=0; x<rowlen; x++) { + if (x == 0) { r11 = row1; r21 = row1; r31 = row1; @@ -236,7 +236,7 @@ void IMB_filterN(ImBuf *out, ImBuf *in) r31 = row1-4; } - if(x == rowlen-1) { + if (x == rowlen-1) { r13 = row1; r23 = row1; r33 = row1; @@ -273,26 +273,27 @@ void IMB_mask_filter_extend(char *mask, int width, int height) /* make a copy, to prevent flooding */ temprect= MEM_dupallocN(mask); - for(y=1; y<=height; y++) { + for (y=1; y<=height; y++) { /* setup rows */ 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++) { + for (x=0; x<rowlen; x++) { if (mask[((y-1)*rowlen)+x]==0) { if (*row1 || *row2 || *row3 || *(row1+1) || *(row3+1) ) { mask[((y-1)*rowlen)+x] = FILTER_MASK_MARGIN; - } else if((x!=rowlen-1) && (*(row1+2) || *(row2+2) || *(row3+2)) ) { + } + else if ((x!=rowlen-1) && (*(row1+2) || *(row2+2) || *(row3+2)) ) { mask[((y-1)*rowlen)+x] = FILTER_MASK_MARGIN; } } - if(x!=0) { + if (x!=0) { row1++; row2++; row3++; } } @@ -305,18 +306,19 @@ void IMB_mask_clear(ImBuf *ibuf, char *mask, int val) { int x,y; if (ibuf->rect_float) { - for(x=0; x<ibuf->x; x++) { - for(y=0; y<ibuf->y; y++) { + for (x=0; x<ibuf->x; x++) { + for (y=0; y<ibuf->y; y++) { if (mask[ibuf->x*y + x] == val) { float *col= ibuf->rect_float + 4*(ibuf->x*y + x); col[0] = col[1] = col[2] = col[3] = 0.0f; } } } - } else { + } + else { /* char buffer */ - for(x=0; x<ibuf->x; x++) { - for(y=0; y<ibuf->y; y++) { + for (x=0; x<ibuf->x; x++) { + for (y=0; y<ibuf->y; y++) { if (mask[ibuf->x*y + x] == val) { char *col= (char *)(ibuf->rect + ibuf->x*y + x); col[0] = col[1] = col[2] = col[3] = 0; @@ -328,7 +330,7 @@ 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) return -1; /* return bad index */ + if (x<0 || x>=w || y<0 || y>=h) return -1; /* return bad index */ else return y*w+x; } @@ -336,13 +338,13 @@ static int check_pixel_assigned(const void *buffer, const char *mask, const int { int res = 0; - if(index>=0) { + if (index>=0) { const int alpha_index = depth*index+(depth-1); - if(mask!=NULL) { + if (mask!=NULL) { res = mask[index]!=0 ? 1 : 0; } - else if( (is_float && ((const float *) buffer)[alpha_index]!=0.0f) || + else if ( (is_float && ((const float *) buffer)[alpha_index]!=0.0f) || (!is_float && ((const unsigned char *) buffer)[alpha_index]!=0) ) { res=1; } @@ -375,8 +377,8 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) #if 0 k= 0; - for(i = -n; i <= n; i++) - for(j = -n; j <= n; j++) + for (i = -n; i <= n; i++) + for (j = -n; j <= n; j++) weight[k++] = sqrt((float) i * i + j * j); #endif @@ -385,16 +387,16 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) weight[6]=1; weight[7]=2; weight[8]=1; /* run passes */ - for(r = 0; cannot_early_out == 1 && r < filter; r++) { + for (r = 0; cannot_early_out == 1 && r < filter; r++) { int x, y; cannot_early_out = 0; - for(y= 0; y<height; y++) { - for(x= 0; x<width; x++) { + for (y= 0; y<height; y++) { + for (x= 0; x<width; x++) { const int index= filter_make_index(x, y, width, height); /* only update unassigned pixels */ - if(!check_pixel_assigned(srcbuf, srcmask, index, depth, is_float)) { + if (!check_pixel_assigned(srcbuf, srcmask, index, depth, is_float)) { float tmp[4]; float wsum=0; float acc[4]={0,0,0,0}; @@ -404,24 +406,24 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) check_pixel_assigned(srcbuf, srcmask, filter_make_index(x+1, y, width, height), depth, is_float) || check_pixel_assigned(srcbuf, srcmask, filter_make_index(x, y-1, width, height), depth, is_float) || check_pixel_assigned(srcbuf, srcmask, filter_make_index(x, y+1, width, height), depth, is_float)) { - for(i= -n; i<=n; i++) { - for(j=-n; j<=n; j++) { - if(i != 0 || j != 0) { + for (i= -n; i<=n; i++) { + for (j=-n; j<=n; j++) { + if (i != 0 || j != 0) { const int tmpindex= filter_make_index(x+i, y+j, width, height); - if(check_pixel_assigned(srcbuf, srcmask, tmpindex, depth, is_float)) { - if(is_float) { - for(c=0; c<depth; c++) + if (check_pixel_assigned(srcbuf, srcmask, tmpindex, depth, is_float)) { + if (is_float) { + 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]; } } @@ -429,21 +431,21 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) } } - if(wsum!=0) { - for(c=0; c<depth; c++) + if (wsum!=0) { + for (c=0; c<depth; c++) acc[c]/= wsum; - if(is_float) { - for(c=0; c<depth; c++) + if (is_float) { + for (c=0; c<depth; c++) ((float *) dstbuf)[depth*index+c] = acc[c]; } else { - for(c=0; c<depth; c++) { + for (c=0; c<depth; c++) { ((unsigned char *) dstbuf)[depth*index+c]= acc[c] > 255 ? 255 : (acc[c] < 0 ? 0 : ((unsigned char) (acc[c]+0.5f))); } } - if(dstmask!=NULL) dstmask[index]=FILTER_MASK_MARGIN; /* assigned */ + if (dstmask!=NULL) dstmask[index]=FILTER_MASK_MARGIN; /* assigned */ cannot_early_out = 1; } } @@ -453,12 +455,12 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) /* keep the original buffer up to date. */ memcpy(srcbuf, dstbuf, bsize); - if(dstmask!=NULL) memcpy(srcmask, dstmask, width*height); + if (dstmask!=NULL) memcpy(srcmask, dstmask, width*height); } /* free memory */ MEM_freeN(dstbuf); - if(dstmask!=NULL) MEM_freeN(dstmask); + if (dstmask!=NULL) MEM_freeN(dstmask); } /* threadsafe version, only recreates existing maps */ @@ -471,9 +473,9 @@ void IMB_remakemipmap(ImBuf *ibuf, int use_filter) while(curmap < IB_MIPMAP_LEVELS) { - if(ibuf->mipmap[curmap]) { + if (ibuf->mipmap[curmap]) { - if(use_filter) { + if (use_filter) { ImBuf *nbuf= IMB_allocImBuf(hbuf->x, hbuf->y, 32, IB_rect); IMB_filterN(nbuf, hbuf); imb_onehalf_no_alloc(ibuf->mipmap[curmap], nbuf); @@ -485,10 +487,10 @@ void IMB_remakemipmap(ImBuf *ibuf, int use_filter) 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++; @@ -506,7 +508,7 @@ void IMB_makemipmap(ImBuf *ibuf, int use_filter) ibuf->miptot= 1; while(curmap < IB_MIPMAP_LEVELS) { - if(use_filter) { + if (use_filter) { ImBuf *nbuf= IMB_allocImBuf(hbuf->x, hbuf->y, 32, IB_rect); IMB_filterN(nbuf, hbuf); ibuf->mipmap[curmap] = IMB_onehalf(nbuf); @@ -519,7 +521,7 @@ void IMB_makemipmap(ImBuf *ibuf, int use_filter) hbuf= ibuf->mipmap[curmap]; hbuf->miplevel= curmap+1; - if(hbuf->x <= 2 && hbuf->y <= 2) + if (hbuf->x <= 2 && hbuf->y <= 2) break; curmap++; @@ -537,18 +539,18 @@ void IMB_premultiply_rect(unsigned int *rect, char planes, int w, int h) char *cp; int x, y, val; - if(planes == 24) { /* put alpha at 255 */ + 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); - 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) { val= cp[3]; cp[0]= (cp[0]*val)>>8; cp[1]= (cp[1]*val)>>8; @@ -563,17 +565,17 @@ void IMB_premultiply_rect_float(float *rect_float, char planes, int w, int h) float val, *cp; int x, y; - if(planes==24) { /* put alpha at 1.0 */ + if (planes==24) { /* put alpha at 1.0 */ cp= rect_float; - 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]= 1.0; } else { cp= rect_float; - 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) { val= cp[3]; cp[0]= cp[0]*val; cp[1]= cp[1]*val; @@ -586,13 +588,13 @@ void IMB_premultiply_rect_float(float *rect_float, char planes, 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->planes, ibuf->x, ibuf->y); } diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c index 0462c998e44..85bd3137ddc 100644 --- a/source/blender/imbuf/intern/imageprocess.c +++ b/source/blender/imbuf/intern/imageprocess.c @@ -156,11 +156,11 @@ void bicubic_interpolation_color(struct ImBuf *in, unsigned char *outI, float *o wy[2] = P(b- 1); wy[3] = P(b- 2); - for(n= -1; n<= 2; n++){ + for (n= -1; n<= 2; n++) { x1= i+n; CLAMP(x1, 0, in->x-1); wx = P(n-a); - for(m= -1; m<= 2; m++){ + for (m= -1; m<= 2; m++) { y1= j+m; CLAMP(y1, 0, in->y-1); /* normally we could do this */ @@ -189,8 +189,8 @@ void bicubic_interpolation_color(struct ImBuf *in, unsigned char *outI, float *o #if 0 /* older, slower function, works the same as above */ - for(n= -1; n<= 2; n++){ - for(m= -1; m<= 2; m++){ + for (n= -1; n<= 2; n++) { + for (m= -1; m<= 2; m++) { x1= i+n; y1= j+m; if (x1>0 && x1 < in->x && y1>0 && y1<in->y) { @@ -338,11 +338,11 @@ void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *outI, fl if (x2<0 || x1>in->x-1 || y2<0 || y1>in->y-1) return; /* wrap interpolation pixels - main difference from bilinear_interpolation_color */ - if(x1<0)x1= in->x+x1; - if(y1<0)y1= in->y+y1; + if (x1<0)x1= in->x+x1; + if (y1<0)y1= in->y+y1; - if(x2>=in->x)x2= x2-in->x; - if(y2>=in->y)y2= y2-in->y; + if (x2>=in->x)x2= x2-in->x; + if (y2>=in->y)y2= y2-in->y; if (outF) { // sample including outside of edges of image @@ -423,7 +423,8 @@ void neareast_interpolation_color(struct ImBuf *in, unsigned char *outI, float * outF[2]= 0.0f; outF[3]= 0.0f; } - } else { + } + else { dataI= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x1; if (outI) { outI[0]= dataI[0]; diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index dcbce6d028c..33ff769217d 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -122,7 +122,8 @@ void IMB_index_builder_proc_frame(anim_index_builder * fp, e.pts = pts; fp->proc_frame(fp, buffer, data_size, &e); - } else { + } + else { IMB_index_builder_add_entry(fp, frameno, seek_pos, seek_pos_dts, pts); } @@ -138,7 +139,8 @@ void IMB_index_builder_finish(anim_index_builder * fp, int rollback) if (rollback) { unlink(fp->temp_name); - } else { + } + else { unlink(fp->name); BLI_rename(fp->temp_name, fp->name); } @@ -260,14 +262,16 @@ int IMB_indexer_get_frame_index(struct anim_index * idx, int frameno) first = middle; ++first; len = len - half - 1; - } else { + } + else { len = half; } } if (first == idx->num_entries) { return idx->num_entries - 1; - } else { + } + else { return first; } } @@ -361,7 +365,8 @@ static void get_index_dir(struct anim * anim, char * index_dir) BLI_splitdirstring(index_dir, fname); BLI_join_dirfile(index_dir, FILE_MAXDIR, index_dir, "BL_proxy"); BLI_join_dirfile(index_dir, FILE_MAXDIR, index_dir, fname); - } else { + } + else { BLI_strncpy(index_dir, anim->index_dir, FILE_MAXDIR); } } @@ -505,7 +510,8 @@ static struct proxy_output_ctx * alloc_proxy_output_ffmpeg( if (rv->codec->pix_fmts) { rv->c->pix_fmt = rv->codec->pix_fmts[0]; - } else { + } + else { rv->c->pix_fmt = PIX_FMT_YUVJ420P; } @@ -633,7 +639,8 @@ static int add_to_proxy_output_ffmpeg( } return 1; - } else { + } + else { return 0; } } @@ -686,7 +693,8 @@ static void free_proxy_output_ffmpeg(struct proxy_output_ctx * ctx, if (rollback) { unlink(fname_tmp); - } else { + } + else { get_proxy_filename(ctx->anim, ctx->proxy_size, fname, FALSE); unlink(fname); @@ -731,7 +739,7 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim, IMB_Tim memset(context->proxy_ctx, 0, sizeof(context->proxy_ctx)); memset(context->indexer, 0, sizeof(context->indexer)); - if(av_open_input_file(&context->iFormatCtx, anim->name, NULL, 0, NULL) != 0) { + if (av_open_input_file(&context->iFormatCtx, anim->name, NULL, 0, NULL) != 0) { MEM_freeN(context); return NULL; } @@ -747,7 +755,7 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim, IMB_Tim /* Find the video stream */ context->videoStream = -1; for (i = 0; i < context->iFormatCtx->nb_streams; i++) - if(context->iFormatCtx->streams[i]->codec->codec_type + if (context->iFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (streamcount > 0) { streamcount--; @@ -919,7 +927,7 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context, if (context->tcs_in_use & tc_types[i]) { int tc_frameno = frameno; - if(tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS) + if (tc_types[i] == IMB_TC_RECORD_RUN_NO_GAPS) tc_frameno = frameno_gapless; IMB_index_builder_proc_frame( @@ -1048,7 +1056,8 @@ static void index_rebuild_fallback_finish(FallbackIndexBuilderContext *context, if (stop) { unlink(fname_tmp); - } else { + } + else { unlink(fname); rename(fname_tmp, fname); } diff --git a/source/blender/imbuf/intern/indexer_dv.c b/source/blender/imbuf/intern/indexer_dv.c index 4ccd8ec464d..f0c38f6db06 100644 --- a/source/blender/imbuf/intern/indexer_dv.c +++ b/source/blender/imbuf/intern/indexer_dv.c @@ -139,7 +139,8 @@ static void parse_packet(indexer_dv_context * This, unsigned char * p) This->rec_curr_year = parse_bcd(&b, 8); if (This->rec_curr_year < 25) { This->rec_curr_year += 2000; - } else { + } + else { This->rec_curr_year += 1900; } This->got_record_date = 1; @@ -201,7 +202,7 @@ static void parse_audio_headers( { int i; - for(i = 0; i < 9; i++) { + for (i = 0; i < 9; i++) { if (target[3] != 0xff) { parse_packet(This, target + 3); } @@ -238,7 +239,8 @@ static void inc_frame(int * frame, time_t * t, int isPAL) if (isPAL && *frame >= 25) { (*t)++; *frame = 0; - } else if (!isPAL && *frame >= 30) { + } + else if (!isPAL && *frame >= 30) { (*t)++; *frame = 0; } @@ -308,7 +310,8 @@ static void proc_frame(indexer_dv_context * This, if (This->ref_time_read < 0) { This->ref_time_read = This->ref_time_read_new; This->curr_frame = 0; - } else { + } + else { if (This->ref_time_read_new - This->ref_time_read == 1) { This->curr_frame = 0; This->ref_time_read = This->ref_time_read_new; @@ -316,9 +319,11 @@ static void proc_frame(indexer_dv_context * This, fill_gap(This, isPAL); This->gap_frame = -1; } - } else if (This->ref_time_read_new == This->ref_time_read) { + } + else if (This->ref_time_read_new == This->ref_time_read) { // do nothing - } else { + } + else { This->gap_start = This->ref_time_read; This->gap_frame = This->curr_frame; This->ref_time_read = This->ref_time_read_new; @@ -347,7 +352,8 @@ static void indexer_dv_proc_frame(anim_index_builder * idx, if (This->curr_frame >= 0) { write_index(This, entry); inc_frame(&This->curr_frame, &This->ref_time_read, isPAL); - } else { + } + else { This->backbuffer[This->fsize++] = *entry; if (This->fsize >= 31) { int i; diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 38fc6f92c83..b4f1415207e 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -216,8 +216,8 @@ static void test_endian_zbuf(struct ImBuf *ibuf) int len; int *zval; - if( BIG_LONG(1) == 1 ) return; - if(ibuf->zbuf == NULL) return; + if ( BIG_LONG(1) == 1 ) return; + if (ibuf->zbuf == NULL) return; len= ibuf->x*ibuf->y; zval= ibuf->zbuf; @@ -262,7 +262,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) (void)size; /* unused */ - if(!imb_is_a_iris(mem)) return NULL; + if (!imb_is_a_iris(mem)) return NULL; /*printf("new iris\n");*/ @@ -270,14 +270,14 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) file_offset = 0; readheader(inf, &image); - if(image.imagic != IMAGIC) { + if (image.imagic != IMAGIC) { fprintf(stderr,"longimagedata: bad magic number in image file\n"); return(NULL); } rle = ISRLE(image.type); bpp = BPP(image.type); - if(bpp != 1 && bpp != 2) { + if (bpp != 1 && bpp != 2) { fprintf(stderr,"longimagedata: image must have 1 or 2 byte per pix chan\n"); return(NULL); } @@ -313,7 +313,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } cur = starttab[y+z*ysize]; } - if(badorder) + if (badorder) break; } @@ -325,9 +325,9 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) zbase = (unsigned int *)ibuf->zbuf; if (badorder) { - for(z=0; z<zsize; z++) { + for (z=0; z<zsize; z++) { lptr = base; - for(y=0; y<ysize; y++) { + for (y=0; y<ysize; y++) { file_offset = starttab[y+z*ysize]; rledat = file_data + file_offset; @@ -337,20 +337,21 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) lptr += xsize; } } - } else { + } + else { lptr = base; zptr = zbase; - for(y=0; y<ysize; y++) { + for (y=0; y<ysize; y++) { - for(z=0; z<zsize; z++) { + for (z=0; z<zsize; z++) { file_offset = starttab[y+z*ysize]; rledat = file_data + file_offset; file_offset += lengthtab[y+z*ysize]; - if(z<4) expandrow((uchar *)lptr, rledat, 3-z); - else if(z<8) expandrow((uchar *)zptr, rledat, 7-z); + if (z<4) expandrow((uchar *)lptr, rledat, 3-z); + else if (z<8) expandrow((uchar *)zptr, rledat, 7-z); } lptr += xsize; zptr += xsize; @@ -358,16 +359,17 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } - } else { /* bpp == 2 */ + } + else { /* bpp == 2 */ ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect)|IB_rectfloat); fbase = ibuf->rect_float; if (badorder) { - for(z=0; z<zsize; z++) { + for (z=0; z<zsize; z++) { fptr = fbase; - for(y=0; y<ysize; y++) { + for (y=0; y<ysize; y++) { file_offset = starttab[y+z*ysize]; rledat = file_data + file_offset; @@ -377,12 +379,13 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) fptr += xsize * 4; } } - } else { + } + else { fptr = fbase; - for(y=0; y<ysize; y++) { + for (y=0; y<ysize; y++) { - for(z=0; z<zsize; z++) { + for (z=0; z<zsize; z++) { file_offset = starttab[y+z*ysize]; @@ -400,7 +403,8 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) MEM_freeN(starttab); MEM_freeN(lengthtab); - } else { + } + else { if (bpp == 1) { ibuf = IMB_allocImBuf(xsize, ysize, 8 * zsize, IB_rect); @@ -412,12 +416,12 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) file_offset = 512; rledat = file_data + file_offset; - for(z = 0; z < zsize; z++) { + for (z = 0; z < zsize; z++) { - if(z<4) lptr = base; - else if(z<8) lptr= zbase; + if (z<4) lptr = base; + else if (z<8) lptr= zbase; - for(y = 0; y < ysize; y++) { + for (y = 0; y < ysize; y++) { interleaverow((uchar *)lptr, rledat, 3-z, xsize); rledat += xsize; @@ -426,7 +430,8 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } } - } else { /* bpp == 2 */ + } + else { /* bpp == 2 */ ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect)|IB_rectfloat); @@ -435,11 +440,11 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) file_offset = 512; rledat = file_data + file_offset; - for(z = 0; z < zsize; z++) { + for (z = 0; z < zsize; z++) { fptr = fbase; - for(y = 0; y < ysize; y++) { + for (y = 0; y < ysize; y++) { interleaverow2(fptr, rledat, 3-z, xsize); rledat += xsize * 2; @@ -455,14 +460,15 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) if (bpp == 1) { uchar * rect; - if (image.zsize == 1){ + if (image.zsize == 1) { rect = (uchar *) ibuf->rect; for (x = ibuf->x * ibuf->y; x > 0; x--) { rect[0] = 255; rect[1] = rect[2] = rect[3]; rect += 4; } - } else if (image.zsize == 2){ + } + else if (image.zsize == 2) { /* grayscale with alpha */ rect = (uchar *) ibuf->rect; for (x = ibuf->x * ibuf->y; x > 0; x--) { @@ -470,7 +476,8 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) rect[1] = rect[2] = rect[3]; rect += 4; } - } else if (image.zsize == 3){ + } + else if (image.zsize == 3) { /* add alpha */ rect = (uchar *) ibuf->rect; for (x = ibuf->x * ibuf->y; x > 0; x--) { @@ -479,16 +486,18 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } } - } else { /* bpp == 2 */ + } + else { /* bpp == 2 */ - if (image.zsize == 1){ + if (image.zsize == 1) { fbase = ibuf->rect_float; for (x = ibuf->x * ibuf->y; x > 0; x--) { fbase[0] = 1; fbase[1] = fbase[2] = fbase[3]; fbase += 4; } - } else if (image.zsize == 2){ + } + else if (image.zsize == 2) { /* grayscale with alpha */ fbase = ibuf->rect_float; for (x = ibuf->x * ibuf->y; x > 0; x--) { @@ -496,7 +505,8 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) fbase[1] = fbase[2] = fbase[3]; fbase += 4; } - } else if (image.zsize == 3){ + } + else if (image.zsize == 3) { /* add alpha */ fbase = ibuf->rect_float; for (x = ibuf->x * ibuf->y; x > 0; x--) { @@ -558,7 +568,7 @@ static void expandrow2(float *optr, unsigned char *iptr, int z) if ( !(count = (pixel & 0x7f)) ) return; - if(pixel & 0x80) { + if (pixel & 0x80) { while(count>=8) { optr[0*4] = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF; optr[1*4] = ((iptr[2]<<8) | (iptr[3]<<0))/(float)0xFFFF; @@ -577,7 +587,8 @@ static void expandrow2(float *optr, unsigned char *iptr, int z) iptr+=2; optr+=4; } - } else { + } + else { pixel_f = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF; iptr += 2; @@ -610,7 +621,7 @@ static void expandrow(unsigned char *optr, unsigned char *iptr, int z) pixel = *iptr++; if ( !(count = (pixel & 0x7f)) ) return; - if(pixel & 0x80) { + if (pixel & 0x80) { while(count>=8) { optr[0*4] = iptr[0]; optr[1*4] = iptr[1]; @@ -628,7 +639,8 @@ static void expandrow(unsigned char *optr, unsigned char *iptr, int z) *optr = *iptr++; optr+=4; } - } else { + } + else { pixel = *iptr++; while(count>=8) { optr[0*4] = pixel; @@ -675,7 +687,7 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons goodwrite = 1; outf = BLI_fopen(name, "wb"); - if(!outf) return 0; + if (!outf) return 0; tablen = ysize*zsize*sizeof(int); @@ -689,7 +701,7 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons memset(image, 0, sizeof(IMAGE)); image->imagic = IMAGIC; image->type = RLE(1); - if(zsize>1) + if (zsize>1) image->dim = 3; else image->dim = 2; @@ -710,14 +722,14 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons len = compressrow((uchar *)lumbuf,rlebuf,CHANOFFSET(z),xsize); } else { - if(z<4) { + if (z<4) { len = compressrow((uchar *)lptr, rlebuf,CHANOFFSET(z),xsize); } - else if(z<8 && zptr) { + else if (z<8 && zptr) { len = compressrow((uchar *)zptr, rlebuf,CHANOFFSET(z-4),xsize); } } - if(len>rlebuflen) { + if (len>rlebuflen) { fprintf(stderr,"output_iris: rlebuf is too small - bad poop\n"); exit(1); } @@ -727,7 +739,7 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons pos += len; } lptr += xsize; - if(zptr) zptr += xsize; + if (zptr) zptr += xsize; } fseek(outf,512,SEEK_SET); @@ -739,7 +751,7 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons 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"); diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index 87450170c66..275d19d518c 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -157,7 +157,7 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) opj_cio_close(cio); - if((image->numcomps * image->x1 * image->y1) == 0) { + if ((image->numcomps * image->x1 * image->y1) == 0) { fprintf(stderr,"\nError: invalid raw image parameters\n"); return NULL; } @@ -195,7 +195,7 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) ibuf= IMB_allocImBuf(w, h, planes, use_float ? IB_rectfloat : IB_rect); if (ibuf==NULL) { - if(dinfo) + if (dinfo) opj_destroy_decompress(dinfo); return NULL; } @@ -217,7 +217,8 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) else rect_float[3]= 1.0f; } - } else { + } + else { /* rgb or rgba 12bits+ */ for (i = 0; i < w * h; i++, rect_float+=4) { index = w * h - ((i) / (w) + 1) * w + (i) % (w); @@ -233,7 +234,8 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) } } - } else { + } + else { unsigned char *rect= (unsigned char *)ibuf->rect; if (image->numcomps < 3) { @@ -248,7 +250,8 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) else rect[3]= 255; } - } else { + } + else { /* 8bit rgb or rgba */ for (i = 0; i < w * h; i++, rect+=4) { int index = w * h - ((i) / (w) + 1) * w + (i) % (w); @@ -266,7 +269,7 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) } /* free remaining structures */ - if(dinfo) { + if (dinfo) { opj_destroy_decompress(dinfo); } @@ -365,13 +368,13 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag int i; float temp_rate; - switch (parameters->cp_cinema){ + switch (parameters->cp_cinema) { case CINEMA2K_24: case CINEMA2K_48: - if(parameters->numresolution > 6){ + if (parameters->numresolution > 6) { parameters->numresolution = 6; } - if (!((image->comps[0].w == 2048) || (image->comps[0].h == 1080))){ + if (!((image->comps[0].w == 2048) || (image->comps[0].h == 1080))) { fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 " "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n", image->comps[0].w,image->comps[0].h); @@ -380,15 +383,16 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag break; case CINEMA4K_24: - if(parameters->numresolution < 1){ - parameters->numresolution = 1; - }else if(parameters->numresolution > 7){ - parameters->numresolution = 7; - } - if (!((image->comps[0].w == 4096) || (image->comps[0].h == 2160))){ - fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" - "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", - image->comps[0].w,image->comps[0].h); + if (parameters->numresolution < 1) { + parameters->numresolution = 1; + } + else if (parameters->numresolution > 7) { + parameters->numresolution = 7; + } + if (!((image->comps[0].w == 4096) || (image->comps[0].h == 2160))) { + fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" + "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", + image->comps[0].w,image->comps[0].h); parameters->cp_rsiz = STD_RSIZ; } parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution); @@ -398,21 +402,23 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag break; } - switch (parameters->cp_cinema){ + switch (parameters->cp_cinema) { case CINEMA2K_24: case CINEMA4K_24: - for(i=0 ; i<parameters->tcp_numlayers ; i++){ + for (i=0 ; i<parameters->tcp_numlayers ; i++) { temp_rate = 0; - if (img_fol->rates[i]== 0){ + if (img_fol->rates[i]== 0) { parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ + } + else { temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_24_CS ){ + if (temp_rate > CINEMA_24_CS ) { parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ + } + else { parameters->tcp_rates[i]= img_fol->rates[i]; } } @@ -421,18 +427,20 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag break; case CINEMA2K_48: - for(i=0 ; i<parameters->tcp_numlayers ; i++){ + for (i=0 ; i<parameters->tcp_numlayers ; i++) { temp_rate = 0; - if (img_fol->rates[i]== 0){ + if (img_fol->rates[i]== 0) { parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ + } + else { temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_48_CS ){ + if (temp_rate > CINEMA_48_CS ) { parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ + } + else { parameters->tcp_rates[i]= img_fol->rates[i]; } } @@ -477,9 +485,9 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) parameters->cp_cinema= CINEMA2K_24; } } - if (parameters->cp_cinema){ + if (parameters->cp_cinema) { img_fol.rates = (float*)MEM_mallocN(parameters->tcp_numlayers * sizeof(float), "jp2_rates"); - for(i=0; i< parameters->tcp_numlayers; i++){ + for (i=0; i< parameters->tcp_numlayers; i++) { img_fol.rates[i] = parameters->tcp_rates[i]; } cinema_parameters(parameters); @@ -508,7 +516,7 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) /* initialize image components */ memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); - for(i = 0; i < numcomps; i++) { + for (i = 0; i < numcomps; i++) { cmptparm[i].prec = prec; cmptparm[i].bpp = prec; cmptparm[i].sgnd = 0; @@ -519,7 +527,7 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) } /* create the image */ image = opj_image_create(numcomps, &cmptparm[0], color_space); - if(!image) { + if (!image) { printf("Error: opj_image_create() failed\n"); return NULL; } @@ -545,9 +553,9 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) switch (prec) { case 8: /* Convert blenders float color channels to 8,12 or 16bit ints */ - for(y=h-1; y>=0; y--) { + for (y=h-1; y>=0; y--) { y_row = y*w; - for(x=0; x<w; x++, rect_float+=4) { + for (x=0; x<w; x++, rect_float+=4) { i = y_row + x; if (ibuf->profile == IB_PROFILE_LINEAR_RGB) @@ -565,9 +573,9 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) break; case 12: - for(y=h-1; y>=0; y--) { + for (y=h-1; y>=0; y--) { y_row = y*w; - for(x=0; x<w; x++, rect_float+=4) { + for (x=0; x<w; x++, rect_float+=4) { i = y_row + x; if (ibuf->profile == IB_PROFILE_LINEAR_RGB) @@ -584,9 +592,9 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) } break; case 16: - for(y=h-1; y>=0; y--) { + for (y=h-1; y>=0; y--) { y_row = y*w; - for(x=0; x<w; x++, rect_float+=4) { + for (x=0; x<w; x++, rect_float+=4) { i = y_row + x; if (ibuf->profile == IB_PROFILE_LINEAR_RGB) @@ -603,13 +611,14 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) } break; } - } else { + } + else { /* just use rect*/ switch (prec) { case 8: - for(y=h-1; y>=0; y--) { + for (y=h-1; y>=0; y--) { y_row = y*w; - for(x=0; x<w; x++, rect+=4) { + for (x=0; x<w; x++, rect+=4) { i = y_row + x; image->comps[0].data[i] = rect[0]; @@ -622,9 +631,9 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) break; case 12: /* Up Sampling, a bit pointless but best write the bit depth requested */ - for(y=h-1; y>=0; y--) { + for (y=h-1; y>=0; y--) { y_row = y*w; - for(x=0; x<w; x++, rect+=4) { + for (x=0; x<w; x++, rect+=4) { i = y_row + x; image->comps[0].data[i]= UPSAMPLE_8_TO_12(rect[0]); @@ -636,9 +645,9 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) } break; case 16: - for(y=h-1; y>=0; y--) { + for (y=h-1; y>=0; y--) { y_row = y*w; - for(x=0; x<w; x++, rect+=4) { + for (x=0; x<w; x++, rect+=4) { i = y_row + x; image->comps[0].data[i]= UPSAMPLE_8_TO_16(rect[0]); @@ -655,7 +664,7 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) /* Decide if MCT should be used */ parameters->tcp_mct = image->numcomps == 3 ? 1 : 0; - if(parameters->cp_cinema){ + if (parameters->cp_cinema) { cinema_setup_encoder(parameters,image,&img_fol); } diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 75a5f274413..3f3ebc5872d 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -158,7 +158,7 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) { my_src_ptr src = (my_src_ptr) cinfo->src; - if(num_bytes > 0) { + if (num_bytes > 0) { // prevent skipping over file end size_t skip_size = (size_t)num_bytes <= src->pub.bytes_in_buffer ? num_bytes : src->pub.bytes_in_buffer; @@ -372,8 +372,8 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f } marker= cinfo->marker_list; - while(marker) { - if(marker->marker != JPEG_COM) + while (marker) { + if (marker->marker != JPEG_COM) goto next_stamp_marker; /* @@ -385,7 +385,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f * That is why we need split it to the * common key/value here. */ - if(strncmp((char *) marker->data, "Blender", 7)) { + if (strncmp((char *) marker->data, "Blender", 7)) { /* * Maybe the file have text that * we don't know "what it's", in that @@ -432,7 +432,7 @@ next_stamp_marker: } jpeg_destroy((j_common_ptr) cinfo); - if(ibuf) { + if (ibuf) { ibuf->ftype = ibuf_ftype; ibuf->profile = IB_PROFILE_SRGB; } @@ -447,7 +447,7 @@ ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags) struct my_error_mgr jerr; ImBuf * ibuf; - if(!imb_is_a_jpeg(buffer)) return NULL; + if (!imb_is_a_jpeg(buffer)) return NULL; cinfo->err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = jpeg_error; @@ -488,11 +488,11 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf) memcpy(neogeo + 6, &ibuf_ftype, 4); jpeg_write_marker(cinfo, 0xe1, (JOCTET*) neogeo, 10); - if(ibuf->metadata) { + if (ibuf->metadata) { /* key + max value + "Blender" */ text= MEM_mallocN(530, "stamp info read"); iptr= ibuf->metadata; - while(iptr) { + while (iptr) { if (!strcmp (iptr->key, "None")) { jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen (iptr->value) + 1); goto next_stamp_info; @@ -520,11 +520,11 @@ next_stamp_info: cinfo->input_components * cinfo->image_width, "jpeg row_pointer"); - for(y = ibuf->y - 1; y >= 0; y--){ + for (y = ibuf->y - 1; y >= 0; y--) { rect = (uchar *) (ibuf->rect + y * ibuf->x); buffer = row_pointer[0]; - switch(cinfo->in_color_space){ + switch(cinfo->in_color_space) { case JCS_RGB: for (x = 0; x < ibuf->x; x++) { *buffer++ = rect[0]; @@ -577,7 +577,7 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct if (ibuf->planes == 32) cinfo->in_color_space = JCS_UNKNOWN; #endif - switch(cinfo->in_color_space){ + switch(cinfo->in_color_space) { case JCS_RGB: cinfo->input_components = 3; break; diff --git a/source/blender/imbuf/intern/metadata.c b/source/blender/imbuf/intern/metadata.c index 2b6fed59004..0da7358b55b 100644 --- a/source/blender/imbuf/intern/metadata.c +++ b/source/blender/imbuf/intern/metadata.c @@ -95,7 +95,8 @@ int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* value if (!img->metadata) { img->metadata = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); info = img->metadata; - } else { + } + else { info = img->metadata; last = info; while (info) { diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index 67d9a602d12..24317278a43 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -120,7 +120,7 @@ static void check_unused_keys(MovieCache *cache) BLI_ghashIterator_step(iter); - if(!item->ibuf) + if (!item->ibuf) BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree); } @@ -154,22 +154,22 @@ 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->miptot) { + for (a= 0; a<ibuf->miptot; a++) { + if (ibuf->mipmap[a]) size+= IMB_get_size_in_memory(ibuf->mipmap[a]); } } - if(ibuf->tiles) { + if (ibuf->tiles) { size+= sizeof(unsigned int)*ibuf->ytiles*ibuf->xtiles; } @@ -181,7 +181,7 @@ 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; @@ -194,7 +194,7 @@ void IMB_moviecache_init(void) void IMB_moviecache_destruct(void) { - if(limitor) + if (limitor) delete_MEM_CacheLimiter(limitor); } @@ -223,7 +223,7 @@ void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf) MovieCacheKey *key; MovieCacheItem *item; - if(!limitor) + if (!limitor) IMB_moviecache_init(); IMB_refImBuf(ibuf); @@ -251,7 +251,7 @@ void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf) /* cache limiter can't remove unused keys which points to destoryed values */ check_unused_keys(cache); - if(cache->points) { + if (cache->points) { MEM_freeN(cache->points); cache->points= NULL; } @@ -266,10 +266,10 @@ ImBuf* IMB_moviecache_get(MovieCache *cache, void *userkey) key.userkey= userkey; item= (MovieCacheItem*)BLI_ghash_lookup(cache->hash, &key); - if(item) { + if (item) { item->last_access= cache->curtime++; - if(item->ibuf) { + if (item->ibuf) { MEM_CacheLimiter_touch(item->c_handle); IMB_refImBuf(item->ibuf); @@ -288,7 +288,7 @@ 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); MEM_freeN(cache); @@ -300,20 +300,21 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_ *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->proxy!=proxy || cache->render_flags!=render_flags) { + if (cache->points) MEM_freeN(cache->points); cache->points= NULL; } - if(cache->points) { + if (cache->points) { *totseg_r= cache->totseg; *points_r= cache->points; - } else { + } + else { int totframe= BLI_ghash_size(cache->hash); int *frames= MEM_callocN(totframe*sizeof(int), "movieclip cache frames"); int a, totseg= 0; @@ -326,10 +327,10 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_ MovieCacheItem *item= BLI_ghashIterator_getValue(iter); int framenr, curproxy, curflags; - if(item->ibuf) { + 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; } @@ -341,30 +342,30 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_ qsort(frames, totframe, sizeof(int), compare_int); /* count */ - for(a= 0; a<totframe; a++) { - if(a && frames[a]-frames[a-1]!=1) + for (a= 0; a<totframe; a++) { + if (a && frames[a]-frames[a-1]!=1) totseg++; - if(a==totframe-1) + if (a==totframe-1) totseg++; } - if(totseg) { + if (totseg) { int b, *points; points= MEM_callocN(2*sizeof(int)*totseg, "movieclip cache segments"); /* fill */ - for(a= 0, b= 0; a<totframe; a++) { - if(a==0) + for (a= 0, b= 0; a<totframe; a++) { + if (a==0) points[b++]= frames[a]; - if(a && frames[a]-frames[a-1]!=1) { + 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]; } diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 78c7c672e22..de935c7cc42 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -114,7 +114,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) compression= compression < 0 ? 0 : (compression > 9 ? 9 : compression); /* for prints */ - if(flags & IB_mem) + if (flags & IB_mem) name= "<memory>"; bytesperpixel = (ibuf->planes + 7) >> 3; @@ -256,7 +256,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) } - if(ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { + if (ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { png_set_pHYs(png_ptr, info_ptr, (unsigned int)(ibuf->ppm[0] + 0.5), (unsigned int)(ibuf->ppm[1] + 0.5), PNG_RESOLUTION_METER); } @@ -366,7 +366,8 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags) png_set_palette_to_rgb(png_ptr); if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { bytesperpixel = 4; - } else { + } + else { bytesperpixel = 3; } break; @@ -392,8 +393,8 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags) int unit_type; png_uint_32 xres, yres; - if(png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) - if(unit_type == PNG_RESOLUTION_METER) { + if (png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type)) + if (unit_type == PNG_RESOLUTION_METER) { ibuf->ppm[0]= xres; ibuf->ppm[1]= yres; } @@ -470,7 +471,7 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags) if (flags & IB_metadata) { png_text* text_chunks; int count = png_get_text(png_ptr, info_ptr, &text_chunks, NULL); - for(i = 0; i < count; i++) { + for (i = 0; i < count; i++) { IMB_metadata_add_field(ibuf, text_chunks[i].key, text_chunks[i].text); ibuf->flags |= IB_metadata; } diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 42e4db54f3f..5b093dc6cac 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -262,7 +262,8 @@ static int fwritecolrs(FILE* file, int width, int channels, unsigned char* ibufs fcol[RED] = fpscan[j]; fcol[GRN] = (channels >= 2)? fpscan[j+1]: fpscan[j]; fcol[BLU] = (channels >= 3)? fpscan[j+2]: fpscan[j]; - } else { + } + else { fcol[RED] = (float)ibufscan[j] / 255.f; fcol[GRN] = (float)((channels >= 2)? ibufscan[j+1]: ibufscan[j]) / 255.f; fcol[BLU] = (float)((channels >= 3)? ibufscan[j+2]: ibufscan[j]) / 255.f; @@ -343,9 +344,9 @@ 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 (y=height-1;y>=0;y--) { @@ -354,8 +355,8 @@ int imb_savehdr(struct ImBuf *ibuf, const char *name, int flags) printf("HDR write error\n"); return 0; } - if(cp) cp-= ibuf->channels*width; - if(fp) fp-= ibuf->channels*width; + if (cp) cp-= ibuf->channels*width; + 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 2ee389a42f6..61f90f7a97a 100644 --- a/source/blender/imbuf/intern/readimage.c +++ b/source/blender/imbuf/intern/readimage.c @@ -55,16 +55,16 @@ ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags, const c ImBuf *ibuf; ImFileType *type; - if(mem == NULL) { + if (mem == NULL) { fprintf(stderr, "%s: NULL pointer\n", __func__); return NULL; } - for(type=IMB_FILE_TYPES; type->is_a; type++) { - if(type->load) { + for (type=IMB_FILE_TYPES; type->is_a; type++) { + if (type->load) { ibuf= type->load(mem, size, flags); - if(ibuf) { - if(flags & IB_premul) { + if (ibuf) { + if (flags & IB_premul) { IMB_premultiply_alpha(ibuf); ibuf->flags |= IB_premul; } @@ -85,19 +85,19 @@ ImBuf *IMB_loadifffile(int file, int flags, const char *descr) unsigned char *mem; size_t size; - if(file == -1) return NULL; + if (file == -1) return NULL; size= BLI_file_descriptor_size(file); mem= mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); - if(mem==(unsigned char*)-1) { + if (mem==(unsigned char*)-1) { fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr); return NULL; } ibuf= IMB_ibImageFromMemory(mem, size, flags, descr); - if(munmap(mem, size)) + if (munmap(mem, size)) fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr); return ibuf; @@ -106,12 +106,12 @@ ImBuf *IMB_loadifffile(int file, int flags, const char *descr) 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) { + if (flags & IB_tilecache) { BLI_strncpy(filename, name, IB_FILENAME_SIZE); - if(!BLI_replace_extension(filename, IB_FILENAME_SIZE, ".tx")) + if (!BLI_replace_extension(filename, IB_FILENAME_SIZE, ".tx")) return; - if(BLI_file_older(name, filename)) + if (BLI_file_older(name, filename)) return; } @@ -127,16 +127,16 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags) imb_cache_filename(filepath_tx, filepath, flags); file = BLI_open(filepath_tx, O_BINARY|O_RDONLY, 0); - if(file < 0) return NULL; + if (file < 0) return NULL; ibuf= IMB_loadifffile(file, flags, filepath_tx); - if(ibuf) { + 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)); - if(flags & IB_fields) IMB_de_interlace(ibuf); + if (flags & IB_fields) IMB_de_interlace(ibuf); } close(file); @@ -153,11 +153,11 @@ 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 < 0) return NULL; + if (file < 0) return NULL; ibuf=IMB_loadifffile(file, flags|IB_test|IB_multilayer, filepath_tx); - if(ibuf) { + if (ibuf) { BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename)); } @@ -173,21 +173,21 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int unsigned char *mem; size_t size; - if(file == -1) return; + if (file == -1) return; size= BLI_file_descriptor_size(file); mem= mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); - if(mem==(unsigned char*)-1) { + if (mem==(unsigned char*)-1) { fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename); return; } - for(type=IMB_FILE_TYPES; type->is_a; type++) - if(type->load_tile && type->ftype(type, ibuf)) + for (type=IMB_FILE_TYPES; type->is_a; type++) + if (type->load_tile && type->ftype(type, ibuf)) type->load_tile(ibuf, mem, size, tx, ty, rect); - if(munmap(mem, size)) + if (munmap(mem, size)) fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename); } @@ -196,7 +196,7 @@ 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 < 0) return; + if (file < 0) 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 888fe5713d1..6ea84fd6717 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -61,11 +61,11 @@ static void blend_color_add(char *cp, char *cp1, char *cp2, int fac) int temp; temp= cp1[0] + ((fac*cp2[0])/255); - if(temp>254) cp[0]= 255; else cp[0]= temp; + if (temp>254) cp[0]= 255; else cp[0]= temp; temp= cp1[1] + ((fac*cp2[1])/255); - if(temp>254) cp[1]= 255; else cp[1]= temp; + if (temp>254) cp[1]= 255; else cp[1]= temp; temp= cp1[2] + ((fac*cp2[2])/255); - if(temp>254) cp[2]= 255; else cp[2]= temp; + if (temp>254) cp[2]= 255; else cp[2]= temp; } static void blend_color_sub(char *cp, char *cp1, char *cp2, int fac) @@ -73,11 +73,11 @@ static void blend_color_sub(char *cp, char *cp1, char *cp2, int fac) int temp; temp= cp1[0] - ((fac*cp2[0])/255); - if(temp<0) cp[0]= 0; else cp[0]= temp; + if (temp<0) cp[0]= 0; else cp[0]= temp; temp= cp1[1] - ((fac*cp2[1])/255); - if(temp<0) cp[1]= 0; else cp[1]= temp; + if (temp<0) cp[1]= 0; else cp[1]= temp; temp= cp1[2] - ((fac*cp2[2])/255); - if(temp<0) cp[2]= 0; else cp[2]= temp; + if (temp<0) cp[2]= 0; else cp[2]= temp; } static void blend_color_mul(char *cp, char *cp1, char *cp2, int fac) @@ -348,7 +348,8 @@ void IMB_rectblend(struct ImBuf *dbuf, struct ImBuf *sbuf, int destx, if (do_char) srect = sbuf->rect + srcy * sbuf->x + srcx; if (do_float) srectf = sbuf->rect_float + (srcy * sbuf->x + srcx)*4; srcskip = sbuf->x; - } else { + } + else { srect = drect; srectf = drectf; srcskip = destskip; @@ -452,7 +453,7 @@ void IMB_rectfill(struct ImBuf *drect, const float col[4]) { int num; - if(drect->rect) { + if (drect->rect) { unsigned int *rrect = drect->rect; char ccol[4]; @@ -466,7 +467,7 @@ void IMB_rectfill(struct ImBuf *drect, const float col[4]) *rrect++ = *((unsigned int*)ccol); } - if(drect->rect_float) { + if (drect->rect_float) { float *rrectf = drect->rect_float; num = drect->x * drect->y; @@ -514,7 +515,8 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, chr = FTOCHAR(col[0]); chg = FTOCHAR(col[1]); chb = FTOCHAR(col[2]); - } else { + } + else { fr = col[0]*a; fg = col[1]*a; fb = col[2]*a; @@ -528,7 +530,8 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, pixel[1] = chg; pixel[2] = chb; pixel[3] = 255; - } else { + } + else { int alphatest; pixel[0] = (char)((fr + ((float)pixel[0]*aich))*255.0f); pixel[1] = (char)((fg + ((float)pixel[1]*aich))*255.0f); @@ -550,7 +553,8 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, pixel[1] = col[1]; pixel[2] = col[2]; pixel[3] = 1.0f; - } else { + } + else { float alphatest; pixel[0] = (col[0]*a) + (pixel[0]*ai); pixel[1] = (col[1]*a) + (pixel[1]*ai); diff --git a/source/blender/imbuf/intern/rotate.c b/source/blender/imbuf/intern/rotate.c index 7ca7445569f..8914d4ee64d 100644 --- a/source/blender/imbuf/intern/rotate.c +++ b/source/blender/imbuf/intern/rotate.c @@ -62,7 +62,7 @@ void IMB_flipy(struct ImBuf * ibuf) y >>= 1; - for(;y>0;y--) { + for (;y>0;y--) { memcpy(line, top, x*sizeof(int)); memcpy(top, bottom, x*sizeof(int)); memcpy(bottom, line, x*sizeof(int)); @@ -85,7 +85,7 @@ void IMB_flipy(struct ImBuf * ibuf) y >>= 1; - for(;y>0;y--) { + for (;y>0;y--) { memcpy(linef, topf, 4*x*sizeof(float)); memcpy(topf, bottomf, 4*x*sizeof(float)); memcpy(bottomf, linef, 4*x*sizeof(float)); @@ -108,16 +108,16 @@ void IMB_flipx(struct ImBuf * ibuf) y = ibuf->y; if (ibuf->rect) { - for(yi=y-1;yi>=0;yi--) { - for(xr=x-1, xl=0; xr>=xl; xr--, xl++) { + for (yi=y-1;yi>=0;yi--) { + for (xr=x-1, xl=0; xr>=xl; xr--, xl++) { SWAP(unsigned int, ibuf->rect[(x*yi)+xr], ibuf->rect[(x*yi)+xl]); } } } if (ibuf->rect_float) { - for(yi=y-1;yi>=0;yi--) { - for(xr=x-1, xl=0; xr>=xl; xr--, xl++) { + for (yi=y-1;yi>=0;yi--) { + for (xr=x-1, xl=0; xr>=xl; xr--, xl++) { memcpy(&px_f, &ibuf->rect_float[((x*yi)+xr)*4], 4*sizeof(float)); memcpy(&ibuf->rect_float[((x*yi)+xr)*4], &ibuf->rect_float[((x*yi)+xl)*4], 4*sizeof(float)); memcpy(&ibuf->rect_float[((x*yi)+xl)*4], &px_f, 4*sizeof(float)); diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index 361faa08b29..a7b994beef9 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -76,10 +76,10 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) _p1f = ibuf1->rect_float; destf= ibuf2->rect_float; - for(y=ibuf2->y;y>0;y--) { + for (y=ibuf2->y;y>0;y--) { p1 = _p1; p1f = _p1f; - for(x = ibuf2->x; x>0; x--) { + for (x = ibuf2->x; x>0; x--) { if (do_rect) { a = *(p1++); b = *(p1++); @@ -136,7 +136,7 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1) p1f = (float *)ibuf1->rect_float; destf = (float *)ibuf2->rect_float; - for(i = ibuf1->y * ibuf1->x; i > 0; i--) { + for (i = ibuf1->y * ibuf1->x; i > 0; i--) { if (do_rect) { col = *p1++; *dest++ = col; @@ -195,7 +195,7 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) _p1f = (float *) ibuf1->rect_float; destf= (float *) ibuf2->rect_float; - for(y=ibuf2->y; y>0; y--) { + for (y=ibuf2->y; y>0; y--) { if (do_rect) { p1 = _p1; p2 = _p1 + (ibuf1->x << 2); @@ -204,7 +204,7 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) p1f = _p1f; p2f = _p1f + (ibuf1->x << 2); } - for(x = ibuf2->x; x > 0; x--) { + for (x = ibuf2->x; x > 0; x--) { if (do_rect) { a = *(p1++); b = *(p1++); @@ -263,15 +263,15 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1) p1f = (float *) ibuf1->rect_float; dest1f= (float *) ibuf2->rect_float; - for(y = ibuf1->y; y > 0; y--) { + for (y = ibuf1->y; y > 0; y--) { if (do_rect) { dest2 = dest1 + ibuf2->x; - for(x = ibuf2->x; x > 0; x--) *dest1++ = *dest2++ = *p1++; + 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--) *dest1f++ = *dest2f++ = *p1f++; + for (x = ibuf2->x * 4; x > 0; x--) *dest1f++ = *dest2f++ = *p1f++; dest1f = dest2f; } } @@ -301,7 +301,7 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) const short do_rect= (ibuf1->rect != NULL); const short do_float= (ibuf1->rect_float != NULL) && (ibuf2->rect_float != NULL); - if(do_rect && (ibuf2->rect == NULL)) { + if (do_rect && (ibuf2->rect == NULL)) { imb_addrectImBuf(ibuf2); } @@ -310,10 +310,10 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) p1 = (uchar *) ibuf1->rect; dest=(uchar *) ibuf2->rect; - for(y=ibuf2->y;y>0;y--) { + for (y=ibuf2->y;y>0;y--) { if (do_rect) p2 = p1 + (ibuf1->x << 2); if (do_float) p2f = p1f + (ibuf1->x << 2); - for(x=ibuf2->x;x>0;x--) { + for (x=ibuf2->x;x>0;x--) { if (do_rect) { dest[0] = (p1[0] + p2[0] + p1[4] + p2[4]) >> 2; dest[1] = (p1[1] + p2[1] + p1[5] + p2[5]) >> 2; @@ -335,7 +335,7 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) } if (do_rect) p1=p2; if (do_float) p1f=p2f; - if(ibuf1->x & 1) { + if (ibuf1->x & 1) { if (do_rect) p1+=4; if (do_float) p1f+=4; } @@ -567,7 +567,8 @@ static void q_scale_byte(unsigned char* in, unsigned char* out, int in_width, if (dst_width > in_width && dst_height > in_height) { enlarge_picture_byte(in, out, in_width, in_height, dst_width, dst_height); - } else if (dst_width < in_width && dst_height < in_height) { + } + else if (dst_width < in_width && dst_height < in_height) { shrink_picture_byte(in, out, in_width, in_height, dst_width, dst_height); } @@ -767,7 +768,8 @@ static void q_scale_float(float* in, float* out, int in_width, if (dst_width > in_width && dst_height > in_height) { enlarge_picture_float(in, out, in_width, in_height, dst_width, dst_height); - } else if (dst_width < in_width && dst_height < in_height) { + } + else if (dst_width < in_width && dst_height < in_height) { shrink_picture_float(in, out, in_width, in_height, dst_width, dst_height); } @@ -1511,7 +1513,7 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned if (newx == ibuf->x && newy == ibuf->y) return(ibuf); - if(do_rect) { + if (do_rect) { _newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf"); if (_newrect==NULL) return(ibuf); newrect = _newrect; @@ -1531,7 +1533,7 @@ struct ImBuf *IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned ofsy = 32768; for (y = newy; y > 0; y--) { - if(do_rect) { + if (do_rect) { rect = ibuf->rect; rect += (ofsy >> 16) * ibuf->x; } diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index 1801c1a8ef9..c8c4a4fd38c 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -126,13 +126,13 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI last = *rect++; this = *rect++; copy = last^this; - while (bytes > 0){ - if (copy){ + while (bytes > 0) { + if (copy) { do { last = this; this = *rect++; - if (last == this){ - if (this == rect[-3]){ /* three the same? */ + if (last == this) { + if (this == rect[-3]) { /* three the same? */ bytes --; /* set bytes */ break; } @@ -146,7 +146,7 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI temp = rect; rect = rectstart; - while (copy){ + while (copy) { last = copy; if (copy>=128) last = 128; copy -= last; @@ -160,8 +160,9 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI last = this; copy = FALSE; - } else { - while (*rect++ == this){ /* seek for first different byte */ + } + else { + while (*rect++ == this) { /* seek for first different byte */ if (--bytes == 0) break; /* oor end of line */ } rect --; @@ -170,14 +171,16 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI bytes --; this = *rect++; - while (copy){ - if (copy>128){ + while (copy) { + if (copy>128) { if (fputc(255,file) == EOF) return(0); copy -= 128; - } else { - if (copy == 1){ + } + else { + if (copy == 1) { if (fputc(0,file) == EOF) return(0); - } else if (fputc(127 + copy,file) == EOF) return(0); + } + else if (fputc(127 + copy,file) == EOF) return(0); copy = 0; } if (out(last,file) == EOF) return(0); @@ -201,28 +204,31 @@ static int dumptarga(struct ImBuf * ibuf, FILE * file) rect = (uchar *) ibuf->rect; if (ibuf->planes <= 8) { - while(size > 0){ + while(size > 0) { if (putc(*rect, file) == EOF) return (0); size--; rect += 4; } - } else if (ibuf->planes <= 16) { - while(size > 0){ + } + else if (ibuf->planes <= 16) { + while(size > 0) { putc(rect[0], file); if (putc(rect[1], file) == EOF) return (0); size--; rect += 4; } - } else if (ibuf->planes <= 24) { - while(size > 0){ + } + else if (ibuf->planes <= 24) { + while(size > 0) { putc(rect[2], file); putc(rect[1], file); if (putc(rect[0], file) == EOF) return (0); size--; rect += 4; } - } else if (ibuf->planes <= 32) { - while(size > 0){ + } + else if (ibuf->planes <= 32) { + while(size > 0) { putc(rect[2], file); putc(rect[1], file); putc(rect[0], file); @@ -230,7 +236,8 @@ static int dumptarga(struct ImBuf * ibuf, FILE * file) size--; rect += 4; } - } else return (0); + } + else return (0); return (1); } @@ -245,9 +252,10 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags) (void)flags; /* unused */ buf[16] = (ibuf->planes + 0x7 ) & ~0x7; - if (ibuf->planes > 8 ){ + if (ibuf->planes > 8 ) { buf[2] = 10; - } else{ + } + else { buf[2] = 11; } @@ -278,8 +286,9 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags) if (ibuf->ftype == RAWTGA) { ok = dumptarga(ibuf, fildes); - } else { - switch((ibuf->planes + 7) >> 3){ + } + else { + switch((ibuf->planes + 7) >> 3) { case 1: ok = makebody_tga(ibuf, fildes, tga_out1); break; @@ -317,7 +326,7 @@ static int checktarga(TARGA *tga, unsigned char *mem) tga->imgdes = mem[17]; if (tga->maptyp > 1) return(0); - switch (tga->imgtyp){ + switch (tga->imgtyp) { case 1: /* raw cmap */ case 2: /* raw rgb */ case 3: /* raw b&w */ @@ -346,7 +355,7 @@ int imb_is_a_targa(unsigned char *buf) static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect) { int size = (ibuf->x * ibuf->y) - (rect - ibuf->rect); - if(size) { + if (size) { printf("decodetarga: incomplete file, %.1f%% missing\n", 100*((float)size / (ibuf->x * ibuf->y))); /* not essential but makes displaying partially rendered TGA's less ugly */ @@ -375,18 +384,18 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, cp[0] = 0xff; cp[1] = cp[2] = 0; - while(size > 0){ + 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");*/ count -= 127; - if (psize & 2){ - if (psize & 1){ + if (psize & 2) { + if (psize & 1) { /* order = bgra */ cp[0] = mem[3]; cp[1] = mem[0]; @@ -394,19 +403,22 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, cp[3] = mem[2]; /*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/ mem += 4; - } else{ + } + else { cp[1] = mem[0]; cp[2] = mem[1]; cp[3] = mem[2]; /*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/ mem += 3; } - } else{ - if (psize & 1){ + } + else { + if (psize & 1) { cp[0] = mem[0]; cp[1] = mem[1]; mem += 2; - } else{ + } + else { col = *mem++; } } @@ -418,13 +430,14 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, count--; } } - } else{ + } + else { count ++; size -= count; if (size >= 0) { - while (count > 0){ - if (psize & 2){ - if (psize & 1){ + while (count > 0) { + if (psize & 2) { + if (psize & 1) { /* order = bgra */ cp[0] = mem[3]; cp[1] = mem[0]; @@ -432,30 +445,33 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, cp[3] = mem[2]; /*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/ mem += 4; - } else{ + } + else { cp[1] = mem[0]; cp[2] = mem[1]; cp[3] = mem[2]; /*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/ mem += 3; } - } else{ - if (psize & 1){ + } + else { + if (psize & 1) { cp[0] = mem[0]; cp[1] = mem[1]; mem += 2; - } else{ + } + else { col = *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; } } @@ -486,12 +502,12 @@ static void ldtarga(struct ImBuf * ibuf,unsigned char * mem, size_t mem_size, in cp[0] = 0xff; cp[1] = cp[2] = 0; - while(size > 0){ - if(mem>mem_end) + while(size > 0) { + if (mem>mem_end) goto partial_load; - if (psize & 2){ - if (psize & 1){ + if (psize & 2) { + if (psize & 1) { /* order = bgra */ cp[0] = mem[3]; cp[1] = mem[0]; @@ -499,7 +515,8 @@ static void ldtarga(struct ImBuf * ibuf,unsigned char * mem, size_t mem_size, in cp[3] = mem[2]; /*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/ mem += 4; - } else{ + } + else { /* set alpha for 24 bits colors */ cp[1] = mem[0]; cp[2] = mem[1]; @@ -507,12 +524,14 @@ static void ldtarga(struct ImBuf * ibuf,unsigned char * mem, size_t mem_size, in /*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/ mem += 3; } - } else{ - if (psize & 1){ + } + else { + if (psize & 1) { cp[0] = mem[0]; cp[1] = mem[1]; mem += 2; - } else{ + } + else { col = *mem++; } } @@ -547,7 +566,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) cp[0] = 0xff; cp[1] = cp[2] = 0; - if (tga.mapsize){ + if (tga.mapsize) { /* load color map */ /*mincol = tga.maporig;*/ /*UNUSED*/ maxcol = tga.mapsize; @@ -592,13 +611,13 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) if (flags & IB_test) return (ibuf); if (tga.imgtyp != 1 && tga.imgtyp != 9) { /* happens sometimes (beuh) */ - if(cmap) { + if (cmap) { MEM_freeN(cmap); cmap= NULL; } } - switch(tga.imgtyp){ + switch(tga.imgtyp) { case 1: case 2: case 3: @@ -617,10 +636,10 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) break; } - if(cmap) { + if (cmap) { /* apply color map */ rect = ibuf->rect; - for(size = ibuf->x * ibuf->y; size>0; --size, ++rect) { + for (size = ibuf->x * ibuf->y; size>0; --size, ++rect) { col = *rect; if (col >= 0 && col < maxcol) *rect = cmap[col]; } @@ -630,7 +649,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) if (tga.pixsize == 16) { rect = ibuf->rect; - for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect){ + for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) { col = *rect; cp = (uchar*)rect; mem = (uchar*)&col; @@ -646,14 +665,14 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) ibuf->planes = 24; } - if (tga.imgtyp == 3 || tga.imgtyp == 11){ + if (tga.imgtyp == 3 || tga.imgtyp == 11) { uchar *crect; unsigned int *lrect, col; crect = (uchar *) ibuf->rect; lrect = (unsigned int *) ibuf->rect; - for (size = ibuf->x * ibuf->y; size > 0; size --){ + for (size = ibuf->x * ibuf->y; size > 0; size --) { col = *lrect++; crect[0] = 255; diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index be716870dad..f5c22b67c1b 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -149,7 +149,8 @@ static void escape_uri_string (const char *string, char* escaped_string, int len *q++ = '%'; /* means hex coming */ *q++ = hex[c >> 4]; *q++ = hex[c & 15]; - } else { + } + else { *q++ = *p; } } @@ -280,9 +281,9 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im } /* exception, skip images over 100mb */ - if(source == THB_SOURCE_IMAGE) { + if (source == THB_SOURCE_IMAGE) { const size_t size= BLI_file_size(path); - if(size != -1 && size > THUMB_SIZE_MAX) { + if (size != -1 && size > THUMB_SIZE_MAX) { // printf("file too big: %d, skipping %s\n", (int)size, path); return NULL; } @@ -300,12 +301,13 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im if (size == THB_FAIL) { img = IMB_allocImBuf(1,1,32, IB_rect | IB_metadata); if (!img) return NULL; - } else { + } + else { if (THB_SOURCE_IMAGE == source || THB_SOURCE_BLEND == source) { /* only load if we didnt give an image */ - if(img==NULL) { - if(THB_SOURCE_BLEND == source) { + if (img==NULL) { + if (THB_SOURCE_BLEND == source) { img = IMB_loadblend_thumb(path); } else { @@ -319,14 +321,16 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im BLI_snprintf(cwidth, sizeof(cwidth), "%d", img->x); BLI_snprintf(cheight, sizeof(cheight), "%d", img->y); } - } else if (THB_SOURCE_MOVIE == source) { + } + else if (THB_SOURCE_MOVIE == source) { struct anim * anim = NULL; anim = IMB_open_anim(path, IB_rect | IB_metadata, 0); if (anim != NULL) { img = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE); if (img == NULL) { printf("not an anim; %s\n", path); - } else { + } + else { IMB_freeImBuf(img); img = IMB_anim_previewframe(anim); } @@ -349,8 +353,8 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im ey = (short)scaledy; /* save some time by only scaling byte buf */ - if(img->rect_float) { - if(img->rect == NULL) { + if (img->rect_float) { + if (img->rect == NULL) { IMB_rect_from_float(img); } @@ -443,7 +447,8 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) { if (BLI_path_ncmp(path, thumb, sizeof(thumb)) == 0) { img = IMB_loadiffname(path, IB_rect); - } else { + } + else { img = IMB_loadiffname(thumb, IB_rect | IB_metadata); if (img) { char mtime[40]; @@ -451,7 +456,8 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) /* illegal thumb, forget it! */ IMB_freeImBuf(img); img = NULL; - } else { + } + else { time_t t = atol(mtime); if (st.st_mtime != t) { /* recreate all thumbs */ @@ -461,7 +467,7 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) IMB_thumb_delete(path, THB_LARGE); IMB_thumb_delete(path, THB_FAIL); img = IMB_thumb_create(path, size, source, NULL); - if(!img){ + if (!img) { /* thumb creation failed, write fail thumb */ img = IMB_thumb_create(path, THB_FAIL, source, NULL); if (img) { @@ -472,9 +478,10 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source) } } } - } else { + } + else { img = IMB_thumb_create(path, size, source, NULL); - if(!img){ + if (!img) { /* thumb creation failed, write fail thumb */ img = IMB_thumb_create(path, THB_FAIL, source, NULL); if (img) { diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index fd0be89df0d..91df1e78f44 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -53,23 +53,23 @@ static ImBuf *loadblend_thumb(gzFile gzfile) int sizeof_bhead; /* read the blend file header */ - if(gzread(gzfile, buf, 12) != 12) + if (gzread(gzfile, buf, 12) != 12) return NULL; - if(strncmp(buf, "BLENDER", 7)) + if (strncmp(buf, "BLENDER", 7)) return NULL; - if(buf[7]=='-') + if (buf[7]=='-') pointer_size= 8; - else if(buf[7]=='_') + else if (buf[7]=='_') pointer_size= 4; else return NULL; sizeof_bhead = 16 + pointer_size; - if(buf[8]=='V') + if (buf[8]=='V') endian= B_ENDIAN; /* big: PPC */ - else if(buf[8]=='v') + else if (buf[8]=='v') endian= L_ENDIAN; /* little: x86 */ else return NULL; @@ -77,7 +77,7 @@ static ImBuf *loadblend_thumb(gzFile gzfile) endian_switch = ((ENDIAN_ORDER != endian)) ? 1 : 0; while(gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) { - if(endian_switch) + if (endian_switch) SWITCH_INT(bhead[1]); /* length */ if (bhead[0]==REND) { @@ -89,14 +89,14 @@ static ImBuf *loadblend_thumb(gzFile gzfile) } /* using 'TEST' since new names segfault when loading in old blenders */ - if(bhead[0] == TEST) { + if (bhead[0] == TEST) { ImBuf *img= NULL; int size[2]; - if(gzread(gzfile, size, sizeof(size)) != sizeof(size)) + if (gzread(gzfile, size, sizeof(size)) != sizeof(size)) return NULL; - if(endian_switch) { + if (endian_switch) { SWITCH_INT(size[0]); SWITCH_INT(size[1]); } @@ -104,13 +104,13 @@ static ImBuf *loadblend_thumb(gzFile gzfile) bhead[1] -= sizeof(int) * 2; /* inconsistent image size, quit early */ - if(bhead[1] != size[0] * size[1] * sizeof(int)) + if (bhead[1] != size[0] * size[1] * sizeof(int)) return NULL; /* finally malloc and read the data */ img= IMB_allocImBuf(size[0], size[1], 32, IB_rect | IB_metadata); - if(gzread(gzfile, img->rect, bhead[1]) != bhead[1]) { + if (gzread(gzfile, img->rect, bhead[1]) != bhead[1]) { IMB_freeImBuf(img); img= NULL; } @@ -151,7 +151,7 @@ void IMB_overlayblend_thumb(unsigned int *thumb, int width, int height, float as int margin_r = width - MARGIN; int margin_t = height - MARGIN; - if(aspect < 1.0f) { + if (aspect < 1.0f) { margin_l= (int)((width - ((float)width * aspect)) / 2.0f); margin_l += MARGIN; CLAMP(margin_l, MARGIN, (width/2)); @@ -168,18 +168,19 @@ void IMB_overlayblend_thumb(unsigned int *thumb, int width, int height, float as int x, y; int stride_x= (margin_r - margin_l) - 2; - for(y=0; y < height; y++) { - for(x=0; x < width; x++, px+=4) { + for (y=0; y < height; y++) { + for (x=0; x < width; x++, px+=4) { int hline= 0, vline= 0; - if((x > margin_l && x < margin_r) && (y > margin_b && y < margin_t)) { + if ((x > margin_l && x < margin_r) && (y > margin_b && y < margin_t)) { /* interior. skip */ x += stride_x; px += stride_x * 4; - } else if( (hline=(((x == margin_l || x == margin_r)) && y >= margin_b && y <= margin_t)) || - (vline=(((y == margin_b || y == margin_t)) && x >= margin_l && x <= margin_r)) - ) { + } + else if ((hline=(((x == margin_l || x == margin_r)) && y >= margin_b && y <= margin_t)) || + (vline=(((y == margin_b || y == margin_t)) && x >= margin_l && x <= margin_r))) + { /* dashed line */ - if((hline && y % 2) || (vline && x % 2)) { + if ((hline && y % 2) || (vline && x % 2)) { px[0]= px[1]= px[2]= 0; px[3] = 255; } diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index 1e6bc216128..5a8caa8769f 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -128,23 +128,23 @@ static tsize_t imb_tiff_ReadProc(thandle_t handle, tdata_t data, tsize_t n) /* get the pointer to the in-memory file */ mfile = IMB_TIFF_GET_MEMFILE(handle); - if(!mfile || !mfile->mem) { + if (!mfile || !mfile->mem) { fprintf(stderr, "imb_tiff_ReadProc: !mfile || !mfile->mem!\n"); return 0; } /* 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 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) */ @@ -195,7 +195,7 @@ static toff_t imb_tiff_SeekProc(thandle_t handle, toff_t ofs, int whence) /* get the pointer to the in-memory file */ mfile = IMB_TIFF_GET_MEMFILE(handle); - if(!mfile || !mfile->mem) { + if (!mfile || !mfile->mem) { fprintf(stderr, "imb_tiff_SeekProc: !mfile || !mfile->mem!\n"); return (-1); } @@ -241,7 +241,7 @@ static int imb_tiff_CloseProc(thandle_t handle) /* get the pointer to the in-memory file */ mfile = IMB_TIFF_GET_MEMFILE(handle); - if(!mfile || !mfile->mem) { + if (!mfile || !mfile->mem) { fprintf(stderr,"imb_tiff_CloseProc: !mfile || !mfile->mem!\n"); return (0); } @@ -267,7 +267,7 @@ static toff_t imb_tiff_SizeProc(thandle_t handle) /* get the pointer to the in-memory file */ mfile = IMB_TIFF_GET_MEMFILE(handle); - if(!mfile || !mfile->mem) { + if (!mfile || !mfile->mem) { fprintf(stderr,"imb_tiff_SizeProc: !mfile || !mfile->mem!\n"); return (0); } @@ -361,7 +361,7 @@ static void imb_read_tiff_resolution(ImBuf *ibuf, TIFF *image) TIFFGetFieldDefaulted(image, TIFFTAG_XRESOLUTION, &xres); TIFFGetFieldDefaulted(image, TIFFTAG_YRESOLUTION, &yres); - if(unit == RESUNIT_CENTIMETER) { + if (unit == RESUNIT_CENTIMETER) { ibuf->ppm[0]= (double)xres * 100.0; ibuf->ppm[1]= (double)yres * 100.0; } @@ -397,10 +397,12 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul) if (bitspersample == 32) { ib_flag = IB_rectfloat; fbuf = (float *)_TIFFmalloc(scanline); - } else if (bitspersample == 16) { + } + else if (bitspersample == 16) { ib_flag = IB_rectfloat; sbuf = (unsigned short *)_TIFFmalloc(scanline); - } else { + } + else { ib_flag = IB_rect; } @@ -419,13 +421,15 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul) success |= TIFFReadScanline(image, fbuf, row, 0); scanline_contig_32bit(tmpibuf->rect_float+ib_offset, fbuf, ibuf->x, spp); - } else if (bitspersample == 16) { + } + else if (bitspersample == 16) { success |= TIFFReadScanline(image, sbuf, row, 0); scanline_contig_16bit(tmpibuf->rect_float+ib_offset, sbuf, ibuf->x, spp); } } /* separate channels: RRRGGGBBB */ - } else if (config == PLANARCONFIG_SEPARATE) { + } + else if (config == PLANARCONFIG_SEPARATE) { /* imbufs always have 4 channels of data, so we iterate over all of them * but only fill in from the TIFF scanline where necessary. */ @@ -440,7 +444,8 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul) success |= TIFFReadScanline(image, fbuf, row, chan); scanline_separate_32bit(tmpibuf->rect_float+ib_offset, fbuf, ibuf->x, chan); - } else if (bitspersample == 16) { + } + else if (bitspersample == 16) { if (chan == 3 && spp == 3) /* fill alpha if only RGB TIFF */ memset(sbuf, 65535, sizeof(sbuf)); else @@ -457,14 +462,14 @@ static int imb_read_tiff_pixels(ImBuf *ibuf, TIFF *image, int premul) else if (bitspersample == 16) _TIFFfree(sbuf); - if(success) { + if (success) { ibuf->profile = (bitspersample==32)?IB_PROFILE_LINEAR_RGB:IB_PROFILE_SRGB; // 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); - if(premul) { + if (premul) { IMB_premultiply_alpha(tmpibuf); ibuf->flags |= IB_premul; } @@ -514,16 +519,16 @@ ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags) int ib_depth; /* check whether or not we have a TIFF file */ - if(size < IMB_TIFF_NCB) { + if (size < IMB_TIFF_NCB) { 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; image = imb_tiff_client_open(&memFile, mem, size); - if(image == NULL) { + if (image == NULL) { printf("imb_loadtiff: could not open TIFF IO layer.\n"); return NULL; } @@ -536,7 +541,7 @@ ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags) ib_depth = (spp==3)?24:32; ibuf = IMB_allocImBuf(width, height, ib_depth, 0); - if(ibuf) { + if (ibuf) { ibuf->ftype = TIF; } else { @@ -548,26 +553,26 @@ ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags) } /* if testing, we're done */ - if(flags & IB_test) { + if (flags & IB_test) { TIFFClose(image); return ibuf; } /* detect if we are reading a tiled/mipmapped texture, in that case * we don't read pixels but leave it to the cache to load tiles */ - if(flags & IB_tilecache) { + if (flags & IB_tilecache) { format= NULL; TIFFGetField(image, TIFFTAG_PIXAR_TEXTUREFORMAT, &format); - if(format && strcmp(format, "Plain Texture")==0 && TIFFIsTiled(image)) { + if (format && strcmp(format, "Plain Texture")==0 && TIFFIsTiled(image)) { int numlevel = TIFFNumberOfDirectories(image); /* create empty mipmap levels in advance */ - for(level=0; level<numlevel; level++) { - if(!TIFFSetDirectory(image, level)) + for (level=0; level<numlevel; level++) { + if (!TIFFSetDirectory(image, level)) break; - if(level > 0) { + if (level > 0) { width= (width > 1)? width/2: 1; height= (height > 1)? height/2: 1; @@ -576,7 +581,7 @@ ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags) hbuf->ftype= ibuf->ftype; ibuf->mipmap[level-1] = hbuf; - if(flags & IB_premul) + if (flags & IB_premul) hbuf->flags |= IB_premul; } else @@ -598,7 +603,7 @@ ImBuf *imb_loadtiff(unsigned char *mem, size_t size, int flags) } /* read pixels */ - if(!(ibuf->flags & IB_tilecache) && !imb_read_tiff_pixels(ibuf, image, 0)) { + if (!(ibuf->flags & IB_tilecache) && !imb_read_tiff_pixels(ibuf, image, 0)) { fprintf(stderr, "imb_loadtiff: Failed to read tiff image.\n"); TIFFClose(image); return NULL; @@ -619,23 +624,23 @@ void imb_loadtiletiff(ImBuf *ibuf, unsigned char *mem, size_t size, int tx, int image = imb_tiff_client_open(&memFile, mem, size); - if(image == NULL) { + if (image == NULL) { printf("imb_loadtiff: could not open TIFF IO layer for loading mipmap level.\n"); return; } - if(TIFFSetDirectory(image, ibuf->miplevel)) { /* allocate the image buffer */ + if (TIFFSetDirectory(image, ibuf->miplevel)) { /* allocate the image buffer */ TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width); TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height); - if(width == ibuf->x && height == ibuf->y) { - if(rect) { + if (width == ibuf->x && height == ibuf->y) { + if (rect) { /* 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 (TIFFReadRGBATile(image, tx*ibuf->tilex, (ibuf->ytiles - 1 - ty)*ibuf->tiley, rect) == 1) { + if (ibuf->tiley > ibuf->y) memmove(rect, rect+ibuf->tilex*(ibuf->tiley - ibuf->y), sizeof(int)*ibuf->tilex*ibuf->y); - if(ibuf->flags & IB_premul) + if (ibuf->flags & IB_premul) IMB_premultiply_rect(rect, 32, ibuf->tilex, ibuf->tiley); } else @@ -686,20 +691,20 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) * the TIFF writer supports 1, 3 or 4 bytes per pixel, corresponding * to gray, RGB, RGBA respectively. */ samplesperpixel = (uint16)((ibuf->planes + 7) >> 3); - if((samplesperpixel > 4) || (samplesperpixel == 2)) { + if ((samplesperpixel > 4) || (samplesperpixel == 2)) { fprintf(stderr, "imb_savetiff: unsupported number of bytes per " "pixel: %d\n", samplesperpixel); return (0); } - if((ibuf->ftype & TIF_16BIT) && ibuf->rect_float) + if ((ibuf->ftype & TIF_16BIT) && ibuf->rect_float) bitspersample = 16; else bitspersample = 8; /* open TIFF file for writing */ - if(flags & IB_mem) { + if (flags & IB_mem) { /* bork at the creation of a TIFF in memory */ fprintf(stderr, "imb_savetiff: creation of in-memory TIFF files is " @@ -710,7 +715,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) /* create image as a file */ image = TIFFOpen(name, "w"); } - if(image == NULL) { + if (image == NULL) { fprintf(stderr, "imb_savetiff: could not open TIFF for writing.\n"); return (0); @@ -718,14 +723,14 @@ 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 pixels = (unsigned char*)_TIFFmalloc(npixels * samplesperpixel * sizeof(unsigned char)); - if(pixels == NULL && pixels16 == NULL) { + if (pixels == NULL && pixels16 == NULL) { fprintf(stderr, "imb_savetiff: could not allocate pixels array.\n"); TIFFClose(image); @@ -733,7 +738,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) } /* setup pointers */ - if(bitspersample == 16) { + if (bitspersample == 16) { fromf = ibuf->rect_float; to16 = pixels16; } @@ -746,31 +751,31 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, bitspersample); TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); - if(samplesperpixel == 4) { + if (samplesperpixel == 4) { /* RGBA images */ TIFFSetField(image, TIFFTAG_EXTRASAMPLES, 1, extraSampleTypes); TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); } - else if(samplesperpixel == 3) { + else if (samplesperpixel == 3) { /* RGB images */ TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); } - else if(samplesperpixel == 1) { + else if (samplesperpixel == 1) { /* greyscale images, 1 channel */ TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); } /* copy pixel data. While copying, we flip the image vertically. */ - for(x = 0; x < ibuf->x; x++) { - for(y = 0; y < ibuf->y; y++) { + for (x = 0; x < ibuf->x; x++) { + for (y = 0; y < ibuf->y; y++) { from_i = 4*(y*ibuf->x+x); to_i = samplesperpixel*((ibuf->y-y-1)*ibuf->x+x); - if(pixels16) { + if (pixels16) { /* convert from float source */ float rgb[3]; @@ -790,7 +795,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) } } 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]; } } @@ -805,7 +810,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); - if(ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { + if (ibuf->ppm[0] > 0.0 && ibuf->ppm[1] > 0.0) { xres= (float)(ibuf->ppm[0] * 0.0254); yres= (float)(ibuf->ppm[1] * 0.0254); } @@ -816,20 +821,20 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) TIFFSetField(image, TIFFTAG_XRESOLUTION, xres); TIFFSetField(image, TIFFTAG_YRESOLUTION, yres); TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); - if(TIFFWriteEncodedStrip(image, 0, + if (TIFFWriteEncodedStrip(image, 0, (bitspersample == 16)? (unsigned char*)pixels16: pixels, ibuf->x*ibuf->y*samplesperpixel*bitspersample/8) == -1) { fprintf(stderr, "imb_savetiff: Could not write encoded TIFF.\n"); TIFFClose(image); - if(pixels) _TIFFfree(pixels); - if(pixels16) _TIFFfree(pixels16); + if (pixels) _TIFFfree(pixels); + if (pixels16) _TIFFfree(pixels16); return (1); } /* close the TIFF file */ TIFFClose(image); - if(pixels) _TIFFfree(pixels); - if(pixels16) _TIFFfree(pixels16); + if (pixels) _TIFFfree(pixels); + if (pixels16) _TIFFfree(pixels16); return (1); } diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index fdcc0641628..008be2fde74 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -152,17 +152,17 @@ static int IMB_ispic_name(const char *name) struct stat st; int fp, buf[10]; - if(UTIL_DEBUG) printf("IMB_ispic_name: loading %s\n", name); + if (UTIL_DEBUG) printf("IMB_ispic_name: loading %s\n", name); - if(stat(name,&st) == -1) + if (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)) < 0) + if ((fp = BLI_open(name,O_BINARY|O_RDONLY, 0)) < 0) return FALSE; - if(read(fp, buf, 32) != 32) { + if (read(fp, buf, 32) != 32) { close(fp); return FALSE; } @@ -170,11 +170,11 @@ static int IMB_ispic_name(const char *name) close(fp); /* XXX move this exception */ - if((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0) + if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0) return JPG; - for(type=IMB_FILE_TYPES; type->is_a; type++) - if(type->is_a((uchar*)buf)) + for (type=IMB_FILE_TYPES; type->is_a; type++) + if (type->is_a((uchar*)buf)) return type->filetype; return FALSE; @@ -182,8 +182,8 @@ static int IMB_ispic_name(const char *name) int IMB_ispic(const char *filename) { - if(U.uiflag & USER_FILTERFILEEXTS) { - if( (BLI_testextensie_array(filename, imb_ext_image)) || + if (U.uiflag & USER_FILTERFILEEXTS) { + if ( (BLI_testextensie_array(filename, imb_ext_image)) || (G.have_quicktime && BLI_testextensie_array(filename, imb_ext_image_qt)) ) { return IMB_ispic_name(filename); @@ -234,7 +234,8 @@ void do_init_ffmpeg(void) if ((G.f & G_DEBUG) == 0) { silence_log_ffmpeg(1); - } else { + } + else { silence_log_ffmpeg(0); } } @@ -250,7 +251,7 @@ static int isffmpeg (const char *filename) do_init_ffmpeg(); - if( BLI_testextensie(filename, ".swf") || + if ( BLI_testextensie(filename, ".swf") || BLI_testextensie(filename, ".jpg") || BLI_testextensie(filename, ".png") || BLI_testextensie(filename, ".dds") || @@ -260,24 +261,24 @@ static int isffmpeg (const char *filename) BLI_testextensie(filename, ".cin") || BLI_testextensie(filename, ".wav")) return 0; - if(av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) { - if(UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_open_input_file failed\n"); + if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) { + if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_open_input_file failed\n"); return 0; } - if(av_find_stream_info(pFormatCtx)<0) { - if(UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_find_stream_info failed\n"); + if (av_find_stream_info(pFormatCtx)<0) { + if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_find_stream_info failed\n"); av_close_input_file(pFormatCtx); return 0; } - if(UTIL_DEBUG) av_dump_format(pFormatCtx, 0, filename, 0); + if (UTIL_DEBUG) av_dump_format(pFormatCtx, 0, filename, 0); /* Find the first video stream */ videoStream=-1; - for(i=0; i<pFormatCtx->nb_streams; i++) - if(pFormatCtx->streams[i] && + for (i=0; i<pFormatCtx->nb_streams; i++) + if (pFormatCtx->streams[i] && pFormatCtx->streams[i]->codec && (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)) { @@ -285,7 +286,7 @@ static int isffmpeg (const char *filename) break; } - if(videoStream==-1) { + if (videoStream==-1) { av_close_input_file(pFormatCtx); return 0; } @@ -294,12 +295,12 @@ static int isffmpeg (const char *filename) /* Find the decoder for the video stream */ pCodec=avcodec_find_decoder(pCodecCtx->codec_id); - if(pCodec==NULL) { + if (pCodec==NULL) { av_close_input_file(pFormatCtx); return 0; } - if(avcodec_open(pCodecCtx, pCodec)<0) { + if (avcodec_open(pCodecCtx, pCodec)<0) { av_close_input_file(pFormatCtx); return 0; } @@ -329,7 +330,7 @@ int imb_get_anim_type(const char * name) int type; struct stat st; - if(UTIL_DEBUG) printf("in getanimtype: %s\n", name); + if (UTIL_DEBUG) printf("in getanimtype: %s\n", name); #ifndef _WIN32 # ifdef WITH_QUICKTIME @@ -370,9 +371,9 @@ int IMB_isanim(const char *filename) { int type; - if(U.uiflag & USER_FILTERFILEEXTS) { - if (G.have_quicktime){ - if( BLI_testextensie(filename, ".avi") + if (U.uiflag & USER_FILTERFILEEXTS) { + if (G.have_quicktime) { + if ( BLI_testextensie(filename, ".avi") || BLI_testextensie(filename, ".flc") || BLI_testextensie(filename, ".dv") || BLI_testextensie(filename, ".r3d") @@ -380,11 +381,13 @@ int IMB_isanim(const char *filename) || BLI_testextensie(filename, ".movie") || BLI_testextensie(filename, ".mv")) { type = imb_get_anim_type(filename); - } else { + } + else { return(FALSE); } - } else { // no quicktime - if( BLI_testextensie(filename, ".avi") + } + else { // no quicktime + if ( BLI_testextensie(filename, ".avi") || BLI_testextensie(filename, ".dv") || BLI_testextensie(filename, ".r3d") || BLI_testextensie(filename, ".mv")) { @@ -394,7 +397,8 @@ int IMB_isanim(const char *filename) return(FALSE); } } - } else { // no FILTERFILEEXTS + } + else { // no FILTERFILEEXTS type = imb_get_anim_type(filename); } diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c index 8fbed6da32b..60fc7db6465 100644 --- a/source/blender/imbuf/intern/writeimage.c +++ b/source/blender/imbuf/intern/writeimage.c @@ -44,13 +44,13 @@ short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags) { ImFileType *type; - if(ibuf == NULL) return (FALSE); + if (ibuf == NULL) return (FALSE); ibuf->flags = flags; - for(type=IMB_FILE_TYPES; type->is_a; type++) { - if(type->save && type->ftype(type, ibuf)) { - if(!(type->flag & IM_FTYPE_FLOAT)) { - if(ibuf->rect==NULL && ibuf->rect_float) + for (type=IMB_FILE_TYPES; type->is_a; type++) { + if (type->save && type->ftype(type, ibuf)) { + if (!(type->flag & IM_FTYPE_FLOAT)) { + if (ibuf->rect==NULL && ibuf->rect_float) IMB_rect_from_float(ibuf); } return type->save(ibuf, name, flags); |