|
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 2011 Audrey Mandet <mandet.audrey@gmail.com>
|
|
Packit Service |
2781ba |
* Copyright (c) 1997 Eric L. Hernes (erich@rrnet.com)
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#include <glib/gi18n-lib.h>
|
|
Packit Service |
2781ba |
#include <math.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef GEGL_CHANT_PROPERTIES
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_double_ui (x, _("X"), -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, 0.0, 1024.0, 1.0,
|
|
Packit Service |
2781ba |
_("X coordinate of the center of the waves"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_double_ui (y, _("Y"), -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, 0.0, 1024.0, 1.0,
|
|
Packit Service |
2781ba |
_("Coordinate y of the center of the waves"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_double (amplitude, _("Amplitude"), 0.0, 1000.0, 25.0,
|
|
Packit Service |
2781ba |
_("Amplitude of the ripple"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_double (period, _("Period"), 0.0, 1000.0, 200.0,
|
|
Packit Service |
2781ba |
_("Period of the ripple"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_double (phi, _("Phase shift"), -1.0, 1.0, 0.0,
|
|
Packit Service |
2781ba |
_("Phase shift"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_enum (sampler_type, _("Sampler"), GeglSamplerType, GEGL_TYPE_SAMPLER_TYPE,
|
|
Packit Service |
2781ba |
GEGL_SAMPLER_CUBIC, _("Sampler used internally"))
|
|
Packit Service |
2781ba |
|
|
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 "waves.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 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 = o->amplitude;
|
|
Packit Service |
2781ba |
op_area->right = o->amplitude;
|
|
Packit Service |
2781ba |
op_area->top = o->amplitude;
|
|
Packit Service |
2781ba |
op_area->bottom = o->amplitude;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_set_format (operation, "input",
|
|
Packit Service |
2781ba |
babl_format ("RGBA float"));
|
|
Packit Service |
2781ba |
gegl_operation_set_format (operation, "output",
|
|
Packit Service |
2781ba |
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 |
|
|
Packit Service |
2781ba |
gint x = result->x; /* initial x */
|
|
Packit Service |
2781ba |
gint y = result->y; /* and y coordinates */
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gfloat *dst_buf = g_slice_alloc (result->width * result->height * 4 * sizeof(gfloat));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gfloat *out_pixel = dst_buf;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglSampler *sampler = gegl_buffer_sampler_new (input,
|
|
Packit Service |
2781ba |
babl_format ("RGBA float"),
|
|
Packit Service |
2781ba |
o->sampler_type);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gint n_pixels = result->width * result->height;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
while (n_pixels--)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gdouble coordsx = 0.0;
|
|
Packit Service |
2781ba |
gdouble coordsy = 0.0;
|
|
Packit Service |
2781ba |
gdouble radius = 0.0;
|
|
Packit Service |
2781ba |
gdouble shift = 0.0;
|
|
Packit Service |
2781ba |
gdouble ux = 0.0; /* unit vector of the radius */
|
|
Packit Service |
2781ba |
gdouble uy = 0.0;
|
|
Packit Service |
2781ba |
gdouble vx = 0.0; /* orthogonal vector of u */
|
|
Packit Service |
2781ba |
gdouble vy = 0.0;
|
|
Packit Service |
2781ba |
gdouble dx = 0.0;
|
|
Packit Service |
2781ba |
gdouble dy = 0.0;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
dx = (gdouble)x-o->x;
|
|
Packit Service |
2781ba |
dy = (gdouble)y-o->y;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
radius = sqrt( dx * dx + dy * dy );
|
|
Packit Service |
2781ba |
shift = o->amplitude * sin(2.0 * G_PI * radius / o->period + 2.0 * G_PI * o->phi);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
ux = dx / radius;
|
|
Packit Service |
2781ba |
uy = dy / radius;
|
|
Packit Service |
2781ba |
vx = -uy;
|
|
Packit Service |
2781ba |
vy = ux;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
coordsx = x + shift * vx;
|
|
Packit Service |
2781ba |
coordsy = y + shift * vy;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_sampler_get (sampler,
|
|
Packit Service |
2781ba |
coordsx,
|
|
Packit Service |
2781ba |
coordsy,
|
|
Packit Service |
2781ba |
NULL,
|
|
Packit Service |
2781ba |
out_pixel);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
out_pixel += 4;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* update x and y coordinates */
|
|
Packit Service |
2781ba |
x++;
|
|
Packit Service |
2781ba |
if (x>=result->x + result->width)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
x=result->x;
|
|
Packit Service |
2781ba |
y++;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_buffer_set (output, result, 0, babl_format ("RGBA float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
|
|
Packit Service |
2781ba |
g_slice_free1 (result->width * result->height * 4 * sizeof(gfloat), dst_buf);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_unref (sampler);
|
|
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:waves",
|
|
Packit Service |
2781ba |
"categories" , "distort",
|
|
Packit Service |
2781ba |
"description", _("Transform the buffer with waves"),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|