[gegl/gsoc2011-opencl: 13/19] OpenCL Unit-Tests: GeglBuffer
- From: Victor Matheus de Araujo Oliveira <vmaolive src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/gsoc2011-opencl: 13/19] OpenCL Unit-Tests: GeglBuffer
- Date: Tue, 13 Sep 2011 18:29:26 +0000 (UTC)
commit 42bf8e0031484b48c928c5c4a78cafda06a6f391
Author: Victor Oliveira <victormatheus gmail com>
Date: Tue Jul 26 10:22:06 2011 -0300
OpenCL Unit-Tests: GeglBuffer
tests/opencl/Makefile.am | 8 +-
tests/opencl/test-gegl-buffer-blank.c | 55 +++++
.../test-gegl-buffer-cl-brightness-contrast.c | 236 ++++++++++++++++++++
tests/opencl/test-gegl-buffer-cl-read-write.c | 176 +++++++++++++++
tests/opencl/test-gegl-buffer-cl-read.c | 129 +++++++++++
tests/opencl/test-gegl-buffer-cl-write.c | 93 ++++++++
tests/opencl/test-gegl-buffer-operations.c | 68 ++++++
7 files changed, 764 insertions(+), 1 deletions(-)
---
diff --git a/tests/opencl/Makefile.am b/tests/opencl/Makefile.am
index 48432a6..66a08a0 100644
--- a/tests/opencl/Makefile.am
+++ b/tests/opencl/Makefile.am
@@ -6,6 +6,7 @@ TESTS_ENVIRONMENT = \
# The tests
noinst_PROGRAMS = \
+ test-gegl-buffer-operations \
test-gegl-cl-texture-dup \
test-gegl-cl-texture-copy \
test-gegl-cl-texture-set \
@@ -13,7 +14,12 @@ 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-cl-write \
+ test-gegl-buffer-cl-read \
+ test-gegl-buffer-cl-read-write \
+ test-gegl-buffer-cl-brightness-contrast
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-cl-brightness-contrast.c b/tests/opencl/test-gegl-buffer-cl-brightness-contrast.c
new file mode 100644
index 0000000..cc3c176
--- /dev/null
+++ b/tests/opencl/test-gegl-buffer-cl-brightness-contrast.c
@@ -0,0 +1,236 @@
+/* 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 <assert.h>
+#include <babl/babl.h>
+#include <sys/time.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_read, *buffer_write;
+ GeglBuffer *buffer_truth;
+
+ gfloat *buf_write;
+ gfloat *buf_truth;
+
+ gfloat brightness = 2.0f;
+ gfloat contrast = 0.5f;
+
+ int errcode;
+ cl_program program;
+ cl_kernel kernel;
+
+ char image_name[1000] = "GEGL.png";
+ if (argc > 1)
+ strcpy(image_name, argv[1]);
+
+ gegl_init (&argc, &argv);
+ gegl_cl_init (NULL);
+
+ /* Load Image */
+ {
+ GeglNode *gegl, *sink;
+ const GeglRectangle * rect;
+
+ /* read and write buffers */
+ gegl = gegl_graph (sink = gegl_node ("gegl:buffer-sink", "buffer", &buffer_read,
+ "format", babl_format ("RGBA float"), NULL,
+ gegl_node ("gegl:load", "path", image_name, NULL)));
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+
+ rect = gegl_buffer_get_extent (buffer_read);
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Image Size: %d %d\n", rect->width, rect->height);
+
+ buffer_write = gegl_buffer_new (rect, babl_format ("RGBA float"));
+ buf_write = g_new (gfloat, gegl_buffer_get_pixel_count (buffer_write) * 4);
+ }
+
+ /* process cpu */
+ {
+ GeglNode *gegl, *sink, *bc, *load;
+ struct timeval start;
+ struct timeval end;
+ long mtime, seconds, useconds;
+
+ gegl = gegl_graph (sink = gegl_node ("gegl:buffer-sink", "buffer", &buffer_truth,
+ "format", babl_format ("RGBA float"), NULL,
+ bc = gegl_node ("gegl:brightness-contrast", "brightness", brightness,
+ "contrast", contrast, NULL,
+ load = gegl_node ("gegl:load", "path", image_name, NULL))));
+
+ gegl_node_process (load);
+
+ gettimeofday(&start, NULL);
+
+ gegl_node_process (bc);
+
+ gettimeofday(&end, NULL);
+
+ gegl_node_process (sink);
+
+ seconds = end.tv_sec - start.tv_sec;
+ useconds = end.tv_usec - start.tv_usec;
+ mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "CPU Elapsed time: %ld milliseconds\n", mtime);
+
+ buf_truth = g_new (gfloat, gegl_buffer_get_pixel_count (buffer_truth) * 4);
+ gegl_buffer_get (buffer_truth, 1.0, NULL, NULL, buf_truth, GEGL_AUTO_ROWSTRIDE);
+
+ g_object_unref (gegl);
+ }
+
+ /* define and compile OpenCL Kernel */
+ {
+ char buffer[10000];
+ const char* kernel_source[] =
+ {
+ "sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | \n",
+ " CLK_ADDRESS_NONE | \n",
+ " CLK_FILTER_NEAREST; \n",
+ "__kernel void kernel_bc(__read_only image2d_t in, \n",
+ " __write_only image2d_t out, \n",
+ " float brightness, \n",
+ " float contrast) \n",
+ "{ \n",
+ " int2 gid = (int2)(get_global_id(0), get_global_id(1)); \n",
+ " float4 in_v = read_imagef(in, sampler, gid); \n",
+ " float4 out_v; \n",
+ " out_v.xyz = (in_v.xyz - 0.5f) * contrast + brightness + 0.5f;\n",
+ " out_v.w = in_v.w; \n",
+ " write_imagef(out, gid, out_v); \n",
+ "} \n",
+ NULL,
+ };
+
+ CL_SAFE_CALL( program = gegl_clCreateProgramWithSource(gegl_cl_get_context(),
+ gegl_cl_count_lines(kernel_source),
+ (const char **)&kernel_source,
+ NULL, &errcode) );
+
+ errcode = gegl_clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
+ if (errcode != CL_SUCCESS)
+ {
+ CL_SAFE_CALL( errcode = gegl_clGetProgramBuildInfo(program,
+ gegl_cl_get_device(),
+ CL_PROGRAM_BUILD_LOG,
+ sizeof(buffer), buffer, NULL) );
+ g_warning("OpenCL Build Error in Line %u in file %s\nError:%s\n%s",
+ __LINE__, __FILE__, gegl_cl_errstring(errcode), buffer);
+ }
+
+ CL_SAFE_CALL( kernel = gegl_clCreateKernel(program, "kernel_bc", &errcode) );
+ }
+
+ /* process opencl */
+ {
+ GeglBufferIterator *i;
+ gint index;
+ struct timeval start;
+ struct timeval end;
+ long mtime, seconds, useconds;
+
+ gettimeofday(&start, NULL);
+
+ i = gegl_buffer_iterator_new (buffer_write, NULL, NULL, GEGL_BUFFER_CL_WRITE);
+ index = gegl_buffer_iterator_add (i, buffer_read, NULL, NULL, GEGL_BUFFER_CL_READ);
+ while (gegl_buffer_iterator_next (i))
+ {
+ GeglClTexture *in_tex = i->cl_data[index];
+ GeglClTexture *out_tex = i->cl_data[0];
+ size_t global_worksize[2] = {i->roi[0].width, i->roi[0].height};
+
+ CL_SAFE_CALL( errcode = gegl_clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&in_tex->data) );
+ CL_SAFE_CALL( errcode = gegl_clSetKernelArg(kernel, 1, sizeof(cl_mem), (void*)&out_tex->data) );
+ CL_SAFE_CALL( errcode = gegl_clSetKernelArg(kernel, 2, sizeof(cl_float), (void*)&brightness) );
+ CL_SAFE_CALL( errcode = gegl_clSetKernelArg(kernel, 3, sizeof(cl_float), (void*)&contrast) );
+
+ CL_SAFE_CALL( errcode = gegl_clEnqueueNDRangeKernel(gegl_cl_get_command_queue(), kernel, 2,
+ NULL, global_worksize, NULL,
+ 0, NULL, NULL) );
+ CL_SAFE_CALL( errcode = gegl_clFinish(gegl_cl_get_command_queue()) );
+ }
+
+ gettimeofday(&end, NULL);
+
+ gegl_buffer_get (buffer_write, 1.0, NULL, NULL, buf_write, GEGL_AUTO_ROWSTRIDE);
+
+ seconds = end.tv_sec - start.tv_sec;
+ useconds = end.tv_usec - start.tv_usec;
+ mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "OpenCL Elapsed time: %ld milliseconds\n", mtime);
+ }
+
+
+ /* verification */
+ {
+ gint i;
+
+ assert(gegl_buffer_get_pixel_count (buffer_truth) == gegl_buffer_get_pixel_count (buffer_write));
+
+ for (i=0; i<gegl_buffer_get_pixel_count (buffer_write)*4; i++)
+ if (!GEGL_FLOAT_EQUAL (buf_truth[i], buf_write[i]))
+ {
+ g_printerr ("The test failed. "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ goto abort;
+ }
+ g_printerr ("Test OK.\n");
+ goto ok;
+ }
+
+abort:
+ /* Save Image */
+ {
+ GeglNode *gegl, *sink;
+ gegl = gegl_graph (sink = gegl_node ("gegl:png-save", "path", "error.png", NULL,
+ gegl_node ("gegl:buffer-source", "buffer", buffer_write, NULL)));
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ }
+
+ok:
+ g_free (buf_truth);
+ g_free (buf_write);
+ gegl_buffer_destroy (buffer_read);
+ gegl_buffer_destroy (buffer_write);
+ gegl_buffer_destroy (buffer_truth);
+
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-buffer-cl-read-write.c b/tests/opencl/test-gegl-buffer-cl-read-write.c
new file mode 100644
index 0000000..979d4a2
--- /dev/null
+++ b/tests/opencl/test-gegl-buffer-cl-read-write.c
@@ -0,0 +1,176 @@
+/* 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 <assert.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_read, *buffer_write;
+ gfloat *buf_write;
+
+ int errcode;
+ cl_program program;
+ cl_kernel kernel;
+
+ gegl_init (&argc, &argv);
+ gegl_cl_init (NULL);
+
+ /* Load Image */
+ {
+ GeglNode *gegl, *sink;
+ gegl = gegl_graph (sink = gegl_node ("gegl:buffer-sink", "buffer", &buffer_read,
+ "format", babl_format ("RGBA float"), NULL,
+ gegl_node ("gegl:load", "path", "GEGL.png", NULL)));
+
+ gegl_node_process (sink);
+
+ buffer_write = gegl_buffer_new (gegl_buffer_get_extent (buffer_read), babl_format ("RGBA float"));
+
+ buf_write = g_new (gfloat, gegl_buffer_get_pixel_count (buffer_write) * 4);
+ g_object_unref (gegl);
+ }
+
+ /* define and compile OpenCL Kernel */
+ {
+ char buffer[10000];
+ const char* kernel_source[] =
+ {
+ "sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | \n",
+ " CLK_ADDRESS_NONE | \n",
+ " CLK_FILTER_NEAREST; \n",
+ "__kernel void kernel_m (__read_only image2d_t in, \n",
+ " __write_only image2d_t out) \n",
+ "{ \n",
+ " int2 gid = (int2)(get_global_id(0), get_global_id(1)); \n",
+ " float4 in_v = read_imagef(in, sampler, gid); \n",
+ " write_imagef(out, gid, in_v*0.5f); \n",
+ "} \n",
+ NULL,
+ };
+
+ CL_SAFE_CALL( program = gegl_clCreateProgramWithSource(gegl_cl_get_context(),
+ gegl_cl_count_lines(kernel_source),
+ (const char **)&kernel_source,
+ NULL, &errcode) );
+
+ errcode = gegl_clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
+ if (errcode != CL_SUCCESS)
+ {
+ CL_SAFE_CALL( errcode = gegl_clGetProgramBuildInfo(program,
+ gegl_cl_get_device(),
+ CL_PROGRAM_BUILD_LOG,
+ sizeof(buffer), buffer, NULL) );
+ g_warning("OpenCL Build Error in Line %u in file %s\nError:%s\n%s",
+ __LINE__, __FILE__, gegl_cl_errstring(errcode), buffer);
+ }
+
+ CL_SAFE_CALL( kernel = gegl_clCreateKernel(program, "kernel_m", &errcode) );
+ }
+
+ /* process */
+ {
+ GeglBufferIterator *i;
+ gint index;
+
+ i = gegl_buffer_iterator_new (buffer_write, NULL, NULL, GEGL_BUFFER_CL_WRITE);
+ index = gegl_buffer_iterator_add (i, buffer_read, NULL, NULL, GEGL_BUFFER_CL_READ);
+ while (gegl_buffer_iterator_next (i))
+ {
+ GeglClTexture *in_tex = i->cl_data[index];
+ GeglClTexture *out_tex = i->cl_data[0];
+ size_t global_worksize[2] = {i->roi[0].width, i->roi[0].height};
+
+ CL_SAFE_CALL( errcode = gegl_clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&in_tex->data) );
+ CL_SAFE_CALL( errcode = gegl_clSetKernelArg(kernel, 1, sizeof(cl_mem), (void*)&out_tex->data) );
+ CL_SAFE_CALL( errcode = gegl_clEnqueueNDRangeKernel(gegl_cl_get_command_queue(), kernel, 2,
+ NULL, global_worksize, NULL,
+ 0, NULL, NULL) );
+ CL_SAFE_CALL( errcode = gegl_clFinish(gegl_cl_get_command_queue()) );
+ }
+
+ gegl_buffer_get (buffer_write, 1.0, NULL, NULL, buf_write, GEGL_AUTO_ROWSTRIDE);
+ }
+
+ /* verification */
+ {
+ GeglNode *gegl, *sink;
+ GeglBuffer *buffer_truth;
+ gfloat *buf_truth;
+ gint i;
+
+ gegl = gegl_graph (sink = gegl_node ("gegl:buffer-sink", "buffer", &buffer_truth,
+ "format", babl_format ("RGBA float"), NULL,
+ gegl_node ("gegl:load", "path", "GEGL.png", NULL)));
+
+ gegl_node_process (sink);
+
+ buf_truth = g_new (gfloat, gegl_buffer_get_pixel_count (buffer_truth) * 4);
+ gegl_buffer_get (buffer_truth, 1.0, NULL, NULL, buf_truth, GEGL_AUTO_ROWSTRIDE);
+
+ assert(gegl_buffer_get_pixel_count (buffer_truth) == gegl_buffer_get_pixel_count (buffer_write));
+
+ for (i=0; i<gegl_buffer_get_pixel_count (buffer_write)*4; i++)
+ if (!GEGL_FLOAT_EQUAL (buf_truth[i]*0.5f, buf_write[i]))
+ {
+ g_printerr ("The test failed. "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ goto abort;
+ }
+ goto ok;
+
+abort:
+ /* Save Image */
+ {
+ GeglNode *gegl, *sink;
+ gegl = gegl_graph (sink = gegl_node ("gegl:png-save", "path", "error.png", NULL,
+ gegl_node ("gegl:buffer-source", "buffer", buffer_write, NULL)));
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ }
+
+ok:
+ g_free (buf_truth);
+ gegl_buffer_destroy (buffer_truth);
+ g_object_unref (gegl);
+ }
+
+ g_free (buf_write);
+ gegl_buffer_destroy (buffer_read);
+ gegl_buffer_destroy (buffer_write);
+
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-buffer-cl-read.c b/tests/opencl/test-gegl-buffer-cl-read.c
new file mode 100644
index 0000000..a41fe59
--- /dev/null
+++ b/tests/opencl/test-gegl-buffer-cl-read.c
@@ -0,0 +1,129 @@
+/* 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 <assert.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_read, *buffer_write;
+ gfloat *buf_write;
+
+ gegl_init (&argc, &argv);
+ gegl_cl_init (NULL);
+
+ /* Load Image */
+ {
+ GeglNode *gegl, *sink;
+ gegl = gegl_graph (sink = gegl_node ("gegl:buffer-sink", "buffer", &buffer_read,
+ "format", babl_format ("RGBA float"), NULL,
+ gegl_node ("gegl:load", "path", "GEGL.png", NULL)));
+
+ gegl_node_process (sink);
+
+ buffer_write = gegl_buffer_new (gegl_buffer_get_extent (buffer_read), babl_format ("RGBA float"));
+
+ buf_write = g_new (gfloat, gegl_buffer_get_pixel_count (buffer_write) * 4);
+ g_object_unref (gegl);
+ }
+
+ /* process */
+
+ {
+ GeglBufferIterator *i;
+ gint index;
+
+ i = gegl_buffer_iterator_new (buffer_write, NULL, NULL, GEGL_BUFFER_WRITE);
+ index = gegl_buffer_iterator_add (i, buffer_read, NULL, NULL, GEGL_BUFFER_CL_READ);
+ while (gegl_buffer_iterator_next (i))
+ {
+ GeglClTexture *in_tex = i->cl_data[index];
+ gpointer *out = i->data[0];
+ gegl_cl_texture_get (in_tex, out);
+ }
+
+ gegl_buffer_get (buffer_write, 1.0, NULL, NULL, buf_write, GEGL_AUTO_ROWSTRIDE);
+ }
+
+ /* Verification */
+ {
+ GeglNode *gegl, *sink;
+ GeglBuffer *buffer_truth;
+ gfloat *buf_truth;
+ gint i;
+
+ gegl = gegl_graph (sink = gegl_node ("gegl:buffer-sink", "buffer", &buffer_truth,
+ "format", babl_format ("RGBA float"), NULL,
+ gegl_node ("gegl:load", "path", "GEGL.png", NULL)));
+
+ gegl_node_process (sink);
+
+ buf_truth = g_new (gfloat, gegl_buffer_get_pixel_count (buffer_truth) * 4);
+ gegl_buffer_get (buffer_truth, 1.0, NULL, NULL, buf_truth, GEGL_AUTO_ROWSTRIDE);
+
+ assert(gegl_buffer_get_pixel_count (buffer_truth) == gegl_buffer_get_pixel_count (buffer_write));
+
+ for (i=0; i<gegl_buffer_get_pixel_count (buffer_write)*4; i++)
+ if (!GEGL_FLOAT_EQUAL (buf_truth[i], buf_write[i]))
+ {
+ g_printerr ("The test failed. "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ goto abort;
+ }
+ goto ok;
+
+abort:
+ /* Save Image */
+ {
+ GeglNode *gegl, *sink;
+ gegl = gegl_graph (sink = gegl_node ("gegl:png-save", "path", "error.png", NULL,
+ gegl_node ("gegl:buffer-source", "buffer", buffer_write, NULL)));
+ gegl_node_process (sink);
+ g_object_unref (gegl);
+ }
+
+ok:
+ g_free (buf_truth);
+ gegl_buffer_destroy (buffer_truth);
+ g_object_unref (gegl);
+ }
+
+ g_free (buf_write);
+ gegl_buffer_destroy (buffer_read);
+ gegl_buffer_destroy (buffer_write);
+
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-buffer-cl-write.c b/tests/opencl/test-gegl-buffer-cl-write.c
new file mode 100644
index 0000000..2ee8b73
--- /dev/null
+++ b/tests/opencl/test-gegl-buffer-cl-write.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;
+}
diff --git a/tests/opencl/test-gegl-buffer-operations.c b/tests/opencl/test-gegl-buffer-operations.c
new file mode 100644
index 0000000..f63cb0e
--- /dev/null
+++ b/tests/opencl/test-gegl-buffer-operations.c
@@ -0,0 +1,68 @@
+/* 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>
+ */
+
+/* This is just a sanity test */
+
+#include <string.h>
+#include <assert.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"
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gegl_init (&argc, &argv);
+
+ GeglBuffer *buffer_truth;
+
+ GeglNode *gegl = gegl_node_new ();
+
+ gfloat brightness = 2.0f;
+ gfloat contrast = 0.5f;
+
+ /* Load Image */
+ {
+ GeglNode *sink, *bc, *load;
+
+ /* truth */
+ sink = gegl_node_new_child
+ (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer_truth, "format", babl_format ("RGBA float"), NULL);
+
+ bc = gegl_node_new_child
+ (gegl, "operation", "gegl:brightness-contrast", "brightness", brightness, "contrast", contrast, NULL);
+
+ load = gegl_node_new_child
+ (gegl, "operation", "gegl:load", "path", "GEGL.png", NULL);
+
+ gegl_node_link_many(load, bc, sink, NULL);
+
+ gegl_node_process (load);
+ gegl_node_process (bc);
+ gegl_node_process (sink);
+ }
+
+ gegl_exit ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]