mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Depth neutral implementation of CSDL_Ext::rotate01 and CSDL_Ext::hFlip.
This commit is contained in:
@@ -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);
|
SDL_UpdateRect(ekran, x, y, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vertical flip
|
||||||
|
|
||||||
///**************/
|
|
||||||
///Reverses the toRot surface by the vertical axis
|
|
||||||
///**************/
|
|
||||||
SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
|
SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
|
||||||
{
|
{
|
||||||
SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags);
|
SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags);
|
||||||
//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
|
const int bpl = ret->pitch;
|
||||||
if(toRot->format->BytesPerPixel!=1)
|
const int bpp = ret->format->BytesPerPixel;
|
||||||
{
|
|
||||||
for(int i=0; i<ret->w; ++i)
|
for(int i=0; i<ret->h; i++) {
|
||||||
{
|
char *src = (char *)toRot->pixels + i*bpl;
|
||||||
for(int j=0; j<ret->h; ++j)
|
char *dst = (char *)ret->pixels + i*bpl;
|
||||||
{
|
for(int j=0; j<ret->w; j++) {
|
||||||
{
|
for (int k=0; k<bpp; k++) {
|
||||||
Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel;
|
dst[j*bpp + k] = src[(ret->w-j-1)*bpp + k];
|
||||||
CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for(int i=0; i<ret->w; ++i)
|
|
||||||
{
|
|
||||||
for(int j=0; j<ret->h; ++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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Horizontal flip
|
||||||
SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot)
|
SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot)
|
||||||
{
|
{
|
||||||
SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags);
|
SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags);
|
||||||
//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
|
int bpl = ret->pitch;
|
||||||
if(ret->format->BytesPerPixel!=1)
|
|
||||||
{
|
for(int i=0; i<ret->h; i++) {
|
||||||
for(int i=0; i<ret->w; ++i)
|
memcpy((char *)ret->pixels + i*bpl, (char *)toRot->pixels + (ret->h-i-1)*bpl, bpl);
|
||||||
{
|
|
||||||
for(int j=0; j<ret->h; ++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; i<ret->w; ++i)
|
|
||||||
{
|
|
||||||
for(int j=0; j<ret->h; ++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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user