[gegl/gsoc2009-gpu] Fix and cleanup index calculation to pixel data in automated tests



commit 5195ee84f6e3d23a77a4ad6127ffcd95265bd212
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Thu Aug 20 05:46:33 2009 +0800

    Fix and cleanup index calculation to pixel data in automated tests

 tests/test-gegl-gpu-texture-clear-subrect.c        |    4 ++--
 tests/test-gegl-gpu-texture-clear.c                |    4 ++--
 tests/test-gegl-gpu-texture-dup.c                  |    8 ++++----
 tests/test-gegl-tile-cow-consistency.c             |    6 +++---
 ...t-gegl-tile-lock-mode-gpu-write-then-gpu-read.c |   12 ++++++------
 .../test-gegl-tile-lock-mode-gpu-write-then-read.c |   10 +++++-----
 .../test-gegl-tile-lock-mode-write-then-gpu-read.c |   12 ++++++------
 tests/test-gegl-tile-lock-mode-write-then-read.c   |   12 ++++++------
 8 files changed, 34 insertions(+), 34 deletions(-)
---
diff --git a/tests/test-gegl-gpu-texture-clear-subrect.c b/tests/test-gegl-gpu-texture-clear-subrect.c
index 22b606a..ab54378 100644
--- a/tests/test-gegl-gpu-texture-clear-subrect.c
+++ b/tests/test-gegl-gpu-texture-clear-subrect.c
@@ -70,7 +70,7 @@ main (gint    argc,
   gegl_init (&argc, &argv);
 
   texture    = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
-  components = g_new (gfloat, 4 * 50 * 50);
+  components = g_new (gfloat, 50 * 50 * 4);
 
     {
       gint   cnt;
@@ -114,7 +114,7 @@ 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)];
+                gfloat *pixel = &components[((y * 50) + x) * 4];
 
                 if (   !GEGL_FLOAT_IS_ZERO (pixel[0])
                     || !GEGL_FLOAT_IS_ZERO (pixel[1])
diff --git a/tests/test-gegl-gpu-texture-clear.c b/tests/test-gegl-gpu-texture-clear.c
index 6ac92d9..b115f7b 100644
--- a/tests/test-gegl-gpu-texture-clear.c
+++ b/tests/test-gegl-gpu-texture-clear.c
@@ -37,7 +37,7 @@ main (gint    argc,
   gegl_init (&argc, &argv);
 
   texture    = gegl_gpu_texture_new (50, 50, babl_format ("RGBA float"));
-  components = g_new (gfloat, 4 * 50 * 50);
+  components = g_new (gfloat, 50 * 50 * 4);
 
     {
       gint   cnt;
@@ -68,7 +68,7 @@ main (gint    argc,
       gegl_gpu_texture_clear (texture, NULL);
       gegl_gpu_texture_get   (texture, NULL, components, NULL);
 
-      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
         if (!GEGL_FLOAT_IS_ZERO (components[cnt]))
           {
             g_printerr ("The gegl_gpu_texture_clear() test failed. "
diff --git a/tests/test-gegl-gpu-texture-dup.c b/tests/test-gegl-gpu-texture-dup.c
index 041e39e..6da33df 100644
--- a/tests/test-gegl-gpu-texture-dup.c
+++ b/tests/test-gegl-gpu-texture-dup.c
@@ -40,8 +40,8 @@ main (gint    argc,
 
   texture1 = 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;
@@ -51,7 +51,7 @@ main (gint    argc,
         {
           gint    x     = g_random_int_range (0, 50);
           gint    y     = g_random_int_range (0, 50);
-          gfloat *pixel = &components1[(y * 50) + (x * 4)];
+          gfloat *pixel = &components1[((y * 50) + x) * 4];
 
           pixel[0] = 1.0;
           pixel[1] = 1.0;
@@ -65,7 +65,7 @@ main (gint    argc,
       gegl_gpu_texture_get (texture2, NULL, components2, NULL);
 
       /* compare the two images */
-      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
         if (components1[cnt] != components2[cnt])
           {
             g_printerr ("The gegl_gpu_texture_dup() test failed. Aborting.\n");
diff --git a/tests/test-gegl-tile-cow-consistency.c b/tests/test-gegl-tile-cow-consistency.c
index 17f0d55..d067284 100644
--- a/tests/test-gegl-tile-cow-consistency.c
+++ b/tests/test-gegl-tile-cow-consistency.c
@@ -45,7 +45,7 @@ main (gint    argc,
 
   /* clear tile data (not GPU data) and leave the tile unsynchronized */
   gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
-  memset (gegl_tile_get_data (tile), 0x00, sizeof (gfloat) * 4 * 50 * 50);
+  memset (gegl_tile_get_data (tile), 0x00, sizeof (gfloat) * 50 * 50 * 4);
   gegl_tile_unlock (tile);
 
   tile2 = gegl_tile_dup (tile);
@@ -59,13 +59,13 @@ main (gint    argc,
        */
       gfloat *components  = (gpointer) gegl_tile_get_data (tile2);
 
-      gpu_components = g_new (gfloat, 4 * 50 * 50);
+      gpu_components = g_new (gfloat, 50 * 50 * 4);
       gegl_gpu_texture_get (gegl_tile_get_gpu_data (tile2),
                             NULL,
                             gpu_components,
                             babl_format ("RGBA float"));
 
-      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
         if (!GEGL_FLOAT_EQUAL (components[cnt], gpu_components[cnt]))
           {
             g_printerr ("Test on gegl_tile_dup() GPU data/data consistency "
diff --git a/tests/test-gegl-tile-lock-mode-gpu-write-then-gpu-read.c b/tests/test-gegl-tile-lock-mode-gpu-write-then-gpu-read.c
index cfac8b0..58f7d57 100644
--- a/tests/test-gegl-tile-lock-mode-gpu-write-then-gpu-read.c
+++ b/tests/test-gegl-tile-lock-mode-gpu-write-then-gpu-read.c
@@ -40,22 +40,21 @@ main (gint    argc,
   gegl_init (&argc, &argv);
 
   tile       = gegl_tile_new (50, 50, babl_format ("RGBA float"));
-  components = g_new (gfloat, 4 * 50 * 50);
+  components = g_new (gfloat, 50 * 50 * 4);
 
     {
       gint    cnt;
-      gfloat *tile_components = g_new (gfloat, 4 * 50 * 50);
+      gfloat *tile_components = g_new (gfloat, 50 * 50 * 4);
 
-      memset (tile->data, 0, 4 * 50 * 50);
+      memset (tile->data, 0, 50 * 50 * 4);
       gegl_gpu_texture_clear (tile->gpu_data, NULL);
 
-      /* initialize tile to a 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 = &components[(y * 4 * 50) + (x * 4)];
+          gfloat *pixel = &components[((y * 50) + x) * 4];
 
           pixel[0] = g_random_double ();
           pixel[1] = g_random_double ();
@@ -65,6 +64,7 @@ main (gint    argc,
 
       gegl_tile_lock (tile, GEGL_TILE_LOCK_GPU_WRITE);
 
+      /* set tile to a random image */
       gegl_gpu_texture_set (gegl_tile_get_gpu_data (tile),
                             NULL,
                             components,
@@ -80,7 +80,7 @@ main (gint    argc,
                             tile_components,
                             babl_format ("RGBA float"));
 
-      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
         if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
           {
             g_printerr ("Tile GPU texture inconsistent with original GPU "
diff --git a/tests/test-gegl-tile-lock-mode-gpu-write-then-read.c b/tests/test-gegl-tile-lock-mode-gpu-write-then-read.c
index 07e9acb..533dcee 100644
--- a/tests/test-gegl-tile-lock-mode-gpu-write-then-read.c
+++ b/tests/test-gegl-tile-lock-mode-gpu-write-then-read.c
@@ -40,22 +40,21 @@ main (gint    argc,
   gegl_init (&argc, &argv);
 
   tile       = gegl_tile_new (50, 50, babl_format ("RGBA float"));
-  components = g_new (gfloat, 4 * 50 * 50);
+  components = g_new (gfloat, 50 * 50 * 4);
 
     {
       gint    cnt;
       gfloat *tile_components;
 
-      memset (tile->data, 0, 4 * 50 * 50);
+      memset (tile->data, 0, 50 * 50 * 4);
       gegl_gpu_texture_clear (tile->gpu_data, NULL);
 
-      /* initialize tile to a 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 = &components[(y * 4 * 50) + (x * 4)];
+          gfloat *pixel = &components[((y * 50) + x) * 4];
 
           pixel[0] = g_random_double ();
           pixel[1] = g_random_double ();
@@ -65,6 +64,7 @@ main (gint    argc,
 
       gegl_tile_lock (tile, GEGL_TILE_LOCK_GPU_WRITE);
 
+      /* set tile to a random image */
       gegl_gpu_texture_set (gegl_tile_get_gpu_data (tile),
                             NULL,
                             components,
@@ -76,7 +76,7 @@ main (gint    argc,
       gegl_tile_lock (tile, GEGL_TILE_LOCK_READ);
       tile_components = (gpointer) gegl_tile_get_data (tile);
 
-      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
         if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
           {
             g_printerr ("Tile data inconsistent with original GPU texture. "
diff --git a/tests/test-gegl-tile-lock-mode-write-then-gpu-read.c b/tests/test-gegl-tile-lock-mode-write-then-gpu-read.c
index 4fa0371..1d708e5 100644
--- a/tests/test-gegl-tile-lock-mode-write-then-gpu-read.c
+++ b/tests/test-gegl-tile-lock-mode-write-then-gpu-read.c
@@ -44,18 +44,17 @@ main (gint    argc,
 
     {
       gint    cnt;
-      gfloat *tile_components = g_new (gfloat, 4 * 50 * 50);
+      gfloat *tile_components = g_new (gfloat, 50 * 50 * 4);
 
-      memset (tile->data, 0, 4 * 50 * 50);
+      memset (tile->data, 0, 50 * 50 * 4);
       gegl_gpu_texture_clear (tile->gpu_data, NULL);
 
-      /* initialize tile to a 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 = &components[(y * 4 * 50) + (x * 4)];
+          gfloat *pixel = &components[((y * 50) + x) * 4];
 
           pixel[0] = g_random_double ();
           pixel[1] = g_random_double ();
@@ -65,9 +64,10 @@ main (gint    argc,
 
       gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
 
+      /* set tile to a random image */
       memcpy (gegl_tile_get_data (tile),
               components,
-              sizeof (gfloat) * 4 * 50 * 50);
+              sizeof (gfloat) * 50 * 50 * 4);
 
       gegl_tile_unlock (tile);
 
@@ -79,7 +79,7 @@ main (gint    argc,
                             tile_components,
                             babl_format ("RGBA float"));
 
-      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
         if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
           {
             g_printerr ("Tile GPU texture inconsistent with original image "
diff --git a/tests/test-gegl-tile-lock-mode-write-then-read.c b/tests/test-gegl-tile-lock-mode-write-then-read.c
index da963a0..9090e32 100644
--- a/tests/test-gegl-tile-lock-mode-write-then-read.c
+++ b/tests/test-gegl-tile-lock-mode-write-then-read.c
@@ -40,22 +40,21 @@ main (gint    argc,
   gegl_init (&argc, &argv);
 
   tile       = gegl_tile_new (50, 50, babl_format ("RGBA float"));
-  components = g_new (gfloat, 4 * 50 * 50);
+  components = g_new (gfloat, 50 * 50 * 4);
 
     {
       gint    cnt;
       gfloat *tile_components;
 
-      memset (tile->data, 0, 4 * 50 * 50);
+      memset (tile->data, 0, 50 * 50 * 4);
       gegl_gpu_texture_clear (tile->gpu_data, NULL);
 
-      /* initialize tile to a 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 = &components[(y * 4 * 50) + (x * 4)];
+          gfloat *pixel = &components[((y * 50) + x) * 4];
 
           pixel[0] = g_random_double ();
           pixel[1] = g_random_double ();
@@ -65,9 +64,10 @@ main (gint    argc,
 
       gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
 
+      /* set tile to a random image */
       memcpy (gegl_tile_get_data (tile),
               components,
-              sizeof (gfloat) * 4 * 50 * 50);
+              sizeof (gfloat) * 50 * 50 * 4);
 
       gegl_tile_unlock (tile);
 
@@ -75,7 +75,7 @@ main (gint    argc,
       gegl_tile_lock (tile, GEGL_TILE_LOCK_READ);
       tile_components = (gpointer) gegl_tile_get_data (tile);
 
-      for (cnt = 0; cnt < 4 * 50 * 50; cnt++)
+      for (cnt = 0; cnt < 50 * 50 * 4; cnt++)
         if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
           {
             g_printerr ("Tile data inconsistent with original image data. "



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