mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-09 02:19:45 +01:00
Use SDL_GetRGBA and SDL_MapRGBA to read and draw pixels
Honestly not too sure why we ever wrote the mask handling logic ourselves instead of using SDL functions. Hell, we even used SDL_MapRGB for Graphics::getRGB before.
This commit is contained in:
parent
8dc088896f
commit
b0ca322b3f
1 changed files with 4 additions and 22 deletions
|
@ -94,11 +94,6 @@ static void DrawPixel(SDL_Surface* surface, const int x, const int y, const SDL_
|
||||||
const SDL_PixelFormat* fmt = surface->format;
|
const SDL_PixelFormat* fmt = surface->format;
|
||||||
const int bpp = fmt->BytesPerPixel;
|
const int bpp = fmt->BytesPerPixel;
|
||||||
Uint32* pixel = (Uint32*) ((Uint8*) surface->pixels + y * surface->pitch + x * bpp);
|
Uint32* pixel = (Uint32*) ((Uint8*) surface->pixels + y * surface->pitch + x * bpp);
|
||||||
const Uint32 packed =
|
|
||||||
(color.r << fmt->Rshift) |
|
|
||||||
(color.g << fmt->Gshift) |
|
|
||||||
(color.b << fmt->Bshift) |
|
|
||||||
(color.a << fmt->Ashift);
|
|
||||||
|
|
||||||
switch (bpp)
|
switch (bpp)
|
||||||
{
|
{
|
||||||
|
@ -109,8 +104,7 @@ static void DrawPixel(SDL_Surface* surface, const int x, const int y, const SDL_
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
*pixel = packed;
|
*pixel = SDL_MapRGBA(fmt, color.r, color.g, color.b, color.a);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,32 +113,20 @@ SDL_Color ReadPixel(const SDL_Surface* surface, const int x, const int y)
|
||||||
const SDL_PixelFormat* fmt = surface->format;
|
const SDL_PixelFormat* fmt = surface->format;
|
||||||
const int bpp = surface->format->BytesPerPixel;
|
const int bpp = surface->format->BytesPerPixel;
|
||||||
const Uint32* pixel = (Uint32*) ((Uint8*) surface->pixels + y * surface->pitch + x * bpp);
|
const Uint32* pixel = (Uint32*) ((Uint8*) surface->pixels + y * surface->pitch + x * bpp);
|
||||||
|
SDL_Color color = {0, 0, 0, 0};
|
||||||
|
|
||||||
switch (bpp)
|
switch (bpp)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
{
|
|
||||||
SDL_assert(0 && "Non-32-bit colors not supported!");
|
SDL_assert(0 && "Non-32-bit colors not supported!");
|
||||||
const SDL_Color color = {0, 0, 0, 0};
|
break;
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
{
|
SDL_GetRGBA(*pixel, fmt, &color.r, &color.g, &color.b, &color.a);
|
||||||
const SDL_Color color = {
|
|
||||||
(Uint8) ((*pixel & fmt->Rmask) >> fmt->Rshift),
|
|
||||||
(Uint8) ((*pixel & fmt->Gmask) >> fmt->Gshift),
|
|
||||||
(Uint8) ((*pixel & fmt->Bmask) >> fmt->Bshift),
|
|
||||||
(Uint8) ((*pixel & fmt->Amask) >> fmt->Ashift)
|
|
||||||
};
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* shouldn't happen, but avoids warnings */
|
|
||||||
const SDL_Color color = {0, 0, 0, 0};
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue