|
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_double (radius, _("Radius"), 0.0, 200.0, 4.0,
|
|
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-min.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
#include <stdio.h>
|
|
Packit Service |
2781ba |
#include <math.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static inline gfloat
|
|
Packit Service |
2781ba |
get_min_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 |
gfloat min=1000000000.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 |
if (buf [offset] < min)
|
|
Packit Service |
2781ba |
min = 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 |
return min;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
hor_min (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 ("RGBA float"), src_buf,
|
|
Packit Service |
2781ba |
GEGL_AUTO_ROWSTRIDE, 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 |
|
|
Packit Service |
2781ba |
for (i=0; i<4; i++)
|
|
Packit Service |
2781ba |
dst_buf [offset++] = get_min_component (src_buf,
|
|
Packit Service |
2781ba |
src_rect->width,
|
|
Packit Service |
2781ba |
src_rect->height,
|
|
Packit Service |
2781ba |
u + radius - radius,
|
|
Packit Service |
2781ba |
v + radius,
|
|
Packit Service |
2781ba |
1 + radius*2,
|
|
Packit Service |
2781ba |
1,
|
|
Packit Service |
2781ba |
i);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_set (dst, dst_rect, 0, babl_format ("RGBA float"), dst_buf,
|
|
Packit Service |
2781ba |
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 |
static void
|
|
Packit Service |
2781ba |
ver_min (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 * src_rect->height * 4);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_get (src, src_rect, 1.0, babl_format ("RGBA float"), src_buf,
|
|
Packit Service |
2781ba |
GEGL_AUTO_ROWSTRIDE, 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 c;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (c=0; c<4; c++)
|
|
Packit Service |
2781ba |
dst_buf [offset++] =
|
|
Packit Service |
2781ba |
get_min_component (src_buf,
|
|
Packit Service |
2781ba |
src_rect->width,
|
|
Packit Service |
2781ba |
src_rect->height,
|
|
Packit Service |
2781ba |
u,
|
|
Packit Service |
2781ba |
v - radius,
|
|
Packit Service |
2781ba |
1,
|
|
Packit Service |
2781ba |
1 + radius * 2,
|
|
Packit Service |
2781ba |
c);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_set (dst, dst_rect, 0, babl_format ("RGBA float"), dst_buf,
|
|
Packit Service |
2781ba |
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 |
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
|
|
Packit Service |
2781ba |
area->left =
|
|
Packit Service |
2781ba |
area->right =
|
|
Packit Service |
2781ba |
area->top =
|
|
Packit Service |
2781ba |
area->bottom = GEGL_CHANT_PROPERTIES (operation)->radius;
|
|
Packit Service |
2781ba |
gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
|
|
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 |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglRectangle input_rect = gegl_operation_get_required_for_output (operation, "input", result);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
hor_min ( input, &input_rect, output, result, o->radius);
|
|
Packit Service |
2781ba |
ver_min (output, result, output, result, o->radius);
|
|
Packit Service |
2781ba |
|
|
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 |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name" , "gegl:box-min",
|
|
Packit Service |
2781ba |
"categories" , "misc",
|
|
Packit Service |
2781ba |
"description" ,
|
|
Packit Service |
2781ba |
_("Sets the target pixel to the value of the minimum value in a box surrounding the pixel"),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|