From 21155f3b356f4ddcd4c5a1d564efafe8eeb29751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 26 Mar 2009 17:55:10 +0000 Subject: [PATCH] Refactored and hopefully fixed blitWithRotateNclip functions family --- SDL_Extensions.cpp | 96 +++++++++------------------------------------- 1 file changed, 18 insertions(+), 78 deletions(-) diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 7bba9cd73..091d80e96 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -473,6 +473,15 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src) return src; } // <=> + +void prepareOutRect(SDL_Rect &dst, const SDL_Rect *dstRect, const SDL_Rect *clip_rect) +{ + dst.x = std::max(dstRect->x,clip_rect->x); + dst.y = std::max(dstRect->y,clip_rect->y); + dst.w = std::max(0,std::min(dstRect->w - (dst.x - dstRect->x), clip_rect->x + clip_rect->w - dst.x)); + 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 { Uint8 *dp, *sp = (Uint8 *)src->pixels; @@ -492,32 +501,9 @@ void CSDL_Ext::blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface void CSDL_Ext::blitWithRotate1clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests { - Uint8 *dp, *sp = (Uint8 *)src->pixels; - for(int i=0; ih; i++) - { - if(i + dstRect->y + 1 >= dst->clip_rect.y && i + dstRect->y + 1 <= dst->clip_rect.y + dst->clip_rect.h) - { - dp = (Uint8 *)dst->pixels + (i+dstRect->y)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel; - for(int j=0; jw; j++, sp++) - { - if((dstRect->x+dstRect->w - j-1) >= dst->clip_rect.x && (dstRect->x+dstRect->w - j) <= dst->clip_rect.x + dst->clip_rect.w) - { - const SDL_Color * const color = src->format->palette->colors+(*sp); - *(--dp) = color->r; - *(--dp) = color->g; - *(--dp) = color->b; - } - else - { - dp-=3; - } - } - } - else - { - sp+=dstRect->w; - } - } + SDL_Rect realDest; + prepareOutRect(realDest,dstRect,&dst->clip_rect); + 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 @@ -539,32 +525,9 @@ void CSDL_Ext::blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface 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 { - Uint8 *dp, *sp = (Uint8 *)src->pixels; - for(int i=0; ih; i++) - { - if((dstRect->y + dstRect->h - i) >= dst->clip_rect.y && (dstRect->y + dstRect->h - i) <= dst->clip_rect.y + dst->clip_rect.h) - { - dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + dstRect->x*dst->format->BytesPerPixel; - for(int j=0; jw; j++, sp++) - { - if(j + dstRect->x >= dst->clip_rect.x && j + dstRect->x+1 <= dst->clip_rect.x + dst->clip_rect.w) - { - const SDL_Color * const color = src->format->palette->colors+(*sp); - *(dp++) = color->b; - *(dp++) = color->g; - *(dp++) = color->r; - } - else - { - dp+=3; - } - } - } - else - { - sp+=dstRect->w; - } - } + SDL_Rect realDest; + prepareOutRect(realDest,dstRect,&dst->clip_rect); + blitWithRotate2(src,srcRect,dst,&realDest); } void CSDL_Ext::blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests @@ -586,32 +549,9 @@ void CSDL_Ext::blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface void CSDL_Ext::blitWithRotate3clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests { - Uint8 *dp, *sp = (Uint8 *)src->pixels; - for(int i=0; ih; i++) - { - if((dstRect->y + dstRect->h - i) >= dst->clip_rect.y && (dstRect->y + dstRect->h - i) <= dst->clip_rect.y + dst->clip_rect.h) - { - dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel; - for(int j=0; jw; j++, sp++) - { - if((dstRect->x+dstRect->w - j) >= dst->clip_rect.x && (dstRect->x+dstRect->w - j) <= dst->clip_rect.x + dst->clip_rect.w) - { - const SDL_Color * const color = src->format->palette->colors+(*sp); - *(--dp) = color->r; - *(--dp) = color->g; - *(--dp) = color->b; - } - else - { - dp -=3; - } - } - } - else - { - sp+=dstRect->w; - } - } + SDL_Rect realDest; + prepareOutRect(realDest,dstRect,&dst->clip_rect); + blitWithRotate3(src,srcRect,dst,&realDest); } int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)