mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
- moved PutPixel templates into header to allow inlining
This commit is contained in:
@ -23,176 +23,6 @@ SDL_Color Colors::createColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a /*= 0*/)
|
||||
return temp;
|
||||
}
|
||||
|
||||
template<int bpp, int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
|
||||
{
|
||||
PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
|
||||
}
|
||||
|
||||
template<int bpp, int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColor(Uint8 *&ptr, const SDL_Color & Color)
|
||||
{
|
||||
PutColor(ptr, Color.r, Color.g, Color.b);
|
||||
}
|
||||
|
||||
template<int bpp, int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlphaSwitch(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A)
|
||||
{
|
||||
switch (A)
|
||||
{
|
||||
case 255:
|
||||
ptr += bpp * incrementPtr;
|
||||
return;
|
||||
case 0:
|
||||
PutColor(ptr, R, G, B);
|
||||
return;
|
||||
case 128: // optimized
|
||||
PutColor(ptr, ((Uint16)R + (Uint16)ptr[2]) >> 1,
|
||||
((Uint16)G + (Uint16)ptr[1]) >> 1,
|
||||
((Uint16)B + (Uint16)ptr[0]) >> 1);
|
||||
return;
|
||||
default:
|
||||
PutColor(ptr, R, G, B, A);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template<int bpp, int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColor(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A)
|
||||
{
|
||||
PutColor(ptr, ((((Uint32)ptr[2]-(Uint32)R)*(Uint32)A) >> 8 ) + (Uint32)R,
|
||||
((((Uint32)ptr[1]-(Uint32)G)*(Uint32)A) >> 8 ) + (Uint32)G,
|
||||
((((Uint32)ptr[0]-(Uint32)B)*(Uint32)A) >> 8 ) + (Uint32)B);
|
||||
}
|
||||
|
||||
|
||||
template<int bpp, int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColor(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B)
|
||||
{
|
||||
if(incrementPtr == 0)
|
||||
{
|
||||
ptr[0] = B;
|
||||
ptr[1] = G;
|
||||
ptr[2] = R;
|
||||
}
|
||||
else if(incrementPtr == 1)
|
||||
{
|
||||
*ptr++ = B;
|
||||
*ptr++ = G;
|
||||
*ptr++ = R;
|
||||
|
||||
if(bpp == 4)
|
||||
*ptr++ = 0;
|
||||
}
|
||||
else if(incrementPtr == -1)
|
||||
{
|
||||
if(bpp == 4)
|
||||
*(--ptr) = 0;
|
||||
|
||||
*(--ptr) = R;
|
||||
*(--ptr) = G;
|
||||
*(--ptr) = B;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
template<int bpp, int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorRow(Uint8 *&ptr, const SDL_Color & Color, size_t count)
|
||||
{
|
||||
Uint32 pixel = ((Uint32)Color.b << 0 ) + ((Uint32)Color.g << 8) + ((Uint32)Color.r << 16);
|
||||
|
||||
for (size_t i=0; i<count; i++)
|
||||
{
|
||||
memcpy(ptr, &pixel, bpp);
|
||||
if(incrementPtr == -1)
|
||||
ptr -= bpp;
|
||||
if(incrementPtr == 1)
|
||||
ptr += bpp;
|
||||
}
|
||||
}
|
||||
|
||||
template <int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B)
|
||||
{
|
||||
if(incrementPtr == -1)
|
||||
ptr -= 2;
|
||||
|
||||
Uint16 * const px = (Uint16*)ptr;
|
||||
*px = (B>>3) + ((G>>2) << 5) + ((R>>3) << 11); //drop least significant bits of 24 bpp encoded color
|
||||
|
||||
if(incrementPtr == 1)
|
||||
ptr += 2; //bpp
|
||||
}
|
||||
|
||||
template <int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorAlphaSwitch(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A)
|
||||
{
|
||||
switch (A)
|
||||
{
|
||||
case 255:
|
||||
ptr += 2 * incrementPtr;
|
||||
return;
|
||||
case 0:
|
||||
PutColor(ptr, R, G, B);
|
||||
return;
|
||||
default:
|
||||
PutColor(ptr, R, G, B, A);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template <int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A)
|
||||
{
|
||||
const int rbit = 5, gbit = 6, bbit = 5; //bits per color
|
||||
const int rmask = 0xF800, gmask = 0x7E0, bmask = 0x1F;
|
||||
const int rshift = 11, gshift = 5, bshift = 0;
|
||||
|
||||
const Uint8 r5 = (*((Uint16 *)ptr) & rmask) >> rshift,
|
||||
b5 = (*((Uint16 *)ptr) & bmask) >> bshift,
|
||||
g5 = (*((Uint16 *)ptr) & gmask) >> gshift;
|
||||
|
||||
const Uint32 r8 = (r5 << (8 - rbit)) | (r5 >> (2*rbit - 8)),
|
||||
g8 = (g5 << (8 - gbit)) | (g5 >> (2*gbit - 8)),
|
||||
b8 = (b5 << (8 - bbit)) | (b5 >> (2*bbit - 8));
|
||||
|
||||
PutColor(ptr,
|
||||
(((r8-R)*A) >> 8) + R,
|
||||
(((g8-G)*A) >> 8) + G,
|
||||
(((b8-B)*A) >> 8) + B);
|
||||
}
|
||||
|
||||
template <int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
|
||||
{
|
||||
PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
|
||||
}
|
||||
|
||||
template <int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(Uint8 *&ptr, const SDL_Color & Color)
|
||||
{
|
||||
PutColor(ptr, Color.r, Color.g, Color.b);
|
||||
}
|
||||
|
||||
template <int incrementPtr>
|
||||
STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorRow(Uint8 *&ptr, const SDL_Color & Color, size_t count)
|
||||
{
|
||||
//drop least significant bits of 24 bpp encoded color
|
||||
Uint16 pixel = (Color.b>>3) + ((Color.g>>2) << 5) + ((Color.r>>3) << 11);
|
||||
|
||||
for (size_t i=0; i<count; i++)
|
||||
{
|
||||
memcpy(ptr, &pixel, 2);
|
||||
if(incrementPtr == -1)
|
||||
ptr -= 2;
|
||||
if(incrementPtr == 1)
|
||||
ptr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
|
||||
{
|
||||
return SDL_CreateRGBSurface(mod->flags,w,h,mod->format->BitsPerPixel,mod->format->Rmask,mod->format->Gmask,mod->format->Bmask,mod->format->Amask);
|
||||
@ -1317,14 +1147,3 @@ std::string CSDL_Ext::trimToFit(std::string text, int widthLimit, EFonts font)
|
||||
}
|
||||
|
||||
SDL_Surface * CSDL_Ext::std32bppSurface = NULL;
|
||||
|
||||
//instantiation of templates used in CAnimation and CCreatureAnimation, required for correct linking
|
||||
template struct ColorPutter<2,-1>;
|
||||
template struct ColorPutter<3,-1>;
|
||||
template struct ColorPutter<4,-1>;
|
||||
template struct ColorPutter<2, 0>;
|
||||
template struct ColorPutter<3, 0>;
|
||||
template struct ColorPutter<4, 0>;
|
||||
template struct ColorPutter<2, 1>;
|
||||
template struct ColorPutter<3, 1>;
|
||||
template struct ColorPutter<4, 1>;
|
||||
|
Reference in New Issue
Block a user