Commit 27d9e45d authored by Daniel Sabo's avatar Daniel Sabo

operations: A faster gegl:checkerboard

parent b25abdc2
...@@ -65,6 +65,11 @@ get_bounding_box (GeglOperation *operation) ...@@ -65,6 +65,11 @@ get_bounding_box (GeglOperation *operation)
return gegl_rectangle_infinite_plane (); return gegl_rectangle_infinite_plane ();
} }
#define TILE_INDEX(coordinate,stride) \
(((coordinate) >= 0)?\
(coordinate) / (stride):\
((((coordinate) + 1) /(stride)) - 1))
static gboolean static gboolean
process (GeglOperation *operation, process (GeglOperation *operation,
void *out_buf, void *out_buf,
...@@ -73,71 +78,62 @@ process (GeglOperation *operation, ...@@ -73,71 +78,62 @@ process (GeglOperation *operation,
gint level) gint level)
{ {
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
const Babl *out_format = babl_format ("RGBA float");
gfloat *out_pixel = out_buf; gfloat *out_pixel = out_buf;
gfloat color1[4]; gfloat color1[4];
gfloat color2[4]; gfloat color2[4];
gint x = roi->x; /* initial x */ gint y;
gint y = roi->y; /* and y coordinates */ gint x;
const gint x_min = roi->x - o->x_offset;
gegl_color_get_pixel (o->color1, babl_format ("RGBA float"), color1); const gint y_min = roi->y - o->y_offset;
gegl_color_get_pixel (o->color2, babl_format ("RGBA float"), color2); const gint x_max = roi->x + roi->width - o->x_offset;
const gint y_max = roi->y + roi->height - o->y_offset;
while (n_pixels--) const gint square_width = o->x;
{ const gint square_height = o->y;
gint nx,ny;
if ((x - o->x_offset) < 0) gegl_color_get_pixel (o->color1, out_format, color1);
{ gegl_color_get_pixel (o->color2, out_format, color2);
nx = div (x - o->x_offset + 1, o->x).quot;
}
else
{
nx = div (x - o->x_offset, o->x).quot;
}
if ((y - o->y_offset) < 0) for (y = y_min; y < y_max; y++)
{ {
ny = div (y - o->y_offset + 1, o->y).quot; x = x_min;
}
else
{
ny = div (y - o->y_offset, o->y).quot;
}
/* shift negative cell indices */ gfloat *cur_color;
nx -= (x - o->x_offset) < 0 ? 1 : 0;
ny -= (y - o->y_offset) < 0 ? 1 : 0;
if ( (nx+ny) % 2 == 0) /* Figure out which box we're in */
{ gint tilex = TILE_INDEX (x, square_width);
out_pixel[0]=color1[0]; gint tiley = TILE_INDEX (y, square_height);
out_pixel[1]=color1[1]; if ((tilex + tiley) % 2 == 0)
out_pixel[2]=color1[2]; cur_color = color1;
out_pixel[3]=color1[3];
}
else else
{ cur_color = color2;
out_pixel[0]=color2[0];
out_pixel[1]=color2[1];
out_pixel[2]=color2[2];
out_pixel[3]=color2[3];
}
out_pixel += 4; while (x < x_max)
/* update x and y coordinates */
x++;
if (x>=roi->x + roi->width)
{ {
x=roi->x; /* Figure out how long this stripe is */
y++; gint stripe_end = (TILE_INDEX (x, square_width) + 1) * square_width;
stripe_end = stripe_end > x_max ? x_max : stripe_end;
while (x < stripe_end)
{
*out_pixel++ = cur_color[0];
*out_pixel++ = cur_color[1];
*out_pixel++ = cur_color[2];
*out_pixel++ = cur_color[3];
x++;
}
if (cur_color == color1)
cur_color = color2;
else
cur_color = color1;
} }
} }
return TRUE; return TRUE;
} }
static void static void
gegl_chant_class_init (GeglChantClass *klass) gegl_chant_class_init (GeglChantClass *klass)
{ {
......
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