资源简介
yuv422包括打包和分片两种格式
yuv422与yuv420互转
代码片段和文件信息
/*
*YUV422->YUV420
*/
#if 0
//YUV422是分片组装
void YUV422toYUV420(unsigned char *yuv420 unsigned char *yuv422 int Y_width int Y_height)
{
int UV_width_422 = Y_width>>1; //422色度信号U和V宽度
int UV_height_422 = Y_height; //422色度信号U和V高度
int UV_width_420 = Y_width>>1; //420色度信号U和V宽度
int UV_height_420 = Y_height>>1; //420色度信号U和V高度
int Ylen = Y_width*Y_height;
unsigned char *p_Y420 = yuv420 ;
unsigned char *p_U420 = p_Y420 + Ylen ;
unsigned char *p_V420 = p_U420 + Ylen/4 ;
unsigned char *p_Y422 = yuv422 ;
unsigned char *p_U422 = p_Y422 + Ylen ;
unsigned char *p_V422 = p_U422 + Ylen/2 ;
//亮度信号Y复制
memcpy(p_Y420 p_Y422 Ylen);
//U、V取平均值
int k = 0 ;
BYTE u1 u2 v1 v2 ;
for ( int i = 0 ; i < UV_height_422 ; i+= 2 )
{
for ( int j = 0 ; j < UV_width_422 ; j++ )
{
u1 = *(p_U422+i*UV_width_422+j) ;
u2 = *(p_U422+(i+1)*UV_width_422+j) ;
v1 = *(p_V422+i*UV_width_422+j) ;
v2 = *(p_V422+(i+1)*UV_width_422+j) ;
//色度信号U复制
*(p_U420+k*UV_width_420+j) = ((u1+u2) >> 1) ;
//色度信号V复制
*(p_V420+k*UV_width_420+j) = ((v1+v2) >> 1) ;
}
k++ ;
}
}
#else
//YUV422是打包组装
void YUV422toYUV420(unsigned char *yuv420 unsigned char *yuv422 int Y_width int Y_height)
{
int len = Y_width * Y_height;
unsigned char* pY420 = yuv420;
unsigned char* pU420 = yuv420 + len;
unsigned char* pV420 = pU420 + len/4;
unsigned char* pY422 = yuv422;
for (int i = 0; i {
*pY420 = *pY422;
pY420++;
pY422+=2;
}
unsigned char* pU422 = yuv422 + 1;
for (int i = 0; i {
*pU420 = (*pU422 + *(pU422 + 4))/2;
pU420++;
pU422+=8;
}
unsigned char* pV422 = yuv422 + 3;
for (int i = 0; i {
*pV420 = (*pV422 + *(pV422 + 4))
- 上一篇:《C语言接口与实现》书中源代码
- 下一篇:ATSHA204的C语言代码
评论
共有 条评论