1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-30 16:38:29 +02:00
VVVVVV/desktop_version/src/GraphicsUtil.h
Misa 351a022ebd Use SDL_Color for colors instead of colourTransform
colourTransform is a struct with only one member, a Uint32. The issue
with `Uint32`s is that it requires a bunch of bit shifting logic to edit
the colors. The issue with bit shifting logic is that people have a
tendency to hardcode the shift amounts instead of using the shift amount
variables of the SDL_PixelFormat, which makes it annoying to change the
color masks of surfaces.

This commit fixes both issues by unhardcoding the bit shift amounts in
DrawPixel and ReadPixel, and by axing the `Uint32`s in favor of using
SDL_Color.

According to the SDL_PixelFormat documentation (
https://wiki.libsdl.org/SDL2/SDL_PixelFormat ), the logic to read and
draw to pixels from colors below 32-bit was just wrong. Specifically,
for 8-bit, there's a color palette used instead of some intrinsic color
information stored in the pixel itself. But we shouldn't need that logic
anyways because we don't use colors below 32-bit. So I axed that too.
2023-01-01 16:36:43 -08:00

43 lines
1.5 KiB
C

#ifndef GRAPHICSUTIL_H
#define GRAPHICSUTIL_H
#include <SDL.h>
void setRect(SDL_Rect& _r, int x, int y, int w, int h);
SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height );
SDL_Color ReadPixel(const SDL_Surface* surface, int x, int y);
SDL_Surface * ScaleSurface( SDL_Surface *Surface, int Width, int Height, SDL_Surface * Dest = NULL );
void BlitSurfaceStandard( SDL_Surface* _src, SDL_Rect* _srcRect, SDL_Surface* _dest, SDL_Rect* _destRect );
void BlitSurfaceColoured(SDL_Surface* src, const SDL_Rect* src_rect, SDL_Surface* dest, SDL_Rect* dest_rect, SDL_Color color);
void BlitSurfaceTinted(SDL_Surface* src, const SDL_Rect* src_rect, SDL_Surface* dest, SDL_Rect* dest_rect, SDL_Color color);
void FillRect( SDL_Surface* surface, const int x, const int y, const int w, const int h, const int r, int g, int b );
void FillRect( SDL_Surface* surface, const int r, int g, int b );
void FillRect( SDL_Surface* surface, SDL_Rect& rect, const int r, int g, int b );
void FillRect(SDL_Surface* surface, SDL_Rect rect, SDL_Color color);
void FillRect(SDL_Surface* surface, SDL_Color color);
void FillRect(SDL_Surface* surface, int x, int y, int w, int h, SDL_Color color);
void FillRect(SDL_Surface* surface, int r, int g, int b, int a);
void ClearSurface(SDL_Surface* surface);
void ScrollSurface(SDL_Surface* _src, int pX, int py);
SDL_Surface * FlipSurfaceVerticle(SDL_Surface* _src);
void UpdateFilter(void);
SDL_Surface* ApplyFilter( SDL_Surface* _src );
#endif /* GRAPHICSUTIL_H */