|
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 |
#ifdef GEGL_CHANT_PROPERTIES
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_double_ui (radius, _("Radius"), 0.0, 1000.0, 4.0, 0.0, 100.0, 1.5,
|
|
Packit Service |
2781ba |
_("Radius of square pixel region, (width and height will be radius*2+1)"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_TYPE_AREA_FILTER
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "box-blur.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
#include "gegl/gegl-debug.h"
|
|
Packit Service |
2781ba |
#include <stdio.h>
|
|
Packit Service |
2781ba |
#include <math.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef USE_DEAD_CODE
|
|
Packit Service |
2781ba |
static inline float
|
|
Packit Service |
2781ba |
get_mean_component (gfloat *buf,
|
|
Packit Service |
2781ba |
gint buf_width,
|
|
Packit Service |
2781ba |
gint buf_height,
|
|
Packit Service |
2781ba |
gint x0,
|
|
Packit Service |
2781ba |
gint y0,
|
|
Packit Service |
2781ba |
gint width,
|
|
Packit Service |
2781ba |
gint height,
|
|
Packit Service |
2781ba |
gint component)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint x, y;
|
|
Packit Service |
2781ba |
gdouble acc=0;
|
|
Packit Service |
2781ba |
gint count=0;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gint offset = (y0 * buf_width + x0) * 4 + component;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (y=y0; y
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
for (x=x0; x
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (x>=0 && x
|
|
Packit Service |
2781ba |
y>=0 && y
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
acc += buf [offset];
|
|
Packit Service |
2781ba |
count++;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
offset+=4;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
offset+= (buf_width * 4) - 4 * width;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
if (count)
|
|
Packit Service |
2781ba |
return acc/count;
|
|
Packit Service |
2781ba |
return 0.0;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static inline void
|
|
Packit Service |
2781ba |
get_mean_components (gfloat *buf,
|
|
Packit Service |
2781ba |
gint buf_width,
|
|
Packit Service |
2781ba |
gint buf_height,
|
|
Packit Service |
2781ba |
gint x0,
|
|
Packit Service |
2781ba |
gint y0,
|
|
Packit Service |
2781ba |
gint width,
|
|
Packit Service |
2781ba |
gint height,
|
|
Packit Service |
2781ba |
gfloat *components)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint y;
|
|
Packit Service |
2781ba |
gdouble acc[4]={0,0,0,0};
|
|
Packit Service |
2781ba |
gint count[4]={0,0,0,0};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gint offset = (y0 * buf_width + x0) * 4;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (y=y0; y
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint x;
|
|
Packit Service |
2781ba |
for (x=x0; x
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (x>=0 && x
|
|
Packit Service |
2781ba |
y>=0 && y
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint c;
|
|
Packit Service |
2781ba |
for (c=0;c<4;c++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
acc[c] += buf [offset+c];
|
|
Packit Service |
2781ba |
count[c]++;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
offset+=4;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
offset+= (buf_width * 4) - 4 * width;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint c;
|
|
Packit Service |
2781ba |
for (c=0;c<4;c++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (count[c])
|
|
Packit Service |
2781ba |
components[c] = acc[c]/count[c];
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
components[c] = 0.0;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* expects src and dst buf to have the same extent */
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
hor_blur (GeglBuffer *src,
|
|
Packit Service |
2781ba |
const GeglRectangle *src_rect,
|
|
Packit Service |
2781ba |
GeglBuffer *dst,
|
|
Packit Service |
2781ba |
const GeglRectangle *dst_rect,
|
|
Packit Service |
2781ba |
gint radius)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint u,v;
|
|
Packit Service |
2781ba |
gint offset;
|
|
Packit Service |
2781ba |
gfloat *src_buf;
|
|
Packit Service |
2781ba |
gfloat *dst_buf;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* src == dst for hor blur */
|
|
Packit Service |
2781ba |
src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
|
|
Packit Service |
2781ba |
dst_buf = g_new0 (gfloat, dst_rect->width * dst_rect->height * 4);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_get (src, src_rect, 1.0, babl_format ("RaGaBaA float"), src_buf, GEGL_AUTO_ROWSTRIDE,
|
|
Packit Service |
2781ba |
GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
offset = 0;
|
|
Packit Service |
2781ba |
for (v=0; v<dst_rect->height; v++)
|
|
Packit Service |
2781ba |
for (u=0; u<dst_rect->width; u++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint i;
|
|
Packit Service |
2781ba |
gfloat components[4];
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
get_mean_components (src_buf,
|
|
Packit Service |
2781ba |
src_rect->width,
|
|
Packit Service |
2781ba |
src_rect->height,
|
|
Packit Service |
2781ba |
u - radius,
|
|
Packit Service |
2781ba |
v,
|
|
Packit Service |
2781ba |
1 + radius*2,
|
|
Packit Service |
2781ba |
1,
|
|
Packit Service |
2781ba |
components);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (i=0; i<4; i++)
|
|
Packit Service |
2781ba |
dst_buf [offset++] = components[i];
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_set (dst, dst_rect, 0, babl_format ("RaGaBaA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
|
|
Packit Service |
2781ba |
g_free (src_buf);
|
|
Packit Service |
2781ba |
g_free (dst_buf);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* expects dst buf to be radius smaller than src buf */
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
ver_blur (GeglBuffer *src,
|
|
Packit Service |
2781ba |
const GeglRectangle *src_rect,
|
|
Packit Service |
2781ba |
GeglBuffer *dst,
|
|
Packit Service |
2781ba |
const GeglRectangle *dst_rect,
|
|
Packit Service |
2781ba |
gint radius)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gint u,v;
|
|
Packit Service |
2781ba |
gint offset;
|
|
Packit Service |
2781ba |
gfloat *src_buf;
|
|
Packit Service |
2781ba |
gfloat *dst_buf;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
|
|
Packit Service |
2781ba |
dst_buf = g_new0 (gfloat, dst_rect->width * dst_rect->height * 4);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_get (src, src_rect, 1.0, babl_format ("RaGaBaA float"), src_buf, GEGL_AUTO_ROWSTRIDE,
|
|
Packit Service |
2781ba |
GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
offset=0;
|
|
Packit Service |
2781ba |
for (v=0; v<dst_rect->height; v++)
|
|
Packit Service |
2781ba |
for (u=0; u<dst_rect->width; u++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gfloat components[4];
|
|
Packit Service |
2781ba |
gint c;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
get_mean_components (src_buf,
|
|
Packit Service |
2781ba |
src_rect->width,
|
|
Packit Service |
2781ba |
src_rect->height,
|
|
Packit Service |
2781ba |
u + radius, /* 1x radius is the offset between the bufs */
|
|
Packit Service |
2781ba |
v - radius + radius, /* 1x radius is the offset between the bufs */
|
|
Packit Service |
2781ba |
1,
|
|
Packit Service |
2781ba |
1 + radius * 2,
|
|
Packit Service |
2781ba |
components);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (c=0; c<4; c++)
|
|
Packit Service |
2781ba |
dst_buf [offset++] = components[c];
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_set (dst, dst_rect, 0, babl_format ("RaGaBaA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
|
|
Packit Service |
2781ba |
g_free (src_buf);
|
|
Packit Service |
2781ba |
g_free (dst_buf);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void prepare (GeglOperation *operation)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o;
|
|
Packit Service |
2781ba |
GeglOperationAreaFilter *op_area;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
op_area = GEGL_OPERATION_AREA_FILTER (operation);
|
|
Packit Service |
2781ba |
o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
op_area->left =
|
|
Packit Service |
2781ba |
op_area->right =
|
|
Packit Service |
2781ba |
op_area->top =
|
|
Packit Service |
2781ba |
op_area->bottom = ceil (o->radius);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_set_format (operation, "input", babl_format ("RaGaBaA float"));
|
|
Packit Service |
2781ba |
gegl_operation_set_format (operation, "output", babl_format ("RaGaBaA float"));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "opencl/gegl-cl.h"
|
|
Packit Service |
2781ba |
#include "buffer/gegl-buffer-cl-iterator.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static const char* kernel_source =
|
|
Packit Service |
2781ba |
"__kernel void kernel_blur_hor (__global const float4 *in, \n"
|
|
Packit Service |
2781ba |
" __global float4 *aux, \n"
|
|
Packit Service |
2781ba |
" int width, int radius) \n"
|
|
Packit Service |
2781ba |
"{ \n"
|
|
Packit Service |
2781ba |
" const int in_index = get_global_id(0) * (width + 2 * radius) \n"
|
|
Packit Service |
2781ba |
" + (radius + get_global_id (1)); \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" const int aux_index = get_global_id(0) * width + get_global_id (1); \n"
|
|
Packit Service |
2781ba |
" int i; \n"
|
|
Packit Service |
2781ba |
" float4 mean; \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" mean = (float4)(0.0f); \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" for (i=-radius; i <= radius; i++) \n"
|
|
Packit Service |
2781ba |
" { \n"
|
|
Packit Service |
2781ba |
" mean += in[in_index + i]; \n"
|
|
Packit Service |
2781ba |
" } \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" aux[aux_index] = mean / (2 * radius + 1); \n"
|
|
Packit Service |
2781ba |
"} \n"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
"__kernel void kernel_blur_ver (__global const float4 *aux, \n"
|
|
Packit Service |
2781ba |
" __global float4 *out, \n"
|
|
Packit Service |
2781ba |
" int width, int radius) \n"
|
|
Packit Service |
2781ba |
"{ \n"
|
|
Packit Service |
2781ba |
" const int aux_index = (radius + get_global_id(0)) * width + get_global_id (1); \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" const int out_index = get_global_id(0) * width + get_global_id (1); \n"
|
|
Packit Service |
2781ba |
" int i; \n"
|
|
Packit Service |
2781ba |
" float4 mean; \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" mean = (float4)(0.0f); \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" for (i=-radius; i <= radius; i++) \n"
|
|
Packit Service |
2781ba |
" { \n"
|
|
Packit Service |
2781ba |
" mean += aux[aux_index + i * width]; \n"
|
|
Packit Service |
2781ba |
" } \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" out[out_index] = mean / (2 * radius + 1); \n"
|
|
Packit Service |
2781ba |
"} \n";
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gegl_cl_run_data *cl_data = NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static cl_int
|
|
Packit Service |
2781ba |
cl_box_blur (cl_mem in_tex,
|
|
Packit Service |
2781ba |
cl_mem aux_tex,
|
|
Packit Service |
2781ba |
cl_mem out_tex,
|
|
Packit Service |
2781ba |
size_t global_worksize,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi,
|
|
Packit Service |
2781ba |
gint radius)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
cl_int cl_err = 0;
|
|
Packit Service |
2781ba |
size_t global_ws_hor[2], global_ws_ver[2];
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!cl_data)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const char *kernel_name[] = {"kernel_blur_hor", "kernel_blur_ver", NULL};
|
|
Packit Service |
2781ba |
cl_data = gegl_cl_compile_and_build (kernel_source, kernel_name);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!cl_data) return 1;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
global_ws_hor[0] = roi->height + 2 * radius;
|
|
Packit Service |
2781ba |
global_ws_hor[1] = roi->width;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
global_ws_ver[0] = roi->height;
|
|
Packit Service |
2781ba |
global_ws_ver[1] = roi->width;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 0, sizeof(cl_mem), (void*)&in_tex);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 1, sizeof(cl_mem), (void*)&aux_tex);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 2, sizeof(cl_int), (void*)&roi->width);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 3, sizeof(cl_int), (void*)&radius);
|
|
Packit Service |
2781ba |
if (cl_err != CL_SUCCESS) return cl_err;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cl_err = gegl_clEnqueueNDRangeKernel(gegl_cl_get_command_queue (),
|
|
Packit Service |
2781ba |
cl_data->kernel[0], 2,
|
|
Packit Service |
2781ba |
NULL, global_ws_hor, NULL,
|
|
Packit Service |
2781ba |
0, NULL, NULL);
|
|
Packit Service |
2781ba |
if (cl_err != CL_SUCCESS) return cl_err;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_clEnqueueBarrier (gegl_cl_get_command_queue ());
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[1], 0, sizeof(cl_mem), (void*)&aux_tex);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[1], 1, sizeof(cl_mem), (void*)&out_tex);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[1], 2, sizeof(cl_int), (void*)&roi->width);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[1], 3, sizeof(cl_int), (void*)&radius);
|
|
Packit Service |
2781ba |
if (cl_err != CL_SUCCESS) return cl_err;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cl_err = gegl_clEnqueueNDRangeKernel(gegl_cl_get_command_queue (),
|
|
Packit Service |
2781ba |
cl_data->kernel[1], 2,
|
|
Packit Service |
2781ba |
NULL, global_ws_ver, NULL,
|
|
Packit Service |
2781ba |
0, NULL, NULL);
|
|
Packit Service |
2781ba |
if (cl_err != CL_SUCCESS) return cl_err;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return cl_err;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
cl_process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglBuffer *input,
|
|
Packit Service |
2781ba |
GeglBuffer *output,
|
|
Packit Service |
2781ba |
const GeglRectangle *result)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const Babl *in_format = gegl_operation_get_format (operation, "input");
|
|
Packit Service |
2781ba |
const Babl *out_format = gegl_operation_get_format (operation, "output");
|
|
Packit Service |
2781ba |
gint err;
|
|
Packit Service |
2781ba |
gint j;
|
|
Packit Service |
2781ba |
cl_int cl_err;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglBufferClIterator *i = gegl_buffer_cl_iterator_new (output, result, out_format, GEGL_CL_BUFFER_WRITE, GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
gint read = gegl_buffer_cl_iterator_add_2 (i, input, result, in_format, GEGL_CL_BUFFER_READ, op_area->left, op_area->right, op_area->top, op_area->bottom, GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
gint aux = gegl_buffer_cl_iterator_add_2 (i, NULL, result, in_format, GEGL_CL_BUFFER_AUX, 0, 0, op_area->top, op_area->bottom, GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
while (gegl_buffer_cl_iterator_next (i, &err))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (err) return FALSE;
|
|
Packit Service |
2781ba |
for (j=0; j < i->n; j++)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
cl_err = cl_box_blur(i->tex[read][j], i->tex[aux][j], i->tex[0][j], i->size[0][j], &i->roi[0][j], ceil (o->radius));
|
|
Packit Service |
2781ba |
if (cl_err != CL_SUCCESS)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GEGL_NOTE (GEGL_DEBUG_OPENCL, "Error in gegl:box-blur: %s", gegl_cl_errstring(cl_err));
|
|
Packit Service |
2781ba |
return FALSE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglBuffer *input,
|
|
Packit Service |
2781ba |
GeglBuffer *output,
|
|
Packit Service |
2781ba |
const GeglRectangle *result,
|
|
Packit Service |
2781ba |
gint level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglRectangle rect;
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglBuffer *temp;
|
|
Packit Service |
2781ba |
GeglOperationAreaFilter *op_area;
|
|
Packit Service |
2781ba |
op_area = GEGL_OPERATION_AREA_FILTER (operation);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (gegl_cl_is_accelerated ())
|
|
Packit Service |
2781ba |
if (cl_process (operation, input, output, result))
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
rect = *result;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
rect.x-=op_area->left;
|
|
Packit Service |
2781ba |
rect.y-=op_area->top;
|
|
Packit Service |
2781ba |
rect.width+=op_area->left + op_area->right;
|
|
Packit Service |
2781ba |
rect.height+=op_area->top + op_area->bottom;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
temp = gegl_buffer_new (&rect,
|
|
Packit Service |
2781ba |
babl_format ("RaGaBaA float"));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
hor_blur (input, &rect, temp, &rect, o->radius);
|
|
Packit Service |
2781ba |
ver_blur (temp, &rect, output, result, o->radius);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_unref (temp);
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
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 |
GeglOperationFilterClass *filter_class;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
filter_class = GEGL_OPERATION_FILTER_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
filter_class->process = process;
|
|
Packit Service |
2781ba |
operation_class->prepare = prepare;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->opencl_support = TRUE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name", "gegl:box-blur",
|
|
Packit Service |
2781ba |
"categories", "blur",
|
|
Packit Service |
2781ba |
"description", _("Performs an averaging of a square box of pixels"),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|