From bf562bdb77ef0e48ca2113e35526466f578def7f Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Sun, 17 May 2009 02:43:36 +0000 Subject: [PATCH] Depth neutral implementation of CSDL_Ext::rotate01 and CSDL_Ext::hFlip. --- SDL_Extensions.cpp | 80 +++++++++++----------------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 3c89f0d60..37f84c1a2 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -257,80 +257,36 @@ inline void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, const int & x, const int SDL_UpdateRect(ekran, x, y, 1, 1); } - - -///**************/ -///Reverses the toRot surface by the vertical axis -///**************/ +// Vertical flip SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot) { SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags); - //SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey); - if(toRot->format->BytesPerPixel!=1) - { - for(int i=0; iw; ++i) - { - for(int j=0; jh; ++j) - { - { - Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel; - CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]); - } - } - } - } - else - { - for(int i=0; iw; ++i) - { - for(int j=0; jh; ++j) - { - { - Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel; - (*((Uint8*)ret->pixels + j*ret->pitch + i*ret->format->BytesPerPixel)) = *p; - } + const int bpl = ret->pitch; + const int bpp = ret->format->BytesPerPixel; + + for(int i=0; ih; i++) { + char *src = (char *)toRot->pixels + i*bpl; + char *dst = (char *)ret->pixels + i*bpl; + for(int j=0; jw; j++) { + for (int k=0; kw-j-1)*bpp + k]; } } } + return ret; } + +// Horizontal flip SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot) { SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags); - //SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey); - if(ret->format->BytesPerPixel!=1) - { - for(int i=0; iw; ++i) - { - for(int j=0; jh; ++j) - { - { - Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel; - //int k=2; -/* -#if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[0], p[1], p[2]); -#else -*/ - CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]); -//#endif - } - } - } - } - else - { - for(int i=0; iw; ++i) - { - for(int j=0; jh; ++j) - { - { - Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel; - (*((Uint8*)ret->pixels + j*ret->pitch + i*ret->format->BytesPerPixel)) = *p; - } - } - } + int bpl = ret->pitch; + + for(int i=0; ih; i++) { + memcpy((char *)ret->pixels + i*bpl, (char *)toRot->pixels + (ret->h-i-1)*bpl, bpl); } + return ret; };