aboutsummaryrefslogtreecommitdiff
path: root/smelt
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2019-06-15 13:19:46 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2019-06-15 13:19:46 +0800
commit2da6a4aec9a249417a9e4c0106ab6bec0489a36f (patch)
tree96b3d7bb38e01170fb59435a16ee4f7d2572d782 /smelt
parentb859c1accbb2bf7b19f634346528458ccf11b6f1 (diff)
downloadSMELT-2da6a4aec9a249417a9e4c0106ab6bec0489a36f.tar.xz
Added DevIL as an option for image loader.
Diffstat (limited to 'smelt')
-rw-r--r--smelt/glfw/gfx_glfw.cpp26
-rw-r--r--smelt/glfw/gfx_glfw_compat.cpp24
2 files changed, 48 insertions, 2 deletions
diff --git a/smelt/glfw/gfx_glfw.cpp b/smelt/glfw/gfx_glfw.cpp
index c545073..aa5f4bd 100644
--- a/smelt/glfw/gfx_glfw.cpp
+++ b/smelt/glfw/gfx_glfw.cpp
@@ -9,7 +9,13 @@
*
*/
#include "smelt_internal.hpp"
+
+#ifdef USE_CXIMAGE
#include "CxImage/ximage.h"
+#else
+#include "IL/il.h"
+#endif
+
#define dbg printf("%d: 0x%X\n",__LINE__,glGetError())
#ifndef USE_OPENGL_COMPATIBILITY_PROFILE
#include "smmath_priv.hpp"
@@ -575,6 +581,8 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int &
}
return px;
}
+
+#ifdef USE_CXIMAGE
CxImage img;
img.Decode(data,size,CXIMAGE_FORMAT_UNKNOWN);
if(img.IsValid())
@@ -593,6 +601,24 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int &
*(sptr++)=achannel?rgb.rgbReserved:0xFF;
}
}
+#else
+ ilInit();
+ ILuint iid;
+ ilGenImages(1,&iid);
+ if(ilLoadL(IL_TYPE_UNKNOWN,data,size))
+ {
+ w=ilGetInteger(IL_IMAGE_WIDTH);
+ h=ilGetInteger(IL_IMAGE_HEIGHT);
+ if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_UNSIGNED_INT||ilGetInteger(IL_IMAGE_TYPE)!=IL_RGBA)
+ ilConvertImage(IL_UNSIGNED_INT,IL_RGBA);
+ px=new DWORD[w*h];
+ for(int i=0;i<h;++i)
+ memcpy(px+w*(h-1-i),ilGetData()+w*i*sizeof(DWORD)/sizeof(ILubyte),w*sizeof(DWORD));
+ }
+ ilDeleteImages(1,&iid);
+ ilShutDown();
+#endif
+
return px;
}
void SMELT_IMPL::bindTexture(glTexture *t)
diff --git a/smelt/glfw/gfx_glfw_compat.cpp b/smelt/glfw/gfx_glfw_compat.cpp
index 995f697..16ee500 100644
--- a/smelt/glfw/gfx_glfw_compat.cpp
+++ b/smelt/glfw/gfx_glfw_compat.cpp
@@ -582,6 +582,8 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int &
}
return px;
}
+
+#ifdef USE_CXIMAGE
CxImage img;
img.Decode(data,size,CXIMAGE_FORMAT_UNKNOWN);
if(img.IsValid())
@@ -589,7 +591,7 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int &
w=img.GetWidth();h=img.GetHeight();
px=new DWORD[w*h];
BYTE *sptr=(BYTE*)px;
- bool atunnel=img.AlphaIsValid();
+ bool achannel=img.AlphaIsValid();
for(int i=0;i<h;++i)
for(int j=0;j<w;++j)
{
@@ -597,9 +599,27 @@ DWORD* SMELT_IMPL::decodeImage(BYTE *data,const char *fn,DWORD size,int &w,int &
*(sptr++)=rgb.rgbRed;
*(sptr++)=rgb.rgbGreen;
*(sptr++)=rgb.rgbBlue;
- *(sptr++)=atunnel?rgb.rgbReserved:0xFF;
+ *(sptr++)=achannel?rgb.rgbReserved:0xFF;
}
}
+#else
+ ilInit();
+ ILuint iid;
+ ilGenImages(1,&iid);
+ if(ilLoadL(IL_TYPE_UNKNOWN,data,size))
+ {
+ w=ilGetInteger(IL_IMAGE_WIDTH);
+ h=ilGetInteger(IL_IMAGE_HEIGHT);
+ if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_UNSIGNED_INT||ilGetInteger(IL_IMAGE_TYPE)!=IL_RGBA)
+ ilConvertImage(IL_UNSIGNED_INT,IL_RGBA);
+ px=new DWORD[w*h];
+ for(int i=0;i<h;++i)
+ memcpy(px+w*(h-1-i),ilGetData()+w*i*sizeof(DWORD)/sizeof(ILubyte),w*sizeof(DWORD));
+ }
+ ilDeleteImages(1,&iid);
+ ilShutDown();
+#endif
+
return px;
}
void SMELT_IMPL::bindTexture(glTexture *t)