Class PixelFormat

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

class PixelFormat ;

Constructors

NameDescription
this (sdlPixelFormat, isOwner, userRef) Constructs a dsdl2.PixelFormat from a vanilla SDL_PixelFormat* from bindbc-sdl
this (sdlPixelFormatEnum) Constructs a dsdl2.PixelFormat using an SDL_PixelFormatEnum from bindbc-sdl
this (sdlPixelFormatEnum, palette) Constructs a dsdl2.PixelFormat using an indexed SDL_PixelFormatEnum from bindbc-sdl, allowing use with dsdl2.Palettes
this (bitsPerPixel, 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

Fields

NameTypeDescription
sdlPixelFormat sdl.pixels.SDL_PixelFormat*Internal SDL_PixelFormat pointer

Properties

NameTypeDescription
bitsPerPixel[get] ubyteGets the bit depth (size of a pixel in bits) of the dsdl2.PixelFormat
bytesPerPixel[get] ulongGets the how many bytes needed to represent a pixel in the dsdl2.PixelFormat
fourCC[get] boolWraps SDL_ISPIXELFORMAT_FOURCC which checks whether the dsdl2.PixelFormat represents a unique format
hasAlpha[get] boolWraps SDL_ISPIXELFORMAT_ALPHA which checks whether the dsdl2.PixelFormat is capable of storing alpha value
indexed[get] boolWraps SDL_ISPIXELFORMAT_INDEXED which checks whether the dsdl2.PixelFormat is indexed
palette[get] inout(Palette)Gets the dsdl2.Palette bounds to the indexed dsdl2.PixelFormat
palette[set] PaletteWraps SDL_SetPixelFormatPalette which sets the dsdl2.Palette for indexed dsdl2.PixelFormats`
sdlPixelFormatEnum[get] uintGets the SDL_PixelFormatEnum of the underlying SDL_PixelFormat

Methods

NameDescription
getRGB (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 (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
mapRGB (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 (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 (rhs) Equality operator overload
toHash () Gets the hash of the dsdl2.PixelFormat
toMasks () Wraps SDL_PixelFormatEnumToMasks which gets the bit mask for all four channels of the dsdl2.PixelFormat
toString () Formats the dsdl2.PixelFormat into its construction representation: "dsdl2.PixelFormat(<sdlPixelFormatEnum>)" or "dsdl2.PixelFormat(<sdlPixelFormatEnum>, <palette>)"

Aliases

NameDescription
abgr1555 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
abgr32 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.5)
abgr4444 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
abgr8888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
argb1555 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
argb2101010 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
argb32 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.5)
argb4444 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
argb8888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgr24 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgr555 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgr565 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgr888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgra32 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.5)
bgra4444 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgra5551 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgra8888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
bgrx8888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
index1lsb Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants
index1msb Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants
index4lsb Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants
index4msb Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants
index8 Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants
iyuv Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
nv12 Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.4)
nv21 Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.4)
rgb24 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgb332 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgb444 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgb555 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgb565 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgb888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgba32 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants (from SDL 2.0.5)
rgba444 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgba5551 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgba8888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
rgbx8888 Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
uyvy Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants
yuy2 Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants
yv12 Instantiates indexed dsdl2.PixelFormat for use with dsdl2.Palettes from SDL_PIXELFORMAT_* enumeration constants
yvyu Retrieves one of the dsdl2.PixelFormat multiton presets from SDL_PIXELFORMAT_* enumeration constants

Example

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));
}