Uyvy422 to rgb888 Conversion

Source: Internet
Author: User

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

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.