From b896832e76dfae96c80bed757b525990a8084010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 20 Oct 2013 14:34:55 +0200 Subject: [PATCH] Removed dependency to OpenIL/libDevIL --- .gitignore | 1 + src/controlling/controlling.pro | 7 ++- src/editing/editing.pro | 8 ++- src/paysages.pro | 15 +++++- src/rendering/render.c | 1 + src/rendering/rendering.pro | 7 ++- src/rendering/system.c | 90 --------------------------------- src/rendering/system.h | 7 --- src/rendering/tools/color.h | 1 + src/rendering/tools/texture.c | 49 +----------------- src/rendering/tools/texture.h | 3 -- src/system/PictureFile.cpp | 25 +++++++++ src/system/PictureFile.h | 43 ++++++++++++++++ src/system/system.pro | 28 ++++++++++ src/system/system_global.h | 21 ++++++++ src/testing/testing.pro | 7 ++- 16 files changed, 160 insertions(+), 153 deletions(-) create mode 100644 src/system/PictureFile.cpp create mode 100644 src/system/PictureFile.h create mode 100644 src/system/system.pro create mode 100644 src/system/system_global.h diff --git a/.gitignore b/.gitignore index 1b5c31b..e44ccc3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ ui_*.h /debian/files /debian/*.substvars /debian/paysages3d +/*.trace diff --git a/src/controlling/controlling.pro b/src/controlling/controlling.pro index 266dba0..67c1b6a 100644 --- a/src/controlling/controlling.pro +++ b/src/controlling/controlling.pro @@ -1,7 +1,6 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -CONFIG -= qt TARGET = paysages-cli @@ -15,3 +14,9 @@ win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../rendering/release/ else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ -lpaysages_rendering else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering DEPENDPATH += $$PWD/../rendering + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system +else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system +INCLUDEPATH += $$PWD/../system +DEPENDPATH += $$PWD/../system diff --git a/src/editing/editing.pro b/src/editing/editing.pro index 7af6734..b2eaef1 100644 --- a/src/editing/editing.pro +++ b/src/editing/editing.pro @@ -6,7 +6,7 @@ QT += core gui opengl TARGET = paysages-gui unix:LIBS += -lGLU -win32:LIBS += ../../libpaysages.a -lDevIL -lILU -lILUT -lglib-2.0 -lgthread-2.0 +win32:LIBS += ../../libpaysages.a -lglib-2.0 -lgthread-2.0 CONFIG(release, debug|release): DEFINES += NDEBUG @@ -154,3 +154,9 @@ RESOURCES += \ ../../data/ui_pictures.qrc TRANSLATIONS = ../../data/i18n/paysages_fr.ts + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system +else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system +INCLUDEPATH += $$PWD/../system +DEPENDPATH += $$PWD/../system diff --git a/src/paysages.pro b/src/paysages.pro index 24f99f1..c83080b 100644 --- a/src/paysages.pro +++ b/src/paysages.pro @@ -1,3 +1,16 @@ TEMPLATE = subdirs +CONFIG += ordered -SUBDIRS = rendering exploring editing controlling testing +SUBDIRS = \ + system \ + rendering \ + exploring \ + editing \ + controlling \ + testing + +rendering.depends = system +exploring.depends = rendering +editing.depends = exploring rendering +controlling.depends = rendering +testing.depends = rendering diff --git a/src/rendering/render.c b/src/rendering/render.c index 54113b1..5dcdaf6 100644 --- a/src/rendering/render.c +++ b/src/rendering/render.c @@ -7,6 +7,7 @@ #include "renderer.h" #include "camera.h" #include "system.h" +#include "PictureFile.h" typedef struct { diff --git a/src/rendering/rendering.pro b/src/rendering/rendering.pro index 3448657..437cd97 100644 --- a/src/rendering/rendering.pro +++ b/src/rendering/rendering.pro @@ -9,7 +9,7 @@ INCLUDEPATH += $$PWD/.. unix { CONFIG += link_pkgconfig - PKGCONFIG += glib-2.0 gthread-2.0 IL ILU + PKGCONFIG += glib-2.0 gthread-2.0 } DEFINES += HAVE_GLIB=1 CONFIG(release, debug|release): DEFINES += NDEBUG @@ -117,3 +117,8 @@ HEADERS += \ water/public.h \ water/private.h +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system +else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system +INCLUDEPATH += $$PWD/../system +DEPENDPATH += $$PWD/../system diff --git a/src/rendering/system.c b/src/rendering/system.c index 1f87c1e..f13b341 100644 --- a/src/rendering/system.c +++ b/src/rendering/system.c @@ -4,9 +4,6 @@ #include #include -#include "IL/il.h" -#include "IL/ilu.h" - #ifndef NDEBUG #define DEBUG_ONETHREAD 1 #endif @@ -54,10 +51,6 @@ void systemInit() g_thread_init(NULL); #endif _core_count = _getCoreCount(); - ilInit(); - iluInit(); - ilOriginFunc(IL_ORIGIN_LOWER_LEFT); - ilEnable(IL_ORIGIN_SET); } int systemGetCoreCount() @@ -65,89 +58,6 @@ int systemGetCoreCount() return _core_count; } -int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height) -{ - ILuint image_id; - Color result; - ILuint x, y; - ILuint rgba; - ILuint pixels[width * height]; - ILenum error; - int error_count; - - ilGenImages(1, &image_id); - ilBindImage(image_id); - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - result = callback_pixel(data, x, y); - colorNormalize(&result); - rgba = colorTo32BitRGBA(&result); - pixels[y * width + x] = rgba; - } - } - - ilTexImage((ILuint)width, (ILuint)height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, pixels); - remove(filepath); - ilSaveImage(filepath); - - ilDeleteImages(1, &image_id); - - error_count = 0; - while ((error=ilGetError()) != IL_NO_ERROR) - { - fprintf(stderr, "IL ERROR : %s\n", iluErrorString(error)); - error_count++; - } - return !error_count; -} - -int systemLoadPictureFile(const char* filepath, PictureCallbackLoadStarted callback_start, PictureCallbackLoadPixel callback_pixel, void* data) -{ - ILuint image_id; - ILenum error; - int error_count; - int width, height; - ILuint* pixels; - int x, y; - - ilGenImages(1, &image_id); - ilBindImage(image_id); - - if (ilLoadImage(filepath)) - { - width = ilGetInteger(IL_IMAGE_WIDTH); - height = ilGetInteger(IL_IMAGE_HEIGHT); - if (callback_start) - { - callback_start(data, width, height); - } - - pixels = malloc(sizeof(ILuint) * width * height); - ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA, IL_UNSIGNED_BYTE, pixels); - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - callback_pixel(data, x, y, colorFrom32BitRGBA(pixels[y * width + x])); - } - } - - free(pixels); - } - - error_count = 0; - while ((error=ilGetError()) != IL_NO_ERROR) - { - fprintf(stderr, "IL ERROR : %s\n", iluErrorString(error)); - error_count++; - } - return !error_count; -} - int systemGetFileSize(const char* path) { struct stat st; diff --git a/src/rendering/system.h b/src/rendering/system.h index 012997d..5bda037 100644 --- a/src/rendering/system.h +++ b/src/rendering/system.h @@ -3,7 +3,6 @@ /* Library dependent features */ -#include "tools/color.h" #include #ifdef __cplusplus @@ -11,16 +10,10 @@ extern "C" { #endif typedef void* (*ThreadFunction)(void* data); -typedef Color (*PictureCallbackSavePixel)(void* data, int x, int y); -typedef void (*PictureCallbackLoadStarted)(void* data, int width, int height); -typedef void (*PictureCallbackLoadPixel)(void* data, int x, int y, Color col); void systemInit(); int systemGetCoreCount(); -int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height); -int systemLoadPictureFile(const char* filepath, PictureCallbackLoadStarted callback_start, PictureCallbackLoadPixel callback_pixel, void* data); - int systemGetFileSize(const char* path); #ifdef HAVE_GLIB diff --git a/src/rendering/tools/color.h b/src/rendering/tools/color.h index fb10505..7541601 100644 --- a/src/rendering/tools/color.h +++ b/src/rendering/tools/color.h @@ -8,6 +8,7 @@ extern "C" { #endif +#define TYPEDEF_COLOR typedef struct { double r; diff --git a/src/rendering/tools/texture.c b/src/rendering/tools/texture.c index d36ea80..d6dee11 100644 --- a/src/rendering/tools/texture.c +++ b/src/rendering/tools/texture.c @@ -3,6 +3,7 @@ #include #include #include "../system.h" +#include "PictureFile.h" struct Texture2D { @@ -196,19 +197,6 @@ void texture2DSaveToFile(Texture2D* tex, const char* filepath) systemSavePictureFile(filepath, (PictureCallbackSavePixel)texture2DGetPixel, tex, tex->xsize, tex->ysize); } -static void _callbackTex2dLoad(Texture2D* tex, int x, int y, Color col) -{ - if (x >= 0 && x < tex->xsize && y >= 0 && y < tex->ysize) - { - tex->data[y * tex->xsize + x] = col; - } -} - -void texture2DLoadFromFile(Texture2D* tex, const char* filepath) -{ - systemLoadPictureFile(filepath, NULL, (PictureCallbackLoadPixel)_callbackTex2dLoad, tex); -} - @@ -403,22 +391,6 @@ void texture3DSaveToFile(Texture3D* tex, const char* filepath) systemSavePictureFile(filepath, (PictureCallbackSavePixel)_callbackTex3dSave, tex, tex->xsize, tex->ysize * tex->zsize); } -static void _callbackTex3dLoad(Texture3D* tex, int x, int y, Color col) -{ - int z = y / tex->ysize; - y = y % tex->ysize; - - if (x >= 0 && x < tex->xsize && y >= 0 && y < tex->ysize && z >= 0 && z < tex->zsize) - { - tex->data[z * tex->xsize * tex->ysize + y * tex->xsize + x] = col; - } -} - -void texture3DLoadFromFile(Texture3D* tex, const char* filepath) -{ - systemLoadPictureFile(filepath, NULL, (PictureCallbackLoadPixel)_callbackTex3dLoad, tex); -} - Texture4D* texture4DCreate(int xsize, int ysize, int zsize, int wsize) @@ -649,22 +621,3 @@ void texture4DSaveToFile(Texture4D* tex, const char* filepath) { systemSavePictureFile(filepath, (PictureCallbackSavePixel)_callbackTex4dSave, tex, tex->xsize * tex->wsize, tex->ysize * tex->zsize); } - -static void _callbackTex4dLoad(Texture4D* tex, int x, int y, Color col) -{ - int w = x / tex->xsize; - x = x % tex->xsize; - - int z = y / tex->ysize; - y = y % tex->ysize; - - if (x >= 0 && x < tex->xsize && y >= 0 && y < tex->ysize && z >= 0 && z < tex->zsize && w >= 0 && w < tex->wsize) - { - tex->data[w * tex->xsize * tex->ysize * tex->zsize + z * tex->xsize * tex->ysize + y * tex->xsize + x] = col; - } -} - -void texture4DLoadFromFile(Texture4D* tex, const char* filepath) -{ - systemLoadPictureFile(filepath, NULL, (PictureCallbackLoadPixel)_callbackTex4dLoad, tex); -} diff --git a/src/rendering/tools/texture.h b/src/rendering/tools/texture.h index ced5908..a9159ff 100644 --- a/src/rendering/tools/texture.h +++ b/src/rendering/tools/texture.h @@ -29,7 +29,6 @@ void texture2DAdd(Texture2D* source, Texture2D* destination); void texture2DSave(PackStream* stream, Texture2D* tex); void texture2DLoad(PackStream* stream, Texture2D* tex); void texture2DSaveToFile(Texture2D* tex, const char* filepath); -void texture2DLoadFromFile(Texture2D* tex, const char* filepath); Texture3D* texture3DCreate(int xsize, int ysize, int zsize); void texture3DDelete(Texture3D* tex); @@ -44,7 +43,6 @@ void texture3DAdd(Texture3D* source, Texture3D* destination); void texture3DSave(PackStream* stream, Texture3D* tex); void texture3DLoad(PackStream* stream, Texture3D* tex); void texture3DSaveToFile(Texture3D* tex, const char* filepath); -void texture3DLoadFromFile(Texture3D* tex, const char* filepath); Texture4D* texture4DCreate(int xsize, int ysize, int zsize, int wsize); void texture4DDelete(Texture4D* tex); @@ -59,7 +57,6 @@ void texture4DAdd(Texture4D* source, Texture4D* destination); void texture4DSave(PackStream* stream, Texture4D* tex); void texture4DLoad(PackStream* stream, Texture4D* tex); void texture4DSaveToFile(Texture4D* tex, const char* filepath); -void texture4DLoadFromFile(Texture4D* tex, const char* filepath); #ifdef __cplusplus } diff --git a/src/system/PictureFile.cpp b/src/system/PictureFile.cpp new file mode 100644 index 0000000..afcdb07 --- /dev/null +++ b/src/system/PictureFile.cpp @@ -0,0 +1,25 @@ +#include "PictureFile.h" + +#include +#include + +PictureFile::PictureFile() +{ +} + +int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height) +{ + QImage result(width, height, QImage::Format_ARGB32); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + Color pixel = callback_pixel(data, x, y); + QColor pixelconv = QColor::fromRgbF(pixel.r, pixel.g, pixel.b, pixel.a); + result.setPixel(x, height - 1 - y, pixelconv.rgba()); + } + } + + return result.save(filepath); +} diff --git a/src/system/PictureFile.h b/src/system/PictureFile.h new file mode 100644 index 0000000..727a0a4 --- /dev/null +++ b/src/system/PictureFile.h @@ -0,0 +1,43 @@ +#ifndef PICTUREFILE_H +#define PICTUREFILE_H + +#ifdef __cplusplus +#include "system_global.h" + +namespace paysages +{ +namespace system +{ + +class SYSTEMSHARED_EXPORT PictureFile +{ +public: + PictureFile(); +}; + +} +} + +extern "C" { +#endif + +// Transitional C-API + +#ifndef TYPEDEF_COLOR +typedef struct +{ + double r; + double g; + double b; + double a; +} Color; +#endif + +typedef Color (*PictureCallbackSavePixel)(void* data, int x, int y); +int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height); + +#ifdef __cplusplus +} +#endif + +#endif // PICTUREFILE_H diff --git a/src/system/system.pro b/src/system/system.pro new file mode 100644 index 0000000..6fb74de --- /dev/null +++ b/src/system/system.pro @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-10-20T11:38:08 +# +#------------------------------------------------- + +#QT -= gui + +TARGET = paysages_system +TEMPLATE = lib + +DEFINES += SYSTEM_LIBRARY + +SOURCES += \ + PictureFile.cpp + +HEADERS +=\ + system_global.h \ + PictureFile.h + +unix:!symbian { + maemo5 { + target.path = /opt/usr/lib + } else { + target.path = /usr/lib + } + INSTALLS += target +} diff --git a/src/system/system_global.h b/src/system/system_global.h new file mode 100644 index 0000000..5b4e693 --- /dev/null +++ b/src/system/system_global.h @@ -0,0 +1,21 @@ +#ifndef SYSTEM_GLOBAL_H +#define SYSTEM_GLOBAL_H + +#include + +#if defined(SYSTEM_LIBRARY) +# define SYSTEMSHARED_EXPORT Q_DECL_EXPORT +#else +# define SYSTEMSHARED_EXPORT Q_DECL_IMPORT +#endif + +#ifdef __cplusplus +namespace paysages +{ + namespace system {} +} + +using namespace paysages::system; +#endif + +#endif // SYSTEM_GLOBAL_H diff --git a/src/testing/testing.pro b/src/testing/testing.pro index abfcd72..d7820a2 100644 --- a/src/testing/testing.pro +++ b/src/testing/testing.pro @@ -1,7 +1,6 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -CONFIG -= qt TARGET = paysages-tests @@ -32,3 +31,9 @@ SOURCES += main.c \ HEADERS += \ common.h + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system +else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system +INCLUDEPATH += $$PWD/../system +DEPENDPATH += $$PWD/../system