From ccaa2aa6676bd3ff61d30e557394810fdd339e64 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 29 Dec 2014 15:16:22 +0300 Subject: [PATCH] support of using de_image instead of FreeImage - part 1 --- dlanguilib.visualdproj | 18 +++++++++++++- dub.json | 3 ++- src/dlangui/graphics/images.d | 44 ++++++++++++++++++++++++++++------- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj index 3b55b66e..695e44a7 100644 --- a/dlanguilib.visualdproj +++ b/dlanguilib.visualdproj @@ -47,7 +47,7 @@ 0 0 $(DMDInstallDir)windows\bin\dmd.exe - 3rdparty ../DerelictGL3/source ../DerelictUtil/source ../DerelictFT/source + 3rdparty ../DerelictGL3/source ../DerelictUtil/source ../DerelictFT/source ../de_image/source/interfaces ../de_image/source/png $(ConfigurationName) $(OutDir) @@ -234,6 +234,22 @@ + + + + + + + + + + + + + + + + diff --git a/dub.json b/dub.json index 83961467..620ea17f 100644 --- a/dub.json +++ b/dub.json @@ -95,7 +95,8 @@ "derelict-sdl2": "~master", "derelict-gl3": "~master", "derelict-fi": "~master", - "derelict-ft": "~master" + "derelict-ft": "~master", + "de_image:png": "~master" }, "-ddoxFilterArgs": ["--unittest-examples", "--min-protection=Protected", "--ex", "win32.", "--ex", "src.dlangui"] }, diff --git a/src/dlangui/graphics/images.d b/src/dlangui/graphics/images.d index 9f9b10dc..36d567e1 100644 --- a/src/dlangui/graphics/images.d +++ b/src/dlangui/graphics/images.d @@ -22,6 +22,15 @@ module dlangui.graphics.images; immutable bool USE_FREEIMAGE = true; +//version = USE_DEIMAGE; + + + +version (USE_DEIMAGE) { + import devisualization.image.creation; + import devisualization.image.image; +} + import dlangui.core.logger; import dlangui.core.types; import dlangui.graphics.drawbuf; @@ -31,22 +40,39 @@ import std.conv : to; /// load and decode image from file to ColorDrawBuf, returns null if loading or decoding is failed ColorDrawBuf loadImage(string filename) { Log.d("Loading image from file " ~ filename); - try { - std.stream.File f = new std.stream.File(filename); - scope(exit) { f.close(); } - return loadImage(f); - } catch (Exception e) { - Log.e("exception while loading image from file ", filename); - Log.e(to!string(e)); - return null; + version (USE_DEIMAGE) { + try { + Image image = imageFromFile(filename); + ColorDrawBuf buf = new ColorDrawBuf(image.width, image.height); + Color_RGBA[] pixels = image.rgba.allPixels; + for (int y = 0; y < image.height; y++) { + // TODO: convert pixels + } + return buf; + } catch (NotAnImageException e) { + Log.e("Failed to load image from file ", filename, " using de_image"); + Log.e(to!string(e)); + return null; + } + } else { + try { + std.stream.File f = new std.stream.File(filename); + scope(exit) { f.close(); } + return loadImage(f); + } catch (Exception e) { + Log.e("exception while loading image from file ", filename); + Log.e(to!string(e)); + return null; + } } + } /// 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; - static if (USE_FREEIMAGE) { + static if (USE_FREEIMAGE) { return loadFreeImage(stream); } }