分类: LINUX
2007-08-18 18:37:01
+-----------+
+ YUV +
+-----------+
Images in YUV format is planed-oriented, with all data for Y channel
comes first, followed by U and V data.
==========+============+=============+==========================================
Sequence Frames Resolution Remark
==========+============+=============+==========================================
mobile
color 94 720x576 ITU 601/PAL
Interlaced, first field starts
on first line
4:2:2, 50 fields/sec
----------+------------+-------------+------------------------------------------
所以我在YUV420->RGB上修改了CONVERT 函数,实现这种格式的读取:
// convert yuv422(planed) into rgb mode for further dispaly operations
void CYuvTstDlg::convert_yuv422_rgb(unsigned char * src, unsigned char * dst,
int width, int height, int flipUV, int ColSpace)
{
unsigned char *Y, *U, *V ;
int y1, y2, u, v ;
int v1, v2, u1, u2 ;
unsigned char *pty1, *pty2 ;
int i, j ;
unsigned char *RGB1, *RGB2 ;
int r, g, b ;
//Initialization
Y = src;
V = Y + width * height;
U = Y + width * height + width * height / 2;
pty1 = Y;
RGB1 = dst;
for (j = 0; j < height; j++) {
for (i = 0; i < width; i += 2) {
if (flipUV) {
u = (*V++) - 128;
v = (*U++) - 128;
} else {
v = (*V++) - 128;
u = (*U++) - 128;
}
switch (ColSpace) {
case 0:
{
// M$ color space
v1 = ((v << 10) + (v << 9) + (v << 6) + (v << 5)) >> 10; // 1.593
u1 = ((u << 8) + (u << 7) + (u << 4)) >> 10; // 0.390
v2 = ((v << 9) + (v << 4)) >> 10; // 0.515
u2 = ((u << 11) + (u << 4)) >> 10; // 2.015
}
break;
// PAL specific
case 1:
{
v1 = ((v << 10) + (v << 7) + (v << 4)) >> 10; // 1.1406
u1 = ((u << 8) + (u << 7) + (u << 4) + (u << 3)) >> 10; // 0.3984
v2 = ((v << 9) + (v << 6) + (v << 4) + (v << 1)) >> 10; // 0.5800
u2 = ((u << 11) + (u << 5)) >> 10; // 2.0312
}
break;
// V4l2
case 2:
{
v1 = ((v << 10) + (v << 8) + (v << 7) + (v << 5)) >> 10; // 1.406
u1 = ((u << 8) + (u << 6) + (u << 5)) >> 10; // 0.343
v2 = ((v << 9) + (v << 7) + (v << 6) + (v << 5)) >> 10; // 0.718
u2 = ((u << 10) + (u << 9) + (u << 8) + (u << 4) + (u << 3)) >> 10; // 1.773
}
break;
case 3:
{
v1 = u1 = v2 = u2 = 0;
}
break;
default:
break;
} // end switch
//up-left
y1 = (*pty1++);
if (y1 > 0) {
r = y1 + (v1);
g = y1 - (u1) - (v2);
b = y1 + (u2);
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} else {
r = g = b = 0;
}
/* *RGB1++ = r; */
/* *RGB1++ = g; */
/* *RGB1++ = b; */
*RGB1++ = b;
*RGB1++ = g;
*RGB1++ = r;
//up-right
y1 = (*pty1++);
if (y1 > 0) {
r = y1 + (v1);
g = y1 - (u1) - (v2);
b = y1 + (u2);
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} else {
r = g = b = 0;
}
*RGB1++ = b;
*RGB1++ = g;
*RGB1++ = r;
/* *RGB1++ = r; */
/* *RGB1++ = g; */
/* *RGB1++ = b; */
}
//RGB1 += 3 * width;
//pty1 += width;
}
}
然后转换的效果还不错,就是机器性能不行,显示不太流畅。
然而,对于PACK格式的,下面这个附件里有很完整的函数实现,但是,就是它的CONVER FORMULA不知道是不是正确的。
|