Rotate Surface In Sdl


NokFrt

Still Fresh
Joined
Jan 31, 2007
Messages
4
Does anybody know how to rotate SDL surface horizontally without using SDL_gfx? The code below works perfect on PC but it doesn't work on GP2X and I don't why. What am I doing wrong? :(
Thanks for help.


Code:
SDL_Surface* CGameApp::FlipImage(SDL_Surface *aImg, int aFlip)
{
	// Create a new surface
	const SDL_PixelFormat *format = aImg->format;
	SDL_Surface *img = SDL_CreateRGBSurface(aImg->flags, aImg->w, aImg->h, format->BitsPerPixel,
		format->Rmask, format->Gmask, format->Bmask, format->Amask);

	if (img == NULL)
		return NULL;

	// Lock surfaces
	SDL_LockSurface(aImg);
	SDL_LockSurface(img);

	// Flip
	int bytesPerPixel = format->BytesPerPixel;
	int bytesPerLine = bytesPerPixel * img->w;
	int w, h, cnt;

	Uint8 *sLine = (Uint8*)aImg->pixels;
	Uint8 *dLine = (Uint8*)img->pixels;
	Uint8 *sPixel = sLine;
	Uint8 *dPixel;

	if (aFlip == FLIP_HORIZONTALLY)
	{
		// Flip horizontaly
		h = img->h;

		do
		{
			dPixel = dLine + (bytesPerLine - bytesPerPixel);
			w = img->w;

			do
			{
				cnt = bytesPerPixel;

				do
				{
					*dPixel++ = *sPixel++;
				}
				while (--cnt != 0);

				dPixel -= (bytesPerPixel << 1);
			}
			while (--w != 0);

			// Next line
			sPixel = (sLine += aImg->pitch);
			dLine += img->pitch;
		}
		while (--h != 0);
	}
	
	SDL_UnlockSurface(img);
	SDL_UnlockSurface(aImg);

	return img;
}
 
Back
Top