1 /+ 2 + Copyright 2022 – 2024 Aya Partridge 3 + Copyright 2018 - 2022 Michael D. Parker 4 + Distributed under the Boost Software License, Version 1.0. 5 + (See accompanying file LICENSE_1_0.txt or copy at 6 + http://www.boost.org/LICENSE_1_0.txt) 7 +/ 8 module sdl.surface; 9 10 import bindbc.sdl.config; 11 import bindbc.sdl.codegen; 12 13 import sdl.blendmode: SDL_BlendMode; 14 import sdl.rect: SDL_Rect; 15 import sdl.rwops; 16 import sdl.pixels: SDL_Palette, SDL_PixelFormat; 17 import sdl.stdinc: SDL_bool; 18 19 enum{ 20 SDL_SWSURFACE = 0x0000_0000, 21 SDL_PREALLOC = 0x0000_0001, 22 SDL_RLEACCEL = 0x0000_0002, 23 SDL_DONTFREE = 0x0000_0004, 24 } 25 26 pragma(inline, true) bool SDL_MUSTLOCK(const(SDL_Surface)* s) nothrow @nogc pure{ 27 return (s.flags & SDL_RLEACCEL) != 0; 28 } 29 30 struct SDL_BlitMap; 31 32 struct SDL_Surface{ 33 int flags; 34 SDL_PixelFormat* format; 35 int w, h; 36 int pitch; 37 void* pixels; 38 39 void* userdata; 40 41 int locked; 42 43 static if(sdlSupport >= SDLSupport.v2_0_14){ 44 void* list_blitmap; 45 }else{ 46 void* lock_data; 47 } 48 49 SDL_Rect clip_rect; 50 51 SDL_BlitMap* map; 52 53 int refcount; 54 } 55 56 alias SDL_blit = extern(C) int function(SDL_Surface* src, SDL_Rect* srcRect, SDL_Surface* dst, SDL_Rect* dstRect) nothrow; 57 58 static if(sdlSupport >= SDLSupport.v2_0_8){ 59 alias SDL_YUV_CONVERSION_MODE = int; 60 enum: SDL_YUV_CONVERSION_MODE{ 61 SDL_YUV_CONVERSION_JPEG, 62 SDL_YUV_CONVERSION_BT601, 63 SDL_YUV_CONVERSION_BT709, 64 SDL_YUV_CONVERSION_AUTOMATIC, 65 } 66 } 67 68 pragma(inline, true) nothrow @nogc{ 69 SDL_Surface* SDL_LoadBMP(const(char)* file){ 70 return SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1); 71 } 72 73 int SDL_SaveBMP(SDL_Surface* surface, const(char)* file){ 74 return SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1); 75 } 76 } 77 78 mixin(joinFnBinds((){ 79 FnBind[] ret = [ 80 {q{SDL_Surface*}, q{SDL_CreateRGBSurface}, q{uint flags, int width, int height, int depth, uint rMask, uint gMask, uint bMask, uint aMask}}, 81 {q{SDL_Surface*}, q{SDL_CreateRGBSurfaceFrom}, q{void* pixels, int width, int height, int depth, int pitch, uint rMask, uint gMask, uint bMask, uint aMask}}, 82 {q{void}, q{SDL_FreeSurface}, q{SDL_Surface* surface}}, 83 {q{int}, q{SDL_SetSurfacePalette}, q{SDL_Surface* surface, SDL_Palette* palette}}, 84 {q{int}, q{SDL_LockSurface}, q{SDL_Surface* surface}}, 85 {q{int}, q{SDL_UnlockSurface}, q{SDL_Surface* surface}}, 86 {q{SDL_Surface*}, q{SDL_LoadBMP_RW}, q{SDL_RWops* src, int freeSrc}}, 87 {q{int}, q{SDL_SaveBMP_RW}, q{SDL_Surface* surface, SDL_RWops* dst, int freeDst}}, 88 {q{int}, q{SDL_SetSurfaceRLE}, q{SDL_Surface* surface, int flag}}, 89 {q{int}, q{SDL_SetColorKey}, q{SDL_Surface* surface, int flag, uint key}}, 90 {q{int}, q{SDL_GetColorKey}, q{SDL_Surface* surface, uint* key}}, 91 {q{int}, q{SDL_SetSurfaceColorMod}, q{SDL_Surface* surface, ubyte r, ubyte g, ubyte b}}, 92 {q{int}, q{SDL_GetSurfaceColorMod}, q{SDL_Surface* surface, ubyte* r, ubyte* g, ubyte* b}}, 93 {q{int}, q{SDL_SetSurfaceAlphaMod}, q{SDL_Surface* surface, ubyte alpha}}, 94 {q{int}, q{SDL_GetSurfaceAlphaMod}, q{SDL_Surface* surface, ubyte* alpha}}, 95 {q{int}, q{SDL_SetSurfaceBlendMode}, q{SDL_Surface* surface, SDL_BlendMode blendMode}}, 96 {q{int}, q{SDL_GetSurfaceBlendMode}, q{SDL_Surface* surface, SDL_BlendMode* blendMode}}, 97 {q{SDL_bool}, q{SDL_SetClipRect}, q{SDL_Surface* surface, const(SDL_Rect)* rect}}, 98 {q{void}, q{SDL_GetClipRect}, q{SDL_Surface* surface, SDL_Rect* rect}}, 99 {q{SDL_Surface*}, q{SDL_ConvertSurface}, q{SDL_Surface* surface, const(SDL_PixelFormat)* fmt, uint flags}}, 100 {q{SDL_Surface*}, q{SDL_ConvertSurfaceFormat}, q{SDL_Surface* surface, uint pixelFormat, uint flags}}, 101 {q{int}, q{SDL_ConvertPixels}, q{int width, int height, uint srcFormat, const(void)* src, int srcPitch, uint dstFormat, void* dst, int dstPitch}}, 102 {q{int}, q{SDL_FillRect}, q{SDL_Surface* surface, const(SDL_Rect)* rect, uint colour}}, 103 {q{int}, q{SDL_FillRects}, q{SDL_Surface* surface, const(SDL_Rect)* rects, int count, uint colour}}, 104 {q{int}, q{SDL_UpperBlit}, q{SDL_Surface* src, const(SDL_Rect)* srcrect, SDL_Surface* dst, SDL_Rect* dstRect}}, 105 {q{int}, q{SDL_LowerBlit}, q{SDL_Surface* src, SDL_Rect* srcRect, SDL_Surface* dst, SDL_Rect* dstRect}}, 106 {q{int}, q{SDL_SoftStretch}, q{SDL_Surface* src, const(SDL_Rect)* srcRect, SDL_Surface* dst, const(SDL_Rect)* dstRect}}, 107 {q{int}, q{SDL_UpperBlitScaled}, q{SDL_Surface* src, const(SDL_Rect)* srcRect, SDL_Surface* dst, SDL_Rect* dstRect}}, 108 {q{int}, q{SDL_LowerBlitScaled}, q{SDL_Surface* src, SDL_Rect* srcRect, SDL_Surface* dst, SDL_Rect* dstRect}}, 109 ]; 110 if(sdlSupport >= SDLSupport.v2_0_5){ 111 FnBind[] add = [ 112 {q{SDL_Surface*}, q{SDL_CreateRGBSurfaceWithFormat}, q{uint flags, int width, int height, int depth, uint format}}, 113 {q{SDL_Surface*}, q{SDL_CreateRGBSurfaceWithFormatFrom}, q{void* pixels, int width, int height, int depth, int pitch, uint format}}, 114 ]; 115 ret ~= add; 116 } 117 if(sdlSupport >= SDLSupport.v2_0_5){ 118 FnBind[] add = [ 119 {q{SDL_Surface*}, q{SDL_DuplicateSurface}, q{SDL_Surface* surface}}, 120 ]; 121 ret ~= add; 122 } 123 if(sdlSupport >= SDLSupport.v2_0_8){ 124 FnBind[] add = [ 125 {q{void}, q{SDL_SetYUVConversionMode}, q{SDL_YUV_CONVERSION_MODE mode}}, 126 {q{SDL_YUV_CONVERSION_MODE}, q{SDL_GetYUVConversionMode}, q{}}, 127 {q{SDL_YUV_CONVERSION_MODE}, q{SDL_GetYUVConversionModeForResolution}, q{int width, int height}}, 128 ]; 129 ret ~= add; 130 } 131 if(sdlSupport >= SDLSupport.v2_0_9){ 132 FnBind[] add = [ 133 {q{SDL_bool}, q{SDL_HasColorKey}, q{SDL_Surface* surface}}, 134 ]; 135 ret ~= add; 136 } 137 if(sdlSupport >= SDLSupport.v2_0_16){ 138 FnBind[] add = [ 139 {q{int}, q{SDL_SoftStretchLinear}, q{SDL_Surface* src, const(SDL_Rect)* srcRect, SDL_Surface* dst, const(SDL_Rect)* dstRect}}, 140 ]; 141 ret ~= add; 142 } 143 if(sdlSupport >= SDLSupport.v2_0_18){ 144 FnBind[] add = [ 145 {q{int}, q{SDL_PremultiplyAlpha}, q{int width, int height, uint srcFormat, const(void)* src, int srcPitch, uint dstFormat, void* dst, int dstPitch}}, 146 ]; 147 ret ~= add; 148 } 149 return ret; 150 }())); 151 152 alias SDL_SetColourKey = SDL_SetColorKey; 153 alias SDL_GetColourKey = SDL_GetColorKey; 154 alias SDL_SetSurfaceColourMod = SDL_SetSurfaceColorMod; 155 alias SDL_GetSurfaceColourMod = SDL_GetSurfaceColorMod; 156 alias SDL_BlitSurface = SDL_UpperBlit; 157 alias SDL_BlitScaled = SDL_UpperBlitScaled; 158 static if(sdlSupport >= SDLSupport.v2_0_9){ 159 alias SDL_HasColourKey = SDL_HasColorKey; 160 }