RE: HOW to display raw YUV data -----(problem still )???

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"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. ;)
.



Relevant Pages

  • Re: Can glReadPixels get Alpha in color buffer?
    ... I used glDrawPixels to draw some pixels in GL_AUX0,then I want to ... I use GL_RGBA as the format for draw ... So I just wonder how to get the right alpha? ...
    (comp.graphics.api.opengl)
  • Can glReadPixels get Alpha in color buffer?
    ... I used glDrawPixels to draw some pixels in GL_AUX0,then I want to read ... I use GL_RGBA as the format for draw and ... So I just wonder how to get the right alpha? ...
    (comp.graphics.api.opengl)
  • Re: Multiple date formats in a Table
    ... could choose a future date so they all sort at the end. ... However if you are set up to use UK format dates of dd/mm/yy, ... converting any entries where you know the full date. ... > iii) Once you've got a function that works, create a new query in design ...
    (microsoft.public.access.tablesdbdesign)
  • Re: mp3 in the car
    ... >>I started converting to CDs and I have spent years replacing all the ... I seriously doubt they'd be available in MP3 format. ... >>many aren't available in as cassettes. ... When I said converting, I meant replacing. ...
    (rec.audio.car)
  • Re: using "!!" in "c"
    ... that Keith was". ... Here's what the standard says about the "%p" format for the *printf ... The argument shall be a pointer to void. ... converting an integer to a pointer-to-function might ...
    (comp.lang.c)