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 static if(sdlSupport >= SDLSupport.sdl208) { 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 mixin(expandEnum!SDL_YUV_CONVERSION_MODE); 67 } 68 69 version(BindSDL_Static) { 70 extern(C) @nogc nothrow { 71 SDL_Surface* SDL_CreateRGBSurface(uint,int,int,int,uint,uint,uint,uint); 72 SDL_Surface* SDL_CreateRGBSurfaceFrom(void*,int,int,int,int,uint,uint,uint,uint); 73 void SDL_FreeSurface(SDL_Surface*); 74 int SDL_SetSurfacePalette(SDL_Surface*,SDL_Palette*); 75 int SDL_LockSurface(SDL_Surface*); 76 int SDL_UnlockSurface(SDL_Surface*); 77 SDL_Surface* SDL_LoadBMP_RW(SDL_RWops*,int); 78 int SDL_SaveBMP_RW(SDL_Surface*,SDL_RWops*,int); 79 int SDL_SetSurfaceRLE(SDL_Surface*,int); 80 int SDL_SetColorKey(SDL_Surface*,int,uint); 81 int SDL_GetColorKey(SDL_Surface*,uint*); 82 int SDL_SetSurfaceColorMod(SDL_Surface*,ubyte,ubyte,ubyte); 83 int SDL_GetSurfaceColorMod(SDL_Surface*,ubyte*,ubyte*,ubyte*); 84 int SDL_SetSurfaceAlphaMod(SDL_Surface*,ubyte); 85 int SDL_GetSurfaceAlphaMod(SDL_Surface*,ubyte*); 86 int SDL_SetSurfaceBlendMode(SDL_Surface*,SDL_BlendMode); 87 int SDL_GetSurfaceBlendMode(SDL_Surface*,SDL_BlendMode*); 88 SDL_bool SDL_SetClipRect(SDL_Surface*,const(SDL_Rect)*); 89 void SDL_GetClipRect(SDL_Surface*,SDL_Rect*); 90 SDL_Surface* SDL_ConvertSurface(SDL_Surface*,const(SDL_PixelFormat)*,uint); 91 SDL_Surface* SDL_ConvertSurfaceFormat(SDL_Surface*,uint,uint); 92 int SDL_ConvertPixels(int,int,uint,const(void)*,int,uint,void*,int); 93 int SDL_FillRect(SDL_Surface*,const(SDL_Rect)*,uint); 94 int SDL_FillRects(SDL_Surface*,const(SDL_Rect)*,int,uint); 95 int SDL_UpperBlit(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 96 int SDL_LowerBlit(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 97 int SDL_SoftStretch(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,const(SDL_Rect)*); 98 int SDL_UpperBlitScaled(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 99 int SDL_LowerBlitScaled(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 100 101 static if(sdlSupport >= SDLSupport.sdl205) { 102 SDL_Surface* SDL_CreateRGBSurfaceWithFormat(uint,int,int,int,uint); 103 SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom(void*,int,int,int,int,uint); 104 } 105 static if(sdlSupport >= SDLSupport.sdl205) { 106 SDL_Surface* SDL_DuplicateSurface(SDL_Surface*); 107 } 108 static if(sdlSupport >= SDLSupport.sdl208) { 109 void SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE); 110 SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode(); 111 SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution(int,int); 112 } 113 static if(sdlSupport >= SDLSupport.sdl209) { 114 SDL_bool SDL_HasColorKey(SDL_Surface*); 115 } 116 } 117 } 118 else { 119 extern(C) @nogc nothrow {alias pSDL_CreateRGBSurface = SDL_Surface* function(uint,int,int,int,uint,uint,uint,uint); 120 alias pSDL_CreateRGBSurfaceFrom = SDL_Surface* function(void*,int,int,int,int,uint,uint,uint,uint); 121 alias pSDL_FreeSurface = void function(SDL_Surface*); 122 alias pSDL_SetSurfacePalette = int function(SDL_Surface*,SDL_Palette*); 123 alias pSDL_LockSurface = int function(SDL_Surface*); 124 alias pSDL_UnlockSurface = int function(SDL_Surface*); 125 alias pSDL_LoadBMP_RW = SDL_Surface* function(SDL_RWops*,int); 126 alias pSDL_SaveBMP_RW = int function(SDL_Surface*,SDL_RWops*,int); 127 alias pSDL_SetSurfaceRLE = int function(SDL_Surface*,int); 128 alias pSDL_SetColorKey = int function(SDL_Surface*,int,uint); 129 alias pSDL_GetColorKey = int function(SDL_Surface*,uint*); 130 alias pSDL_SetSurfaceColorMod = int function(SDL_Surface*,ubyte,ubyte,ubyte); 131 alias pSDL_GetSurfaceColorMod = int function(SDL_Surface*,ubyte*,ubyte*,ubyte*); 132 alias pSDL_SetSurfaceAlphaMod = int function(SDL_Surface*,ubyte); 133 alias pSDL_GetSurfaceAlphaMod = int function(SDL_Surface*,ubyte*); 134 alias pSDL_SetSurfaceBlendMode = int function(SDL_Surface*,SDL_BlendMode); 135 alias pSDL_GetSurfaceBlendMode = int function(SDL_Surface*,SDL_BlendMode*); 136 alias pSDL_SetClipRect = SDL_bool function(SDL_Surface*,const(SDL_Rect)*); 137 alias pSDL_GetClipRect = void function(SDL_Surface*,SDL_Rect*); 138 alias pSDL_ConvertSurface = SDL_Surface* function(SDL_Surface*,const(SDL_PixelFormat)*,uint); 139 alias pSDL_ConvertSurfaceFormat = SDL_Surface* function(SDL_Surface*,uint,uint); 140 alias pSDL_ConvertPixels = int function(int,int,uint,const(void)*,int,uint,void*,int); 141 alias pSDL_FillRect = int function(SDL_Surface*,const(SDL_Rect)*,uint); 142 alias pSDL_FillRects = int function(SDL_Surface*,const(SDL_Rect)*,int,uint); 143 alias pSDL_UpperBlit = int function(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 144 alias pSDL_LowerBlit = int function(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 145 alias pSDL_SoftStretch = int function(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,const(SDL_Rect)*); 146 alias pSDL_UpperBlitScaled = int function(SDL_Surface*,const(SDL_Rect)*,SDL_Surface*,SDL_Rect*); 147 alias pSDL_LowerBlitScaled = int function(SDL_Surface*,SDL_Rect*,SDL_Surface*,SDL_Rect*); 148 } 149 150 __gshared { 151 pSDL_CreateRGBSurface SDL_CreateRGBSurface; 152 pSDL_CreateRGBSurfaceFrom SDL_CreateRGBSurfaceFrom; 153 pSDL_FreeSurface SDL_FreeSurface; 154 pSDL_SetSurfacePalette SDL_SetSurfacePalette; 155 pSDL_LockSurface SDL_LockSurface; 156 pSDL_UnlockSurface SDL_UnlockSurface; 157 pSDL_LoadBMP_RW SDL_LoadBMP_RW; 158 pSDL_SaveBMP_RW SDL_SaveBMP_RW; 159 pSDL_SetSurfaceRLE SDL_SetSurfaceRLE; 160 pSDL_SetColorKey SDL_SetColorKey; 161 pSDL_GetColorKey SDL_GetColorKey; 162 pSDL_SetSurfaceColorMod SDL_SetSurfaceColorMod; 163 pSDL_GetSurfaceColorMod SDL_GetSurfaceColorMod; 164 pSDL_SetSurfaceAlphaMod SDL_SetSurfaceAlphaMod; 165 pSDL_GetSurfaceAlphaMod SDL_GetSurfaceAlphaMod; 166 pSDL_SetSurfaceBlendMode SDL_SetSurfaceBlendMode; 167 pSDL_GetSurfaceBlendMode SDL_GetSurfaceBlendMode; 168 pSDL_SetClipRect SDL_SetClipRect; 169 pSDL_GetClipRect SDL_GetClipRect; 170 pSDL_ConvertSurface SDL_ConvertSurface; 171 pSDL_ConvertSurfaceFormat SDL_ConvertSurfaceFormat; 172 pSDL_ConvertPixels SDL_ConvertPixels; 173 pSDL_FillRect SDL_FillRect; 174 pSDL_FillRects SDL_FillRects; 175 pSDL_UpperBlit SDL_UpperBlit; 176 pSDL_LowerBlit SDL_LowerBlit; 177 pSDL_SoftStretch SDL_SoftStretch; 178 pSDL_UpperBlitScaled SDL_UpperBlitScaled; 179 pSDL_LowerBlitScaled SDL_LowerBlitScaled; 180 } 181 182 static if(sdlSupport >= SDLSupport.sdl205) { 183 extern(C) @nogc nothrow { 184 alias pSDL_CreateRGBSurfaceWithFormat = SDL_Surface* function(uint,int,int,int,uint); 185 alias pSDL_CreateRGBSurfaceWithFormatFrom = SDL_Surface* function(void*,int,int,int,int,uint); 186 } 187 188 __gshared { 189 pSDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat; 190 pSDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom; 191 } 192 } 193 194 static if(sdlSupport >= SDLSupport.sdl205) { 195 extern(C) @nogc nothrow { 196 alias pSDL_DuplicateSurface = SDL_Surface* function(SDL_Surface*); 197 } 198 199 __gshared { 200 pSDL_DuplicateSurface SDL_DuplicateSurface; 201 } 202 } 203 204 static if(sdlSupport >= SDLSupport.sdl208) { 205 extern(C) @nogc nothrow { 206 alias pSDL_SetYUVConversionMode = void function(SDL_YUV_CONVERSION_MODE); 207 alias pSDL_GetYUVConversionMode = SDL_YUV_CONVERSION_MODE function(); 208 alias pSDL_GetYUVConversionModeForResolution = SDL_YUV_CONVERSION_MODE function(int,int); 209 } 210 211 __gshared { 212 pSDL_SetYUVConversionMode SDL_SetYUVConversionMode; 213 pSDL_GetYUVConversionMode SDL_GetYUVConversionMode; 214 pSDL_GetYUVConversionModeForResolution SDL_GetYUVConversionModeForResolution; 215 } 216 } 217 218 static if(sdlSupport >= SDLSupport.sdl209) { 219 extern(C) @nogc nothrow { 220 alias pSDL_HasColorKey = SDL_bool function(SDL_Surface*); 221 } 222 223 __gshared { 224 pSDL_HasColorKey SDL_HasColorKey; 225 } 226 } 227 }