mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Refactored and hopefully fixed blitWithRotateNclip functions family
This commit is contained in:
@@ -473,6 +473,15 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
|
|||||||
return 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
|
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;
|
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
|
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;
|
SDL_Rect realDest;
|
||||||
for(int i=0; i<dstRect->h; i++)
|
prepareOutRect(realDest,dstRect,&dst->clip_rect);
|
||||||
{
|
blitWithRotate1(src,srcRect,dst,&realDest);
|
||||||
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; j<dstRect->w; 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(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
|
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;
|
SDL_Rect realDest;
|
||||||
for(int i=0; i<dstRect->h; i++)
|
prepareOutRect(realDest,dstRect,&dst->clip_rect);
|
||||||
{
|
blitWithRotate2(src,srcRect,dst,&realDest);
|
||||||
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; j<dstRect->w; 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
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
|
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;
|
SDL_Rect realDest;
|
||||||
for(int i=0; i<dstRect->h; i++)
|
prepareOutRect(realDest,dstRect,&dst->clip_rect);
|
||||||
{
|
blitWithRotate3(src,srcRect,dst,&realDest);
|
||||||
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; j<dstRect->w; 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)
|
int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)
|
||||||
|
Reference in New Issue
Block a user