diff options
Diffstat (limited to 'source/blender/imbuf/intern/divers.c')
-rw-r--r-- | source/blender/imbuf/intern/divers.c | 222 |
1 files changed, 111 insertions, 111 deletions
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); |