diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-15 13:16:39 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-15 13:16:39 +0400 |
commit | 917714acf72340bbea363c81773887c6c532c7d8 (patch) | |
tree | f987aa296bb053949b2dbecf7931f4a73dc3a2db /source/blender/blenlib | |
parent | 3bb9c4adf985aff5e8e213807f3db0d7cd7556e7 (diff) | |
parent | 5c93135ef9a1e7265ead3b92b10ea9a4ef82b909 (diff) |
svn merge ^/trunk/blender -r43345:43381
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_color.h | 10 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 18 |
2 files changed, 20 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h index 32c300944b4..6d37aabd6ab 100644 --- a/source/blender/blenlib/BLI_math_color.h +++ b/source/blender/blenlib/BLI_math_color.h @@ -69,8 +69,10 @@ void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *l unsigned int rgb_to_cpack(float r, float g, float b); unsigned int hsv_to_cpack(float h, float s, float v); -float rgb_to_grayscale(float rgb[3]); -unsigned char rgb_to_grayscale_byte(unsigned char rgb[3]); +float rgb_to_grayscale(const float rgb[3]); +unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3]); +float rgb_to_luma(const float rgb[3]); +unsigned char rgb_to_luma_byte(const unsigned char rgb[3]); /**************** Profile Transformations *****************/ @@ -99,8 +101,8 @@ void minmax_rgb(short c[3]); void rgb_float_set_hue_float_offset(float * rgb, float hue_offset); void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset); -void rgb_byte_to_float(const unsigned char *in, float *out); -void rgb_float_to_byte(const float *in, unsigned char *out); +void rgb_byte_to_float(const unsigned char in[3], float out[3]); +void rgb_float_to_byte(const float in[3], unsigned char out[3]); /***************** lift/gamma/gain / ASC-CDL conversion *****************/ diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 3627b38a091..20df893015d 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -337,14 +337,14 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b) *b /= 255.0f; } -void rgb_byte_to_float(const unsigned char *in, float *out) +void rgb_byte_to_float(const unsigned char in[3], float out[3]) { 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(const float *in, unsigned char *out) +void rgb_float_to_byte(const float in[3], unsigned char out[3]) { int r, g, b; @@ -434,16 +434,26 @@ int constrain_rgb(float *r, float *g, float *b) return 0; /* Color within RGB gamut */ } -float rgb_to_grayscale(float rgb[3]) +float rgb_to_grayscale(const float rgb[3]) { return 0.3f*rgb[0] + 0.58f*rgb[1] + 0.12f*rgb[2]; } -unsigned char rgb_to_grayscale_byte(unsigned char rgb[3]) +unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3]) { return (76*(unsigned short)rgb[0] + 148*(unsigned short)rgb[1] + 31*(unsigned short)rgb[2]) / 255; } +float rgb_to_luma(const float rgb[3]) +{ + return 0.299f*rgb[0] + 0.587f*rgb[1] + 0.114f*rgb[2]; +} + +unsigned char rgb_to_luma_byte(const unsigned char rgb[3]) +{ + return (76*(unsigned short)rgb[0] + 150*(unsigned short)rgb[1] + 29*(unsigned short)rgb[2]) / 255; +} + /* ********************************* lift/gamma/gain / ASC-CDL conversion ********************************* */ void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power) |