Commit dae9f75a authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

plug-ins/file-jpeg/jpeg.[ch] plug-ins/file-jpeg/jpeg-save.[ch] introduced

2008-09-25  Sven Neumann  <sven@gimp.org>

	* plug-ins/file-jpeg/jpeg.[ch]
	* plug-ins/file-jpeg/jpeg-save.[ch]
	* plug-ins/file-jpeg/jpeg-settings.[ch]: introduced an enum for
	the subsampling factor.


svn path=/trunk/; revision=27056
parent 9665fee4
2008-09-25 Sven Neumann <sven@gimp.org>
* plug-ins/file-jpeg/jpeg.[ch]
* plug-ins/file-jpeg/jpeg-save.[ch]
* plug-ins/file-jpeg/jpeg-settings.[ch]: introduced an enum for
the subsampling factor.
2008-09-25 Sven Neumann <sven@gimp.org>
Bug 553412 – JPEG sampling factors not set to 1x1 on grayscale
......
......@@ -52,13 +52,14 @@
#define SCALE_WIDTH 125
/* See bugs #63610 and #61088 for a discussion about the quality settings */
#define DEFAULT_QUALITY 85.0
#define DEFAULT_SMOOTHING 0.0
#define DEFAULT_OPTIMIZE TRUE
#define DEFAULT_PROGRESSIVE FALSE
#define DEFAULT_BASELINE TRUE
#define DEFAULT_SUBSMP 0
#define DEFAULT_SUBSMP JPEG_SUPSAMPLING_2x2_1x1_1x1
#define DEFAULT_RESTART 0
#define DEFAULT_DCT 0
#define DEFAULT_PREVIEW FALSE
......@@ -263,12 +264,12 @@ save_image (const gchar *filename,
GimpParasite *parasite;
struct jpeg_compress_struct cinfo;
struct my_error_mgr jerr;
JpegSubsampling subsampling;
FILE * volatile outfile;
guchar *temp, *t;
guchar *data;
guchar *src, *s;
gboolean has_alpha;
gint subsampling;
gint rowstride, yend;
gint i, j;
......@@ -394,7 +395,8 @@ save_image (const gchar *filename,
cinfo.optimize_coding = jsvals.optimize;
subsampling = gimp_drawable_is_rgb (drawable_ID) ? jsvals.subsmp : 2;
subsampling = (gimp_drawable_is_rgb (drawable_ID) ?
jsvals.subsmp : JPEG_SUPSAMPLING_1x1_1x1_1x1);
/* smoothing is not supported with nonstandard sampling ratios */
if (subsampling != 1 && subsampling != 3)
......@@ -407,7 +409,7 @@ save_image (const gchar *filename,
switch (subsampling)
{
case 0:
case JPEG_SUPSAMPLING_2x2_1x1_1x1:
default:
cinfo.comp_info[0].h_samp_factor = 2;
cinfo.comp_info[0].v_samp_factor = 2;
......@@ -417,7 +419,7 @@ save_image (const gchar *filename,
cinfo.comp_info[2].v_samp_factor = 1;
break;
case 1:
case JPEG_SUPSAMPLING_2x1_1x1_1x1:
cinfo.comp_info[0].h_samp_factor = 2;
cinfo.comp_info[0].v_samp_factor = 1;
cinfo.comp_info[1].h_samp_factor = 1;
......@@ -426,7 +428,7 @@ save_image (const gchar *filename,
cinfo.comp_info[2].v_samp_factor = 1;
break;
case 2:
case JPEG_SUPSAMPLING_1x1_1x1_1x1:
cinfo.comp_info[0].h_samp_factor = 1;
cinfo.comp_info[0].v_samp_factor = 1;
cinfo.comp_info[1].h_samp_factor = 1;
......@@ -435,7 +437,7 @@ save_image (const gchar *filename,
cinfo.comp_info[2].v_samp_factor = 1;
break;
case 3:
case JPEG_SUPSAMPLING_1x2_1x1_1x1:
cinfo.comp_info[0].h_samp_factor = 1;
cinfo.comp_info[0].v_samp_factor = 2;
cinfo.comp_info[1].h_samp_factor = 1;
......@@ -1081,10 +1083,14 @@ save_dialog (void)
gtk_widget_show (label);
pg.subsmp =
combo = gimp_int_combo_box_new (_("1x1,1x1,1x1 (best quality)"), 2,
_("2x1,1x1,1x1 (4:2:2)"), 1,
_("1x2,1x1,1x1"), 3,
_("2x2,1x1,1x1 (smallest file)"), 0,
combo = gimp_int_combo_box_new (_("1x1,1x1,1x1 (best quality)"),
JPEG_SUPSAMPLING_1x1_1x1_1x1,
_("2x1,1x1,1x1 (4:2:2)"),
JPEG_SUPSAMPLING_2x1_1x1_1x1,
_("1x2,1x1,1x1"),
JPEG_SUPSAMPLING_1x2_1x1_1x1,
_("2x2,1x1,1x1 (smallest file)"),
JPEG_SUPSAMPLING_2x2_1x1_1x1,
NULL);
gtk_table_attach (GTK_TABLE (table), combo, 3, 6, 2, 3,
GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
......@@ -1094,7 +1100,7 @@ save_dialog (void)
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
gimp_drawable_is_rgb (drawable_ID_global) ?
jsvals.subsmp : 2,
jsvals.subsmp : JPEG_SUPSAMPLING_1x1_1x1_1x1,
G_CALLBACK (subsampling_changed),
entry);
......@@ -1242,6 +1248,7 @@ load_save_defaults (void)
gchar *def_str;
JpegSaveVals tmpvals;
gint num_fields;
gint subsampling;
jsvals.quality = DEFAULT_QUALITY;
jsvals.smoothing = DEFAULT_SMOOTHING;
......@@ -1277,7 +1284,7 @@ load_save_defaults (void)
&tmpvals.smoothing,
&tmpvals.optimize,
&tmpvals.progressive,
&tmpvals.subsmp,
&subsampling,
&tmpvals.baseline,
&tmpvals.restart,
&tmpvals.dct,
......@@ -1286,6 +1293,8 @@ load_save_defaults (void)
&tmpvals.save_thumbnail,
&tmpvals.save_xmp);
tmpvals.subsmp = subsampling;
if (num_fields == 12)
memcpy (&jsvals, &tmpvals, sizeof (tmpvals));
}
......@@ -1301,7 +1310,7 @@ save_defaults (void)
jsvals.smoothing,
jsvals.optimize,
jsvals.progressive,
jsvals.subsmp,
(gint) jsvals.subsmp,
jsvals.baseline,
jsvals.restart,
jsvals.dct,
......@@ -1384,11 +1393,16 @@ static void
subsampling_changed (GtkWidget *combo,
GtkObject *entry)
{
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo), &jsvals.subsmp);
gint value;
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo), &value);
jsvals.subsmp = value;
/* smoothing is not supported with nonstandard sampling ratios */
gimp_scale_entry_set_sensitive (entry,
jsvals.subsmp != 1 && jsvals.subsmp != 3);
jsvals.subsmp != JPEG_SUPSAMPLING_2x1_1x1_1x1 &&
jsvals.subsmp != JPEG_SUPSAMPLING_1x2_1x1_1x1);
make_preview ();
}
......
......@@ -18,19 +18,19 @@
typedef struct
{
gdouble quality;
gdouble smoothing;
gboolean optimize;
gboolean progressive;
gboolean baseline;
gint subsmp;
gint restart;
gint dct;
gboolean preview;
gboolean save_exif;
gboolean save_thumbnail;
gboolean save_xmp;
gboolean use_orig_quality;
gdouble quality;
gdouble smoothing;
gboolean optimize;
gboolean progressive;
gboolean baseline;
JpegSubsampling subsmp;
gint restart;
gint dct;
gboolean preview;
gboolean save_exif;
gboolean save_thumbnail;
gboolean save_xmp;
gboolean use_orig_quality;
} JpegSaveVals;
extern JpegSaveVals jsvals;
......
......@@ -45,15 +45,21 @@
#include "config.h"
#include <string.h>
#include <setjmp.h>
#include <glib/gstdio.h>
#include <jpeglib.h>
#ifdef HAVE_EXIF
#include <libexif/exif-data.h>
#endif /* HAVE_EXIF */
#include <libgimp/gimp.h>
#include "libgimp/stdplugins-intl.h"
#include "jpeg.h"
#include "jpeg-quality.h"
#include "jpeg-settings.h"
......@@ -163,10 +169,10 @@ jpeg_detect_original_settings (struct jpeg_decompress_struct *cinfo,
* Return Value: TRUE if a valid parasite was attached to the image
*/
gboolean
jpeg_restore_original_settings (gint32 image_ID,
gint *quality,
gint *subsmp,
gint *num_quant_tables)
jpeg_restore_original_settings (gint32 image_ID,
gint *quality,
JpegSubsampling *subsmp,
gint *num_quant_tables)
{
GimpParasite *parasite;
const guchar *src;
......@@ -219,24 +225,28 @@ jpeg_restore_original_settings (gint32 image_ID,
if (h[1] == 1 && v[1] == 1 && h[2] == 1 && v[2] == 1)
{
if (h[0] == 1 && v[0] == 1)
*subsmp = 2;
*subsmp = JPEG_SUPSAMPLING_1x1_1x1_1x1;
else if (h[0] == 2 && v[0] == 1)
*subsmp = 1;
*subsmp = JPEG_SUPSAMPLING_2x1_1x1_1x1;
else if (h[0] == 1 && v[0] == 2)
*subsmp = 3;
*subsmp = JPEG_SUPSAMPLING_1x2_1x1_1x1;
else if (h[0] == 2 && v[0] == 2)
*subsmp = 0;
*subsmp = JPEG_SUPSAMPLING_2x2_1x1_1x1;
}
}
gimp_parasite_free (parasite);
return TRUE;
}
}
gimp_parasite_free (parasite);
}
*quality = -1;
*subsmp = -1;
*num_quant_tables = 0;
return FALSE;
}
......
......@@ -20,14 +20,14 @@
*/
gboolean jpeg_detect_original_settings (struct jpeg_decompress_struct *cinfo,
gint32 image_ID);
gint32 image_ID);
gboolean jpeg_restore_original_settings (gint32 image_ID,
gint *quality,
gint *subsmp,
gint *num_quant_tables);
gboolean jpeg_restore_original_settings (gint32 image_ID,
gint *quality,
JpegSubsampling *subsmp,
gint *num_quant_tables);
guint **jpeg_restore_original_tables (gint32 image_ID,
gint num_quant_tables);
guint **jpeg_restore_original_tables (gint32 image_ID,
gint num_quant_tables);
void jpeg_swap_original_settings (gint32 image_ID);
void jpeg_swap_original_settings (gint32 image_ID);
......@@ -51,21 +51,21 @@ static void run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
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;
gint orig_subsmp;
gint num_quant_tables;
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;
#ifdef HAVE_EXIF
ExifData *exif_data = NULL;
ExifData *exif_data = NULL;
#endif
const GimpPlugInInfo PLUG_IN_INFO =
......@@ -213,7 +213,7 @@ run (const gchar *name,
has_metadata = FALSE;
orig_quality = 0;
orig_subsmp = 0;
orig_subsmp = JPEG_SUPSAMPLING_2x2_1x1_1x1;
num_quant_tables = 0;
if (strcmp (name, LOAD_PROC) == 0)
......@@ -441,7 +441,9 @@ run (const gchar *name,
jsvals.use_orig_quality = TRUE;
}
if (orig_subsmp == 2 || (orig_subsmp > 0 && jsvals.subsmp == 0))
if (orig_subsmp == JPEG_SUPSAMPLING_1x1_1x1_1x1 ||
(orig_subsmp > JPEG_SUPSAMPLING_1x1_1x1_1x1 &&
jsvals.subsmp == JPEG_SUPSAMPLING_1x1_1x1_1x1))
jsvals.subsmp = orig_subsmp;
}
break;
......
......@@ -40,6 +40,13 @@ typedef struct my_error_mgr
jmp_buf setjmp_buffer; /* for return to caller */
} *my_error_ptr;
typedef enum
{
JPEG_SUPSAMPLING_2x2_1x1_1x1 = 0, /* smallest file */
JPEG_SUPSAMPLING_2x1_1x1_1x1 = 1, /* 4:2:2 */
JPEG_SUPSAMPLING_1x1_1x1_1x1 = 2,
JPEG_SUPSAMPLING_1x2_1x1_1x1 = 3
} JpegSubsampling;
extern gint32 volatile preview_image_ID;
extern gint32 preview_layer_ID;
......@@ -50,7 +57,7 @@ extern gint32 display_ID;
extern gchar *image_comment;
extern gboolean has_metadata;
extern gint orig_quality;
extern gint orig_subsmp;
extern JpegSubsampling orig_subsmp;
extern gint num_quant_tables;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment