[gegl/soc-2011-ops] Addded the ripple op, better then gimp version (faster)



commit a5c90319aaf28712ea709e9990eae9ea34ee321c
Author: Robert Sasu <sasu robert gmail com>
Date:   Wed Jul 20 00:52:38 2011 +0300

    Addded the ripple op, better then gimp version (faster)

 operations/workshop/ripple.c |  136 +++++++++++++++++++++++++++++------------
 1 files changed, 96 insertions(+), 40 deletions(-)
---
diff --git a/operations/workshop/ripple.c b/operations/workshop/ripple.c
index 4380a6c..4323394 100644
--- a/operations/workshop/ripple.c
+++ b/operations/workshop/ripple.c
@@ -34,10 +34,10 @@ gegl_chant_string (wave, _("Wave type"), "sine",
                    _("Type of wave to choose."
                      "Choices are sine, sawtooth."
                      "Default is sine"))
-gegl_chant_string (background, _("Edges"), "wrap",
+gegl_chant_string (background, _("Edges"), "smear",
                    _("Type of edges to choose."
                      "Choices are wrap, smear, blank."
-                     "Default is wrap"))
+                     "Default is smear"))
 gegl_chant_int (amplitude, _("Amplitude"), 0, 200, 50,
                 _("Amplitude of ripple"))
 gegl_chant_int (period, _("Period"), 0, 200, 50,
@@ -94,7 +94,7 @@ static void prepare (GeglOperation *operation)
   o       = GEGL_CHANT_PROPERTIES (operation);
 
   op_area->left   = op_area->bottom = 
-  op_area->right  = op_area->top = o->amplitude;
+  op_area->right  = op_area->top = o->amplitude + 2;
 
   gegl_operation_set_format (operation, "input", 
                              babl_format ("RGBA float"));
@@ -156,10 +156,12 @@ ripple_horizontal (gfloat              *src_buf,
                    const GeglRectangle *image,
                    gint                 y,
                    RippleContext        rip,
-                   GeglChantO          *o)
+                   GeglChantO          *o,
+                   GeglBuffer          *input)
 {
-  gint x;
-  gint src_offset, dst_offset;
+  gint  x;
+  gint  src_offset, dst_offset;
+  Babl *format = babl_format ("RGBA float");  
 
   dst_offset = (y - result->y) * result->width * 4;
 
@@ -196,19 +198,29 @@ ripple_horizontal (gfloat              *src_buf,
          gfloat temp1[4], temp2[4]; 
          if (xi >= 0 && xi < image->width)
            {
-              src_offset = (y - extended->y) * extended->width * 4 + 
-                           (xi - extended->x) * 4;
-              for (i=0;i<4;i++)
-                  temp1[i] = src_buf[src_offset++];
+              if (xi >= extended->x && xi < extended->x + extended->width) 
+                { 
+                 src_offset = (y - extended->y) * extended->width * 4 + 
+                              (xi - extended->x) * 4;
+                 for (i=0;i<4;i++)
+                     temp1[i] = src_buf[src_offset++];
+                }
+              else gegl_buffer_sample (input, xi, y, NULL, temp1, format,
+                                       GEGL_INTERPOLATION_NEAREST);
            }
          else temp1[0] = temp1[1] = temp2[2] = temp1[3] = 0.0;
 
          if (xi_a >= 0 && xi_a < image->width)
            {
-              src_offset = (y - extended->y) * extended->width * 4 + 
-                           (xi_a - extended->x) * 4;
-              for (i=0;i<4;i++)
-                  temp1[i] = src_buf[src_offset++];
+              if (xi_a >= extended->x && xi_a < extended->x + extended->width) 
+                { 
+                 src_offset = (y - extended->y) * extended->width * 4 + 
+                              (xi_a - extended->x) * 4;
+                 for (i=0;i<4;i++)
+                     temp2[i] = src_buf[src_offset++];
+                }
+              else gegl_buffer_sample (input, xi_a, y, NULL, temp2, format,
+                                       GEGL_INTERPOLATION_NEAREST);
            }
          else temp2[0] = temp2[1] = temp2[2] = temp2[3] = 0.0; 
 
@@ -218,10 +230,15 @@ ripple_horizontal (gfloat              *src_buf,
         {
          if (xi >= 0 && xi < image->width)
            {
-              src_offset = (y - extended->y) * extended->width * 4 + 
-                           (xi - extended->x) * 4;
-              for (i=0;i<4;i++)
-                  dest[i] = src_buf[src_offset++];
+              if (xi >= extended->x && xi < extended->x + extended->width) 
+                { 
+                 src_offset = (y - extended->y) * extended->width * 4 + 
+                              (xi - extended->x) * 4;
+                 for (i=0;i<4;i++)
+                     dest[i] = src_buf[src_offset++];
+                }
+              else gegl_buffer_sample (input, xi, y, NULL, dest, format,
+                                       GEGL_INTERPOLATION_NEAREST);
            }
          else dest[0] = dest[1] = dest[2] = dest[3] = 0.0;
         }
@@ -240,11 +257,12 @@ ripple_vertical   (gfloat              *src_buf,
                    const GeglRectangle *image,
                    gint                 y,
                    RippleContext        rip,
-                   GeglChantO          *o)
+                   GeglChantO          *o,
+                   GeglBuffer          *input)
 {
   gint x;
   gint src_offset, dst_offset;
-
+  Babl *format = babl_format ("RGBA float"); 
   dst_offset = (y - result->y) * result->width * 4;
 
   for (x = result->x; x < result->x + result->width; x++)
@@ -278,35 +296,50 @@ ripple_vertical   (gfloat              *src_buf,
      if (o->antialias)
         {
          gfloat temp1[4], temp2[4]; 
-         if (xi >= 0 && xi < image->height)
+         if (xi >= 0 && xi < image->width)
            {
-              src_offset = (xi - extended->y) * extended->width * 4 + 
-                           (x - extended->x) * 4;
-              for (i=0;i<4;i++)
-                  temp1[i] = src_buf[src_offset++];
+              if (xi >= extended->y && xi < extended->y + extended->height) 
+                { 
+                 src_offset = (xi - extended->y) * extended->width * 4 + 
+                              (x - extended->x) * 4;
+                 for (i=0;i<4;i++)
+                     temp1[i] = src_buf[src_offset++];
+                }
+              else gegl_buffer_sample (input, x, xi, NULL, temp1, format,
+                                       GEGL_INTERPOLATION_NEAREST);
            }
          else temp1[0] = temp1[1] = temp2[2] = temp1[3] = 0.0;
-
-         if (xi_a >= 0 && xi_a < image->height)
+   
+         if (xi_a >= 0 && xi_a < image->width)
            {
-              src_offset = (xi_a - extended->y) * extended->width * 4 + 
-                           (x - extended->x) * 4;
-              for (i=0;i<4;i++)
-                  temp1[i] = src_buf[src_offset++];
-           }
+              if (xi_a >= extended->y && xi_a < extended->y + extended->height) 
+                { 
+                 src_offset = (xi_a - extended->y) * extended->width * 4 + 
+                              (x - extended->x) * 4;
+                 for (i=0;i<4;i++)
+                     temp2[i] = src_buf[src_offset++];
+                }
+              else gegl_buffer_sample (input, x, xi_a, NULL, temp2, format,
+                                       GEGL_INTERPOLATION_NEAREST);
+            }
          else temp2[0] = temp2[1] = temp2[2] = temp2[3] = 0.0; 
 
          average_two_pixels (dest, temp1, temp2, rem);
         }
      else
         {
-         if (xi >= 0 && xi < image->height)
+         if (xi >= 0 && xi < image->width)
            {
-              src_offset = (xi - extended->y) * extended->width * 4 + 
-                           (x - extended->x) * 4;
-              for (i=0;i<4;i++)
-                  dest[i] = src_buf[src_offset++];
-           }
+              if (xi >= extended->y && xi < extended->y + extended->height) 
+                { 
+                 src_offset = (xi - extended->y) * extended->width * 4 + 
+                              (x - extended->x) * 4;
+                 for (i=0;i<4;i++)
+                     dest[i] = src_buf[src_offset++];
+                }
+              else gegl_buffer_sample (input, x, xi, NULL, dest, format,
+                                       GEGL_INTERPOLATION_NEAREST);
+            }
          else dest[0] = dest[1] = dest[2] = dest[3] = 0.0;
         }
 
@@ -393,10 +426,10 @@ process (GeglOperation       *operation,
   for (y = result->y; y < result->y + result->height; y++)
     if (rip.orie_t == ORIENTATION_TYPE_HORIZONTAL)
         ripple_horizontal (src_buf, dst_buf, result, &extended, &boundary, y,
-                           rip, o);
+                           rip, o, input);
     else if (rip.orie_t == ORIENTATION_TYPE_VERTICAL)
         ripple_vertical   (src_buf, dst_buf, result, &extended, &boundary, y,
-                           rip, o);
+                           rip, o, input);
 
   gegl_buffer_set (output, result, format, dst_buf, GEGL_AUTO_ROWSTRIDE);
 
@@ -406,6 +439,26 @@ process (GeglOperation       *operation,
   return  TRUE;
 }
 
+static GeglRectangle
+get_bounding_box (GeglOperation *operation)
+{
+  GeglRectangle  result = {0,0,0,0};
+  GeglRectangle *in_rect;
+
+  in_rect = gegl_operation_source_get_bounding_box (operation, "input");
+  if (!in_rect)
+    return result;
+
+  return *in_rect;
+}
+
+static GeglRectangle
+get_required_for_output (GeglOperation       *operation,
+                         const gchar         *input_pad,
+                         const GeglRectangle *roi)
+{
+  return get_bounding_box (operation);
+}
 
 static void
 gegl_chant_class_init (GeglChantClass *klass)
@@ -418,6 +471,9 @@ gegl_chant_class_init (GeglChantClass *klass)
 
   filter_class->process    = process;
   operation_class->prepare = prepare;
+  operation_class->get_bounding_box        = get_bounding_box;
+  operation_class->get_required_for_output = get_required_for_output;
+
 
   operation_class->categories  = "distorts";
   operation_class->name        = "gegl:ripple";



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