RE: HOW to display raw YUV data -----(problem still )???
- From: "Jeremy Noring" <JeremyNoring@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 1 Dec 2005 10:25:02 -0800
"panzi" wrote:
> I can get the VPE/capture buffer's pointer,
> and get the YUY2 format data from the decoder.
> The pixels of each line and lines in one frame is known for me.
>
>
> The raw data as below: U0Y0V0Y1 U1Y2V1Y2.
>
> I use the simple converting algorithms(YUV->RGB).
> // Given char y0, char u, char y1, char v:
> long y0l = (y0 - 16) * 76260;
> long y1l = (y1 - 16) * 76260;
> short ux = u - 128;
> short vx = v - 128;
> short r0 = (y0l + 105007 * vx) >> 16;
> short g0 = (y0l - 25775 * ux - 53488 * vx) >> 16;
> short b0 = (y0l + 132720 * ux ) >> 16;
> short r1 = (y1l + 105007 * vx) >> 16;
> short g1 = (y1l - 25775 * ux - 53488 * vx) >> 16;
> short b1 = (y1l + 132720 * ux ) >> 16;
>
> it then can get the bmp, but the problem is: in the bitmap file.
> The color of some parts of the picture is wrong just red, or like patch.
>
> I know the best way is to converte the YUV 4:2:2 to YUV 4:4:4,then to
> convert to RGB.
> Is this the reason.
>
> Where can I find YUV 4:2:2 to YUV 4:4:4 converting algorithms.
> thanks advance.
Are you clipping your final values at 0 and 255?
That being said, "converting" from one YUV format to another is very easy,
because there isn't any conversion neccessary. Because your source and
destination images are all in the YUV colorspace, all of your pixels have
equivalent values (i.e: all Y, U, and V values are 8 bit and have identical
properties) and it's simply a matter of formatting.
Given that YUY2 is a packed, 16 bpp format, and YUV 4:4:4 is a packed, 32
bpp format, the conversion is very simple. See here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/YUVFormats.asp
So, looking at that, you see that YUV 4:4:4 devotes a full 32 bpp (including
an alpha channel that you probably don't need) to a single pixel, where as
YUY2 subsamples the U and V values.
To copy from YUY2 to YUV444, your code would look something like so (by no
means is this optimized/tested, but it should get you started):
char * pSource = pYUY2Buffer; // Note: this buffer will be w * h * 2 bytes
(16 bpp)
char * pDest = pYUV444Buffer; // note: this buffer will be w * h * 4 bytes
(32 bpp)
for( int rows = 0; rows < IMAGEHEIGHT; rows++ )
{
for( int columns = 0; columns < (IMAGEWIDTH / 2); columns++ ) // the
"/ 2" is because we're going to deal with two pixels at a time
{
// we'll copy two pixels at a time, since it's easier to deal with
that way.
char Y0, U0, Y1, V0; // these are going to be our YUY2 values
memcpy( &Y0, pSource, sizeof( char ) );
pSource++;
memcpy( &U0, pSource, sizeof( char ) );
pSource++;
memcpy( &Y1, pSource, sizeof( char ) );
pSource++;
memcpy( &V0, pSource, sizeof( char ) );
pSource++;
// So, we have the first two pixels--because the U and V values are
subsampled, we *reuse* them when converting
// to 32 bpp.
// First pixel
memcpy( pDest, &V0, sizeof( char ) );
pDest++;
memcpy( pDest, &U0, sizeof( char ) );
pDest++;
memcpy( pDest, &Y0, sizeof( char ) );
pDest += 2; // NOTE: not sure if you have to put in a value for the
alpha channel--we'll just skip over it.
// Second pixel
memcpy( pDest, &V0, sizeof( char ) );
pDest++;
memcpy( pDest, &U0, sizeof( char ) );
pDest++;
memcpy( pDest, &Y1, sizeof( char ) );
pDest += 2; // NOTE: not sure if you have to put in a value for the
alpha channel--we'll just skip over it.
}
}
Not sure what to do with the alpha channel--I'll leave that guy up to you to
figure out. ;)
.
- Prev by Date: Re: Mixing bitmaps with DIrectshow VIdeo
- Next by Date: Getting mouse evnts from Video playback
- Previous by thread: Performance issues with the analog output
- Next by thread: Getting mouse evnts from Video playback
- Index(es):
Relevant Pages
|