[gimp] libgimp: add GimpThumbnailProceudre
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: add GimpThumbnailProceudre
- Date: Mon, 19 Aug 2019 12:05:09 +0000 (UTC)
commit c4a973c30af1433ead72f28469b6a711f754dff1
Author: Michael Natterer <mitch gimp org>
Date: Mon Aug 19 14:02:34 2019 +0200
libgimp: add GimpThumbnailProceudre
which handles the standard thmbnail procedure args and return values.
libgimp/Makefile.gi | 6 +-
libgimp/gimp.def | 4 +
libgimp/gimp.h | 1 +
libgimp/gimpthumbnailprocedure.c | 239 +++++++++++++++++++++++++++++++++++++++
libgimp/gimpthumbnailprocedure.h | 91 +++++++++++++++
5 files changed, 339 insertions(+), 2 deletions(-)
---
diff --git a/libgimp/Makefile.gi b/libgimp/Makefile.gi
index d8f20b493c..fc982dcfd9 100644
--- a/libgimp/Makefile.gi
+++ b/libgimp/Makefile.gi
@@ -129,7 +129,8 @@ libgimp_introspectable_headers = \
../libgimp/gimpprocedure.h \
../libgimp/gimpprogress.h \
../libgimp/gimpsaveprocedure.h \
- ../libgimp/gimpselection.h
+ ../libgimp/gimpselection.h \
+ ../libgimp/gimpthumbnailprocedure.h
libgimp_introspectable = \
$(libgimp_introspectable_headers) \
@@ -156,7 +157,8 @@ libgimp_introspectable = \
../libgimp/gimpprocedure.c \
../libgimp/gimpprogress.c \
../libgimp/gimpsaveprocedure.c \
- ../libgimp/gimpselection.c
+ ../libgimp/gimpselection.c \
+ ../libgimp/gimpthumbnailprocedure.c
libgimpui_introspectable_headers = \
../libgimp/gimpui.h \
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 346dea45dc..55888ec180 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -431,6 +431,8 @@ EXPORTS
gimp_image_new_with_precision
gimp_image_pick_color
gimp_image_pick_correlate_layer
+ gimp_image_procedure_get_type
+ gimp_image_procedure_new
gimp_image_raise_item
gimp_image_raise_item_to_top
gimp_image_remove_channel
@@ -760,6 +762,8 @@ EXPORTS
gimp_text_layer_set_letter_spacing
gimp_text_layer_set_line_spacing
gimp_text_layer_set_text
+ gimp_thumbnail_procedure_get_type
+ gimp_thumbnail_procedure_new
gimp_tile_height
gimp_tile_width
gimp_user_time
diff --git a/libgimp/gimp.h b/libgimp/gimp.h
index a23ca58ced..46e14f8473 100644
--- a/libgimp/gimp.h
+++ b/libgimp/gimp.h
@@ -56,6 +56,7 @@
#include <libgimp/gimpprogress.h>
#include <libgimp/gimpsaveprocedure.h>
#include <libgimp/gimpselection.h>
+#include <libgimp/gimpthumbnailprocedure.h>
#include <libgimp/gimp_pdb_headers.h>
diff --git a/libgimp/gimpthumbnailprocedure.c b/libgimp/gimpthumbnailprocedure.c
new file mode 100644
index 0000000000..1b4273ac4e
--- /dev/null
+++ b/libgimp/gimpthumbnailprocedure.c
@@ -0,0 +1,239 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpthumbnailprocedure.c
+ * Copyright (C) 2019 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (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
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#define GIMP_DISABLE_COMPAT_CRUFT
+
+#include "gimp.h"
+
+#include "gimpthumbnailprocedure.h"
+
+
+struct _GimpThumbnailProcedurePrivate
+{
+ GimpRunThumbnailFunc run_func;
+ gpointer run_data;
+ GDestroyNotify run_data_destroy;
+};
+
+
+static void gimp_thumbnail_procedure_constructed (GObject *object);
+static void gimp_thumbnail_procedure_finalize (GObject *object);
+
+static GimpValueArray *
+ gimp_thumbnail_procedure_run (GimpProcedure *procedure,
+ const GimpValueArray *args);
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (GimpThumbnailProcedure, gimp_thumbnail_procedure,
+ GIMP_TYPE_PROCEDURE)
+
+#define parent_class gimp_thumbnail_procedure_parent_class
+
+
+static void
+gimp_thumbnail_procedure_class_init (GimpThumbnailProcedureClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GimpProcedureClass *procedure_class = GIMP_PROCEDURE_CLASS (klass);
+
+ object_class->constructed = gimp_thumbnail_procedure_constructed;
+ object_class->finalize = gimp_thumbnail_procedure_finalize;
+
+ procedure_class->run = gimp_thumbnail_procedure_run;
+}
+
+static void
+gimp_thumbnail_procedure_init (GimpThumbnailProcedure *procedure)
+{
+ procedure->priv = gimp_thumbnail_procedure_get_instance_private (procedure);
+}
+
+static void
+gimp_thumbnail_procedure_constructed (GObject *object)
+{
+ GimpProcedure *procedure = GIMP_PROCEDURE (object);
+
+ G_OBJECT_CLASS (parent_class)->constructed (object);
+
+ GIMP_PROC_ARG_STRING (procedure, "uri",
+ "URI",
+ "URI of the file to load the thumbnail from",
+ NULL,
+ GIMP_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_INT (procedure, "thumb-size",
+ "Thumb Size",
+ "Preferred thumbnail size",
+ 16, 2014, 256,
+ GIMP_PARAM_READWRITE);
+
+ GIMP_PROC_VAL_IMAGE (procedure, "image",
+ "Image",
+ "Thumbnail image",
+ FALSE,
+ GIMP_PARAM_READWRITE);
+
+ GIMP_PROC_VAL_INT (procedure, "image-width",
+ "Image width",
+ "Width of the full-sized image (0 for unknown)",
+ 0, GIMP_MAX_IMAGE_SIZE, 0,
+ GIMP_PARAM_READWRITE);
+
+ GIMP_PROC_VAL_INT (procedure, "image-height",
+ "Image height",
+ "Height of the full-sized image (0 for unknown)",
+ 0, GIMP_MAX_IMAGE_SIZE, 0,
+ GIMP_PARAM_READWRITE);
+
+ GIMP_PROC_VAL_ENUM (procedure, "image-type",
+ "Image type",
+ "Type of the image",
+ GIMP_TYPE_IMAGE_TYPE,
+ GIMP_RGB_IMAGE,
+ GIMP_PARAM_READWRITE);
+
+ GIMP_PROC_VAL_INT (procedure, "num-layers",
+ "Num layers",
+ "Number of layers in the image",
+ 1, G_MAXINT, 1,
+ GIMP_PARAM_READWRITE);
+}
+
+static void
+gimp_thumbnail_procedure_finalize (GObject *object)
+{
+ GimpThumbnailProcedure *procedure = GIMP_THUMBNAIL_PROCEDURE (object);
+
+ if (procedure->priv->run_data_destroy)
+ procedure->priv->run_data_destroy (procedure->priv->run_data);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static GimpValueArray *
+gimp_thumbnail_procedure_run (GimpProcedure *procedure,
+ const GimpValueArray *args)
+{
+ GimpThumbnailProcedure *thumbnail_proc = GIMP_THUMBNAIL_PROCEDURE (procedure);
+ GimpValueArray *remaining;
+ GimpValueArray *return_values;
+ const gchar *uri;
+ GFile *file;
+ gint size;
+ gint i;
+
+ uri = g_value_get_string (gimp_value_array_index (args, 0));
+ size = g_value_get_int (gimp_value_array_index (args, 1));
+
+ file = g_file_new_for_uri (uri);
+
+ remaining = gimp_value_array_new (gimp_value_array_length (args) - 2);
+
+ for (i = 2; i < gimp_value_array_length (args); i++)
+ {
+ GValue *value = gimp_value_array_index (args, i);
+
+ gimp_value_array_append (remaining, value);
+ }
+
+ return_values = thumbnail_proc->priv->run_func (procedure,
+ file,
+ size,
+ remaining,
+ thumbnail_proc->priv->run_data);
+
+ gimp_value_array_unref (remaining);
+ g_object_unref (file);
+
+ return return_values;
+}
+
+
+/* public functions */
+
+/**
+ * gimp_thumbnail_procedure_new:
+ * @plug_in: a #GimpPlugIn.
+ * @name: the new procedure's name.
+ * @proc_type: the new procedure's #GimpPDBProcType.
+ * @run_func: the run function for the new procedure.
+ * @run_data: user data passed to @run_func.
+ * @run_data_destroy: (nullable): free function for @run_data, or %NULL.
+ *
+ * Creates a new thumbnail procedure named @name which will call @run_func
+ * when invoked.
+ *
+ * See gimp_procedure_new() for information about @proc_type.
+ *
+ * #GimpThumbnailProcedure is a #GimpProcedure subclass that makes it easier
+ * to write file thumbnail procedures.
+ *
+ * It automatically adds the standard
+ *
+ * (uri, size)
+ *
+ * arguments and the standard
+ *
+ * (image-id, image-width, image-height, image-type, num-layers)
+ *
+ * return value of a thumbnail procedure. It is possible to add
+ * additional arguments.
+ *
+ * When invoked via gimp_procedure_run(), it unpacks these standard
+ * arguemnts and calls @run_func which is a #GimpRunThumbnailFunc. The
+ * "args" #GimpValueArray of #GimpRunThumbnailFunc only contains
+ * additionally added arguments.
+ *
+ * #GimpThumbnailRunFunc must gimp_value_array_truncate() the returned
+ * #GimpValueArray to the number of return values it actually uses.
+ *
+ * Returns: a new #GimpProcedure.
+ *
+ * Since: 3.0
+ **/
+GimpProcedure *
+gimp_thumbnail_procedure_new (GimpPlugIn *plug_in,
+ const gchar *name,
+ GimpPDBProcType proc_type,
+ GimpRunThumbnailFunc run_func,
+ gpointer run_data,
+ GDestroyNotify run_data_destroy)
+{
+ GimpThumbnailProcedure *procedure;
+
+ g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
+ g_return_val_if_fail (gimp_is_canonical_identifier (name), NULL);
+ g_return_val_if_fail (proc_type != GIMP_INTERNAL, NULL);
+ g_return_val_if_fail (run_func != NULL, NULL);
+
+ procedure = g_object_new (GIMP_TYPE_THUMBNAIL_PROCEDURE,
+ "plug-in", plug_in,
+ "name", name,
+ "procedure-type", proc_type,
+ NULL);
+
+ procedure->priv->run_func = run_func;
+ procedure->priv->run_data = run_data;
+ procedure->priv->run_data_destroy = run_data_destroy;
+
+ return GIMP_PROCEDURE (procedure);
+}
diff --git a/libgimp/gimpthumbnailprocedure.h b/libgimp/gimpthumbnailprocedure.h
new file mode 100644
index 0000000000..89b8399ffe
--- /dev/null
+++ b/libgimp/gimpthumbnailprocedure.h
@@ -0,0 +1,91 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpthumbnailprocedure.h
+ * Copyright (C) 2019 Michael Natterer <mitch gimp org>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_THUMBNAIL_PROCEDURE_H__
+#define __GIMP_THUMBNAIL_PROCEDURE_H__
+
+#include <libgimp/gimpprocedure.h>
+
+G_BEGIN_DECLS
+
+/* For information look into the C source or the html documentation */
+
+
+/**
+ * GimpRunThumbnailFunc:
+ * @procedure: the #GimpProcedure that runs.
+ * @file: the #GFile to load the thumbnail from.
+ * @size: the requested thumbnail size.
+ * @args: the @procedure's remaining arguments.
+ * @run_data: the run_data given in gimp_thumbnail_procedure_new().
+ *
+ * The thumbnail function is run during the lifetime of the GIMP session,
+ * each time a plug-in thumbnail procedure is called.
+ *
+ * Returns: (transfer full): the @procedure's return values.
+ *
+ * Since: 3.0
+ **/
+typedef GimpValueArray * (* GimpRunThumbnailFunc) (GimpProcedure *procedure,
+ GFile *file,
+ gint size,
+ const GimpValueArray *args,
+ gpointer run_data);
+
+
+#define GIMP_TYPE_THUMBNAIL_PROCEDURE (gimp_thumbnail_procedure_get_type ())
+#define GIMP_THUMBNAIL_PROCEDURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GIMP_TYPE_THUMBNAIL_PROCEDURE, GimpThumbnailProcedure))
+#define GIMP_THUMBNAIL_PROCEDURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GIMP_TYPE_THUMBNAIL_PROCEDURE, GimpThumbnailProcedureClass))
+#define GIMP_IS_THUMBNAIL_PROCEDURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GIMP_TYPE_THUMBNAIL_PROCEDURE))
+#define GIMP_IS_THUMBNAIL_PROCEDURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GIMP_TYPE_THUMBNAIL_PROCEDURE))
+#define GIMP_THUMBNAIL_PROCEDURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GIMP_TYPE_THUMBNAIL_PROCEDURE, GimpThumbnailProcedureClass))
+
+
+typedef struct _GimpThumbnailProcedure GimpThumbnailProcedure;
+typedef struct _GimpThumbnailProcedureClass GimpThumbnailProcedureClass;
+typedef struct _GimpThumbnailProcedurePrivate GimpThumbnailProcedurePrivate;
+
+struct _GimpThumbnailProcedure
+{
+ GimpProcedure parent_instance;
+
+ GimpThumbnailProcedurePrivate *priv;
+};
+
+struct _GimpThumbnailProcedureClass
+{
+ GimpProcedureClass parent_class;
+};
+
+
+GType gimp_thumbnail_procedure_get_type (void) G_GNUC_CONST;
+
+GimpProcedure * gimp_thumbnail_procedure_new (GimpPlugIn *plug_in,
+ const gchar *name,
+ GimpPDBProcType proc_type,
+ GimpRunThumbnailFunc run_func,
+ gpointer run_data,
+ GDestroyNotify run_data_destroy);
+
+
+G_END_DECLS
+
+#endif /* __GIMP_THUMBNAIL_PROCEDURE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]