[gimp/goat-invasion] app: derive GimpOperationSetAlpha from GeglOperationPointComposer



commit 0de3ad21a5c8278cb33dde74712802cffc621810
Author: Michael Natterer <mitch gimp org>
Date:   Sun Mar 18 20:22:09 2012 +0100

    app: derive GimpOperationSetAlpha from GeglOperationPointComposer
    
    and use the aux input as additional source of alpha.

 app/gegl/gimpoperationsetalpha.c |   53 +++++++++++++++++++++++++++++--------
 app/gegl/gimpoperationsetalpha.h |    4 +-
 2 files changed, 43 insertions(+), 14 deletions(-)
---
diff --git a/app/gegl/gimpoperationsetalpha.c b/app/gegl/gimpoperationsetalpha.c
index 7b55452..0fd2513 100644
--- a/app/gegl/gimpoperationsetalpha.c
+++ b/app/gegl/gimpoperationsetalpha.c
@@ -43,15 +43,17 @@ static void   gimp_operation_set_alpha_set_property (GObject      *object,
                                                      const GValue *value,
                                                      GParamSpec   *pspec);
 
+static void   gimp_operation_set_alpha_prepare      (GeglOperation       *operation);
 static gboolean   gimp_operation_set_alpha_process  (GeglOperation       *operation,
                                                      void                *in_buf,
+                                                     void                *aux_buf,
                                                      void                *out_buf,
                                                      glong                samples,
                                                      const GeglRectangle *roi);
 
 
 G_DEFINE_TYPE (GimpOperationSetAlpha, gimp_operation_set_alpha,
-               GEGL_TYPE_OPERATION_POINT_FILTER)
+               GEGL_TYPE_OPERATION_POINT_COMPOSER)
 
 #define parent_class gimp_operation_set_alpha_parent_class
 
@@ -59,9 +61,9 @@ G_DEFINE_TYPE (GimpOperationSetAlpha, gimp_operation_set_alpha,
 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);
+  GObjectClass                    *object_class    = G_OBJECT_CLASS (klass);
+  GeglOperationClass              *operation_class = GEGL_OPERATION_CLASS (klass);
+  GeglOperationPointComposerClass *point_class     = GEGL_OPERATION_POINT_COMPOSER_CLASS (klass);
 
   object_class->set_property = gimp_operation_set_alpha_set_property;
   object_class->get_property = gimp_operation_set_alpha_get_property;
@@ -69,6 +71,7 @@ gimp_operation_set_alpha_class_init (GimpOperationSetAlphaClass *klass)
   operation_class->name        = "gimp:set-alpha";
   operation_class->categories  = "color";
   operation_class->description = "Set a buffer's alpha channel to a value";
+  operation_class->prepare     = gimp_operation_set_alpha_prepare;
 
   point_class->process         = gimp_operation_set_alpha_process;
 
@@ -126,26 +129,52 @@ gimp_operation_set_alpha_set_property (GObject      *object,
     }
 }
 
+static void
+gimp_operation_set_alpha_prepare (GeglOperation *operation)
+{
+  gegl_operation_set_format (operation, "input",  babl_format ("RGBA float"));
+  gegl_operation_set_format (operation, "aux",    babl_format ("Y float"));
+  gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
+}
+
 static gboolean
 gimp_operation_set_alpha_process (GeglOperation       *operation,
                                   void                *in_buf,
+                                  void                *aux_buf,
                                   void                *out_buf,
                                   glong                samples,
                                   const GeglRectangle *roi)
 {
   GimpOperationSetAlpha *self = GIMP_OPERATION_SET_ALPHA (operation);
   gfloat                *src  = in_buf;
+  gfloat                *aux  = aux_buf;
   gfloat                *dest = out_buf;
 
-  while (samples--)
+  if (aux)
     {
-      dest[RED]   = src[RED];
-      dest[GREEN] = src[GREEN];
-      dest[BLUE]  = src[BLUE];
-      dest[ALPHA] = self->value;
-
-      src  += 4;
-      dest += 4;
+      while (samples--)
+        {
+          dest[RED]   = src[RED];
+          dest[GREEN] = src[GREEN];
+          dest[BLUE]  = src[BLUE];
+          dest[ALPHA] = self->value * src[0];
+
+          src  += 4;
+          dest += 4;
+        }
+    }
+  else
+    {
+      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
index d90dd81..53f6538 100644
--- a/app/gegl/gimpoperationsetalpha.h
+++ b/app/gegl/gimpoperationsetalpha.h
@@ -38,14 +38,14 @@ typedef struct _GimpOperationSetAlphaClass GimpOperationSetAlphaClass;
 
 struct _GimpOperationSetAlpha
 {
-  GeglOperationPointFilter  parent_instance;
+  GeglOperationPointComposer  parent_instance;
 
   gdouble                   value;
 };
 
 struct _GimpOperationSetAlphaClass
 {
-  GeglOperationPointFilterClass  parent_class;
+  GeglOperationPointComposerClass  parent_class;
 };
 
 



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