1 /* 2 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 */ 28 module derelict.sdl.image; 29 30 private 31 { 32 import derelict.util.loader; 33 import derelict.util.exception; 34 import derelict.util.compat; 35 import derelict.sdl.sdl; 36 } 37 38 alias SDL_SetError IMG_SetError; 39 alias SDL_GetError IMG_GetError; 40 41 enum : Uint8 42 { 43 SDL_IMAGE_MAJOR_VERSION = 1, 44 SDL_IMAGE_MINOR_VERSION = 2, 45 SDL_IMAGE_PATCHLEVEL = 11, 46 } 47 48 void SDL_IMAGE_VERSION(SDL_version* X) 49 { 50 X.major = SDL_IMAGE_MAJOR_VERSION; 51 X.minor = SDL_IMAGE_MINOR_VERSION; 52 X.patch = SDL_IMAGE_PATCHLEVEL; 53 } 54 55 enum 56 { 57 IMG_INIT_JPG = 0x00000001, 58 IMG_INIT_PNG = 0x00000002, 59 IMG_INIT_TIF = 0x00000004, 60 IMG_INIT_WEBP = 0x00000008, 61 } 62 63 64 65 extern(C) 66 { 67 alias int function(int) da_IMG_Init; 68 alias int function() da_IMG_Quit; 69 alias CSDLVERPTR function() da_IMG_Linked_Version; 70 alias SDL_Surface* function(SDL_RWops*, int, char*) da_IMG_LoadTyped_RW; 71 alias SDL_Surface* function(in char*) da_IMG_Load; 72 alias SDL_Surface* function(SDL_RWops*, int) da_IMG_Load_RW; 73 alias int function(int) da_IMG_InvertAlpha; 74 alias int function(SDL_RWops*) da_IMG_isBMP; 75 alias int function(SDL_RWops*) da_IMG_isGIF; 76 alias int function(SDL_RWops*) da_IMG_isJPG; 77 alias int function(SDL_RWops*) da_IMG_isLBM; 78 alias int function(SDL_RWops*) da_IMG_isPCX; 79 alias int function(SDL_RWops*) da_IMG_isPNG; 80 alias int function(SDL_RWops*) da_IMG_isPNM; 81 alias int function(SDL_RWops*) da_IMG_isTIF; 82 alias int function(SDL_RWops*) da_IMG_isXCF; 83 alias int function(SDL_RWops*) da_IMG_isXPM; 84 alias int function(SDL_RWops*) da_IMG_isXV; 85 alias int function(SDL_RWops*) da_IMG_isICO; 86 alias int function(SDL_RWops*) da_IMG_isCUR; 87 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadBMP_RW; 88 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadGIF_RW; 89 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadJPG_RW; 90 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadLBM_RW; 91 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadPCX_RW; 92 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadPNG_RW; 93 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadPNM_RW; 94 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadTGA_RW; 95 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadTIF_RW; 96 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadXCF_RW; 97 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadXPM_RW; 98 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadXV_RW; 99 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadICO_RW; 100 alias SDL_Surface* function(SDL_RWops*) da_IMG_LoadCUR_RW; 101 alias SDL_Surface* function(char**) da_IMG_ReadXPMFromArray; 102 } 103 104 mixin(gsharedString!() ~ 105 " 106 da_IMG_Init IMG_Init; 107 da_IMG_Quit IMG_Quit; 108 da_IMG_Linked_Version IMG_Linked_Version; 109 da_IMG_LoadTyped_RW IMG_LoadTyped_RW; 110 da_IMG_Load IMG_Load; 111 da_IMG_Load_RW IMG_Load_RW; 112 da_IMG_InvertAlpha IMG_InvertAlpha; 113 da_IMG_isBMP IMG_isBMP; 114 da_IMG_isGIF IMG_isGIF; 115 da_IMG_isJPG IMG_isJPG; 116 da_IMG_isLBM IMG_isLBM; 117 da_IMG_isPCX IMG_isPCX; 118 da_IMG_isPNG IMG_isPNG; 119 da_IMG_isPNM IMG_isPNM; 120 da_IMG_isTIF IMG_isTIF; 121 da_IMG_isXCF IMG_isXCF; 122 da_IMG_isXPM IMG_isXPM; 123 da_IMG_isXV IMG_isXV; 124 da_IMG_isICO IMG_isICO; 125 da_IMG_isCUR IMG_isCUR; 126 da_IMG_LoadBMP_RW IMG_LoadBMP_RW; 127 da_IMG_LoadGIF_RW IMG_LoadGIF_RW; 128 da_IMG_LoadJPG_RW IMG_LoadJPG_RW; 129 da_IMG_LoadLBM_RW IMG_LoadLBM_RW; 130 da_IMG_LoadPCX_RW IMG_LoadPCX_RW; 131 da_IMG_LoadPNG_RW IMG_LoadPNG_RW; 132 da_IMG_LoadPNM_RW IMG_LoadPNM_RW; 133 da_IMG_LoadTGA_RW IMG_LoadTGA_RW; 134 da_IMG_LoadTIF_RW IMG_LoadTIF_RW; 135 da_IMG_LoadXCF_RW IMG_LoadXCF_RW; 136 da_IMG_LoadXPM_RW IMG_LoadXPM_RW; 137 da_IMG_LoadXV_RW IMG_LoadXV_RW; 138 da_IMG_LoadICO_RW IMG_LoadICO_RW; 139 da_IMG_LoadCUR_RW IMG_LoadCUR_RW; 140 da_IMG_ReadXPMFromArray IMG_ReadXPMFromArray; 141 "); 142 143 144 class DerelictSDLImageLoader : SharedLibLoader 145 { 146 public: 147 this() 148 { 149 super( 150 "SDL_image.dll", 151 "libSDL_image.so, libSDL_image-1.2.so, libSDL_image-1.2.so.0", 152 "../Frameworks/SDL_image.framework/SDL_image, /Library/Frameworks/SDL_image.framework/SDL_image, /System/Library/Frameworks/SDL_image.framework/SDL_image" 153 ); 154 } 155 156 protected: 157 override void loadSymbols() 158 { 159 if(!DerelictSDL.isLoaded) 160 { 161 throw new SharedLibLoadException("DerelictSDL must be loaded before attempting to load DerelictSDLImage!"); 162 } 163 bindFunc(cast(void**)&IMG_Init, "IMG_Init"); 164 bindFunc(cast(void**)&IMG_Quit, "IMG_Quit"); 165 bindFunc(cast(void**)&IMG_Linked_Version, "IMG_Linked_Version"); 166 bindFunc(cast(void**)&IMG_LoadTyped_RW, "IMG_LoadTyped_RW"); 167 bindFunc(cast(void**)&IMG_Load, "IMG_Load"); 168 bindFunc(cast(void**)&IMG_Load_RW, "IMG_Load_RW"); 169 bindFunc(cast(void**)&IMG_InvertAlpha, "IMG_InvertAlpha"); 170 bindFunc(cast(void**)&IMG_isBMP, "IMG_isBMP"); 171 bindFunc(cast(void**)&IMG_isGIF, "IMG_isGIF"); 172 bindFunc(cast(void**)&IMG_isJPG, "IMG_isJPG"); 173 bindFunc(cast(void**)&IMG_isLBM, "IMG_isLBM"); 174 bindFunc(cast(void**)&IMG_isPCX, "IMG_isPCX"); 175 bindFunc(cast(void**)&IMG_isPNG, "IMG_isPNG"); 176 bindFunc(cast(void**)&IMG_isPNM, "IMG_isPNM"); 177 bindFunc(cast(void**)&IMG_isTIF, "IMG_isTIF"); 178 bindFunc(cast(void**)&IMG_isXCF, "IMG_isXCF"); 179 bindFunc(cast(void**)&IMG_isXPM, "IMG_isXPM"); 180 bindFunc(cast(void**)&IMG_isXV, "IMG_isXV"); 181 bindFunc(cast(void**)&IMG_isICO, "IMG_isICO"); 182 bindFunc(cast(void**)&IMG_isCUR, "IMG_isCUR"); 183 bindFunc(cast(void**)&IMG_LoadBMP_RW, "IMG_LoadBMP_RW"); 184 bindFunc(cast(void**)&IMG_LoadGIF_RW, "IMG_LoadGIF_RW"); 185 bindFunc(cast(void**)&IMG_LoadJPG_RW, "IMG_LoadJPG_RW"); 186 bindFunc(cast(void**)&IMG_LoadLBM_RW, "IMG_LoadLBM_RW"); 187 bindFunc(cast(void**)&IMG_LoadPCX_RW, "IMG_LoadPCX_RW"); 188 bindFunc(cast(void**)&IMG_LoadPNG_RW, "IMG_LoadPNG_RW"); 189 bindFunc(cast(void**)&IMG_LoadPNM_RW, "IMG_LoadPNM_RW"); 190 bindFunc(cast(void**)&IMG_LoadTGA_RW, "IMG_LoadTGA_RW"); 191 bindFunc(cast(void**)&IMG_LoadTIF_RW, "IMG_LoadTIF_RW"); 192 bindFunc(cast(void**)&IMG_LoadXCF_RW, "IMG_LoadXCF_RW"); 193 bindFunc(cast(void**)&IMG_LoadXPM_RW, "IMG_LoadXPM_RW"); 194 bindFunc(cast(void**)&IMG_LoadXV_RW, "IMG_LoadXV_RW"); 195 bindFunc(cast(void**)&IMG_LoadICO_RW, "IMG_LoadICO_RW"); 196 bindFunc(cast(void**)&IMG_LoadCUR_RW, "IMG_LoadCUR_RW"); 197 bindFunc(cast(void**)&IMG_ReadXPMFromArray, "IMG_ReadXPMFromArray"); 198 } 199 } 200 201 DerelictSDLImageLoader DerelictSDLImage; 202 203 static this() 204 { 205 DerelictSDLImage = new DerelictSDLImageLoader(); 206 } 207 208 static ~this() 209 { 210 if(SharedLibLoader.isAutoUnloadEnabled()) 211 DerelictSDLImage.unload(); 212 }