Added three XYZ color space options in code, will be activated later.

Thanks matt for the typing work :)
This commit is contained in:
Ton Roosendaal 2008-09-22 09:09:03 +00:00
parent b7e8df1eff
commit d1dedb2cef
3 changed files with 26 additions and 8 deletions

@ -322,6 +322,10 @@ void i_window(
float mat[][4]
);
#define BLI_CS_SMPTE 0
#define BLI_CS_REC709 1
#define BLI_CS_CIE 2
void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
void hex_to_rgb(char *hexcol, float *r, float *g, float *b);
void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
@ -329,7 +333,7 @@ void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb);
void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb);
void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr);
void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b);
void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b, int colorspace);
int constrain_rgb(float *r, float *g, float *b);
void gamma_correct_rgb(float *r, float *g, float *b);
unsigned int hsv_to_cpack(float h, float s, float v);

@ -3453,13 +3453,27 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
*lv = v;
}
/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
* SMPTE-C XYZ to RGB matrix*/
void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b)
/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */
void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)
{
switch (colorspace) {
case BLI_CS_SMPTE:
*r = (3.50570 * xc) + (-1.73964 * yc) + (-0.544011 * zc);
*g = (-1.06906 * xc) + (1.97781 * yc) + (0.0351720 * zc);
*b = (0.0563117 * xc) + (-0.196994 * yc) + (1.05005 * zc);
break;
case BLI_CS_REC709:
*r = (3.240476 * xc) + (-1.537150 * yc) + (-0.498535 * zc);
*g = (-0.969256 * xc) + (1.875992 * yc) + (0.041556 * zc);
*b = (0.055648 * xc) + (-0.204043 * yc) + (1.057311 * zc);
break;
case BLI_CS_CIE:
*r = (2.28783848734076f * xc) + (-0.833367677835217f * yc) + (-0.454470795871421f * zc);
*g = (-0.511651380743862f * xc) + (1.42275837632178f * yc) + (0.0888930017552939f * zc);
*b = (0.00572040983140966f * xc) + (-0.0159068485104036f * yc) + (1.0101864083734f * zc);
break;
}
}
/*If the requested RGB shade contains a negative weight for

@ -594,7 +594,7 @@ void shadeSunView(struct SunSky *sunsky, float *colf, float *rco, float *view, f
colorxyz[1] /= scale;
colorxyz[2] /= scale;
xyz_to_rgb(colorxyz[0], colorxyz[1], colorxyz[2], &colf[0], &colf[1], &colf[2]);
xyz_to_rgb(colorxyz[0], colorxyz[1], colorxyz[2], &colf[0], &colf[1], &colf[2], BLI_CS_SMPTE);
ClipColor(colf);
}