[gegl] domain-transform: code cleanup
- From: Thomas Manni <tmanni src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] domain-transform: code cleanup
- Date: Thu, 18 Jul 2019 17:22:55 +0000 (UTC)
commit 6250741eac8b0daba6f7807ac29ed8805737ced5
Author: Thomas Manni <thomas manni free fr>
Date: Thu Jul 18 18:30:19 2019 +0200
domain-transform: code cleanup
Keep the file 80 characters wide + indentation cleanup.
operations/workshop/domain-transform.c | 469 +++++++++++++++++----------------
1 file changed, 246 insertions(+), 223 deletions(-)
---
diff --git a/operations/workshop/domain-transform.c b/operations/workshop/domain-transform.c
index 13f516f9b..ee1a6cf1a 100644
--- a/operations/workshop/domain-transform.c
+++ b/operations/workshop/domain-transform.c
@@ -21,16 +21,20 @@
#ifdef GEGL_PROPERTIES
-property_int (num_iterations, _("Quality"), 3)
- description(_("Number of filtering iterations. A value between 2 and 4 is usually enough."))
+property_int (n_iterations, _("Quality"), 3)
+ description(_("Number of filtering iterations. "
+ "A value between 2 and 4 is usually enough."))
value_range (1, 5)
property_double (spatial_factor, _("Blur radius"), 30.0)
- description (_("Spatial standard deviation of the blur kernel, measured in pixels."))
+ description (_("Spatial standard deviation of the blur kernel, "
+ "measured in pixels."))
value_range (0, 1000.0)
property_double (edge_preservation, _("Edge preservation"), 0.8)
- description (_("Amount of edge preservation. This quantity is inversely proportional to the range
standard deviation of the blur kernel."))
+ description (_("Amount of edge preservation. This quantity is inversely "
+ "proportional to the range standard deviation of the blur "
+ "kernel."))
value_range (0, 1.0)
#else
@@ -61,17 +65,19 @@ absolute (gint16 x)
}
static void
-report_progress (GeglOperation* operation, gdouble progress, GTimer* timer)
+report_progress (GeglOperation *operation,
+ gdouble progress,
+ GTimer *timer)
{
static gboolean reported = FALSE;
if (progress == 0.0)
reported = FALSE;
- if (g_timer_elapsed(timer, NULL) >= REPORT_PROGRESS_TIME && !reported)
+ if (g_timer_elapsed (timer, NULL) >= REPORT_PROGRESS_TIME && !reported)
{
reported = TRUE;
- gegl_operation_progress(operation, 0.0, "");
+ gegl_operation_progress (operation, 0.0, "");
}
if (reported)
@@ -79,293 +85,315 @@ report_progress (GeglOperation* operation, gdouble progress, GTimer* timer)
}
static gint
-domain_transform (GeglOperation *operation,
- gint image_width,
- gint image_height,
- gint image_channels,
- gfloat spatial_factor,
- gfloat range_factor,
- gint num_iterations,
- GeglBuffer *input,
- GeglBuffer *output)
+domain_transform (GeglOperation *operation,
+ gint width,
+ gint height,
+ gint n_chan,
+ gfloat spatial_factor,
+ gfloat range_factor,
+ gint n_iterations,
+ GeglBuffer *input,
+ GeglBuffer *output)
{
- gfloat** rf_table;
- guint16* transforms_buffer;
- gfloat* image_buffer;
-
- gint16 last_pixel_r, last_pixel_g, last_pixel_b;
- gint16 current_pixel_r, current_pixel_g, current_pixel_b;
- gfloat last_pixel_r_f, last_pixel_g_f, last_pixel_b_f, last_pixel_a_f;
- gfloat current_pixel_r_f, current_pixel_g_f, current_pixel_b_f, current_pixel_a_f;
- gfloat sum_channels_difference, a, w, current_standard_deviation;
- gint i, j, k, n, real_stride, d_x_position, d_y_position, biggest_dimension;
- guint16 d;
- GeglRectangle current_rectangle;
- GTimer* timer;
-
- timer = g_timer_new();
+ gfloat **rf_table;
+ guint16 *transforms_buffer;
+ gfloat *buffer;
+
+ gint16 last[3];
+ gint16 current[3];
+ gfloat lastf[4];
+ gfloat currentf[4];
+ gfloat sum_channels_difference, a, w, sdt_dev;
+ gint i, j, k, n;
+ gint real_stride, d_x_position, d_y_position, biggest_dimension;
+ guint16 d;
+ GeglRectangle rect;
+ GTimer *timer;
+
+ timer = g_timer_new ();
/* PRE-ALLOC MEMORY */
- biggest_dimension = (image_width > image_height) ? image_width : image_height;
- image_buffer = g_new(gfloat, BLOCK_STRIDE * biggest_dimension * image_channels);
- transforms_buffer = g_new(guint16, BLOCK_STRIDE * biggest_dimension);
+ biggest_dimension = (width > height) ? width : height;
+ buffer = g_new (gfloat, BLOCK_STRIDE * biggest_dimension * n_chan);
+ transforms_buffer = g_new (guint16, BLOCK_STRIDE * biggest_dimension);
- rf_table = g_new(gfloat*, num_iterations);
- for (i = 0; i < num_iterations; ++i)
- rf_table[i] = g_new(gfloat, RF_TABLE_SIZE);
+ rf_table = g_new (gfloat *, n_iterations);
+
+ for (i = 0; i < n_iterations; ++i)
+ rf_table[i] = g_new (gfloat, RF_TABLE_SIZE);
/* ************************ */
- report_progress(operation, 0.0, timer);
+ report_progress (operation, 0.0, timer);
/* Pre-calculate RF table */
- for (i = 0; i < num_iterations; ++i)
+ for (i = 0; i < n_iterations; ++i)
{
/* calculating RF feedback coefficient 'a' from desired variance
* 'a' will change each iteration while the domain transform will
* remain constant
*/
- current_standard_deviation = spatial_factor * SQRT3 * (powf(2.0f, (gfloat)(num_iterations - (i + 1)))
/ sqrtf(powf(4.0f, (gfloat)num_iterations) - 1));
- a = expf(-SQRT2 / current_standard_deviation);
-
+ sdt_dev = spatial_factor * SQRT3 *
+ (powf (2.0f, (gfloat)(n_iterations - (i + 1))) /
+ sqrtf (powf (4.0f, (gfloat) n_iterations) - 1));
+
+ a = expf (-SQRT2 / sdt_dev);
+
for (j = 0; j < RF_TABLE_SIZE; ++j)
- rf_table[i][j] = powf(a, 1.0f + (spatial_factor / range_factor) * ((gfloat)j / 255.0f));
+ {
+ rf_table[i][j] = powf (a, 1.0f + (spatial_factor / range_factor) *
+ ((gfloat)j / 255.0f));
+ }
}
/* Filter Iterations */
- for (n = 0; n < num_iterations; ++n)
+ for (n = 0; n < n_iterations; ++n)
{
/* Horizontal Pass */
- for (i = 0; i < image_height; i += BLOCK_STRIDE)
+ for (i = 0; i < height; i += BLOCK_STRIDE)
{
- real_stride = (i + BLOCK_STRIDE > image_height) ? image_height - i : BLOCK_STRIDE;
+ real_stride = (i + BLOCK_STRIDE > height) ? height - i : BLOCK_STRIDE;
- current_rectangle.x = 0;
- current_rectangle.y = i;
- current_rectangle.width = image_width;
- current_rectangle.height = real_stride;
+ rect.x = 0;
+ rect.y = i;
+ rect.width = width;
+ rect.height = real_stride;
- gegl_buffer_get (input, ¤t_rectangle, 1.0, babl_format ("R'G'B' u8"), image_buffer,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
+ gegl_buffer_get (input, &rect, 1.0, babl_format ("R'G'B' u8"),
+ buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
/* Domain Transform */
- for (j = 0; j < current_rectangle.height; ++j)
+ for (j = 0; j < rect.height; ++j)
{
- last_pixel_r = ((guint8*)image_buffer)[j * current_rectangle.width * 3];
- last_pixel_g = ((guint8*)image_buffer)[j * current_rectangle.width * 3 + 1];
- last_pixel_b = ((guint8*)image_buffer)[j * current_rectangle.width * 3 + 2];
+ last[0] = ((guint8*) buffer)[j * rect.width * 3];
+ last[1] = ((guint8*) buffer)[j * rect.width * 3 + 1];
+ last[2] = ((guint8*) buffer)[j * rect.width * 3 + 2];
- for (k = 0; k < current_rectangle.width; ++k)
+ for (k = 0; k < rect.width; ++k)
{
- current_pixel_r = ((guint8*)image_buffer)[j * current_rectangle.width * 3 + k * 3];
- current_pixel_g = ((guint8*)image_buffer)[j * current_rectangle.width * 3 + k * 3 + 1];
- current_pixel_b = ((guint8*)image_buffer)[j * current_rectangle.width * 3 + k * 3 + 2];
+ current[0] = ((guint8*) buffer)[j * rect.width * 3 + k * 3];
+ current[1] = ((guint8*) buffer)[j * rect.width * 3 + k * 3 + 1];
+ current[2] = ((guint8*) buffer)[j * rect.width * 3 + k * 3 + 2];
- sum_channels_difference = absolute(current_pixel_r - last_pixel_r) +
absolute(current_pixel_g - last_pixel_g) + absolute(current_pixel_b - last_pixel_b);
+ sum_channels_difference = absolute (current[0] - last[0]) +
+ absolute (current[1] - last[1]) +
+ absolute (current[2] - last[2]);
/* @NOTE: 'd' should be 1.0f + s_s / s_r * sum_diff
* However, we will store just sum_diff.
* 1.0f + s_s / s_r will be calculated later when calculating
* the RF table. This is done this way because the sum_diff is
* perfect to be used as the index of the RF table.
- * d = 1.0f + (vdt_information->spatial_factor / vdt_information->range_factor) *
sum_channels_difference;
+ * d = 1.0f + (vdt_information->spatial_factor /
+ * vdt_information->range_factor) * sum_channels_difference;
*/
- transforms_buffer[j * current_rectangle.width + k] = sum_channels_difference;
+ transforms_buffer[j * rect.width + k] = sum_channels_difference;
- last_pixel_r = current_pixel_r;
- last_pixel_g = current_pixel_g;
- last_pixel_b = current_pixel_b;
+ last[0] = current[0];
+ last[1] = current[1];
+ last[2] = current[2];
}
}
if (n == 0)
- gegl_buffer_get (input, ¤t_rectangle, 1.0, babl_format ("R'G'B'A float"), image_buffer,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
+ gegl_buffer_get (input, &rect, 1.0, babl_format ("R'G'B'A float"),
+ buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
else
- gegl_buffer_get (output, ¤t_rectangle, 1.0, babl_format ("R'G'B'A float"), image_buffer,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
+ gegl_buffer_get (output, &rect, 1.0, babl_format ("R'G'B'A float"),
+ buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
/* Horizontal Filter (Left-Right) */
- for (j = 0; j < current_rectangle.height; ++j)
+ for (j = 0; j < rect.height; ++j)
{
- last_pixel_r_f = image_buffer[j * current_rectangle.width * image_channels];
- last_pixel_g_f = image_buffer[j * current_rectangle.width * image_channels + 1];
- last_pixel_b_f = image_buffer[j * current_rectangle.width * image_channels + 2];
- last_pixel_a_f = image_buffer[j * current_rectangle.width * image_channels + 3];
+ lastf[0] = buffer[j * rect.width * n_chan];
+ lastf[1] = buffer[j * rect.width * n_chan + 1];
+ lastf[2] = buffer[j * rect.width * n_chan + 2];
+ lastf[3] = buffer[j * rect.width * n_chan + 3];
- for (k = 0; k < current_rectangle.width; ++k)
+ for (k = 0; k < rect.width; ++k)
{
- d = transforms_buffer[j * current_rectangle.width + k];
+ d = transforms_buffer[j * rect.width + k];
w = rf_table[n][d];
- current_pixel_r_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels];
- current_pixel_g_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels + 1];
- current_pixel_b_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels + 2];
- current_pixel_a_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels + 3];
+ currentf[0] = buffer[j * rect.width * n_chan + k * n_chan];
+ currentf[1] = buffer[j * rect.width * n_chan + k * n_chan + 1];
+ currentf[2] = buffer[j * rect.width * n_chan + k * n_chan + 2];
+ currentf[3] = buffer[j * rect.width * n_chan + k * n_chan + 3];
- last_pixel_r_f = ((1 - w) * current_pixel_r_f + w * last_pixel_r_f);
- last_pixel_g_f = ((1 - w) * current_pixel_g_f + w * last_pixel_g_f);
- last_pixel_b_f = ((1 - w) * current_pixel_b_f + w * last_pixel_b_f);
- last_pixel_a_f = ((1 - w) * current_pixel_a_f + w * last_pixel_a_f);
+ lastf[0] = ((1 - w) * currentf[0] + w * lastf[0]);
+ lastf[1] = ((1 - w) * currentf[1] + w * lastf[1]);
+ lastf[2] = ((1 - w) * currentf[2] + w * lastf[2]);
+ lastf[3] = ((1 - w) * currentf[3] + w * lastf[3]);
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels] =
last_pixel_r_f;
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels + 1] =
last_pixel_g_f;
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels + 2] =
last_pixel_b_f;
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels + 3] =
last_pixel_a_f;
+ buffer[j * rect.width * n_chan + k * n_chan] = lastf[0];
+ buffer[j * rect.width * n_chan + k * n_chan + 1] = lastf[1];
+ buffer[j * rect.width * n_chan + k * n_chan + 2] = lastf[2];
+ buffer[j * rect.width * n_chan + k * n_chan + 3] = lastf[3];
}
}
/* Horizontal Filter (Right-Left) */
- for (j = 0; j < current_rectangle.height; ++j)
+ for (j = 0; j < rect.height; ++j)
{
- last_pixel_r_f = image_buffer[j * current_rectangle.width * image_channels +
(current_rectangle.width - 1) * image_channels];
- last_pixel_g_f = image_buffer[j * current_rectangle.width * image_channels +
(current_rectangle.width - 1) * image_channels + 1];
- last_pixel_b_f = image_buffer[j * current_rectangle.width * image_channels +
(current_rectangle.width - 1) * image_channels + 2];
- last_pixel_a_f = image_buffer[j * current_rectangle.width * image_channels +
(current_rectangle.width - 1) * image_channels + 3];
+ lastf[0] = buffer[j * rect.width * n_chan + (rect.width - 1) * n_chan];
+ lastf[1] = buffer[j * rect.width * n_chan + (rect.width - 1) * n_chan + 1];
+ lastf[2] = buffer[j * rect.width * n_chan + (rect.width - 1) * n_chan + 2];
+ lastf[3] = buffer[j * rect.width * n_chan + (rect.width - 1) * n_chan + 3];
- for (k = current_rectangle.width - 1; k >= 0; --k)
+ for (k = rect.width - 1; k >= 0; --k)
{
- d_x_position = (k < current_rectangle.width - 1) ? k + 1 : k;
- d = transforms_buffer[j * current_rectangle.width + d_x_position];
+ d_x_position = (k < rect.width - 1) ? k + 1 : k;
+ d = transforms_buffer[j * rect.width + d_x_position];
w = rf_table[n][d];
- current_pixel_r_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels];
- current_pixel_g_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels + 1];
- current_pixel_b_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels + 2];
- current_pixel_a_f = image_buffer[j * current_rectangle.width * image_channels + k *
image_channels + 3];
+ currentf[0] = buffer[j * rect.width * n_chan + k * n_chan];
+ currentf[1] = buffer[j * rect.width * n_chan + k * n_chan + 1];
+ currentf[2] = buffer[j * rect.width * n_chan + k * n_chan + 2];
+ currentf[3] = buffer[j * rect.width * n_chan + k * n_chan + 3];
- last_pixel_r_f = ((1 - w) * current_pixel_r_f + w * last_pixel_r_f);
- last_pixel_g_f = ((1 - w) * current_pixel_g_f + w * last_pixel_g_f);
- last_pixel_b_f = ((1 - w) * current_pixel_b_f + w * last_pixel_b_f);
- last_pixel_a_f = ((1 - w) * current_pixel_a_f + w * last_pixel_a_f);
+ lastf[0] = ((1 - w) * currentf[0] + w * lastf[0]);
+ lastf[1] = ((1 - w) * currentf[1] + w * lastf[1]);
+ lastf[2] = ((1 - w) * currentf[2] + w * lastf[2]);
+ lastf[3] = ((1 - w) * currentf[3] + w * lastf[3]);
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels] =
last_pixel_r_f;
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels + 1] =
last_pixel_g_f;
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels + 2] =
last_pixel_b_f;
- image_buffer[j * current_rectangle.width * image_channels + k * image_channels + 3] =
last_pixel_a_f;
+ buffer[j * rect.width * n_chan + k * n_chan] = lastf[0];
+ buffer[j * rect.width * n_chan + k * n_chan + 1] = lastf[1];
+ buffer[j * rect.width * n_chan + k * n_chan + 2] = lastf[2];
+ buffer[j * rect.width * n_chan + k * n_chan + 3] = lastf[3];
}
}
- gegl_buffer_set (output, ¤t_rectangle, 0, babl_format ("R'G'B'A float"), image_buffer,
GEGL_AUTO_ROWSTRIDE);
+ gegl_buffer_set (output, &rect, 0, babl_format ("R'G'B'A float"),
+ buffer, GEGL_AUTO_ROWSTRIDE);
}
- report_progress(operation, (2.0 * n + 1.0) / (2.0 * num_iterations), timer);
+ report_progress (operation, (2.0 * n + 1.0) / (2.0 * n_iterations), timer);
/* Vertical Pass */
- for (i = 0; i < image_width; i += BLOCK_STRIDE)
+ for (i = 0; i < width; i += BLOCK_STRIDE)
{
- real_stride = (i + BLOCK_STRIDE > image_width) ? image_width - i : BLOCK_STRIDE;
+ real_stride = (i + BLOCK_STRIDE > width) ? width - i : BLOCK_STRIDE;
- current_rectangle.x = i;
- current_rectangle.y = 0;
- current_rectangle.width = real_stride;
- current_rectangle.height = image_height;
+ rect.x = i;
+ rect.y = 0;
+ rect.width = real_stride;
+ rect.height = height;
- gegl_buffer_get (input, ¤t_rectangle, 1.0, babl_format ("R'G'B' u8"), image_buffer,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
+ gegl_buffer_get (input, &rect, 1.0, babl_format ("R'G'B' u8"),
+ buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
/* Domain Transform */
- for (j = 0; j < current_rectangle.width; ++j)
+ for (j = 0; j < rect.width; ++j)
{
- last_pixel_r = ((guint8*)image_buffer)[j * 3];
- last_pixel_g = ((guint8*)image_buffer)[j * 3 + 1];
- last_pixel_b = ((guint8*)image_buffer)[j * 3 + 2];
+ last[0] = ((guint8*) buffer)[j * 3];
+ last[1] = ((guint8*) buffer)[j * 3 + 1];
+ last[2] = ((guint8*) buffer)[j * 3 + 2];
- for (k = 0; k < current_rectangle.height; ++k)
+ for (k = 0; k < rect.height; ++k)
{
- current_pixel_r = ((guint8*)image_buffer)[k * current_rectangle.width * 3 + j * 3];
- current_pixel_g = ((guint8*)image_buffer)[k * current_rectangle.width * 3 + j * 3 + 1];
- current_pixel_b = ((guint8*)image_buffer)[k * current_rectangle.width * 3 + j * 3 + 2];
+ current[0] = ((guint8*) buffer)[k * rect.width * 3 + j * 3];
+ current[1] = ((guint8*) buffer)[k * rect.width * 3 + j * 3 + 1];
+ current[2] = ((guint8*) buffer)[k * rect.width * 3 + j * 3 + 2];
- sum_channels_difference = absolute(current_pixel_r - last_pixel_r) +
absolute(current_pixel_g - last_pixel_g) + absolute(current_pixel_b - last_pixel_b);
+ sum_channels_difference = absolute (current[0] - last[0]) +
+ absolute (current[1] - last[1]) +
+ absolute (current[2] - last[2]);
/* @NOTE: 'd' should be 1.0f + s_s / s_r * sum_diff
* However, we will store just sum_diff.
* 1.0f + s_s / s_r will be calculated later when calculating
* the RF table. This is done this way because the sum_diff is
* perfect to be used as the index of the RF table.
- * d = 1.0f + (vdt_information->spatial_factor / vdt_information->range_factor) *
sum_channels_difference;
+ * d = 1.0f + (vdt_information->spatial_factor /
+ * vdt_information->range_factor) * sum_channels_difference;
*/
- transforms_buffer[k * current_rectangle.width + j] = sum_channels_difference;
+ transforms_buffer[k * rect.width + j] = sum_channels_difference;
- last_pixel_r = current_pixel_r;
- last_pixel_g = current_pixel_g;
- last_pixel_b = current_pixel_b;
+ last[0] = current[0];
+ last[1] = current[1];
+ last[2] = current[2];
}
}
- gegl_buffer_get (output, ¤t_rectangle, 1.0, babl_format ("R'G'B'A float"), image_buffer,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
+ gegl_buffer_get (output, &rect, 1.0, babl_format ("R'G'B'A float"),
+ buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
/* Vertical Filter (Top-Down) */
- for (j = 0; j < current_rectangle.width; ++j)
+ for (j = 0; j < rect.width; ++j)
{
- last_pixel_r_f = image_buffer[j * image_channels];
- last_pixel_g_f = image_buffer[j * image_channels + 1];
- last_pixel_b_f = image_buffer[j * image_channels + 2];
- last_pixel_a_f = image_buffer[j * image_channels + 3];
+ lastf[0] = buffer[j * n_chan];
+ lastf[1] = buffer[j * n_chan + 1];
+ lastf[2] = buffer[j * n_chan + 2];
+ lastf[3] = buffer[j * n_chan + 3];
- for (k = 0; k < current_rectangle.height; ++k)
+ for (k = 0; k < rect.height; ++k)
{
- d = transforms_buffer[k * current_rectangle.width + j];
+ d = transforms_buffer[k * rect.width + j];
w = rf_table[n][d];
- current_pixel_r_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels];
- current_pixel_g_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels + 1];
- current_pixel_b_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels + 2];
- current_pixel_a_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels + 3];
+ currentf[0] = buffer[k * rect.width * n_chan + j * n_chan];
+ currentf[1] = buffer[k * rect.width * n_chan + j * n_chan + 1];
+ currentf[2] = buffer[k * rect.width * n_chan + j * n_chan + 2];
+ currentf[3] = buffer[k * rect.width * n_chan + j * n_chan + 3];
- last_pixel_r_f = ((1 - w) * current_pixel_r_f + w * last_pixel_r_f);
- last_pixel_g_f = ((1 - w) * current_pixel_g_f + w * last_pixel_g_f);
- last_pixel_b_f = ((1 - w) * current_pixel_b_f + w * last_pixel_b_f);
- last_pixel_a_f = ((1 - w) * current_pixel_a_f + w * last_pixel_a_f);
+ lastf[0] = ((1 - w) * currentf[0] + w * lastf[0]);
+ lastf[1] = ((1 - w) * currentf[1] + w * lastf[1]);
+ lastf[2] = ((1 - w) * currentf[2] + w * lastf[2]);
+ lastf[3] = ((1 - w) * currentf[3] + w * lastf[3]);
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels] =
last_pixel_r_f;
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels + 1] =
last_pixel_g_f;
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels + 2] =
last_pixel_b_f;
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels + 3] =
last_pixel_a_f;
+ buffer[k * rect.width * n_chan + j * n_chan] = lastf[0];
+ buffer[k * rect.width * n_chan + j * n_chan + 1] = lastf[1];
+ buffer[k * rect.width * n_chan + j * n_chan + 2] = lastf[2];
+ buffer[k * rect.width * n_chan + j * n_chan + 3] = lastf[3];
}
}
/* Vertical Filter (Bottom-Up) */
- for (j = 0; j < current_rectangle.width; ++j)
+ for (j = 0; j < rect.width; ++j)
{
- last_pixel_r_f = image_buffer[(current_rectangle.height - 1) * current_rectangle.width *
image_channels + j * image_channels];
- last_pixel_g_f = image_buffer[(current_rectangle.height - 1) * current_rectangle.width *
image_channels + j * image_channels + 1];
- last_pixel_b_f = image_buffer[(current_rectangle.height - 1) * current_rectangle.width *
image_channels + j * image_channels + 2];
- last_pixel_a_f = image_buffer[(current_rectangle.height - 1) * current_rectangle.width *
image_channels + j * image_channels + 3];
+ lastf[0] = buffer[(rect.height - 1) * rect.width * n_chan + j * n_chan];
+ lastf[1] = buffer[(rect.height - 1) * rect.width * n_chan + j * n_chan + 1];
+ lastf[2] = buffer[(rect.height - 1) * rect.width * n_chan + j * n_chan + 2];
+ lastf[3] = buffer[(rect.height - 1) * rect.width * n_chan + j * n_chan + 3];
- for (k = current_rectangle.height - 1; k >= 0; --k)
+ for (k = rect.height - 1; k >= 0; --k)
{
- d_y_position = (k < current_rectangle.height - 1) ? k + 1 : k;
- d = transforms_buffer[d_y_position * current_rectangle.width + j];
+ d_y_position = (k < rect.height - 1) ? k + 1 : k;
+ d = transforms_buffer[d_y_position * rect.width + j];
w = rf_table[n][d];
- current_pixel_r_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels];
- current_pixel_g_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels + 1];
- current_pixel_b_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels + 2];
- current_pixel_a_f = image_buffer[k * current_rectangle.width * image_channels + j *
image_channels + 3];
+ currentf[0] = buffer[k * rect.width * n_chan + j * n_chan];
+ currentf[1] = buffer[k * rect.width * n_chan + j * n_chan + 1];
+ currentf[2] = buffer[k * rect.width * n_chan + j * n_chan + 2];
+ currentf[3] = buffer[k * rect.width * n_chan + j * n_chan + 3];
- last_pixel_r_f = ((1 - w) * current_pixel_r_f + w * last_pixel_r_f);
- last_pixel_g_f = ((1 - w) * current_pixel_g_f + w * last_pixel_g_f);
- last_pixel_b_f = ((1 - w) * current_pixel_b_f + w * last_pixel_b_f);
- last_pixel_a_f = ((1 - w) * current_pixel_a_f + w * last_pixel_a_f);
+ lastf[0] = ((1 - w) * currentf[0] + w * lastf[0]);
+ lastf[1] = ((1 - w) * currentf[1] + w * lastf[1]);
+ lastf[2] = ((1 - w) * currentf[2] + w * lastf[2]);
+ lastf[3] = ((1 - w) * currentf[3] + w * lastf[3]);
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels] =
last_pixel_r_f;
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels + 1] =
last_pixel_g_f;
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels + 2] =
last_pixel_b_f;
- image_buffer[k * current_rectangle.width * image_channels + j * image_channels + 3] =
last_pixel_a_f;
+ buffer[k * rect.width * n_chan + j * n_chan] = lastf[0];
+ buffer[k * rect.width * n_chan + j * n_chan + 1] = lastf[1];
+ buffer[k * rect.width * n_chan + j * n_chan + 2] = lastf[2];
+ buffer[k * rect.width * n_chan + j * n_chan + 3] = lastf[3];
}
}
- gegl_buffer_set (output, ¤t_rectangle, 0, babl_format ("R'G'B'A float"), image_buffer,
GEGL_AUTO_ROWSTRIDE);
+ gegl_buffer_set (output, &rect, 0, babl_format ("R'G'B'A float"),
+ buffer, GEGL_AUTO_ROWSTRIDE);
}
- report_progress(operation, (2.0 * n + 2.0) / (2.0 * num_iterations), timer);
+ report_progress (operation, (2.0 * n + 2.0) / (2.0 * n_iterations), timer);
}
- g_free(transforms_buffer);
- g_free(image_buffer);
- for (i = 0; i < num_iterations; ++i)
- g_free(rf_table[i]);
- g_free(rf_table);
+ g_free (transforms_buffer);
+ g_free (buffer);
+
+ for (i = 0; i < n_iterations; ++i)
+ g_free (rf_table[i]);
- g_timer_destroy(timer);
+ g_free (rf_table);
+ g_timer_destroy (timer);
return 0;
}
@@ -382,25 +410,27 @@ get_required_for_output (GeglOperation *operation,
const gchar *input_pad,
const GeglRectangle *roi)
{
- GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
+ GeglRectangle *result =
+ gegl_operation_source_get_bounding_box (operation, "input");
/* Don't request an infinite plane */
- if (gegl_rectangle_is_infinite_plane (&result))
+ if (result && gegl_rectangle_is_infinite_plane (result))
return *roi;
- return result;
+ return *result;
}
static GeglRectangle
get_cached_region (GeglOperation *operation,
const GeglRectangle *roi)
{
- GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
+ GeglRectangle *result =
+ gegl_operation_source_get_bounding_box (operation, "input");
- if (gegl_rectangle_is_infinite_plane (&result))
+ if (result && gegl_rectangle_is_infinite_plane (result))
return *roi;
- return result;
+ return *result;
}
static gboolean
@@ -410,40 +440,30 @@ process (GeglOperation *operation,
const GeglRectangle *result,
gint level)
{
- GeglProperties *o;
- gint image_height, image_width, image_channels;
- gfloat spatial_factor, edge_preservation, range_factor, num_iterations;
-
- o = GEGL_PROPERTIES (operation);
- image_height = result->height;
- image_width = result->width;
- image_channels = 4;
+ GeglProperties *o = GEGL_PROPERTIES (operation);
+ gfloat range_factor;
- spatial_factor = o->spatial_factor;
- edge_preservation = o->edge_preservation;
- num_iterations = o->num_iterations;
-
- if (edge_preservation != 1.0f)
+ if (o->edge_preservation != 1.0f)
{
- if (edge_preservation != 0.0f)
- range_factor = (1.0f / edge_preservation) - 1.0f;
+ if (o->edge_preservation != 0.0)
+ range_factor = (1.0 / o->edge_preservation) - 1.0f;
else
range_factor = G_MAXFLOAT;
/* Buffer is ready for domain transform */
- domain_transform(operation,
- image_width,
- image_height,
- image_channels,
- spatial_factor,
- range_factor,
- num_iterations,
- input,
- output);
+ domain_transform (operation,
+ result->width,
+ result->height,
+ 4,
+ o->spatial_factor,
+ range_factor,
+ o->n_iterations,
+ input,
+ output);
}
else
{
- gegl_buffer_copy(input, result, GEGL_ABYSS_NONE, output, result);
+ gegl_buffer_copy (input, result, GEGL_ABYSS_NONE, output, result);
}
return TRUE;
@@ -466,10 +486,11 @@ operation_process (GeglOperation *operation,
operation_class = GEGL_OPERATION_CLASS (gegl_op_parent_class);
if (in_rect && gegl_rectangle_is_infinite_plane (in_rect))
- {
- gpointer in = gegl_operation_context_get_object (context, "input");
- gegl_operation_context_take_object (context, "output", g_object_ref (G_OBJECT (in)));
- return TRUE;
+ {
+ gpointer in = gegl_operation_context_get_object (context, "input");
+ gegl_operation_context_take_object (context, "output",
+ g_object_ref (G_OBJECT (in)));
+ return TRUE;
}
/* chain up, which will create the needed buffers for our actual
@@ -493,20 +514,22 @@ gegl_op_class_init (GeglOpClass *klass)
operation_class = GEGL_OPERATION_CLASS (klass);
filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
- filter_class->process = process;
- operation_class->prepare = prepare;
- operation_class->threaded = FALSE;
- operation_class->process = operation_process;
+ filter_class->process = process;
+ operation_class->prepare = prepare;
+ operation_class->threaded = FALSE;
+ operation_class->process = operation_process;
operation_class->get_required_for_output = get_required_for_output;
- operation_class->get_cached_region = get_cached_region;
- operation_class->opencl_support = FALSE;
+ operation_class->get_cached_region = get_cached_region;
+ operation_class->opencl_support = FALSE;
gegl_operation_class_set_keys (operation_class,
- "name", "gegl:domain-transform",
- "title", _("Smooth by Domain Transform"),
- "categories" , "enhance:noise-reduction",
- "description", _("An edge-preserving smoothing filter implemented with the Domain Transform recursive
technique. Similar to a bilateral filter, but faster to compute."),
- NULL);
+ "name", "gegl:domain-transform",
+ "title", _("Smooth by Domain Transform"),
+ "categories" , "enhance:noise-reduction",
+ "description", _("An edge-preserving smoothing filter implemented with the "
+ "Domain Transform recursive technique. Similar to a "
+ "bilateral filter, but faster to compute."),
+ NULL);
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]