[gimp/goat-invasion: 165/608] app: apply patch from Villa Sokk that implements GimpOperationDissolveMode



commit 915b7746d891d56931cb4344572c383c98b4c559
Author: Michael Natterer <mitch gimp org>
Date:   Tue Mar 20 20:40:30 2012 +0100

    app: apply patch from Villa Sokk that implements GimpOperationDissolveMode

 app/core/gimplayer.c                 |    1 -
 app/gegl/gimpoperationdissolvemode.c |   86 ++++++++++++++++++++++++++++------
 2 files changed, 72 insertions(+), 15 deletions(-)
---
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index c44c03c..c4ff71f 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -1033,7 +1033,6 @@ gimp_layer_sync_mode_node (GimpLayer *layer)
 
       switch (layer->mode)
         {
-        case GIMP_DISSOLVE_MODE:
         case GIMP_BEHIND_MODE:
         case GIMP_MULTIPLY_MODE:
         case GIMP_SCREEN_MODE:
diff --git a/app/gegl/gimpoperationdissolvemode.c b/app/gegl/gimpoperationdissolvemode.c
index 857c2a4..05636b0 100644
--- a/app/gegl/gimpoperationdissolvemode.c
+++ b/app/gegl/gimpoperationdissolvemode.c
@@ -2,7 +2,7 @@
  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  *
  * gimpoperationdissolvemode.c
- * Copyright (C) 2008 Michael Natterer <mitch gimp org>
+ * Copyright (C) 2012 Ville Sokk <ville sokk gmail com>
  *
  * 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
@@ -28,6 +28,9 @@
 #include "gimpoperationdissolvemode.h"
 
 
+#define RANDOM_TABLE_SIZE 4096
+
+
 static gboolean gimp_operation_dissolve_mode_process (GeglOperation       *operation,
                                                       void                *in_buf,
                                                       void                *aux_buf,
@@ -40,12 +43,16 @@ static gboolean gimp_operation_dissolve_mode_process (GeglOperation       *opera
 G_DEFINE_TYPE (GimpOperationDissolveMode, gimp_operation_dissolve_mode,
                GIMP_TYPE_OPERATION_POINT_LAYER_MODE)
 
+static gint32  random_table[RANDOM_TABLE_SIZE];
+
 
 static void
 gimp_operation_dissolve_mode_class_init (GimpOperationDissolveModeClass *klass)
 {
   GeglOperationClass              *operation_class;
   GeglOperationPointComposerClass *point_class;
+  GRand                           *gr;
+  gint                             i;
 
   operation_class = GEGL_OPERATION_CLASS (klass);
   point_class     = GEGL_OPERATION_POINT_COMPOSER_CLASS (klass);
@@ -56,6 +63,18 @@ gimp_operation_dissolve_mode_class_init (GimpOperationDissolveModeClass *klass)
            NULL);
 
   point_class->process         = gimp_operation_dissolve_mode_process;
+
+#define RANDOM_SEED 314159265
+
+  /* generate a table of random seeds */
+  gr = g_rand_new_with_seed (RANDOM_SEED);
+
+  for (i = 0; i < RANDOM_TABLE_SIZE; i++)
+    {
+      random_table[i] = g_rand_int (gr);
+    }
+
+  g_rand_free (gr);
 }
 
 static void
@@ -72,20 +91,59 @@ gimp_operation_dissolve_mode_process (GeglOperation       *operation,
                                       const GeglRectangle *roi,
                                       gint                 level)
 {
-  gfloat *in    = in_buf;
-  gfloat *layer = aux_buf;
-  gfloat *out   = out_buf;
-
-  while (samples--)
+  gfloat *in     = in_buf;
+  gfloat *layer  = aux_buf;
+  gfloat *out    = out_buf;
+  gint    x      = roi->x;
+  gint    y      = roi->y;
+  gint    width  = roi->width;
+  gint    height = roi->height;
+  gint    row;
+
+  for (row = 0; row < height; row++)
     {
-      out[RED]   = in[RED];
-      out[GREEN] = in[GREEN];
-      out[BLUE]  = in[BLUE];
-      out[ALPHA] = in[ALPHA];
-
-      in    += 4;
-      layer += 4;
-      out   += 4;
+      GRand *gr;
+      gint   pixel;
+      gint   i;
+
+      gr = g_rand_new_with_seed (random_table[(y + row) % RANDOM_TABLE_SIZE]);
+      for (i = 0; i < x; i++)
+        {
+          g_rand_int (gr);
+        }
+
+      for (pixel = 0; pixel < width; pixel++)
+        {
+          gdouble rand_val;
+
+          /* dissolve if random value is >= opacity */
+          rand_val = g_rand_double_range (gr, 0.0, 1.0);
+
+          if (layer[ALPHA] >= rand_val)
+            {
+              out[ALPHA] = 1.0;
+
+              for (i = RED; i < ALPHA; i++)
+                {
+                  out[i] = layer[ALPHA] ? layer[i] / layer[ALPHA] : 0.0;
+                }
+            }
+          else
+            {
+              out[ALPHA] = in[ALPHA];
+
+              for (i = RED; i < ALPHA; i++)
+                {
+                  out[i] = in[i];
+                }
+            }
+
+          in += 4;
+          layer += 4;
+          out += 4;
+        }
+
+      g_rand_free (gr);
     }
 
   return TRUE;



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