PixelFormat

D class that wraps SDL_PixelFormat defining the color and alpha channel bit layout in the internal representation of a pixel

@safe final
class PixelFormat {}

Constructors

this
this(SDL_PixelFormat* sdlPixelFormat, bool isOwner, void* userRef)

Constructs a dsdl2.PixelFormat from a vanilla SDL_PixelFormat* from bindbc-sdl

this
this(SDL_PixelFormatEnum sdlPixelFormatEnum)

Constructs a dsdl2.PixelFormat using an SDL_PixelFormatEnum from bindbc-sdl

this
this(SDL_PixelFormatEnum sdlPixelFormatEnum, Palette palette)

Constructs a dsdl2.PixelFormat using an indexed SDL_PixelFormatEnum from bindbc-sdl, allowing use with dsdl2.Palettes

this
this(ubyte bitsPerPixel, uint[4] rgbaMasks)

Constructs a dsdl2.PixelFormat from user-provided bit masks for RGB color and alpha channels by internally using SDL_MasksToPixelFormatEnum to retrieve the SDL_PixelFormatEnum

Destructor

~this
~this()
Undocumented in source.

Members

Aliases

abgr1555
alias abgr1555 = _multiton!SDL_PIXELFORMAT_ABGR1555
Undocumented in source.
abgr32
alias abgr32 = _multiton!(SDL_PIXELFORMAT_ABGR32, 0, 5)
Undocumented in source.
abgr4444
alias abgr4444 = _multiton!SDL_PIXELFORMAT_ABGR4444
Undocumented in source.
abgr8888
alias abgr8888 = _multiton!SDL_PIXELFORMAT_ABGR8888
Undocumented in source.
argb1555
alias argb1555 = _multiton!SDL_PIXELFORMAT_ARGB1555
Undocumented in source.
argb2101010
alias argb2101010 = _multiton!SDL_PIXELFORMAT_ARGB2101010
Undocumented in source.
argb32
alias argb32 = _multiton!(SDL_PIXELFORMAT_ARGB32, 0, 5)
Undocumented in source.
argb4444
alias argb4444 = _multiton!SDL_PIXELFORMAT_ARGB4444
Undocumented in source.
argb8888
alias argb8888 = _multiton!SDL_PIXELFORMAT_ARGB8888
Undocumented in source.
bgr24
alias bgr24 = _multiton!SDL_PIXELFORMAT_BGR24
Undocumented in source.
bgr555
alias bgr555 = _multiton!SDL_PIXELFORMAT_BGR555
Undocumented in source.
bgr565
alias bgr565 = _multiton!SDL_PIXELFORMAT_BGR565
Undocumented in source.
bgr888
alias bgr888 = _multiton!SDL_PIXELFORMAT_BGR888
Undocumented in source.
bgra32
alias bgra32 = _multiton!(SDL_PIXELFORMAT_BGRA32, 0, 5)
Undocumented in source.
bgra4444
alias bgra4444 = _multiton!SDL_PIXELFORMAT_BGRA4444
Undocumented in source.
bgra5551
alias bgra5551 = _multiton!SDL_PIXELFORMAT_BGRA5551
Undocumented in source.
bgra8888
alias bgra8888 = _multiton!SDL_PIXELFORMAT_BGRA8888
Undocumented in source.
bgrx8888
alias bgrx8888 = _multiton!SDL_PIXELFORMAT_BGRX8888
Undocumented in source.
index1lsb
alias index1lsb = _instantiateIndexed!SDL_PIXELFORMAT_INDEX1LSB

Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants

index1msb
alias index1msb = _instantiateIndexed!SDL_PIXELFORMAT_INDEX1MSB
Undocumented in source.
index4lsb
alias index4lsb = _instantiateIndexed!SDL_PIXELFORMAT_INDEX4LSB
Undocumented in source.
index4msb
alias index4msb = _instantiateIndexed!SDL_PIXELFORMAT_INDEX4MSB
Undocumented in source.
index8
alias index8 = _instantiateIndexed!SDL_PIXELFORMAT_INDEX8
Undocumented in source.
iyuv
alias iyuv = _multiton!SDL_PIXELFORMAT_IYUV
Undocumented in source.
nv12
alias nv12 = _instantiateIndexed!(SDL_PIXELFORMAT_NV12, 0, 4)

Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.4)

nv21
alias nv21 = _instantiateIndexed!(SDL_PIXELFORMAT_NV21, 0, 4)
Undocumented in source.
rgb24
alias rgb24 = _multiton!SDL_PIXELFORMAT_RGB24
Undocumented in source.
rgb332
alias rgb332 = _multiton!SDL_PIXELFORMAT_RGB332

Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants

rgb444
alias rgb444 = _multiton!SDL_PIXELFORMAT_RGB444
Undocumented in source.
rgb555
alias rgb555 = _multiton!SDL_PIXELFORMAT_RGB555
Undocumented in source.
rgb565
alias rgb565 = _multiton!SDL_PIXELFORMAT_RGB565
Undocumented in source.
rgb888
alias rgb888 = _multiton!SDL_PIXELFORMAT_RGB888
Undocumented in source.
rgba32
alias rgba32 = _multiton!(SDL_PIXELFORMAT_RGBA32, 0, 5)

Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.5)

rgba444
alias rgba444 = _multiton!SDL_PIXELFORMAT_RGBA4444
Undocumented in source.
rgba5551
alias rgba5551 = _multiton!SDL_PIXELFORMAT_RGBA5551
Undocumented in source.
rgba8888
alias rgba8888 = _multiton!SDL_PIXELFORMAT_RGBA8888
Undocumented in source.
rgbx8888
alias rgbx8888 = _multiton!SDL_PIXELFORMAT_RGBX8888
Undocumented in source.
uyvy
alias uyvy = _multiton!SDL_PIXELFORMAT_UYVY
Undocumented in source.
yuy2
alias yuy2 = _instantiateIndexed!SDL_PIXELFORMAT_YUY2
Undocumented in source.
yv12
alias yv12 = _instantiateIndexed!SDL_PIXELFORMAT_YV12
Undocumented in source.
yvyu
alias yvyu = _multiton!SDL_PIXELFORMAT_YVYU
Undocumented in source.

Functions

bitsPerPixel
ubyte bitsPerPixel()

Gets the bit depth (size of a pixel in bits) of the dsdl2.PixelFormat

bytesPerPixel
size_t bytesPerPixel()

Gets the how many bytes needed to represent a pixel in the dsdl2.PixelFormat

fourCC
bool fourCC()

Wraps SDL_ISPIXELFORMAT_FOURCC which checks whether the dsdl2.PixelFormat represents a unique format

getRGB
Color getRGB(uint pixel)

Wraps SDL_GetRGB which converts a pixel uint value to a comprehensible dsdl2.Color struct without accounting the alpha value (automatically set to opaque [255]), based on the pixel format defined by the dsdl2.PixelFormat

getRGBA
Color getRGBA(uint pixel)

Wraps SDL_GetRGBA which converts a pixel uint value to a comprehensible dsdl2.Color struct, based on the pixel format defined by the dsdl2.PixelFormat

hasAlpha
bool hasAlpha()

Wraps SDL_ISPIXELFORMAT_ALPHA which checks whether the dsdl2.PixelFormat is capable of storing alpha value

indexed
bool indexed()

Wraps SDL_ISPIXELFORMAT_INDEXED which checks whether the dsdl2.PixelFormat is indexed

mapRGB
uint mapRGB(Color color)

Wraps SDL_MapRGB which converts a dsdl2.Color to its pixel uint value according to the pixel format defined by the dsdl2.PixelFormat without accounting the alpha value, assuming that it's opaque

mapRGBA
uint mapRGBA(Color color)

Wraps SDL_MapRGBA which converts a dsdl2.Color to its pixel uint value according to the pixel format defined by the dsdl2.PixelFormat

opEquals
bool opEquals(PixelFormat rhs)

Equality operator overload

palette
inout(Palette) palette()

Gets the dsdl2.Palette bounds to the indexed dsdl2.PixelFormat

palette
void palette(Palette newPalette)

Wraps SDL_SetPixelFormatPalette which sets the dsdl2.Palette for indexed dsdl2.PixelFormats`

sdlPixelFormatEnum
SDL_PixelFormatEnum sdlPixelFormatEnum()

Gets the SDL_PixelFormatEnum of the underlying SDL_PixelFormat

toHash
hash_t toHash()

Gets the hash of the dsdl2.PixelFormat

toMasks
uint[4] toMasks()

Wraps SDL_PixelFormatEnumToMasks which gets the bit mask for all four channels of the dsdl2.PixelFormat

toString
string toString()

Formats the dsdl2.PixelFormat into its construction representation: "dsdl2.PixelFormat(<sdlPixelFormatEnum>)" or "dsdl2.PixelFormat(<sdlPixelFormatEnum>, <palette>)"

Static functions

_instantiateIndexed
PixelFormat _instantiateIndexed(Palette palette)
Undocumented in source.
_multiton
PixelFormat _multiton()
Undocumented in source.

Variables

sdlPixelFormat
SDL_PixelFormat* sdlPixelFormat;

Internal SDL_PixelFormat pointer

Examples

static if (sdlSupport >= SDLSupport.v2_0_5) {
    const auto rgba32 = dsdl2.PixelFormat.rgba32;
    assert(rgba32.mapRGBA(dsdl2.Color(0x12, 0x34, 0x56, 0x78)) == 0x12345678);
    assert(rgba32.getRGBA(0x12345678) == dsdl2.Color(0x12, 0x34, 0x56, 0x78));
}

const auto rgba8888 = dsdl2.PixelFormat.rgba8888;
version (LittleEndian) {
    assert(rgba8888.mapRGBA(dsdl2.Color(0x12, 0x34, 0x56, 0x78)) == 0x12345678);
    assert(rgba8888.getRGBA(0x12345678) == dsdl2.Color(0x12, 0x34, 0x56, 0x78));
}
version (BigEndian) {
    assert(rgba8888.mapRGBA(dsdl2.Color(0x12, 0x34, 0x56, 0x78)) == 0x78563412);
    assert(rgba8888.get(0x78563412) == dsdl2.Color(0x12, 0x34, 0x56, 0x78));
}

Meta