[gimp/goat-invasion: 97/412] app: add GimpOperationSetAlpha which sets the alpha channel to a value



commit 1fd48666b8bb4051e7eafb8b3a03ca66f56dee12
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 17 16:22:59 2012 +0100

    app: add GimpOperationSetAlpha which sets the alpha channel to a value

 app/gegl/Makefile.am             |   11 ++-
 app/gegl/gimp-gegl-types.h       |    1 +
 app/gegl/gimp-gegl.c             |    9 ++-
 app/gegl/gimpoperationsetalpha.c |  152 ++++++++++++++++++++++++++++++++++++++
 app/gegl/gimpoperationsetalpha.h |   55 ++++++++++++++
 5 files changed, 222 insertions(+), 6 deletions(-)
---
diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am
index f562e3b..1340cc6 100644
--- a/app/gegl/Makefile.am
+++ b/app/gegl/Makefile.am
@@ -48,6 +48,13 @@ libappgegl_a_sources = \
 	gimpthresholdconfig.c			\
 	gimpthresholdconfig.h			\
 	\
+	gimpoperationcagecoefcalc.c		\
+	gimpoperationcagecoefcalc.h		\
+	gimpoperationcagetransform.c		\
+	gimpoperationcagetransform.h		\
+	gimpoperationsetalpha.c			\
+	gimpoperationsetalpha.h			\
+	\
 	gimpoperationpointfilter.c		\
 	gimpoperationpointfilter.h		\
 	gimpoperationbrightnesscontrast.c	\
@@ -56,10 +63,6 @@ libappgegl_a_sources = \
 	gimpoperationcolorbalance.h		\
 	gimpoperationcolorize.c			\
 	gimpoperationcolorize.h			\
-	gimpoperationcagecoefcalc.c		\
-	gimpoperationcagecoefcalc.h		\
-	gimpoperationcagetransform.c		\
-	gimpoperationcagetransform.h		\
 	gimpoperationcurves.c			\
 	gimpoperationcurves.h			\
 	gimpoperationdesaturate.c		\
diff --git a/app/gegl/gimp-gegl-types.h b/app/gegl/gimp-gegl-types.h
index 130fd09..5eddece 100644
--- a/app/gegl/gimp-gegl-types.h
+++ b/app/gegl/gimp-gegl-types.h
@@ -32,6 +32,7 @@ typedef struct _GimpOperationTileSource         GimpOperationTileSource;
 
 typedef struct _GimpOperationCageCoefCalc       GimpOperationCageCoefCalc;
 typedef struct _GimpOperationCageTransform      GimpOperationCageTransform;
+typedef struct _GimpOperationSetAlpha           GimpOperationSetAlpha;
 
 typedef struct _GimpOperationPointFilter        GimpOperationPointFilter;
 typedef struct _GimpOperationBrightnessContrast GimpOperationBrightnessContrast;
diff --git a/app/gegl/gimp-gegl.c b/app/gegl/gimp-gegl.c
index 9d8d978..f714888 100644
--- a/app/gegl/gimp-gegl.c
+++ b/app/gegl/gimp-gegl.c
@@ -31,9 +31,12 @@
 #include "core/gimp.h"
 
 #include "gimp-gegl.h"
-#include "gimpoperationbrightnesscontrast.h"
+
 #include "gimpoperationcagecoefcalc.h"
 #include "gimpoperationcagetransform.h"
+#include "gimpoperationsetalpha.h"
+
+#include "gimpoperationbrightnesscontrast.h"
 #include "gimpoperationcolorbalance.h"
 #include "gimpoperationcolorize.h"
 #include "gimpoperationcurves.h"
@@ -114,9 +117,11 @@ gimp_gegl_init (Gimp *gimp)
                    babl_component ("A"),
                    NULL);
 
-  g_type_class_ref (GIMP_TYPE_OPERATION_BRIGHTNESS_CONTRAST);
   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_SET_ALPHA);
+
+  g_type_class_ref (GIMP_TYPE_OPERATION_BRIGHTNESS_CONTRAST);
   g_type_class_ref (GIMP_TYPE_OPERATION_COLOR_BALANCE);
   g_type_class_ref (GIMP_TYPE_OPERATION_COLORIZE);
   g_type_class_ref (GIMP_TYPE_OPERATION_CURVES);
diff --git a/app/gegl/gimpoperationsetalpha.c b/app/gegl/gimpoperationsetalpha.c
new file mode 100644
index 0000000..7b55452
--- /dev/null
+++ b/app/gegl/gimpoperationsetalpha.c
@@ -0,0 +1,152 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoperationsetalpha.c
+ * Copyright (C) 2012 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 "gimp-gegl-types.h"
+
+#include "gimpoperationsetalpha.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_VALUE
+};
+
+
+static void   gimp_operation_set_alpha_get_property (GObject    *object,
+                                                     guint       property_id,
+                                                     GValue     *value,
+                                                     GParamSpec *pspec);
+static void   gimp_operation_set_alpha_set_property (GObject      *object,
+                                                     guint         property_id,
+                                                     const GValue *value,
+                                                     GParamSpec   *pspec);
+
+static gboolean   gimp_operation_set_alpha_process  (GeglOperation       *operation,
+                                                     void                *in_buf,
+                                                     void                *out_buf,
+                                                     glong                samples,
+                                                     const GeglRectangle *roi);
+
+
+G_DEFINE_TYPE (GimpOperationSetAlpha, gimp_operation_set_alpha,
+               GEGL_TYPE_OPERATION_POINT_FILTER)
+
+#define parent_class gimp_operation_set_alpha_parent_class
+
+
+static void
+gimp_operation_set_alpha_class_init (GimpOperationSetAlphaClass *klass)
+{
+  GObjectClass                  *object_class    = G_OBJECT_CLASS (klass);
+  GeglOperationClass            *operation_class = GEGL_OPERATION_CLASS (klass);
+  GeglOperationPointFilterClass *point_class     = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
+
+  object_class->set_property = gimp_operation_set_alpha_set_property;
+  object_class->get_property = gimp_operation_set_alpha_get_property;
+
+  operation_class->name        = "gimp:set-alpha";
+  operation_class->categories  = "color";
+  operation_class->description = "Set a buffer's alpha channel to a value";
+
+  point_class->process         = gimp_operation_set_alpha_process;
+
+  g_object_class_install_property (object_class, PROP_VALUE,
+                                   g_param_spec_double ("value",
+                                                        "Value",
+                                                        "The alpha value",
+                                                        0.0, 1.0, 1.0,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT));
+}
+
+static void
+gimp_operation_set_alpha_init (GimpOperationSetAlpha *self)
+{
+}
+
+static void
+gimp_operation_set_alpha_get_property (GObject    *object,
+                                       guint       property_id,
+                                       GValue     *value,
+                                       GParamSpec *pspec)
+{
+  GimpOperationSetAlpha *self = GIMP_OPERATION_SET_ALPHA (object);
+
+  switch (property_id)
+    {
+    case PROP_VALUE:
+      g_value_set_double (value, self->value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_operation_set_alpha_set_property (GObject      *object,
+                                       guint         property_id,
+                                       const GValue *value,
+                                       GParamSpec   *pspec)
+{
+  GimpOperationSetAlpha *self = GIMP_OPERATION_SET_ALPHA (object);
+
+  switch (property_id)
+    {
+    case PROP_VALUE:
+      self->value = g_value_get_double (value);
+      break;
+
+   default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static gboolean
+gimp_operation_set_alpha_process (GeglOperation       *operation,
+                                  void                *in_buf,
+                                  void                *out_buf,
+                                  glong                samples,
+                                  const GeglRectangle *roi)
+{
+  GimpOperationSetAlpha *self = GIMP_OPERATION_SET_ALPHA (operation);
+  gfloat                *src  = in_buf;
+  gfloat                *dest = out_buf;
+
+  while (samples--)
+    {
+      dest[RED]   = src[RED];
+      dest[GREEN] = src[GREEN];
+      dest[BLUE]  = src[BLUE];
+      dest[ALPHA] = self->value;
+
+      src  += 4;
+      dest += 4;
+    }
+
+  return TRUE;
+}
diff --git a/app/gegl/gimpoperationsetalpha.h b/app/gegl/gimpoperationsetalpha.h
new file mode 100644
index 0000000..d90dd81
--- /dev/null
+++ b/app/gegl/gimpoperationsetalpha.h
@@ -0,0 +1,55 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoperationsetalpha.h
+ * Copyright (C) 2012 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_SET_ALPHA_H__
+#define __GIMP_OPERATION_SET_ALPHA_H__
+
+
+#include <gegl-plugin.h>
+#include <operation/gegl-operation-point-filter.h>
+
+
+#define GIMP_TYPE_OPERATION_SET_ALPHA            (gimp_operation_set_alpha_get_type ())
+#define GIMP_OPERATION_SET_ALPHA(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_SET_ALPHA, GimpOperationSetAlpha))
+#define GIMP_OPERATION_SET_ALPHA_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GIMP_TYPE_OPERATION_SET_ALPHA, GimpOperationSetAlphaClass))
+#define GIMP_IS_OPERATION_SET_ALPHA(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_OPERATION_SET_ALPHA))
+#define GIMP_IS_OPERATION_SET_ALPHA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIMP_TYPE_OPERATION_SET_ALPHA))
+#define GIMP_OPERATION_SET_ALPHA_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIMP_TYPE_OPERATION_SET_ALPHA, GimpOperationSetAlphaClass))
+
+
+typedef struct _GimpOperationSetAlphaClass GimpOperationSetAlphaClass;
+
+struct _GimpOperationSetAlpha
+{
+  GeglOperationPointFilter  parent_instance;
+
+  gdouble                   value;
+};
+
+struct _GimpOperationSetAlphaClass
+{
+  GeglOperationPointFilterClass  parent_class;
+};
+
+
+GType   gimp_operation_set_alpha_get_type (void) G_GNUC_CONST;
+
+
+#endif /* __GIMP_OPERATION_SET_ALPHA_H__ */



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