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.freeimage.freeimage;
29 
30 import derelict.util.exception,
31        derelict.util.system;
32 
33 public
34 import derelict.freeimage.functions,
35        derelict.freeimage.types,
36        derelict.util.loader;
37 
38 class DerelictFILoader : SharedLibLoader
39 {
40     this() { super(libNames); }
41 
42 protected:
43     override void configureMinimumVersion(SharedLibVersion minVersion)
44     {
45         if(minVersion.major == 3) {
46             if(minVersion.minor == 15) {
47                 if(minVersion.patch == 4)
48                     missingSymbolCallback = &allowFI_3_15_4;
49                 else
50                     missingSymbolCallback = &allowFI_3_15_0;
51             }
52             else if(minVersion.minor == 16)
53                 missingSymbolCallback = &allowFI_3_16_0;
54         }
55     }
56 
57     override void loadSymbols() { loadFuncs(this); }
58 
59 private:
60     ShouldThrow allowFI_3_15_0(string symbolName)
61     {
62         static if(Derelict_OS_Windows && !Derelict_Arch_64) {
63             if(symbolName == "_FreeImage_ConvertToRGB16@4")
64                 return ShouldThrow.No;
65         }
66         else {
67             if(symbolName == "FreeImage_ConvertToRGB16")
68                 return ShouldThrow.No;
69         }
70         return allowFI_3_15_4(symbolName);
71     }
72 
73     ShouldThrow allowFI_3_15_4(string symbolName)
74     {
75         switch(symbolName) {
76             static if(Derelict_OS_Windows && !Derelict_Arch_64) {
77                 case "_FreeImage_JPEGTransformFromHandle@40":
78                 case "_FreeImage_JPEGTransformCombined@32":
79                 case "_FreeImage_JPEGTransformCombinedU@32":
80                 case "_FreeImage_JPEGTransformCombinedFromMemory@32":
81                     return ShouldThrow.No;
82             }
83             else {
84                 case "FreeImage_JPEGTransformFromHandle":
85                 case "FreeImage_JPEGTransformCombined":
86                 case "FreeImage_JPEGTransformCombinedU":
87                 case "FreeImage_JPEGTransformCombinedFromMemory":
88                     return ShouldThrow.No;
89             }
90             default: return allowFI_3_16_0(symbolName);
91         }
92     }
93 
94     ShouldThrow allowFI_3_16_0(string symbolName)
95     {
96         switch(symbolName) {
97             static if(Derelict_OS_Windows && !Derelict_Arch_64) {
98                 case "_FreeImage_GetMemorySize@4":
99                 case "_FreeImage_ConvertFromRawBitsEx@44":
100                 case "_FreeImage_ConvertToRGBAF@4":
101                 case "_FreeImage_ConvertToRGBA16@4":
102                 case "_FreeImage_SetMetadataKeyValue@16":
103                 case "_FreeImage_RescaleRect@36":
104                 case "_FreeImage_CreateView@20":
105                     return ShouldThrow.No;
106             }
107             else {
108                 case "FreeImage_GetMemorySize":
109                 case "FreeImage_ConvertFromRawBitsEx":
110                 case "FreeImage_ConvertToRGBAF":
111                 case "FreeImage_ConvertToRGBA16":
112                 case "FreeImage_SetMetadataKeyValue":
113                 case "FreeImage_RescaleRect":
114                 case "FreeImage_CreateView":
115                     return ShouldThrow.No;
116             }
117             default: return ShouldThrow.Yes;
118         }
119     }
120 }
121 
122 __gshared DerelictFILoader DerelictFI;
123 
124 shared static this()
125 {
126     DerelictFI = new DerelictFILoader();
127 }
128 
129 private:
130     static if(Derelict_OS_Windows)
131         enum libNames = "FreeImage.dll";
132     else static if(Derelict_OS_Mac)
133         enum libNames = "libfreeimage.dylib,libfreeimage.dylib.3";
134     else static if(Derelict_OS_Posix)
135         enum libNames = "libfreeimage.so,libfreeimage.so.3";
136     else
137         static assert(0, "Need to implement FreeImage libNames for this operating system.");