diff --git a/3rdparty/DerelictFI/DerelictFI.dproj b/3rdparty/DerelictFI/DerelictFI.dproj deleted file mode 100644 index c512ac7f..00000000 --- a/3rdparty/DerelictFI/DerelictFI.dproj +++ /dev/null @@ -1,67 +0,0 @@ - - - - Debug - AnyCPU - 10.0.0 - 2.0 - {ED644EF9-A446-4987-873F-B7F3CC28E3B7} - true - true - DMD2 - true - - - {0B737AB4-0C3B-4250-A133-3AD793E2D322} - - - - - ../../../DerelictUtil/source - - - - - true - bin\Debug - obj/Debug - false - false - DerelictFI - StaticLibrary - true - 0 - - - bin\Release - obj/Release - false - false - DerelictFI - Executable - true - 0 - - - true - bin\Unittest - obj/Unittest - false - true - DerelictFI - Executable - true - 0 - - - - freeimage.d - - - functions.d - - - types.d - - - \ No newline at end of file diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj index dbdda100..96e5fe2b 100644 --- a/dlanguilib.visualdproj +++ b/dlanguilib.visualdproj @@ -190,11 +190,6 @@ - - - - - diff --git a/src/dlangui/graphics/images.d b/src/dlangui/graphics/images.d index e60e286f..67fcecdd 100644 --- a/src/dlangui/graphics/images.d +++ b/src/dlangui/graphics/images.d @@ -20,9 +20,6 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com */ module dlangui.graphics.images; -//immutable bool USE_FREEIMAGE = true; - -//version = USE_FREEIMAGE; //version = USE_DEIMAGE; version = USE_DLIBIMAGE; @@ -113,138 +110,9 @@ ColorDrawBuf loadImage(string filename) { } -version (USE_FREEIMAGE) { - /// load and decode image from stream to ColorDrawBuf, returns null if loading or decoding is failed - ColorDrawBuf loadImage(InputStream stream) { - if (stream is null || !stream.isOpen) - return null; - return loadFreeImage(stream); - } -} - class ImageDecodingException : Exception { this(string msg) { super(msg); } } -shared static this() { - //import derelict.freeimage.freeimage; - //DerelictFI.load(); -} - -version (USE_FREEIMAGE) { - ColorDrawBuf loadFreeImage(InputStream stream) { - import derelict.freeimage.freeimage; - - static bool FREE_IMAGE_LOADED; - if (!FREE_IMAGE_LOADED) { - DerelictFI.load(); - FREE_IMAGE_LOADED = true; - } - - ubyte[] imagebuf; - ubyte[4096] readbuf; - for (;;) { - size_t bytesRead = stream.read(readbuf); - if (!bytesRead) - break; - imagebuf ~= readbuf[0..bytesRead]; - } - //pointer to the image, once loaded - FIBITMAP *dib = null; //image format - FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; - // attach the binary data to a memory stream - FIMEMORY *hmem = FreeImage_OpenMemory(imagebuf.ptr, imagebuf.length); - fif = FreeImage_GetFileTypeFromMemory(hmem); - //check that the plugin has reading capabilities and load the file - if(!FreeImage_FIFSupportsReading(fif)) { - FreeImage_CloseMemory(hmem); - return null; - } - - // load an image from the memory stream - dib = FreeImage_LoadFromMemory(fif, hmem, 0); - - //if the image failed to load, return failure - if (!dib) { - Log.e("Failed to decode image"); - FreeImage_CloseMemory(hmem); - return null; - } - //retrieve the image data - ubyte * data = cast(ubyte*)FreeImage_GetBits(dib); - //get the image width and height, and size per pixel - int width = FreeImage_GetWidth(dib); - int height = FreeImage_GetHeight(dib); - int stride = FreeImage_GetPitch(dib); - int bpp = FreeImage_GetBPP(dib); - int pixelSize = (bpp + 7)/8; - //Log.d("image ", width, "x", height, " stride ", stride, "(", stride / pixelSize, ") bpp ", bpp, " pixelSize ", pixelSize); - FREE_IMAGE_COLOR_TYPE colorType = FreeImage_GetColorType(dib); - int transparentIndex = 0; - int transparencyCount = 0; - RGBQUAD * palette = null; - ubyte * transparencyTable = null; - if (colorType == FIC_PALETTE) { - palette = FreeImage_GetPalette(dib); - transparentIndex = FreeImage_GetTransparentIndex(dib); - transparencyCount = FreeImage_GetTransparencyCount(dib); - transparencyTable = FreeImage_GetTransparencyTable(dib); - } - //int size = stride*height; - - ColorDrawBuf res = new ColorDrawBuf(width, height); - - //swap R and B and invert image while copying - ubyte* src; - uint* dst; - uint r, g, b, a; - for( int i = 0, ii = height-1; i < height ; ++i, --ii ) { - dst = res.scanLine(i); - src = data + ii * stride; - for( int j = 0; j < width; ++j, ++dst, src += pixelSize ) { - if (colorType == FIC_PALETTE) { - ubyte index = src[0]; - a = 0; - if (transparencyTable !is null) { - a = transparencyTable[index] ^ 0xFF; - } else if (transparentIndex >= 0 && index >= transparentIndex && index < transparentIndex + transparencyCount) { - a = 0xFF; - } - RGBQUAD pcolor = palette[index]; - r = pcolor.rgbRed; - g = pcolor.rgbGreen; - b = pcolor.rgbBlue; - dst[0] = (a << 24) | (r << 16) | (g << 8) | b; - } else { - a = 0; - switch (pixelSize) { - case 4: - a = src[3] ^ 255; - // fall through - goto case; - case 3: - r = src[2]; - g = src[1]; - b = src[0]; - break; - case 2: - // todo: do something better - r = g = src[1]; - b = src[0]; - break; - default: - case 1: - r = g = b = src[0]; - break; - } - dst[0] = (a << 24) | (r << 16) | (g << 8) | b; - } - } - } - FreeImage_CloseMemory(hmem); - return res; - } -} -