![]() |
![]() |
Functions | |
void | IMG_ycbcr422pl_to_rgb565 (const short coeff[5], const unsigned char *restrict y_data, const unsigned char *restrict cb_data, const unsigned char *restrict cr_data, unsigned short *restrict rgb_data, unsigned num_pixels) |
void IMG_ycbcr422pl_to_rgb565 | ( | const short | coeff[5], | |
const unsigned char *restrict | y_data, | |||
const unsigned char *restrict | cb_data, | |||
const unsigned char *restrict | cr_data, | |||
unsigned short *restrict | rgb_data, | |||
unsigned | num_pixels | |||
) |
[ coeff[0] 0.0000 coeff[1] ] [ Y' - 16 ] [ R'] [ coeff[0] coeff[2] coeff[3] ] * [ Cb - 128 ] = [ G'] [ coeff[0] coeff[4] 0.0000 ] [ Cr - 128 ] [ B']
1. Y'CbCr -> RGB conversion with RGB levels that correspond to the 219-level range of Y'. Expected ranges are [16..235] for Y' and [16..240] for Cb and Cr. coeff[] = { 0x2000, 0x2BDD, -0x0AC5, -0x1658, 0x3770 }; [ 1.0000 0.0000 1.3707 ] [ Y' - 16 ] [ R'] [ 1.0000 -0.3365 -0.6982 ] * [ Cb - 128 ] = [ G'] [ 1.0000 1.7324 0.0000 ] [ Cr - 128 ] [ B'] 2. Y'CbCr -> RGB conversion with the 219-level range of Y' expanded to fill the full RGB dynamic range. (The matrix has been scaled by 255/219.) Expected ranges are [16..235] for Y' and [16..240] for Cb and Cr. coeff[] = { 0x2543, 0x3313, -0x0C8A, -0x1A04, 0x408D }; [ 1.1644 0.0000 1.5960 ] [ Y' - 16 ] [ R'] [ 1.1644 -0.3918 -0.8130 ] * [ Cb - 128 ] = [ G'] [ 1.1644 2.0172 0.0000 ] [ Cr - 128 ] [ B'] 3. Y'CbCr -> BGR conversion with RGB levels that correspond to the 219-level range of Y'. This is equivalent to #1 above, except that the R, G, and B output order in the packed pixels is reversed. Note: The 'cr_data' and 'cb_data' input arguments must be exchanged for this example as indicated under USAGE above. coeff[] = { 0x2000, 0x3770, -0x1658, -0x0AC5, 0x2BDD }; [ 1.0000 0.0000 1.7324 ] [ Y' - 16 ] [ B'] [ 1.0000 -0.6982 -0.3365 ] * [ Cr - 128 ] = [ G'] [ 1.0000 1.3707 0.0000 ] [ Cb - 128 ] [ R'] 4. Y'CbCr -> BGR conversion with the 219-level range of Y' expanded to fill the full RGB dynamic range. This is equivalent to #2 above, except that the R, G, and B output order in the packed pixels is reversed. Note: The 'cr_data' and 'cb_data' input arguments must be exchanged for this example as indicated under USAGE above. coeff[] = { 0x2000, 0x408D, -0x1A04, -0x0C8A, 0x3313 }; [ 1.0000 0.0000 2.0172 ] [ Y' - 16 ] [ B'] [ 1.0000 -0.8130 -0.3918 ] * [ Cr - 128 ] = [ G'] [ 1.0000 1.5960 0.0000 ] [ Cb - 128 ] [ R']
Other scalings of the color differences (B'-Y') and (R'-Y') (sometimes incorrectly referred to as U and V) are supported, as long as the color differences are unsigned values centered around 128 rather than signed values centered around 0, as noted above.
coeff | Matrix coefficients. | |
y_data | Luminence data (Y') | |
cb_data | Blue color-diff (B'-Y') | |
cr_data | Red color-diff (R'-Y') | |
rgb_data | RGB 5:6:5 packed pixel out. | |
num_pixels | Number of luma pixels to process |
[ coeff[0] 0.0000 coeff[1] ] [ Y' - 16 ] [ R'] [ coeff[0] coeff[2] coeff[3] ] * [ Cb - 128 ] = [ G'] [ coeff[0] coeff[4] 0.0000 ] [ Cr - 128 ] [ B']
15 11 10 5 4 0 +----------+----------+----------+ | Red | Green | Blue | +----------+----------+----------+
This kernel can also return the red, green, and blue values in the opposite order if a particular application requires it. This is achieved by exchanging the 'cb_data' and 'cr_data' arguments when calling the function, and by reversing the order of coefficients in coeff[1] through coeff[4]. This essentially implements the following matrix multiply:
[ coeff[0] 0.0000 coeff[4] ] [ Y' - 16 ] [ B'] [ coeff[0] coeff[3] coeff[2] ] * [ Cr - 128 ] = [ G'] [ coeff[0] coeff[1] 0.0000 ] [ Cb - 128 ] [ R']
The reversed RGB ordering output by this mode is as follows:
15 11 10 5 4 0 +----------+----------+----------+ | Blue | Green | Red | +----------+----------+----------+