[gegl] Bug 779903 - wind is non deterministic
- From: Thomas Manni <tmanni src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] Bug 779903 - wind is non deterministic
- Date: Wed, 15 Mar 2017 13:37:29 +0000 (UTC)
commit e24a7f730ae2d308d738dd4013e425287bb3b3b0
Author: Thomas Manni <thomas manni free fr>
Date: Wed Mar 15 12:56:54 2017 +0100
Bug 779903 - wind is non deterministic
Add a seed property to the operation and use gegl_random_* functions
operations/common/wind.c | 38 +++++++++++++++++++++++---------------
1 files changed, 23 insertions(+), 15 deletions(-)
---
diff --git a/operations/common/wind.c b/operations/common/wind.c
index 8347e07..86d3fb7 100644
--- a/operations/common/wind.c
+++ b/operations/common/wind.c
@@ -65,6 +65,8 @@ property_int (strength, _("Strength"), 10)
description (_("Higher values increase the magnitude of the effect"))
value_range (1, 100)
+property_seed (seed, _("Random seed"), rand)
+
#else
#define GEGL_OP_FILTER
@@ -188,7 +190,8 @@ render_wind_row (gfloat *buffer,
gint n_components,
gint lpi,
GeglProperties *o,
- GRand *gr)
+ gint x,
+ gint y)
{
gfloat *blend_color;
gfloat *target_color;
@@ -227,7 +230,7 @@ render_wind_row (gfloat *buffer,
target_color[b] = buffer[sbi + b];
}
- if (g_rand_int_range (gr, 0, 3))
+ if (gegl_random_int_range (o->rand, x, y, 0, 0, 0, 3))
{
bleed_length_max = o->strength;
}
@@ -236,7 +239,8 @@ render_wind_row (gfloat *buffer,
bleed_length_max = 4 * o->strength;
}
- bleed_length = 1 + (gint) (bleed_length_max * g_rand_double (gr));
+ bleed_length = 1 + (gint) (bleed_length_max *
+ gegl_random_float (o->rand, x, y, 0, 1));
lbi = sbi + bleed_length * n_components;
if (lbi > lpi)
@@ -257,7 +261,7 @@ render_wind_row (gfloat *buffer,
has_alpha,
o->edge,
o->threshold)
- && g_rand_boolean (gr))
+ && gegl_random_int_range (o->rand, x, y, 0, 2, 0, 1))
{
break;
}
@@ -286,6 +290,8 @@ render_wind_row (gfloat *buffer,
n--;
}
}
+
+ x++;
}
g_free (target_color);
@@ -298,7 +304,8 @@ render_blast_row (gfloat *buffer,
gint n_components,
gint lpi,
GeglProperties *o,
- GRand *gr)
+ gint x,
+ gint y)
{
gint sbi, lbi;
gint bleed_length;
@@ -317,7 +324,7 @@ render_blast_row (gfloat *buffer,
o->threshold))
{
sbi = j;
- weight = g_rand_int_range (gr, 0, 10);
+ weight = gegl_random_int_range (o->rand, x, y, 0, 0, 0, 10);
if (weight > 5)
{
@@ -334,7 +341,7 @@ render_blast_row (gfloat *buffer,
bleed_length = 0;
- switch (g_rand_int_range (gr, 0, random_factor))
+ switch (gegl_random_int_range (o->rand, x, y, 0, 1, 0, random_factor))
{
case 3:
bleed_length += o->strength;
@@ -358,11 +365,13 @@ render_blast_row (gfloat *buffer,
j = lbi - n_components;
- if (g_rand_int_range (gr, 0, 10) > 7)
+ if (gegl_random_int_range (o->rand, x, y, 0, 2, 0, 10) > 7)
{
skip = TRUE;
}
}
+
+ x++;
}
return skip;
}
@@ -547,14 +556,11 @@ process (GeglOperation *operation,
gint row_start, row_end;
GeglRectangle row_rect;
gfloat *row_buf;
- GRand *gr;
gboolean skip_rows;
gboolean need_reverse;
gboolean horizontal_effect;
gint last_pix;
- gr = g_rand_new ();
-
horizontal_effect = (o->direction == GEGL_WIND_DIRECTION_LEFT ||
o->direction == GEGL_WIND_DIRECTION_RIGHT);
@@ -599,12 +605,13 @@ process (GeglOperation *operation,
{
last_pix = row_size - (n_components * COMPARE_WIDTH);
skip_rows = FALSE;
- render_wind_row (row_buf, n_components, last_pix, o, gr);
+ render_wind_row (row_buf, n_components, last_pix, o, row_rect.x, y);
}
else
{
last_pix = row_size - n_components;
- skip_rows = render_blast_row (row_buf, n_components, last_pix, o, gr);
+ skip_rows = render_blast_row (row_buf, n_components, last_pix, o,
+ row_rect.x, y);
}
if (need_reverse)
@@ -616,7 +623,9 @@ process (GeglOperation *operation,
if (skip_rows)
{
GeglRectangle rect = row_rect;
- gint n_rows = g_rand_int_range (gr, 1, 3);
+ gint n_rows = gegl_random_int_range (o->rand,
+ row_rect.x, y, 0, 4,
+ 1, 3);
if (horizontal_effect)
{
@@ -634,7 +643,6 @@ process (GeglOperation *operation,
}
}
- g_rand_free (gr);
g_free (row_buf);
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]