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.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.c')
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 22 |
1 files changed, 2 insertions, 20 deletions
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 94dbdf9fe58..ca2aeca8f36 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -354,30 +354,12 @@ void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4]) void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3]) { - int r, g, b; - - r= (int)(col_f[0] * 255.0f); - g= (int)(col_f[1] * 255.0f); - b= (int)(col_f[2] * 255.0f); - - col_r[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r); - col_r[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g); - col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b); + F3TOCHAR3(col_f, col_r); } void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]) { - int r, g, b, a; - - r= (int)(col_f[0] * 255.0f); - g= (int)(col_f[1] * 255.0f); - b= (int)(col_f[2] * 255.0f); - a= (int)(col_f[3] * 255.0f); - - col_r[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r); - col_r[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g); - col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b); - col_r[3]= (char)((a <= 0)? 0 : (a >= 255)? 255 : a); + F4TOCHAR4(col_f, col_r); } /* ********************************* color transforms ********************************* */ |