📄 ycbcr422.c
字号:
///////////////////////////////////////////////////////////////////////////////
//
// YCbCr422.c
//
// DESCRIPTION
// Accepts the MCU blocks available in 4:2:2 format. Convert them to the
// specified formats:
// 1. RGB32
// 2. RGB24
// 3. RGB565
// 4. RGB555
//
//
///////////////////////////////////////////////////////////////////////////////
#include "YCbCr422.h"
#if SUPPORT_YUV422
#if SUPPORT_RGB32
/////////////////////////////////////////////////////////////////////////////
// NAME
// YCbCr422ToRGB32
//
// DESCRIPTION
// Convert YCbCr422 format to RGB32 format
//
// INPUTS
// imageBlocks - pointer to YUV buffers
// decodedImage - pointer to output image structure
//
// OUTPUTS
// decodedImage - store output in output image structure
//
// RETURN VALUE
// Always returns JPEG_OK
//
/////////////////////////////////////////////////////////////////////////////
int YCbCr422ToRGB32
(
OP_UINT8 *imageBlocks,
JPEGFieldDec *decodedImage
)
{
int i;
int j;
int k;
OP_UINT8 *pY1;
OP_UINT8 *pY2;
OP_UINT8 *pCb;
OP_UINT8 *pCr;
OP_UINT8 *destLine;
OP_UINT8 y11;
OP_UINT8 y12;
OP_UINT8 y13;
OP_UINT8 y14;
OP_UINT8 Cb11;
OP_UINT8 Cb13;
OP_UINT8 Cr11;
OP_UINT8 Cr13;
OP_UINT32 *id1;
int fieldRowDist;
pY1 = imageBlocks;
pY2 = pY1 + BLOCK_AREA;
pCb = pY2 + BLOCK_AREA;
pCr = pCb + BLOCK_AREA;
fieldRowDist = decodedImage->fieldRowDist;
destLine = decodedImage->mcuBuf;
k = ((OP_UINT32)(decodedImage->mcuBufRowEnd - decodedImage->mcuBuf)) >> 3;
if(k > 8)
{
k = 8;
}
k = 8 - k;
// 8 rows per block
for (i = 8; i > 0; i --)
{
id1 = (OP_UINT32 *) destLine;
// two iterations per row
for (j = 4; j > 0; j --)
{
Cb11 = *pCb++;
Cb13 = *pCb++;
Cr11 = *pCr++;
Cr13 = *pCr++;
if (j > 2)
{
y11 = *pY1++;
y12 = *pY1++;
y13 = *pY1++;
y14 = *pY1++;
}
else
{
y11 = *pY2++;
y12 = *pY2++;
y13 = *pY2++;
y14 = *pY2++;
}
if(j * 2 > k)
{
// RGB
*id1 ++ = GetR(y11, Cr11, 0) | (GetG(y11, Cr11, Cb11, 0) << 8) |
(GetB(y11, Cb11, 0) << 16) | 0xff000000L;
// RGB
*id1 ++ = GetR(y12, Cr11, 0) | (GetG(y12, Cr11, Cb11, 0) << 8) |
(GetB(y12, Cb11, 0) << 16) | 0xff000000L;
}
if(j * 2 - 1 > k)
{
// RGB
*id1 ++ = GetR(y13, Cr13, 0) | (GetG(y13, Cr13, Cb13, 0) << 8) |
(GetB(y13, Cb13, 0) << 16) | 0xff000000L;
// RGB
*id1 ++ = GetR(y14, Cr13, 0) | (GetG(y14, Cr13, Cb13, 0) << 8) |
(GetB(y14, Cb13, 0) << 16) | 0xff000000L;
}
}
destLine += fieldRowDist;
}
decodedImage->mcuBuf += 64;
return JPEG_OK;
}
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
// NAME
// NullFunction
//
// DESCRIPTION
// A dummy function
//
// INPUTS
// imageBlocks - pointer to YUV buffers
// decodedImage - pointer to output image structure
//
// OUTPUTS
// none.
//
// RETURN VALUE
// Always returns JPEG_OK
//
/////////////////////////////////////////////////////////////////////////////
int NullFunction
(
OP_UINT8 *imageBlocks,
JPEGFieldDec *decodedImage
)
{
return JPEG_OK;
}
#if USE_C
/////////////////////////////////////////////////////////////////////////////
// NAME
// GetR
//
// DESCRIPTION
// Convert Y and Cr to Red
//
// INPUTS
// y - Y component
// cr - Cr component
// offset - Offset for conversion
//
// OUTPUTS
// none.
//
// RETURN VALUE
// Returns the red component.
//
/////////////////////////////////////////////////////////////////////////////
OP_UINT8 GetR
(
OP_UINT8 y,
OP_UINT8 cr,
OP_UINT8 offset
)
{
int temp;
temp = y + ((CREDCR * (cr - 128)) >> CRGBSHIFT) + offset;
return (temp > 0x00ff) ? 0xff : ((temp < 0) ? 0 : (OP_UINT8)temp);
}
/////////////////////////////////////////////////////////////////////////////
// NAME
// GetG
//
// DESCRIPTION
// Convert Y and Cr and Cb to Green
//
// INPUTS
// y - Y component
// cr - Cr component
// cb - Cb component
// offset - Offset for conversion
//
// OUTPUTS
// none.
//
// RETURN VALUE
// Returns the green component.
//
/////////////////////////////////////////////////////////////////////////////
OP_UINT8 GetG
(
OP_UINT8 y,
OP_UINT8 cr,
OP_UINT8 cb,
OP_UINT8 offset
)
{
int temp;
temp = y + ((CGREENCR * (cr - 128) + CGREENCB * (cb - 128)) >> CRGBSHIFT) + offset;
return (temp > 0x00ff) ? 0xff : ((temp < 0) ? 0 : (OP_UINT8)temp);
}
/////////////////////////////////////////////////////////////////////////////
// NAME
// GetB
//
// DESCRIPTION
// Convert Y and Cb to Blue
//
// INPUTS
// y - Y component
// cb - Cb component
// offset - Offset for conversion
//
// OUTPUTS
// none.
//
// RETURN VALUE
// Returns the blue component.
//
/////////////////////////////////////////////////////////////////////////////
OP_UINT8 GetB
(
OP_UINT8 y,
OP_UINT8 cb,
OP_UINT8 offset
)
{
int temp;
temp = y + ((CBLUECB * (cb - 128)) >> CRGBSHIFT) + offset;
return (temp > 0x00ff) ? 0xff : ((temp < 0) ? 0 : (OP_UINT8)temp);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -