[gegl/soc-2011-ops] Added cubsim op, with random seed



commit a665bdf2e0b82cd2169b2e519335fdb857cd9aed
Author: Robert Sasu <sasu robert gmail com>
Date:   Fri Jul 8 13:50:56 2011 +0300

    Added cubsim op, with random seed

 operations/workshop/cubism.c |  172 +++++-------------------------------------
 1 files changed, 20 insertions(+), 152 deletions(-)
---
diff --git a/operations/workshop/cubism.c b/operations/workshop/cubism.c
index f6ba2b3..939b0fc 100644
--- a/operations/workshop/cubism.c
+++ b/operations/workshop/cubism.c
@@ -33,6 +33,8 @@ gegl_chant_double (tile_saturation, _("Tile saturation"), 0.0, 10.0, 2.5,
                   _("Tile saturation"))
 gegl_chant_boolean (background, _("Background"), FALSE,
                   _("Use background color"))
+gegl_chant_int (seed, _("Seed"), 0 , G_MAXINT, 1,
+                _("Random seed"))
 
 
 # else
@@ -141,15 +143,13 @@ convert_segment (gint  x1,
 }
 
 static void
-randomize_indices (gint  count,
-                   gint *indices)
+randomize_indices (gint   count,
+                   gint  *indices,
+                   GRand *gr)
 {
   gint i;
   gint index1, index2;
   gint tmp;
-  GRand *gr;
-
-  gr = g_rand_new();
 
   for (i = 0; i < count * RANDOMNESS; i++)
     {
@@ -160,7 +160,6 @@ randomize_indices (gint  count,
       indices[index2] = tmp;
     }
 
-  g_rand_free (gr);
 }
 
 static void
@@ -249,138 +248,6 @@ polygon_reset (Polygon *poly)
 }
 
 static void
-set_background_color (gfloat              *dst_buf,
-                      const GeglRectangle *extended,
-                      gfloat              *color,
-                      GeglBuffer          *input,
-                      const GeglRectangle *result)
-{
-  gint           i = 0, j, k, offset = 0, area = 0;
-  GeglRectangle  tmp;
-  gfloat        *tmp_buf; 
-  
-  tmp.x      = extended->x;
-  tmp.y      = extended->y;
-  tmp.width  = extended->width;
-  tmp.height = 2 * (result->y - extended->y);
-
-/*get previously calculated pixels*/
-/*top*/
-  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);
-
-     for (i=0; i<tmp.width * tmp.height * 4; i++)
-         {
-         dst_buf[i] = tmp_buf[i];
-         }
-     g_free (tmp_buf);
-
-     area += 1;
-     }
-  
-  if (area!=0)
-     {
-     tmp.y      = result->y + (result->y - extended->y);
-     tmp.width  = 2 * (result->x - extended->x);
-     tmp.height = extended->height - 2 * (result->y - extended->y);
-     }
-  else 
-     {
-     tmp.y      = result->y;
-     tmp.width  = 2 * (result->x - extended->x);   
-     tmp.height = extended->height - (result->y - extended->y);
-     }
-  
-/*left*/
-  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);
-
-     if (i!=0)
-         {
-         offset = (extended->width) * (result->y - extended->y - 1) * 4;
-         }
-     else
-         {
-         offset = (extended->width) * (2 * (result->y - extended->y) - 1) * 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 * tmp.width * 4 + j];
-             }
-	}
-     g_free (tmp_buf);
- 
-     area += 2;
-     }
-
-  switch (area) /*no top, neither bottom*/
-     {
-     case 0:
-        k = 0;
-        for (i=0; i < extended->height * extended->width * 4; i++)
-            {
-            dst_buf[i] = color[k++];
-            if (k % 4 == 0) k = 0;
-            }
-        break;
-    
-     case 1: /*just top*/
-
-     for (i=2 * result->y - extended->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];
-        }
-     break;
-
-     case 2: /*just left*/
-
-     for (i=result->y; i < extended->height; i++)
-       {
-       offset = ((i - extended->y) * extended->width + 2 * (result->x - extended->x)) * 4;
-       for (j=2 * result->x - extended->x; j<extended->width; j++)
-           for (k=0; k<4; k++)
-               dst_buf[offset++] = color[k];
-       }
-     break;
-
-     case 3: /*top and left*/
-
-     for (i=2 * result->y - extended->y; i < extended->height; i++)
-        {
-        offset = ((i - extended->y) * extended->width + 2 * (result->x - extended->x)) * 4;
-        for (j=2 * result->x - extended->x; j<extended->width; j++)
-            for (k=0; k<4; k++)
-                dst_buf[offset++] = color[k];
-        }
-     break; 
-     }
-
-
-
-   /*
-   for (i=0; i<extended->height * extended->width * 4;i++)
-       {
-           if (dst_buf[i]!=0) fprintf(f,"\t %d %lf ",i, dst_buf[i]);
-
-           if (dst_buf[i]!=0 && (i+1) % 4 == 0) fprintf(f,"\n");
-       }*/
-//  fprintf(f,"\n\n");
-}
-
-static void
 fill_poly_color (Polygon             *poly,
                  GeglBuffer          *input,
                  GeglBuffer          *output,
@@ -412,8 +279,9 @@ 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;
   ex = poly->pts[1].x;
@@ -536,10 +404,11 @@ fill_poly_color (Polygon             *poly,
                                                                     one_over_dist,
                                                                     xx - sx,
                                                                     yy - sy));
-                         /*
-                          gegl_buffer_sample (output, x, y, 1.0, buf, 
+                        /* 
+                        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
@@ -548,12 +417,10 @@ fill_poly_color (Polygon             *poly,
                         for (b = 0; b < 4; b++)
                             buf[b] = (color[b] * alpha) + (buf[b] * (1 - alpha));
 
-
-
-                         for (b = 0; b < 4; 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;
@@ -601,7 +468,7 @@ process (GeglOperation       *operation,
   GeglRectangle            extended;
   Babl                    *format       = babl_format ("RGBA float");
 
-  GRand  *gr = g_rand_new ();
+  GRand  *gr = g_rand_new_with_seed (o->seed);
   gfloat  bg_col[4], color[4];
   gint    cols, rows, num_tiles, count;
   gint   *random_indices;
@@ -634,7 +501,7 @@ 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, &extended, bg_col, input, result);
+  /*here to set background color*/
 
   num_tiles = (rows + 1) * (cols + 1);
 
@@ -643,7 +510,7 @@ process (GeglOperation       *operation,
   for (i = 0; i < num_tiles; i++)
       random_indices[i] = i;
   
-  randomize_indices (num_tiles, random_indices);
+  randomize_indices (num_tiles, random_indices, gr);
 
   for (count = 0; count < num_tiles; count++)
     {
@@ -691,6 +558,7 @@ process (GeglOperation       *operation,
   
   g_free (dst_buf);
   g_free (random_indices);
+  g_free (gr);
 
   return TRUE;
 }
@@ -731,14 +599,14 @@ get_required_for_output (GeglOperation       *operation,
 
   return result;
 }
-/*
+
 static GeglRectangle
 get_cached_region (GeglOperation       *operation,
                    const GeglRectangle *roi)
 {
   return *gegl_operation_source_get_bounding_box (operation, "input");
 }
-*/
+
 
 static void 
 gegl_chant_class_init (GeglChantClass *klass)
@@ -755,7 +623,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]