[gegl/gsoc2009-gpu] Texture set* and copy* tests should test on random images
- From: Jerson Michael Perpetua <jperpetua src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gegl/gsoc2009-gpu] Texture set* and copy* tests should test on random images
- Date: Wed, 19 Aug 2009 22:52:16 +0000 (UTC)
commit 644d6d02389b865be970b469fce57b92341a1468
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date: Thu Aug 20 05:29:59 2009 +0800
Texture set* and copy* tests should test on random images
Texture set* and copy* tests should test on random images instead of
static blocks of colors to handle more transfer cases (i.e. mirrored).
tests/test-gegl-gpu-texture-copy-subrect.c | 48 +++++++++-----
tests/test-gegl-gpu-texture-copy.c | 29 +++++----
tests/test-gegl-gpu-texture-set-subrect.c | 95 ++++++++++++++++------------
tests/test-gegl-gpu-texture-set.c | 43 +++++++++----
4 files changed, 131 insertions(+), 84 deletions(-)
---
diff --git a/tests/test-gegl-gpu-texture-copy-subrect.c b/tests/test-gegl-gpu-texture-copy-subrect.c
index 9eb205d..8ba60e6 100644
--- a/tests/test-gegl-gpu-texture-copy-subrect.c
+++ b/tests/test-gegl-gpu-texture-copy-subrect.c
@@ -68,29 +68,42 @@ main (gint argc,
GeglGpuTexture *texture1;
GeglGpuTexture *texture2;
- gfloat *components;
+ gfloat *components1;
+ gfloat *components2;
gegl_init (&argc, &argv);
texture1 = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
texture2 = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
- components = g_new (gfloat, 4 * 50 * 50);
+ components1 = g_new0 (gfloat, 50 * 50 * 4);
+ components2 = g_new0 (gfloat, 50 * 50 * 4);
{
gint cnt;
- /* initialize first texture to some solid color */
- for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
- components[cnt] = 1.0;
+ for (cnt = 0; cnt < 1000; cnt++)
+ {
+ gint x = g_random_int_range (0, 50);
+ gint y = g_random_int_range (0, 50);
+
+ gfloat *pixel = &components1[((y * 50) + x) * 4];
- gegl_gpu_texture_set (texture1, NULL, components, NULL);
+ pixel[0] = g_random_double();
+ pixel[1] = g_random_double();
+ pixel[2] = g_random_double();
+ pixel[3] = g_random_double();
+ }
- /* clear second texture and copy individual subregions from the
- * first texture to the second texture
+ /* set the texture to a random image (note: this test assumes that
+ * gegl_gpu_texture_set() works as expected)
*/
+ gegl_gpu_texture_set (texture1, NULL, components1, NULL);
gegl_gpu_texture_clear (texture2, NULL);
+ /* copy individual subregions from the first texture to the
+ * second texture
+ */
for (cnt = 0; cnt < ARRAY_SIZE (test_cases); cnt++)
gegl_gpu_texture_copy (texture1,
&test_cases[cnt].roi,
@@ -98,8 +111,7 @@ main (gint argc,
test_cases[cnt].roi.x,
test_cases[cnt].roi.y);
- memset (components, 0, sizeof (gfloat) * 4 * 50 * 50);
- gegl_gpu_texture_get (texture2, NULL, components, NULL);
+ gegl_gpu_texture_get (texture2, NULL, components2, NULL);
/* test individual subregions */
for (cnt = 0; cnt < ARRAY_SIZE (test_cases); cnt++)
@@ -112,12 +124,15 @@ main (gint argc,
for (y = test_cases[cnt].roi.y; y <= last_y; y++)
for (x = test_cases[cnt].roi.x; x <= last_x; x++)
{
- gfloat *pixel = &components[(y * 4 * 50) + (x * 4)];
+ gint index = ((y * 50) + x) * 4;
+
+ gfloat *pixel1 = &components1[index];
+ gfloat *pixel2 = &components2[index];
- if ( !GEGL_FLOAT_EQUAL (pixel[0], 1.0)
- || !GEGL_FLOAT_EQUAL (pixel[1], 1.0)
- || !GEGL_FLOAT_EQUAL (pixel[2], 1.0)
- || !GEGL_FLOAT_EQUAL (pixel[3], 1.0))
+ if ( !GEGL_FLOAT_EQUAL (pixel1[0], pixel2[0])
+ || !GEGL_FLOAT_EQUAL (pixel1[1], pixel2[1])
+ || !GEGL_FLOAT_EQUAL (pixel1[2], pixel2[2])
+ || !GEGL_FLOAT_EQUAL (pixel1[3], pixel2[3]))
{
g_printerr ("The gegl_gpu_texture_copy() (%s) test failed. "
"Aborting.\n", test_cases[cnt].name);
@@ -130,7 +145,8 @@ main (gint argc,
}
abort:
- g_free (components);
+ g_free (components2);
+ g_free (components1);
gegl_gpu_texture_free (texture2);
gegl_gpu_texture_free (texture1);
diff --git a/tests/test-gegl-gpu-texture-copy.c b/tests/test-gegl-gpu-texture-copy.c
index b202d42..77c7e47 100644
--- a/tests/test-gegl-gpu-texture-copy.c
+++ b/tests/test-gegl-gpu-texture-copy.c
@@ -42,33 +42,36 @@ main (gint argc,
texture1 = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
texture2 = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
- components1 = g_new (gfloat, 4 * 50 * 50);
- components2 = g_new (gfloat, 4 * 50 * 50);
+ components1 = g_new (gfloat, 50 * 50 * 4);
+ components2 = g_new (gfloat, 50 * 50 * 4);
{
gint cnt;
- /* generate random image */
for (cnt = 0; cnt < 1000; cnt++)
{
- gint x = g_random_int_range (0, 50);
- gint y = g_random_int_range (0, 50);
- gfloat *pixel = &components1[(y * 50) + (x * 4)];
-
- pixel[0] = 1.0;
- pixel[1] = 1.0;
- pixel[2] = 1.0;
- pixel[3] = 1.0;
+ gint x = g_random_int_range (0, 50);
+ gint y = g_random_int_range (0, 50);
+
+ gfloat *pixel = &components1[((y * 50) + x) * 4];
+
+ pixel[0] = g_random_double();
+ pixel[1] = g_random_double();
+ pixel[2] = g_random_double();
+ pixel[3] = g_random_double();
}
+ /* set the texture to a random image (note: this test assumes that
+ * gegl_gpu_texture_set() works as expected)
+ */
gegl_gpu_texture_set (texture1, NULL, components1, NULL);
/* copy first texture to second texture */
gegl_gpu_texture_copy (texture1, NULL, texture2, 0, 0);
gegl_gpu_texture_get (texture2, NULL, components2, NULL);
- /* compare the two images */
- for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+ /* compare the two textures */
+ for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
if (!GEGL_FLOAT_EQUAL (components1[cnt], components2[cnt]))
{
g_printerr ("The gegl_gpu_texture_copy() test failed. "
diff --git a/tests/test-gegl-gpu-texture-set-subrect.c b/tests/test-gegl-gpu-texture-set-subrect.c
index c9dd4e1..96c6e5d 100644
--- a/tests/test-gegl-gpu-texture-set-subrect.c
+++ b/tests/test-gegl-gpu-texture-set-subrect.c
@@ -16,6 +16,7 @@
* Copyright 2009 Jerson Michael Perpetua <jersonperpetua gmail com>
*/
+#include <string.h>
#include <babl/babl.h>
#include "gegl.h"
@@ -65,60 +66,72 @@ main (gint argc,
};
GeglGpuTexture *texture;
- gfloat *components;
- gegl_init (&argc, &argv);
-
- texture = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
- components = g_new (gfloat, 4 * 50 * 50);
-
- {
- gint cnt;
- gfloat *region = g_new (gfloat, 4 * 10 * 10);
+ gfloat *components1;
+ gfloat *components2;
- /* set individual subregions to a solid color */
- for (cnt = 0; cnt < 4 * 10 * 10; cnt++)
- region[cnt] = 1.0;
+ gegl_init (&argc, &argv);
- gegl_gpu_texture_clear (texture, NULL);
+ texture = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
- for (cnt = 0; cnt < ARRAY_SIZE (test_cases); cnt++)
- gegl_gpu_texture_set (texture, &test_cases[cnt].roi, region, NULL);
+ components1 = g_new (gfloat, 10 * 10 * 4);
+ components2 = g_new (gfloat, 10 * 10 * 4);
- gegl_gpu_texture_get (texture, NULL, components, NULL);
+ {
+ gint i;
- /* test individual subregions */
- for (cnt = 0; cnt < ARRAY_SIZE (test_cases); cnt++)
+ for (i = 0; i < ARRAY_SIZE (test_cases); i++)
{
- gint x, y;
-
- gint last_x = test_cases[cnt].roi.x + test_cases[cnt].roi.width - 1;
- gint last_y = test_cases[cnt].roi.y + test_cases[cnt].roi.height - 1;
-
- for (y = test_cases[cnt].roi.y; y <= last_y; y++)
- for (x = test_cases[cnt].roi.x; x <= last_x; x++)
+ gint j;
+
+ memset (components1, 0, sizeof (gfloat) * 10 * 10 * 4);
+ memset (components2, 0, sizeof (gfloat) * 10 * 10 * 4);
+
+ for (j = 0; j < 400; j++)
+ {
+ gint x = g_random_int_range (0, 10);
+ gint y = g_random_int_range (0, 10);
+
+ gfloat *pixel = &components1[((y * 10) + x) * 4];
+
+ pixel[0] = g_random_double();
+ pixel[1] = g_random_double();
+ pixel[2] = g_random_double();
+ pixel[3] = g_random_double();
+ }
+
+ /* set the texture subregion to a random image */
+ gegl_gpu_texture_set (texture,
+ &test_cases[i].roi,
+ components1,
+ NULL);
+
+ /* get the texture and put it in a different buffer (actually, this
+ * test should also be considered as a test for
+ * gegl_gpu_texture_get())
+ */
+ gegl_gpu_texture_get (texture,
+ &test_cases[i].roi,
+ components2,
+ NULL);
+
+ /* test subregion */
+ for (j = 0; j < 10 * 10 * 4; j++)
+ if (!GEGL_FLOAT_EQUAL (components1[j], components2[j]))
{
- gfloat *pixel = &components[(y * 4 * 50) + (x * 4)];
-
- if ( !GEGL_FLOAT_EQUAL (pixel[0], 1.0)
- || !GEGL_FLOAT_EQUAL (pixel[1], 1.0)
- || !GEGL_FLOAT_EQUAL (pixel[2], 1.0)
- || !GEGL_FLOAT_EQUAL (pixel[3], 1.0))
- {
- g_printerr ("The gegl_gpu_texture_set() (%s) test failed. "
- "Aborting.\n", test_cases[cnt].name);
-
- retval = FAILURE;
- goto abort;
- }
+ g_printerr ("The gegl_gpu_texture_set() (%s) test failed. "
+ "Aborting.\n", test_cases[i].name);
+
+ retval = FAILURE;
+ goto abort;
}
}
-
- g_free (region);
}
abort:
- g_free (components);
+ g_free (components2);
+ g_free (components1);
+
gegl_gpu_texture_free (texture);
gegl_exit ();
diff --git a/tests/test-gegl-gpu-texture-set.c b/tests/test-gegl-gpu-texture-set.c
index 6b810dd..2ac9869 100644
--- a/tests/test-gegl-gpu-texture-set.c
+++ b/tests/test-gegl-gpu-texture-set.c
@@ -33,30 +33,43 @@ main (gint argc,
gint retval = SUCCESS;
GeglGpuTexture *texture;
- gfloat *components;
+
+ gfloat *components1;
+ gfloat *components2;
gegl_init (&argc, &argv);
- texture = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
- components = g_new (gfloat, 4 * 50 * 50);
+ texture = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
+
+ components1 = g_new0 (gfloat, 50 * 50 * 4);
+ components2 = g_new0 (gfloat, 50 * 50 * 4);
{
gint cnt;
- /* set texture to some solid color */
- for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
- components[cnt] = 1.0;
+ for (cnt = 0; cnt < 1000; cnt++)
+ {
+ gint x = g_random_int_range (0, 50);
+ gint y = g_random_int_range (0, 50);
- gegl_gpu_texture_clear (texture, NULL);
- gegl_gpu_texture_set (texture, NULL, components, NULL);
+ gfloat *pixel = &components1[((y * 50) + x) * 4];
- /* we zero to make sure that we aren't testing this array's old values */
- memset (components, 0, sizeof (gfloat) * 4 * 50 * 50);
+ pixel[0] = g_random_double();
+ pixel[1] = g_random_double();
+ pixel[2] = g_random_double();
+ pixel[3] = g_random_double();
+ }
- gegl_gpu_texture_get (texture, NULL, components, NULL);
+ /* set the texture to a random image */
+ gegl_gpu_texture_set (texture, NULL, components1, NULL);
- for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
- if (!GEGL_FLOAT_EQUAL (components[cnt], 1.0))
+ /* get the texture and put it in a different buffer (actually, this test
+ * should also be considered as a test for gegl_gpu_texture_get())
+ */
+ gegl_gpu_texture_get (texture, NULL, components2, NULL);
+
+ for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (components1[cnt], components2[cnt]))
{
g_printerr ("The gegl_gpu_texture_set() test failed. Aborting.\n");
retval = FAILURE;
@@ -65,7 +78,9 @@ main (gint argc,
}
abort:
- g_free (components);
+ g_free (components2);
+ g_free (components1);
+
gegl_gpu_texture_free (texture);
gegl_exit ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]