Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change to FreeImage for image loading

  • Loading branch information...
commit 70877b4e299310fe5c545f330d8a20e6342d1973 1 parent 276235a
@puffnfresh authored
Showing with 28 additions and 25 deletions.
  1. +2 −6 README.md
  2. +24 −17 src/image.h
  3. +2 −2 wscript
View
8 README.md
@@ -12,10 +12,7 @@ Dependencies
* node.js
* SDL
* OpenGL
-* DevIL
-
-I'd like to try and get rid of the DevIL dependency when there are more node.js
-image libraries.
+* FreeImage
Building
--------
@@ -26,7 +23,7 @@ Testing
-------
node examples/example.js
- chromium-browser --enable-webgl examples/example.html
+ chromium-browser examples/example.html
On Mac OS X, you have to run the following first:
@@ -37,7 +34,6 @@ Developing
* Add more WebGL functions!
* Make some node.js image libraries
-* Replace DevIL with those node.js image libraries
* Find nice ways to remove the `nodejs` variable from example-include.js
* Add more events (e.g. keyboard)
* Make/port some WebGL examples
View
41 src/image.h
@@ -5,7 +5,7 @@
#include <node.h>
-#include <IL/il.h>
+#include <FreeImage.h>
using namespace v8;
using namespace node;
@@ -30,7 +30,7 @@ class Image : public EventEmitter {
target->Set(String::NewSymbol("Image"), t->GetFunction());
- ilInit();
+ FreeImage_Initialise(true);
}
void
@@ -52,36 +52,43 @@ class Image : public EventEmitter {
int
GetBPP () {
- ilBindImage(image_id);
- return ilGetInteger(IL_IMAGE_BPP);
+ //return FreeImage_GetBPP(image_bmp);
+ return 32;
}
int
GetWidth () {
- ilBindImage(image_id);
- return ilGetInteger(IL_IMAGE_WIDTH);
+ return FreeImage_GetWidth(image_bmp);
}
int
GetHeight () {
- ilBindImage(image_id);
- return ilGetInteger(IL_IMAGE_HEIGHT);
+ return FreeImage_GetHeight(image_bmp);
}
void *
GetData () {
- return data;
+ BYTE *pixels = FreeImage_GetBits(image_bmp);
+
+ // FreeImage stores data in BGR
+ // Convert from BGR to RGB
+ for(int i = 0; i < FreeImage_GetWidth(image_bmp) * FreeImage_GetHeight(image_bmp); i++)
+ {
+ BYTE temp = pixels[i * 4 + 0];
+ pixels[i * 4 + 0] = pixels[i * 4 + 2];
+ pixels[i * 4 + 2] = temp;
+ }
+
+ return pixels;
}
void
Load (const char *filename) {
this->filename = (char *)filename;
- ilBindImage(image_id);
- ilLoadImage(filename);
- ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
-
- data = ilGetData();
+ FREE_IMAGE_FORMAT format = FreeImage_GetFileType(filename, 0);
+ image_bmp = FreeImage_Load(format, filename, 0);
+ image_bmp = FreeImage_ConvertTo32Bits(image_bmp);
}
protected:
@@ -157,16 +164,16 @@ class Image : public EventEmitter {
}
Image () : EventEmitter() {
- ilGenImages(1, &image_id);
}
~Image () {
- ilDeleteImages(1, &image_id);
+ if (image_bmp) FreeImage_Unload(image_bmp);
+ FreeImage_DeInitialise();
}
private:
- ILuint image_id;
+ FIBITMAP *image_bmp;
char *filename;
void *data;
View
4 wscript
@@ -16,13 +16,13 @@ def configure(conf):
conf.env["CXXDEFINES"] = ["GL_GLEXT_PROTOTYPES"]
conf.check_cfg(package='gl', mandatory=True, args='--cflags --libs')
conf.check_cfg(package='sdl', mandatory=True, args='--cflags --libs')
- conf.check_cfg(package='IL', mandatory=True, args='--cflags --libs')
def build(bld):
webgl = bld.new_task_gen("cxx", "shlib", "node_addon")
webgl.target = "webgl"
webgl.source = "src/webgl.cc"
- webgl.uselib = ["GL", "SDL", 'IL']
+ webgl.lib = ['freeimage']
+ webgl.uselib = ["GL", "SDL"]
def shutdown():
# HACK to get binding.node out of build directory.
Please sign in to comment.
Something went wrong with that request. Please try again.