Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-01-14 21:14:23 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-14 21:14:23 +0400
commit0d5595befb71303926d03e40dc5791e55f7f7ad9 (patch)
treed4c3f976df9ea92c546d35ed99215e4710a3db51 /source/blender/blenlib
parent6e72a7c1138169eb23ff3628e5e0a27349e7015a (diff)
add utility function to BLI_math_color - rgb_to_luma, rgb_to_luma_byte, also use rgb_to_grayscale in more places.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_math_color.h6
-rw-r--r--source/blender/blenlib/intern/math_color.c14
2 files changed, 16 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 2d8b0188165..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 *****************/
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index e9e700d355a..20df893015d 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -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)