diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-01-19 20:22:22 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-01-19 20:22:22 +0400 |
commit | 1d46bbef7e07d70cf44d304f261bc5a1e8056f24 (patch) | |
tree | bd16f305b2d41099aa3237964dd85d918ddf16e8 /source/blender/blenlib/intern/math_color_inline.c | |
parent | 167999304ea0053532e84aff0c7fd0d1ce002a6c (diff) |
Fix issue in recent color commits, was still doing a multiplication by 255 too
many, also don't check uchar range after casting to int, this can still cause
overflow with large float values.
Diffstat (limited to 'source/blender/blenlib/intern/math_color_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 2c7b13b86a2..386452ed592 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -62,32 +62,20 @@ MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4]) srgb[3] = linear[3]; } -MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[4], const float linear[4]) +MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3]) { - int r, g, b; + float srgb_f[3]; - r = 255 * linearrgb_to_srgb(linear[0]); - g = 255 * linearrgb_to_srgb(linear[1]); - b = 255 * linearrgb_to_srgb(linear[2]); - - srgb[0] = FTOCHAR(r); - srgb[1] = FTOCHAR(g); - srgb[2] = FTOCHAR(b); + linearrgb_to_srgb_v3_v3(srgb_f, linear); + F3TOCHAR3(srgb_f, srgb); } MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4]) { - int r, g, b, a; - - r = 255 * linearrgb_to_srgb(linear[0]); - g = 255 * linearrgb_to_srgb(linear[1]); - b = 255 * linearrgb_to_srgb(linear[2]); - a = 255 * linear[3]; + float srgb_f[4]; - srgb[0] = FTOCHAR(r); - srgb[1] = FTOCHAR(g); - srgb[2] = FTOCHAR(b); - srgb[3] = FTOCHAR(a); + linearrgb_to_srgb_v4(srgb_f, linear); + F4TOCHAR4(srgb_f, srgb); } /* predivide versions to work on associated/premultipled alpha. if this should |