[gimp] file-tiff-save: GEGL convert TIFF saving code



commit df10419a162d3c486af012feabb4b6524b69d877
Author: Mukund Sivaraman <muks banu com>
Date:   Mon May 13 18:22:32 2013 +0530

    file-tiff-save: GEGL convert TIFF saving code

 plug-ins/common/Makefile.am      |    1 +
 plug-ins/common/file-tiff-save.c |   44 +++++++++++++++++++++++--------------
 plug-ins/common/plugin-defs.pl   |    2 +-
 3 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 5496d80..d6db081 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -1511,6 +1511,7 @@ file_tiff_save_LDADD = \
        $(libgimpcolor)         \
        $(libgimpbase)          \
        $(GTK_LIBS)             \
+       $(GEGL_LIBS)            \
        $(TIFF_LIBS)            \
        $(RT_LIBS)              \
        $(INTLLIBS)             \
diff --git a/plug-ins/common/file-tiff-save.c b/plug-ins/common/file-tiff-save.c
index 8a6ee4c..14bd929 100644
--- a/plug-ins/common/file-tiff-save.c
+++ b/plug-ins/common/file-tiff-save.c
@@ -226,6 +226,7 @@ run (const gchar      *name,
   run_mode = param[0].data.d_int32;
 
   INIT_I18N ();
+  gegl_init (NULL, NULL);
 
   *nreturn_vals = 1;
   *return_vals  = values;
@@ -658,6 +659,7 @@ save_image (const gchar  *filename,
             gint32        orig_image,  /* the export function might have */
             GError      **error)       /* created a duplicate            */
 {
+  gboolean       status = FALSE;
   TIFF          *tif;
   gushort        red[256];
   gushort        grn[256];
@@ -672,13 +674,14 @@ save_image (const gchar  *filename,
   gshort         samplesperpixel;
   gshort         bitspersample;
   gint           bytesperrow;
-  guchar        *t, *src, *data;
+  guchar        *t;
+  guchar        *src = NULL;
+  guchar        *data = NULL;
   guchar        *cmap;
   gint           num_colors;
   gint           success;
-  GimpDrawable  *drawable;
   GimpImageType  drawable_type;
-  GimpPixelRgn   pixel_rgn;
+  GeglBuffer    *buffer = NULL;
   gint           tile_height;
   gint           y, yend;
   gboolean       is_bw    = FALSE;
@@ -707,7 +710,7 @@ save_image (const gchar  *filename,
         g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                      _("Could not open '%s' for writing: %s"),
                      gimp_filename_to_utf8 (filename), g_strerror (errno));
-      return FALSE;
+      goto out;
     }
 
   TIFFSetWarningHandler (tiff_warning);
@@ -716,15 +719,11 @@ save_image (const gchar  *filename,
   gimp_progress_init_printf (_("Saving '%s'"),
                              gimp_filename_to_utf8 (filename));
 
-  drawable = gimp_drawable_get (layer);
   drawable_type = gimp_drawable_type (layer);
-  gimp_pixel_rgn_init (&pixel_rgn, drawable,
-                       0, 0, drawable->width, drawable->height, FALSE, FALSE);
+  buffer = gimp_drawable_get_buffer (layer);
 
-  cols = drawable->width;
-  rows = drawable->height;
-
-  gimp_tile_cache_ntiles (1 + drawable->width / gimp_tile_width ());
+  cols = gegl_buffer_get_width (buffer);
+  rows = gegl_buffer_get_height (buffer);
 
   switch (drawable_type)
     {
@@ -808,7 +807,7 @@ save_image (const gchar  *filename,
                    _("TIFF save cannot handle indexed images with "
                      "an alpha channel."));
     default:
-      return FALSE;
+      goto out;
     }
 
   if (compression == COMPRESSION_CCITTFAX3 ||
@@ -818,7 +817,7 @@ save_image (const gchar  *filename,
         {
           g_message (_("Only monochrome pictures can be compressed with "
                        "\"CCITT Group 4\" or \"CCITT Group 3\"."));
-          return FALSE;
+          goto out;
         }
     }
 
@@ -969,7 +968,13 @@ save_image (const gchar  *filename,
       yend = y + tile_height;
       yend = MIN (yend, rows);
 
-      gimp_pixel_rgn_get_rect (&pixel_rgn, src, 0, y, cols, yend - y);
+      gegl_buffer_get (buffer,
+                       GEGL_RECTANGLE (0, y, cols, yend - y),
+                       1.0,
+                       NULL,
+                       src,
+                       GEGL_AUTO_ROWSTRIDE,
+                       GEGL_ABYSS_NONE);
 
       for (row = y; row < yend; row++)
         {
@@ -1047,7 +1052,7 @@ save_image (const gchar  *filename,
           if (!success)
             {
               g_message (_("Failed a scanline write on row %d"), row);
-              return FALSE;
+              goto out;
             }
         }
 
@@ -1060,11 +1065,16 @@ save_image (const gchar  *filename,
 
   gimp_progress_update (1.0);
 
-  gimp_drawable_detach (drawable);
+  status = TRUE;
+
+ out:
+  if (buffer)
+    g_object_unref (buffer);
+
   g_free (data);
   g_free (src);
 
-  return TRUE;
+  return status;
 }
 
 static gboolean
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index c34bb11..00f345a 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -73,7 +73,7 @@
     'file-svg' => { ui => 1, optional => 1, libs => 'SVG_LIBS', cflags => 'SVG_CFLAGS' },
     'file-tga' => { ui => 1, gegl => 1 },
     'file-tiff-load' => { ui => 1, gegl => 1, optional => 1, libs => 'TIFF_LIBS' },
-    'file-tiff-save' => { ui => 1, optional => 1, libs => 'TIFF_LIBS' },
+    'file-tiff-save' => { ui => 1, gegl => 1, optional => 1, libs => 'TIFF_LIBS' },
     'file-wmf' => { ui => 1, optional => 1, libs => 'WMF_LIBS', cflags => 'WMF_CFLAGS' },
     'file-xbm' => { ui => 1, gegl => 1 },
     'file-xmc' => { ui => 1, optional => 1, libs => 'XMC_LIBS' },


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