Explorar el Código

Optimized blitWithRotate2.

Frank Zago hace 16 años
padre
commit
af5dfd9dbc
Se han modificado 2 ficheros con 21 adiciones y 13 borrados
  1. 19 11
      client/SDL_Extensions.cpp
  2. 2 2
      client/SDL_Extensions.h

+ 19 - 11
client/SDL_Extensions.cpp

@@ -489,26 +489,34 @@ void CSDL_Ext::blitWithRotate1clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surf
 	blitWithRotate1(src,srcRect,dst,&realDest);
 }
 
-void CSDL_Ext::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 CSDL_Ext::blitWithRotate2(const SDL_Surface *src, const SDL_Rect * srcRect, SDL_Surface * dst, const 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; i<dstRect->h; i++)
+	Uint8 *sp = (Uint8 *)src->pixels;
+	const int bpp = dst->format->BytesPerPixel;
+	Uint8 *dporg = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1)*dst->pitch + dstRect->x*bpp;
+	const SDL_Color * const colors = src->format->palette->colors;
+
+	for(int i=dstRect->h; i>0; i--, dporg -= dst->pitch)
 	{
-		dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + dstRect->x*dst->format->BytesPerPixel;
-		for(int j=0; j<dstRect->w; j++, sp++)
+		Uint8 *dp = dporg;
+
+		for(int j=dstRect->w; j>0; j--, sp++)
 		{
-			const SDL_Color * const color = src->format->palette->colors+(*sp);
-			*(dp++) = color->b;
-			*(dp++) = color->g;
-			*(dp++) = color->r;
-			if (dst->format->BytesPerPixel == 4)
+			const SDL_Color color = colors[*sp];
+
+			*(dp++) = color.b;
+			*(dp++) = color.g;
+			*(dp++) = color.r;
+
+			if (bpp == 4)
 				*(dp++) = 0;
 		}
+
 		sp += src->w - dstRect->w;
 	}
 }
 
-void CSDL_Ext::blitWithRotate2clip(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::blitWithRotate2clip(const SDL_Surface *src, const SDL_Rect * srcRect, SDL_Surface * dst, const SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests
 {
 	SDL_Rect realDest;
 	prepareOutRect(realDest,dstRect,&dst->clip_rect);

+ 2 - 2
client/SDL_Extensions.h

@@ -61,10 +61,10 @@ namespace CSDL_Ext
 	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(const SDL_Surface *src, const SDL_Rect * srcRect, 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 blitWithRotate2(const SDL_Surface *src, const SDL_Rect * srcRect, SDL_Surface * dst, const 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
-	void blitWithRotate2clip(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
+	void blitWithRotate2clip(const SDL_Surface *src, const SDL_Rect * srcRect, SDL_Surface * dst, const SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect
 	void blitWithRotate3clip(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
 	int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
 	Uint32 colorToUint32(const SDL_Color * color); //little endian only