4 SDL_Rect in a single SDL_Surface

Hi all,
i’m writing an application that use 4 SDL_Rect in a single SDL_Surface. The
source image came from a videograbber and are in YUV format. So i create 4
YUVOverlay and link them with the Y, U and V components of my image in the
follow manner.

overlay = SDL_CreateYUVOverlay(horz, vert, SDL_IYUV_OVERLAY, screen);
overlay2= SDL_CreateYUVOverlay(horz, vert, SDL_IYUV_OVERLAY, screen);
overlay3= SDL_CreateYUVOverlay(horz, vert, SDL_IYUV_OVERLAY, screen);
overlay4= SDL_CreateYUVOverlay(horz, vert, SDL_IYUV_OVERLAY, screen);

pY=image1;
pU=image1+DIM_WIDTH*DIM_HEIGHT;
pV=pU+(DIM_WIDTH*DIM_HEIGHT/4);

pY2=image2;
pU2=image2+DIM_WIDTH*DIM_HEIGHT;
pV2=pU+(DIM_WIDTH*DIM_HEIGHT/4);
	.....................

	....................
overlay->pixels[0] = pY;
overlay->pixels[1] = pU;
overlay->pixels[2] = pV;

overlay2->pixels[0] = pY2;
overlay2->pixels[1] = pU2;
overlay2->pixels[2] = pV2;

overlay3->pixels[0] = pY3;
overlay3->pixels[1] = pU3;
overlay3->pixels[2] = pV3;

overlay4->pixels[0] = pY4;
overlay4->pixels[1] = pU4;
overlay4->pixels[2] = pV4;
............................

After I set the position and the size of SDL_Rect in the SDL_Surface and copy
a new image in the 4 YUVOverlay like the follow.

dstrect.x = 0;
dstrect.y = 0;
dstrect.w = (horz-1)/2;
dstrect.h = (vert-1)/2;

	dstrect2.x = (horz-1)/2;
	dstrect2.y = 0;
	dstrect2.w = horz/2;
	dstrect2.h = vert/2;

	dstrect3.x = 0;
	dstrect3.y = vert/2;
	dstrect3.w = (horz-1)/2;
	dstrect3.h = vert/2;

	dstrect4.x = (horz-1)/2;
	dstrect4.y = vert/2;
	dstrect4.w = (horz-1)/2;
	dstrect4.h = vert/2;

	SDL_LockYUVOverlay(overlay);
	memcpy(image1, data+(IMG_BYTE_SIZE_YUV*0), IMG_BYTE_SIZE_YUV);
	SDL_DisplayYUVOverlay(overlay, &dstrect);
	SDL_UnlockYUVOverlay(overlay);

	SDL_LockYUVOverlay(overlay2);
	memcpy(image2, data+(IMG_BYTE_SIZE_YUV*1), IMG_BYTE_SIZE_YUV);
	SDL_DisplayYUVOverlay(overlay2, &dstrect2);
	SDL_UnlockYUVOverlay(overlay2);

	SDL_LockYUVOverlay(overlay3);
	memcpy(image3, data+(IMG_BYTE_SIZE_YUV*0), IMG_BYTE_SIZE_YUV);
	SDL_DisplayYUVOverlay(overlay3, &dstrect3);
	SDL_UnlockYUVOverlay(overlay3);

	SDL_LockYUVOverlay(overlay4);
	memcpy(image4, data+(IMG_BYTE_SIZE_YUV*1), IMG_BYTE_SIZE_YUV);
	SDL_DisplayYUVOverlay(overlay4, &dstrect4);
	SDL_UnlockYUVOverlay(overlay4);

.......................

The result is incorrect because the image on the left-up corner with the face
is reflected in the other images with the clock. Are my steps correct?
There is something i can do to avoid this problem?
Thanks a lot by now and sorry for my english.

PS: May i attach an image to illustrate this problem?-------------------------------------------------------

Carlo Alberto Scarpato

hello all,

i am doing similar thing. i want to display a YUV
file,

i open file the read it.
and my display function are :

void initDisplay(){

/* Initialize the SDL library */

if( SDL_Init(SDL_INIT_VIDEO) ==-1 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}

screen = SDL_SetVideoMode(width, height, 24,
SDL_SWSURFACE|SDL_ANYFORMAT);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x8 video
mode: %s\n”,
SDL_GetError());
exit(1);
}

YUVOverlay = SDL_CreateYUVOverlay(width, height,
SDL_YUY2_OVERLAY , screen);
YUVOverlay->pixels=pYCbCrData;
}
void displayYUV (){

int i;
disRect.x = 0;
disRect.y = 0;
disRect.w= width;
disRect.h= height;
printf(“OK2 = %d \n %d \n %d \n%d”,
disRect.x,disRect.y, disRect.w,disRect.h);

SDL_LockYUVOverlay(YUVOverlay);

memcpy(pYCbCrData, pYCbCrData+(Total_Bytes*0),
Total_Bytes);
i = SDL_DisplayYUVOverlay(YUVOverlay, &disRect );
printf(“something\n”);
if(i!=0){
printf(“canot display overlay”);
}
SDL_UnlockYUVOverlay(YUVOverlay);

}

i have got a problem when i run the program,
it doesn’t seem to display the file, it just display a
green color.

can you please help me with that.

thanks in advace________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

elhadj benkhelifa wrote:

SDL_LockYUVOverlay(YUVOverlay);

memcpy(pYCbCrData, pYCbCrData+(Total_Bytes*0),
Total_Bytes);

Try to replace this libe with:
memcpy(YUVOverlay->pixels, pYCbCrData, Total_Bytes);

The LockYUV function set the pixels pointer to the value in graphic card
memory where your data should be displayed, so you cannot set it yourself!

Bye,
Gabry

thanks for the reply,
i tried that but it give segmentation fault when i ran
it.

i can send you the full code, if that would help you
to help me.

thanks in advance> Try to replace this libe with:

memcpy(YUVOverlay->pixels, pYCbCrData,
Total_Bytes);

The LockYUV function set the pixels pointer to the
value in graphic card
memory where your data should be displayed, so you
cannot set it yourself!

Bye,
Gabry


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

elhadj benkhelifa wrote:

I’m posting to the public ML since this may be useful.

thanks for the reply,
i tried that but it give segmentation fault when i ran
it.
i can send you the full code, if that would help you
to help me.

Sorry, I was forgetting that pixels in YUV surfaces is a pointer to
pointer, you need to copy Y to pixels[0], U to pixels[1] and V
to pixels[2], and you should also pay attenton to the pitch value of
each component, here is a smile example that works with U and V
components DOWNSAMPLED by 2, note that line by line copy is only needed
if the source and destination pitches are different, and this is often
the case with DirectX SDL YUV surfaces that have weird alignment issues:

 if(!SDL_LockYUVOverlay(yuv) ) {
     register unsigned char *y1,*y2,*y3,*i1,*i2,*i3;
     register int yuv_pitch = yuv->pitches[0];

     y1 = yuv->pixels[0];
     y3 = yuv->pixels[1]; // invertiti xche' avevo i colori sballati!
     y2 = yuv->pixels[2];

     i1=picture.data[0];
     i2=picture.data[1];
     i3=picture.data[2];

len = picture_length/2;

     while(len--) {
         memcpy(y1,i1,yuv_pitch);
         i1+=picture.linesize[0];
         y1+=yuv_pitch;
         memcpy(y1,i1,yuv_pitch);

         memcpy(y2,i2,yuv_pitch/2);
         memcpy(y3,i3,yuv_pitch/2);

         y1+=yuv_pitch;
         y2+=yuv_pitch/2;
         y3+=yuv_pitch/2;
         i1+=picture.linesize[0];
         i2+=picture.linesize[1];
         i3+=picture.linesize[2];
     }
     SDL_UnlockYUVOverlay(yuv);
 }

Bye,
Gabry

hi all,

i am trying to display a YUV file,
the problem i am having now, is:

i need to run the program twice to get the video
diplay, the first run will result a green window then
when i run a second time it displays the video
can you tell me why is that

thanks very much in advance________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

hi all,
i am dispplaying a YUV file, but i need to run the
program twice to get the display of the video.
the first run, is just a green screen flashing,

any suggestion is really appreciated.

thanks________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk