[gimp/wip/Jehan/classy-GIMP: 57/57] plug-ins: port file-tiff to GimpImage|Drawable|Vectors, etc.



commit 39d403b6b3fb75ddcc14313bf5abaab0d5ec3fca
Author: Jehan <jehan girinstud io>
Date:   Sat Aug 17 10:52:05 2019 +0200

    plug-ins: port file-tiff to GimpImage|Drawable|Vectors, etc.

 plug-ins/file-tiff/Makefile.am      |  1 -
 plug-ins/file-tiff/file-tiff-load.c | 81 ++++++++++++++++++-------------------
 plug-ins/file-tiff/file-tiff-load.h |  2 +-
 plug-ins/file-tiff/file-tiff-save.c | 69 ++++++++++++++++---------------
 plug-ins/file-tiff/file-tiff-save.h |  4 +-
 plug-ins/file-tiff/file-tiff.c      | 53 ++++++++++++------------
 6 files changed, 107 insertions(+), 103 deletions(-)
---
diff --git a/plug-ins/file-tiff/Makefile.am b/plug-ins/file-tiff/Makefile.am
index 7c669f832a..8969040675 100644
--- a/plug-ins/file-tiff/Makefile.am
+++ b/plug-ins/file-tiff/Makefile.am
@@ -22,7 +22,6 @@ AM_LDFLAGS = $(mwindows)
 libexecdir = $(gimpplugindir)/plug-ins/file-tiff
 
 AM_CPPFLAGS = \
-       -DGIMP_DEPRECATED_REPLACE_NEW_API \
        -I$(top_srcdir)         \
        $(GTK_CFLAGS)           \
        $(EXIF_CFLAGS)          \
diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c
index fb457384b2..83765a709d 100644
--- a/plug-ins/file-tiff/file-tiff-load.c
+++ b/plug-ins/file-tiff/file-tiff-load.c
@@ -70,11 +70,11 @@ typedef struct
 
 typedef struct
 {
-  gint32      ID;
-  GeglBuffer *buffer;
-  const Babl *format;
-  guchar     *pixels;
-  guchar     *pixel;
+  GimpDrawable *drawable;
+  GeglBuffer   *buffer;
+  const Babl   *format;
+  guchar       *pixels;
+  guchar       *pixel;
 } ChannelData;
 
 typedef enum
@@ -105,7 +105,7 @@ static void               load_separate    (TIFF              *tif,
                                             gboolean           is_bw,
                                             gint               extra);
 static void               load_paths       (TIFF              *tif,
-                                            gint               image,
+                                            GimpImage         *image,
                                             gint               width,
                                             gint               height,
                                             gint               offset_x,
@@ -149,7 +149,7 @@ tiff_get_page_name (TIFF *tif)
 GimpPDBStatusType
 load_image (GFile        *file,
             GimpRunMode   run_mode,
-            gint32       *image,
+            GimpImage   **image,
             gboolean     *resolution_loaded,
             gboolean     *profile_loaded,
             GError      **error)
@@ -166,7 +166,7 @@ load_image (GFile        *file,
   gint               max_col          = 0;
   gint               li;
 
-  *image = 0;
+  *image = NULL;
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
@@ -315,7 +315,7 @@ load_image (GFile        *file,
       gint              rows;
       gboolean          alpha;
       gint              image_type           = GIMP_RGB;
-      gint              layer;
+      GimpLayer        *layer;
       gint              layer_type           = GIMP_RGB_IMAGE;
       float             layer_offset_x       = 0.0;
       float             layer_offset_y       = 0.0;
@@ -796,7 +796,7 @@ load_image (GFile        *file,
           *image = gimp_image_new_with_precision (cols, rows, image_type,
                                                   image_precision);
 
-          if (*image < 1)
+          if (! *image)
             {
               TIFFClose (tif);
               g_message ("Could not create a new image: %s",
@@ -814,8 +814,7 @@ load_image (GFile        *file,
               gimp_image_set_filename (*image, fname);
               g_free (fname);
 
-              images_list = g_list_prepend (images_list,
-                                            GINT_TO_POINTER (*image));
+              images_list = g_list_prepend (images_list, *image);
             }
           else if (pages.o_pages != pages.n_pages)
             {
@@ -1047,18 +1046,18 @@ load_image (GFile        *file,
           /* can't create the palette format here, need to get it from
            * an existing layer
            */
-          base_format = gimp_drawable_get_format (layer);
+          base_format = gimp_drawable_get_format (GIMP_DRAWABLE (layer));
         }
       else
         {
           base_format =
             babl_format_with_space (babl_format_get_encoding (base_format),
-                                    gimp_drawable_get_format (layer));
+                                    gimp_drawable_get_format (GIMP_DRAWABLE (layer)));
         }
 
-      channel[0].ID     = layer;
-      channel[0].buffer = gimp_drawable_get_buffer (layer);
-      channel[0].format = base_format;
+      channel[0].drawable = GIMP_DRAWABLE (layer);
+      channel[0].buffer   = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
+      channel[0].format   = base_format;
 
       if (extra > 0 && ! worst_case)
         {
@@ -1069,11 +1068,11 @@ load_image (GFile        *file,
 
               gimp_rgb_set (&color, 0.0, 0.0, 0.0);
 
-              channel[i].ID = gimp_channel_new (*image, _("TIFF Channel"),
-                                                cols, rows,
-                                                100.0, &color);
-              gimp_image_insert_channel (*image, channel[i].ID, -1, 0);
-              channel[i].buffer = gimp_drawable_get_buffer (channel[i].ID);
+              channel[i].drawable = GIMP_DRAWABLE (gimp_channel_new (*image, _("TIFF Channel"),
+                                                                     cols, rows,
+                                                                     100.0, &color));
+              gimp_image_insert_channel (*image, GIMP_CHANNEL (channel[i].drawable), NULL, 0);
+              channel[i].buffer = gimp_drawable_get_buffer (channel[i].drawable);
 
               /* Unlike color channels, we don't care about the source
                * TRC for extra channels. We just want to import them
@@ -1140,13 +1139,13 @@ load_image (GFile        *file,
             }
 
           if (flip_horizontal)
-            gimp_item_transform_flip_simple (layer,
+            gimp_item_transform_flip_simple (GIMP_ITEM (layer),
                                              GIMP_ORIENTATION_HORIZONTAL,
                                              TRUE /* auto_center */,
                                              -1.0 /* axis */);
 
           if (flip_vertical)
-            gimp_item_transform_flip_simple (layer,
+            gimp_item_transform_flip_simple (GIMP_ITEM (layer),
                                              GIMP_ORIENTATION_VERTICAL,
                                              TRUE /* auto_center */,
                                              -1.0 /* axis */);
@@ -1184,7 +1183,7 @@ load_image (GFile        *file,
             }
         }
 
-      gimp_image_insert_layer (*image, layer, -1, -1);
+      gimp_image_insert_layer (*image, layer, NULL, -1);
 
       if (pages.target == GIMP_PAGE_SELECTOR_TARGET_IMAGES)
         {
@@ -1201,14 +1200,14 @@ load_image (GFile        *file,
 
       if (list)
         {
-          *image = GPOINTER_TO_INT (list->data);
+          *image = list->data;
 
           list = g_list_next (list);
         }
 
       for (; list; list = g_list_next (list))
         {
-          gimp_display_new (GPOINTER_TO_INT (list->data));
+          gimp_display_new (list->data);
         }
 
       g_list_free (images_list);
@@ -1308,12 +1307,12 @@ load_rgba (TIFF        *tif,
 }
 
 static void
-load_paths (TIFF *tif,
-            gint  image,
-            gint  width,
-            gint  height,
-            gint  offset_x,
-            gint  offset_y)
+load_paths (TIFF      *tif,
+            GimpImage *image,
+            gint       width,
+            gint       height,
+            gint       offset_x,
+            gint       offset_y)
 {
   gsize  n_bytes;
   gchar *bytes;
@@ -1387,16 +1386,16 @@ load_paths (TIFF *tif,
       if (id >= 2000 && id <= 2998)
         {
           /* path information */
-          guint16   type;
-          gint      rec = pos;
-          gint32    vectors;
-          gdouble  *points          = NULL;
-          gint      expected_points = 0;
-          gint      pointcount      = 0;
-          gboolean  closed          = FALSE;
+          guint16      type;
+          gint         rec = pos;
+          GimpVectors *vectors;
+          gdouble     *points          = NULL;
+          gint         expected_points = 0;
+          gint         pointcount      = 0;
+          gboolean     closed          = FALSE;
 
           vectors = gimp_vectors_new (image, name);
-          gimp_image_insert_vectors (image, vectors, -1, path_index);
+          gimp_image_insert_vectors (image, vectors, NULL, path_index);
           path_index++;
 
           while (rec < pos + len)
diff --git a/plug-ins/file-tiff/file-tiff-load.h b/plug-ins/file-tiff/file-tiff-load.h
index 19dc0c7d64..c94f881d79 100644
--- a/plug-ins/file-tiff/file-tiff-load.h
+++ b/plug-ins/file-tiff/file-tiff-load.h
@@ -36,7 +36,7 @@ typedef struct
 
 GimpPDBStatusType load_image  (GFile        *file,
                                GimpRunMode   run_mode,
-                               gint32       *image,
+                               GimpImage   **image,
                                gboolean     *resolution_loaded,
                                gboolean     *profile_loaded,
                                GError      **error);
diff --git a/plug-ins/file-tiff/file-tiff-save.c b/plug-ins/file-tiff/file-tiff-save.c
index ae07e3b53a..76fe29d442 100644
--- a/plug-ins/file-tiff/file-tiff-save.c
+++ b/plug-ins/file-tiff/file-tiff-save.c
@@ -63,7 +63,7 @@
 
 
 static gboolean  save_paths             (TIFF          *tif,
-                                         gint32         image,
+                                         GimpImage     *image,
                                          gdouble        width,
                                          gdouble        height,
                                          gint           offset_x,
@@ -78,7 +78,7 @@ static void      byte2bit               (const guchar  *byteline,
                                          gboolean       invert);
 
 static void      save_thumbnail         (TiffSaveVals  *tsvals,
-                                         gint32         image,
+                                         GimpImage     *image,
                                          TIFF          *tif);
 
 
@@ -106,27 +106,29 @@ double_to_psd_fixed (gdouble  value,
 }
 
 static gboolean
-save_paths (TIFF    *tif,
-            gint32   image,
-            gdouble  width,
-            gdouble  height,
-            gint     offset_x,
-            gint     offset_y)
+save_paths (TIFF      *tif,
+            GimpImage *image,
+            gdouble    width,
+            gdouble    height,
+            gint       offset_x,
+            gint       offset_y)
 {
   gint id = 2000; /* Photoshop paths have IDs >= 2000 */
-  gint num_vectors, *vectors, v;
+  GList *vectors;
+  GList *iter;
+  gint   v;
   gint num_strokes, *strokes, s;
   GString *ps_tag;
 
-  vectors = gimp_image_get_vectors (image, &num_vectors);
+  vectors = gimp_image_get_vectors (image);
 
-  if (num_vectors <= 0)
+  if (! vectors)
     return FALSE;
 
   ps_tag = g_string_new ("");
 
   /* Only up to 1000 paths supported */
-  for (v = 0; v < MIN (num_vectors, 1000); v++)
+  for (iter = vectors, v = 0; iter && v < 1000; iter = iter->next, v++)
     {
       GString *data;
       gchar   *name, *nameend;
@@ -144,7 +146,7 @@ save_paths (TIFF    *tif,
        * - use iso8859-1 if possible
        * - otherwise use UTF-8, prepended with \xef\xbb\xbf (Byte-Order-Mark)
        */
-      name = gimp_item_get_name (vectors[v]);
+      name = gimp_item_get_name (iter->data);
       tmpname = g_convert (name, -1, "iso8859-1", "utf-8", NULL, &len, &err);
 
       if (tmpname && err == NULL)
@@ -181,7 +183,7 @@ save_paths (TIFF    *tif,
       pointrecord[1] = 6;  /* fill rule record */
       g_string_append_len (data, pointrecord, 26);
 
-      strokes = gimp_vectors_get_strokes (vectors[v], &num_strokes);
+      strokes = gimp_vectors_get_strokes (iter->data, &num_strokes);
 
       for (s = 0; s < num_strokes; s++)
         {
@@ -191,7 +193,7 @@ save_paths (TIFF    *tif,
           gboolean  closed;
           gint      p = 0;
 
-          type = gimp_vectors_stroke_get_points (vectors[v], strokes[s],
+          type = gimp_vectors_stroke_get_points (iter->data, strokes[s],
                                                  &num_points, &points, &closed);
 
           if (type != GIMP_VECTORS_STROKE_TYPE_BEZIER ||
@@ -242,7 +244,7 @@ save_paths (TIFF    *tif,
   TIFFSetField (tif, TIFFTAG_PHOTOSHOP, ps_tag->len, ps_tag->str);
   g_string_free (ps_tag, TRUE);
 
-  g_free (vectors);
+  g_list_free (vectors);
 
   return TRUE;
 }
@@ -268,11 +270,11 @@ static gboolean
 save_layer (TIFF         *tif,
             TiffSaveVals *tsvals,
             const Babl   *space,
-            gint32        image,
-            gint32        layer,
+            GimpImage    *image,
+            GimpLayer    *layer,
             gint32        page,
             gint32        num_pages,
-            gint32        orig_image, /* the export function might */
+            GimpImage    *orig_image, /* the export function might */
                                       /* have created a duplicate  */
             gint         *saved_bpp,
             gboolean      out_linear,
@@ -318,7 +320,7 @@ save_layer (TIFF         *tif,
 
   compression = tsvals->compression;
 
-  layer_name = gimp_item_get_name (layer);
+  layer_name = gimp_item_get_name (GIMP_ITEM (layer));
 
   /* Disabled because this isn't in older releases of libtiff, and it
    * wasn't helping much anyway
@@ -332,8 +334,8 @@ save_layer (TIFF         *tif,
   tile_height = gimp_tile_height ();
   rowsperstrip = tile_height;
 
-  drawable_type = gimp_drawable_type (layer);
-  buffer        = gimp_drawable_get_buffer (layer);
+  drawable_type = gimp_drawable_type (GIMP_DRAWABLE (layer));
+  buffer        = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
 
   format = gegl_buffer_get_format (buffer);
   type   = babl_format_get_type (format, 0);
@@ -582,7 +584,7 @@ save_layer (TIFF         *tif,
       samplesperpixel = (drawable_type == GIMP_INDEXEDA_IMAGE) ? 2 : 1;
       bytesperrow     = cols;
       alpha           = (drawable_type == GIMP_INDEXEDA_IMAGE);
-      format          = gimp_drawable_get_format (layer);
+      format          = gimp_drawable_get_format (GIMP_DRAWABLE (layer));
 
       g_free (cmap);
       break;
@@ -683,7 +685,7 @@ save_layer (TIFF         *tif,
       TIFFSetField (tif, TIFFTAG_RESOLUTIONUNIT, save_unit);
     }
 
-  gimp_drawable_offsets (layer, &offset_x, &offset_y);
+  gimp_drawable_offsets (GIMP_DRAWABLE (layer), &offset_x, &offset_y);
 
   if (offset_x || offset_y)
     {
@@ -777,7 +779,7 @@ out:
 
 static void
 save_thumbnail (TiffSaveVals *tsvals,
-                gint32        image,
+                GimpImage    *image,
                 TIFF         *tif)
 {
   /* now switch IFD and write thumbnail
@@ -860,7 +862,7 @@ save_thumbnail (TiffSaveVals *tsvals,
 static void
 save_metadata (GFile                 *file,
                TiffSaveVals          *tsvals,
-               gint32                 image,
+               GimpImage             *image,
                GimpMetadata          *metadata,
                GimpMetadataSaveFlags  metadata_flags,
                gint                   saved_bpp)
@@ -942,8 +944,8 @@ save_metadata (GFile                 *file,
 gboolean
 save_image (GFile                  *file,
             TiffSaveVals           *tsvals,
-            gint32                  image,
-            gint32                  orig_image,    /* the export function */
+            GimpImage              *image,
+            GimpImage              *orig_image,    /* the export function */
                                                    /* might have created  */
                                                    /* a duplicate         */
             const gchar            *image_comment,
@@ -958,9 +960,11 @@ save_image (GFile                  *file,
   gboolean    out_linear          = FALSE;
   gint        number_of_sub_IFDs  = 1;
   toff_t      sub_IFDs_offsets[1] = { 0UL };
-  gint32      num_layers, *layers, current_layer = 0;
+  gint32      num_layers, current_layer = 0;
+  GList      *layers;
 
-  layers = gimp_image_get_layers (image, &num_layers);
+  layers = gimp_image_get_layers (image);
+  num_layers = g_list_length (layers);
 
   gimp_progress_init_printf (_("Exporting '%s'"),
                              gimp_file_get_utf8_name (file));
@@ -1055,7 +1059,7 @@ save_image (GFile                  *file,
 
   /* write last layer as first page. */
   if (! save_layer (tif,  tsvals, space, image,
-                    layers[num_layers - current_layer - 1],
+                    g_list_nth_data (layers, num_layers - current_layer - 1),
                     current_layer, num_layers,
                     orig_image, saved_bpp, out_linear, error))
     {
@@ -1096,7 +1100,7 @@ save_image (GFile                  *file,
         {
           gint tmp_saved_bpp;
           if (! save_layer (tif,  tsvals, space, image,
-                            layers[num_layers - current_layer - 1],
+                            g_list_nth_data (layers, num_layers - current_layer - 1),
                             current_layer, num_layers, orig_image,
                             &tmp_saved_bpp, out_linear, error))
             {
@@ -1128,6 +1132,7 @@ save_image (GFile                  *file,
   status = TRUE;
 
 out:
+  g_list_free (layers);
   return status;
 }
 
diff --git a/plug-ins/file-tiff/file-tiff-save.h b/plug-ins/file-tiff/file-tiff-save.h
index 0a8762c4c6..129263153b 100644
--- a/plug-ins/file-tiff/file-tiff-save.h
+++ b/plug-ins/file-tiff/file-tiff-save.h
@@ -39,8 +39,8 @@ typedef struct
 
 gboolean  save_image  (GFile                  *file,
                        TiffSaveVals           *tsvals,
-                       gint32                  image,
-                       gint32                  orig_image,
+                       GimpImage              *image,
+                       GimpImage              *orig_image,
                        const gchar            *image_comment,
                        gint                   *saved_bpp,
                        GimpMetadata           *metadata,
diff --git a/plug-ins/file-tiff/file-tiff.c b/plug-ins/file-tiff/file-tiff.c
index 1fbe378080..e0a1a92b29 100644
--- a/plug-ins/file-tiff/file-tiff.c
+++ b/plug-ins/file-tiff/file-tiff.c
@@ -81,23 +81,23 @@ GType                   tiff_get_type         (void) G_GNUC_CONST;
 
 static GList          * tiff_query_procedures (GimpPlugIn           *plug_in);
 static GimpProcedure  * tiff_create_procedure (GimpPlugIn           *plug_in,
-                                              const gchar          *name);
+                                               const gchar          *name);
 
 static GimpValueArray * tiff_load             (GimpProcedure        *procedure,
-                                              GimpRunMode           run_mode,
-                                              GFile                *file,
-                                              const GimpValueArray *args,
-                                              gpointer              run_data);
+                                               GimpRunMode           run_mode,
+                                               GFile                *file,
+                                               const GimpValueArray *args,
+                                               gpointer              run_data);
 static GimpValueArray * tiff_save             (GimpProcedure        *procedure,
-                                              GimpRunMode           run_mode,
-                                              gint32                image,
-                                              gint32                drawable,
-                                              GFile                *file,
-                                              const GimpValueArray *args,
-                                              gpointer              run_data);
+                                               GimpRunMode           run_mode,
+                                               GimpImage            *image,
+                                               GimpDrawable         *drawable,
+                                               GFile                *file,
+                                               const GimpValueArray *args,
+                                               gpointer              run_data);
 
-static gboolean         image_is_monochrome  (gint32                image);
-static gboolean         image_is_multi_layer (gint32                image);
+static gboolean         image_is_monochrome  (GimpImage            *image);
+static gboolean         image_is_multi_layer (GimpImage            *image);
 
 
 G_DEFINE_TYPE (Tiff, tiff, GIMP_TYPE_PLUG_IN)
@@ -243,7 +243,7 @@ tiff_load (GimpProcedure        *procedure,
 {
   GimpValueArray    *return_vals;
   GimpPDBStatusType  status;
-  gint32             image             = 0;
+  GimpImage         *image             = NULL;
   gboolean           resolution_loaded = FALSE;
   gboolean           profile_loaded    = FALSE;
   GimpMetadata      *metadata;
@@ -260,7 +260,7 @@ tiff_load (GimpProcedure        *procedure,
                        &profile_loaded,
                        &error);
 
-  if (image < 1)
+  if (!image)
     return gimp_procedure_new_return_values (procedure, status, error);
 
   metadata = gimp_image_metadata_load_prepare (image,
@@ -288,8 +288,8 @@ tiff_load (GimpProcedure        *procedure,
                                                   GIMP_PDB_SUCCESS,
                                                   NULL);
 
-  gimp_value_set_image_id (gimp_value_array_index (return_vals, 1),
-                           image);
+  g_value_set_object (gimp_value_array_index (return_vals, 1),
+                      image);
 
   return return_vals;
 }
@@ -297,8 +297,8 @@ tiff_load (GimpProcedure        *procedure,
 static GimpValueArray *
 tiff_save (GimpProcedure        *procedure,
           GimpRunMode           run_mode,
-          gint32                image,
-          gint32                drawable,
+          GimpImage            *image,
+          GimpDrawable         *drawable,
           GFile                *file,
           const GimpValueArray *args,
           gpointer              run_data)
@@ -307,7 +307,7 @@ tiff_save (GimpProcedure        *procedure,
   GimpMetadata          *metadata;
   GimpMetadataSaveFlags  metadata_flags;
   GimpParasite          *parasite;
-  gint32                 orig_image = image;
+  GimpImage             *orig_image = image;
   GimpExportReturn       export     = GIMP_EXPORT_CANCEL;
   GError                *error      = NULL;
 
@@ -470,13 +470,13 @@ tiff_save (GimpProcedure        *procedure,
 }
 
 static gboolean
-image_is_monochrome (gint32 image)
+image_is_monochrome (GimpImage *image)
 {
   guchar   *colors;
   gint      num_colors;
   gboolean  monochrome = FALSE;
 
-  g_return_val_if_fail (image != -1, FALSE);
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
 
   colors = gimp_image_get_colormap (image, &num_colors);
 
@@ -501,13 +501,14 @@ image_is_monochrome (gint32 image)
 }
 
 static gboolean
-image_is_multi_layer (gint32 image)
+image_is_multi_layer (GimpImage *image)
 {
-  gint32 *layers;
+  GList  *layers;
   gint32  n_layers;
 
-  layers = gimp_image_get_layers (image, &n_layers);
-  g_free (layers);
+  layers = gimp_image_get_layers (image);
+  n_layers = g_list_length (layers);
+  g_list_free (layers);
 
   return (n_layers > 1);
 }


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