1 2 // Copyright Michael D. Parker 2018. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module bindbc.sdl.bind.sdlsurface; 8 9 import bindbc.sdl.config; 10 import bindbc.sdl.bind.sdlblendmode : SDL_BlendMode; 11 import bindbc.sdl.bind.sdlrect : SDL_Rect; 12 import bindbc.sdl.bind.sdlrwops; 13 import bindbc.sdl.bind.sdlpixels : SDL_Palette, SDL_PixelFormat; 14 import bindbc.sdl.bind.sdlstdinc : SDL_bool; 15 16 enum { 17 SDL_SWSURFACE = 0, 18 SDL_PREALLOC = 0x00000001, 19 SDL_RLEACCEL = 0x00000002, 20 SDL_DONTFREE = 0x00000004, 21 } 22 23 @nogc nothrow pure 24 bool SDL_MUSTLOCK(const(SDL_Surface)* S) 25 { 26 pragma(inline, true); 27 return (S.flags & SDL_RLEACCEL) != 0; 28 } 29 30 struct SDL_BlitMap; 31 struct SDL_Surface { 32 int flags; 33 SDL_PixelFormat* format; 34 int w, h; 35 int pitch; 36 void* pixels; 37 void* userdata; 38 int locked; 39 void* lock_data; 40 SDL_Rect clip_rect; 41 SDL_BlitMap* map; 42 int refcount; 43 } 44 45 extern(C) nothrow alias SDL_blit = int function(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect); 46 47 @nogc nothrow { 48 SDL_Surface* SDL_LoadBMP(const(char)* file) { 49 pragma(inline, true); 50 return SDL_LoadBMP_RW(SDL_RWFromFile(file,"rb"),1); 51 } 52 53 int SDL_SaveBMP(SDL_Surface* surface,const(char)* file) { 54 pragma(inline, true); 55 return SDL_SaveBMP_RW(surface,SDL_RWFromFile(file,"wb"),1); 56 } 57 } 58 59 alias SDL_BlitSurface = SDL_UpperBlit; 60 alias SDL_BlitScaled = SDL_UpperBlitScaled; 61 62 static if(sdlSupport >= SDLSupport.sdl208) { 63 enum SDL_YUV_CONVERSION_MODE { 64 SDL_YUV_CONVERSION_JPEG, 65 SDL_YUV_CONVERSION_BT601, 66 SDL_YUV_CONVERSION_BT709, 67 SDL_YUV_CONVERSION_AUTOMATIC, 68 } 69 mixin(expandEnum!SDL_YUV_CONVERSION_MODE); 70 } 71 72 version(BindSDL_Static) { 73 extern(C) @nogc nothrow { 74 SDL_Surface* SDL_CreateRGBSurface(uint,int,int,int,uint,uint,uint,uint); 75 SDL_Surface* SDL_CreateRGBSurfaceFrom(void*,int,int,int,int,uint,uint,uint,uint); 76 void SDL_FreeSurface(SDL_Surface*); 77 int SDL_SetSurfacePalette(SDL_Surface*,SDL_Palette*); 78 int SDL_LockSurface(SDL_Surface*); 79 int SDL_UnlockSurface(SDL_Surface*); 80 SDL_Surface* SDL_LoadBMP_RW(SDL_RWops*,int); 81 int SDL_SaveBMP_RW(SDL_Surface*,SDL_RWops*,int); 82 int SDL_SetSurfaceRLE(SDL_Surface*,int); 83 int SDL_SetColorKey(SDL_Surface*,int,uint); 84 int SDL_GetColorKey(SDL_Surface*,uint*); 85 int SDL_SetSurfaceColorMod(SDL_Surface*,ubyte,ubyte,ubyte); 86 int SDL_GetSurfaceColorMod(SDL_Surface*,ubyte*,ubyte*,ubyte*); 87 int SDL_SetSurfaceAlphaMod(SDL_Surface*,ubyte); 88 int SDL_GetSurfaceAlphaMod(SDL_Surface*,ubyte*); 89 int SDL_SetSurfaceBlendMode(SDL_Surface*,SDL_BlendMode); 90 int SDL_GetSurfaceBlendMode(SDL_Surface*,SDL_BlendMode*); 91 SDL_bool SDL_SetClipRect(SDL_Surface*,const(SDL_Rect)*); 92 void SDL_GetClipRect(SDL_Surface*,SDL_Rect*); 93 SDL_Surface* SDL_ConvertSurface(SDL_Surface*,const(SDL_PixelFormat)*,uint); 94 SDL_Surface* SDL_ConvertSurfaceFormat(SDL_Surface*,uint,uint); 95 int SDL_ConvertPixels(int,int,uint,const(void)*,int,uint,void*,int); 96 int SDL_FillRect(SDL_Surface*,const(SDL_Rect)*,uint); 97 int SDL_FillRects(SDL_Surface*,const(SDL_Rect)*,int,uint); 98 int SDL_UpperBlit(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 99 int SDL_LowerBlit(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 100 int SDL_SoftStretch(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,const(SDL_Rect)*); 101 int SDL_UpperBlitScaled(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 102 int SDL_LowerBlitScaled(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 103 104 static if(sdlSupport >= SDLSupport.sdl205) { 105 SDL_Surface* SDL_CreateRGBSurfaceWithFormat(uint,int,int,int,uint); 106 SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom(void*,int,int,int,int,uint); 107 } 108 static if(sdlSupport >= SDLSupport.sdl205) { 109 SDL_Surface* SDL_DuplicateSurface(SDL_Surface*); 110 } 111 static if(sdlSupport >= SDLSupport.sdl208) { 112 void SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE); 113 SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode(); 114 SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution(int,int); 115 } 116 static if(sdlSupport >= SDLSupport.sdl209) { 117 SDL_bool SDL_HasColorKey(SDL_Surface*); 118 } 119 } 120 } 121 else { 122 extern(C) @nogc nothrow {alias pSDL_CreateRGBSurface = SDL_Surface* function(uint,int,int,int,uint,uint,uint,uint); 123 alias pSDL_CreateRGBSurfaceFrom = SDL_Surface* function(void*,int,int,int,int,uint,uint,uint,uint); 124 alias pSDL_FreeSurface = void function(SDL_Surface*); 125 alias pSDL_SetSurfacePalette = int function(SDL_Surface*,SDL_Palette*); 126 alias pSDL_LockSurface = int function(SDL_Surface*); 127 alias pSDL_UnlockSurface = int function(SDL_Surface*); 128 alias pSDL_LoadBMP_RW = SDL_Surface* function(SDL_RWops*,int); 129 alias pSDL_SaveBMP_RW = int function(SDL_Surface*,SDL_RWops*,int); 130 alias pSDL_SetSurfaceRLE = int function(SDL_Surface*,int); 131 alias pSDL_SetColorKey = int function(SDL_Surface*,int,uint); 132 alias pSDL_GetColorKey = int function(SDL_Surface*,uint*); 133 alias pSDL_SetSurfaceColorMod = int function(SDL_Surface*,ubyte,ubyte,ubyte); 134 alias pSDL_GetSurfaceColorMod = int function(SDL_Surface*,ubyte*,ubyte*,ubyte*); 135 alias pSDL_SetSurfaceAlphaMod = int function(SDL_Surface*,ubyte); 136 alias pSDL_GetSurfaceAlphaMod = int function(SDL_Surface*,ubyte*); 137 alias pSDL_SetSurfaceBlendMode = int function(SDL_Surface*,SDL_BlendMode); 138 alias pSDL_GetSurfaceBlendMode = int function(SDL_Surface*,SDL_BlendMode*); 139 alias pSDL_SetClipRect = SDL_bool function(SDL_Surface*,const(SDL_Rect)*); 140 alias pSDL_GetClipRect = void function(SDL_Surface*,SDL_Rect*); 141 alias pSDL_ConvertSurface = SDL_Surface* function(SDL_Surface*,const(SDL_PixelFormat)*,uint); 142 alias pSDL_ConvertSurfaceFormat = SDL_Surface* function(SDL_Surface*,uint,uint); 143 alias pSDL_ConvertPixels = int function(int,int,uint,const(void)*,int,uint,void*,int); 144 alias pSDL_FillRect = int function(SDL_Surface*,const(SDL_Rect)*,uint); 145 alias pSDL_FillRects = int function(SDL_Surface*,const(SDL_Rect)*,int,uint); 146 alias pSDL_UpperBlit = int function(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 147 alias pSDL_LowerBlit = int function(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 148 alias pSDL_SoftStretch = int function(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,const(SDL_Rect)*); 149 alias pSDL_UpperBlitScaled = int function(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 150 alias pSDL_LowerBlitScaled = int function(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 151 } 152 153 __gshared { 154 pSDL_CreateRGBSurface SDL_CreateRGBSurface; 155 pSDL_CreateRGBSurfaceFrom SDL_CreateRGBSurfaceFrom; 156 pSDL_FreeSurface SDL_FreeSurface; 157 pSDL_SetSurfacePalette SDL_SetSurfacePalette; 158 pSDL_LockSurface SDL_LockSurface; 159 pSDL_UnlockSurface SDL_UnlockSurface; 160 pSDL_LoadBMP_RW SDL_LoadBMP_RW; 161 pSDL_SaveBMP_RW SDL_SaveBMP_RW; 162 pSDL_SetSurfaceRLE SDL_SetSurfaceRLE; 163 pSDL_SetColorKey SDL_SetColorKey; 164 pSDL_GetColorKey SDL_GetColorKey; 165 pSDL_SetSurfaceColorMod SDL_SetSurfaceColorMod; 166 pSDL_GetSurfaceColorMod SDL_GetSurfaceColorMod; 167 pSDL_SetSurfaceAlphaMod SDL_SetSurfaceAlphaMod; 168 pSDL_GetSurfaceAlphaMod SDL_GetSurfaceAlphaMod; 169 pSDL_SetSurfaceBlendMode SDL_SetSurfaceBlendMode; 170 pSDL_GetSurfaceBlendMode SDL_GetSurfaceBlendMode; 171 pSDL_SetClipRect SDL_SetClipRect; 172 pSDL_GetClipRect SDL_GetClipRect; 173 pSDL_ConvertSurface SDL_ConvertSurface; 174 pSDL_ConvertSurfaceFormat SDL_ConvertSurfaceFormat; 175 pSDL_ConvertPixels SDL_ConvertPixels; 176 pSDL_FillRect SDL_FillRect; 177 pSDL_FillRects SDL_FillRects; 178 pSDL_UpperBlit SDL_UpperBlit; 179 pSDL_LowerBlit SDL_LowerBlit; 180 pSDL_SoftStretch SDL_SoftStretch; 181 pSDL_UpperBlitScaled SDL_UpperBlitScaled; 182 pSDL_LowerBlitScaled SDL_LowerBlitScaled; 183 } 184 185 static if(sdlSupport >= SDLSupport.sdl205) { 186 extern(C) @nogc nothrow { 187 alias pSDL_CreateRGBSurfaceWithFormat = SDL_Surface* function(uint,int,int,int,uint); 188 alias pSDL_CreateRGBSurfaceWithFormatFrom = SDL_Surface* function(void*,int,int,int,int,uint); 189 } 190 191 __gshared { 192 pSDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat; 193 pSDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom; 194 } 195 } 196 197 static if(sdlSupport >= SDLSupport.sdl205) { 198 extern(C) @nogc nothrow { 199 alias pSDL_DuplicateSurface = SDL_Surface* function(SDL_Surface*); 200 } 201 202 __gshared { 203 pSDL_DuplicateSurface SDL_DuplicateSurface; 204 } 205 } 206 207 static if(sdlSupport >= SDLSupport.sdl208) { 208 extern(C) @nogc nothrow { 209 alias pSDL_SetYUVConversionMode = void function(SDL_YUV_CONVERSION_MODE); 210 alias pSDL_GetYUVConversionMode = SDL_YUV_CONVERSION_MODE function(); 211 alias pSDL_GetYUVConversionModeForResolution = SDL_YUV_CONVERSION_MODE function(int,int); 212 } 213 214 __gshared { 215 pSDL_SetYUVConversionMode SDL_SetYUVConversionMode; 216 pSDL_GetYUVConversionMode SDL_GetYUVConversionMode; 217 pSDL_GetYUVConversionModeForResolution SDL_GetYUVConversionModeForResolution; 218 } 219 } 220 221 static if(sdlSupport >= SDLSupport.sdl209) { 222 extern(C) @nogc nothrow { 223 alias pSDL_HasColorKey = SDL_bool function(SDL_Surface*); 224 } 225 226 __gshared { 227 pSDL_HasColorKey SDL_HasColorKey; 228 } 229 } 230 }