From b38c279225ff95c869278ddeb09db0851489cc64 Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Wed, 27 May 2009 04:10:35 +0000 Subject: [PATCH] Optimized blitWithRotate1. --- client/SDL_Extensions.cpp | 28 ++++++++++++++++++---------- client/SDL_Extensions.h | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/client/SDL_Extensions.cpp b/client/SDL_Extensions.cpp index f9ca2bb70..22f8d6020 100644 --- a/client/SDL_Extensions.cpp +++ b/client/SDL_Extensions.cpp @@ -455,21 +455,29 @@ static void prepareOutRect(SDL_Rect &dst, const SDL_Rect *dstRect, const SDL_Rec dst.h = std::max(0,std::min(dstRect->h - (dst.y - dstRect->y), clip_rect->y + clip_rect->h - dst.y)); } -void CSDL_Ext::blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests +void CSDL_Ext::blitWithRotate1(const SDL_Surface *src, const SDL_Rect * srcRect, const SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24/32 bpp dests { - Uint8 *dp, *sp = (Uint8 *)src->pixels; - for(int i=0; ih; i++) + Uint8 *sp = (Uint8 *)src->pixels; + const int bpp = dst->format->BytesPerPixel; + Uint8 *dporg = (Uint8 *)dst->pixels + dstRect->y*dst->pitch + (dstRect->x+dstRect->w)*bpp; + const SDL_Color * const colors = src->format->palette->colors; + + for(int i=dstRect->h; i>0; i--, dporg += dst->pitch) { + Uint8 *dp = dporg; + sp += src->w - dstRect->w; - dp = (Uint8 *)dst->pixels + (i+dstRect->y)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel; - for(int j=0; jw; j++, sp++) + + for(int j=dstRect->w; j>0; j--, sp++) { - const SDL_Color * const color = src->format->palette->colors+(*sp); - if (dst->format->BytesPerPixel == 4) + if (bpp == 4) *(--dp) = 0; - *(--dp) = color->r; - *(--dp) = color->g; - *(--dp) = color->b; + + const SDL_Color color = colors[*sp]; + + *(--dp) = color.r; + *(--dp) = color.g; + *(--dp) = color.b; } } } diff --git a/client/SDL_Extensions.h b/client/SDL_Extensions.h index 04c8e16d5..cf8255cf5 100644 --- a/client/SDL_Extensions.h +++ b/client/SDL_Extensions.h @@ -60,7 +60,7 @@ namespace CSDL_Ext Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false); SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); //returns color of pixel at given position SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) - void blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests + void blitWithRotate1(const SDL_Surface *src, const SDL_Rect * srcRect, const SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests void blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests void blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests void blitWithRotate1clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect