|
Packit Service |
2781ba |
/* This file is an image processing operation for GEGL
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is free software; you can redistribute it and/or
|
|
Packit Service |
2781ba |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
2781ba |
* version 3 of the License, or (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is distributed in the hope that it will be useful,
|
|
Packit Service |
2781ba |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2781ba |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
2781ba |
* Lesser General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#include <glib/gi18n-lib.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef GEGL_CHANT_PROPERTIES
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_object (buffer, _("Buffer location"),
|
|
Packit Service |
2781ba |
_("Write to an existing GeglBuffer"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_TYPE_SINK
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "write-buffer.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
#include "graph/gegl-node.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl/gegl-debug.h"
|
|
Packit Service |
2781ba |
#include "opencl/gegl-cl.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglBuffer *input,
|
|
Packit Service |
2781ba |
const GeglRectangle *result,
|
|
Packit Service |
2781ba |
gint level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (o->buffer)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglBuffer *output = GEGL_BUFFER (o->buffer);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (gegl_cl_is_accelerated ()
|
|
Packit Service |
2781ba |
&& gegl_cl_color_supported (input->soft_format, output->soft_format) == GEGL_CL_COLOR_CONVERT)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
size_t size;
|
|
Packit Service |
2781ba |
gboolean err;
|
|
Packit Service |
2781ba |
cl_int cl_err;
|
|
Packit Service |
2781ba |
gint j;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglBufferClIterator *i = gegl_buffer_cl_iterator_new (output, result, output->soft_format, GEGL_CL_BUFFER_WRITE, GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
gint read = gegl_buffer_cl_iterator_add (i, input, result, output->soft_format, GEGL_CL_BUFFER_READ, GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_cl_color_babl (output->soft_format, &size);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GEGL_NOTE (GEGL_DEBUG_OPENCL, "write-buffer: %p %p %s %s {%d %d %d %d}", input, output, babl_get_name(input->soft_format), babl_get_name(output->soft_format),
|
|
Packit Service |
2781ba |
result->x, result->y, result->width, result->height);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
while (gegl_buffer_cl_iterator_next (i, &err))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (err) break;
|
|
Packit Service |
2781ba |
for (j=0; j < i->n; j++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
cl_err = gegl_clEnqueueCopyBuffer (gegl_cl_get_command_queue (),
|
|
Packit Service |
2781ba |
i->tex[read][j], i->tex[0][j], 0, 0, i->size[0][j] * size,
|
|
Packit Service |
2781ba |
0, NULL, NULL);
|
|
Packit Service |
2781ba |
if (cl_err != CL_SUCCESS)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GEGL_NOTE (GEGL_DEBUG_OPENCL, "Error in gegl_buffer_copy: %s", gegl_cl_errstring(cl_err));
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (cl_err || err)
|
|
Packit Service |
2781ba |
gegl_buffer_copy (input, result, output, result);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
gegl_buffer_copy (input, result, output, result);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_flush (output);
|
|
Packit Service |
2781ba |
gegl_node_emit_computed (operation->node, result);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
dispose (GObject *object)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (object);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (o->buffer)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_object_unref (o->buffer);
|
|
Packit Service |
2781ba |
o->buffer = NULL;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
G_OBJECT_CLASS (gegl_chant_parent_class)->dispose (object);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_chant_class_init (GeglChantClass *klass)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationClass *operation_class;
|
|
Packit Service |
2781ba |
GeglOperationSinkClass *sink_class;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
sink_class = GEGL_OPERATION_SINK_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
sink_class->process = process;
|
|
Packit Service |
2781ba |
sink_class->needs_full = FALSE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
G_OBJECT_CLASS (klass)->dispose = dispose;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name" , "gegl:write-buffer",
|
|
Packit Service |
2781ba |
"categories" , "programming:output",
|
|
Packit Service |
2781ba |
"description", _("A GEGL buffer destination surface."),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|