[gegl] tests: Add test case for linear shift
- From: Daniel Sabo <daniels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] tests: Add test case for linear shift
- Date: Tue, 10 Sep 2013 01:21:49 +0000 (UTC)
commit b87a98110dd8b62b75c63aea0c5f339c46861d2e
Author: Daniel Sabo <DanielSabo gmail com>
Date: Mon Sep 9 18:01:28 2013 -0700
tests: Add test case for linear shift
tests/buffer/reference/linear_shift.buf | 8 +++
tests/buffer/tests/linear_shift.c | 91 +++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 0 deletions(-)
---
diff --git a/tests/buffer/reference/linear_shift.buf b/tests/buffer/reference/linear_shift.buf
new file mode 100644
index 0000000..9b656af
--- /dev/null
+++ b/tests/buffer/reference/linear_shift.buf
@@ -0,0 +1,8 @@
+Test: linear_shift
+▛▀▀▀▀▀▜
+▌░░▒░░▐
+▌░░▒░░▐
+▌▒▒█▒▒▐
+▌░░▒░░▐
+▌░░▒░░▐
+▙▄▄▄▄▄▟
diff --git a/tests/buffer/tests/linear_shift.c b/tests/buffer/tests/linear_shift.c
new file mode 100644
index 0000000..f988113
--- /dev/null
+++ b/tests/buffer/tests/linear_shift.c
@@ -0,0 +1,91 @@
+TEST ()
+{
+ GeglBuffer *out;
+ gint i;
+ GeglBuffer *linear_a;
+ GeglBuffer *linear_b;
+ GeglBuffer *linear_c;
+ GeglBuffer *linear_d;
+ gfloat *linear_data;
+ GeglBufferIterator *iter;
+ GeglRectangle out_extent = {-1, -1, 5, 5};
+
+ test_start();
+
+ linear_data = malloc (sizeof(float) * 3 * 3);
+
+ for (i = 0; i < 3 * 3; ++i)
+ linear_data[i] = 0.25;
+
+ linear_a = gegl_buffer_linear_new_from_data (linear_data,
+ babl_format ("Y float"),
+ GEGL_RECTANGLE(-1, -1, 3, 3),
+ GEGL_AUTO_ROWSTRIDE,
+ NULL,
+ NULL);
+
+ linear_b = gegl_buffer_linear_new_from_data (linear_data,
+ babl_format ("Y float"),
+ GEGL_RECTANGLE(1, -1, 3, 3),
+ GEGL_AUTO_ROWSTRIDE,
+ NULL,
+ NULL);
+
+ linear_c = gegl_buffer_linear_new_from_data (linear_data,
+ babl_format ("Y float"),
+ GEGL_RECTANGLE(1, 1, 3, 3),
+ GEGL_AUTO_ROWSTRIDE,
+ NULL,
+ NULL);
+
+ linear_d = gegl_buffer_linear_new_from_data (linear_data,
+ babl_format ("Y float"),
+ GEGL_RECTANGLE(-1, 1, 3, 3),
+ GEGL_AUTO_ROWSTRIDE,
+ NULL,
+ NULL);
+
+ out = gegl_buffer_new (&out_extent, babl_format ("Y float"));
+
+ iter = gegl_buffer_iterator_new (out, &out_extent, 0, NULL,
+ GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
+
+ gegl_buffer_iterator_add (iter, linear_a, &out_extent, 0, NULL,
+ GEGL_BUFFER_READ, GEGL_ABYSS_BLACK);
+
+ gegl_buffer_iterator_add (iter, linear_b, &out_extent, 0, NULL,
+ GEGL_BUFFER_READ, GEGL_ABYSS_BLACK);
+
+ gegl_buffer_iterator_add (iter, linear_c, &out_extent, 0, NULL,
+ GEGL_BUFFER_READ, GEGL_ABYSS_BLACK);
+
+ gegl_buffer_iterator_add (iter, linear_d, &out_extent, 0, NULL,
+ GEGL_BUFFER_READ, GEGL_ABYSS_BLACK);
+
+ while (gegl_buffer_iterator_next (iter))
+ {
+ gint ix, iy, pos;
+
+ pos = 0;
+ for (iy = iter->roi[0].y; iy < iter->roi[0].y + iter->roi[0].height; ++iy)
+ for (ix = iter->roi[0].x; ix < iter->roi[0].x + iter->roi[0].width; ++ix)
+ {
+ gfloat **fdata = (gfloat **)iter->data;
+
+ fdata[0][pos] = fdata[1][pos] + fdata[2][pos] + fdata[3][pos] + fdata[4][pos];
+ if (fdata[0][pos] > 1.0f)
+ fdata[0][pos] = 1.0f;
+
+ ++pos;
+ }
+ }
+
+ print_buffer (out);
+ g_object_unref (out);
+ g_object_unref (linear_a);
+ g_object_unref (linear_b);
+ g_object_unref (linear_c);
+ g_object_unref (linear_d);
+ free (linear_data);
+ test_end ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]