parent
8119a84cca
commit
4a56b2ee6e
|
@ -1655,6 +1655,11 @@ src/modules/loaders/edb/Makefile
|
|||
src/modules/loaders/eet/Makefile
|
||||
src/modules/loaders/jpeg/Makefile
|
||||
src/modules/loaders/png/Makefile
|
||||
src/modules/savers/Makefile
|
||||
src/modules/savers/edb/Makefile
|
||||
src/modules/savers/eet/Makefile
|
||||
src/modules/savers/jpeg/Makefile
|
||||
src/modules/savers/png/Makefile
|
||||
src/lib/include/Makefile
|
||||
proj/Makefile
|
||||
proj/win32_gdi/Makefile
|
||||
|
|
|
@ -1,300 +1,50 @@
|
|||
#include "config.h"
|
||||
#include "evas_options.h"
|
||||
|
||||
#define SWAP32(x) (x) = ((((x) & 0x000000ff ) << 24) | (((x) & 0x0000ff00 ) << 8) | (((x) & 0x00ff0000 ) >> 8) | (((x) & 0xff000000 ) >> 24))
|
||||
|
||||
#ifdef BUILD_LOADER_PNG
|
||||
#include <png.h>
|
||||
#include <setjmp.h>
|
||||
#define PNG_BYTES_TO_CHECK 4
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_JPEG
|
||||
#include <stdio.h>
|
||||
#include <jpeglib.h>
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_EET
|
||||
#include <Eet.h>
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_EDB
|
||||
#include <Edb.h>
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_TEMPLATE
|
||||
#include <Template.h>
|
||||
#endif
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
#ifdef BUILD_LOADER_PNG
|
||||
static int
|
||||
save_image_png(RGBA_Image *im, const char *file, int compress, int interlace)
|
||||
{
|
||||
FILE *f;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
DATA32 *ptr;
|
||||
int x, y, j;
|
||||
png_bytep row_ptr, data = NULL;
|
||||
png_color_8 sig_bit;
|
||||
int quality = 75, compression = 3, num_passes = 1, pass;
|
||||
|
||||
f = fopen(file, "wb");
|
||||
if (!f) return 0;
|
||||
|
||||
png_ptr = png_create_write_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 == NULL)
|
||||
{
|
||||
fclose(f);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
return 0;
|
||||
}
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
fclose(f);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
|
||||
png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (interlace)
|
||||
{
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
png_ptr->interlaced = PNG_INTERLACE_ADAM7;
|
||||
num_passes = png_set_interlace_handling(png_ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, f);
|
||||
|
||||
if (im->flags & RGBA_IMAGE_HAS_ALPHA)
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
|
||||
PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
png_set_swap_alpha(png_ptr);
|
||||
#else
|
||||
png_set_bgr(png_ptr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
|
||||
PNG_COLOR_TYPE_RGB, png_ptr->interlaced,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
data = alloca(im->image->w * 3 * sizeof(char));
|
||||
}
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
sig_bit.blue = 8;
|
||||
sig_bit.alpha = 8;
|
||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
|
||||
png_set_compression_level(png_ptr, compress);
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
png_set_shift(png_ptr, &sig_bit);
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
for (pass = 0; pass < num_passes; pass++)
|
||||
{
|
||||
ptr = im->image->data;
|
||||
|
||||
for (y = 0; y < im->image->h; y++)
|
||||
{
|
||||
if (im->flags & RGBA_IMAGE_HAS_ALPHA)
|
||||
row_ptr = (png_bytep) ptr;
|
||||
else
|
||||
{
|
||||
for (j = 0, x = 0; x < im->image->w; x++)
|
||||
{
|
||||
data[j++] = (ptr[x] >> 16) & 0xff;
|
||||
data[j++] = (ptr[x] >> 8) & 0xff;
|
||||
data[j++] = (ptr[x]) & 0xff;
|
||||
}
|
||||
row_ptr = (png_bytep) data;
|
||||
}
|
||||
png_write_rows(png_ptr, &row_ptr, 1);
|
||||
ptr += im->image->w;
|
||||
}
|
||||
}
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
|
||||
png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
|
||||
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_JPEG
|
||||
struct _JPEG_error_mgr
|
||||
{
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmp_buffer;
|
||||
};
|
||||
typedef struct _JPEG_error_mgr *emptr;
|
||||
|
||||
static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
|
||||
static void
|
||||
_JPEGFatalErrorHandler(j_common_ptr cinfo)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
longjmp(errmgr->setjmp_buffer, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
static void _JPEGErrorHandler(j_common_ptr cinfo);
|
||||
static void
|
||||
_JPEGErrorHandler(j_common_ptr cinfo)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
return;
|
||||
}
|
||||
|
||||
static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level);
|
||||
static void
|
||||
_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
return;
|
||||
msg_level = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
save_image_jpeg(RGBA_Image *im, const char *file, int quality)
|
||||
{
|
||||
struct _JPEG_error_mgr jerr;
|
||||
struct jpeg_compress_struct cinfo;
|
||||
FILE *f;
|
||||
DATA8 *buf;
|
||||
DATA32 *ptr;
|
||||
JSAMPROW *jbuf;
|
||||
int y = 0;
|
||||
int i, j;
|
||||
|
||||
buf = alloca(im->image->w * 3 * sizeof(DATA8));
|
||||
f = fopen(file, "wb");
|
||||
if (!f)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
jerr.pub.error_exit = _JPEGFatalErrorHandler;
|
||||
jerr.pub.emit_message = _JPEGErrorHandler2;
|
||||
jerr.pub.output_message = _JPEGErrorHandler;
|
||||
cinfo.err = jpeg_std_error(&(jerr.pub));
|
||||
if (sigsetjmp(jerr.setjmp_buffer, 1))
|
||||
{
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
jpeg_create_compress(&cinfo);
|
||||
jpeg_stdio_dest(&cinfo, f);
|
||||
cinfo.image_width = im->image->w;
|
||||
cinfo.image_height = im->image->h;
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality(&cinfo, quality, TRUE);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
ptr = im->image->data;
|
||||
while (cinfo.next_scanline < cinfo.image_height)
|
||||
{
|
||||
for (j = 0, i = 0; i < im->image->w; i++)
|
||||
{
|
||||
buf[j++] = ((*ptr) >> 16) & 0xff;
|
||||
buf[j++] = ((*ptr) >> 8) & 0xff;
|
||||
buf[j++] = ((*ptr)) & 0xff;
|
||||
ptr++;
|
||||
}
|
||||
jbuf = (JSAMPROW *) (&buf);
|
||||
jpeg_write_scanlines(&cinfo, jbuf, 1);
|
||||
y++;
|
||||
}
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_EET
|
||||
static int
|
||||
save_image_eet(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
|
||||
{
|
||||
Eet_File *ef;
|
||||
int alpha = 0, lossy = 0, ok = 0;
|
||||
|
||||
ef = eet_open((char *)file, EET_FILE_MODE_READ_WRITE);
|
||||
if (!ef) ef = eet_open((char *)file, EET_FILE_MODE_WRITE);
|
||||
if (!ef) return 0;
|
||||
if ((quality <= 100) || (compress < 0)) lossy = 1;
|
||||
if (im->flags & RGBA_IMAGE_HAS_ALPHA) alpha = 1;
|
||||
ok = eet_data_image_write(ef, (char *)key, im->image->data,
|
||||
im->image->w, im->image->h, alpha, compress,
|
||||
quality, lossy);
|
||||
eet_close(ef);
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_EDB
|
||||
static int
|
||||
save_image_edb(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_LOADER_TEMPLATE
|
||||
#endif
|
||||
extern Evas_List *evas_modules;
|
||||
|
||||
int
|
||||
evas_common_save_image_to_file(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
|
||||
{
|
||||
Evas_Image_Save_Func *evas_image_save_func = NULL;
|
||||
char *p;
|
||||
char *saver = NULL;
|
||||
|
||||
p = strrchr(file, '.');
|
||||
if (p)
|
||||
{
|
||||
p++;
|
||||
|
||||
#ifdef BUILD_LOADER_PNG
|
||||
if (!strcasecmp(p, "png"))
|
||||
return save_image_png(im, file, compress, 0);
|
||||
#endif
|
||||
#ifdef BUILD_LOADER_JPEG
|
||||
if ((!strcasecmp(p, "jpg")) ||
|
||||
(!strcasecmp(p, "jpeg")) ||
|
||||
saver = "png";
|
||||
if ((!strcasecmp(p, "jpg")) || (!strcasecmp(p, "jpeg")) ||
|
||||
(!strcasecmp(p, "jfif")))
|
||||
return save_image_jpeg(im, file, quality);
|
||||
#endif
|
||||
#ifdef BUILD_LOADER_EET
|
||||
if (!strcasecmp(p, "eet"))
|
||||
return save_image_eet(im, file, key, quality, compress);
|
||||
#endif
|
||||
#ifdef BUILD_LOADER_EDB
|
||||
saver = "jpeg";
|
||||
if ((!strcasecmp(p, "eet")) || (!strcasecmp(p, "edj")) ||
|
||||
(!strcasecmp(p, "eap")))
|
||||
saver = "eet";
|
||||
if (!strcasecmp(p, "edb"))
|
||||
return save_image_edb(im, file, key, quality, compress);
|
||||
#endif
|
||||
saver = "edb";
|
||||
}
|
||||
printf ("Saver %s\n", saver);
|
||||
if (saver)
|
||||
{
|
||||
Evas_Module *em;
|
||||
|
||||
em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_SAVER, saver);
|
||||
if (em)
|
||||
{
|
||||
printf ("saver found %d\n", em->loaded);
|
||||
if (evas_module_load(em))
|
||||
{
|
||||
evas_image_save_func = em->functions;
|
||||
return evas_image_save_func->image_save(im, file, key, quality, compress);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -111,6 +111,7 @@ evas_module_paths_init(void)
|
|||
/* 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_IMAGE_SAVER, paths->data, "savers");
|
||||
_evas_module_path_append(EVAS_MODULE_TYPE_OBJECT, paths->data, "objects");
|
||||
free(paths->data);
|
||||
paths = evas_list_remove_list(paths, paths);
|
||||
|
@ -126,7 +127,7 @@ evas_module_init(void)
|
|||
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)
|
||||
{
|
||||
|
@ -137,7 +138,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;
|
||||
|
@ -173,7 +174,10 @@ evas_module_init(void)
|
|||
else if (em->type == EVAS_MODULE_TYPE_IMAGE_LOADER)
|
||||
{
|
||||
}
|
||||
/* 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_SAVER)
|
||||
{
|
||||
}
|
||||
/* 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);
|
||||
|
@ -277,6 +281,7 @@ evas_module_shutdown(void)
|
|||
{
|
||||
Evas_Module *em;
|
||||
|
||||
/* printf("[shutdown modules]\n"); */
|
||||
while (evas_modules)
|
||||
{
|
||||
em = (Evas_Module *)evas_modules->data;
|
||||
|
@ -290,6 +295,9 @@ evas_module_shutdown(void)
|
|||
else if (em->type == EVAS_MODULE_TYPE_IMAGE_LOADER)
|
||||
{
|
||||
}
|
||||
else if (em->type == EVAS_MODULE_TYPE_IMAGE_SAVER)
|
||||
{
|
||||
}
|
||||
free(evas_modules->data);
|
||||
evas_modules = evas_list_remove_list(evas_modules, evas_modules);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ typedef enum _Evas_Module_Type
|
|||
{
|
||||
EVAS_MODULE_TYPE_ENGINE,
|
||||
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
||||
EVAS_MODULE_TYPE_IMAGE_SAVER,
|
||||
EVAS_MODULE_TYPE_OBJECT
|
||||
} Evas_Module_Type;
|
||||
|
||||
|
@ -83,6 +84,7 @@ 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_Image_Save_Func Evas_Image_Save_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;
|
||||
|
@ -599,6 +601,11 @@ struct _Evas_Image_Load_Func
|
|||
int (*file_data) (RGBA_Image *im, const char *file, const char *key);
|
||||
};
|
||||
|
||||
struct _Evas_Image_Save_Func
|
||||
{
|
||||
int (*image_save) (RGBA_Image *im, const char *file, const char *key, int quality, int compress);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = engines loaders
|
||||
SUBDIRS = engines loaders savers
|
||||
|
|
|
@ -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/savers/edb/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_save_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_save_edb.c
|
|
@ -0,0 +1,39 @@
|
|||
#include <Edb.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
int evas_image_save_file_edb(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
|
||||
|
||||
Evas_Image_Save_Func evas_image_save_edb_func =
|
||||
{
|
||||
evas_image_save_file_edb
|
||||
};
|
||||
|
||||
int
|
||||
evas_image_save_file_edb(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_save_edb_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_SAVER,
|
||||
"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/savers/eet/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_save_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_save_eet.c
|
|
@ -0,0 +1,50 @@
|
|||
#include <Eet.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
int evas_image_save_file_eet(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
|
||||
|
||||
Evas_Image_Save_Func evas_image_save_eet_func =
|
||||
{
|
||||
evas_image_save_file_eet
|
||||
};
|
||||
|
||||
int
|
||||
evas_image_save_file_eet(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
|
||||
{
|
||||
Eet_File *ef;
|
||||
int alpha = 0, lossy = 0, ok = 0;
|
||||
|
||||
ef = eet_open((char *)file, EET_FILE_MODE_READ_WRITE);
|
||||
if (!ef) ef = eet_open((char *)file, EET_FILE_MODE_WRITE);
|
||||
if (!ef) return 0;
|
||||
if ((quality <= 100) || (compress < 0)) lossy = 1;
|
||||
if (im->flags & RGBA_IMAGE_HAS_ALPHA) alpha = 1;
|
||||
ok = eet_data_image_write(ef, (char *)key, im->image->data,
|
||||
im->image->w, im->image->h, alpha, compress,
|
||||
quality, lossy);
|
||||
eet_close(ef);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_save_eet_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_SAVER,
|
||||
"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/savers/jpeg/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_save_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_save_jpeg.c
|
|
@ -0,0 +1,135 @@
|
|||
#include <stdio.h>
|
||||
#include <jpeglib.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
int evas_image_save_file_jpeg(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
|
||||
|
||||
Evas_Image_Save_Func evas_image_save_jpeg_func =
|
||||
{
|
||||
evas_image_save_file_jpeg
|
||||
};
|
||||
|
||||
struct _JPEG_error_mgr
|
||||
{
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmp_buffer;
|
||||
};
|
||||
typedef struct _JPEG_error_mgr *emptr;
|
||||
|
||||
static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
|
||||
static void
|
||||
_JPEGFatalErrorHandler(j_common_ptr cinfo)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
longjmp(errmgr->setjmp_buffer, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
static void _JPEGErrorHandler(j_common_ptr cinfo);
|
||||
static void
|
||||
_JPEGErrorHandler(j_common_ptr cinfo)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
return;
|
||||
}
|
||||
|
||||
static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level);
|
||||
static void
|
||||
_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level)
|
||||
{
|
||||
emptr errmgr;
|
||||
|
||||
errmgr = (emptr) cinfo->err;
|
||||
return;
|
||||
msg_level = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
save_image_jpeg(RGBA_Image *im, const char *file, int quality)
|
||||
{
|
||||
struct _JPEG_error_mgr jerr;
|
||||
struct jpeg_compress_struct cinfo;
|
||||
FILE *f;
|
||||
DATA8 *buf;
|
||||
DATA32 *ptr;
|
||||
JSAMPROW *jbuf;
|
||||
int y = 0;
|
||||
int i, j;
|
||||
|
||||
buf = alloca(im->image->w * 3 * sizeof(DATA8));
|
||||
f = fopen(file, "wb");
|
||||
if (!f)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
jerr.pub.error_exit = _JPEGFatalErrorHandler;
|
||||
jerr.pub.emit_message = _JPEGErrorHandler2;
|
||||
jerr.pub.output_message = _JPEGErrorHandler;
|
||||
cinfo.err = jpeg_std_error(&(jerr.pub));
|
||||
if (sigsetjmp(jerr.setjmp_buffer, 1))
|
||||
{
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
jpeg_create_compress(&cinfo);
|
||||
jpeg_stdio_dest(&cinfo, f);
|
||||
cinfo.image_width = im->image->w;
|
||||
cinfo.image_height = im->image->h;
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality(&cinfo, quality, TRUE);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
ptr = im->image->data;
|
||||
while (cinfo.next_scanline < cinfo.image_height)
|
||||
{
|
||||
for (j = 0, i = 0; i < im->image->w; i++)
|
||||
{
|
||||
buf[j++] = ((*ptr) >> 16) & 0xff;
|
||||
buf[j++] = ((*ptr) >> 8) & 0xff;
|
||||
buf[j++] = ((*ptr)) & 0xff;
|
||||
ptr++;
|
||||
}
|
||||
jbuf = (JSAMPROW *) (&buf);
|
||||
jpeg_write_scanlines(&cinfo, jbuf, 1);
|
||||
y++;
|
||||
}
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int evas_image_save_file_jpeg(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
|
||||
{
|
||||
return save_image_jpeg(im, file, quality);
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_save_jpeg_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_SAVER,
|
||||
"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/savers/png/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = evas_image_save_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_save_png.c
|
|
@ -0,0 +1,143 @@
|
|||
#include <png.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "evas_common.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
|
||||
int evas_image_save_file_png(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
|
||||
|
||||
Evas_Image_Save_Func evas_image_save_png_func =
|
||||
{
|
||||
evas_image_save_file_png
|
||||
};
|
||||
|
||||
static int
|
||||
save_image_png(RGBA_Image *im, const char *file, int compress, int interlace)
|
||||
{
|
||||
FILE *f;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
DATA32 *ptr;
|
||||
int x, y, j;
|
||||
png_bytep row_ptr, data = NULL;
|
||||
png_color_8 sig_bit;
|
||||
int quality = 75, compression = 3, num_passes = 1, pass;
|
||||
|
||||
f = fopen(file, "wb");
|
||||
if (!f) return 0;
|
||||
|
||||
png_ptr = png_create_write_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 == NULL)
|
||||
{
|
||||
fclose(f);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
|
||||
return 0;
|
||||
}
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
fclose(f);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
|
||||
png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (interlace)
|
||||
{
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
png_ptr->interlaced = PNG_INTERLACE_ADAM7;
|
||||
num_passes = png_set_interlace_handling(png_ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, f);
|
||||
|
||||
if (im->flags & RGBA_IMAGE_HAS_ALPHA)
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
|
||||
PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
png_set_swap_alpha(png_ptr);
|
||||
#else
|
||||
png_set_bgr(png_ptr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
|
||||
PNG_COLOR_TYPE_RGB, png_ptr->interlaced,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
data = alloca(im->image->w * 3 * sizeof(char));
|
||||
}
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
sig_bit.blue = 8;
|
||||
sig_bit.alpha = 8;
|
||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
|
||||
png_set_compression_level(png_ptr, compress);
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
png_set_shift(png_ptr, &sig_bit);
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
for (pass = 0; pass < num_passes; pass++)
|
||||
{
|
||||
ptr = im->image->data;
|
||||
|
||||
for (y = 0; y < im->image->h; y++)
|
||||
{
|
||||
if (im->flags & RGBA_IMAGE_HAS_ALPHA)
|
||||
row_ptr = (png_bytep) ptr;
|
||||
else
|
||||
{
|
||||
for (j = 0, x = 0; x < im->image->w; x++)
|
||||
{
|
||||
data[j++] = (ptr[x] >> 16) & 0xff;
|
||||
data[j++] = (ptr[x] >> 8) & 0xff;
|
||||
data[j++] = (ptr[x]) & 0xff;
|
||||
}
|
||||
row_ptr = (png_bytep) data;
|
||||
}
|
||||
png_write_rows(png_ptr, &row_ptr, 1);
|
||||
ptr += im->image->w;
|
||||
}
|
||||
}
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
|
||||
png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
|
||||
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int evas_image_save_file_png(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
|
||||
{
|
||||
return save_image_png(im, file, compress, 0);
|
||||
}
|
||||
|
||||
int module_open(Evas_Module *em)
|
||||
{
|
||||
if (!em) return 0;
|
||||
em->functions = (void *)(&evas_image_save_png_func);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void module_close(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Evas_Module_Api evas_modapi =
|
||||
{
|
||||
EVAS_MODULE_API_VERSION,
|
||||
EVAS_MODULE_TYPE_IMAGE_SAVER,
|
||||
"png",
|
||||
"none"
|
||||
};
|
Loading…
Reference in New Issue