[gegl/soc-2011-ops] Added cubism op
- From: Robert Sasu <sasurobert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2011-ops] Added cubism op
- Date: Mon, 4 Jul 2011 09:06:03 +0000 (UTC)
commit f68e9ab6908a9db2247a637f91bac2b9699429d4
Author: Robert Sasu <sasu robert gmail com>
Date: Mon Jul 4 12:05:27 2011 +0300
Added cubism op
operations/workshop/cubism.c | 61 ++++++++++++++++++++++++-----------------
1 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/operations/workshop/cubism.c b/operations/workshop/cubism.c
index 03a21dd..4ffe2d2 100644
--- a/operations/workshop/cubism.c
+++ b/operations/workshop/cubism.c
@@ -52,9 +52,6 @@ gegl_chant_boolean (background, _("Background"), FALSE,
#define MAX_POINTS 4
#define RANDOMNESS 5
-FILE *f;
-
-
typedef struct
{
gint x,y;
@@ -81,8 +78,6 @@ static void prepare (GeglOperation *operation)
*/
tmp = ceil ((9 * o->tile_size / 8.0) * o->tile_saturation);
-
- fprintf(f,"op_area: %d\n",tmp);
op_area->left = op_area->right = op_area->top = op_area->bottom = tmp;
@@ -268,7 +263,6 @@ fill_poly_color (Polygon *poly,
GeglBuffer *output,
const GeglRectangle *extended,
const GeglRectangle *boundary,
- const GeglRectangle *roi,
gfloat *dst_buf,
gfloat *color)
{
@@ -295,6 +289,7 @@ fill_poly_color (Polygon *poly,
gint x1, y1, x2, y2;
gint *vals, *vals_iter, *vals_end;
gint b;
+ GeglRectangle rect;
sx = poly->pts[0].x;
sy = poly->pts[0].y;
@@ -424,17 +419,31 @@ fill_poly_color (Polygon *poly,
xx - sx,
yy - sy));
- for (b = 0; b < 4; b++)
+ gegl_buffer_sample (output, x, y, 1.0, buf,
+ babl_format ("RGBA float"),
+ GEGL_INTERPOLATION_NEAREST);
+
+ /* for (b = 0; b < 4; b++)
buf[b] = dst_buf[( (y-extended->y) * extended->width
+ (x-extended->x)) * 4 + b];
-
+ */
for (b = 0; b < 4; b++)
buf[b] = (color[b] * alpha) + (buf[b] * (1 - alpha));
- for (b = 0; b < 4; b++)
+
+
+ /* for (b = 0; b < 4; b++)
dst_buf[((y-extended->y) * extended->width +
(x - extended->x)) * 4 + b] = buf[b];
-
+ */
+ rect.x = x;
+ rect.y = y;
+ rect.width = 1;
+ rect.height = 1;
+
+ gegl_buffer_set (output, &rect,
+ babl_format ("RGBA float"), buf,
+ GEGL_AUTO_ROWSTRIDE);
}
}
}
@@ -490,10 +499,7 @@ process (GeglOperation *operation,
extended.height = CLAMP (result->height + op_area->top + op_area->bottom, 0,
boundary.height);
- fprintf(f,"%d %d\n",extended.width, extended.height);
- printf("%d %d \n",extended.width, extended.height);
-
- dst_buf = g_new0 (gfloat, extended.width * extended.height * 4);
+ dst_buf = g_new0 (gfloat, result->width * result->height * 4);
if (!o->background)
{
@@ -508,8 +514,8 @@ process (GeglOperation *operation,
cols = (result->width + o->tile_size - 1) / o->tile_size;
rows = (result->height + o->tile_size - 1) / o->tile_size;
- set_background_color (dst_buf, &extended, bg_col);
-
+ set_background_color (dst_buf, result, bg_col);
+
num_tiles = (rows + 1) * (cols + 1);
random_indices = g_new0 (gint, num_tiles);
@@ -528,10 +534,10 @@ process (GeglOperation *operation,
j = random_indices[count] % (cols + 1);
x = j * o->tile_size + (o->tile_size / 4.0)
- - g_rand_double_range (gr, 0, (o->tile_size /2.0) + result->x);
+ - g_rand_double_range (gr, 0, (o->tile_size /2.0)) + result->x;
y = i * o->tile_size + (o->tile_size / 4.0)
- - g_rand_double_range (gr, 0, (o->tile_size /2.0) + result->y);
+ - g_rand_double_range (gr, 0, (o->tile_size /2.0)) + result->y;
width = (o->tile_size +
g_rand_double_range (gr, -o->tile_size / 8.0, o->tile_size / 8.0))
@@ -551,19 +557,18 @@ process (GeglOperation *operation,
polygon_rotate (&poly, theta);
polygon_translate (&poly, x, y);
-
ix = CLAMP (x, boundary.x, boundary.x + boundary.width - 1);
iy = CLAMP (y, boundary.y, boundary.y + boundary.height - 1);
gegl_buffer_sample (input, ix, iy, 1.0, color, format,
GEGL_INTERPOLATION_NEAREST);
- fill_poly_color (&poly, input, output, &extended, &boundary, result,
+ fill_poly_color (&poly, input, output, &extended, &boundary,
dst_buf, color);
}
-
+ /*
gegl_buffer_set (output, &extended, format, dst_buf, GEGL_AUTO_ROWSTRIDE);
-
+ */
g_free (dst_buf);
g_free (random_indices);
@@ -606,7 +611,14 @@ get_required_for_output (GeglOperation *operation,
return result;
}
-
+/*
+static GeglRectangle
+get_cached_region (GeglOperation *operation,
+ const GeglRectangle *roi)
+{
+ return *gegl_operation_source_get_bounding_box (operation, "input");
+}
+*/
static void
gegl_chant_class_init (GeglChantClass *klass)
@@ -614,8 +626,6 @@ gegl_chant_class_init (GeglChantClass *klass)
GeglOperationClass *operation_class;
GeglOperationFilterClass *filter_class;
- f = fopen ("tryyy","w+t");
-
operation_class = GEGL_OPERATION_CLASS (klass);
filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
@@ -623,6 +633,7 @@ gegl_chant_class_init (GeglChantClass *klass)
operation_class->prepare = prepare;
operation_class->get_bounding_box = get_bounding_box;
operation_class->get_required_for_output = get_required_for_output;
+/* operation_class->get_cached_region = get_cached_region;*/
operation_class->categories = "artistic";
operation_class->name = "gegl:cubism";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]