2006-01-15 02:35:02 -08:00
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2006-10-27 20:02:23 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <jpeglib.h>
|
|
|
|
#include <setjmp.h>
|
2006-01-15 02:35:02 -08:00
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static int evas_image_save_file_jpeg(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
|
2006-01-15 02:35:02 -08:00
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Image_Save_Func evas_image_save_jpeg_func =
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
|
|
|
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;
|
2011-02-27 02:04:19 -08:00
|
|
|
|
2006-01-15 02:35:02 -08:00
|
|
|
errmgr = (emptr) cinfo->err;
|
|
|
|
longjmp(errmgr->setjmp_buffer, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-22 15:33:06 -07:00
|
|
|
_JPEGErrorHandler(j_common_ptr cinfo __UNUSED__)
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
2009-10-22 15:33:06 -07:00
|
|
|
/* emptr errmgr; */
|
2011-02-27 02:04:19 -08:00
|
|
|
|
2009-10-22 15:33:06 -07:00
|
|
|
/* errmgr = (emptr) cinfo->err; */
|
2006-01-15 02:35:02 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-22 15:33:06 -07:00
|
|
|
_JPEGErrorHandler2(j_common_ptr cinfo __UNUSED__, int msg_level __UNUSED__)
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
2009-10-22 15:33:06 -07:00
|
|
|
/* emptr errmgr; */
|
2011-02-27 02:04:19 -08:00
|
|
|
|
2009-10-22 15:33:06 -07:00
|
|
|
/* errmgr = (emptr) cinfo->err; */
|
2006-01-15 02:35:02 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
save_image_jpeg(RGBA_Image *im, const char *file, int quality)
|
|
|
|
{
|
|
|
|
struct jpeg_compress_struct cinfo;
|
2012-07-18 20:04:47 -07:00
|
|
|
struct _JPEG_error_mgr jerr;
|
2006-01-15 02:35:02 -08:00
|
|
|
FILE *f;
|
|
|
|
DATA8 *buf;
|
|
|
|
DATA32 *ptr;
|
|
|
|
JSAMPROW *jbuf;
|
|
|
|
int y = 0;
|
2006-04-10 00:27:54 -07:00
|
|
|
|
2008-04-11 17:32:30 -07:00
|
|
|
if (!im || !im->image.data || !file)
|
2006-04-10 00:27:54 -07:00
|
|
|
return 0;
|
2011-02-27 02:04:19 -08:00
|
|
|
|
2008-04-11 17:32:30 -07:00
|
|
|
buf = alloca(im->cache_entry.w * 3 * sizeof(DATA8));
|
2006-01-15 02:35:02 -08:00
|
|
|
f = fopen(file, "wb");
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-18 20:04:47 -07:00
|
|
|
memset(&cinfo, 0, sizeof(cinfo));
|
|
|
|
cinfo.err = jpeg_std_error(&(jerr.pub));
|
2006-01-15 02:35:02 -08:00
|
|
|
jerr.pub.error_exit = _JPEGFatalErrorHandler;
|
|
|
|
jerr.pub.emit_message = _JPEGErrorHandler2;
|
|
|
|
jerr.pub.output_message = _JPEGErrorHandler;
|
|
|
|
if (sigsetjmp(jerr.setjmp_buffer, 1))
|
|
|
|
{
|
|
|
|
jpeg_destroy_compress(&cinfo);
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
jpeg_create_compress(&cinfo);
|
|
|
|
jpeg_stdio_dest(&cinfo, f);
|
2008-04-11 17:32:30 -07:00
|
|
|
cinfo.image_width = im->cache_entry.w;
|
|
|
|
cinfo.image_height = im->cache_entry.h;
|
2006-01-15 02:35:02 -08:00
|
|
|
cinfo.input_components = 3;
|
|
|
|
cinfo.in_color_space = JCS_RGB;
|
2011-11-16 03:52:36 -08:00
|
|
|
cinfo.optimize_coding = FALSE;
|
|
|
|
cinfo.dct_method = JDCT_ISLOW; // JDCT_FLOAT JDCT_IFAST(quality loss)
|
|
|
|
if (quality < 60) cinfo.dct_method = JDCT_IFAST;
|
2006-01-15 02:35:02 -08:00
|
|
|
jpeg_set_defaults(&cinfo);
|
|
|
|
jpeg_set_quality(&cinfo, quality, TRUE);
|
2011-11-16 03:52:36 -08:00
|
|
|
if (quality >= 90)
|
|
|
|
{
|
|
|
|
cinfo.comp_info[0].h_samp_factor = 1;
|
|
|
|
cinfo.comp_info[0].v_samp_factor = 1;
|
|
|
|
cinfo.comp_info[1].h_samp_factor = 1;
|
|
|
|
cinfo.comp_info[1].v_samp_factor = 1;
|
|
|
|
cinfo.comp_info[2].h_samp_factor = 1;
|
|
|
|
cinfo.comp_info[2].v_samp_factor = 1;
|
|
|
|
}
|
2006-01-15 02:35:02 -08:00
|
|
|
jpeg_start_compress(&cinfo, TRUE);
|
2008-04-11 17:32:30 -07:00
|
|
|
ptr = im->image.data;
|
2006-01-15 02:35:02 -08:00
|
|
|
while (cinfo.next_scanline < cinfo.image_height)
|
|
|
|
{
|
2011-02-27 02:04:19 -08:00
|
|
|
unsigned int i, j;
|
2008-04-11 17:32:30 -07:00
|
|
|
for (j = 0, i = 0; i < im->cache_entry.w; i++)
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static int evas_image_save_file_jpeg(RGBA_Image *im, const char *file, const char *key __UNUSED__, int quality, int compress __UNUSED__)
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
|
|
|
return save_image_jpeg(im, file, quality);
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static int
|
2006-09-06 00:28:46 -07:00
|
|
|
module_open(Evas_Module *em)
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
|
|
|
if (!em) return 0;
|
|
|
|
em->functions = (void *)(&evas_image_save_jpeg_func);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static void
|
cleanup: fix some "unused" errors from -Wextra.
As we're heading for a release we better remove as much errors as
possible and as the first step I'm removing warnings due unused
parameters, variables and functions. These tend to pollute real errors
spotted by -Wall and clang/llvm.
This does not fixes all, just the clear that could be set to
__UNUSED__, particularly to do (and I'd like some help from the
authors):
* src/lib/engines/common/evas_font_{draw,query}.c (tasn):
intl_props is just used while doing BIDI, but also used in other
#ifdef blocks :-/
* evas_map_* (raster):
huge amount of warnings, code is quite confusing and thus I'm not
touching it. I have no idea whenever the commented blocks or extra
parameters are intended to be used or no.
* src/modules/engines/fbevas_fb_main.c (raster?):
is fb_setvt() to be used? If not do you mind removing it?
* src/modules/engines/gl_{common,x11} (raster):
huge amount of warnings, code is quite nested and full of #ifdefs
that does not help to give a clear picture of what's going on.
* src/bin/evas_cserve_main.c (raster):
I could have ignored most of the errors, but is the code correct? I
mean, there is no unload of images being applied. If you confirm
none of those warnings are harmful I can flag them as unused.
* src/lib/engines/common_8 (dottedmag):
lots of unused functions that were acquired from common_16, they
are unused and if they will not, then they should be removed.
SVN revision: 52421
2010-09-18 12:17:41 -07:00
|
|
|
module_close(Evas_Module *em __UNUSED__)
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Module_Api evas_modapi =
|
2006-01-15 02:35:02 -08:00
|
|
|
{
|
|
|
|
EVAS_MODULE_API_VERSION,
|
2009-06-16 06:01:36 -07:00
|
|
|
"jpeg",
|
|
|
|
"none",
|
|
|
|
{
|
|
|
|
module_open,
|
|
|
|
module_close
|
|
|
|
}
|
2006-01-15 02:35:02 -08:00
|
|
|
};
|
2009-06-16 06:01:36 -07:00
|
|
|
|
|
|
|
EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_SAVER, image_saver, jpeg);
|
|
|
|
|
|
|
|
#ifndef EVAS_STATIC_BUILD_JPEG
|
|
|
|
EVAS_EINA_MODULE_DEFINE(image_saver, jpeg);
|
|
|
|
#endif
|