[gegl/soc-2012-ops] Shift Operation: Use gegl_chant_seed and fix formatting.
- From: Hans Shu Lo <hanslo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2012-ops] Shift Operation: Use gegl_chant_seed and fix formatting.
- Date: Thu, 9 Aug 2012 02:17:49 +0000 (UTC)
commit 95d7e22c4c7cb90e14c001ba08e104083d2fdad9
Author: Hans Lo <hansshulo gmail com>
Date: Wed Aug 8 17:58:24 2012 -0400
Shift Operation: Use gegl_chant_seed and fix formatting.
operations/common/shift.c | 109 ++++++++++++++++++++++-----------------------
1 files changed, 54 insertions(+), 55 deletions(-)
---
diff --git a/operations/common/shift.c b/operations/common/shift.c
index f9559a3..3d504f2 100644
--- a/operations/common/shift.c
+++ b/operations/common/shift.c
@@ -26,8 +26,7 @@
gegl_chant_int (shift, _("Shift"), 1, 200, 5,
_("Maximum amount to shift"))
-gegl_chant_int (seed, _("Seed"), 0, 100, 0,
- _("Random seed"))
+gegl_chant_seed (seed, _("Seed"), _("Random seed"))
gegl_chant_register_enum (gegl_direction)
enum_value (GEGL_HORIZONTAL, "Horizontal")
@@ -48,7 +47,7 @@ static void prepare (GeglOperation *operation)
{
GeglChantO *o;
GeglOperationAreaFilter *op_area;
-
+
op_area = GEGL_OPERATION_AREA_FILTER (operation);
o = GEGL_CHANT_PROPERTIES (operation);
@@ -56,7 +55,7 @@ static void prepare (GeglOperation *operation)
g_array_free (o->chant_data, TRUE);
o->chant_data = NULL;
}
-
+
if (o->direction == GEGL_HORIZONTAL)
{
op_area->left = o->shift;
@@ -94,7 +93,7 @@ process (GeglOperation *operation,
gint x = 0; /* initial x */
gint y = 0; /* and y coordinates */
-
+
gfloat *in_pixel;
gfloat *out_pixel;
@@ -107,41 +106,41 @@ process (GeglOperation *operation,
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
GeglRectangle *boundary;
-
+
GRand *gr;
-
+
gint array_size = 0;
gint r;
/* calculate offsets once */
g_static_mutex_lock (&mutex);
if (!o->chant_data)
- {
+ {
boundary = gegl_operation_source_get_bounding_box (operation, "input");
if (boundary)
- {
- gr = g_rand_new ();
- g_rand_set_seed (gr, o->seed);
-
- offsets = g_array_new(FALSE, FALSE, sizeof(gint));
-
- if (o->direction == GEGL_HORIZONTAL)
- {
- array_size = boundary->height;
- }
- else if (o->direction == GEGL_VERTICAL)
- {
- array_size = boundary->width;
- }
-
- for (i = 0; i < array_size; i++)
- {
- r = g_rand_int_range(gr, -s, s);
- g_array_append_val(offsets, r);
- }
- o->chant_data = offsets;
- }
+ {
+ gr = g_rand_new ();
+ g_rand_set_seed (gr, o->seed);
+
+ offsets = g_array_new (FALSE, FALSE, sizeof (gint));
+
+ if (o->direction == GEGL_HORIZONTAL)
+ {
+ array_size = boundary->height;
+ }
+ else if (o->direction == GEGL_VERTICAL)
+ {
+ array_size = boundary->width;
+ }
+
+ for (i = 0; i < array_size; i++)
+ {
+ r = g_rand_int_range (gr, -s, s);
+ g_array_append_val (offsets, r);
+ }
+ o->chant_data = offsets;
+ }
}
g_static_mutex_unlock (&mutex);
offsets = (GArray*) o->chant_data;
@@ -151,47 +150,47 @@ process (GeglOperation *operation,
src_rect.y = result->y - op_area->top;
src_rect.height = result->height + op_area->top + op_area->bottom;
- src_buf = g_slice_alloc (src_rect.width * src_rect.height * 4 * sizeof(gfloat));
- dst_buf = g_slice_alloc (result->width * result->height * 4 * sizeof(gfloat));
+ src_buf = g_slice_alloc (src_rect.width * src_rect.height * 4 * sizeof (gfloat));
+ dst_buf = g_slice_alloc (result->width * result->height * 4 * sizeof (gfloat));
in_pixel = src_buf;
out_pixel = dst_buf;
gegl_buffer_get (input, &src_rect, 1.0, babl_format ("RGBA float"),
- src_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+ src_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
while (n_pixels--)
{
/* select the desired input pixel */
if (o->direction == GEGL_HORIZONTAL)
- {
- shift = g_array_index(offsets, gint, result->y + y);
- in_pixel = src_buf + 4*(src_rect.width * y + s + x + shift);
- }
+ {
+ shift = g_array_index (offsets, gint, result->y + y);
+ in_pixel = src_buf + 4*(src_rect.width * y + s + x + shift);
+ }
else if (o->direction == GEGL_VERTICAL)
- {
- shift = g_array_index(offsets, gint, result->x + x);
- in_pixel = src_buf + 4*(src_rect.width * (y + s + shift) + x);
- }
-
+ {
+ shift = g_array_index (offsets, gint, result->x + x);
+ in_pixel = src_buf + 4*(src_rect.width * (y + s + shift) + x);
+ }
+
/* copy pixel */
for (i = 0; i < 4; i++)
- {
- *out_pixel = *in_pixel;
- in_pixel ++;
- out_pixel ++;
- }
+ {
+ *out_pixel = *in_pixel;
+ in_pixel ++;
+ out_pixel ++;
+ }
x++;
if (x == result->width)
- {
- x = 0;
- y++;
- }
+ {
+ x = 0;
+ y++;
+ }
}
-
+
gegl_buffer_set (output, result, 0, babl_format ("RGBA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
- g_slice_free1 (src_rect.width * src_rect.height * 4 * sizeof(gfloat), src_buf);
- g_slice_free1 (result->width * result->height * 4 * sizeof(gfloat), dst_buf);
+ g_slice_free1 (src_rect.width * src_rect.height * 4 * sizeof (gfloat), src_buf);
+ g_slice_free1 (result->width * result->height * 4 * sizeof (gfloat), dst_buf);
return TRUE;
}
@@ -215,7 +214,7 @@ gegl_chant_class_init (GeglChantClass *klass)
GObjectClass *object_class;
GeglOperationClass *operation_class;
GeglOperationFilterClass *filter_class;
-
+
object_class = G_OBJECT_CLASS (klass);
operation_class = GEGL_OPERATION_CLASS (klass);
filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]