pixels.nim
Header for the enumerated pixel format definitions.
Types
Color = object r*: uint8 g*: uint8 b*: uint8 a*: uint8
Colour = Color
Palette = object ncolors*: cint colors*: ptr Color version*: uint32 refcount*: cint
PixelFormat = object format*: uint32 palette*: ptr Palette BitsPerPixel*: uint8 BytesPerPixel*: uint8 padding*: array[2, uint8] Rmask*: uint32 Gmask*: uint32 Bmask*: uint32 Amask*: uint32 Rloss*: uint8 Gloss*: uint8 Bloss*: uint8 Aloss*: uint8 Rshift*: uint8 Gshift*: uint8 Bshift*: uint8 Ashift*: uint8 refcount*: cint next*: ptr PixelFormat
- Note: Everything in the pixel format object is read-only.
Consts
ALPHA_OPAQUE = 255
ALPHA_TRANSPARENT = 0
PIXELTYPE_UNKNOWN = 0
PIXELTYPE_INDEX1 = 1
PIXELTYPE_INDEX4 = 2
PIXELTYPE_INDEX8 = 3
PIXELTYPE_PACKED8 = 4
PIXELTYPE_PACKED16 = 5
PIXELTYPE_PACKED32 = 6
PIXELTYPE_ARRAYU8 = 7
PIXELTYPE_ARRAYU16 = 8
PIXELTYPE_ARRAYU32 = 9
PIXELTYPE_ARRAYF16 = 10
PIXELTYPE_ARRAYF32 = 11
BITMAPORDER_NONE = 0
BITMAPORDER_4321 = 1
BITMAPORDER_1234 = 2
PACKEDORDER_NONE = 0
PACKEDORDER_XRGB = 1
PACKEDORDER_RGBX = 2
PACKEDORDER_ARGB = 3
PACKEDORDER_RGBA = 4
PACKEDORDER_XBGR = 5
PACKEDORDER_BGRX = 6
PACKEDORDER_ABGR = 7
PACKEDORDER_BGRA = 8
ARRAYORDER_NONE = 0
ARRAYORDER_RGB = 1
ARRAYORDER_RGBA = 2
ARRAYORDER_ARGB = 3
ARRAYORDER_BGR = 4
ARRAYORDER_BGRA = 5
ARRAYORDER_ABGR = 6
PACKEDLAYOUT_NONE = 0
PACKEDLAYOUT_332 = 1
PACKEDLAYOUT_4444 = 2
PACKEDLAYOUT_1555 = 3
PACKEDLAYOUT_5551 = 4
PACKEDLAYOUT_565 = 5
PACKEDLAYOUT_8888 = 6
PACKEDLAYOUT_2101010 = 7
PACKEDLAYOUT_1010102 = 8
PIXELFORMAT_RGBA32 = 376840196
PIXELFORMAT_ARGB32 = 377888772
PIXELFORMAT_BGRA32 = 372645892
PIXELFORMAT_ABGR32 = 373694468
Procs
proc getPixelFormatName(format: uint32): cstring {.
cdecl, importc: "SDL_GetPixelFormatName", dynlib: SDL2_LIB.}- Get the human readable name of a pixel format.
proc pixelFormatEnumToMasks(format: uint32; bpp: ptr cint; rMask: ptr uint32; gMask: ptr uint32; bMask: ptr uint32; aMask: ptr uint32): bool {.
cdecl, importc: "SDL_PixelFormatEnumToMasks", dynlib: SDL2_LIB.}-
Convert one of the enumerated pixel formats to a bpp and RGBA masks.
Return true, or false if the conversion wasn't possible.
See also:
masksToPixelFormatEnum()
proc masksToPixelFormatEnum(bpp: cint; rMask: uint32; gMask: uint32; bMask: uint32; aMask: uint32): uint32 {.
cdecl, importc: "SDL_MasksToPixelFormatEnum", dynlib: SDL2_LIB.}-
Convert a bpp and RGBA masks to an enumerated pixel format.
Return the pixel format, or PIXELFORMAT_UNKNOWN if the conversion wasn't possible.
See also:
pixelFormatEnumToMasks()
proc allocFormat(pixel_format: uint32): ptr PixelFormat {.
cdecl, importc: "SDL_AllocFormat", dynlib: SDL2_LIB.}- Create an PixelFormat object from a pixel format enum.
proc freeFormat(format: ptr PixelFormat) {.
cdecl, importc: "SDL_FreeFormat", dynlib: SDL2_LIB.}- Free an PixelFormat object.
proc allocPalette(ncolors: cint): ptr Palette {.
cdecl, importc: "SDL_AllocPalette", dynlib: SDL2_LIB.}-
Create a palette structure with the specified number of color entries.
Return a new palette, or nil if there wasn't enough memory.
Note: The palette entries are initialized to white.
See also:
freePalette()
proc setPixelFormatPalette(format: ptr PixelFormat; palette: ptr Palette): cint {.
cdecl, importc: "SDL_SetPixelFormatPalette", dynlib: SDL2_LIB.}- Set the palette for a pixel format object.
proc setPaletteColors(palette: ptr Palette; colors: ptr Color; firstcolor: cint; ncolors: cint): cint {.
cdecl, importc: "SDL_SetPaletteColors", dynlib: SDL2_LIB.}-
Set a range of colors in a palette.
palette The palette to modify. colors An array of colors to copy into the palette. firstcolor The index of the first palette entry to modify. ncolors The number of entries to modify.
Return 0 on success, or -1 if not all of the colors could be set.
proc freePalette(palette: ptr Palette) {.
cdecl, importc: "SDL_FreePalette", dynlib: SDL2_LIB.}-
Free a palette created with allocPalette().
See also:
allocPalette()
proc mapRGB(format: ptr PixelFormat; r: uint8; g: uint8; b: uint8): uint32 {.
cdecl, importc: "SDL_MapRGB", dynlib: SDL2_LIB.}-
Maps an RGB triple to an opaque pixel value for a given pixel format.
See also:
mapRGBA()
proc mapRGB(format: ptr PixelFormat; color: Color): uint32 {.
inline, raises: [], tags: [].}proc mapRGBA(format: ptr PixelFormat; r: uint8; g: uint8; b: uint8; a: uint8): uint32 {.
cdecl, importc: "SDL_MapRGBA", dynlib: SDL2_LIB.}-
Maps an RGBA quadruple to a pixel value for a given pixel format.
See also:
mapRGB()
proc mapRGBA(format: ptr PixelFormat; color: Color): uint32 {.
inline, raises: [], tags: [].}proc getRGB(pixel: uint32; format: ptr PixelFormat; r: ptr uint8; g: ptr uint8; b: ptr uint8) {.
cdecl, importc: "SDL_GetRGB", dynlib: SDL2_LIB.}-
Get the RGB components from a pixel of the specified format.
See also:
getRGBA()
proc getRGB(pixel: uint32; format: ptr PixelFormat): Color {.
inline, raises: [], tags: [].}proc getRGBA(pixel: uint32; format: ptr PixelFormat; r: ptr uint8; g: ptr uint8; b: ptr uint8; a: ptr uint8) {.
cdecl, importc: "SDL_GetRGBA", dynlib: SDL2_LIB.}-
Get the RGBA components from a pixel of the specified format.
See also:
getRGB()
proc getRGBA(pixel: uint32; format: ptr PixelFormat): Color {.
inline, raises: [], tags: [].}proc calculateGammaRamp(gamma: cfloat; ramp: ptr uint16) {.
cdecl, importc: "SDL_CalculateGammaRamp", dynlib: SDL2_LIB.}- Calculate a 256 entry gamma ramp for a gamma value.
Templates
template definePixelFourCC(a, b, c, d: untyped): untyped
template definePixelFormat(kind, order, layout, bits, bytes: untyped): untyped
template pixelFlag(x: untyped): untyped
template pixelType(x: untyped): untyped
template pixelOrder(x: untyped): untyped
template pixelLayout(x: untyped): untyped
template bitsPerPixel(x: untyped): untyped
template bytesPerPixel(x: untyped): untyped
template isPixelFormatIndexed(format: untyped): untyped
template isPixelFormatPacked(format: untyped): untyped
template isPixelFormatArray(format: untyped): untyped
template isPixelFormatAlpha(format: untyped): untyped
template isPixelFormatFourCC(format: untyped): untyped
- The flag is set to 1 because 0x1? is not in the printable ASCII range.