[gegl/gsoc2009-gpu] Texture dup test should test on random images



commit aac4fd574a527a91a682e1dfec4ed1627e93ca60
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Thu Aug 20 06:33:19 2009 +0800

    Texture dup test should test on random images
    
    Texture dup test should test on random images instead of static blocks
    of colors to handle more transfer cases (i.e. mirrored).

 tests/test-gegl-gpu-texture-dup.c |   42 ++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 16 deletions(-)
---
diff --git a/tests/test-gegl-gpu-texture-dup.c b/tests/test-gegl-gpu-texture-dup.c
index 6da33df..8bbf137 100644
--- a/tests/test-gegl-gpu-texture-dup.c
+++ b/tests/test-gegl-gpu-texture-dup.c
@@ -19,11 +19,17 @@
 #include <babl/babl.h>
 
 #include "gegl.h"
+#include "gegl-utils.h"
 #include "gegl-gpu-texture.h"
 
 #define SUCCESS 0
 #define FAILURE (-1)
 
+#define TEXTURE_WIDTH  50
+#define TEXTURE_HEIGHT 50
+
+#define RANDOM_PIXEL_COUNT 1000
+
 gint
 main (gint    argc,
       gchar **argv)
@@ -38,35 +44,39 @@ main (gint    argc,
 
   gegl_init (&argc, &argv);
 
-  texture1 = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
+  texture1 = gegl_gpu_texture_new (TEXTURE_WIDTH,
+                                   TEXTURE_HEIGHT,
+                                   babl_format ("RGBA float"));
 
-  components1 = g_new (gfloat, 50 * 50 * 4);
-  components2 = g_new (gfloat, 50 * 50 * 4);
+  components1 = g_new (gfloat, TEXTURE_WIDTH * TEXTURE_HEIGHT * 4);
+  components2 = g_new (gfloat, TEXTURE_WIDTH * TEXTURE_HEIGHT * 4);
 
     {
       gint cnt;
 
-      /* generate random image */
-      for (cnt = 0; cnt < 1000; cnt++)
+      for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; 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, TEXTURE_WIDTH);
+          gint y = g_random_int_range (0, TEXTURE_HEIGHT);
+
+          gfloat *pixel = &components1[((y * TEXTURE_WIDTH) + x) * 4];
+
+          pixel[0] = g_random_double ();
+          pixel[1] = g_random_double ();
+          pixel[2] = g_random_double ();
+          pixel[3] = g_random_double ();
         }
 
-      /* duplicate texture */
+      /* set texture to a random image */
       gegl_gpu_texture_set (texture1, NULL, components1, NULL);
+
+      /* duplicate texture */
       texture2 = gegl_gpu_texture_dup (texture1);
       gegl_gpu_texture_get (texture2, NULL, components2, NULL);
 
       /* compare the two images */
-      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
-        if (components1[cnt] != components2[cnt])
+      for (cnt = 0; cnt < TEXTURE_WIDTH * TEXTURE_HEIGHT * 4; cnt++)
+        if (!GEGL_FLOAT_EQUAL (components1[cnt], components2[cnt]))
           {
             g_printerr ("The gegl_gpu_texture_dup() test failed. Aborting.\n");
             retval = FAILURE;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]