Added initial implementation of the SDL Pixels category.
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
/** @file PixelFormat.hpp
|
||||
* @brief HDK sdl video header only wrapper for SDL_PixelFormat enum & related functions
|
||||
*/
|
||||
#include <SDL3/SDL_pixels.h>
|
||||
#include <hdk/grid/PrimitiveWrapper.hpp>
|
||||
/** PixelFormat makes working with SDL_PixelFormat easier. */
|
||||
namespace hdk::sdl {
|
||||
/// Forward declare to avoid circular dependency with PixelFormatDetails
|
||||
class PixelFormatDetails;
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
class PixelFormat : public hdk::grid::PrimitiveWrapper<SDL_PixelFormat> {
|
||||
public:
|
||||
/** Inherit constructors from PrimitiveWrapper */
|
||||
using hdk::grid::PrimitiveWrapper<SDL_PixelFormat>::PrimitiveWrapper;
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetMasksForPixelFormat
|
||||
* @brief Get the pixel format masks for a given pixel format.
|
||||
* @param bpp Pointer to int to be filled in with the number of bytes per pixel.
|
||||
* @param Rmask Pointer to Uint32 to be filled in with the red mask for the pixel format.
|
||||
* @param Gmask Pointer to Uint32 to be filled in with the green mask for the pixel format.
|
||||
* @param Bmask Pointer to Uint32 to be filled in with the blue mask for the pixel format.
|
||||
* @param Amask Pointer to Uint32 to be filled in with the alpha mask for the pixel format.
|
||||
* @return bool True on success
|
||||
*/
|
||||
bool GetMasks(int* bpp, Uint32* Rmask, Uint32* Gmask, Uint32* Bmask, Uint32* Amask) const {
|
||||
return SDL_GetMasksForPixelFormat(*this, bpp, Rmask, Gmask, Bmask, Amask);
|
||||
}
|
||||
// Implemented in `../pixels.hpp` to avoid circular dependency
|
||||
PixelFormatDetails GetDetails() const;
|
||||
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetPixelFormatForMasks
|
||||
* @brief Get the pixel format for a given set of pixel format masks.
|
||||
* @param bpp The number of bytes per pixel for the pixel format.
|
||||
* @param Rmask The red mask for the pixel format.
|
||||
* @param Gmask The green mask for the pixel format.
|
||||
* @param Bmask The blue mask for the pixel format.
|
||||
* @param Amask The alpha mask for the pixel format.
|
||||
* @return The pixel format corresponding to the given masks, or ::SDL_PIXELFORMAT_UNKNOWN
|
||||
*/
|
||||
static SDL_PixelFormat GetForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) {
|
||||
return SDL_GetPixelFormatForMasks(bpp, Rmask, Gmask, Bmask, Amask);
|
||||
}
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetPixelFormatName
|
||||
* @brief Get the name of a pixel format.
|
||||
* @return const char* The name of the pixel format, or "Unknown" if the pixel format is not recognized.
|
||||
*/
|
||||
const char* GetName() const { return SDL_GetPixelFormatName(*this); }
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user