38 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
42 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
43 #include <SDL_gfxBlitFunc.h>
47 #ifndef SDL_BIG_ENDIAN
48 #error missing SDL_endian.h
57 SDL_Surface *
const tmpImage =
loadPng(rw);
58 if (tmpImage ==
nullptr)
66 rgba.palette =
nullptr;
67 rgba.BitsPerPixel = 32;
68 rgba.BytesPerPixel = 4;
76 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
77 rgba.Rmask = 0x000000FFU;
79 rgba.Gmask = 0x0000FF00U;
81 rgba.Bmask = 0x00FF0000U;
83 rgba.Amask = 0xFF000000U;
87 rgba.Rmask = 0xFF000000U;
89 rgba.Gmask = 0x00FF0000U;
91 rgba.Bmask = 0x0000FF00U;
93 rgba.Amask = 0x000000FFU;
99 tmpImage, &rgba, SDL_SWSURFACE);
105 uint32_t *pixels =
static_cast<uint32_t *
>(surf->pixels);
106 const int type = dye.
getType();
114 DYEPALETTEP(pal, SColor)(pixels, surf->w * surf->h);
121 DYEPALETTEP(pal, AColor)(pixels, surf->w * surf->h);
127 dye.
normalDye(pixels, surf->w * surf->h);
147 if (tmpImage ==
nullptr)
150 bool hasAlpha =
false;
151 const size_t sz = tmpImage->w * tmpImage->h;
154 uint8_t *alphaChannel =
new uint8_t[sz];
156 const SDL_PixelFormat *
const fmt = tmpImage->format;
157 if (fmt->Amask != 0U)
159 for (
size_t i = 0; i < sz; ++ i)
161 uint32_t c = (
static_cast<uint32_t*
>(tmpImage->pixels))[i];
163 const unsigned v = (c & fmt->Amask) >> fmt->Ashift;
164 const uint8_t a =
static_cast<uint8_t
>((v << fmt->Aloss)
165 + (v >> (8 - (fmt->Aloss << 1))));
168 static_cast<float>(a) * alpha);
171 c |= ((a2 >> fmt->Aloss) << fmt->Ashift & fmt->Amask);
172 (
static_cast<uint32_t*
>(tmpImage->pixels))[i] = c;
194 delete [] alphaChannel;
195 alphaChannel =
nullptr;
198 if (image ==
nullptr)
201 delete [] alphaChannel;
205 Image *
const img =
new Image(image, hasAlpha, alphaChannel);
212 if ((tmpImage ==
nullptr) || (tmpImage->format ==
nullptr))
220 if (tmpImage ==
nullptr)
223 bool hasAlpha =
false;
224 bool converted =
false;
226 if (tmpImage->format->BitsPerPixel != 32)
231 if (tmpImage ==
nullptr)
236 const size_t sz = tmpImage->w * tmpImage->h;
239 uint8_t *alphaChannel =
new uint8_t[sz];
242 if (tmpImage->format->palette ==
nullptr)
244 const SDL_PixelFormat *
const fmt = tmpImage->format;
245 if (fmt->Amask != 0U)
247 const uint32_t amask = fmt->Amask;
248 const uint8_t ashift = fmt->Ashift;
249 const uint8_t aloss = fmt->Aloss;
250 const uint32_t *pixels =
static_cast<uint32_t*
>(tmpImage->pixels);
251 for (
size_t i = 0; i < sz; ++ i)
253 const unsigned v = (pixels[i] & amask) >> ashift;
254 const uint8_t a =
static_cast<uint8_t
>((v << aloss)
255 + (v >> (8 - (aloss << 1))));
268 memset(alphaChannel, SDL_ALPHA_OPAQUE, sz);
277 memset(alphaChannel, SDL_ALPHA_OPAQUE, sz);
294 delete [] alphaChannel;
295 alphaChannel =
nullptr;
298 if (image ==
nullptr)
301 delete [] alphaChannel;
307 return new Image(image, hasAlpha, alphaChannel);
315 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
319 return SDL_gfxBlitRGBA(src, srcrect, dst, dstrect);
324 const int x,
const int y,
325 SDL_Surface *
const surface)
const
327 if ((image ==
nullptr) || (surface ==
nullptr))
330 SDL_SetAlpha(surface, 0, SDL_ALPHA_OPAQUE);
334 CAST_U16(surface->w),
static_cast<uint16_t
>(surface->h)
337 SDL_BlitSurface(surface,
nullptr, image->mSDLSurface, &rect);
#define reportAlways(...)
const DyePalette * getSPalete() const
const DyePalette * getAPalete() const
void normalDye(uint32_t *pixels, const int bufSize) const
static SDL_Surface * convertTo32Bit(SDL_Surface *const tmpImage)
static SDL_Surface * loadPng(SDL_RWops *const rw)
static Image * _SDLload(SDL_Surface *tmpImage)
static int combineSurface(SDL_Surface *const src, SDL_Rect *const srcrect, SDL_Surface *const dst, SDL_Rect *const dstrect)
static SDL_Surface * SDLDuplicateSurface(SDL_Surface *const tmpImage)
void copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *const surface) const
Image * createTextSurface(SDL_Surface *const tmpImage, const int width, const int height, const float alpha)
Image * load(SDL_RWops *const rw, Dye const &dye)
static bool mEnableAlphaCache
Image * loadSurface(SDL_Surface *const tmpImage)
#define MSDL_ConvertSurface(src, fmt, flags)
#define MSDL_DisplayFormatAlpha(surface)
#define MSDL_DisplayFormat(surface)
#define MSDL_FreeSurface(surface)
#define DYEPALETTEP(palette, color)
int SDLgfxBlitRGBA(const SDL_Surface *const src, const SDL_Rect *const srcrect, SDL_Surface *const dst, const SDL_Rect *const dstrect)