[gegl/soc-2011-ops] Added plasma op
- From: Robert Sasu <sasurobert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2011-ops] Added plasma op
- Date: Mon, 27 Jun 2011 18:45:28 +0000 (UTC)
commit 55b3ac8b5fe69efad5d38ceac4276b1973e31faf
Author: Robert Sasu <sasu robert gmail com>
Date: Mon Jun 27 21:44:44 2011 +0300
Added plasma op
operations/workshop/plasma.c | 322 +++++++-----------------------------------
1 files changed, 54 insertions(+), 268 deletions(-)
---
diff --git a/operations/workshop/plasma.c b/operations/workshop/plasma.c
index 422e40d..406fc88 100644
--- a/operations/workshop/plasma.c
+++ b/operations/workshop/plasma.c
@@ -33,7 +33,7 @@ gegl_chant_double (turbulance, _("Turbulance"), 0.1, 7.0, 2,
#define GEGL_CHANT_TYPE_FILTER
-#define GEGL_CHANT_C_FILE "plasma.c"
+#define GEGL_CHANT_C_FILE "plasma2.c"
#define floats_per_pixel 4
#define MANUAL_ROI_VAL 500
@@ -54,8 +54,10 @@ average_pixel (gfloat *dst_buf,
gfloat *src_buf2)
{
gint i;
- for (i = 0; i < floats_per_pixel; i++)
+ for (i = 0; i < floats_per_pixel - 1; i++)
*dst_buf++ = (*src_buf1++ + *src_buf2++) / 2;
+
+ *dst_buf = 1;
}
static void
@@ -83,7 +85,7 @@ add_random (GRand *gr,
rnd = fabs(fmod(amount, 1));
if (amount > 0)
- for (i = 0; i < floats_per_pixel-1; i++)
+ for (i = 0; i < floats_per_pixel - 1; i++)
{
tmp = dest[i] + (gfloat) g_rand_double_range(gr, -rnd, rnd);
dest[i] = CLAMP (tmp, 0, 1);
@@ -103,79 +105,22 @@ put_pixel_to_buffer (GeglBuffer *output,
GEGL_AUTO_ROWSTRIDE);
}
-
-static void
-init_rect_buf (GeglBuffer *input,
- gfloat *src_buf,
- GeglRectangle *roi,
- gint x1,
- gint y1,
- gint x2,
- gint y2)
-{
- roi->x = x1;
- roi->y = y1;
- roi->width = x2 - x1;
- roi->height = y2 - y1;
-}
-
-
-static void
-get_pixel (gfloat *src_buf,
- const GeglRectangle *src,
- gint x,
- gint y,
- gfloat *dst)
-{
- gint i, offset;
- offset = ((y - src->y) * src->width + x - src->x) * floats_per_pixel;
-
- if (src_buf == NULL) printf("NULL \n");
-
- for (i = 0; i < floats_per_pixel; i++)
- dst[i] = src_buf[offset++];
-
- dst[i] = dst[i];
-}
-
-static void
-put_pixel (gfloat *dst_buf,
- gfloat *pixel,
- gint offset)
-{
- gint i;
- for (i = 0; i < floats_per_pixel; i++)
- dst_buf[offset++] = pixel[i];
-}
-
-
-
static gboolean
-do_plasma_big (GeglBuffer *output,
- gfloat *dst_buf,
- const GeglRectangle *dst,
- gint x1,
- gint y1,
- gint x2,
- gint y2,
- gint depth,
- gint scale_depth,
- GRand *gr,
- GeglChantO *op,
- gint small)
+do_plasma_big (GeglBuffer *output,
+ gint x1,
+ gint y1,
+ gint x2,
+ gint y2,
+ gint depth,
+ gint scale_depth,
+ GRand *gr,
+ GeglChantO *op)
{
- gfloat *tl, *ml, *bl, *mt, *mm, *mb, *tr, *mr, *br;
- gfloat *tmp;
- gint xm, ym, offset;
+ gfloat tl[4], ml[4], bl[4], mt[4], mm[4], mb[4], tr[4], mr[4], br[4];
+ gfloat tmp[4];
+ gint xm, ym;
gfloat ran;
static gint count = 0;
-
- GeglRectangle roi = {0, 0, 0, 0};
- gfloat *src_buf;
- gboolean toreturn;
-
- tl = ml = bl = mt = mm = mb = tr = mr = br = tmp
- = g_new0 (gfloat, floats_per_pixel);
xm = (x1 + x2) / 2;
ym = (y1 + y2) / 2;
@@ -183,53 +128,36 @@ do_plasma_big (GeglBuffer *output,
if (depth == -1)
{
random_rgba (gr, tl);
+ put_pixel_to_buffer (output, tl, x1, y1);
+
random_rgba (gr, tr);
- random_rgba (gr, bl);
+ put_pixel_to_buffer (output, tr, x2, y1);
+
+ random_rgba (gr, bl);
+ put_pixel_to_buffer (output, bl, x1, y2);
+
random_rgba (gr, br);
+ put_pixel_to_buffer (output, br, x2, y2);
+
random_rgba (gr, mm);
+ put_pixel_to_buffer (output, mm, xm, ym);
+
random_rgba (gr, ml);
+ put_pixel_to_buffer (output, ml, x1, ym);
+
random_rgba (gr, mr);
+ put_pixel_to_buffer (output, mr, x2, ym);
+
random_rgba (gr, mt);
- random_rgba (gr, mb);
+ put_pixel_to_buffer (output, mt, xm, y1);
- if (!small)
- {
- put_pixel_to_buffer (output, tl, x1, y1);
- put_pixel_to_buffer (output, tr, x2, y1);
- put_pixel_to_buffer (output, bl, x1, y2);
- put_pixel_to_buffer (output, br, x2, y2);
- put_pixel_to_buffer (output, mm, xm, ym);
- put_pixel_to_buffer (output, ml, x1, ym);
- put_pixel_to_buffer (output, mr, x2, ym);
- put_pixel_to_buffer (output, mt, xm, y1);
- put_pixel_to_buffer (output, mb, xm, y2);
- }
- else
- {
- offset = ((y1 - dst->y) * dst->width + x1 - dst->x) * 4;
- put_pixel (dst_buf, tl, offset);
- offset = ((y1 - dst->y) * dst->width + x2 - dst->x) * 4;
- put_pixel (dst_buf, tr, offset);
- offset = ((y2 - dst->y) * dst->width + x1 - dst->x) * 4;
- put_pixel (dst_buf, bl, offset);
- offset = ((y2 - dst->y) * dst->width + x2 - dst->x) * 4;
- put_pixel (dst_buf, br, offset);
- offset = ((ym - dst->y) * dst->width + xm - dst->x) * 4;
- put_pixel (dst_buf, mm, offset);
- offset = ((ym - dst->y) * dst->width + x1 - dst->x) * 4;
- put_pixel (dst_buf, ml, offset);
- offset = ((ym - dst->y) * dst->width + x2 - dst->x) * 4;
- put_pixel (dst_buf, mr, offset);
- offset = ((y1 - dst->y) * dst->width + xm - dst->x) * 4;
- put_pixel (dst_buf, mt, offset);
- offset = ((y2 - dst->y) * dst->width + xm - dst->x) * 4;
- put_pixel (dst_buf, mb, offset);
- }
+ random_rgba (gr, mb);
+ put_pixel_to_buffer (output, mb, xm, y2);
/*ugly but working*/
return FALSE;
}
- if (!depth && !small)
+ if (!depth)
{
if (x1 == x2 && y1 == y2) return FALSE;
@@ -242,7 +170,7 @@ do_plasma_big (GeglBuffer *output,
gegl_buffer_sample (output, x2, y2, 1.0, br, babl_format ("RGBA float"),
GEGL_INTERPOLATION_NEAREST);
- ran = ((gfloat) op->turbulance / (2.0 * scale_depth));
+ ran = ((gfloat) op->turbulance / (4.0 * scale_depth));
if (xm != x1 || xm != x2)
{
@@ -294,161 +222,21 @@ do_plasma_big (GeglBuffer *output,
return x2 - x1 < 3 && y2 - y1 < 3;
}
- if (!depth && small)
- {
- if (x1 == x2 && y1 == y2) return FALSE;
-
- get_pixel (dst_buf, dst, x1, y1, tl);
- get_pixel (dst_buf, dst, x1, y2, bl);
- get_pixel (dst_buf, dst, x2, y1, tr);
- get_pixel (dst_buf, dst, x2, y2, tr);
-
- ran = ((gfloat) op->turbulance / (2.0 * scale_depth));
-
- if (xm != x1 || xm != x2)
- {
- /*left*/
- average_pixel (ml, tl, bl);
- add_random (gr, ml, ran);
- offset = ((ym - dst->y) * dst->width + x1 - dst->x) * 4;
- put_pixel (dst_buf, ml, offset);
-
- /*right*/
- if (x1 != x2)
- {
- average_pixel (mr, tr, br);
- add_random (gr, mr, ran);
- offset = ((ym - dst->y) * dst->width + x2 - dst->x) * 4;
- put_pixel (dst_buf, mr, offset);
- }
- }
-
-
- if (ym != y1 || ym != x2)
- {
- /*bottom*/
- if (x1 != xm || ym != y2)
- {
- average_pixel (mb, bl, br);
- add_random (gr, mb, ran);
- offset = ((y2 - dst->y) * dst->width + xm - dst->x) *4;
- put_pixel (dst_buf, mb, offset);
- }
-
- if (y1 != y2)
- {
- /*top*/
- average_pixel (mt, tl, tr);
- add_random (gr, mt, ran);
- offset = ((y1 - dst->y)* dst->width + xm - dst->x) * 4;
- put_pixel (dst_buf, mt, offset);
- }
- }
-
- if (y1 != y2 || x1 != x2)
- {
- average_pixel (mm, tl, br);
- average_pixel (tmp, bl, tr);
- average_pixel (mm, mm, tmp);
-
- add_random (gr, mm, ran);
- offset = ((ym - dst->y) * dst->width + xm - dst->x) * 4;
- put_pixel (dst_buf, mm, offset);
- }
- count++;
-
- return x2 - x1 < 3 && y2 - y1 < 3;
- }
-
-
if (x1 < x2 || y1 < y2)
{
- if (x2 - x1 < MANUAL_ROI_VAL && y2 - y1 < MANUAL_ROI_VAL && !small)
- {
- /*top-left*/
- src_buf = NULL;
- init_rect_buf (output, src_buf, &roi, x1, y1, xm, ym);
-
- src_buf = g_new0 (gfloat, (roi.width + 1) * (roi.height + 1) * floats_per_pixel);
- gegl_buffer_get (output, 1.0, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
-
- do_plasma_big (NULL, src_buf, &roi, x1, y1, xm, ym, depth - 1,
- scale_depth + 1, gr, op, 1);
- gegl_buffer_set (output, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
- g_free(src_buf);
- /*bottom-left*/
- init_rect_buf (output, src_buf, &roi, x1, ym, xm, y2);
-
- src_buf = g_new0 (gfloat, (roi.width + 1) * (roi.height + 1) * floats_per_pixel);
- gegl_buffer_get (output, 1.0, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
-
- do_plasma_big (NULL, src_buf, &roi, x1, ym, xm, y2, depth - 1,
- scale_depth + 1, gr, op, 1);
- gegl_buffer_set (output, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
- g_free(src_buf);
- /*top-right*/
- init_rect_buf (output, src_buf, &roi, xm, y1, x2, ym);
-
- src_buf = g_new0 (gfloat, (roi.width + 1) * (roi.height + 1) * floats_per_pixel);
- gegl_buffer_get (output, 1.0, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
-
- do_plasma_big (NULL, src_buf, &roi, xm, y1, x2, ym, depth - 1,
- scale_depth + 1, gr, op, 1);
- gegl_buffer_set (output, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
- g_free(src_buf);
- /*bottom-right*/
- init_rect_buf (output, src_buf, &roi, xm, ym, x2, y2);
-
- src_buf = g_new0 (gfloat, (roi.width + 1) * (roi.height + 1) * floats_per_pixel);
- gegl_buffer_get (output, 1.0, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
-
- toreturn = do_plasma_big (NULL, src_buf, &roi, xm, ym, x2, y2, depth - 1,
- scale_depth + 1, gr, op, 1);
- gegl_buffer_set (output, &roi, babl_format ("RGBA float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
- g_free(src_buf);
-
- return toreturn;
- }
- else if (x2 - x1 < MANUAL_ROI_VAL && y2 - y1 < MANUAL_ROI_VAL && small)
- {
/*top-left*/
- do_plasma_big (NULL, dst_buf, dst, x1, y1, xm, ym, depth - 1,
- scale_depth + 1, gr, op, 1);
+ do_plasma_big (output, x1, y1, xm, ym, depth - 1,
+ scale_depth + 1, gr, op);
/*bottom-left*/
- do_plasma_big (NULL, dst_buf, dst, x1, ym, xm, y2, depth - 1,
- scale_depth + 1, gr, op, 1);
+ do_plasma_big (output, x1, ym, xm, y2, depth - 1,
+ scale_depth + 1, gr, op);
/*top-right*/
- do_plasma_big (NULL, dst_buf, dst, xm, y1, x2, ym, depth - 1,
- scale_depth + 1, gr, op, 1);
+ do_plasma_big (output, xm, y1, x2, ym, depth - 1,
+ scale_depth + 1, gr, op);
/*bottom-right*/
- return do_plasma_big (NULL, dst_buf, dst, xm, ym, x2, y2, depth - 1,
- scale_depth + 1, gr, op, 1);
- }
- else
- {
- /*top-left*/
- do_plasma_big (output, dst_buf, dst, x1, y1, xm, ym, depth - 1,
- scale_depth + 1, gr, op, 0);
- /*bottom-left*/
- do_plasma_big (output, dst_buf, dst, x1, ym, xm, y2, depth - 1,
- scale_depth + 1, gr, op, 0);
- /*top-right*/
- do_plasma_big (output, dst_buf, dst, xm, y1, x2, ym, depth - 1,
- scale_depth + 1, gr, op, 0);
- /*bottom-right*/
- return do_plasma_big (output, dst_buf, dst, xm, ym, x2, y2, depth - 1,
- scale_depth + 1, gr, op, 0);
- }
+ return do_plasma_big (output, xm, ym, x2, y2, depth - 1,
+ scale_depth + 1, gr, op);
}
- else return TRUE;
return TRUE;
}
@@ -476,12 +264,11 @@ process (GeglOperation *operation,
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
- GeglRectangle boundary = plasma_get_bounding_box(operation);
+ GeglRectangle boundary=plasma_get_bounding_box(operation);
- GRand *gr = g_rand_new_with_seed (o->seed);
- gint depth;
- gint x, y;
- gfloat *src = NULL;
+ GRand *gr = g_rand_new_with_seed (o->seed);
+ gint depth;
+ gint x, y;
/*
* The first time only puts seed pixels (corners, center of edges,
@@ -490,15 +277,14 @@ process (GeglOperation *operation,
x = boundary.x + boundary.width;
y = boundary.y + boundary.height;
- do_plasma_big (output, src, &boundary, boundary.x, boundary.y, x-1, y-1, -1,
- 0, gr, o, 0);
+ do_plasma_big (output, boundary.x, boundary.y, x-1, y-1, -1,
+ 0, gr, o);
/*
* Now we recurse through the images, going deeper each time
*/
depth = 1;
- while (!do_plasma_big (output, src, &boundary, boundary.x, boundary.y, x-1,
- y-1, depth, 0, gr, o, 0))
-
+ while (!do_plasma_big (output, boundary.x, boundary.y, x-1,
+ y-1, depth, 0, gr, o))
depth++;
return TRUE;
@@ -537,7 +323,7 @@ gegl_chant_class_init (GeglChantClass *klass)
operation_class->get_cached_region = get_cached_region;
operation_class->categories = "render";
- operation_class->name = "gegl:plasma";
+ operation_class->name = "gegl:plasma2";
operation_class->description =
_("Performs plasma on the image.");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]