gimp r27056 - in trunk: . plug-ins/file-jpeg



Author: neo
Date: Thu Sep 25 14:30:02 2008
New Revision: 27056
URL: http://svn.gnome.org/viewvc/gimp?rev=27056&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/plug-ins/file-jpeg/jpeg-save.c
   trunk/plug-ins/file-jpeg/jpeg-save.h
   trunk/plug-ins/file-jpeg/jpeg-settings.c
   trunk/plug-ins/file-jpeg/jpeg-settings.h
   trunk/plug-ins/file-jpeg/jpeg.c
   trunk/plug-ins/file-jpeg/jpeg.h

Modified: trunk/plug-ins/file-jpeg/jpeg-save.c
==============================================================================
--- trunk/plug-ins/file-jpeg/jpeg-save.c	(original)
+++ trunk/plug-ins/file-jpeg/jpeg-save.c	Thu Sep 25 14:30:02 2008
@@ -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 @@
   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 @@
 
   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 @@
 
   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 @@
       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 @@
       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 @@
       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 @@
   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 @@
 
   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 @@
   gchar        *def_str;
   JpegSaveVals  tmpvals;
   gint          num_fields;
+  gint          subsampling;
 
   jsvals.quality          = DEFAULT_QUALITY;
   jsvals.smoothing        = DEFAULT_SMOOTHING;
@@ -1277,7 +1284,7 @@
                        &tmpvals.smoothing,
                        &tmpvals.optimize,
                        &tmpvals.progressive,
-                       &tmpvals.subsmp,
+                       &subsampling,
                        &tmpvals.baseline,
                        &tmpvals.restart,
                        &tmpvals.dct,
@@ -1286,6 +1293,8 @@
                        &tmpvals.save_thumbnail,
                        &tmpvals.save_xmp);
 
+  tmpvals.subsmp = subsampling;
+
   if (num_fields == 12)
     memcpy (&jsvals, &tmpvals, sizeof (tmpvals));
 }
@@ -1301,7 +1310,7 @@
                              jsvals.smoothing,
                              jsvals.optimize,
                              jsvals.progressive,
-                             jsvals.subsmp,
+                             (gint) jsvals.subsmp,
                              jsvals.baseline,
                              jsvals.restart,
                              jsvals.dct,
@@ -1384,11 +1393,16 @@
 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 ();
 }

Modified: trunk/plug-ins/file-jpeg/jpeg-save.h
==============================================================================
--- trunk/plug-ins/file-jpeg/jpeg-save.h	(original)
+++ trunk/plug-ins/file-jpeg/jpeg-save.h	Thu Sep 25 14:30:02 2008
@@ -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;

Modified: trunk/plug-ins/file-jpeg/jpeg-settings.c
==============================================================================
--- trunk/plug-ins/file-jpeg/jpeg-settings.c	(original)
+++ trunk/plug-ins/file-jpeg/jpeg-settings.c	Thu Sep 25 14:30:02 2008
@@ -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 @@
  * 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 @@
                   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;
 }
 

Modified: trunk/plug-ins/file-jpeg/jpeg-settings.h
==============================================================================
--- trunk/plug-ins/file-jpeg/jpeg-settings.h	(original)
+++ trunk/plug-ins/file-jpeg/jpeg-settings.h	Thu Sep 25 14:30:02 2008
@@ -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);

Modified: trunk/plug-ins/file-jpeg/jpeg.c
==============================================================================
--- trunk/plug-ins/file-jpeg/jpeg.c	(original)
+++ trunk/plug-ins/file-jpeg/jpeg.c	Thu Sep 25 14:30:02 2008
@@ -51,21 +51,21 @@
                     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 @@
 
   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 @@
                   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;

Modified: trunk/plug-ins/file-jpeg/jpeg.h
==============================================================================
--- trunk/plug-ins/file-jpeg/jpeg.h	(original)
+++ trunk/plug-ins/file-jpeg/jpeg.h	Thu Sep 25 14:30:02 2008
@@ -40,6 +40,13 @@
   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 gchar           *image_comment;
 extern gboolean         has_metadata;
 extern gint             orig_quality;
-extern gint             orig_subsmp;
+extern JpegSubsampling  orig_subsmp;
 extern gint             num_quant_tables;
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]