diff options
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__ */ |