From 0ce2d278b7a895a96c673f2c74020543b94413a3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 15 Jan 2013 08:37:17 +0000 Subject: Follow general mathutils rules for naming straight<->premul functions --- source/blender/blenlib/BLI_math_color.h | 6 ++++-- source/blender/blenlib/intern/math_color_inline.c | 14 ++++++++++++-- source/blender/imbuf/intern/colormanagement.c | 6 +++--- source/blender/imbuf/intern/divers.c | 20 ++++++++++---------- source/blender/imbuf/intern/png.c | 6 +++--- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h index 3831ec3cbb4..145427ea529 100644 --- a/source/blender/blenlib/BLI_math_color.h +++ b/source/blender/blenlib/BLI_math_color.h @@ -102,8 +102,10 @@ void BLI_init_srgb_conversion(void); /**************** Alpha Transformations *****************/ -MINLINE void premul_to_straight_v4(float straight[4], const float premul[4]); -MINLINE void straight_to_premul_v4(float straight[4], const float premul[4]); +MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4]); +MINLINE void premul_to_straight_v4(float color[4]); +MINLINE void straight_to_premul_v4_v4(float straight[4], const float premul[4]); +MINLINE void straight_to_premul_v4(float color[4]); MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4]); MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4]); diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index b8eeca50db6..c24da9fcf80 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -270,7 +270,7 @@ MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char /**************** Alpha Transformations *****************/ -MINLINE void premul_to_straight_v4(float straight[4], const float premul[4]) +MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4]) { if (premul[3] == 0.0f || premul[3] == 1.0f) { straight[0] = premul[0]; @@ -287,7 +287,12 @@ MINLINE void premul_to_straight_v4(float straight[4], const float premul[4]) } } -MINLINE void straight_to_premul_v4(float premul[4], const float straight[4]) +MINLINE void premul_to_straight_v4(float color[4]) +{ + premul_to_straight_v4_v4(color, color); +} + +MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4]) { float alpha = straight[3]; premul[0] = straight[0] * alpha; @@ -296,6 +301,11 @@ MINLINE void straight_to_premul_v4(float premul[4], const float straight[4]) premul[3] = straight[3]; } +MINLINE void straight_to_premul_v4(float color[4]) +{ + straight_to_premul_v4_v4(color, color); +} + MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4]) { float alpha = color[3] / 255.0f; diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 2c6e46cb664..86f47fe07c4 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -1222,7 +1222,7 @@ static void *display_buffer_apply_get_linear_buffer(DisplayBufferThread *handle) } else if (channels == 4) { rgba_uchar_to_float(fp, cp); - straight_to_premul_v4(fp, fp); + straight_to_premul_v4(fp); } else { BLI_assert(!"Buffers of 3 or 4 channels are only supported here"); @@ -2347,7 +2347,7 @@ static void partial_buffer_update_rect(ImBuf *ibuf, unsigned char *display_buffe else if (byte_buffer) { rgba_uchar_to_float(pixel, byte_buffer + linear_index); IMB_colormanagement_colorspace_to_scene_linear_v3(pixel, rect_colorspace); - straight_to_premul_v4(pixel, pixel); + straight_to_premul_v4(pixel); } if (!is_data) { @@ -2361,7 +2361,7 @@ static void partial_buffer_update_rect(ImBuf *ibuf, unsigned char *display_buffe } else { float pixel_straight[4]; - premul_to_straight_v4(pixel_straight, pixel); + premul_to_straight_v4_v4(pixel_straight, pixel); rgba_float_to_uchar(display_buffer + display_index, pixel_straight); } } diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 84339b51721..20d51fddb35 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -255,7 +255,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, /* no color space conversion */ if (dither && predivide) { for (x = 0; x < width; x++, from += 4, to += 4) { - premul_to_straight_v4(straight, from); + premul_to_straight_v4_v4(straight, from); float_to_byte_dither_v4(to, straight, di); } } @@ -265,7 +265,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, } else if (predivide) { for (x = 0; x < width; x++, from += 4, to += 4) { - premul_to_straight_v4(straight, from); + premul_to_straight_v4_v4(straight, from); rgba_float_to_uchar(to, straight); } } @@ -281,7 +281,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, if (dither && predivide) { for (x = 0; x < width; x++, from += 4, to += 4) { - premul_to_straight_v4(straight, from); + premul_to_straight_v4_v4(straight, from); linearrgb_to_srgb_ushort4(us, from); ushort_to_byte_dither_v4(to, us, di); } @@ -294,7 +294,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, } else if (predivide) { for (x = 0; x < width; x++, from += 4, to += 4) { - premul_to_straight_v4(straight, from); + premul_to_straight_v4_v4(straight, from); linearrgb_to_srgb_ushort4(us, from); ushort_to_byte_v4(to, us); } @@ -690,20 +690,20 @@ void IMB_buffer_float_clamp(float *buf, int width, int height) void IMB_buffer_float_unpremultiply(float *buf, int width, int height) { int total = width * height; - float *cp = buf; + float *fp = buf; while (total--) { - premul_to_straight_v4(cp, cp); - cp += 4; + premul_to_straight_v4(fp); + fp += 4; } } void IMB_buffer_float_premultiply(float *buf, int width, int height) { int total = width * height; - float *cp = buf; + float *fp = buf; while (total--) { - straight_to_premul_v4(cp, cp); - cp += 4; + straight_to_premul_v4(fp); + fp += 4; } } diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 02aea4b9965..cc73f688e70 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -204,7 +204,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) if (is_16bit) { if (has_float) { for (i = ibuf->x * ibuf->y; i > 0; i--) { - premul_to_straight_v4(from_straight, from_float); + premul_to_straight_v4_v4(from_straight, from_float); to16[0] = ftoshort(chanel_colormanage_cb(from_straight[0])); to16[1] = ftoshort(chanel_colormanage_cb(from_straight[1])); to16[2] = ftoshort(chanel_colormanage_cb(from_straight[2])); @@ -237,7 +237,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) if (is_16bit) { if (has_float) { for (i = ibuf->x * ibuf->y; i > 0; i--) { - premul_to_straight_v4(from_straight, from_float); + premul_to_straight_v4_v4(from_straight, from_float); to16[0] = ftoshort(chanel_colormanage_cb(from_straight[0])); to16[1] = ftoshort(chanel_colormanage_cb(from_straight[1])); to16[2] = ftoshort(chanel_colormanage_cb(from_straight[2])); @@ -267,7 +267,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) if (is_16bit) { if (has_float) { for (i = ibuf->x * ibuf->y; i > 0; i--) { - premul_to_straight_v4(from_straight, from_float); + premul_to_straight_v4_v4(from_straight, from_float); to16[0] = ftoshort(chanel_colormanage_cb(from_straight[0])); to16++; from_float += 4; } -- cgit v1.2.3