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-19 15:31:31 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-19 15:31:31 +0400
commit7b2101ace983cc9d7112dd45a8b264b51657dea9 (patch)
treec1d75f2ae3f30fe9de51c1c7332e862064a93193 /source/blender/blenlib
parent787ea5feb4a80babccd86689b066153ac57db91c (diff)
parenta87c5eb52cd4951b138f518bf12d498bc5e5eb8a (diff)
svn merge ^/trunk/blender -r43482:43524
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.c49
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c28
3 files changed, 68 insertions, 15 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 6d37aabd6ab..453f1258272 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -101,8 +101,10 @@ 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[3], float out[3]);
-void rgb_float_to_byte(const float in[3], unsigned char out[3]);
+void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3]);
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4]);
+void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3]);
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]);
/***************** 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 20df893015d..94dbdf9fe58 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -337,24 +337,47 @@ 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[3], float out[3])
+void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3])
{
- out[0]= ((float)in[0]) / 255.0f;
- out[1]= ((float)in[1]) / 255.0f;
- out[2]= ((float)in[2]) / 255.0f;
+ col_r[0]= ((float)col_ub[0]) / 255.0f;
+ col_r[1]= ((float)col_ub[1]) / 255.0f;
+ col_r[2]= ((float)col_ub[2]) / 255.0f;
}
-void rgb_float_to_byte(const float in[3], unsigned char out[3])
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4])
+{
+ col_r[0]= ((float)col_ub[0]) / 255.0f;
+ col_r[1]= ((float)col_ub[1]) / 255.0f;
+ col_r[2]= ((float)col_ub[2]) / 255.0f;
+ col_r[3]= ((float)col_ub[3]) / 255.0f;
+}
+
+void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3])
{
int r, g, b;
- r= (int)(in[0] * 255.0f);
- g= (int)(in[1] * 255.0f);
- b= (int)(in[2] * 255.0f);
+ r= (int)(col_f[0] * 255.0f);
+ g= (int)(col_f[1] * 255.0f);
+ b= (int)(col_f[2] * 255.0f);
- 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);
+ col_r[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r);
+ col_r[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g);
+ col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
+}
+
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4])
+{
+ int r, g, b, a;
+
+ r= (int)(col_f[0] * 255.0f);
+ g= (int)(col_f[1] * 255.0f);
+ b= (int)(col_f[2] * 255.0f);
+ a= (int)(col_f[3] * 255.0f);
+
+ col_r[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r);
+ col_r[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g);
+ col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
+ col_r[3]= (char)((a <= 0)? 0 : (a >= 255)? 255 : a);
}
/* ********************************* color transforms ********************************* */
@@ -490,9 +513,9 @@ void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset)
{
float rgb_float[3];
- rgb_byte_to_float(rgb, rgb_float);
+ rgb_uchar_to_float(rgb_float, rgb);
rgb_float_set_hue_float_offset(rgb_float, hue_offset);
- rgb_float_to_byte(rgb_float, rgb);
+ rgb_float_to_uchar(rgb, rgb_float);
}
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index 1247632cf79..2c7b13b86a2 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -62,6 +62,34 @@ MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
srgb[3] = linear[3];
}
+MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[4], const float linear[4])
+{
+ int r, g, b;
+
+ r = 255 * linearrgb_to_srgb(linear[0]);
+ g = 255 * linearrgb_to_srgb(linear[1]);
+ b = 255 * linearrgb_to_srgb(linear[2]);
+
+ srgb[0] = FTOCHAR(r);
+ srgb[1] = FTOCHAR(g);
+ srgb[2] = FTOCHAR(b);
+}
+
+MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
+{
+ int r, g, b, a;
+
+ r = 255 * linearrgb_to_srgb(linear[0]);
+ g = 255 * linearrgb_to_srgb(linear[1]);
+ b = 255 * linearrgb_to_srgb(linear[2]);
+ a = 255 * linear[3];
+
+ srgb[0] = FTOCHAR(r);
+ srgb[1] = FTOCHAR(g);
+ srgb[2] = FTOCHAR(b);
+ srgb[3] = FTOCHAR(a);
+}
+
/* predivide versions to work on associated/premultipled alpha. if this should
be done or not depends on the background the image will be composited over,
ideally you would never do color space conversion on an image with alpha