1 module sbylib.wrapper.freeimage.freeimage; 2 3 import derelict.freeimage.freeimage; 4 import derelict.util.exception; 5 import sbylib.wrapper.freeimage.constants; 6 7 private ShouldThrow missingSymFunc(string) { 8 return ShouldThrow.No; 9 } 10 11 package class FreeImage { 12 13 private static FreeImage instance; 14 15 static FreeImage opCall() { 16 if (instance is null) instance = new FreeImage(); 17 return instance; 18 } 19 20 private this() { 21 DerelictFI.missingSymbolCallback = &missingSymFunc; 22 DerelictFI.load(); 23 } 24 25 string getVersion() { 26 import std.conv : to; 27 return FreeImage_GetVersion().to!string; 28 } 29 30 FIBITMAP* allocate(int width, int height, int bpp) { 31 return FreeImage_Allocate(width, height, bpp, uint.max, uint.max, uint.max); 32 } 33 34 FIBITMAP* allocate(int width, int height, ImageType type) { 35 return FreeImage_AllocateT(type, width, height); 36 } 37 38 FIBITMAP* load(ImageFormat format, string path, int option) { 39 import std..string : toStringz; 40 return FreeImage_Load(format, path.toStringz, option); 41 } 42 43 void unload(FIBITMAP* bitmap) { 44 FreeImage_Unload(bitmap); 45 } 46 47 RGBQUAD* getPalette(FIBITMAP *bitmap) { 48 return FreeImage_GetPalette(bitmap); 49 } 50 51 FIBITMAP* convertTo32Bits(FIBITMAP* bitmap) { 52 return FreeImage_ConvertTo32Bits(bitmap); 53 } 54 55 int getWidth(FIBITMAP* bitmap) { 56 return FreeImage_GetWidth(bitmap); 57 } 58 59 int getHeight(FIBITMAP* bitmap) { 60 return FreeImage_GetHeight(bitmap); 61 } 62 63 int getBPP(FIBITMAP* bitmap) { 64 return FreeImage_GetBPP(bitmap); 65 } 66 67 void* getBits(FIBITMAP* bitmap) { 68 return FreeImage_GetBits(bitmap); 69 } 70 71 ImageFormat getFileType(string path) { 72 import std..string : toStringz; 73 // 第2引数は現在使われていないらしい。 74 return cast(ImageFormat)FreeImage_GetFileType(path.toStringz,0); 75 } 76 }