[SDL] YUV

Sam Lantinga slouken at devolution.com
Thu Jun 8 00:18:12 PDT 2000


> Question.  I took a look at the YUV overlay struct.  From what it looks
> like it has a RGB pixles inside it?  I am given three arrays of data.
> They jsut happen to be Y U and V  Combined they made an image. :)  I am
> looking to do somthing simpilar to the following code.  Any suggestions.

The overlay struct has generic pixels in it which are defined by the 
particular format.

> YUVimage yuv
> yuv.y = Y;
> yuv.u = U;
> yuv.v = V;
> yuc.show();

Here's a good example:

struct YUVimage {
  SDL_Overlay *overlay;
  unsigned char *y;
  unsigned char *u;
  unsigned char *v;
} yuv;

SDL_Surface *screen;

    /* Create a YV12 image (Y + V + U) */
    yuv.overlay = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, screen);
    if ( ! yuv.overlay ) {
        /* error */;
    }

    for ( ; ; ) {
        if ( SDL_LockYUVOverlay(yuv.overlay) < 0 ) {
            /* error */;
        }
        yuv.y = (unsigned char *)yuv.overlay->pixels;
        yuv.u = (unsigned char *)yuv.overlay->pixels + (w*h) + (w*h)/4;
        yuv.v = (unsigned char *)yuv.overlay->pixels + (w*h);
    
    ... decode into yuv.{y,u,v} ...
    
        SDL_UnlockYUVOverlay(yuv.overlay);
    
        SDL_DisplayYUVOverlay(yuv.overlay, &dstrect);
    }
    SDL_FreeYUVOverlay(yuv.overlay);

SMPEG (http://cvs.lokigames.com/) is a good example of this code.

More information on YUV formats can be found online at:
http://www.webartz.com/fourcc/indexyuv.htm

> P.S. Anyone working on the documention for this?

Akawaka?

See ya!
	-Sam Lantinga, Lead Programmer, Loki Entertainment Software



More information about the SDL mailing list