[gegl/gsoc2011-opencl: 12/12] OpenCL Unit-Tests: GeglBuffer



commit 2d515fb2651156d82787007e054e3ed192f309dd
Author: Victor Oliveira <victormatheus gmail com>
Date:   Tue Jul 26 10:22:06 2011 -0300

    OpenCL Unit-Tests: GeglBuffer

 tests/opencl/Makefile.am              |    4 +-
 tests/opencl/test-gegl-buffer-blank.c |   55 +++++++++++++++++++
 tests/opencl/test-gegl-buffer-color.c |   93 +++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+), 1 deletions(-)
---
diff --git a/tests/opencl/Makefile.am b/tests/opencl/Makefile.am
index 48432a6..1545a50 100644
--- a/tests/opencl/Makefile.am
+++ b/tests/opencl/Makefile.am
@@ -13,7 +13,9 @@ noinst_PROGRAMS = \
 	test-gegl-tile-lock-mode-write-then-read \
 	test-gegl-tile-lock-mode-cl-write-then-read \
 	test-gegl-tile-lock-mode-write-then-cl-read \
-	test-gegl-tile-lock-mode-cl-write-then-cl-read
+	test-gegl-tile-lock-mode-cl-write-then-cl-read \
+	test-gegl-buffer-blank \
+	test-gegl-buffer-color
 
 TESTS = $(noinst_PROGRAMS)
 
diff --git a/tests/opencl/test-gegl-buffer-blank.c b/tests/opencl/test-gegl-buffer-blank.c
new file mode 100644
index 0000000..b34b741
--- /dev/null
+++ b/tests/opencl/test-gegl-buffer-blank.c
@@ -0,0 +1,55 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor M. de Araujo Oliveira <victormatheus gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-types.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  gint retval = SUCCESS;
+
+  GeglBuffer    *buffer;
+  GeglBufferIterator *i;
+  GeglRectangle  rect = {0, 0, 20, 20};
+
+  gegl_init (&argc, &argv);
+  gegl_cl_init (NULL);
+
+  buffer = gegl_buffer_new (&rect, babl_format ("RGBA float"));
+
+  i = gegl_buffer_iterator_new (buffer, &rect, NULL, GEGL_BUFFER_CL_WRITE);
+  while (gegl_buffer_iterator_next (i))
+    gegl_cl_texture_clear(i->cl_data[0], NULL);
+
+  gegl_buffer_destroy (buffer);
+
+  gegl_exit ();
+
+  return retval;
+}
diff --git a/tests/opencl/test-gegl-buffer-color.c b/tests/opencl/test-gegl-buffer-color.c
new file mode 100644
index 0000000..2ee8b73
--- /dev/null
+++ b/tests/opencl/test-gegl-buffer-color.c
@@ -0,0 +1,93 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor M. de Araujo Oliveira <victormatheus gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-types.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  gint retval = SUCCESS;
+
+  gfloat color[4] = {0.3f, 0.8f, 0.1f, 1.0f};
+
+  GeglBuffer    *buffer;
+  GeglBufferIterator *i;
+  GeglRectangle  rect = {0, 0, 200, 200};
+  gfloat *buf = g_new (gfloat, rect.width*rect.height*4);
+  gint j;
+
+  gegl_init (&argc, &argv);
+  gegl_cl_init (NULL);
+
+  buffer = gegl_buffer_new (&rect, babl_format ("RGBA float"));
+
+  i = gegl_buffer_iterator_new (buffer, &rect, NULL, GEGL_BUFFER_CL_WRITE);
+  while (gegl_buffer_iterator_next (i))
+    {
+    /*gfloat *data = (gfloat*)(i->data[0]);
+      int k=0;
+      for (j=0; j<i->length; j++)
+        {
+          data[k+0] = color[0];
+          data[k+1] = color[1];
+          data[k+2] = color[2];
+          data[k+3] = color[3];
+          k+=4;
+        }*/
+      gegl_cl_texture_fill(i->cl_data[0], NULL, color);
+    }
+
+  gegl_buffer_get (buffer, 1.0, NULL, NULL, buf, GEGL_AUTO_ROWSTRIDE);
+
+  for (j=0 ; j<rect.width*rect.height; j++)
+    {
+      gboolean ok = 1;
+      ok &= GEGL_FLOAT_EQUAL (buf[j*4+0], color[0]);
+      ok &= GEGL_FLOAT_EQUAL (buf[j*4+1], color[1]);
+      ok &= GEGL_FLOAT_EQUAL (buf[j*4+2], color[2]);
+      ok &= GEGL_FLOAT_EQUAL (buf[j*4+3], color[3]);
+      if (!ok)
+        {
+          g_printerr ("The test failed. "
+                      "Aborting.\n");
+
+          retval = FAILURE;
+          goto abort;
+        }
+    }
+
+abort:
+
+  g_free (buf);
+  gegl_buffer_destroy (buffer);
+
+  gegl_exit ();
+
+  return retval;
+}



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