const std = @import("std"); pub const c = @import("c.zig").c; pub const PixelType = enum(c_int) { pixeltypeUnknown, pixeltypeIndex1, pixeltypeIndex4, pixeltypeIndex8, pixeltypePacked8, pixeltypePacked16, pixeltypePacked32, pixeltypeArrayu8, pixeltypeArrayu16, pixeltypeArrayu32, pixeltypeArrayf16, pixeltypeArrayf32, pixeltypeIndex2, }; pub const BitmapOrder = enum(c_int) { bitmaporderNone, bitmaporder4321, bitmaporder1234, }; pub const PackedOrder = enum(c_int) { packedorderNone, packedorderXrgb, packedorderRgbx, packedorderArgb, packedorderRgba, packedorderXbgr, packedorderBgrx, packedorderAbgr, packedorderBgra, }; pub const ArrayOrder = enum(c_int) { arrayorderNone, arrayorderRgb, arrayorderRgba, arrayorderArgb, arrayorderBgr, arrayorderBgra, arrayorderAbgr, }; pub const PackedLayout = enum(c_int) { packedlayoutNone, packedlayout332, packedlayout4444, packedlayout1555, packedlayout5551, packedlayout565, packedlayout8888, packedlayout2101010, packedlayout1010102, }; pub const PixelFormat = enum(c_int) { pixelformatUnknown = 0, pixelformatIndex1lsb = 0x11100100, pixelformatIndex1msb = 0x11200100, pixelformatIndex2lsb = 0x1c100200, pixelformatIndex2msb = 0x1c200200, pixelformatIndex4lsb = 0x12100400, pixelformatIndex4msb = 0x12200400, pixelformatIndex8 = 0x13000801, pixelformatRgb332 = 0x14110801, pixelformatXrgb4444 = 0x15120c02, pixelformatXbgr4444 = 0x15520c02, pixelformatXrgb1555 = 0x15130f02, pixelformatXbgr1555 = 0x15530f02, pixelformatArgb4444 = 0x15321002, pixelformatRgba4444 = 0x15421002, pixelformatAbgr4444 = 0x15721002, pixelformatBgra4444 = 0x15821002, pixelformatArgb1555 = 0x15331002, pixelformatRgba5551 = 0x15441002, pixelformatAbgr1555 = 0x15731002, pixelformatBgra5551 = 0x15841002, pixelformatRgb565 = 0x15151002, pixelformatBgr565 = 0x15551002, pixelformatRgb24 = 0x17101803, pixelformatBgr24 = 0x17401803, pixelformatXrgb8888 = 0x16161804, pixelformatRgbx8888 = 0x16261804, pixelformatXbgr8888 = 0x16561804, pixelformatBgrx8888 = 0x16661804, pixelformatArgb8888 = 0x16362004, pixelformatRgba8888 = 0x16462004, pixelformatAbgr8888 = 0x16762004, pixelformatBgra8888 = 0x16862004, pixelformatXrgb2101010 = 0x16172004, pixelformatXbgr2101010 = 0x16572004, pixelformatArgb2101010 = 0x16372004, pixelformatAbgr2101010 = 0x16772004, pixelformatRgb48 = 0x18103006, pixelformatBgr48 = 0x18403006, pixelformatRgba64 = 0x18204008, pixelformatArgb64 = 0x18304008, pixelformatBgra64 = 0x18504008, pixelformatAbgr64 = 0x18604008, pixelformatRgb48Float = 0x1a103006, pixelformatBgr48Float = 0x1a403006, pixelformatRgba64Float = 0x1a204008, pixelformatArgb64Float = 0x1a304008, pixelformatBgra64Float = 0x1a504008, pixelformatAbgr64Float = 0x1a604008, pixelformatRgb96Float = 0x1b10600c, pixelformatBgr96Float = 0x1b40600c, pixelformatRgba128Float = 0x1b208010, pixelformatArgb128Float = 0x1b308010, pixelformatBgra128Float = 0x1b508010, pixelformatAbgr128Float = 0x1b608010, pixelformatYv12 = 0x32315659, //Planar mode: Y + V + U (3 planes) pixelformatIyuv = 0x56555949, //Planar mode: Y + U + V (3 planes) pixelformatYuy2 = 0x32595559, //Packed mode: Y0+U0+Y1+V0 (1 plane) pixelformatUyvy = 0x59565955, //Packed mode: U0+Y0+V0+Y1 (1 plane) pixelformatYvyu = 0x55595659, //Packed mode: Y0+V0+Y1+U0 (1 plane) pixelformatNv12 = 0x3231564e, //Planar mode: Y + U/V interleaved (2 planes) pixelformatNv21 = 0x3132564e, //Planar mode: Y + V/U interleaved (2 planes) pixelformatP010 = 0x30313050, //Planar mode: Y + U/V interleaved (2 planes) pixelformatExternalOes = 0x2053454f, //Android video texture format pixelformatMjpg = 0x47504a4d, //Motion JPEG pub const pixelformatRgba32 = .pixelformatAbgr8888; pub const pixelformatArgb32 = .pixelformatBgra8888; pub const pixelformatBgra32 = .pixelformatArgb8888; pub const pixelformatAbgr32 = .pixelformatRgba8888; pub const pixelformatRgbx32 = .pixelformatXbgr8888; pub const pixelformatXrgb32 = .pixelformatBgrx8888; pub const pixelformatBgrx32 = .pixelformatXrgb8888; pub const pixelformatXbgr32 = .pixelformatRgbx8888; }; pub const ColorType = enum(c_int) { colorTypeUnknown = 0, colorTypeRgb = 1, colorTypeYcbcr = 2, }; pub const ColorRange = enum(c_int) { colorRangeUnknown = 0, colorRangeLimited = 1, //Narrow range, e.g. 16-235 for 8-bit RGB and luma, and 16-240 for 8-bit chroma colorRangeFull = 2, //Full range, e.g. 0-255 for 8-bit RGB and luma, and 1-255 for 8-bit chroma }; pub const ColorPrimaries = enum(c_int) { colorPrimariesUnknown = 0, colorPrimariesBt709 = 1, //ITU-R BT.709-6 colorPrimariesUnspecified = 2, colorPrimariesBt470m = 4, //ITU-R BT.470-6 System M colorPrimariesBt470bg = 5, //ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625 colorPrimariesBt601 = 6, //ITU-R BT.601-7 525, SMPTE 170M colorPrimariesSmpte240 = 7, //SMPTE 240M, functionally the same as SDL_COLOR_PRIMARIES_BT601 colorPrimariesGenericFilm = 8, //Generic film (color filters using Illuminant C) colorPrimariesBt2020 = 9, //ITU-R BT.2020-2 / ITU-R BT.2100-0 colorPrimariesXyz = 10, //SMPTE ST 428-1 colorPrimariesSmpte431 = 11, //SMPTE RP 431-2 colorPrimariesSmpte432 = 12, //SMPTE EG 432-1 / DCI P3 colorPrimariesEbu3213 = 22, //EBU Tech. 3213-E colorPrimariesCustom = 31, }; pub const TransferCharacteristics = enum(c_int) { transferCharacteristicsUnknown = 0, transferCharacteristicsBt709 = 1, //Rec. ITU-R BT.709-6 / ITU-R BT1361 transferCharacteristicsUnspecified = 2, transferCharacteristicsGamma22 = 4, //ITU-R BT.470-6 System M / ITU-R BT1700 625 PAL & SECAM transferCharacteristicsGamma28 = 5, //ITU-R BT.470-6 System B, G transferCharacteristicsBt601 = 6, //SMPTE ST 170M / ITU-R BT.601-7 525 or 625 transferCharacteristicsSmpte240 = 7, //SMPTE ST 240M transferCharacteristicsLinear = 8, transferCharacteristicsLog100 = 9, transferCharacteristicsLog100Sqrt10 = 10, transferCharacteristicsIec61966 = 11, //IEC 61966-2-4 transferCharacteristicsBt1361 = 12, //ITU-R BT1361 Extended Colour Gamut transferCharacteristicsSrgb = 13, //IEC 61966-2-1 (sRGB or sYCC) transferCharacteristicsBt202010bit = 14, //ITU-R BT2020 for 10-bit system transferCharacteristicsBt202012bit = 15, //ITU-R BT2020 for 12-bit system transferCharacteristicsPq = 16, //SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems transferCharacteristicsSmpte428 = 17, //SMPTE ST 428-1 transferCharacteristicsHlg = 18, //ARIB STD-B67, known as "hybrid log-gamma" (HLG) transferCharacteristicsCustom = 31, }; pub const MatrixCoefficients = enum(c_int) { matrixCoefficientsIdentity = 0, matrixCoefficientsBt709 = 1, //ITU-R BT.709-6 matrixCoefficientsUnspecified = 2, matrixCoefficientsFcc = 4, //US FCC Title 47 matrixCoefficientsBt470bg = 5, //ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625, functionally the same as SDL_MATRIX_COEFFICIENTS_BT601 matrixCoefficientsBt601 = 6, //ITU-R BT.601-7 525 matrixCoefficientsSmpte240 = 7, //SMPTE 240M matrixCoefficientsYcgco = 8, matrixCoefficientsBt2020Ncl = 9, //ITU-R BT.2020-2 non-constant luminance matrixCoefficientsBt2020Cl = 10, //ITU-R BT.2020-2 constant luminance matrixCoefficientsSmpte2085 = 11, //SMPTE ST 2085 matrixCoefficientsChromaDerivedNcl = 12, matrixCoefficientsChromaDerivedCl = 13, matrixCoefficientsIctcp = 14, //ITU-R BT.2100-0 ICTCP matrixCoefficientsCustom = 31, }; pub const ChromaLocation = enum(c_int) { chromaLocationNone = 0, //RGB, no chroma sampling chromaLocationLeft = 1, //In MPEG-2, MPEG-4, and AVC, Cb and Cr are taken on midpoint of the left-edge of the 2x2 square. In other words, they have the same horizontal location as the top-left pixel, but is shifted one-half pixel down vertically. chromaLocationCenter = 2, //In JPEG/JFIF, H.261, and MPEG-1, Cb and Cr are taken at the center of the 2x2 square. In other words, they are offset one-half pixel to the right and one-half pixel down compared to the top-left pixel. chromaLocationTopleft = 3, //In HEVC for BT.2020 and BT.2100 content (in particular on Blu-rays), Cb and Cr are sampled at the same location as the group's top-left Y pixel ("co-sited", "co-located"). }; pub const Colorspace = enum(c_int) { colorspaceUnknown = 0, colorspaceSrgb = 0x120005a0, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 colorspaceSrgbLinear = 0x12000500, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 colorspaceHdr10 = 0x12002600, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 colorspaceJpeg = 0x220004c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 colorspaceBt601Limited = 0x211018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 colorspaceBt601Full = 0x221018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 colorspaceBt709Limited = 0x21100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 colorspaceBt709Full = 0x22100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 colorspaceBt2020Limited = 0x21102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 colorspaceBt2020Full = 0x22102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 pub const colorspaceRgbDefault = .colorspaceSrgb; //The default colorspace for RGB surfaces if no colorspace is specified pub const colorspaceYuvDefault = .colorspaceBt601Limited; //The default colorspace for YUV surfaces if no colorspace is specified }; pub const Color = extern struct { r: u8, g: u8, b: u8, a: u8, }; pub const FColor = extern struct { r: f32, g: f32, b: f32, a: f32, }; pub const Palette = extern struct { ncolors: c_int, // number of elements in `colors`. colors: [*c]Color, // an array of colors, `ncolors` long. version: u32, // internal use only, do not touch. refcount: c_int, // internal use only, do not touch. }; pub const PixelFormatDetails = extern struct { format: PixelFormat, bits_per_pixel: u8, bytes_per_pixel: u8, padding: [2]u8, Rmask: u32, Gmask: u32, Bmask: u32, Amask: u32, Rbits: u8, Gbits: u8, Bbits: u8, Abits: u8, Rshift: u8, Gshift: u8, Bshift: u8, Ashift: u8, }; pub inline fn getPixelFormatName(format: PixelFormat) [*c]const u8 { return c.SDL_GetPixelFormatName(@intCast(@backingInt(format))); } pub inline fn getMasksForPixelFormat(format: PixelFormat, bpp: ?*c_int, Rmask: ?*u32, Gmask: ?*u32, Bmask: ?*u32, Amask: ?*u32) bool { return @bitCast(c.SDL_GetMasksForPixelFormat(@intCast(@backingInt(format)), bpp, Rmask, Gmask, Bmask, Amask)); } pub inline fn getPixelFormatForMasks(bpp: c_int, Rmask: u32, Gmask: u32, Bmask: u32, Amask: u32) PixelFormat { return @fromBackingInt(@intCast(c.SDL_GetPixelFormatForMasks(bpp, Rmask, Gmask, Bmask, Amask))); } pub inline fn getPixelFormatDetails(format: PixelFormat) ?*const PixelFormatDetails { return @ptrCast(@alignCast(c.SDL_GetPixelFormatDetails(@intCast(@backingInt(format))))); } pub inline fn createPalette(ncolors: c_int) ?*Palette { return @ptrCast(@alignCast(c.SDL_CreatePalette(ncolors))); } pub inline fn setPaletteColors(palette: ?*Palette, colors: ?*const Color, firstcolor: c_int, ncolors: c_int) bool { return @bitCast(c.SDL_SetPaletteColors(@ptrCast(@alignCast(palette)), @ptrCast(@alignCast(colors)), firstcolor, ncolors)); } pub inline fn destroyPalette(palette: ?*Palette) void { return c.SDL_DestroyPalette(@ptrCast(@alignCast(palette))); } pub inline fn mapRGB(format: ?*const PixelFormatDetails, palette: ?*const Palette, r: u8, g: u8, b: u8) u32 { return c.SDL_MapRGB(@ptrCast(@alignCast(format)), @ptrCast(@alignCast(palette)), r, g, b); } pub inline fn mapRGBA(format: ?*const PixelFormatDetails, palette: ?*const Palette, r: u8, g: u8, b: u8, a: u8) u32 { return c.SDL_MapRGBA(@ptrCast(@alignCast(format)), @ptrCast(@alignCast(palette)), r, g, b, a); } pub inline fn getRGB(pixelvalue: u32, format: ?*const PixelFormatDetails, palette: ?*const Palette, r: [*c]u8, g: [*c]u8, b: [*c]u8) void { return c.SDL_GetRGB(pixelvalue, @ptrCast(@alignCast(format)), @ptrCast(@alignCast(palette)), r, g, b); } pub inline fn getRGBA(pixelvalue: u32, format: ?*const PixelFormatDetails, palette: ?*const Palette, r: [*c]u8, g: [*c]u8, b: [*c]u8, a: [*c]u8) void { return c.SDL_GetRGBA(pixelvalue, @ptrCast(@alignCast(format)), @ptrCast(@alignCast(palette)), r, g, b, a); }