|
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 Ø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 |
gegl_chant_int (shape, _("Shape"), 0, 2, 0, _("Shape to use: 0=circle 1=diamond 2=square"))
|
|
Packit Service |
2781ba |
gegl_chant_color (color, _("Color"), "black", _("Defaults to 'black', you can use transparency here to erase portions of an image"))
|
|
Packit Service |
2781ba |
gegl_chant_double (radius, _("Radius"), 0.0, 3.0, 1.5, _("How far out vignetting goes as portion of half image diagonal"))
|
|
Packit Service |
2781ba |
gegl_chant_double (softness, _("Softness"), 0.0, 1.0, 0.8, _("Softness"))
|
|
Packit Service |
2781ba |
gegl_chant_double (gamma, _("Gamma"), 1.0, 20.0, 2.0, _("Falloff linearity"))
|
|
Packit Service |
2781ba |
gegl_chant_double (proportion, _("Proportion"), 0.0, 1.0, 1.0, _("How close we are to image proportions"))
|
|
Packit Service |
2781ba |
gegl_chant_double (squeeze, _("Squeeze"), -1.0, 1.0, 0.0, _("Aspect ratio to use, -0.5 = 1:2, 0.0 = 1:1, 0.5 = 2:1, -1.0 = 1:inf 1.0 = inf:1, this is applied after proportion is taken into account, to directly use squeeze factor as proportions, set proportion to 0.0."))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_double (x, _("X"), -1.0, 2.0, 0.5, _("Horizontal center of vignetting"))
|
|
Packit Service |
2781ba |
gegl_chant_double (y, _("Y"), -1.0, 2.0, 0.5, _("Vertical center of vignetting"))
|
|
Packit Service |
2781ba |
gegl_chant_double (rotation, _("Rotation"), 0.0, 360.0, 0.0, _("Rotation angle"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_TYPE_POINT_FILTER
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "vignette.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <math.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
prepare (GeglOperation *operation)
|
|
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 |
/* conversion function mapping between scale and aspect
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* -1.0 = 0.0
|
|
Packit Service |
2781ba |
* -0.5 = 0.5
|
|
Packit Service |
2781ba |
* 0.0 = 1.0
|
|
Packit Service |
2781ba |
* 0.5 = 2.0
|
|
Packit Service |
2781ba |
* 1.0 = infinity
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static float aspect_to_scale (float aspect)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (aspect == 0.0)
|
|
Packit Service |
2781ba |
return 1.0;
|
|
Packit Service |
2781ba |
else if (aspect > 0.0)
|
|
Packit Service |
2781ba |
return tan(aspect * (G_PI/2)) + 1;
|
|
Packit Service |
2781ba |
else /* (aspect < 0.0) */
|
|
Packit Service |
2781ba |
return 1.0/(tan((-aspect) * (G_PI/2)) + 1);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#if 0
|
|
Packit Service |
2781ba |
static float scale_to_aspect (float scale)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (scale == 1.0)
|
|
Packit Service |
2781ba |
return 0.0;
|
|
Packit Service |
2781ba |
else if (scale > 1.0)
|
|
Packit Service |
2781ba |
return atan (scale-1) / (G_PI/2);
|
|
Packit Service |
2781ba |
else /* scale < 1.0 */
|
|
Packit Service |
2781ba |
return -atan(1.0/scale- 1) / (G_PI/2);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "opencl/gegl-cl.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static const char* kernel_source =
|
|
Packit Service |
2781ba |
"__kernel void vignette_cl (__global const float4 *in, \n"
|
|
Packit Service |
2781ba |
" __global float4 *out, \n"
|
|
Packit Service |
2781ba |
" float4 color, \n"
|
|
Packit Service |
2781ba |
" float scale, \n"
|
|
Packit Service |
2781ba |
" float cost, \n"
|
|
Packit Service |
2781ba |
" float sint, \n"
|
|
Packit Service |
2781ba |
" int roi_x, \n"
|
|
Packit Service |
2781ba |
" int roi_y, \n"
|
|
Packit Service |
2781ba |
" int midx, \n"
|
|
Packit Service |
2781ba |
" int midy, \n"
|
|
Packit Service |
2781ba |
" int o_shape, \n"
|
|
Packit Service |
2781ba |
" float gamma, \n"
|
|
Packit Service |
2781ba |
" float length, \n"
|
|
Packit Service |
2781ba |
" float radius0, \n"
|
|
Packit Service |
2781ba |
" float rdiff) \n"
|
|
Packit Service |
2781ba |
"{ \n"
|
|
Packit Service |
2781ba |
" int gidx = get_global_id(0); \n"
|
|
Packit Service |
2781ba |
" int gidy = get_global_id(1); \n"
|
|
Packit Service |
2781ba |
" int gid = gidx + gidy * get_global_size(0); \n"
|
|
Packit Service |
2781ba |
" float strength = 0.0f; \n"
|
|
Packit Service |
2781ba |
" float u,v,costy,sinty; \n"
|
|
Packit Service |
2781ba |
" int x,y; \n"
|
|
Packit Service |
2781ba |
" x = gidx + roi_x; \n"
|
|
Packit Service |
2781ba |
" y = gidy + roi_y; \n"
|
|
Packit Service |
2781ba |
" sinty = sint * (y-midy) - midx; \n"
|
|
Packit Service |
2781ba |
" costy = cost * (y-midy) + midy; \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" u = cost * (x-midx) - sinty; \n"
|
|
Packit Service |
2781ba |
" v = sint * (x-midx) + costy; \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" if (length == 0.0f) \n"
|
|
Packit Service |
2781ba |
" strength = 0.0f; \n"
|
|
Packit Service |
2781ba |
" else \n"
|
|
Packit Service |
2781ba |
" { \n"
|
|
Packit Service |
2781ba |
" switch (o_shape) \n"
|
|
Packit Service |
2781ba |
" { \n"
|
|
Packit Service |
2781ba |
" case 0: \n"
|
|
Packit Service |
2781ba |
" strength = hypot ((u-midx) / scale, v-midy); \n"
|
|
Packit Service |
2781ba |
" break; \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" case 1: \n"
|
|
Packit Service |
2781ba |
" strength = fmax (fabs(u-midx)/scale, fabs(v-midy)); \n"
|
|
Packit Service |
2781ba |
" break; \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" case 2: \n"
|
|
Packit Service |
2781ba |
" strength = fabs (u-midx) / scale + fabs(v-midy); \n"
|
|
Packit Service |
2781ba |
" break; \n"
|
|
Packit Service |
2781ba |
" } \n"
|
|
Packit Service |
2781ba |
" strength /= length; \n"
|
|
Packit Service |
2781ba |
" strength = (strength-radius0) / rdiff; \n"
|
|
Packit Service |
2781ba |
" } \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" if (strength < 0.0f) strength = 0.0f; \n"
|
|
Packit Service |
2781ba |
" if (strength > 1.0f) strength = 1.0f; \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" if (gamma > 0.9999f && gamma < 2.0001f) \n"
|
|
Packit Service |
2781ba |
" strength *= strength; \n"
|
|
Packit Service |
2781ba |
" else if (gamma != 1.0f) \n"
|
|
Packit Service |
2781ba |
" strength = pow(strength, gamma); \n"
|
|
Packit Service |
2781ba |
" \n"
|
|
Packit Service |
2781ba |
" out[gid] = in[gid]*(1.0f-strength) + color * strength; \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_process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
cl_mem in_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 level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
gfloat scale;
|
|
Packit Service |
2781ba |
gfloat radius0, radius1;
|
|
Packit Service |
2781ba |
gint roi_x, roi_y,x;
|
|
Packit Service |
2781ba |
gint midx, midy;
|
|
Packit Service |
2781ba |
GeglRectangle *bounds = gegl_operation_source_get_bounding_box (operation, "input");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gfloat length = hypot (bounds->width, bounds->height)/2;
|
|
Packit Service |
2781ba |
gfloat rdiff;
|
|
Packit Service |
2781ba |
gfloat cost, sint;
|
|
Packit Service |
2781ba |
gfloat color[4];
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
scale = bounds->width / (1.0 * bounds->height);
|
|
Packit Service |
2781ba |
scale = scale * (o->proportion) + 1.0 * (1.0-o->proportion);
|
|
Packit Service |
2781ba |
scale *= aspect_to_scale (o->squeeze);
|
|
Packit Service |
2781ba |
length = (bounds->width/2.0);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (scale > 1.0)
|
|
Packit Service |
2781ba |
length /= scale;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_color_get_pixel (o->color, babl_format ("RGBA float"), color);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (x=0; x<3; x++) /* premultiply */
|
|
Packit Service |
2781ba |
color[x] *= color[3];
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
radius0 = o->radius * (1.0-o->softness);
|
|
Packit Service |
2781ba |
radius1 = o->radius;
|
|
Packit Service |
2781ba |
rdiff = radius1-radius0;
|
|
Packit Service |
2781ba |
if (fabs (rdiff) < 0.0001)
|
|
Packit Service |
2781ba |
rdiff = 0.0001;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
midx = bounds->x + bounds->width * o->x;
|
|
Packit Service |
2781ba |
midy = bounds->y + bounds->height * o->y;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
roi_x = roi->x;
|
|
Packit Service |
2781ba |
roi_y = roi->y;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* constant for all pixels */
|
|
Packit Service |
2781ba |
cost = cos(-o->rotation * (G_PI*2/360.0));
|
|
Packit Service |
2781ba |
sint = sin(-o->rotation * (G_PI*2/360.0));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!cl_data)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const char *kernel_name[] = {"vignette_cl",NULL};
|
|
Packit Service |
2781ba |
cl_data = gegl_cl_compile_and_build (kernel_source, kernel_name);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
if (!cl_data) return 1;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const size_t gbl_size[2] = {roi->width, roi->height};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gint shape = o->shape;
|
|
Packit Service |
2781ba |
gfloat gamma = o->gamma;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
cl_int cl_err = 0;
|
|
Packit Service |
2781ba |
cl_float4 f_color;
|
|
Packit Service |
2781ba |
f_color.s[0] = color[0];
|
|
Packit Service |
2781ba |
f_color.s[1] = color[1];
|
|
Packit Service |
2781ba |
f_color.s[2] = color[2];
|
|
Packit Service |
2781ba |
f_color.s[3] = color[3];
|
|
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*)&out_tex);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 2, sizeof(cl_float4),(void*)&f_color);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 3, sizeof(cl_float), (void*)&scale);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 4, sizeof(cl_float), (void*)&cost);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 5, sizeof(cl_float), (void*)&sint);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 6, sizeof(cl_int), (void*)&roi_x);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 7, sizeof(cl_int), (void*)&roi_y);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 8, sizeof(cl_int), (void*)&midx;;
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 9, sizeof(cl_int), (void*)&midy;;
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 10, sizeof(cl_int), (void*)&shape);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 11, sizeof(cl_float), (void*)&gamma);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 12, sizeof(cl_float), (void*)&length);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 13, sizeof(cl_float), (void*)&radius0);
|
|
Packit Service |
2781ba |
cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 14, sizeof(cl_float), (void*)&rdiff);
|
|
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, gbl_size, NULL,
|
|
Packit Service |
2781ba |
0, NULL, NULL);
|
|
Packit Service |
2781ba |
if (cl_err != CL_SUCCESS) return cl_err;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return CL_SUCCESS;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
void *in_buf,
|
|
Packit Service |
2781ba |
void *out_buf,
|
|
Packit Service |
2781ba |
glong n_pixels,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi,
|
|
Packit Service |
2781ba |
gint level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
gfloat *in_pixel = in_buf;
|
|
Packit Service |
2781ba |
gfloat *out_pixel = out_buf;
|
|
Packit Service |
2781ba |
gfloat scale;
|
|
Packit Service |
2781ba |
gfloat radius0, radius1;
|
|
Packit Service |
2781ba |
gint x, y;
|
|
Packit Service |
2781ba |
gint midx, midy;
|
|
Packit Service |
2781ba |
GeglRectangle *bounds = gegl_operation_source_get_bounding_box (operation, "input");
|
|
Packit Service |
2781ba |
gfloat length = hypot (bounds->width, bounds->height)/2;
|
|
Packit Service |
2781ba |
gfloat rdiff;
|
|
Packit Service |
2781ba |
gfloat cost, sint;
|
|
Packit Service |
2781ba |
gfloat costy, sinty;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gfloat color[4];
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
scale = bounds->width / (1.0 * bounds->height);
|
|
Packit Service |
2781ba |
scale = scale * (o->proportion) + 1.0 * (1.0-o->proportion);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
scale *= aspect_to_scale (o->squeeze);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
length = (bounds->width/2.0);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (scale > 1.0)
|
|
Packit Service |
2781ba |
length /= scale;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_color_get_pixel (o->color, babl_format ("RGBA float"), color);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
for (x=0; x<3; x++) /* premultiply */
|
|
Packit Service |
2781ba |
color[x] *= color[3];
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
radius0 = o->radius * (1.0-o->softness);
|
|
Packit Service |
2781ba |
radius1 = o->radius;
|
|
Packit Service |
2781ba |
rdiff = radius1-radius0;
|
|
Packit Service |
2781ba |
if (fabs (rdiff) < 0.0001)
|
|
Packit Service |
2781ba |
rdiff = 0.0001;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
midx = bounds->x + bounds->width * o->x;
|
|
Packit Service |
2781ba |
midy = bounds->y + bounds->height * o->y;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
x = roi->x;
|
|
Packit Service |
2781ba |
y = roi->y;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* constant for all pixels */
|
|
Packit Service |
2781ba |
cost = cos(-o->rotation * (G_PI*2/360.0));
|
|
Packit Service |
2781ba |
sint = sin(-o->rotation * (G_PI*2/360.0));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* constant per scanline */
|
|
Packit Service |
2781ba |
sinty = sint * (y-midy) - midx;
|
|
Packit Service |
2781ba |
costy = cost * (y-midy) + midy;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
while (n_pixels--)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gfloat strength = 0.0;
|
|
Packit Service |
2781ba |
gfloat u, v;
|
|
Packit Service |
2781ba |
#if 0
|
|
Packit Service |
2781ba |
u = cost * (x-midx) - sint * (y-midy) + midx;
|
|
Packit Service |
2781ba |
v = sint * (x-midx) + cost * (y-midy) + midy;
|
|
Packit Service |
2781ba |
/* optimized out of innerscanline loop */
|
|
Packit Service |
2781ba |
#endif
|
|
Packit Service |
2781ba |
u = cost * (x-midx) - sinty;
|
|
Packit Service |
2781ba |
v = sint * (x-midx) + costy;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (length == 0.0)
|
|
Packit Service |
2781ba |
strength = 0.0;
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
switch (o->shape)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
case 0: /* circle */
|
|
Packit Service |
2781ba |
strength = hypot ((u-midx) / scale, v-midy); break;
|
|
Packit Service |
2781ba |
case 1: /* square */
|
|
Packit Service |
2781ba |
strength = MAX(ABS(u-midx) / scale, ABS(v-midy)); break;
|
|
Packit Service |
2781ba |
case 2: /* diamond */
|
|
Packit Service |
2781ba |
strength = ABS(u-midx) / scale + ABS(v-midy); break;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
strength /= length;
|
|
Packit Service |
2781ba |
strength = (strength-radius0) / rdiff;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (strength<0.0)
|
|
Packit Service |
2781ba |
strength = 0.0;
|
|
Packit Service |
2781ba |
if (strength>1.0)
|
|
Packit Service |
2781ba |
strength = 1.0;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (o->gamma > 0.9999 && o->gamma < 2.0001)
|
|
Packit Service |
2781ba |
strength *= strength; /* fast path for default gamma */
|
|
Packit Service |
2781ba |
else if (o->gamma != 1.0)
|
|
Packit Service |
2781ba |
strength = powf(strength, o->gamma); /* this gamma factor is
|
|
Packit Service |
2781ba |
* very expensive..
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
out_pixel[0]=in_pixel[0] * (1.0-strength) + color[0] * strength;
|
|
Packit Service |
2781ba |
out_pixel[1]=in_pixel[1] * (1.0-strength) + color[1] * strength;
|
|
Packit Service |
2781ba |
out_pixel[2]=in_pixel[2] * (1.0-strength) + color[2] * strength;
|
|
Packit Service |
2781ba |
out_pixel[3]=in_pixel[3] * (1.0-strength) + color[3] * strength;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
out_pixel += 4;
|
|
Packit Service |
2781ba |
in_pixel += 4;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* update x and y coordinates */
|
|
Packit Service |
2781ba |
if (++x>=roi->x + roi->width)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
x=roi->x;
|
|
Packit Service |
2781ba |
y++;
|
|
Packit Service |
2781ba |
sinty = sint * (y-midy) - midx;
|
|
Packit Service |
2781ba |
costy = cost * (y-midy) + midy;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return TRUE;
|
|
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 |
GeglOperationPointFilterClass *point_filter_class;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
point_filter_class->process = process;
|
|
Packit Service |
2781ba |
point_filter_class->cl_process = cl_process;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->prepare = prepare;
|
|
Packit Service |
2781ba |
operation_class->no_cache = TRUE;
|
|
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:vignette",
|
|
Packit Service |
2781ba |
"categories" , "render",
|
|
Packit Service |
2781ba |
"description", _("A vignetting op, applies a vignette to an image. Simulates the luminance fall off at edge of exposed film, and some other fuzzier border effects that can naturally occur with analoge photograpy."),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|