65 #ifndef UTILS_SDLPIXEL_H
66 #define UTILS_SDLPIXEL_H
71 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
76 #error missing SDL_endian.h
89 if (surface ==
nullptr)
92 const int bpp = surface->format->BytesPerPixel;
94 SDL_LockSurface(surface);
96 Uint8 *
const p =
static_cast<uint8_t*
>(surface->pixels)
99 const Uint32 pixel = SDL_MapRGB(surface->format,
110 *
reinterpret_cast<uint16_t*
>(p) =
CAST_U16(pixel);
114 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
115 p[0] =
CAST_U8((pixel >> 16) & 0xff);
116 p[1] =
CAST_U8((pixel >> 8) & 0xff);
117 p[2] =
CAST_U8((pixel) & 0xff);
120 p[0] =
CAST_U8((pixel) & 0xff);
121 p[1] =
CAST_U8((pixel >> 8) & 0xff);
122 p[2] =
CAST_U8((pixel >> 16) & 0xff);
128 *
reinterpret_cast<Uint32*
>(p) = pixel;
135 SDL_UnlockSurface(surface);
146 const unsigned int dst,
147 const unsigned char a)
149 const unsigned int b = ((src & 0xff) * a + (dst & 0xff) * (255 - a)) >> 8;
150 const unsigned int g = ((src & 0xff00) * a + (dst & 0xff00)
152 const unsigned int r = ((src & 0xff0000) * a + (dst & 0xff0000)
155 return (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
158 inline unsigned short SDLAlpha16(
const unsigned short src,
159 const unsigned short dst,
160 const unsigned char a,
161 const SDL_PixelFormat *
const f)
A_NONNULL(4);
171 const unsigned short dst,
172 const unsigned char a,
173 const SDL_PixelFormat *
const f)
175 unsigned int b = ((src & f->Rmask) * a + (dst & f->Rmask)
177 unsigned int g = ((src & f->Gmask) * a + (dst & f->Gmask)
179 unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask)
182 return static_cast<unsigned short>((b & f->Rmask)
183 | (g & f->Gmask) | (r & f->Bmask));
196 if (surface ==
nullptr)
198 const int bpp = surface->format->BytesPerPixel;
200 SDL_LockSurface(surface);
202 Uint8 *
const p =
static_cast<uint8_t*
>(surface->pixels)
205 const Uint32 pixel = SDL_MapRGB(surface->format,
218 static_cast<unsigned short>(pixel),
219 *
reinterpret_cast<unsigned short*
>(p),
224 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
225 p[2] =
CAST_U8((p[2] * (255 - color.
a)
226 + color.
b * color.
a) >> 8);
227 p[1] =
CAST_U8((p[1] * (255 - color.
a)
228 + color.
g * color.
a) >> 8);
229 p[0] =
CAST_U8((p[0] * (255 - color.
a)
230 + color.
r * color.
a) >> 8);
233 p[0] =
CAST_U8((p[0] * (255 - color.
a)
234 + color.
b * color.
a) >> 8);
235 p[1] =
CAST_U8((p[1] * (255 - color.
a)
236 + color.
g * color.
a) >> 8);
237 p[2] =
CAST_U8((p[2] * (255 - color.
a)
238 + color.
r * color.
a) >> 8);
244 *
reinterpret_cast<Uint32*
>(p) =
SDLAlpha32(pixel,
245 *
reinterpret_cast<Uint32*
>(p),
252 SDL_UnlockSurface(surface);
void SDLputPixelAlpha(SDL_Surface *surface, int x, int y, const Color &color)
void SDLputPixel(SDL_Surface *surface, int x, int y, const Color &color)
unsigned int SDLAlpha32(const unsigned int src, const unsigned int dst, const unsigned char a)
unsigned short SDLAlpha16(const unsigned short src, const unsigned short dst, const unsigned char a, const SDL_PixelFormat *const f)