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