gegl r2367 - in trunk: . gegl/buffer gegl/operation operations/common



Author: ok
Date: Sun Jun  1 22:55:04 2008
New Revision: 2367
URL: http://svn.gnome.org/viewvc/gegl?rev=2367&view=rev

Log:
* gegl/buffer/gegl-buffer-access.c:
(gegl_buffer_tile_iterator_init), (gegl_buffer_scan_iterator_init),
(gegl_buffer_scan_iterator_next), (gegl_buffer_tile_iterator_next):
modified to make the roi for the scan iterator reported be correct.
* gegl/buffer/gegl-buffer-private.h: modified computation of roi.
* gegl/operation/gegl-operation-point-render.c: override some of the
base source op's modifications of base operation wrt caching.
* operations/common/checkerboard.c: port to be subclass of
point-render.
* operations/common/color.c: (gegl_chant_class_init): removed
initialization now moved to base class.


Modified:
   trunk/ChangeLog
   trunk/gegl/buffer/gegl-buffer-access.c
   trunk/gegl/buffer/gegl-buffer-private.h
   trunk/gegl/operation/gegl-operation-point-render.c
   trunk/operations/common/checkerboard.c
   trunk/operations/common/color.c

Modified: trunk/gegl/buffer/gegl-buffer-access.c
==============================================================================
--- trunk/gegl/buffer/gegl-buffer-access.c	(original)
+++ trunk/gegl/buffer/gegl-buffer-access.c	Sun Jun  1 22:55:04 2008
@@ -45,9 +45,9 @@
 
 
 void gegl_buffer_tile_iterator_init (GeglBufferTileIterator *i,
-                                            GeglBuffer             *buffer,
-                                            GeglRectangle           roi,
-                                            gboolean                write)
+                                     GeglBuffer             *buffer,
+                                     GeglRectangle           roi,
+                                     gboolean                write)
 {
   g_assert (i);
   memset (i, 0, sizeof (GeglBufferTileIterator));
@@ -56,6 +56,8 @@
   i->row    = 0;
   i->col = 0;
   i->tile = NULL;
+  i->real_col = 0;
+  i->real_row = 0;
   i->write = write;
 }
 
@@ -82,6 +84,7 @@
   i->max_size = tile_i->buffer->tile_storage->tile_width *
                 tile_i->buffer->tile_storage->tile_height *
                 tile_i->buffer->format->format.bytes_per_pixel;
+  i->real_row = 0;
 }
 
 GeglBufferScanIterator *gegl_buffer_scan_iterator_new (GeglBuffer             *buffer,
@@ -106,6 +109,7 @@
       i->length = tile_i->subrect.width;
       i->rowstride = tile_i->subrect.width;
       i->row = 0;
+      i->real_row = 0;
     }
   /* we should now have a valid tile */
 
@@ -119,6 +123,11 @@
       i->rowstride = tile_i->subrect.width;
       i->data = data + px_size * (tile_i->subrect.width * tile_i->subrect.y);
       i->row = tile_i->subrect.height;
+      i->real_row = 0;
+      if (i->rowstride < 0)
+        {
+          return FALSE;
+        }
       return TRUE;
     }
   else if (i->row < tile_i->subrect.height)
@@ -126,6 +135,7 @@
     {
       guchar *data = tile_i->sub_data;
       i->data = data + i->row * tile_i->rowstride;
+      i->real_row = i->row;
       i->row ++;
       return TRUE;
     }
@@ -168,6 +178,8 @@
   gint  buffer_y       = buffer->extent.y + buffer_shift_y;
   gint  buffer_abyss_x = buffer->abyss.x + buffer_shift_x;
   gint  abyss_x_total  = buffer_abyss_x + buffer->abyss.width;
+  gint  buffer_abyss_y = buffer->abyss.y + buffer_shift_y;
+  gint  abyss_y_total  = buffer_abyss_y + buffer->abyss.height;
 
   if (i->roi.width == 0 || i->roi.height == 0)
     return FALSE;
@@ -207,20 +219,35 @@
        }
      else
        {
-         /* gap between left side of tile, and abyss */
          i->subrect.x = offsetx;
          i->subrect.y = offsety;
-         /* gap between right side of tile, and abyss */
-
 
-         i->subrect.width = (i->roi.width - i->col < tile_width) ?
-                             (i->roi.width - i->col) - i->subrect.x:
-                             tile_width - i->subrect.x;
+         i->subrect.width = pixels;
+        /* (i->roi.width - i->col + tile_width < tile_width) ?
+                             (i->roi.width - i->col + tile_width) - i->subrect.x:
+                             tile_width - i->subrect.x;*/
 
-         i->subrect.height = (i->roi.height - i->row < tile_height) ?
-                             (i->roi.height - i->row) - i->subrect.y:
+         i->subrect.height = (i->roi.height - i->row + tile_height < tile_height) ?
+                             (i->roi.height - i->row + tile_height) - i->subrect.y:
                              tile_height - i->subrect.y;
 
+         if(1){
+         gint lskip = (buffer_abyss_x) - (buffer_x + i->col);
+         /* gap between left side of tile, and abyss */
+         gint rskip = (buffer_x + i->col + i->subrect.width) - abyss_x_total;
+         /* gap between right side of tile, and abyss */
+
+           if (lskip < 0)
+              lskip = 0;
+           if (lskip > i->subrect.width)
+              lskip = i->subrect.width;
+           if (rskip < 0)
+              rskip = 0;
+           if (rskip > i->subrect.width)
+              rskip = i->subrect.width;
+           i->subrect.width = i->subrect.width - rskip - lskip;
+         }
+
          i->tile = gegl_tile_source_get_tile ((GeglTileSource *) (buffer),
                                                gegl_tile_indice (tiledx, tile_width),
                                                gegl_tile_indice (tiledy, tile_height),
@@ -240,6 +267,8 @@
          /* update with new future position (note this means that the
           * coordinates read from the iterator do not make full sense 
           * */
+         i->real_col = i->col;
+         i->real_row = i->row;
          i->col += tile_width - offsetx;
 
          return TRUE;
@@ -250,6 +279,8 @@
       gint tiledy = buffer_y + i->row;
       gint offsety = gegl_tile_offset (tiledy, tile_height);
 
+      i->real_row = i->row;
+      i->real_col = i->col;
       i->row += tile_height - offsety;
       i->col=0;
 

Modified: trunk/gegl/buffer/gegl-buffer-private.h
==============================================================================
--- trunk/gegl/buffer/gegl-buffer-private.h	(original)
+++ trunk/gegl/buffer/gegl-buffer-private.h	Sun Jun  1 22:55:04 2008
@@ -107,6 +107,8 @@
   GeglRectangle  roi;
   gint           col;
   gint           row;
+  gint           real_col;
+  gint           real_row;
   gboolean       write;   /* perhaps in a subclass struct? */
   GeglRectangle  subrect; /* has x==-1 when entire tile is valid */
   gpointer       data;
@@ -120,22 +122,25 @@
   gint                   rowstride; /* allows computing  */
   gint                   length;
   gint                   row;
+  gint                   real_row;
   gpointer               data;
 } GeglBufferScanIterator;
 
 #define gegl_buffer_scan_iterator_get_x(i) \
-    (((GeglBufferTileIterator*)(i))->col)
+    ((((GeglBufferTileIterator*)(i))->roi.x) + \
+    (((GeglBufferTileIterator*)(i))->real_col))
 #define gegl_buffer_scan_iterator_get_y(i) \
-    ((((GeglBufferTileIterator*)(i))->col)+ ((GeglBufferScanIterator*)(i))->row - 1)
+    ( (((GeglBufferTileIterator*)(i))->roi.y)+ \
+      (((GeglBufferTileIterator*)(i))->real_row)+ \
+      ((GeglBufferScanIterator*)(i))->real_row)
 
 #define gegl_buffer_scan_iterator_get_rectangle(i,rect_ptr) \
   if(i){GeglRectangle *foo = rect_ptr;\
    if (foo) {\
    foo->x=gegl_buffer_scan_iterator_get_x(i);\
    foo->y=gegl_buffer_scan_iterator_get_y(i);\
-   foo->width= ((GeglBufferScanIterator*)i)->rowstride;\
-   foo->height=((GeglBufferScanIterator*)i)->length/ \
-                                       ((GeglBufferScanIterator*)i)->rowstride;\
+   foo->width= ((GeglBufferTileIterator*)i)->subrect.width;\
+   foo->height=((GeglBufferScanIterator*)i)->length/ foo->width;\
    }}
 
 

Modified: trunk/gegl/operation/gegl-operation-point-render.c
==============================================================================
--- trunk/gegl/operation/gegl-operation-point-render.c	(original)
+++ trunk/gegl/operation/gegl-operation-point-render.c	Sun Jun  1 22:55:04 2008
@@ -39,18 +39,31 @@
 
 static void prepare (GeglOperation *operation)
 {
-  gegl_operation_set_format (operation, "input", babl_format ("RGBA float"));
   gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
 }
 
+static GeglNode *
+detect (GeglOperation *operation,
+        gint           x,
+        gint           y)
+{
+  return NULL;
+}
+
 static void
 gegl_operation_point_render_class_init (GeglOperationPointRenderClass *klass)
 {
-  GeglOperationSourceClass *source_class = GEGL_OPERATION_SOURCE_CLASS (klass);
-  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
+  GeglOperationSourceClass *source_class    = GEGL_OPERATION_SOURCE_CLASS (klass);
+  GeglOperationClass       *operation_class = GEGL_OPERATION_CLASS (klass);
 
-  source_class->process = process_inner;
+  source_class->process    = process_inner;
   operation_class->prepare = prepare;
+
+  operation_class->detect = detect;
+  operation_class->no_cache = TRUE;
+  operation_class->get_cached_region = NULL; /* we are able to compute anything
+                                                 anywhere when we're our kind
+                                                 of class */
 }
 
 static void

Modified: trunk/operations/common/checkerboard.c
==============================================================================
--- trunk/operations/common/checkerboard.c	(original)
+++ trunk/operations/common/checkerboard.c	Sun Jun  1 22:55:04 2008
@@ -32,7 +32,7 @@
 
 #else
 
-#define GEGL_CHANT_TYPE_SOURCE
+#define GEGL_CHANT_TYPE_POINT_RENDER
 #define GEGL_CHANT_C_FILE       "checkerboard.c"
 
 #include "gegl-chant.h"
@@ -46,21 +46,23 @@
 static GeglRectangle
 get_bounding_box (GeglOperation *operation)
 {
-  GeglRectangle result = {-10000000, -10000000, 20000000, 20000000};
+  /*GeglRectangle result = {-10000000, -10000000, 20000000, 20000000};*/
+  GeglRectangle result = {40,40,540,540};
   return result;
 }
 
 static gboolean
-process (GeglOperation       *operation,
-         GeglBuffer          *output,
-         const GeglRectangle *result)
+process (GeglOperation *operation,
+         void          *out_buf,
+         glong          n_pixels,
+         GeglRectangle *roi)
 {
   GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
-  gfloat     *buf;
+  gfloat     *out_pixel = out_buf;
   gfloat      color1[4];
   gfloat      color2[4];
-  gint        pxsize;
-  gint        n_pixels;
+  gint        x = roi->x; /* initial x                   */
+  gint        y = roi->y; /*           and y coordinates */
 
   gegl_color_get_rgba (o->color1,
                        &color1[0],
@@ -74,34 +76,38 @@
                        &color2[2],
                        &color2[3]);
 
-  g_object_get (output, "px-size", &pxsize,
-                        "pixels", &n_pixels,
-                        NULL);
-  buf = g_malloc (n_pixels * pxsize);
+  while (n_pixels--)
     {
-      gfloat *dst=buf;
-      gint y;
-      for (y=0; y < result->height; y++)
+      gint nx,ny;
+
+      nx = ((x + o->x_offset + 100000 * o->x)/o->x) ;
+      ny = ((y + o->y_offset + 100000 * o->y)/o->y) ;
+
+      if ( (nx+ny) % 2 == 0)
         {
-          gint x;
-          for (x=0; x < result->width ; x++)
-            {
-              gfloat *rgba_color;
-              gint nx,ny;
-
-              nx = ((x + result->x + o->x_offset + 100000 * o->x)/o->x) ;
-              ny = ((y + result->y + o->y_offset + 100000 * o->y)/o->y) ;
-
-              rgba_color = (nx+ny) % 2 == 0 ? color1 : color2;
-
-              memcpy (dst, rgba_color, 4*sizeof(gfloat));
-              dst += 4;
-            }
+          out_pixel[0]=color1[0];
+          out_pixel[1]=color1[1];
+          out_pixel[2]=color1[2];
+          out_pixel[3]=color1[3];
+        }
+      else
+        {
+          out_pixel[0]=color2[0];
+          out_pixel[1]=color2[1];
+          out_pixel[2]=color2[2];
+          out_pixel[3]=color2[3];
         }
-    }
 
-  gegl_buffer_set (output, NULL, NULL, buf, GEGL_AUTO_ROWSTRIDE);
-  g_free (buf);
+      out_pixel += 4;
+
+      /* update x and y coordinates */
+      x++;
+      if (x>=roi->x + roi->width)
+        {
+          x=roi->x;
+          y++;
+        }
+    }
 
   return  TRUE;
 }
@@ -110,22 +116,19 @@
 static void
 gegl_chant_class_init (GeglChantClass *klass)
 {
-  GeglOperationClass       *operation_class;
-  GeglOperationSourceClass *source_class;
+  GeglOperationClass            *operation_class;
+  GeglOperationPointRenderClass *point_render_class;
 
   operation_class = GEGL_OPERATION_CLASS (klass);
-  source_class    = GEGL_OPERATION_SOURCE_CLASS (klass);
+  point_render_class = GEGL_OPERATION_POINT_RENDER_CLASS (klass);
 
-  source_class->process = process;
+  point_render_class->process = process;
   operation_class->get_bounding_box = get_bounding_box;
   operation_class->prepare = prepare;
 
   operation_class->name        = "checkerboard";
   operation_class->categories  = "render";
   operation_class->description = "Checkerboard renderer.";
-
-  operation_class->no_cache = TRUE;
-  operation_class->get_cached_region = NULL;
 }
 
 #endif

Modified: trunk/operations/common/color.c
==============================================================================
--- trunk/operations/common/color.c	(original)
+++ trunk/operations/common/color.c	Sun Jun  1 22:55:04 2008
@@ -39,14 +39,6 @@
   return result;
 }
 
-static GeglNode *
-detect (GeglOperation *operation,
-        gint           x,
-        gint           y)
-{
-  return NULL;
-}
-
 static gboolean
 process (GeglOperation *operation,
          void          *out_buf,
@@ -93,10 +85,6 @@
   operation_class->categories  = "render";
   operation_class->description =
         "Generates a buffer entirely filled with the specified color, crop it to get smaller dimensions.";
-
-  operation_class->no_cache = TRUE;
-  operation_class->detect = detect;
-  operation_class->get_cached_region = NULL;
 }
 
 #endif



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