Yuv display

hello
I want to display a YUV file,but when i run the program, it doesn’t seem
to display the file, it just display a green color.
The following is my program.

Can you please help me with that.

Thanks in advace

const int frameRate=25;
const int numByteFrame=24176144;
const int numSeconds=5;
int numByteTot;
char *bufferFrames;

SDL_Surface *screen;
SDL_Overlay *videoYUV;
SDL_Rect posizDest={0,0,176,144};
int framenum=40;

int sdl_display_yuv(char *finput)
{

int i=1;

int ret,ret1;
int numFrameTot;

numByteTot=framenum*numByteFrame;
fprintf(stdout,“framenum = %d, numByteTot = %d\n”,framenum,numByteTot);

//???SDL???
ret=SDL_Init ( SDL_INIT_VIDEO );
fprintf(stdout,“initialize SDL:%d\n”,ret);
if ( ret< 0 )
{
fprintf (stdout, “Couldn’t initialize SDL: %s\n”, SDL_GetError() );
return(-1);
}
atexit ( SDL_Quit ) ;

bufferFrames=(int *)calloc(numByteTot+1,sizeof(int));//?bufferFrames???
?
fprintf(stdout,“the size of memory allocated for bufferframes is
%d\n”,bufferFrames);
if(bufferFrames==0)
{
fprintf(stdout,“couldnt allocate memory for bufferframe\n”);
abort();
}

screen=SDL_SetVideoMode(176,144,24,SDL_SWSURFACE|SDL_ANYFORMAT);
if (screen==NULL)
{
fprintf (stdout, “Couldn’t Set SDL_video_mode: %s\n”, SDL_GetError() );
return(-1);
}
videoYUV=SDL_CreateYUVOverlay(176,144,SDL_YV12_OVERLAY,screen);
if (videoYUV==NULL)
{
fprintf (stdout, “Couldn’t create YUVoverlay: %s\n”, SDL_GetError() );
return(-1);
}

fprintf(stdout,“the program go here\n”);

for(i=0;i<framenum;i++)
{
SDL_LockYUVOverlay(videoYUV);
fprintf(stdout,“sdl start to lock the overlay\n”);

memcpy(videoYUV->pixels[0],&bufferFrames[i*numByteFrame],176*144);

memcpy(videoYUV->pixels[1],&bufferFrames[176144+inumByteFrame],176*144/4);

memcpy(videoYUV->pixels[2],&bufferFrames[176144+176144/4+inumByteFrame],176144/4);

SDL_UnlockYUVOverlay(videoYUV);
fprintf(stdout,“sdl start to unlock the overlay\n”);

 SDL_DisplayYUVOverlay(videoYUV,&posizDest);

fprintf(stdout,“sdl start to display the overlay\n”);
SDL_Delay(1000);
}
fprintf(stdout,“the sdl program go to the end/n”);
return(0);
}_________________________________________________________________
??? MSN Hotmail? http://www.hotmail.com

oceanfishzh at hotmail.com wrote:

I want to display a YUV file,but when i run the program, it doesn’t seem
to display the file, it just display a green color.

Have a look at the file conversions.c in Damien Douxchamps’s Coriander
source: http://cvs.sourceforge.net/viewcvs.py/coriander/coriander/

You may have a big/little endian problem with your video card.

Johann

PS: I would very much like to see a simple example of how to use YUV
with SDL. The man pages are a bit sketchy.–
Johann Schoonees Imaging & Sensing Team
Industrial Research Limited, PO Box 2225, Auckland, New Zealand
Phone +64 9 9203679 Fax +64 9 3028106 http://www.is.irl.cri.nz/
Camwire’s home: http://kauri.auck.irl.cri.nz/~johanns/camwire/

PS: I would very much like to see a simple example of how to use YUV
with SDL. The man pages are a bit sketchy.

Don’t you think the examples located int the SDL source distribution fit the bill ?
test/testoverlay.c
test/testoverlay2.c
(especially testoverlay2 with the moose :slight_smile:

Stephane

Stephane Marchesin wrote:

PS: I would very much like to see a simple example of how to use YUV
with SDL. The man pages are a bit sketchy.

Don’t you think the examples located int the SDL source distribution fit the bill ?
test/testoverlay.c
test/testoverlay2.c
(especially testoverlay2 with the moose :slight_smile:

Ah. Excuse me a moment while I get this egg off my face.

My lame excuse is that I did not find the Demos on www.libsdl.org all
that illuminating and I did not think of looking in the CVS for
examples. We don’t have the SDL source installed locally, you see.
No? Oh well…

Thanks Stephane.

Johann–
Johann Schoonees Imaging & Sensing Team
Industrial Research Limited, PO Box 2225, Auckland, New Zealand
Phone +64 9 9203679 Fax +64 9 3028106 http://www.is.irl.cri.nz/
Camwire’s home: http://kauri.auck.irl.cri.nz/~johanns/camwire/