Commit 7e1c32aa authored by Øyvind Kolås's avatar Øyvind Kolås

modified to make the roi for the scan iterator reported be correct.

* 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.

svn path=/trunk/; revision=2367
parent 53771ae1
2008-06-01 Øyvind Kolås <pippin@gimp.org>
* 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.
2008-06-01 Øyvind Kolås <pippin@gimp.org>
* operations/common/color.c: (process), (gegl_chant_class_init): base
......
......@@ -45,9 +45,9 @@ GStaticRecMutex mutex = G_STATIC_REC_MUTEX_INIT;
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 @@ void gegl_buffer_tile_iterator_init (GeglBufferTileIterator *i,
i->row = 0;
i->col = 0;
i->tile = NULL;
i->real_col = 0;
i->real_row = 0;
i->write = write;
}
......@@ -82,6 +84,7 @@ void gegl_buffer_scan_iterator_init (GeglBufferScanIterator *i,
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 @@ gegl_buffer_scan_iterator_next (GeglBufferScanIterator *i)
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 @@ gegl_buffer_scan_iterator_next (GeglBufferScanIterator *i)
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 @@ gegl_buffer_scan_iterator_next (GeglBufferScanIterator *i)
{
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 @@ gegl_buffer_tile_iterator_next (GeglBufferTileIterator *i)
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 @@ gulp:
}
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 @@ gulp:
/* 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 @@ gulp:
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;
......
......@@ -107,6 +107,8 @@ typedef struct GeglBufferTileIterator
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 @@ typedef struct GeglBufferScanIterator {
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;\
}}
......
......@@ -39,18 +39,31 @@ G_DEFINE_TYPE (GeglOperationPointRender, gegl_operation_point_render, GEGL_TYPE_
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
......
......@@ -32,7 +32,7 @@ gegl_chant_color (color2, "Other color", "white",
#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 @@ prepare (GeglOperation *operation)
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,35 +76,39 @@ process (GeglOperation *operation,
&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 x;
for (x=0; x < result->width ; x++)
{
gfloat *rgba_color;
gint nx,ny;
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) ;
nx = ((x + o->x_offset + 100000 * o->x)/o->x) ;
ny = ((y + o->y_offset + 100000 * o->y)/o->y) ;
rgba_color = (nx+ny) % 2 == 0 ? color1 : color2;
if ( (nx+ny) % 2 == 0)
{
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];
}
memcpy (dst, rgba_color, 4*sizeof(gfloat));
dst += 4;
}
out_pixel += 4;
/* update x and y coordinates */
x++;
if (x>=roi->x + roi->width)
{
x=roi->x;
y++;
}
}
gegl_buffer_set (output, NULL, NULL, buf, GEGL_AUTO_ROWSTRIDE);
g_free (buf);
return TRUE;
}
......@@ -110,22 +116,19 @@ process (GeglOperation *operation,
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
......@@ -39,14 +39,6 @@ get_bounding_box (GeglOperation *operation)
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 @@ gegl_chant_class_init (GeglChantClass *klass)
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment