In the embedded system, because the data from the camera color set is generally in YUV format, but framebuffer generally only receives RGB data, the conversion from YUV to RGB color space is required.
The conversion from YUV to RGB generally refers to the conversion of Y, U, and V components according to the standard conversion matrix. The yuv422i sequence is used as an example:
// Input yuv422i buffer data and output RGB buffer data; static int uyvy422torgb888 (const unsigned char * src_buffer, int W, int H, const unsigned char * des_buffer) {unsigned char * YUV, * RGB; unsigned char U, V, Y1, Y2; YUV = src_buffer; RGB = des_buffer; If (YUV = NULL | RGB = NULL) {printf ("error: input data null! \ N "); Return-1;} int size = W * h; For (INT I = 0; I <size; I + = 2) {y1 = YUV [2 * I + 1]; y2 = YUV [2 * I + 3]; u = YUV [2 * I]; V = YUV [2 * I + 2]; # If 0rgb [3 * I] = (unsigned char) (Y1 + 1.402*(u-128 )); RGB [3 * I + 1] = (unsigned char) (Y1-0.344*(u-128)-0.714*(V-128 )); RGB [3 * I + 2] = (unsigned char) (Y1 + 1.772 * (V-128); RGB [3 * I + 3] = (unsigned char) (y2 + 1.375 * (u-128); RGB [3 * I + 4] = (unsigned char) (Y2-0.344 * (u-128) -0.714 * (V-128); RGB [3 * I + 5] = (unsigned char) (y2 + 1.772*(V-128 )); # endif // shift operation is used to improve performance. RGB [3 * I] = (unsigned char) (Y1 + (u-128) + (104 * (u-128)> 8); RGB [3 * I + 1] = (unsigned char) (Y1-(89 * (V-128)> 8)-(183 * (u-128)> 8 )); RGB [3 * I + 2] = (unsigned char) (Y1 + (V-128) + (199 * (V-128)> 8 )); RGB [3 * I + 3] = (unsigned char) (y2 + (u-128) + (104 * (u-128)> 8 )); RGB [3 * I + 4] = (unsigned char) (Y2-(89 * (V-128)> 8) -(183 * (u-128)> 8); RGB [3 * I + 5] = (unsigned char) (y2 + (V-128) + (199 * (V-128)> 8);} return 0 ;}
Reference: Wiki