YUV to RGB Functions

Source: Internet
Author: User

The following is the yuv420 to rgb24 function. You have tried this function. The parameters are as follows:
Src0 is the starting pointer of the Y volume, src1 is the starting pointer of the U volume, and src2 is the starting pointer of the v volume.
Dst_ori is the starting pointer of the RGB buffer.
Width is width, height is high

The YUV volume distribution for data in yuv420 format is
Y is the starting pointer of data.
The U volume is the starting pointer of the Data + width * Height
The V volume is the starting pointer of the Data + the width * height * 5/4

Void convertyuvtorgb (unsigned char * src0, unsigned char * src1, unsigned char * src2, unsigned char * dst_ori, int width, int height)
{
Extern long int crv_tab [];
Extern long int cbu_tab [];
Extern long int cgu_tab [];

Extern long int cgv_tab [];
Extern long int tab_76309 [];

Int y11, Y21;
Int Y12, y22;
Int Y13, y23;
Int Y14, y24;
Int U, V;
Int I, J;
Int C11, C21, C31, c41;
Int C12, c22, c32, c42;
Unsigned int dw;
Unsigned int * id1, * Id2;
Unsigned char * py1, * py2, * pu, * PV;
Unsigned char * D1, * D2;

D1 = dst_ori;
D1 + = width * height * 3-width * 3;
D2 = D1-width * 3;

Py1 = src0;
Pu = src1;
Pv = src2;
Py2 = py1 + width;

Id1 = (unsigned int *) d1;
Id2 = (unsigned int *) D2;

For (j = 0; j

{
/* Line J + 0 */
For (I = 0; I <width; I + = 4)
{
U = * Pu ++;
V = * PV ++;
C11 = crv_tab [v];
C21 = cgu_tab [u];
C31 = cgv_tab [v];
C41 = cbu_tab [u];
U = * Pu ++;
V = * PV ++;
C12 = crv_tab [v];
C22 = cgu_tab [u];
C32 = cgv_tab [v];
C42 = cbu_tab [u];

 

Y11 = tab_76309 [* py1 ++];/* (255/219) * 65536 */
Y12 = tab_76309 [* py1 ++];
Y13 = tab_76309 [* py1 ++];/* (255/219) * 65536 */
Y14 = tab_76309 [* py1 ++];

 

Y21 = tab_76309 [* py2 ++];
Y22 = tab_76309 [* py2 ++];
Y23 = tab_76309 [* py2 ++];
Y24 = tab_76309 [* py2 ++];

 

/* Rgbr */
DW = (CLP [(y11 + c41)> 16]) |
(CLP [(y11-C21-C31)> 16]) <8) |
(CLP [(y11 + C11)> 16]) <16) |
(CLP [(Y12 + c41)> 16]) <24 );
* Id1 ++ = dw;

 

/* Gbrg */
DW = (CLP [(Y12-C21-C31)> 16]) |
(CLP [(Y12 + C11)> 16]) <8) |
(CLP [(Y13 + c42)> 16]) <16) |
(CLP [(Y13-c22-c32)> 16]) <24 );
* Id1 ++ = dw;

 

/* Brgb */
DW = (CLP [(Y13 + C12)> 16]) |
(CLP [(Y14 + c42)> 16]) <8) |
(CLP [(Y14-c22-c32)> 16]) <16) |
(CLP [(Y14 + C12)> 16]) <24 );
* Id1 ++ = dw;

 

/* Rgbr */
DW = (CLP [(Y21 + c41)> 16]) |
(CLP [(Y21-C21-C31)> 16]) <8) |
(CLP [(Y21 + C11)> 16]) <16) |
(CLP [(y22 + c41)> 16]) <24 );
* Id2 ++ = dw;

 

/* Gbrg */
DW = (CLP [(y22-C21-C31)> 16]) |
(CLP [(y22 + C11)> 16]) <8) |
(CLP [(y23 + c42)> 16]) <16) |
(CLP [(y23-c22-c32)> 16]) <24 );
* Id2 ++ = dw;

 

/* Brgb */
DW = (CLP [(y23 + C12)> 16]) |
(CLP [(y24 + c42)> 16]) <8) |
(CLP [(y24-c22-c32)> 16]) <16) |
(CLP [(y24 + C12)> 16]) <24 );
* Id2 ++ = dw;
}
Id1-= (9 * width)> 2;
ID2-= (9 * width)> 2;
Py1 + = width;
Py2 + = width;
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.