I
On 30/01/2010, at 9:21 AM, (*)·´`·.¸.»ÐëÄdMäñ·´`·.¸.»(*) wrote:
Hi,
I'm trying to convert yuv420p to rgb24 myself, could some one please
tell me what am I doing wrong ? here's the code I have so far ( I got
all the equations from wikipedia ) thanks.
void yuv2rgb(AVPicture *src, PixelFormat src_pix_fmt, AVPicture *dst,
PixelFormat dst_pix_fmt, int width, int height)
{
unsigned char y, u,v;
char *rgb = dst->data[0];
unsigned char *yptr = src->data[0];
unsigned char *uptr = src->data[1];
unsigned char *vptr = src->data[2];
int length = width * height;
for( int i = 0; i < length; i++ )
{
y = yptr[ i ];
u = uptr[ i / 4 ];
v = vptr[ i / 4 ];
Your YUV to RGB conversion is correct. But your chroma subsampling
assumption is not.
Looking at this for loop you are taking the chroma of every 4th X
pixel. This would work for chroma subsampling type 411 but not 420.
For 420 there is 1 chroma pixel for ever 4 pixels, 2 in the X
direction and 2 in the Y direction.
So you need something more like:
for (py=0; py < height; py++)
for (px =0; px < width; px++) {
y = yptr[px*width+py];
u = uptr[px/2*width/2+py/2];
v = vptr[px/2*width/2+py/2];
This assumes that you are using progressive 420 subsampling and not
interlaced 420 subsampling. Interlaced chroma subsampling is more
difficult.
HTH
Mark
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user