diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-13 19:13:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-13 19:13:19 +0400 |
commit | 0bed750c3a4f7b368c06d40847356451f51eced6 (patch) | |
tree | 768c667043cb7a7f686994151c11ea9a07986f12 /source/blender/blenlib/intern/math_color_inline.c | |
parent | 1dec23d33a86c0412852ef510fc5b5b619284697 (diff) |
move one line color conversion functions to be inline.
Diffstat (limited to 'source/blender/blenlib/intern/math_color_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index b2a87a91433..417c557af8a 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -222,4 +222,37 @@ MINLINE void cpack_cpy_3ub(unsigned char r_col[3], const unsigned int pack) r_col[2] = ((pack) >> 16) & 0xFF; } + +MINLINE float rgb_to_grayscale(const float rgb[3]) +{ + return 0.3f * rgb[0] + 0.58f * rgb[1] + 0.12f * rgb[2]; +} + +MINLINE 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; +} + +MINLINE float rgb_to_luma(const float rgb[3]) +{ + return 0.299f * rgb[0] + 0.587f * rgb[1] + 0.114f * rgb[2]; +} + +MINLINE 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; +} + +/* gamma-corrected RGB --> CIE XYZ + * for this function we only get the Y component + * see: http://software.intel.com/sites/products/documentation/hpc/ipp/ippi/ippi_ch6/ch6_color_models.html + * + * also known as: + * luminance rec. 709 */ +MINLINE float rgb_to_luma_y(const float rgb[3]) +{ + return 0.212671f * rgb[0] + 0.71516f * rgb[1] + 0.072169f * rgb[2]; +} + + #endif /* __MATH_COLOR_INLINE_C__ */ |