Skip to content

SDL_GetRGBA, SDL_GetRGB are hard to use correctly #8320

@smcv

Description

@smcv

As seen in #8317, to do format-sensitive colour conversion, you have to memcpy the right number of bytes into the low-order bits of a Uint32 (which do not necessarily start at byte 0!), and then pass that to SDL_GetRGBA() or SDL_GetRGB() to decode it into its colour channels. This seems unnecessarily tricky to get right.

One possibility to make this easier (and make implementing #8319 easier, if we want it) would be to change their signature from the current:

void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *, Uint8 *, Uint8 *, Uint8 *);
void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *, Uint8 *, Uint8 *, Uint8 *, Uint8 *);

to be something more like

void SDL_GetRGB(const void *pixel, const SDL_PixelFormat *, Uint8 *, Uint8 *, Uint8 *);
void SDL_GetRGBA(const void *pixel, const SDL_PixelFormat *, Uint8 *, Uint8 *, Uint8 *, Uint8 *);

and do the "memcpy the right number of bytes into the low-order bits of a Uint32" step internally.

This might be troublesome for src/render/software/SDL_drawline.c, though.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions