add support of loading PNG images with de_image

This commit is contained in:
Vadim Lopatin 2014-12-30 10:38:32 +03:00
parent 1576057751
commit eb8ca97878
5 changed files with 32 additions and 18 deletions

View File

@ -47,7 +47,7 @@
<compiler>0</compiler> <compiler>0</compiler>
<otherDMD>0</otherDMD> <otherDMD>0</otherDMD>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program> <program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source </imppath> <imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png</imppath>
<fileImppath /> <fileImppath />
<outdir>$(ConfigurationName)</outdir> <outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir> <objdir>$(OutDir)</objdir>

View File

@ -47,7 +47,7 @@
<compiler>0</compiler> <compiler>0</compiler>
<otherDMD>0</otherDMD> <otherDMD>0</otherDMD>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program> <program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source</imppath> <imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png</imppath>
<fileImppath /> <fileImppath />
<outdir>$(ConfigurationName)</outdir> <outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir> <objdir>$(OutDir)</objdir>

View File

@ -47,7 +47,7 @@
<compiler>0</compiler> <compiler>0</compiler>
<otherDMD>0</otherDMD> <otherDMD>0</otherDMD>
<program>$(DMDInstallDir)windows\bin\dmd.exe</program> <program>$(DMDInstallDir)windows\bin\dmd.exe</program>
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source </imppath> <imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png</imppath>
<fileImppath /> <fileImppath />
<outdir>$(ConfigurationName)</outdir> <outdir>$(ConfigurationName)</outdir>
<objdir>$(OutDir)</objdir> <objdir>$(OutDir)</objdir>

View File

@ -23,6 +23,10 @@ import dlangui.core.logger;
immutable uint COLOR_TRANSFORM_OFFSET_NONE = 0x80808080; immutable uint COLOR_TRANSFORM_OFFSET_NONE = 0x80808080;
immutable uint COLOR_TRANSFORM_MULTIPLY_NONE = 0x40404040; immutable uint COLOR_TRANSFORM_MULTIPLY_NONE = 0x40404040;
uint makeRGBA(T)(T r, T g, T b, T a) {
return (cast(uint)a << 24)|(cast(uint)r << 16)|(cast(uint)g << 8)|(cast(uint)b);
}
/// blend two RGB pixels using alpha /// blend two RGB pixels using alpha
uint blendARGB(uint dst, uint src, uint alpha) { uint blendARGB(uint dst, uint src, uint alpha) {
uint dstalpha = dst >> 24; uint dstalpha = dst >> 24;

View File

@ -20,15 +20,16 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com
*/ */
module dlangui.graphics.images; module dlangui.graphics.images;
immutable bool USE_FREEIMAGE = true; //immutable bool USE_FREEIMAGE = true;
//version = USE_FREEIMAGE;
//version = USE_DEIMAGE; version = USE_DEIMAGE;
version (USE_DEIMAGE) { version (USE_DEIMAGE) {
import devisualization.image.creation; import devisualization.image;
import devisualization.image.image; import devisualization.image.png;
} }
import dlangui.core.logger; import dlangui.core.logger;
@ -43,11 +44,20 @@ ColorDrawBuf loadImage(string filename) {
version (USE_DEIMAGE) { version (USE_DEIMAGE) {
try { try {
Image image = imageFromFile(filename); Image image = imageFromFile(filename);
ColorDrawBuf buf = new ColorDrawBuf(image.width, image.height); int w = cast(int)image.width;
int h = cast(int)image.height;
ColorDrawBuf buf = new ColorDrawBuf(w, h);
Color_RGBA[] pixels = image.rgba.allPixels; Color_RGBA[] pixels = image.rgba.allPixels;
for (int y = 0; y < image.height; y++) { int index = 0;
// TODO: convert pixels for (int y = 0; y < h; y++) {
uint * dstLine = buf.scanLine(y);
for (int x = 0; x < w; x++) {
Color_RGBA * pixel = &pixels[index + x];
dstLine[x] = makeRGBA(pixel.r_ubyte, pixel.g_ubyte, pixel.b_ubyte, pixel.a_ubyte);
} }
index += w;
}
//destroy(image);
return buf; return buf;
} catch (NotAnImageException e) { } catch (NotAnImageException e) {
Log.e("Failed to load image from file ", filename, " using de_image"); Log.e("Failed to load image from file ", filename, " using de_image");
@ -68,11 +78,11 @@ ColorDrawBuf loadImage(string filename) {
} }
/// load and decode image from stream to ColorDrawBuf, returns null if loading or decoding is failed version (USE_FREEIMAGE) {
ColorDrawBuf loadImage(InputStream stream) { /// 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) if (stream is null || !stream.isOpen)
return null; return null;
static if (USE_FREEIMAGE) {
return loadFreeImage(stream); return loadFreeImage(stream);
} }
} }
@ -88,7 +98,7 @@ shared static this() {
//DerelictFI.load(); //DerelictFI.load();
} }
static if (USE_FREEIMAGE) { version (USE_FREEIMAGE) {
ColorDrawBuf loadFreeImage(InputStream stream) { ColorDrawBuf loadFreeImage(InputStream stream) {
import derelict.freeimage.freeimage; import derelict.freeimage.freeimage;