[gegl/soc-2011-ops] Added cubism op



commit 36ace2ff9a53d2186d7f191fe6856ee04090722e
Author: Robert Sasu <sasu robert gmail com>
Date:   Wed Jul 6 14:43:13 2011 +0300

    Added cubism op

 operations/workshop/cubism.c |  117 +++++++++++++++++++++++++++++++-----------
 1 files changed, 86 insertions(+), 31 deletions(-)
---
diff --git a/operations/workshop/cubism.c b/operations/workshop/cubism.c
index 4ffe2d2..9ae3a62 100644
--- a/operations/workshop/cubism.c
+++ b/operations/workshop/cubism.c
@@ -52,6 +52,8 @@ gegl_chant_boolean (background, _("Background"), FALSE,
 #define MAX_POINTS        4
 #define RANDOMNESS        5
 
+
+
 typedef struct
 {
   gint x,y;
@@ -73,8 +75,8 @@ static void prepare (GeglOperation *operation)
   /* 
    * Calculate the needed extension for the ROI
    *      MAX (o->tile_size +
-              g_rand_double_range (gr, 0, o->tile_size / 4.0) -
-              o->tile_size / 8.0) * o->tile_saturation)
+   *           g_rand_double_range (gr, 0, o->tile_size / 4.0) -
+   *           o->tile_size / 8.0) * o->tile_saturation)
    */
   
   tmp = ceil ((9 * o->tile_size / 8.0) * o->tile_saturation);
@@ -248,13 +250,62 @@ polygon_reset (Polygon *poly)
 
 static void
 set_background_color (gfloat              *dst_buf,
-                      const GeglRectangle *result,
-                      gfloat              *color)
+                      const GeglRectangle *extended,
+                      gfloat              *color,
+                      GeglBuffer          *input,
+                      const GeglRectangle *result)
 {
-   gint i, j, offset = 0;
-   for (i=0; i < result->width * result->height; i++)
-        for (j=0; j<4; j++)
-              dst_buf[offset++] = color[j];
+  gint           i, j, k, offset = 0;
+  GeglRectangle  tmp;
+  gfloat        *tmp_buf; 
+  
+  tmp.x      = extended->x;
+  tmp.y      = extended->y;
+  tmp.width  = extended->width;
+  tmp.height = result->y - extended->y;
+
+  if (tmp.height)
+     {
+     tmp_buf = g_new0 (gfloat, tmp.width * tmp.height * 4);
+     gegl_buffer_get (input, 1.0, &tmp, babl_format ("RGBA float"), tmp_buf,
+                      GEGL_AUTO_ROWSTRIDE);
+
+     printf("1: %d %d %d %d\n", tmp.x, tmp.y, tmp.width, tmp.height);
+
+     for (i=0; i<tmp.width * tmp.height * 4; i++)
+         dst_buf[i] = tmp_buf[i];
+     g_free (tmp_buf);
+     }
+
+  tmp.y      = result->y;
+  tmp.width  = result->x - extended->x;   
+  tmp.height = extended->height - (result->y - extended->y);
+
+  if (tmp.width)
+     {
+     tmp_buf = g_new0 (gfloat, tmp.width * tmp.height * 4);
+     gegl_buffer_get (input, 1.0, &tmp, babl_format ("RGBA float"), tmp_buf,
+                      GEGL_AUTO_ROWSTRIDE);
+
+     printf("2: %d %d %d %d\n", tmp.x, tmp.y, tmp.width, tmp.height);
+     offset = (extended->width - 1) * (result->y - extended->y) * 4;
+ 
+     for (i=0; i<tmp.height; i++)
+        {
+         offset += (extended->width * 4);
+         for (j=0; j< tmp.width * 4; j++)
+             dst_buf[offset++] = tmp_buf[i];
+	}
+     g_free (tmp_buf);
+     }
+
+  for (i=result->y; i < extended->height; i++)
+      {
+      offset = ((i - extended->y) * extended->width + result->x - extended->x) * 4;
+      for (j=result->x; j<extended->width; j++)
+          for (k=0; k<4; k++)
+              dst_buf[offset++] = color[k];
+      }
 }
 
 static void
@@ -264,6 +315,7 @@ fill_poly_color (Polygon             *poly,
                  const GeglRectangle *extended,
                  const GeglRectangle *boundary,
                  gfloat              *dst_buf,
+                 gfloat              *src_buf,
                  gfloat              *color)
 {
   gdouble       dmin_x = 0.0;
@@ -289,7 +341,7 @@ fill_poly_color (Polygon             *poly,
   gint          x1, y1, x2, y2;
   gint         *vals, *vals_iter, *vals_end;
   gint          b;
-  GeglRectangle rect;
+ // GeglRectangle rect;
 
   sx = poly->pts[0].x;
   sy = poly->pts[0].y;
@@ -324,11 +376,6 @@ fill_poly_color (Polygon             *poly,
   size_y = (max_y - min_y) * SUPERSAMPLE;
   size_x = (max_x - min_x) * SUPERSAMPLE;
 
-  min_scanlines      = g_new0 (gint, size_y);
-  min_scanlines_iter = g_new0 (gint, size_y); 
-  max_scanlines      = g_new0 (gint, size_y);
-  max_scanlines_iter = g_new0 (gint, size_y);
-
   min_scanlines = min_scanlines_iter = g_new0 (gint, size_y); 
   max_scanlines = max_scanlines_iter = g_new0 (gint, size_y);
 
@@ -418,24 +465,25 @@ fill_poly_color (Polygon             *poly,
                                                                     one_over_dist,
                                                                     xx - sx,
                                                                     yy - sy));
-
+                         /*
                           gegl_buffer_sample (output, x, y, 1.0, buf, 
                                              babl_format ("RGBA float"),
-                                             GEGL_INTERPOLATION_NEAREST);
+                                             GEGL_INTERPOLATION_NEAREST);*/
 
-                       /* for (b = 0; b < 4; b++)
-                              buf[b] = dst_buf[( (y-extended->y) * extended->width
+                        for (b = 0; b < 4; b++)
+                            buf[b] = dst_buf[( (y-extended->y) * extended->width
                                             + (x-extended->x)) * 4 + b];
-		       */
-                          for (b = 0; b < 4; b++)
+		       
+                        for (b = 0; b < 4; b++)
                             buf[b] = (color[b] * alpha) + (buf[b] * (1 - alpha));
 
 
 
-                       /*  for (b = 0; b < 4; b++)
-                                dst_buf[((y-extended->y) * extended->width + 
-                                        (x - extended->x)) * 4 + b] = buf[b];
-                       */
+                         for (b = 0; b < 4; b++)
+                            dst_buf[((y-extended->y) * extended->width + 
+                                     (x - extended->x)) * 4 + b] = buf[b];
+                       
+                       /*
                           rect.x = x;
                           rect.y = y;
                           rect.width = 1;
@@ -444,6 +492,7 @@ fill_poly_color (Polygon             *poly,
                           gegl_buffer_set (output, &rect,
                                            babl_format ("RGBA float"), buf,
                                            GEGL_AUTO_ROWSTRIDE);
+                        */
                         }
                     }
                 }
@@ -476,7 +525,7 @@ process (GeglOperation       *operation,
          const GeglRectangle *result)
 {
   GeglChantO              *o            = GEGL_CHANT_PROPERTIES (operation);
-  GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
+  GeglOperationAreaFilter *op_area      = GEGL_OPERATION_AREA_FILTER (operation);
   GeglRectangle            boundary     = get_effective_area (operation);
   GeglRectangle            extended;
   Babl                    *format       = babl_format ("RGBA float");
@@ -486,6 +535,7 @@ process (GeglOperation       *operation,
   gint    cols, rows, num_tiles, count;
   gint   *random_indices;
   gfloat *dst_buf;
+  gfloat *src_buf;
 
   Polygon poly;
   gint    i;
@@ -499,7 +549,8 @@ process (GeglOperation       *operation,
   extended.height = CLAMP (result->height + op_area->top + op_area->bottom, 0,
                            boundary.height);
 
-  dst_buf = g_new0 (gfloat, result->width * result->height * 4);
+  dst_buf = g_new0 (gfloat, extended.width * extended.height * 4);
+  src_buf = g_new0 (gfloat, extended.width * extended.height * 4);
 
   if (!o->background)
     {
@@ -514,7 +565,10 @@ process (GeglOperation       *operation,
   cols = (result->width + o->tile_size - 1) / o->tile_size;
   rows = (result->height + o->tile_size - 1) / o->tile_size;
 
-  set_background_color (dst_buf, result, bg_col);
+  set_background_color (dst_buf, &extended, bg_col, input, result);
+
+  gegl_buffer_get (input, 1.0, &extended, babl_format ("RGBA float"), src_buf,
+                   GEGL_AUTO_ROWSTRIDE);
 
   num_tiles = (rows + 1) * (cols + 1);
 
@@ -564,11 +618,11 @@ process (GeglOperation       *operation,
                         GEGL_INTERPOLATION_NEAREST);
  
     fill_poly_color (&poly, input, output, &extended, &boundary, 
-                     dst_buf, color);
+                     dst_buf, src_buf, color);
     }
-  /*
+  
   gegl_buffer_set (output, &extended, format, dst_buf, GEGL_AUTO_ROWSTRIDE);
-  */
+  
   g_free (dst_buf);
   g_free (random_indices);
 
@@ -626,6 +680,7 @@ gegl_chant_class_init (GeglChantClass *klass)
   GeglOperationClass       *operation_class;
   GeglOperationFilterClass *filter_class;
 
+
   operation_class = GEGL_OPERATION_CLASS (klass);
   filter_class    = GEGL_OPERATION_FILTER_CLASS (klass);
 
@@ -633,7 +688,7 @@ gegl_chant_class_init (GeglChantClass *klass)
   operation_class->prepare                 = prepare;
   operation_class->get_bounding_box        = get_bounding_box;
   operation_class->get_required_for_output = get_required_for_output;
-/*  operation_class->get_cached_region       = get_cached_region;*/
+ /* operation_class->get_cached_region       = get_cached_region;*/
 
   operation_class->categories = "artistic";
   operation_class->name       = "gegl:cubism";



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