support of using de_image instead of FreeImage - part 1

This commit is contained in:
Vadim Lopatin 2014-12-29 15:16:22 +03:00
parent d5dff418fe
commit ccaa2aa667
3 changed files with 54 additions and 11 deletions

View File

@ -47,7 +47,7 @@
<compiler>0</compiler>
<otherDMD>0</otherDMD>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath>3rdparty ../DerelictGL3/source ../DerelictUtil/source ../DerelictFT/source</imppath>
<imppath>3rdparty ../DerelictGL3/source ../DerelictUtil/source ../DerelictFT/source ../de_image/source/interfaces ../de_image/source/png</imppath>
<fileImppath />
<outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir>
@ -234,6 +234,22 @@
<File path="..\DerelictUtil\source\derelict\util\wintypes.d" />
<File path="..\DerelictUtil\source\derelict\util\xtypes.d" />
</Folder>
<Folder name="de_image">
<File path="..\de_image\source\png\devisualization\image\png\chunks.d" />
<File path="..\de_image\source\interfaces\devisualization\image\color.d" />
<File path="..\de_image\source\interfaces\devisualization\image\creation.d" />
<File path="..\de_image\source\png\devisualization\image\png\defs.d" />
<File path="..\de_image\source\interfaces\devisualization\image\image.d" />
<File path="..\de_image\source\interfaces\devisualization\image\manipulation.d" />
<File path="..\de_image\source\interfaces\devisualization\image\package.d" />
<File path="..\de_image\source\png\devisualization\image\png\package.d" />
<File path="..\de_image\source\png\devisualization\image\png\reader.d" />
<File path="..\de_image\source\png\devisualization\image\png\reader_chunks.d" />
<File path="..\de_image\source\png\devisualization\image\png\reader_chunks_IDAT.d" />
<File path="..\de_image\source\png\devisualization\image\png\writer.d" />
<File path="..\de_image\source\png\devisualization\image\png\writer_chunks.d" />
<File path="..\de_image\source\png\devisualization\image\png\writer_chunks_IDAT.d" />
</Folder>
<Folder name="win32">
<File path="3rdparty\win32\basetsd.d" />
<File path="3rdparty\win32\basetyps.d" />

View File

@ -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"]
},

View File

@ -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);
}
}