diff options
author | Laura Ekstrand <laura@jlekstrand.net> | 2015-09-18 17:33:25 -0700 |
---|---|---|
committer | Laura Ekstrand <laura@jlekstrand.net> | 2015-09-18 17:33:25 -0700 |
commit | 5e4b7eebe5e4d690e542dd1812a903376dad643a (patch) | |
tree | b094cfe3b82babff5c6b3c557ce8986d51998e6f | |
parent | 8ba2766cd2a4a8b38e90e3f53742512d2ef769ab (diff) |
working on a masking functionldeks-master
-rw-r--r-- | examples/testbed.c | 25 | ||||
-rw-r--r-- | operations/common/pixelize.c | 71 |
2 files changed, 85 insertions, 11 deletions
diff --git a/examples/testbed.c b/examples/testbed.c index 888a3a6a..6975b469 100644 --- a/examples/testbed.c +++ b/examples/testbed.c @@ -45,22 +45,25 @@ This is the graph we're going to construct: "width", 512.0, "height", 384.0, NULL); - GeglNode *blur = gegl_node_new_child (gegl, - "operation", "gegl:motion-blur-linear", - NULL); + GeglNode *pixelize = gegl_node_new_child (gegl, + "operation", "gegl:pixelize", + "norm", 1, + "ratio_x", 0.4, + "ratio_y", 0.4, + NULL); GeglNode *mandelbrot = gegl_node_new_child (gegl, "operation", "gegl:fractal-explorer", "shiftx", -256.0, - "fractaltype", 1, - "redmode", 2, - "greenmode", 2, - "bluemode", 2, - "redinvert", TRUE, - "greeninvert", TRUE, - "blueinvert", TRUE, + "fractaltype", 1, + "redmode", 2, + "greenmode", 2, + "bluemode", 2, + "redinvert", TRUE, + "greeninvert", TRUE, + "blueinvert", TRUE, NULL); - gegl_node_link_many (mandelbrot, blur, crop, display, NULL); + gegl_node_link_many (mandelbrot, pixelize, crop, display, NULL); /* request that the save node is processed, all dependencies will * be processed as well diff --git a/operations/common/pixelize.c b/operations/common/pixelize.c index 5a52bc3b..f2e65668 100644 --- a/operations/common/pixelize.c +++ b/operations/common/pixelize.c @@ -212,6 +212,77 @@ set_rectangle (gfloat *output, } static void +compute_mask (gint *mask, + gint *invert_mask, + GeglRectangle *rect, + GeglRectangle *rect_shape, + gint rowstride, + GeglPixelizeNorm norm) +{ + gint i, x, y; + gfloat center_x, center_y; + GeglRectangle rect2; + + if (mask) + free(mask); + if (invert_mask) + free(invert_mask); + + mask = gegl_malloc (rect->width * rect->height * sizeof(gint)); + invert_mask = gegl_malloc (rect->width * rect->height * sizeof(gint)); + for (i = 0; i < rect->width * rect->height; i++) + { + mask[i] = 0; + invert_mask[i] = 1; + } + + gfloat shape_area = rect_shape->width * rect_shape->height; + + center_x = rect_shape->x + rect_shape->width / 2.0f; + center_y = rect_shape->y + rect_shape->height / 2.0f; + + gegl_rectangle_intersect (&rect2, rect, rect_shape); + + switch (norm) + { + case (GEGL_PIXELIZE_NORM_INFINITY): + + for (y = rect2.y; y < rect2.y + rect2.height; y++) + for (x = rect2.x; x < rect2.x + rect2.width; x++) + { + mask [y * rowstride + x] = 1; + invert_mask [y * rowstride + x] = 0; + } + break; + + case (GEGL_PIXELIZE_NORM_EUCLIDEAN): + + for (y = rect->y; y < rect->y + rect->height; y++) + for (x = rect->x; x < rect->x + rect->width; x++) + if (SQR ((x - center_x) / (gfloat) rect_shape->width) + + SQR ((y - center_y) / (gfloat) rect_shape->height) <= 1.0f) + { + mask [y * rowstride + x] = 1; + invert_mask [y * rowstride + x] = 0; + } + break; + + case (GEGL_PIXELIZE_NORM_MANHATTAN): + + for (y = rect->y; y < rect->y + rect->height; y++) + for (x = rect->x; x < rect->x + rect->width; x++) + if (fabsf (center_x - x) * rect_shape->height + + fabsf (center_y - y) * rect_shape->width < shape_area) + { + mask [y * rowstride + x] = 1; + invert_mask [y * rowstride + x] = 0; + } + + break; + } +} + +static void set_rectangle_noalloc (GeglBuffer *output, GeglRectangle *rect, GeglRectangle *rect_shape, |