parent
f3ff4e9ffe
commit
6357a06396
|
@ -613,6 +613,8 @@ if test "x$have_png" = "xyes"; then
|
|||
png_libs="-lpng -lz -lm"
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_LOADER_PNG, test x$have_png = xyes)
|
||||
|
||||
#######################################
|
||||
## JPEG
|
||||
have_jpeg="no";
|
||||
|
@ -646,6 +648,8 @@ if test "x$have_jpeg" = "xyes"; then
|
|||
jpeg_libs="-ljpeg"
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_LOADER_JPEG, test x$have_jpeg = xyes)
|
||||
|
||||
#######################################
|
||||
## EET
|
||||
AC_ARG_WITH(eet-config, [ --with-eet-config=EET_CONFIG use eet-config specified ],
|
||||
|
@ -712,6 +716,8 @@ else
|
|||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_LOADER_EET, test x$have_eet = xyes)
|
||||
|
||||
#######################################
|
||||
## EDB
|
||||
AC_ARG_WITH(edb-config, [ --with-edb-config=EDB_CONFIG use edb-config specified ],
|
||||
|
@ -760,6 +766,8 @@ else
|
|||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_LOADER_EDB, test x$have_edb = xyes)
|
||||
|
||||
#####################################################################
|
||||
## Cpu based optimizations
|
||||
|
||||
|
@ -1642,6 +1650,11 @@ src/modules/engines/gl_x11/Makefile
|
|||
src/modules/engines/cairo_common/Makefile
|
||||
src/modules/engines/cairo_x11/Makefile
|
||||
src/modules/engines/xrender_x11/Makefile
|
||||
src/modules/loaders/Makefile
|
||||
src/modules/loaders/edb/Makefile
|
||||
src/modules/loaders/eet/Makefile
|
||||
src/modules/loaders/jpeg/Makefile
|
||||
src/modules/loaders/png/Makefile
|
||||
src/lib/include/Makefile
|
||||
proj/Makefile
|
||||
proj/win32_gdi/Makefile
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
typedef enum _Evas_Module_Type
|
||||
{
|
||||
EVAS_MODULE_TYPE_ENGINE,
|
||||
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
||||
EVAS_MODULE_TYPE_OBJECT
|
||||
} Evas_Module_Type;
|
||||
|
||||
|
@ -86,6 +87,12 @@ struct _Evas_Module_Engine
|
|||
int id;
|
||||
};
|
||||
|
||||
typedef struct _Evas_Module_Image_Loader Evas_Module_Image_Loader;
|
||||
struct _Evas_Module_Image_Loader
|
||||
{
|
||||
int id;
|
||||
};
|
||||
|
||||
/* end of evas module api */
|
||||
/**************************/
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,8 +10,8 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#include <dirent.h> // DIR, dirent
|
||||
#include <dlfcn.h> // dlopen,dlclose,etc
|
||||
#include <dirent.h> /* DIR, dirent */
|
||||
#include <dlfcn.h> /* dlopen,dlclose,etc */
|
||||
|
||||
#include <evas_common.h>
|
||||
#include <evas_private.h>
|
||||
|
@ -110,6 +110,7 @@ evas_module_paths_init(void)
|
|||
/* do this on a separate function */
|
||||
/* 1. engines */
|
||||
_evas_module_path_append(EVAS_MODULE_TYPE_ENGINE, paths->data, "engines");
|
||||
_evas_module_path_append(EVAS_MODULE_TYPE_IMAGE_LOADER, paths->data, "loaders");
|
||||
_evas_module_path_append(EVAS_MODULE_TYPE_OBJECT, paths->data, "objects");
|
||||
free(paths->data);
|
||||
paths = evas_list_remove_list(paths, paths);
|
||||
|
@ -122,9 +123,10 @@ void
|
|||
evas_module_init(void)
|
||||
{
|
||||
Evas_List *l;
|
||||
int new_id = 1;
|
||||
int new_id_engine = 1;
|
||||
int new_id_loader = 1;
|
||||
|
||||
// printf("[init modules]\n");
|
||||
/* printf("[init modules]\n"); */
|
||||
evas_module_paths_init();
|
||||
for (l = evas_module_paths; l; l = l->next)
|
||||
{
|
||||
|
@ -135,7 +137,7 @@ evas_module_init(void)
|
|||
mp = l->data;
|
||||
|
||||
if (!(dir = opendir(mp->path))) break;
|
||||
// printf("[evas module] searching modules on %s\n", mp->path);
|
||||
/* printf("[evas module] searching modules on %s\n", mp->path); */
|
||||
while ((de = readdir(dir)))
|
||||
{
|
||||
char *buf;
|
||||
|
@ -162,12 +164,24 @@ evas_module_init(void)
|
|||
eme = malloc(sizeof(Evas_Module_Engine));
|
||||
if (eme)
|
||||
{
|
||||
eme->id = new_id;
|
||||
eme->id = new_id_engine;
|
||||
em->data = eme;
|
||||
new_id++;
|
||||
new_id_engine++;
|
||||
}
|
||||
}
|
||||
// printf("[evas module] including module path %s/%s of type %d\n",em->path, em->name, em->type);
|
||||
else if (em->type == EVAS_MODULE_TYPE_IMAGE_LOADER)
|
||||
{
|
||||
Evas_Module_Image_Loader *emil;
|
||||
|
||||
emil = malloc(sizeof(Evas_Module_Image_Loader));
|
||||
if (emil)
|
||||
{
|
||||
emil->id = new_id_loader;
|
||||
em->data = emil;
|
||||
new_id_loader++;
|
||||
}
|
||||
}
|
||||
/* printf("[evas module] including module path %s/%s of type %d\n",em->path, em->name, em->type); */
|
||||
evas_modules = evas_list_append(evas_modules, em);
|
||||
}
|
||||
free(buf);
|
||||
|
|
|
@ -19,6 +19,7 @@ typedef struct _Evas_Font_Alias Evas_Font_Alias;
|
|||
typedef struct _Evas_Data_Node Evas_Data_Node;
|
||||
typedef struct _Evas_Func_Node Evas_Func_Node;
|
||||
typedef struct _Evas_Func Evas_Func;
|
||||
typedef struct _Evas_Image_Load_Func Evas_Image_Load_Func;
|
||||
typedef struct _Evas_Object_Func Evas_Object_Func;
|
||||
typedef struct _Evas_Intercept_Func Evas_Intercept_Func;
|
||||
typedef struct _Evas_Intercept_Func_Basic Evas_Intercept_Func_Basic;
|
||||
|
@ -524,9 +525,17 @@ struct _Evas_Func
|
|||
void (*font_cache_set) (void *data, int bytes);
|
||||
int (*font_cache_get) (void *data);
|
||||
|
||||
/* void (*image_rotation_set) (void *data, void *image); */
|
||||
|
||||
/* Engine functions will over time expand from here */
|
||||
};
|
||||
|
||||
struct _Evas_Image_Load_Func
|
||||
{
|
||||
int (*file_head) (RGBA_Image *im, const char *file, const char *key);
|
||||
int (*file_data) (RGBA_Image *im, const char *file, const char *key);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = engines
|
||||
SUBDIRS = engines loaders
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
if BUILD_LOADER_EDB
|
||||
edb_subdir = edb
|
||||
endif
|
||||
|
||||
if BUILD_LOADER_EET
|
||||
eet_subdir = eet
|
||||
endif
|
||||
|
||||
if BUILD_LOADER_JPEG
|
||||
jpeg_subdir = jpeg
|
||||
endif
|
||||
|
||||
if BUILD_LOADER_PNG
|
||||
png_subdir = png
|
||||
endif
|
||||
|
||||
SUBDIRS = $(edb_subdir) $(eet_subdir) $(jpeg_subdir) $(png_subdir)
|
|
@ -0,0 +1,24 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.4 foreign
|
||||
|
||||
# A list of all the files in the current directory which can be regenerated
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
INCLUDES = -I. \
|
||||
-I$(top_srcdir)/src/lib \
|
||||
-I$(top_srcdir)/src/lib/include \
|
||||
@FREETYPE_CFLAGS@ @edb_cflags@
|
||||
|
||||
pkgdir = $(libdir)/evas/modules/loaders/edb/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_load_edb.c
|
||||
|
||||
module_la_LIBADD =
|
||||
module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs
|
||||
|
||||
module_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||
|
||||
EXTRA_DIST = evas_image_load_edb.c
|
|
@ -0,0 +1,214 @@
|
|||
#include <Edb.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
#define SWAP32(x) (x) = ((((x) & 0x000000ff ) << 24) | (((x) & 0x0000ff00 ) << 8) | (((x) & 0x00ff0000 ) >> 8) | (((x) & 0xff000000 ) >> 24))
|
||||
|
||||
|
||||
int evas_image_load_file_head_edb(RGBA_Image *im, const char *file, const char *key);
|
||||
int evas_image_load_file_data_edb(RGBA_Image *im, const char *file, const char *key);
|
||||
|
||||
Evas_Image_Load_Func evas_image_load_edb_func =
|
||||
{
|
||||
evas_image_load_file_head_edb,
|
||||
evas_image_load_file_data_edb
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
evas_image_load_file_head_edb(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
int w, h, alpha, compression, size;
|
||||
E_DB_File *db;
|
||||
DATA32 *ret;
|
||||
DATA32 header[8];
|
||||
|
||||
if ((!file) || (!key)) return 0;
|
||||
db = e_db_open_read((char *)file);
|
||||
if (!db) return 0;
|
||||
ret = e_db_data_get(db, (char *)key, &size);
|
||||
if (!ret)
|
||||
{
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
if (size < 32)
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
memcpy(header, ret, 32);
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) SWAP32(header[i]);
|
||||
}
|
||||
#endif
|
||||
if (header[0] != 0xac1dfeed)
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
w = header[1];
|
||||
h = header[2];
|
||||
alpha = header[3];
|
||||
compression = header[4];
|
||||
if ((w > 8192) || (h > 8192))
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
if ((compression == 0) && (size < ((w * h * 4) + 32)))
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA;
|
||||
if (!im->image)
|
||||
im->image = evas_common_image_surface_new(im);
|
||||
if (!im->image)
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
im->image->w = w;
|
||||
im->image->h = h;
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
evas_image_load_file_data_edb(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
int w, h, alpha, compression, size;
|
||||
E_DB_File *db;
|
||||
DATA32 *ret;
|
||||
DATA32 *body;
|
||||
DATA32 header[8];
|
||||
|
||||
if ((!file) || (!key)) return 0;
|
||||
db = e_db_open_read((char *)file);
|
||||
if (!db) return 0;
|
||||
ret = e_db_data_get(db, (char *)key, &size);
|
||||
if (!ret)
|
||||
{
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
if (size < 32)
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
memcpy(header, ret, 32);
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) SWAP32(header[i]);
|
||||
}
|
||||
#endif
|
||||
if (header[0] != 0xac1dfeed)
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
w = header[1];
|
||||
h = header[2];
|
||||
alpha = header[3];
|
||||
compression = header[4];
|
||||
if ((w > 8192) || (h > 8192))
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
if ((compression == 0) && (size < ((w * h * 4) + 32)))
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA;
|
||||
if (!im->image)
|
||||
im->image = evas_common_image_surface_new(im);
|
||||
if (!im->image)
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
im->image->w = w;
|
||||
im->image->h = h;
|
||||
body = &(ret[8]);
|
||||
evas_common_image_surface_alloc(im->image);
|
||||
if (!im->image->data)
|
||||
{
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 0;
|
||||
}
|
||||
if (!compression)
|
||||
{
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
{
|
||||
int x;
|
||||
|
||||
memcpy(im->image->data, body, w * h * sizeof(DATA32));
|
||||
for (x = 0; x < (w * h); x++) SWAP32(im->image->data[x]);
|
||||
}
|
||||
#else
|
||||
memcpy(im->image->data, body, w * h * sizeof(DATA32));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
uLongf dlen;
|
||||
|
||||
dlen = w * h * sizeof(DATA32);
|
||||
uncompress((Bytef *)im->image->data, &dlen, (Bytef *)body,
|
||||
(uLongf)(size - 32));
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
{
|
||||
int x;
|
||||
|
||||
for (x = 0; x < (w * h); x++) SWAP32(im->image->data[x]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
free(ret);
|
||||
e_db_close(db);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_load_edb_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
||||
"edb",
|
||||
"none"
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.4 foreign
|
||||
|
||||
# A list of all the files in the current directory which can be regenerated
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
INCLUDES = -I. \
|
||||
-I$(top_srcdir)/src/lib \
|
||||
-I$(top_srcdir)/src/lib/include \
|
||||
@FREETYPE_CFLAGS@ @eet_cflags@
|
||||
|
||||
pkgdir = $(libdir)/evas/modules/loaders/eet/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_load_eet.c
|
||||
|
||||
module_la_LIBADD =
|
||||
module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs
|
||||
|
||||
module_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||
|
||||
EXTRA_DIST = evas_image_load_eet.c
|
|
@ -0,0 +1,114 @@
|
|||
#include <Eet.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
int evas_image_load_file_head_eet(RGBA_Image *im, const char *file, const char *key);
|
||||
int evas_image_load_file_data_eet(RGBA_Image *im, const char *file, const char *key);
|
||||
|
||||
Evas_Image_Load_Func evas_image_load_eet_func =
|
||||
{
|
||||
evas_image_load_file_head_eet,
|
||||
evas_image_load_file_data_eet
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
evas_image_load_file_head_eet(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
int alpha, compression, quality, lossy;
|
||||
unsigned int w, h;
|
||||
Eet_File *ef;
|
||||
int ok;
|
||||
|
||||
if ((!file) || (!key)) return 0;
|
||||
ef = eet_open((char *)file, EET_FILE_MODE_READ);
|
||||
if (!ef) return 0;
|
||||
ok = eet_data_image_header_read(ef, (char *)key,
|
||||
&w, &h, &alpha, &compression, &quality, &lossy);
|
||||
if (!ok)
|
||||
{
|
||||
eet_close(ef);
|
||||
return 0;
|
||||
}
|
||||
if ((w > 8192) || (h > 8192))
|
||||
{
|
||||
eet_close(ef);
|
||||
return 0;
|
||||
}
|
||||
if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA;
|
||||
if (!im->image)
|
||||
im->image = evas_common_image_surface_new(im);
|
||||
if (!im->image)
|
||||
{
|
||||
eet_close(ef);
|
||||
return 0;
|
||||
}
|
||||
im->image->w = w;
|
||||
im->image->h = h;
|
||||
eet_close(ef);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
evas_image_load_file_data_eet(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
unsigned int w, h;
|
||||
int alpha, compression, quality, lossy;
|
||||
Eet_File *ef;
|
||||
DATA32 *body;
|
||||
|
||||
if ((!file) || (!key)) return 0;
|
||||
if ((im->image) && (im->image->data)) return 1;
|
||||
ef = eet_open((char *)file, EET_FILE_MODE_READ);
|
||||
if (!ef) return 0;
|
||||
body = eet_data_image_read(ef, (char *)key,
|
||||
&w, &h, &alpha, &compression, &quality, &lossy);
|
||||
if (!body)
|
||||
{
|
||||
eet_close(ef);
|
||||
return 0;
|
||||
}
|
||||
if ((w > 8192) || (h > 8192))
|
||||
{
|
||||
free(body);
|
||||
eet_close(ef);
|
||||
return 0;
|
||||
}
|
||||
if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA;
|
||||
if (!im->image)
|
||||
im->image = evas_common_image_surface_new(im);
|
||||
if (!im->image)
|
||||
{
|
||||
free(body);
|
||||
eet_close(ef);
|
||||
return 0;
|
||||
}
|
||||
im->image->w = w;
|
||||
im->image->h = h;
|
||||
im->image->data = body;
|
||||
im->image->no_free = 0;
|
||||
eet_close(ef);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_load_eet_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
||||
"eet",
|
||||
"none"
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.4 foreign
|
||||
|
||||
# A list of all the files in the current directory which can be regenerated
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
INCLUDES = -I. \
|
||||
-I$(top_srcdir)/src/lib \
|
||||
-I$(top_srcdir)/src/lib/include \
|
||||
@FREETYPE_CFLAGS@
|
||||
|
||||
pkgdir = $(libdir)/evas/modules/loaders/jpeg/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_load_jpeg.c
|
||||
|
||||
module_la_LIBADD =
|
||||
module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs
|
||||
|
||||
module_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||
|
||||
EXTRA_DIST = evas_image_load_jpeg.c
|
|
@ -0,0 +1,355 @@
|
|||
#include <stdio.h>
|
||||
#include <jpeglib.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
typedef struct _JPEG_error_mgr *emptr;
|
||||
struct _JPEG_error_mgr
|
||||
{
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmp_buffer;
|
||||
};
|
||||
|
||||
static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
|
||||
static void _JPEGErrorHandler(j_common_ptr cinfo);
|
||||
static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level);
|
||||
|
||||
static int evas_image_load_file_head_jpeg_internal(RGBA_Image *im, FILE *f);
|
||||
static int evas_image_load_file_data_jpeg_internal(RGBA_Image *im, FILE *f);
|
||||
#if 0 /* not used at the moment */
|
||||
static int evas_image_load_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f);
|
||||
#endif
|
||||
|
||||
int evas_image_load_file_head_jpeg(RGBA_Image *im, const char *file, const char *key);
|
||||
int evas_image_load_file_data_jpeg(RGBA_Image *im, const char *file, const char *key);
|
||||
|
||||
Evas_Image_Load_Func evas_image_load_jpeg_func =
|
||||
{
|
||||
evas_image_load_file_head_jpeg,
|
||||
evas_image_load_file_data_jpeg
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
_JPEGFatalErrorHandler(j_common_ptr cinfo)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
/* cinfo->err->output_message(cinfo);*/
|
||||
longjmp(errmgr->setjmp_buffer, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_JPEGErrorHandler(j_common_ptr cinfo)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
/* cinfo->err->output_message(cinfo);*/
|
||||
/* longjmp(errmgr->setjmp_buffer, 1);*/
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
/* cinfo->err->output_message(cinfo);*/
|
||||
/* longjmp(errmgr->setjmp_buffer, 1);*/
|
||||
return;
|
||||
msg_level = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
evas_image_load_file_head_jpeg_internal(RGBA_Image *im, FILE *f)
|
||||
{
|
||||
int w, h;
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct _JPEG_error_mgr jerr;
|
||||
|
||||
if (!f) return 0;
|
||||
cinfo.err = jpeg_std_error(&(jerr.pub));
|
||||
jerr.pub.error_exit = _JPEGFatalErrorHandler;
|
||||
jerr.pub.emit_message = _JPEGErrorHandler2;
|
||||
jerr.pub.output_message = _JPEGErrorHandler;
|
||||
if (setjmp(jerr.setjmp_buffer))
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, f);
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
cinfo.do_fancy_upsampling = FALSE;
|
||||
cinfo.do_block_smoothing = FALSE;
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
/* head decoding */
|
||||
if (!im->image)
|
||||
im->image = evas_common_image_surface_new(im);
|
||||
if (!im->image)
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
im->image->w = w = cinfo.output_width;
|
||||
im->image->h = h = cinfo.output_height;
|
||||
/* end head decoding */
|
||||
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
evas_image_load_file_data_jpeg_internal(RGBA_Image *im, FILE *f)
|
||||
{
|
||||
int w, h;
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct _JPEG_error_mgr jerr;
|
||||
DATA8 *ptr, *line[16], *data;
|
||||
DATA32 *ptr2;
|
||||
int x, y, l, i, scans, count, prevy;
|
||||
|
||||
if (!f) return 0;
|
||||
cinfo.err = jpeg_std_error(&(jerr.pub));
|
||||
jerr.pub.error_exit = _JPEGFatalErrorHandler;
|
||||
jerr.pub.emit_message = _JPEGErrorHandler2;
|
||||
jerr.pub.output_message = _JPEGErrorHandler;
|
||||
if (setjmp(jerr.setjmp_buffer))
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, f);
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
cinfo.do_fancy_upsampling = FALSE;
|
||||
cinfo.do_block_smoothing = FALSE;
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
/* head decoding */
|
||||
im->image->w = w = cinfo.output_width;
|
||||
im->image->h = h = cinfo.output_height;
|
||||
/* end head decoding */
|
||||
/* data decoding */
|
||||
if (cinfo.rec_outbuf_height > 16)
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
data = alloca(w * 16 * 3);
|
||||
evas_common_image_surface_alloc(im->image);
|
||||
if (!im->image->data)
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
ptr2 = im->image->data;
|
||||
count = 0;
|
||||
prevy = 0;
|
||||
if (cinfo.output_components == 3)
|
||||
{
|
||||
for (i = 0; i < cinfo.rec_outbuf_height; i++)
|
||||
line[i] = data + (i * w * 3);
|
||||
for (l = 0; l < h; l += cinfo.rec_outbuf_height)
|
||||
{
|
||||
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
|
||||
scans = cinfo.rec_outbuf_height;
|
||||
if ((h - l) < scans) scans = h - l;
|
||||
ptr = data;
|
||||
for (y = 0; y < scans; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
*ptr2 =
|
||||
(0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]);
|
||||
ptr += 3;
|
||||
ptr2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cinfo.output_components == 1)
|
||||
{
|
||||
for (i = 0; i < cinfo.rec_outbuf_height; i++)
|
||||
line[i] = data + (i * w);
|
||||
for (l = 0; l < h; l += cinfo.rec_outbuf_height)
|
||||
{
|
||||
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
|
||||
scans = cinfo.rec_outbuf_height;
|
||||
if ((h - l) < scans) scans = h - l;
|
||||
ptr = data;
|
||||
for (y = 0; y < scans; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
*ptr2 =
|
||||
(0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]);
|
||||
ptr++;
|
||||
ptr2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* end data decoding */
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0 /* not used at the moment */
|
||||
static int
|
||||
evas_image_load_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f)
|
||||
{
|
||||
int w, h;
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct _JPEG_error_mgr jerr;
|
||||
DATA8 *ptr, *line[16], *data;
|
||||
DATA32 *ptr2;
|
||||
int x, y, l, i, scans, count, prevy;
|
||||
|
||||
if (!f) return 0;
|
||||
cinfo.err = jpeg_std_error(&(jerr.pub));
|
||||
jerr.pub.error_exit = _JPEGFatalErrorHandler;
|
||||
jerr.pub.emit_message = _JPEGErrorHandler2;
|
||||
jerr.pub.output_message = _JPEGErrorHandler;
|
||||
if (setjmp(jerr.setjmp_buffer))
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, f);
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
cinfo.do_fancy_upsampling = FALSE;
|
||||
cinfo.do_block_smoothing = FALSE;
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
/* head decoding */
|
||||
im->image->w = w = cinfo.output_width;
|
||||
im->image->h = h = cinfo.output_height;
|
||||
/* end head decoding */
|
||||
/* data decoding */
|
||||
if (cinfo.rec_outbuf_height > 16)
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
data = alloca(w * 16 * 3);
|
||||
if (!im->image->data)
|
||||
{
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 0;
|
||||
}
|
||||
ptr2 = im->image->data;
|
||||
count = 0;
|
||||
prevy = 0;
|
||||
if (cinfo.output_components == 3)
|
||||
{
|
||||
for (i = 0; i < cinfo.rec_outbuf_height; i++)
|
||||
line[i] = data + (i * w * 3);
|
||||
for (l = 0; l < h; l += cinfo.rec_outbuf_height)
|
||||
{
|
||||
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
|
||||
scans = cinfo.rec_outbuf_height;
|
||||
if ((h - l) < scans) scans = h - l;
|
||||
ptr = data;
|
||||
for (y = 0; y < scans; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
*ptr2 =
|
||||
((*ptr2) & 0x00ffffff) |
|
||||
(((ptr[0] + ptr[1] + ptr[2]) / 3) << 24);
|
||||
ptr += 3;
|
||||
ptr2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cinfo.output_components == 1)
|
||||
{
|
||||
for (i = 0; i < cinfo.rec_outbuf_height; i++)
|
||||
line[i] = data + (i * w);
|
||||
for (l = 0; l < h; l += cinfo.rec_outbuf_height)
|
||||
{
|
||||
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
|
||||
scans = cinfo.rec_outbuf_height;
|
||||
if ((h - l) < scans) scans = h - l;
|
||||
ptr = data;
|
||||
for (y = 0; y < scans; y++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
*ptr2 =
|
||||
((*ptr2) & 0x00ffffff) |
|
||||
((ptr[0]) << 24);
|
||||
ptr++;
|
||||
ptr2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* end data decoding */
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
evas_image_load_file_head_jpeg(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
int val;
|
||||
FILE *f;
|
||||
|
||||
if ((!file)) return 0;
|
||||
f = fopen(file, "rb");
|
||||
if (!f) return 0;
|
||||
val = evas_image_load_file_head_jpeg_internal(im, f);
|
||||
fclose(f);
|
||||
return val;
|
||||
key = 0;
|
||||
}
|
||||
|
||||
int
|
||||
evas_image_load_file_data_jpeg(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
int val;
|
||||
FILE *f;
|
||||
|
||||
if ((!file)) return 0;
|
||||
f = fopen(file, "rb");
|
||||
if (!f) return 0;
|
||||
val = evas_image_load_file_data_jpeg_internal(im, f);
|
||||
fclose(f);
|
||||
return val;
|
||||
key = 0;
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_load_jpeg_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
||||
"jpeg",
|
||||
"none"
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AUTOMAKE_OPTIONS = 1.4 foreign
|
||||
|
||||
# A list of all the files in the current directory which can be regenerated
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
INCLUDES = -I. \
|
||||
-I$(top_srcdir)/src/lib \
|
||||
-I$(top_srcdir)/src/lib/include \
|
||||
@FREETYPE_CFLAGS@ @png_cflags@
|
||||
|
||||
pkgdir = $(libdir)/evas/modules/loaders/png/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_load_png.c
|
||||
|
||||
module_la_LIBADD =
|
||||
module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs
|
||||
|
||||
module_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||
|
||||
EXTRA_DIST = evas_image_load_png.c
|
|
@ -0,0 +1,223 @@
|
|||
#include <png.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
#define PNG_BYTES_TO_CHECK 4
|
||||
|
||||
|
||||
int evas_image_load_file_head_png(RGBA_Image *im, const char *file, const char *key);
|
||||
int evas_image_load_file_data_png(RGBA_Image *im, const char *file, const char *key);
|
||||
|
||||
Evas_Image_Load_Func evas_image_load_png_func =
|
||||
{
|
||||
evas_image_load_file_head_png,
|
||||
evas_image_load_file_data_png
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
evas_image_load_file_head_png(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
png_uint_32 w32, h32;
|
||||
FILE *f;
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
int bit_depth, color_type, interlace_type;
|
||||
unsigned char buf[PNG_BYTES_TO_CHECK];
|
||||
char hasa, hasg;
|
||||
|
||||
if ((!file)) return 0;
|
||||
hasa = 0;
|
||||
hasg = 0;
|
||||
f = fopen(file, "rb");
|
||||
if (!f) return 0;
|
||||
|
||||
/* if we havent read the header before, set the header data */
|
||||
fread(buf, 1, PNG_BYTES_TO_CHECK, f);
|
||||
if (!png_check_sig(buf, PNG_BYTES_TO_CHECK))
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
rewind(f);
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
png_init_io(png_ptr, f);
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32),
|
||||
(png_uint_32 *) (&h32), &bit_depth, &color_type,
|
||||
&interlace_type, NULL, NULL);
|
||||
if (!im->image)
|
||||
im->image = evas_common_image_surface_new(im);
|
||||
if (!im->image)
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
im->image->w = (int) w32;
|
||||
im->image->h = (int) h32;
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
png_set_expand(png_ptr);
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1;
|
||||
}
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1;
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
hasa = 1;
|
||||
hasg = 1;
|
||||
}
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) hasg = 1;
|
||||
if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA;
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
|
||||
fclose(f);
|
||||
return 1;
|
||||
key = 0;
|
||||
}
|
||||
|
||||
int
|
||||
evas_image_load_file_data_png(RGBA_Image *im, const char *file, const char *key)
|
||||
{
|
||||
png_uint_32 w32, h32;
|
||||
int w, h;
|
||||
FILE *f;
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
int bit_depth, color_type, interlace_type;
|
||||
unsigned char buf[PNG_BYTES_TO_CHECK];
|
||||
unsigned char **lines;
|
||||
char hasa, hasg;
|
||||
int i;
|
||||
|
||||
if ((!file)) return 0;
|
||||
hasa = 0;
|
||||
hasg = 0;
|
||||
f = fopen(file, "rb");
|
||||
if (!f) return 0;
|
||||
|
||||
/* if we havent read the header before, set the header data */
|
||||
fread(buf, 1, PNG_BYTES_TO_CHECK, f);
|
||||
if (!png_check_sig(buf, PNG_BYTES_TO_CHECK))
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
rewind(f);
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
png_init_io(png_ptr, f);
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32),
|
||||
(png_uint_32 *) (&h32), &bit_depth, &color_type,
|
||||
&interlace_type, NULL, NULL);
|
||||
im->image->w = (int) w32;
|
||||
im->image->h = (int) h32;
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr);
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1;
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
hasa = 1;
|
||||
hasg = 1;
|
||||
}
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) hasg = 1;
|
||||
if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA;
|
||||
|
||||
w = im->image->w;
|
||||
h = im->image->h;
|
||||
if (hasa) png_set_expand(png_ptr);
|
||||
/* we want ARGB */
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
png_set_swap_alpha(png_ptr);
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
|
||||
#else
|
||||
png_set_bgr(png_ptr);
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
#endif
|
||||
/* 16bit color -> 8bit color */
|
||||
png_set_strip_16(png_ptr);
|
||||
/* pack all pixels to byte boundaires */
|
||||
png_set_packing(png_ptr);
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_expand(png_ptr);
|
||||
evas_common_image_surface_alloc(im->image);
|
||||
if (!im->image->data)
|
||||
{
|
||||
evas_common_image_surface_free(im->image);
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
lines = (unsigned char **) alloca(h * sizeof(unsigned char *));
|
||||
|
||||
if (hasg)
|
||||
{
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
if (png_get_bit_depth(png_ptr, info_ptr) < 8)
|
||||
png_set_gray_1_2_4_to_8(png_ptr);
|
||||
}
|
||||
for (i = 0; i < h; i++)
|
||||
lines[i] = ((unsigned char *)(im->image->data)) + (i * w * sizeof(DATA32));
|
||||
png_read_image(png_ptr, lines);
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
|
||||
fclose(f);
|
||||
return 1;
|
||||
key = 0;
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_load_png_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
||||
"png",
|
||||
"none"
|
||||
};
|
Loading…
Reference in New Issue