Well finally I could display an image using SDL_DisolayYUVOverlay, but I guessed well I had to do the RGB->YUV pixel conversion.
I based the conversion on which I read here:
http://www.fourcc.org/fccyvrgb.php (the one based on the "Video Demystified" book).
There are another formulas, I have no clear why this one works for me and why others do not. I could gess it has to do with the YUV scheme selected.
Besides that I had to the sheme conversion:
Code:
inline void ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o)
{
int x,y;
int yuv[3];
Uint8 *p,*op[3];
SDL_LockSurface(s);
SDL_LockYUVOverlay(o);
/* Convert */
for(y=0; y < s->h && y < o->h; y++)
{
p = ((Uint8 *)s->pixels) + s->pitch*y;
op[0]=o->pixels[0]+o->pitches[0]*y;
op[1]=o->pixels[1]+o->pitches[1]*(y/2);
op[2]=o->pixels[2]+o->pitches[2]*(y/2);
for(x=0; x<s->w && x<o->w; x++)
{
RGBtoYUV(p,yuv);
*(op[0]++)=yuv[0];
if(x%2==0 && y%2==0)
{
*(op[1]++)=yuv[1];
*(op[2]++)=yuv[2];
}
p+=s->format->BytesPerPixel;
}
}
SDL_UnlockYUVOverlay(o);
SDL_UnlockSurface(s);
}
Then I scale the bmp to display:
Code:
SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
SDL_Overlay *overlay = NULL;
:
:
:
overlay = SDL_CreateYUVOverlay(bmp->w,bmp->h, SDL_IYUV_OVERLAY , screen);
ConvertRGBtoIYUV(bmp, overlay);
SDL_Rect video_rect;
video_rect.x = 200;
video_rect.y = 0;
video_rect.w = bmp->w*3; // I scaled it by 3 times from its original length
video_rect.h = bmp->h*3;
SDL_DisplayYUVOverlay(overlay, &video_rect);
// DRAWING ENDS HERE
SDL_Flip(screen);
Maybe there are better ways to do these, any suggestions are welcome. Thanks
Regards
Kovi