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:
authorAaron Carlisle <carlisle.b3d@gmail.com>2018-04-30 01:00:45 +0300
committerAaron Carlisle <carlisle.b3d@gmail.com>2018-04-30 01:00:45 +0300
commit128506eeb1a2d87393061b4c9783289a5e4b3275 (patch)
tree2b2fd7159489c128f420c949ad24fa6cfd3fefc3 /source/blender/blenlib
parent16c05161e76621a1943f27abd6bd9f7ee5564efd (diff)
BLI Color: YUV to/from rgb colorspace option
This commit does two things: - Adds an option to do the calculation in different color spaces (BT601 or BT709). - Changes the default caluclation from legacy BT601 to BT709. This affects several areas: - UI areas (mainly scopes) - ViewLevelsNode - Several other nodes that use `COM_ConvertOperation.h`
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_math_color.h9
-rw-r--r--source/blender/blenlib/intern/math_color.c37
2 files changed, 35 insertions, 11 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 34fc52c12c0..72d29164988 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -51,6 +51,10 @@ extern "C" {
#define BLI_YCC_ITU_BT709 1
#define BLI_YCC_JFIF_0_255 2
+/* YUV */
+#define BLI_YUV_ITU_BT601 0
+#define BLI_YUV_ITU_BT709 1
+
/******************* Conversion to RGB ********************/
void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
@@ -58,14 +62,14 @@ void hsv_to_rgb_v(const float hsv[3], float r_rgb[3]);
void hsl_to_rgb(float h, float c, float l, float *r, float *g, float *b);
void hsl_to_rgb_v(const float hcl[3], float r_rgb[3]);
void hex_to_rgb(char *hexcol, float *r, float *g, float *b);
-void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb);
+void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb, int colorspace);
void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, int colorspace);
void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b, int colorspace);
void cpack_to_rgb(unsigned int col, float *r, float *g, float *b);
/***************** Conversion from RGB ********************/
-void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
+void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv, int colorspace);
void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace);
void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3]);
@@ -164,4 +168,3 @@ void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *o
#endif
#endif /* __BLI_MATH_COLOR_H__ */
-
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 6d7d24c79c3..a091595bc6c 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -83,24 +83,45 @@ void hsl_to_rgb_v(const float hsl[3], float r_rgb[3])
hsl_to_rgb(hsl[0], hsl[1], hsl[2], &r_rgb[0], &r_rgb[1], &r_rgb[2]);
}
-void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv)
+void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv, int colorspace)
{
float y, u, v;
- y = 0.299f * r + 0.587f * g + 0.114f * b;
- u = -0.147f * r - 0.289f * g + 0.436f * b;
- v = 0.615f * r - 0.515f * g - 0.100f * b;
+
+ switch (colorspace) {
+ case BLI_YUV_ITU_BT601:
+ y = 0.299f * r + 0.587f * g + 0.114f * b;
+ u = -0.147f * r - 0.289f * g + 0.436f * b;
+ v = 0.615f * r - 0.515f * g - 0.100f * b;
+ break;
+ case BLI_YUV_ITU_BT709:
+ default:
+ y = 0.2126f * r + 0.7152f * g + 0.0722f * b;
+ u = -0.09991f * r - 0.33609f * g + 0.436f * b;
+ v = 0.615f * r - 0.55861f * g - 0.05639f * b;
+ break;
+ }
*ly = y;
*lu = u;
*lv = v;
}
-void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb)
+void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb, int colorspace)
{
float r, g, b;
- r = y + 1.140f * v;
- g = y - 0.394f * u - 0.581f * v;
- b = y + 2.032f * u;
+
+ switch (colorspace) {
+ case BLI_YUV_ITU_BT601:
+ r = y + 1.140f * v;
+ g = y - 0.394f * u - 0.581f * v;
+ b = y + 2.032f * u;
+ break;
+ case BLI_YUV_ITU_BT709:
+ r = y + 1.28033f * v;
+ g = y - 0.21482f * u - 0.38059f * v;
+ b = y + 2.12798f * u;
+ break;
+ }
*lr = r;
*lg = g;