YCbCr←→RGB24无法反转。
根据stackoverflow - Convert RGB to YCbCr - C code:
bar/fixtures
结果:
#include <stdio.h>
void rgbToYuv(u_int8_t R, u_int8_t G, u_int8_t B, int8_t *Y, int8_t *U, int8_t *V) {
*Y = 0.257*R + 0.504*G + 0.098*B + 16;
*U = -0.148*R - 0.291*G + 0.439*B + 128;
*V = 0.439*R - 0.368*G - 0.071*B + 128;
}
void yuvToRgb(int8_t Y, int8_t U, int8_t V, u_int8_t *R, u_int8_t *G, u_int8_t *B) {
*R = 1.164*(Y-16) + 1.596*(V-128);
*G = 1.164*(Y-16) - 0.813*(V-128) - 0.392*(U-128);
*B = 1.164*(Y-16) + 2.017*(U-128);
}
int main() {
u_int8_t R = 0XFF, G = 0, B = 0;
int8_t Y, U, V;
rgbToYuv(R, G, B, &Y, &U, &V);
printf("RGB(%d, %d, %d) -> YUV(%d, %d, %d) \n", R, G, B, Y, U, V);
yuvToRgb(Y, U, V, &R, &G, &B);
printf("YUV(%d, %d, %d) -> RGB(%d, %d, %d) \n", Y, U, V, R, G, B);
return 0;
}
那是什么问题??