Removed dependency to OpenIL/libDevIL

This commit is contained in:
Michaël Lemaire 2013-10-20 14:34:55 +02:00
parent 5032f1b2aa
commit b896832e76
16 changed files with 160 additions and 153 deletions

1
.gitignore vendored
View file

@ -17,3 +17,4 @@ ui_*.h
/debian/files
/debian/*.substvars
/debian/paysages3d
/*.trace

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -7,6 +7,7 @@
#include "renderer.h"
#include "camera.h"
#include "system.h"
#include "PictureFile.h"
typedef struct
{

View file

@ -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

View file

@ -4,9 +4,6 @@
#include <stdlib.h>
#include <sys/stat.h>
#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;

View file

@ -3,7 +3,6 @@
/* Library dependent features */
#include "tools/color.h"
#include <stdlib.h>
#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

View file

@ -8,6 +8,7 @@
extern "C" {
#endif
#define TYPEDEF_COLOR
typedef struct
{
double r;

View file

@ -3,6 +3,7 @@
#include <assert.h>
#include <math.h>
#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);
}

View file

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

View file

@ -0,0 +1,25 @@
#include "PictureFile.h"
#include <QImage>
#include <QColor>
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);
}

43
src/system/PictureFile.h Normal file
View file

@ -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

28
src/system/system.pro Normal file
View file

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

View file

@ -0,0 +1,21 @@
#ifndef SYSTEM_GLOBAL_H
#define SYSTEM_GLOBAL_H
#include <QtCore/qglobal.h>
#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

View file

@ -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