[gimp] app: add new operation gimp:cast-format



commit 8f648471e6d33dc8f0c71978e012a8f1af515869
Author: Michael Natterer <mitch gimp org>
Date:   Sun May 4 20:13:21 2014 +0200

    app: add new operation gimp:cast-format
    
    which casts between two arbitrary formats of the same bpp.

 app/operations/Makefile.am               |    2 +
 app/operations/gimp-operations.c         |    2 +
 app/operations/gimpoperationcastformat.c |  205 ++++++++++++++++++++++++++++++
 app/operations/gimpoperationcastformat.h |   56 ++++++++
 4 files changed, 265 insertions(+), 0 deletions(-)
---
diff --git a/app/operations/Makefile.am b/app/operations/Makefile.am
index d5998fd..6356b3d 100644
--- a/app/operations/Makefile.am
+++ b/app/operations/Makefile.am
@@ -46,6 +46,8 @@ libappoperations_generic_a_sources = \
        \
        gimpoperationborder.c                   \
        gimpoperationborder.h                   \
+       gimpoperationcastformat.c               \
+       gimpoperationcastformat.h               \
        gimpoperationcagecoefcalc.c             \
        gimpoperationcagecoefcalc.h             \
        gimpoperationcagetransform.c            \
diff --git a/app/operations/gimp-operations.c b/app/operations/gimp-operations.c
index 6b35ec9..6c38648 100644
--- a/app/operations/gimp-operations.c
+++ b/app/operations/gimp-operations.c
@@ -28,6 +28,7 @@
 #include "gimp-operations.h"
 
 #include "gimpoperationborder.h"
+#include "gimpoperationcastformat.h"
 #include "gimpoperationcagecoefcalc.h"
 #include "gimpoperationcagetransform.h"
 #include "gimpoperationequalize.h"
@@ -83,6 +84,7 @@ void
 gimp_operations_init (void)
 {
   g_type_class_ref (GIMP_TYPE_OPERATION_BORDER);
+  g_type_class_ref (GIMP_TYPE_OPERATION_CAST_FORMAT);
   g_type_class_ref (GIMP_TYPE_OPERATION_CAGE_COEF_CALC);
   g_type_class_ref (GIMP_TYPE_OPERATION_CAGE_TRANSFORM);
   g_type_class_ref (GIMP_TYPE_OPERATION_EQUALIZE);
diff --git a/app/operations/gimpoperationcastformat.c b/app/operations/gimpoperationcastformat.c
new file mode 100644
index 0000000..60dff0b
--- /dev/null
+++ b/app/operations/gimpoperationcastformat.c
@@ -0,0 +1,205 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoperationcastformat.c
+ * Copyright (C) 2014  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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+
+#include "operations-types.h"
+
+#include "gimpoperationcastformat.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_INPUT_FORMAT,
+  PROP_OUTPUT_FORMAT
+};
+
+
+static void     gimp_operation_cast_format_get_property (GObject              *object,
+                                                         guint                 prop_id,
+                                                         GValue               *value,
+                                                         GParamSpec           *pspec);
+static void     gimp_operation_cast_format_set_property (GObject              *object,
+                                                         guint                 prop_id,
+                                                         const GValue         *value,
+                                                         GParamSpec           *pspec);
+
+static void     gimp_operation_cast_format_prepare      (GeglOperation        *operation);
+static gboolean gimp_operation_cast_format_process      (GeglOperation        *operation,
+                                                         GeglOperationContext *context,
+                                                         const gchar          *output_prop,
+                                                         const GeglRectangle  *result,
+                                                         gint                  level);
+
+
+G_DEFINE_TYPE (GimpOperationCastFormat, gimp_operation_cast_format,
+               GEGL_TYPE_OPERATION_FILTER)
+
+#define parent_class gimp_operation_cast_format_parent_class
+
+
+static void
+gimp_operation_cast_format_class_init (GimpOperationCastFormatClass *klass)
+{
+  GObjectClass       *object_class    = G_OBJECT_CLASS (klass);
+  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
+
+  object_class->set_property = gimp_operation_cast_format_set_property;
+  object_class->get_property = gimp_operation_cast_format_get_property;
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name"       , "gimp:cast-format",
+                                 "categories" , "color",
+                                 "description", "GIMP Format casting operation",
+                                 NULL);
+
+  operation_class->prepare = gimp_operation_cast_format_prepare;
+  operation_class->process = gimp_operation_cast_format_process;
+
+  g_object_class_install_property (object_class, PROP_INPUT_FORMAT,
+                                   g_param_spec_pointer ("input-format",
+                                                         "Input Format",
+                                                         "Input Format",
+                                                         G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class, PROP_OUTPUT_FORMAT,
+                                   g_param_spec_pointer ("output-format",
+                                                         "Output Format",
+                                                         "Output Format",
+                                                         G_PARAM_READWRITE));
+}
+
+static void
+gimp_operation_cast_format_init (GimpOperationCastFormat *self)
+{
+}
+
+static void
+gimp_operation_cast_format_get_property (GObject    *object,
+                                         guint       prop_id,
+                                         GValue     *value,
+                                         GParamSpec *pspec)
+{
+  GimpOperationCastFormat *cast = GIMP_OPERATION_CAST_FORMAT (object);
+
+  switch (prop_id)
+    {
+    case PROP_INPUT_FORMAT:
+      g_value_set_pointer (value, (gpointer) cast->input_format);
+      break;
+
+    case PROP_OUTPUT_FORMAT:
+      g_value_set_pointer (value, (gpointer) cast->output_format);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_operation_cast_format_set_property (GObject      *object,
+                                         guint         prop_id,
+                                         const GValue *value,
+                                         GParamSpec   *pspec)
+{
+  GimpOperationCastFormat *cast = GIMP_OPERATION_CAST_FORMAT (object);
+
+  switch (prop_id)
+    {
+    case PROP_INPUT_FORMAT:
+      cast->input_format = g_value_get_pointer (value);
+      break;
+
+    case PROP_OUTPUT_FORMAT:
+      cast->output_format = g_value_get_pointer (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_operation_cast_format_prepare (GeglOperation *operation)
+{
+  GimpOperationCastFormat *cast = GIMP_OPERATION_CAST_FORMAT (operation);
+
+  if (cast->input_format)
+    gegl_operation_set_format (operation, "input", cast->input_format);
+
+  if (cast->output_format)
+    gegl_operation_set_format (operation, "output", cast->output_format);
+}
+
+static gboolean
+gimp_operation_cast_format_process (GeglOperation        *operation,
+                                    GeglOperationContext *context,
+                                    const gchar          *output_prop,
+                                    const GeglRectangle  *result,
+                                    gint                  level)
+{
+  GimpOperationCastFormat *cast = GIMP_OPERATION_CAST_FORMAT (operation);
+  GeglBuffer              *input;
+  GeglBuffer              *output;
+
+  if (! cast->input_format || ! cast->output_format)
+    {
+      g_warning ("cast: input-format or output-format are not set");
+      return FALSE;
+    }
+
+  if (babl_format_get_bytes_per_pixel (cast->input_format) !=
+      babl_format_get_bytes_per_pixel (cast->output_format))
+    {
+      g_warning ("cast: input-format and output-format have different bpp");
+      return FALSE;
+    }
+
+  if (strcmp (output_prop, "output"))
+    {
+      g_warning ("cast: requested processing of %s pad on a sink", output_prop);
+      return FALSE;
+    }
+
+  input = gegl_operation_context_get_source (context, "input");
+  if (! input)
+    {
+      g_warning ("cast: received NULL input");
+      return FALSE;
+    }
+
+  output = gegl_buffer_new (result, cast->input_format);
+
+  gegl_buffer_copy (input,  result,
+                    output, result);
+  gegl_buffer_set_format (output, cast->output_format);
+
+  g_object_unref (input);
+
+  gegl_operation_context_take_object (context, "output", G_OBJECT (output));
+
+  return TRUE;
+}
diff --git a/app/operations/gimpoperationcastformat.h b/app/operations/gimpoperationcastformat.h
new file mode 100644
index 0000000..dd3e737
--- /dev/null
+++ b/app/operations/gimpoperationcastformat.h
@@ -0,0 +1,56 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoperationcastformat.h
+ * Copyright (C) 2014 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_OPERATION_CAST_FORMAT_H__
+#define __GIMP_OPERATION_CAST_FORMAT_H__
+
+
+#include <gegl-plugin.h>
+
+
+#define GIMP_TYPE_OPERATION_CAST_FORMAT            (gimp_operation_cast_format_get_type ())
+#define GIMP_OPERATION_CAST_FORMAT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIMP_TYPE_OPERATION_CAST_FORMAT, GimpOperationCastFormat))
+#define GIMP_OPERATION_CAST_FORMAT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
GIMP_TYPE_OPERATION_CAST_FORMAT, GimpOperationCastFormatClass))
+#define GEGL_IS_OPERATION_CAST_FORMAT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GIMP_TYPE_OPERATION_CAST_FORMAT))
+#define GEGL_IS_OPERATION_CAST_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
GIMP_TYPE_OPERATION_CAST_FORMAT))
+#define GIMP_OPERATION_CAST_FORMAT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GIMP_TYPE_OPERATION_CAST_FORMAT, GimpOperationCastFormatClass))
+
+
+typedef struct _GimpOperationCastFormat      GimpOperationCastFormat;
+typedef struct _GimpOperationCastFormatClass GimpOperationCastFormatClass;
+
+struct _GimpOperationCastFormat
+{
+  GeglOperationFilter  parent_instance;
+
+  const Babl          *input_format;
+  const Babl          *output_format;
+};
+
+struct _GimpOperationCastFormatClass
+{
+  GeglOperationFilterClass  parent_class;
+};
+
+
+GType   gimp_operation_cast_format_get_type (void) G_GNUC_CONST;
+
+
+#endif /* __GIMP_OPERATION_CAST_FORMAT_H__ */


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