2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-01-04 05:36:43 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2005-01-04 05:36:43 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-01-04 05:36:43 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-01-04 05:36:43 +08:00
|
|
|
*/
|
|
|
|
|
2005-01-07 07:21:43 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <jpeglib.h>
|
|
|
|
#include <jerror.h>
|
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#ifdef HAVE_LIBEXIF
|
2005-01-07 07:21:43 +08:00
|
|
|
#include <libexif/exif-data.h>
|
2011-09-18 09:34:44 +08:00
|
|
|
#endif /* HAVE_LIBEXIF */
|
2005-01-07 07:21:43 +08:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2005-01-04 05:36:43 +08:00
|
|
|
#include "jpeg.h"
|
2007-07-27 07:01:21 +08:00
|
|
|
#include "jpeg-settings.h"
|
2005-01-04 05:36:43 +08:00
|
|
|
#include "jpeg-load.h"
|
2005-01-07 07:21:43 +08:00
|
|
|
#include "jpeg-save.h"
|
2011-09-18 09:51:30 +08:00
|
|
|
#ifdef HAVE_LIBEXIF
|
|
|
|
#include "jpeg-exif.h"
|
2005-01-19 02:37:31 +08:00
|
|
|
#include "gimpexif.h"
|
2011-09-18 10:38:16 +08:00
|
|
|
#endif
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
|
2005-01-04 05:36:43 +08:00
|
|
|
/* Declare local functions.
|
|
|
|
*/
|
2005-01-07 07:21:43 +08:00
|
|
|
|
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
2008-09-25 22:30:02 +08:00
|
|
|
gboolean undo_touched;
|
|
|
|
gboolean load_interactive;
|
|
|
|
gchar *image_comment;
|
|
|
|
gint32 display_ID;
|
|
|
|
JpegSaveVals jsvals;
|
|
|
|
gint32 orig_image_ID_global;
|
|
|
|
gint32 drawable_ID_global;
|
|
|
|
gboolean has_metadata;
|
|
|
|
gint orig_quality;
|
|
|
|
JpegSubsampling orig_subsmp;
|
|
|
|
gint num_quant_tables;
|
2007-08-11 05:45:38 +08:00
|
|
|
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#ifdef HAVE_LIBEXIF
|
2008-09-25 22:30:02 +08:00
|
|
|
ExifData *exif_data = NULL;
|
2007-05-06 22:48:32 +08:00
|
|
|
#endif
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
query (void)
|
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_args[] =
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2005-01-04 05:36:43 +08:00
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
2005-08-12 23:46:46 +08:00
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to load" }
|
2005-01-04 05:36:43 +08:00
|
|
|
};
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_return_vals[] =
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Output image" }
|
|
|
|
};
|
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#ifdef HAVE_LIBEXIF
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef thumb_args[] =
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
2005-08-12 23:46:46 +08:00
|
|
|
{ GIMP_PDB_INT32, "thumb-size", "Preferred thumbnail size" }
|
2005-01-04 05:36:43 +08:00
|
|
|
};
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef thumb_return_vals[] =
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Thumbnail image" },
|
2005-08-12 23:46:46 +08:00
|
|
|
{ GIMP_PDB_INT32, "image-width", "Width of full-sized image" },
|
|
|
|
{ GIMP_PDB_INT32, "image-height", "Height of full-sized image" }
|
2005-01-04 05:36:43 +08:00
|
|
|
};
|
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#endif /* HAVE_LIBEXIF */
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef save_args[] =
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2005-01-04 05:36:43 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" },
|
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
|
2005-08-12 23:46:46 +08:00
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" },
|
2005-01-04 05:36:43 +08:00
|
|
|
{ GIMP_PDB_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" },
|
|
|
|
{ GIMP_PDB_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" },
|
|
|
|
{ GIMP_PDB_INT32, "optimize", "Optimization of entropy encoding parameters (0/1)" },
|
2005-04-12 15:46:10 +08:00
|
|
|
{ GIMP_PDB_INT32, "progressive", "Enable progressive jpeg image loading (0/1)" },
|
2005-01-04 05:36:43 +08:00
|
|
|
{ GIMP_PDB_STRING, "comment", "Image comment" },
|
|
|
|
{ GIMP_PDB_INT32, "subsmp", "The subsampling option number" },
|
|
|
|
{ GIMP_PDB_INT32, "baseline", "Force creation of a baseline JPEG (non-baseline JPEGs can't be read by all decoders) (0/1)" },
|
2011-06-11 02:03:11 +08:00
|
|
|
{ GIMP_PDB_INT32, "restart", "Interval of restart markers (in MCU rows, 0 = no restart markers)" },
|
2005-01-04 05:36:43 +08:00
|
|
|
{ GIMP_PDB_INT32, "dct", "DCT algorithm to use (speed/quality tradeoff)" }
|
|
|
|
};
|
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_install_procedure (LOAD_PROC,
|
2005-01-04 05:36:43 +08:00
|
|
|
"loads files in the JPEG file format",
|
|
|
|
"loads files in the JPEG file format",
|
|
|
|
"Spencer Kimball, Peter Mattis & others",
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
2007-07-27 07:01:21 +08:00
|
|
|
"1995-2007",
|
2005-01-04 05:36:43 +08:00
|
|
|
N_("JPEG image"),
|
|
|
|
NULL,
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (load_args),
|
|
|
|
G_N_ELEMENTS (load_return_vals),
|
|
|
|
load_args, load_return_vals);
|
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_register_file_handler_mime (LOAD_PROC, "image/jpeg");
|
|
|
|
gimp_register_magic_load_handler (LOAD_PROC,
|
2005-01-04 05:36:43 +08:00
|
|
|
"jpg,jpeg,jpe",
|
|
|
|
"",
|
|
|
|
"6,string,JFIF,6,string,Exif");
|
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#ifdef HAVE_LIBEXIF
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_install_procedure (LOAD_THUMB_PROC,
|
2005-01-04 05:36:43 +08:00
|
|
|
"Loads a thumbnail from a JPEG image",
|
|
|
|
"Loads a thumbnail from a JPEG image (only if it exists)",
|
2008-03-25 06:01:03 +08:00
|
|
|
"Mukund Sivaraman <muks@mukund.org>, Sven Neumann <sven@gimp.org>",
|
|
|
|
"Mukund Sivaraman <muks@mukund.org>, Sven Neumann <sven@gimp.org>",
|
2005-01-04 05:36:43 +08:00
|
|
|
"November 15, 2004",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (thumb_args),
|
|
|
|
G_N_ELEMENTS (thumb_return_vals),
|
|
|
|
thumb_args, thumb_return_vals);
|
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC);
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#endif /* HAVE_LIBEXIF */
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_install_procedure (SAVE_PROC,
|
2005-01-04 05:36:43 +08:00
|
|
|
"saves files in the JPEG file format",
|
|
|
|
"saves files in the lossy, widely supported JPEG format",
|
|
|
|
"Spencer Kimball, Peter Mattis & others",
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
2007-07-27 07:01:21 +08:00
|
|
|
"1995-2007",
|
2005-01-04 05:36:43 +08:00
|
|
|
N_("JPEG image"),
|
|
|
|
"RGB*, GRAY*",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (save_args), 0,
|
|
|
|
save_args, NULL);
|
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_register_file_handler_mime (SAVE_PROC, "image/jpeg");
|
|
|
|
gimp_register_save_handler (SAVE_PROC, "jpg,jpeg,jpe", "");
|
2005-01-04 05:36:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
|
|
|
{
|
2012-04-12 03:48:22 +08:00
|
|
|
static GimpParam values[6];
|
2005-01-04 05:36:43 +08:00
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
gint32 image_ID;
|
|
|
|
gint32 drawable_ID;
|
|
|
|
gint32 orig_image_ID;
|
|
|
|
GimpParasite *parasite;
|
|
|
|
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
2008-08-20 15:07:56 +08:00
|
|
|
GError *error = NULL;
|
2005-01-04 05:36:43 +08:00
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
|
2007-08-08 18:31:38 +08:00
|
|
|
preview_image_ID = -1;
|
|
|
|
preview_layer_ID = -1;
|
|
|
|
|
2007-07-27 07:44:51 +08:00
|
|
|
has_metadata = FALSE;
|
2007-08-11 05:45:38 +08:00
|
|
|
orig_quality = 0;
|
2011-06-11 02:10:23 +08:00
|
|
|
orig_subsmp = JPEG_SUBSAMPLING_2x2_1x1_1x1;
|
2007-08-11 05:45:38 +08:00
|
|
|
num_quant_tables = 0;
|
2006-04-19 19:47:06 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
if (strcmp (name, LOAD_PROC) == 0)
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
2005-01-05 01:48:13 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2005-01-05 01:48:13 +08:00
|
|
|
load_interactive = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
load_interactive = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-08-20 15:07:56 +08:00
|
|
|
image_ID = load_image (param[1].data.d_string, run_mode, FALSE, &error);
|
2005-01-04 05:36:43 +08:00
|
|
|
|
|
|
|
if (image_ID != -1)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_IMAGE;
|
|
|
|
values[1].data.d_image = image_ID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
2005-01-05 01:48:13 +08:00
|
|
|
|
2005-01-04 05:36:43 +08:00
|
|
|
}
|
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#ifdef HAVE_LIBEXIF
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
else if (strcmp (name, LOAD_THUMB_PROC) == 0)
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
if (nparams < 2)
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-12 03:48:22 +08:00
|
|
|
const gchar *filename = param[0].data.d_string;
|
|
|
|
gint width = 0;
|
|
|
|
gint height = 0;
|
|
|
|
GimpImageType type = -1;
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2012-04-12 03:48:22 +08:00
|
|
|
image_ID = load_thumbnail_image (filename, &width, &height, &type,
|
|
|
|
&error);
|
2005-01-04 05:36:43 +08:00
|
|
|
|
|
|
|
if (image_ID != -1)
|
|
|
|
{
|
2012-04-12 03:48:22 +08:00
|
|
|
*nreturn_vals = 6;
|
2005-01-04 05:36:43 +08:00
|
|
|
values[1].type = GIMP_PDB_IMAGE;
|
|
|
|
values[1].data.d_image = image_ID;
|
|
|
|
values[2].type = GIMP_PDB_INT32;
|
|
|
|
values[2].data.d_int32 = width;
|
|
|
|
values[3].type = GIMP_PDB_INT32;
|
|
|
|
values[3].data.d_int32 = height;
|
2012-04-12 03:48:22 +08:00
|
|
|
values[4].type = GIMP_PDB_INT32;
|
|
|
|
values[4].data.d_int32 = type;
|
|
|
|
values[5].type = GIMP_PDB_INT32;
|
|
|
|
values[5].data.d_int32 = 1; /* num_layers */
|
2005-01-04 05:36:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#endif /* HAVE_LIBEXIF */
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
else if (strcmp (name, SAVE_PROC) == 0)
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
image_ID = orig_image_ID = param[1].data.d_int32;
|
|
|
|
drawable_ID = param[2].data.d_int32;
|
|
|
|
|
|
|
|
/* eventually export the image */
|
|
|
|
switch (run_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2009-07-21 20:10:29 +08:00
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, NULL,
|
2005-01-04 05:36:43 +08:00
|
|
|
(GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY));
|
|
|
|
switch (export)
|
|
|
|
{
|
|
|
|
case GIMP_EXPORT_EXPORT:
|
|
|
|
{
|
|
|
|
gchar *tmp = g_filename_from_utf8 (_("Export Preview"), -1,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
if (tmp)
|
|
|
|
{
|
|
|
|
gimp_image_set_filename (image_ID, tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
display_ID = -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GIMP_EXPORT_IGNORE:
|
|
|
|
break;
|
|
|
|
case GIMP_EXPORT_CANCEL:
|
|
|
|
values[0].data.d_status = GIMP_PDB_CANCEL;
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (image_comment);
|
|
|
|
image_comment = NULL;
|
|
|
|
|
2011-03-08 20:19:21 +08:00
|
|
|
parasite = gimp_image_get_parasite (orig_image_ID, "gimp-comment");
|
2005-01-04 05:36:43 +08:00
|
|
|
if (parasite)
|
|
|
|
{
|
|
|
|
image_comment = g_strndup (gimp_parasite_data (parasite),
|
|
|
|
gimp_parasite_data_size (parasite));
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
2011-03-08 20:19:21 +08:00
|
|
|
parasite = gimp_image_get_parasite (orig_image_ID, "gimp-metadata");
|
2007-07-27 07:44:51 +08:00
|
|
|
if (parasite)
|
|
|
|
{
|
|
|
|
has_metadata = TRUE;
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#ifdef HAVE_LIBEXIF
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2005-01-19 02:37:31 +08:00
|
|
|
exif_data = gimp_metadata_generate_exif (orig_image_ID);
|
|
|
|
if (exif_data)
|
|
|
|
jpeg_setup_exif_for_save (exif_data, orig_image_ID);
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2011-09-18 09:34:44 +08:00
|
|
|
#endif /* HAVE_LIBEXIF */
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2011-09-30 20:59:54 +08:00
|
|
|
load_defaults ();
|
2007-07-08 21:33:21 +08:00
|
|
|
|
2005-01-04 05:36:43 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
/* pw - added two more progressive and comment */
|
|
|
|
/* sg - added subsampling, preview, baseline, restarts and DCT */
|
|
|
|
if (nparams != 14)
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Once the PDB gets default parameters, remove this hack */
|
2009-08-11 03:26:53 +08:00
|
|
|
if (param[5].data.d_float >= 0.01)
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
jsvals.quality = 100.0 * param[5].data.d_float;
|
|
|
|
jsvals.smoothing = param[6].data.d_float;
|
|
|
|
jsvals.optimize = param[7].data.d_int32;
|
|
|
|
jsvals.progressive = param[8].data.d_int32;
|
|
|
|
jsvals.baseline = param[11].data.d_int32;
|
|
|
|
jsvals.subsmp = param[10].data.d_int32;
|
|
|
|
jsvals.restart = param[12].data.d_int32;
|
|
|
|
jsvals.dct = param[13].data.d_int32;
|
|
|
|
|
|
|
|
/* free up the default -- wasted some effort earlier */
|
|
|
|
g_free (image_comment);
|
|
|
|
image_comment = g_strdup (param[9].data.d_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsvals.preview = FALSE;
|
|
|
|
|
|
|
|
if (jsvals.quality < 0.0 || jsvals.quality > 100.0)
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
else if (jsvals.smoothing < 0.0 || jsvals.smoothing > 1.0)
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2007-07-27 07:01:21 +08:00
|
|
|
else if (jsvals.subsmp < 0 || jsvals.subsmp > 3)
|
2005-01-04 05:36:43 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
else if (jsvals.dct < 0 || jsvals.dct > 2)
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-09 14:42:45 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2005-01-04 05:36:43 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2007-09-19 19:44:42 +08:00
|
|
|
/* restore the values found when loading the file (if available) */
|
2007-08-11 05:45:38 +08:00
|
|
|
jpeg_restore_original_settings (orig_image_ID,
|
|
|
|
&orig_quality,
|
|
|
|
&orig_subsmp,
|
|
|
|
&num_quant_tables);
|
|
|
|
|
2007-09-19 19:44:42 +08:00
|
|
|
/* load up the previously used values (if file was saved once) */
|
2011-03-08 20:19:21 +08:00
|
|
|
parasite = gimp_image_get_parasite (orig_image_ID,
|
|
|
|
"jpeg-save-options");
|
2005-01-04 05:36:43 +08:00
|
|
|
if (parasite)
|
|
|
|
{
|
|
|
|
const JpegSaveVals *save_vals = gimp_parasite_data (parasite);
|
|
|
|
|
2007-08-11 05:45:38 +08:00
|
|
|
jsvals.quality = save_vals->quality;
|
|
|
|
jsvals.smoothing = save_vals->smoothing;
|
|
|
|
jsvals.optimize = save_vals->optimize;
|
|
|
|
jsvals.progressive = save_vals->progressive;
|
|
|
|
jsvals.baseline = save_vals->baseline;
|
|
|
|
jsvals.subsmp = save_vals->subsmp;
|
|
|
|
jsvals.restart = save_vals->restart;
|
|
|
|
jsvals.dct = save_vals->dct;
|
|
|
|
jsvals.preview = save_vals->preview;
|
|
|
|
jsvals.save_exif = save_vals->save_exif;
|
|
|
|
jsvals.save_thumbnail = save_vals->save_thumbnail;
|
|
|
|
jsvals.save_xmp = save_vals->save_xmp;
|
2007-08-29 20:01:38 +08:00
|
|
|
jsvals.use_orig_quality = save_vals->use_orig_quality;
|
2005-01-04 05:36:43 +08:00
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
2007-07-09 14:42:45 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We are called with GIMP_RUN_WITH_LAST_VALS but this image
|
|
|
|
* doesn't have a "jpeg-save-options" parasite. It's better
|
|
|
|
* to prompt the user with a dialog now so that she has control
|
|
|
|
* over the JPEG encoding parameters.
|
|
|
|
*/
|
|
|
|
run_mode = GIMP_RUN_INTERACTIVE;
|
2008-08-20 15:07:56 +08:00
|
|
|
|
2007-08-11 05:45:38 +08:00
|
|
|
/* If this image was loaded from a JPEG file and has not been
|
|
|
|
* saved yet, try to use some of the settings from the
|
2007-07-27 07:01:21 +08:00
|
|
|
* original file if they are better than the default values.
|
|
|
|
*/
|
2007-08-11 05:45:38 +08:00
|
|
|
if (orig_quality > jsvals.quality)
|
2007-07-27 07:01:21 +08:00
|
|
|
{
|
2007-08-11 05:45:38 +08:00
|
|
|
jsvals.quality = orig_quality;
|
2007-08-29 20:01:38 +08:00
|
|
|
jsvals.use_orig_quality = TRUE;
|
2007-07-27 07:01:21 +08:00
|
|
|
}
|
2008-08-20 15:07:56 +08:00
|
|
|
|
2011-06-11 02:10:23 +08:00
|
|
|
if (orig_subsmp == JPEG_SUBSAMPLING_1x1_1x1_1x1 ||
|
2008-10-05 06:46:42 +08:00
|
|
|
((gint) orig_subsmp > 0 &&
|
2011-06-11 02:10:23 +08:00
|
|
|
jsvals.subsmp == JPEG_SUBSAMPLING_1x1_1x1_1x1))
|
2008-10-05 06:46:42 +08:00
|
|
|
{
|
|
|
|
jsvals.subsmp = orig_subsmp;
|
|
|
|
}
|
2007-07-09 14:42:45 +08:00
|
|
|
}
|
2005-01-04 05:36:43 +08:00
|
|
|
break;
|
2007-07-09 14:42:45 +08:00
|
|
|
}
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2007-07-09 14:42:45 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
{
|
|
|
|
if (jsvals.preview)
|
|
|
|
{
|
|
|
|
/* we freeze undo saving so that we can avoid sucking up
|
|
|
|
* tile cache with our unneeded preview steps. */
|
|
|
|
gimp_image_undo_freeze (image_ID);
|
|
|
|
|
|
|
|
undo_touched = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prepare for the preview */
|
2007-08-08 18:31:38 +08:00
|
|
|
preview_image_ID = image_ID;
|
2007-07-09 14:42:45 +08:00
|
|
|
orig_image_ID_global = orig_image_ID;
|
|
|
|
drawable_ID_global = drawable_ID;
|
|
|
|
|
|
|
|
/* First acquire information with a dialog */
|
2008-08-20 15:07:56 +08:00
|
|
|
status = (save_dialog () ? GIMP_PDB_SUCCESS : GIMP_PDB_CANCEL);
|
2007-07-09 14:42:45 +08:00
|
|
|
|
|
|
|
if (undo_touched)
|
|
|
|
{
|
|
|
|
/* thaw undo saving and flush the displays to have them
|
|
|
|
* reflect the current shortcuts */
|
|
|
|
gimp_image_undo_thaw (image_ID);
|
|
|
|
gimp_displays_flush ();
|
|
|
|
}
|
2005-01-04 05:36:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
2007-09-19 19:44:42 +08:00
|
|
|
if (! save_image (param[3].data.d_string,
|
2008-08-20 15:07:56 +08:00
|
|
|
image_ID, drawable_ID, orig_image_ID, FALSE,
|
|
|
|
&error))
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
|
|
|
{
|
|
|
|
/* If the image was exported, delete the new display. */
|
|
|
|
/* This also deletes the image. */
|
|
|
|
|
|
|
|
if (display_ID != -1)
|
|
|
|
gimp_display_delete (display_ID);
|
|
|
|
else
|
|
|
|
gimp_image_delete (image_ID);
|
2008-12-28 10:10:32 +08:00
|
|
|
}
|
2005-01-04 05:36:43 +08:00
|
|
|
|
2008-12-28 10:10:32 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2005-01-04 05:36:43 +08:00
|
|
|
{
|
2008-12-28 10:10:32 +08:00
|
|
|
/* pw - now we need to change the defaults to be whatever
|
|
|
|
* was used to save this image. Dump the old parasites
|
|
|
|
* and add new ones. */
|
|
|
|
|
2011-03-08 20:19:21 +08:00
|
|
|
gimp_image_detach_parasite (orig_image_ID, "gimp-comment");
|
2008-12-28 10:10:32 +08:00
|
|
|
if (image_comment && strlen (image_comment))
|
|
|
|
{
|
|
|
|
parasite = gimp_parasite_new ("gimp-comment",
|
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
strlen (image_comment) + 1,
|
|
|
|
image_comment);
|
2011-03-08 20:19:21 +08:00
|
|
|
gimp_image_attach_parasite (orig_image_ID, parasite);
|
2008-12-28 10:10:32 +08:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
2011-03-08 20:19:21 +08:00
|
|
|
gimp_image_detach_parasite (orig_image_ID, "jpeg-save-options");
|
2008-12-28 10:10:32 +08:00
|
|
|
parasite = gimp_parasite_new ("jpeg-save-options",
|
2011-03-08 20:19:21 +08:00
|
|
|
0, sizeof (jsvals), &jsvals);
|
|
|
|
gimp_image_attach_parasite (orig_image_ID, parasite);
|
2005-01-04 05:36:43 +08:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-08-20 15:07:56 +08:00
|
|
|
if (status != GIMP_PDB_SUCCESS && error)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_STRING;
|
|
|
|
values[1].data.d_string = error->message;
|
|
|
|
}
|
|
|
|
|
2005-01-04 05:36:43 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here's the routine that will replace the standard error_exit method:
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
my_error_exit (j_common_ptr cinfo)
|
|
|
|
{
|
|
|
|
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
|
|
|
|
my_error_ptr myerr = (my_error_ptr) cinfo->err;
|
|
|
|
|
|
|
|
/* Always display the message. */
|
|
|
|
/* We could postpone this until after returning, if we chose. */
|
|
|
|
(*cinfo->err->output_message) (cinfo);
|
|
|
|
|
|
|
|
/* Return control to the setjmp point */
|
|
|
|
longjmp (myerr->setjmp_buffer, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
my_output_message (j_common_ptr cinfo)
|
|
|
|
{
|
|
|
|
gchar buffer[JMSG_LENGTH_MAX + 1];
|
|
|
|
|
|
|
|
(*cinfo->err->format_message)(cinfo, buffer);
|
2008-11-04 22:05:24 +08:00
|
|
|
|
|
|
|
g_message ("%s", buffer);
|
2005-01-04 05:36:43 +08:00
|
|
|
}
|