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