完整 ycrcb转rgb

#include <stdio.h>

int main() {
    
    
	float kr_value[3] = {
    
     0.299f, 0.2126f, 0.2627f };
	float kb_value[3] = {
    
     0.114f, 0.0722f, 0.0593f };

	for (int i = 0; i < 3; i++) {
    
    
		float kr = kr_value[i];
		float kb = kb_value[i];

		printf("R = Y + %0.4f * Cr\n", 2.0f * (1.0f - kr));
		printf("G = Y + %0.4f * Cr + %0.4f * Cb\n", 
		(2.0f * (1.0f - kr) * kr) / (kr + kb - 1.0f), 
		(2.0f * (1.0f - kb) * kb) / (kr + kb - 1.0f));
		printf("B = Y + %0.4f * Cb\n", 2.0f * (1.0f - kb));
		printf("\n");
	}
	printf("\n");

	float aa[3] = {
    
     0.299, 0.2126, 0.2627 };
	float bb[3] = {
    
     0.587, 0.7152, 0.6780 };
	float cc[3] = {
    
     0.114, 0.0722, 0.0593 };
	float dd[3] = {
    
     1.772, 1.8556, 1.8814 };
	float ee[3] ={
    
     1.402, 1.5748, 1.4747};

	for (int i = 0; i < 3; i++) {
    
    
		float a = aa[i];
		float b = bb[i];
		float c = cc[i];
		float d = dd[i];
		float e = ee[i];

		printf("R = Y + %0.4f * Cr\n", e);
		printf("G = Y - %0.4f * Cr - %0.4f * Cb\n", (a * e / b), (c * d / b));
		printf("B = Y + %0.4f * Cb\n", d);
		printf("\n");
	}

	//R = Y + e * Cr
	//G = Y - (a * e / b) * Cr - (c * d / b) * Cb
	//B = Y + d * Cb

	return 0;
}
BT.601
R = Y + 1.4020 * Cr
G = Y + -0.7141 * Cr + -0.3441 * Cb
B = Y + 1.7720 * Cb
 BT.709
R = Y + 1.5748 * Cr
G = Y + -0.4681 * Cr + -0.1873 * Cb
B = Y + 1.8556 * Cb
BT.2020
R = Y + 1.4746 * Cr
G = Y + -0.5714 * Cr + -0.1646 * Cb
B = Y + 1.8814 * Cb

https://www.khronos.org/registry/DataFormat/specs/1.2/dataformat.1.2.html#_bt_709_bt_2020_primary_conversion_example
1.28033
-0.21482 -0.38059
2.12798

1.13983
−0.39465 −0.580600
2.03211

// BT.601, which is the standard for SDTV.
GLfloat kColorConversion601Default[] = {
1.164, 1.164, 1.164,
0.0, -0.392, 2.017,
1.596, -0.813, 0.0,
};

// BT.601 full range (ref: http://www.equasys.de/colorconversion.html)
GLfloat kColorConversion601FullRangeDefault[] = {
1.0, 1.0, 1.0,
0.0, -0.343, 1.765,
1.4, -0.711, 0.0,
};

// BT.709, which is the standard for HDTV.
GLfloat kColorConversion709Default[] = {
1.164, 1.164, 1.164,
0.0, -0.213, 2.112,
1.793, -0.533, 0.0,
};

 // BT.601, which is the standard for SDTV is provided as a reference
 /*
  rgb = mat3(      1,       1,       1,
  0, -.39465, 2.03211,
  1.13983, -.58060,       0) * yuv;
  */
 
 // Using BT.709 which is the standard for HDTV
 rgb = mat3(      1,       1,       1,
            0, -.21482, 2.12798,
            1.28033, -.38059,       0) * yuv;

https://www.bilibili.com/read/cv2832484/

猜你喜欢

转载自blog.csdn.net/chao56789/article/details/110054379