Pixel Formats and Conversion Routines

Pixel Types

The pixel type is one of the following values:

csdl2.SDL_PIXELTYPE_UNKNOWN

Unknown pixel type.

Indexed Pixel Types

csdl2.SDL_PIXELTYPE_INDEX1
csdl2.SDL_PIXELTYPE_INDEX4
csdl2.SDL_PIXELTYPE_INDEX8

Packed Pixel Types

csdl2.SDL_PIXELTYPE_PACKED8
csdl2.SDL_PIXELTYPE_PACKED16
csdl2.SDL_PIXELTYPE_PACKED32

Bitmap Pixel Types

csdl2.SDL_PIXELTYPE_ARRAYU8
csdl2.SDL_PIXELTYPE_ARRAYU16
csdl2.SDL_PIXELTYPE_ARRAYU32
csdl2.SDL_PIXELTYPE_ARRAYF16
csdl2.SDL_PIXELTYPE_ARRAYF32

Pixel Ordering

Depending on the pixel type there are three different types of orderings – bitmapped, packed or array.

Bitmap pixel order (high bit -> low bit)

csdl2.SDL_BITMAPORDER_NONE
csdl2.SDL_BITMAPORDER_4321
csdl2.SDL_BITMAPORDER_1234

Packed component order (high bit -> low bit)

csdl2.SDL_PACKEDORDER_NONE
csdl2.SDL_PACKEDORDER_XRGB
csdl2.SDL_PACKEDORDER_RGBX
csdl2.SDL_PACKEDORDER_ARGB
csdl2.SDL_PACKEDORDER_RGBA
csdl2.SDL_PACKEDORDER_XBGR
csdl2.SDL_PACKEDORDER_BGRX
csdl2.SDL_PACKEDORDER_ABGR
csdl2.SDL_PACKEDORDER_BGRA

Array component order (low byte -> high byte)

csdl2.SDL_ARRAYORDER_NONE
csdl2.SDL_ARRAYORDER_RGB
csdl2.SDL_ARRAYORDER_RGBA
csdl2.SDL_ARRAYORDER_ARGB
csdl2.SDL_ARRAYORDER_BGR
csdl2.SDL_ARRAYORDER_BGRA
csdl2.SDL_ARRAYORDER_ABGR

Pixel Formats

class csdl2.SDL_PixelFormat

Pixel format information.

This structure cannot be directly constructed. Use SDL_AllocFormat() instead.

format

(readonly) A constant specifying the pixel format. See Pixel format constants for possible values.

palette

(readonly) The SDL_Palette associated with this pixel format, or None if this format does not have a palette.

BitsPerPixel

(readonly) The number of significant bits in a pixel value. E.g. 8, 15, 16, 24, 32.

BytesPerPixel

(readonly) The number of bytes required to hold a pixel value. E.g. 1, 2, 3, 4.

Rmask

(readonly) A mask representing the location of the red component of a pixel.

Gmask

(readonly) A mask representing the location of the green component of a pixel.

Bmask

(readonly) A mask representing the location of the blue component of a pixel.

Rloss

(readonly) The red value of a pixel has this number of bits less compared to 8-bit values.

Gloss

(readonly) The green value of a pixel has this number of bits less compared to 8-bit values.

Bloss

(readonly) The blue value of a pixel has this number of bits less compared to 8-bit values.

Aloss

(readonly) The alpha value of a pixel has this number of bits less compared to 8-bit values.

Rshift

(readonly) The bit index of the red field of a pixel.

Gshift

(readonly) The bit index of the green value of a pixel.

Bshift

(readonly) The bit index of the blue value of a pixel.

Ashift

(readonly) The bit index of the alpha value of a pixel.

csdl2.SDL_AllocFormat(pixel_format: int) → SDL_PixelFormat

Creates a SDL_PixelFormat structure corresponding to the pixel format constant pixel_format.

Parameters:pixel_format (int) – One of the Pixel format constants.
Returns:A SDL_PixelFormat.
csdl2.SDL_FreeFormat(format: SDL_PixelFormat) → None

Frees the SDL_PixelFormat structure allocated by SDL_AllocFormat().

There is no need to manually call this function. csdl2 will automatically call this function upon garbage collection.

Parameters:format (SDL_PixelFormat) – SDL_PixelFormat structure to free.

Pixel format constants

csdl2.SDL_PIXELFORMAT_UNKNOWN
csdl2.SDL_PIXELFORMAT_INDEX1LSB
csdl2.SDL_PIXELFORMAT_INDEX1MSB
csdl2.SDL_PIXELFORMAT_INDEX4LSB
csdl2.SDL_PIXELFORMAT_INDEX4MSB
csdl2.SDL_PIXELFORMAT_INDEX8
csdl2.SDL_PIXELFORMAT_RGB332
csdl2.SDL_PIXELFORMAT_RGB444
csdl2.SDL_PIXELFORMAT_RGB555
csdl2.SDL_PIXELFORMAT_BGR555
csdl2.SDL_PIXELFORMAT_ARGB4444
csdl2.SDL_PIXELFORMAT_RGBA4444
csdl2.SDL_PIXELFORMAT_ABGR4444
csdl2.SDL_PIXELFORMAT_BGRA4444
csdl2.SDL_PIXELFORMAT_ARGB1555
csdl2.SDL_PIXELFORMAT_RGBA5551
csdl2.SDL_PIXELFORMAT_ABGR1555
csdl2.SDL_PIXELFORMAT_BGRA5551
csdl2.SDL_PIXELFORMAT_RGB565
csdl2.SDL_PIXELFORMAT_BGR565
csdl2.SDL_PIXELFORMAT_RGB24
csdl2.SDL_PIXELFORMAT_BGR24
csdl2.SDL_PIXELFORMAT_RGB888
csdl2.SDL_PIXELFORMAT_RGBX8888
csdl2.SDL_PIXELFORMAT_BGR888
csdl2.SDL_PIXELFORMAT_BGRX8888
csdl2.SDL_PIXELFORMAT_ARGB8888
csdl2.SDL_PIXELFORMAT_RGBA8888
csdl2.SDL_PIXELFORMAT_ABGR8888
csdl2.SDL_PIXELFORMAT_BGRA8888
csdl2.SDL_PIXELFORMAT_ARGB2101010
csdl2.SDL_PIXELFORMAT_YV12
csdl2.SDL_PIXELFORMAT_IYUV
csdl2.SDL_PIXELFORMAT_YUY2
csdl2.SDL_PIXELFORMAT_UYVY
csdl2.SDL_PIXELFORMAT_YVYU

Color Palette

class csdl2.SDL_Palette

A color palette.

Every pixel in an 8-bit surface is an index into the colors field of the SDL_Palette referenced by the SDL_PixelFormat.

This structure cannot be directly constructed. One will be automatically created as needed when SDL allocates a SDL_PixelFormat. It can also be created through SDL_AllocPalette().

ncolors

(readonly) Number of colors in the palette.

colors

(readonly) An array of SDL_Color structures representing the palette. This array cannot be directly modified. Use SDL_SetPaletteColors() instead.

csdl2.SDL_AllocPalette(ncolors: int) → SDL_AllocPalette

Create a new SDL_Palette with ncolors number of color entries. The color entries are initialized to white.

Parameters:ncolors (int) – Number of colors in the palette.
Returns:A new SDL_Palette.
csdl2.SDL_FreePalette(palette: SDL_Palette) → None

Frees the specified palette.

There is no need to call this function as csdl2 will automatically call this function on garbage collection.

Parameters:palette (SDL_Palette) – The SDL_Palette to be freed.