Added initial implementation of the SDL Pixels category.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
BadQuanta
2026-04-26 17:45:26 +00:00
parent 85dbe33a77
commit 97c8847eb0
8 changed files with 239 additions and 11 deletions
@@ -0,0 +1,72 @@
#pragma once
/** @file Palette.hpp
* @brief HDK sdl video header only wrapper pointers to const SDL_PixelFormatDetails & related functions
* @note Does note use smartpointers because these are SDL owned constant structs.
*/
#include <SDL3/SDL_pixels.h>
#include <hdk/grid/PrimitiveWrapper.hpp>
/** PixelFormatDetails makes getting the details of a pixel format easier. */
namespace hdk::sdl {
/**
* @brief
*
*/
class PixelFormatDetails : public hdk::grid::PrimitiveWrapper<const SDL_PixelFormatDetails*> {
public:
/** Inherit constructors from PrimitiveWrapper */
using hdk::grid::PrimitiveWrapper<const SDL_PixelFormatDetails*>::PrimitiveWrapper;
/*** @see https://wiki.libsdl.org/SDL3/SDL_GetPixelFormatDetails
* @returns an PixelFormatDetails instance
*/
static PixelFormatDetails Get(SDL_PixelFormat format) {
return PixelFormatDetails(SDL_GetPixelFormatDetails(format));
}
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRGB
* @brief Get the RGB values for a pixel value
* @param pixel The pixel value to query
* @param palette for indexed formats the palette to use, or NULL for non-indexed formats
* @param r pointer to Uint8 to store the red component
* @param g pointer to Uint8 to store the green component
* @param b pointer to Uint8 to store the blue component
* @param a pointer to Uint8 to store the alpha component
*/
void GetRGB(Uint32 pixel, SDL_Palette* palette, Uint8* r, Uint8* g, Uint8* b, Uint8* a) const {
SDL_GetRGB(pixel, *this, palette, r, g, b, a);
}
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRGBA
* @brief Get the RGBA values for a pixel value
* @param pixel The pixel value to query
* @param palette for indexed formats the palette to use, or NULL for non-indexed formats
* @param r pointer to Uint8 to store the red component
* @param g pointer to Uint8 to store the green component
* @param b pointer to Uint8 to store the blue component
* @param a pointer to Uint8 to store the alpha component
*/
void GetRGBA(Uint32 pixel, SDL_Palette* palette, Uint8* r, Uint8* g, Uint8* b, Uint8* a) const {
SDL_GetRGBA(pixel, *this, palette, r, g, b, a);
}
/** @see https://wiki.libsdl.org/SDL3/SDL_MapRGB
* @brief Map RGB values to a pixel value for the pixel format
* @param palette for indexed formats the palette to use, or NULL for non-indexed formats
* @param r The red component of the color
* @param g The green component of the color
* @param b The blue component of the color
* @return The pixel value corresponding to the given RGB values for the pixel format
*/
Uint32 MapRGB(SDL_Palette* palette, Uint8 r, Uint8 g, Uint8 b) const {
return SDL_MapRGB(*this, palette, r, g, b);
}
/** @see https://wiki.libsdl.org/SDL3/SDL_MapRGBA
* @brief Map RGBA values to a pixel value for the pixel format
* @param palette for indexed formats the palette to use, or NULL for non-indexed formats
* @param r The red component of the color
* @param g The green component of the color
* @param b The blue component of the color
* @param a The alpha component of the color
* @return The pixel value corresponding to the given RGBA values for the pixel format
*/
Uint32 MapRGBA(SDL_Palette* palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a) const {
return SDL_MapRGBA(*this, palette, r, g, b, a);
}
};
}