diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_color.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 20 |
2 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h index 7444e01c3a6..2123765643e 100644 --- a/source/blender/blenlib/BLI_math_color.h +++ b/source/blender/blenlib/BLI_math_color.h @@ -74,6 +74,9 @@ void linearrgb_to_srgb_v3_v3(float *col_to, float *col_from); int constrain_rgb(float *r, float *g, float *b); void minmax_rgb(short c[3]); +void rgb_byte_to_float(char *in, float *out); +void rgb_float_to_byte(float *in, char *out); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 6dbd9c1381f..a4bd11a4bc8 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -274,6 +274,26 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b) *b /= 255.0f; } +void rgb_byte_to_float(char *in, float *out) +{ + out[0]= ((float)in[0]) / 255.0f; + out[1]= ((float)in[1]) / 255.0f; + out[2]= ((float)in[2]) / 255.0f; +} + +void rgb_float_to_byte(float *in, char *out) +{ + int r, g, b; + + r= (int)(in[0] * 255.0); + g= (int)(in[1] * 255.0); + b= (int)(in[2] * 255.0); + + out[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r); + out[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g); + out[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b); +} + /* ********************************* color transforms ********************************* */ |