Cropping a surface

Hi,

I am using
target=crop(source,&r);
SDL_FreeSurface(source);
to crop a surface, with:

SDL_Surface *crop(SDL_Surface *tobecropped, SDL_Rect *r){
SDL_Surface *temp,cropped;
/
New surface of the cropped size */
cropped=SDL_CreateRGBSurface(tobecropped->flags,r->w, r->h,

tobecropped->format->BitsPerPixel,tobecropped->format->Rmask,tobecropped->format->Gmask,
tobecropped->format->Bmask, tobecropped->format->Amask);

/* Copy the cropped piece */
SDL_BlitSurface(tobecropped,r,cropped,NULL);
return cropped;

}

I wonder if this is the right way. My concern is that I am duplicating a
part of a surface (source) that is going to be freed immediately. I wonder
if it is possible to free just the difference between the surface and the
cropped surface, avoiding SDL_CreateRGBSurface.

Thanks,

Fernando._________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it’s FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/