2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-12-02 22:59:30 +08:00
|
|
|
#include <stdlib.h>
|
2004-01-26 17:22:06 +08:00
|
|
|
#include <string.h>
|
2002-05-03 20:45:22 +08:00
|
|
|
|
2011-04-28 21:50:39 +08:00
|
|
|
#include <cairo.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
1999-09-02 09:41:18 +08:00
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-11-10 00:54:56 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2012-10-22 22:03:40 +08:00
|
|
|
#include "gegl/gimp-gegl-apply-operation.h"
|
2012-03-20 03:53:28 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
#include "gimp.h"
|
2012-05-29 04:55:03 +08:00
|
|
|
#include "gimp-utils.h"
|
2003-09-03 23:13:19 +08:00
|
|
|
#include "gimpchannel.h"
|
2001-11-10 00:54:56 +08:00
|
|
|
#include "gimpcontext.h"
|
|
|
|
#include "gimpdrawable-blend.h"
|
|
|
|
#include "gimpgradient.h"
|
|
|
|
#include "gimpimage.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "gimpprogress.h"
|
1998-07-27 05:49:42 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-05-29 04:55:03 +08:00
|
|
|
//#define USE_GRADIENT_CACHE 1
|
|
|
|
|
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-12-12 02:53:03 +08:00
|
|
|
GimpGradient *gradient;
|
2006-08-30 05:44:51 +08:00
|
|
|
GimpContext *context;
|
2003-07-22 22:24:11 +08:00
|
|
|
gboolean reverse;
|
2012-05-29 04:55:03 +08:00
|
|
|
#ifdef USE_GRADIENT_CACHE
|
|
|
|
GimpRGB *gradient_cache;
|
|
|
|
gint gradient_cache_size;
|
|
|
|
#endif
|
2001-12-12 02:53:03 +08:00
|
|
|
gdouble offset;
|
|
|
|
gdouble sx, sy;
|
|
|
|
GimpGradientType gradient_type;
|
|
|
|
gdouble dist;
|
|
|
|
gdouble vec[2];
|
2004-06-13 09:57:26 +08:00
|
|
|
GimpRepeatMode repeat;
|
2005-02-27 23:06:40 +08:00
|
|
|
GRand *seed;
|
2012-03-27 08:47:06 +08:00
|
|
|
GeglBuffer *dist_buffer;
|
1997-11-25 06:05:25 +08:00
|
|
|
} RenderBlendData;
|
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2012-04-23 23:46:25 +08:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
gfloat *row_data;
|
|
|
|
gint width;
|
|
|
|
GRand *dither_rand;
|
1997-11-25 06:05:25 +08:00
|
|
|
} PutPixelData;
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2001-03-12 04:01:14 +08:00
|
|
|
/* local function prototypes */
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2003-12-01 22:32:42 +08:00
|
|
|
static gdouble gradient_calc_conical_sym_factor (gdouble dist,
|
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_conical_asym_factor (gdouble dist,
|
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_square_factor (gdouble dist,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
2012-04-30 07:22:26 +08:00
|
|
|
static gdouble gradient_calc_radial_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble offset,
|
2003-12-01 22:32:42 +08:00
|
|
|
gdouble x,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble y);
|
2012-04-30 07:22:26 +08:00
|
|
|
static gdouble gradient_calc_linear_factor (gdouble dist,
|
2003-12-01 22:32:42 +08:00
|
|
|
gdouble *vec,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
2012-04-30 07:22:26 +08:00
|
|
|
static gdouble gradient_calc_bilinear_factor (gdouble dist,
|
2003-12-01 22:32:42 +08:00
|
|
|
gdouble *vec,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_spiral_factor (gdouble dist,
|
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gboolean clockwise);
|
|
|
|
|
2012-03-27 08:39:15 +08:00
|
|
|
static gdouble gradient_calc_shapeburst_angular_factor (GeglBuffer *dist_buffer,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_shapeburst_spherical_factor (GeglBuffer *dist_buffer,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_shapeburst_dimpled_factor (GeglBuffer *dist_buffer,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2012-04-24 00:46:49 +08:00
|
|
|
static GeglBuffer * gradient_precalc_shapeburst (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
const GeglRectangle *region,
|
|
|
|
gdouble dist,
|
|
|
|
GimpProgress *progress);
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2012-04-24 01:11:08 +08:00
|
|
|
static void gradient_render_pixel (gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer render_data);
|
|
|
|
static void gradient_put_pixel (gint x,
|
|
|
|
gint y,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer put_pixel_data);
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2012-04-24 00:46:49 +08:00
|
|
|
static void gradient_fill_region (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
const GeglRectangle *buffer_region,
|
2014-04-30 15:17:42 +08:00
|
|
|
GimpGradient *gradient,
|
2012-04-24 00:46:49 +08:00
|
|
|
GimpGradientType gradient_type,
|
|
|
|
gdouble offset,
|
|
|
|
GimpRepeatMode repeat,
|
|
|
|
gboolean reverse,
|
|
|
|
gboolean supersample,
|
|
|
|
gint max_depth,
|
|
|
|
gdouble threshold,
|
|
|
|
gboolean dither,
|
|
|
|
gdouble sx,
|
|
|
|
gdouble sy,
|
|
|
|
gdouble ex,
|
|
|
|
gdouble ey,
|
|
|
|
GimpProgress *progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
/* public functions */
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-03-12 04:01:14 +08:00
|
|
|
void
|
2003-07-22 22:24:11 +08:00
|
|
|
gimp_drawable_blend (GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2014-04-30 15:17:42 +08:00
|
|
|
GimpGradient *gradient,
|
2003-07-22 22:24:11 +08:00
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
GimpGradientType gradient_type,
|
|
|
|
gdouble opacity,
|
|
|
|
gdouble offset,
|
|
|
|
GimpRepeatMode repeat,
|
|
|
|
gboolean reverse,
|
|
|
|
gboolean supersample,
|
|
|
|
gint max_depth,
|
|
|
|
gdouble threshold,
|
|
|
|
gboolean dither,
|
|
|
|
gdouble startx,
|
|
|
|
gdouble starty,
|
|
|
|
gdouble endx,
|
|
|
|
gdouble endy,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
2001-11-10 00:54:56 +08:00
|
|
|
{
|
2014-04-30 15:17:42 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
gint x, y, width, height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2004-11-11 22:05:34 +08:00
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
2014-04-30 15:17:42 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
|
2004-08-11 02:47:21 +08:00
|
|
|
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
|
2001-11-10 00:54:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-10 00:54:56 +08:00
|
|
|
|
2010-09-08 03:28:00 +08:00
|
|
|
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
|
2004-10-20 06:52:04 +08:00
|
|
|
return;
|
1999-01-11 07:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_set_busy (image->gimp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Always create an alpha temp buf (for generality) */
|
2012-05-21 04:00:27 +08:00
|
|
|
buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
gimp_drawable_get_format_with_alpha (drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gradient_fill_region (image, drawable, context,
|
2012-04-24 00:46:49 +08:00
|
|
|
buffer, GEGL_RECTANGLE (0, 0, width, height),
|
2014-04-30 15:17:42 +08:00
|
|
|
gradient, gradient_type, offset, repeat, reverse,
|
2006-04-12 20:49:29 +08:00
|
|
|
supersample, max_depth, threshold, dither,
|
|
|
|
(startx - x), (starty - y),
|
|
|
|
(endx - x), (endy - y),
|
|
|
|
progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-03-23 03:01:10 +08:00
|
|
|
gimp_drawable_apply_buffer (drawable, buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (0, 0, width, height),
|
2010-06-08 19:24:11 +08:00
|
|
|
TRUE, C_("undo-type", "Blend"),
|
2003-10-06 22:40:12 +08:00
|
|
|
opacity, paint_mode,
|
2012-03-24 07:57:11 +08:00
|
|
|
NULL, x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* update the image */
|
2004-10-20 06:52:04 +08:00
|
|
|
gimp_drawable_update (drawable, x, y, width, height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* free the temporary buffer */
|
2012-03-23 03:01:10 +08:00
|
|
|
g_object_unref (buffer);
|
1999-01-11 07:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_unset_busy (image->gimp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_conical_sym_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
else if ((x != 0) || (y != 0))
|
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
gdouble vec[2];
|
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
/* Calculate offset from the start in pixels */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-04-01 00:45:19 +08:00
|
|
|
r = sqrt (SQR (x) + SQR (y));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
vec[0] = x / r;
|
|
|
|
vec[1] = y / r;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
rat = axis[0] * vec[0] + axis[1] * vec[1]; /* Dot product */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
if (rat > 1.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
rat = 1.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
else if (rat < -1.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
rat = -1.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
/* This cool idea is courtesy Josh MacDonald,
|
|
|
|
* Ali Rahimi --- two more XCF losers. */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
rat = acos (rat) / G_PI;
|
2003-05-06 02:45:58 +08:00
|
|
|
rat = pow (rat, (offset / 10.0) + 1.0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
return CLAMP (rat, 0.0, 1.0);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.5;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_conical_asym_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
2005-02-27 02:36:12 +08:00
|
|
|
else if (x != 0 || y != 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
gdouble ang0, ang1;
|
|
|
|
gdouble ang;
|
|
|
|
gdouble rat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
ang0 = atan2 (axis[0], axis[1]) + G_PI;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
ang1 = atan2 (x, y) + G_PI;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
ang = ang1 - ang0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
if (ang < 0.0)
|
|
|
|
ang += (2.0 * G_PI);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
rat = ang / (2.0 * G_PI);
|
|
|
|
rat = pow (rat, (offset / 10.0) + 1.0);
|
|
|
|
|
|
|
|
return CLAMP (rat, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0.5; /* We are on middle point */
|
|
|
|
}
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_square_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Calculate offset from start as a value in [0, 1] */
|
|
|
|
|
|
|
|
offset = offset / 100.0;
|
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
r = MAX (abs (x), abs (y));
|
1997-11-25 06:05:25 +08:00
|
|
|
rat = r / dist;
|
|
|
|
|
|
|
|
if (rat < offset)
|
2006-04-12 20:49:29 +08:00
|
|
|
return 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
return (rat >= 1.0) ? 1.0 : 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
return (rat - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_radial_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Calculate radial offset from start as a value in [0, 1] */
|
|
|
|
|
|
|
|
offset = offset / 100.0;
|
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
r = sqrt (SQR (x) + SQR (y));
|
1997-11-25 06:05:25 +08:00
|
|
|
rat = r / dist;
|
|
|
|
|
|
|
|
if (rat < offset)
|
2006-04-12 20:49:29 +08:00
|
|
|
return 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
return (rat >= 1.0) ? 1.0 : 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
return (rat - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_linear_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble *vec,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
|
|
|
|
1999-09-26 03:49:58 +08:00
|
|
|
offset = offset / 100.0;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
r = vec[0] * x + vec[1] * y;
|
|
|
|
rat = r / dist;
|
1999-09-26 03:49:58 +08:00
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
if (rat >= 0.0 && rat < offset)
|
2006-04-12 20:49:29 +08:00
|
|
|
return 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
return (rat >= 1.0) ? 1.0 : 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (rat < 0.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
return rat / (1.0 - offset);
|
1999-09-26 03:49:58 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
return (rat - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_bilinear_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble *vec,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Calculate linear offset from the start line outward */
|
|
|
|
|
|
|
|
offset = offset / 100.0;
|
|
|
|
|
|
|
|
r = vec[0] * x + vec[1] * y;
|
|
|
|
rat = r / dist;
|
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
if (fabs (rat) < offset)
|
2006-04-12 20:49:29 +08:00
|
|
|
return 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
return (rat == 1.0) ? 1.0 : 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
return (fabs (rat) - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble
|
2003-12-01 22:32:42 +08:00
|
|
|
gradient_calc_spiral_factor (gdouble dist,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gboolean clockwise)
|
1999-01-05 07:56:37 +08:00
|
|
|
{
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
return 0.0;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
2005-02-27 02:36:12 +08:00
|
|
|
else if (x != 0.0 || y != 0.0)
|
1999-01-05 07:56:37 +08:00
|
|
|
{
|
2005-02-27 02:36:12 +08:00
|
|
|
gdouble ang0, ang1;
|
|
|
|
gdouble ang;
|
|
|
|
double r;
|
1999-01-05 07:56:37 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
ang0 = atan2 (axis[0], axis[1]) + G_PI;
|
|
|
|
ang1 = atan2 (x, y) + G_PI;
|
1999-01-05 07:56:37 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
if (clockwise)
|
|
|
|
ang = ang1 - ang0;
|
1999-01-05 07:56:37 +08:00
|
|
|
else
|
2005-02-27 02:36:12 +08:00
|
|
|
ang = ang0 - ang1;
|
|
|
|
|
|
|
|
if (ang < 0.0)
|
|
|
|
ang += (2.0 * G_PI);
|
|
|
|
|
|
|
|
r = sqrt (SQR (x) + SQR (y)) / dist;
|
1999-01-05 07:56:37 +08:00
|
|
|
|
2005-02-27 02:36:12 +08:00
|
|
|
return fmod (ang / (2.0 * G_PI) + r + offset, 1.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0.5 ; /* We are on the middle point */
|
|
|
|
}
|
1999-01-05 07:56:37 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
2012-03-27 08:39:15 +08:00
|
|
|
gradient_calc_shapeburst_angular_factor (GeglBuffer *dist_buffer,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-03-27 08:39:15 +08:00
|
|
|
gint ix = CLAMP (x, 0.0, gegl_buffer_get_width (dist_buffer) - 0.7);
|
|
|
|
gint iy = CLAMP (y, 0.0, gegl_buffer_get_height (dist_buffer) - 0.7);
|
|
|
|
gfloat value;
|
2005-02-27 02:36:12 +08:00
|
|
|
|
2012-04-02 21:19:47 +08:00
|
|
|
gegl_buffer_get (dist_buffer, GEGL_RECTANGLE (ix, iy, 1, 1), 1.0,
|
2012-03-27 08:39:15 +08:00
|
|
|
NULL, &value,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2005-02-27 02:36:12 +08:00
|
|
|
|
2012-03-27 08:39:15 +08:00
|
|
|
value = 1.0 - value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
2012-03-27 08:39:15 +08:00
|
|
|
gradient_calc_shapeburst_spherical_factor (GeglBuffer *dist_buffer,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-03-27 08:39:15 +08:00
|
|
|
gint ix = CLAMP (x, 0.0, gegl_buffer_get_width (dist_buffer) - 0.7);
|
|
|
|
gint iy = CLAMP (y, 0.0, gegl_buffer_get_height (dist_buffer) - 0.7);
|
|
|
|
gfloat value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-04-02 21:19:47 +08:00
|
|
|
gegl_buffer_get (dist_buffer, GEGL_RECTANGLE (ix, iy, 1, 1), 1.0,
|
2012-03-27 08:39:15 +08:00
|
|
|
NULL, &value,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2005-02-27 02:36:12 +08:00
|
|
|
|
1999-08-05 07:22:29 +08:00
|
|
|
value = 1.0 - sin (0.5 * G_PI * value);
|
2005-02-27 02:36:12 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
2012-03-27 08:39:15 +08:00
|
|
|
gradient_calc_shapeburst_dimpled_factor (GeglBuffer *dist_buffer,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-03-27 08:39:15 +08:00
|
|
|
gint ix = CLAMP (x, 0.0, gegl_buffer_get_width (dist_buffer) - 0.7);
|
|
|
|
gint iy = CLAMP (y, 0.0, gegl_buffer_get_height (dist_buffer) - 0.7);
|
|
|
|
gfloat value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-04-02 21:19:47 +08:00
|
|
|
gegl_buffer_get (dist_buffer, GEGL_RECTANGLE (ix, iy, 1, 1), 1.0,
|
2012-03-27 08:39:15 +08:00
|
|
|
NULL, &value,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2005-02-27 02:36:12 +08:00
|
|
|
|
1999-08-05 07:22:29 +08:00
|
|
|
value = cos (0.5 * G_PI * value);
|
2005-02-27 02:36:12 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-03-27 08:47:06 +08:00
|
|
|
static GeglBuffer *
|
2012-04-24 00:46:49 +08:00
|
|
|
gradient_precalc_shapeburst (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
const GeglRectangle *region,
|
|
|
|
gdouble dist,
|
|
|
|
GimpProgress *progress)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 10:45:02 +08:00
|
|
|
GimpChannel *mask;
|
2012-03-27 08:47:06 +08:00
|
|
|
GeglBuffer *dist_buffer;
|
2012-03-20 03:53:28 +08:00
|
|
|
GeglBuffer *temp_buffer;
|
2012-03-27 08:39:15 +08:00
|
|
|
GeglNode *shapeburst;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-07-21 05:32:19 +08:00
|
|
|
gimp_progress_set_text_literal (progress, _("Calculating distance map"));
|
2012-03-27 23:07:42 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* allocate the distance map */
|
2012-04-24 00:46:49 +08:00
|
|
|
dist_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
region->width, region->height),
|
2012-03-27 08:39:15 +08:00
|
|
|
babl_format ("Y float"));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-09-20 01:09:44 +08:00
|
|
|
/* allocate the selection mask copy
|
|
|
|
*/
|
2012-05-21 04:00:27 +08:00
|
|
|
temp_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
region->width, region->height),
|
2014-05-02 02:32:26 +08:00
|
|
|
babl_format ("Y float"));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
mask = gimp_image_get_mask (image);
|
2003-09-03 23:13:19 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
/* If the image mask is not empty, use it as the shape burst source */
|
2003-09-03 23:13:19 +08:00
|
|
|
if (! gimp_channel_is_empty (mask))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-04-23 01:38:12 +08:00
|
|
|
gint x, y, width, height;
|
|
|
|
gint off_x, off_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2010-09-08 03:28:00 +08:00
|
|
|
gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height);
|
2010-09-07 23:43:39 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* copy the mask to the temp mask */
|
2012-03-21 07:42:44 +08:00
|
|
|
gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)),
|
2012-04-23 01:38:12 +08:00
|
|
|
GEGL_RECTANGLE (x + off_x, y + off_y, width, height),
|
2012-03-21 10:57:53 +08:00
|
|
|
temp_buffer,
|
2012-04-23 01:38:12 +08:00
|
|
|
GEGL_RECTANGLE (0, 0, 0, 0));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the intended drawable has an alpha channel, use that */
|
2001-01-15 05:11:52 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2012-04-23 01:38:12 +08:00
|
|
|
const Babl *component_format;
|
|
|
|
|
2014-05-02 02:32:26 +08:00
|
|
|
component_format = babl_format ("A float");
|
2012-04-23 01:38:12 +08:00
|
|
|
|
2012-03-20 03:53:28 +08:00
|
|
|
/* extract the aplha into the temp mask */
|
2012-04-23 01:38:12 +08:00
|
|
|
gegl_buffer_set_format (temp_buffer, component_format);
|
2012-03-21 10:57:53 +08:00
|
|
|
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
|
2012-04-24 00:46:49 +08:00
|
|
|
GEGL_RECTANGLE (region->x, region->y,
|
|
|
|
region->width, region->height),
|
2012-03-21 10:57:53 +08:00
|
|
|
temp_buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (0, 0, 0, 0));
|
2012-03-27 06:48:20 +08:00
|
|
|
gegl_buffer_set_format (temp_buffer, NULL);
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2012-03-20 03:53:28 +08:00
|
|
|
GeglColor *white = gegl_color_new ("white");
|
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
/* Otherwise, just fill the shapeburst to white */
|
2012-03-20 03:53:28 +08:00
|
|
|
gegl_buffer_set_color (temp_buffer, NULL, white);
|
|
|
|
g_object_unref (white);
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2012-03-27 08:39:15 +08:00
|
|
|
shapeburst = gegl_node_new_child (NULL,
|
2014-08-04 02:09:31 +08:00
|
|
|
"operation", "gegl:distance-transform",
|
2014-05-02 02:40:55 +08:00
|
|
|
"normalize", TRUE,
|
2012-03-27 08:39:15 +08:00
|
|
|
NULL);
|
2012-03-27 06:48:20 +08:00
|
|
|
|
2012-03-27 23:07:42 +08:00
|
|
|
gimp_gegl_progress_connect (shapeburst, progress, NULL);
|
|
|
|
|
2012-10-22 22:03:40 +08:00
|
|
|
gimp_gegl_apply_operation (temp_buffer, NULL, NULL,
|
|
|
|
shapeburst,
|
|
|
|
dist_buffer, NULL);
|
2012-03-27 06:48:20 +08:00
|
|
|
|
2012-03-27 08:39:15 +08:00
|
|
|
g_object_unref (shapeburst);
|
2012-03-20 03:53:28 +08:00
|
|
|
|
2012-03-27 06:48:20 +08:00
|
|
|
g_object_unref (temp_buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-03-27 08:47:06 +08:00
|
|
|
return dist_buffer;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-02-27 07:55:50 +08:00
|
|
|
gradient_render_pixel (gdouble x,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble y,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer render_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-13 09:17:57 +08:00
|
|
|
RenderBlendData *rbd = render_data;
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble factor;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Calculate blending factor */
|
|
|
|
|
|
|
|
switch (rbd->gradient_type)
|
|
|
|
{
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_LINEAR:
|
2005-02-27 02:36:12 +08:00
|
|
|
factor = gradient_calc_linear_factor (rbd->dist,
|
|
|
|
rbd->vec, rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_BILINEAR:
|
2005-02-27 02:36:12 +08:00
|
|
|
factor = gradient_calc_bilinear_factor (rbd->dist,
|
|
|
|
rbd->vec, rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_RADIAL:
|
2005-02-27 02:36:12 +08:00
|
|
|
factor = gradient_calc_radial_factor (rbd->dist,
|
|
|
|
rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SQUARE:
|
1999-09-26 03:49:58 +08:00
|
|
|
factor = gradient_calc_square_factor (rbd->dist, rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_CONICAL_SYMMETRIC:
|
2005-02-27 02:36:12 +08:00
|
|
|
factor = gradient_calc_conical_sym_factor (rbd->dist,
|
|
|
|
rbd->vec, rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_CONICAL_ASYMMETRIC:
|
2005-02-27 02:36:12 +08:00
|
|
|
factor = gradient_calc_conical_asym_factor (rbd->dist,
|
|
|
|
rbd->vec, rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SHAPEBURST_ANGULAR:
|
2012-03-27 08:47:06 +08:00
|
|
|
factor = gradient_calc_shapeburst_angular_factor (rbd->dist_buffer, x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SHAPEBURST_SPHERICAL:
|
2012-03-27 08:47:06 +08:00
|
|
|
factor = gradient_calc_shapeburst_spherical_factor (rbd->dist_buffer, x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SHAPEBURST_DIMPLED:
|
2012-03-27 08:47:06 +08:00
|
|
|
factor = gradient_calc_shapeburst_dimpled_factor (rbd->dist_buffer, x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SPIRAL_CLOCKWISE:
|
2005-02-27 02:36:12 +08:00
|
|
|
factor = gradient_calc_spiral_factor (rbd->dist,
|
|
|
|
rbd->vec, rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy, TRUE);
|
1999-01-05 07:56:37 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SPIRAL_ANTICLOCKWISE:
|
2005-02-27 02:36:12 +08:00
|
|
|
factor = gradient_calc_spiral_factor (rbd->dist,
|
|
|
|
rbd->vec, rbd->offset,
|
2006-04-12 20:49:29 +08:00
|
|
|
x - rbd->sx, y - rbd->sy, FALSE);
|
1999-01-05 07:56:37 +08:00
|
|
|
break;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
2001-11-10 00:54:56 +08:00
|
|
|
g_assert_not_reached ();
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust for repeat */
|
|
|
|
|
2004-06-13 09:17:57 +08:00
|
|
|
switch (rbd->repeat)
|
|
|
|
{
|
2014-04-24 23:18:26 +08:00
|
|
|
case GIMP_REPEAT_TRUNCATE:
|
|
|
|
break;
|
2004-06-13 09:17:57 +08:00
|
|
|
case GIMP_REPEAT_NONE:
|
|
|
|
factor = CLAMP (factor, 0.0, 1.0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_REPEAT_SAWTOOTH:
|
|
|
|
factor = factor - floor (factor);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_REPEAT_TRIANGULAR:
|
|
|
|
{
|
|
|
|
guint ifactor;
|
|
|
|
|
|
|
|
if (factor < 0.0)
|
|
|
|
factor = -factor;
|
|
|
|
|
|
|
|
ifactor = (guint) factor;
|
|
|
|
factor = factor - floor (factor);
|
|
|
|
|
|
|
|
if (ifactor & 1)
|
|
|
|
factor = 1.0 - factor;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Blend the colors */
|
|
|
|
|
2014-04-24 23:18:26 +08:00
|
|
|
if (factor < 0.0 || factor > 1.0)
|
|
|
|
{
|
|
|
|
color->r = color->g = color->b = 0;
|
|
|
|
color->a = GIMP_OPACITY_TRANSPARENT;
|
|
|
|
}
|
2014-04-30 15:17:42 +08:00
|
|
|
else
|
2001-01-21 00:28:05 +08:00
|
|
|
{
|
2012-05-29 04:55:03 +08:00
|
|
|
#ifdef USE_GRADIENT_CACHE
|
|
|
|
*color = rbd->gradient_cache[(gint) (factor * (rbd->gradient_cache_size - 1))];
|
|
|
|
#else
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_gradient_get_color_at (rbd->gradient, rbd->context, NULL,
|
2005-02-27 07:55:50 +08:00
|
|
|
factor, rbd->reverse, color);
|
2012-05-29 04:55:03 +08:00
|
|
|
#endif
|
2001-01-21 00:28:05 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-01 22:32:42 +08:00
|
|
|
gradient_put_pixel (gint x,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint y,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer put_pixel_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-04-23 23:46:25 +08:00
|
|
|
PutPixelData *ppd = put_pixel_data;
|
|
|
|
gfloat *dest = ppd->row_data + 4 * x;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-04-23 23:46:25 +08:00
|
|
|
if (ppd->dither_rand)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-04-23 23:46:25 +08:00
|
|
|
gint i = g_rand_int (ppd->dither_rand);
|
2005-03-01 05:52:41 +08:00
|
|
|
|
2012-04-23 23:46:25 +08:00
|
|
|
*dest++ = color->r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
|
|
|
|
*dest++ = color->g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
|
|
|
|
*dest++ = color->b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
|
|
|
|
*dest++ = color->a + (gdouble) (i & 0xff) / 256.0 / 256.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-23 23:46:25 +08:00
|
|
|
*dest++ = color->r;
|
|
|
|
*dest++ = color->g;
|
|
|
|
*dest++ = color->b;
|
|
|
|
*dest++ = color->a;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint whole row if we are on the rightmost pixel */
|
|
|
|
|
|
|
|
if (x == (ppd->width - 1))
|
2012-04-23 23:46:25 +08:00
|
|
|
gegl_buffer_set (ppd->buffer, GEGL_RECTANGLE (0, y, ppd->width, 1),
|
|
|
|
0, babl_format ("R'G'B'A float"), ppd->row_data,
|
|
|
|
GEGL_AUTO_ROWSTRIDE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-24 00:46:49 +08:00
|
|
|
gradient_fill_region (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
const GeglRectangle *buffer_region,
|
2014-04-30 15:17:42 +08:00
|
|
|
GimpGradient *gradient,
|
2012-04-24 00:46:49 +08:00
|
|
|
GimpGradientType gradient_type,
|
|
|
|
gdouble offset,
|
|
|
|
GimpRepeatMode repeat,
|
|
|
|
gboolean reverse,
|
|
|
|
gboolean supersample,
|
|
|
|
gint max_depth,
|
|
|
|
gdouble threshold,
|
|
|
|
gboolean dither,
|
|
|
|
gdouble sx,
|
|
|
|
gdouble sy,
|
|
|
|
gdouble ex,
|
|
|
|
gdouble ey,
|
|
|
|
GimpProgress *progress)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-03-27 08:47:06 +08:00
|
|
|
RenderBlendData rbd = { 0, };
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2012-05-29 04:55:03 +08:00
|
|
|
GIMP_TIMER_START();
|
|
|
|
|
2014-04-30 15:17:42 +08:00
|
|
|
rbd.gradient = gradient;
|
2006-08-30 05:44:51 +08:00
|
|
|
rbd.context = context;
|
2003-07-22 22:24:11 +08:00
|
|
|
rbd.reverse = reverse;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-05-29 04:55:03 +08:00
|
|
|
#ifdef USE_GRADIENT_CACHE
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
rbd.gradient_cache_size = ceil (sqrt (SQR (sx - ex) + SQR (sy - ey)));
|
|
|
|
rbd.gradient_cache = g_new0 (GimpRGB, rbd.gradient_cache_size);
|
|
|
|
|
|
|
|
for (i = 0; i < rbd.gradient_cache_size; i++)
|
|
|
|
{
|
|
|
|
gdouble factor = (gdouble) i / (gdouble) (rbd.gradient_cache_size - 1);
|
|
|
|
|
|
|
|
gimp_gradient_get_color_at (rbd.gradient, rbd.context, NULL,
|
|
|
|
factor, rbd.reverse,
|
|
|
|
rbd.gradient_cache + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-09-20 06:17:06 +08:00
|
|
|
if (gimp_gradient_has_fg_bg_segments (rbd.gradient))
|
|
|
|
rbd.gradient = gimp_gradient_flatten (rbd.gradient, context);
|
|
|
|
else
|
|
|
|
rbd.gradient = g_object_ref (rbd.gradient);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Calculate type-specific parameters */
|
|
|
|
|
|
|
|
switch (gradient_type)
|
|
|
|
{
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_RADIAL:
|
2003-12-01 22:32:42 +08:00
|
|
|
rbd.dist = sqrt (SQR (ex - sx) + SQR (ey - sy));
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SQUARE:
|
2000-01-26 07:06:12 +08:00
|
|
|
rbd.dist = MAX (fabs (ex - sx), fabs (ey - sy));
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_CONICAL_SYMMETRIC:
|
|
|
|
case GIMP_GRADIENT_CONICAL_ASYMMETRIC:
|
|
|
|
case GIMP_GRADIENT_SPIRAL_CLOCKWISE:
|
|
|
|
case GIMP_GRADIENT_SPIRAL_ANTICLOCKWISE:
|
|
|
|
case GIMP_GRADIENT_LINEAR:
|
|
|
|
case GIMP_GRADIENT_BILINEAR:
|
2001-01-02 02:35:09 +08:00
|
|
|
rbd.dist = sqrt (SQR (ex - sx) + SQR (ey - sy));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (rbd.dist > 0.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
rbd.vec[0] = (ex - sx) / rbd.dist;
|
|
|
|
rbd.vec[1] = (ey - sy) / rbd.dist;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SHAPEBURST_ANGULAR:
|
|
|
|
case GIMP_GRADIENT_SHAPEBURST_SPHERICAL:
|
|
|
|
case GIMP_GRADIENT_SHAPEBURST_DIMPLED:
|
2001-01-02 02:35:09 +08:00
|
|
|
rbd.dist = sqrt (SQR (ex - sx) + SQR (ey - sy));
|
2012-03-27 08:47:06 +08:00
|
|
|
rbd.dist_buffer = gradient_precalc_shapeburst (image, drawable,
|
2012-04-24 00:46:49 +08:00
|
|
|
buffer_region,
|
|
|
|
rbd.dist, progress);
|
2014-07-21 05:32:19 +08:00
|
|
|
gimp_progress_set_text_literal (progress, _("Blending"));
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-11-10 00:54:56 +08:00
|
|
|
g_assert_not_reached ();
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize render data */
|
|
|
|
|
|
|
|
rbd.offset = offset;
|
|
|
|
rbd.sx = sx;
|
|
|
|
rbd.sy = sy;
|
|
|
|
rbd.gradient_type = gradient_type;
|
2004-06-13 09:17:57 +08:00
|
|
|
rbd.repeat = repeat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Render the gradient! */
|
|
|
|
|
|
|
|
if (supersample)
|
|
|
|
{
|
2003-12-01 22:32:42 +08:00
|
|
|
PutPixelData ppd;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-04-23 23:46:25 +08:00
|
|
|
ppd.buffer = buffer;
|
2012-04-24 00:46:49 +08:00
|
|
|
ppd.row_data = g_malloc (sizeof (float) * 4 * buffer_region->width);
|
|
|
|
ppd.width = buffer_region->width;
|
2005-02-27 23:06:40 +08:00
|
|
|
ppd.dither_rand = g_rand_new ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-04-24 00:46:49 +08:00
|
|
|
gimp_adaptive_supersample_area (0, 0,
|
|
|
|
(buffer_region->width - 1),
|
|
|
|
(buffer_region->height - 1),
|
2006-04-12 20:49:29 +08:00
|
|
|
max_depth, threshold,
|
|
|
|
gradient_render_pixel, &rbd,
|
|
|
|
gradient_put_pixel, &ppd,
|
|
|
|
progress ?
|
2004-08-11 08:34:34 +08:00
|
|
|
gimp_progress_update_and_flush : NULL,
|
2004-08-11 02:47:21 +08:00
|
|
|
progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 23:06:40 +08:00
|
|
|
g_rand_free (ppd.dither_rand);
|
2001-01-02 02:35:09 +08:00
|
|
|
g_free (ppd.row_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-24 01:11:08 +08:00
|
|
|
GeglBufferIterator *iter;
|
|
|
|
GeglRectangle *roi;
|
|
|
|
gint total = buffer_region->width * buffer_region->height;
|
|
|
|
gint done = 0;
|
|
|
|
|
|
|
|
iter = gegl_buffer_iterator_new (buffer, buffer_region, 0,
|
|
|
|
babl_format ("R'G'B'A float"),
|
2014-07-02 08:00:35 +08:00
|
|
|
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
|
2012-04-24 01:11:08 +08:00
|
|
|
roi = &iter->roi[0];
|
Bit of a large checkin this - it's basically three things: 1 - GimpModules
Sun Jan 11 00:24:21 GMT 1999 Austin Donnelly <austin@greenend.org.uk>
Bit of a large checkin this - it's basically three things:
1 - GimpModules using gmodules to dynamically load and
initialise modules at gimp start of day.
2 - Color selectors now register themselves with a color
notebook.
3 - progress bars have been cleaned up a bit, so now have
progress indictations on all transform tool and gradient
fill operations. Not done bucket fill, but that seems to
be the next candidate.
New directories:
* modules/: new directory for dynamically loadable modules.
New files:
* modules/.cvsignore
* modules/Makefile.am
* modules/colorsel_gtk.c: GTK color selector wrapped up as a
color selector the gimp can use.
* app/gimpprogress.[ch]: progress bars within gimp core, either as
popups, or in the status bar. This is mainly code moved out
of plug-in.c
* app/color_notebook.[ch]: color selector notebook, implementing
very similar interface to color_select.h so it can be used as
a drop-in replacement for it.
* libgimp/color_selector.h: API color selectors need to implement
to become a page in the color_notebook.
* libgimp/gimpmodule.h: API gimp modules need to implement to be
initialised by gimp at start of day.
Modified files:
* Makefile.am: add modules/ to SUBDIRS
* libgimp/Makefile.am: install gimpmodule.h and color_selector.h
* app/gimprc.[ch]: recognise module-path variable.
* gimprc.in: set module-path variable to something sensible
(currently "${gimp_dir}/modules:${gimp_plugin_dir}/modules").
* app/Makefile.am: build color notebook and gimpprogress
* app/app_procs.c: register internal GIMP color selector with
color notebook.
* app/asupsample.c: call progress function less frequently for
better performance.
* app/asupsample.h: progress_func_t typedef moved to gimpprogress.h
* app/blend.c: make callbacks to a progress function
* app/color_area.c: use a color notebook rather than a color selector
* app/color_panel.c: ditto
* app/color_select.c: export color selector interface for notebook
* app/color_select.h: color_select_init() prototype
* app/flip_tool.c: flip the image every time, rather than every
second click.
* app/interface.c: move progress bar stuff out to
gimpprogress.c. Make the code actually work while we're at it.
* app/interface.h: move prototypes for progress functions out to
gimpprogress.h
* app/plug_in.c: load and initialise modules (if possible). Move
progress bar handling code out to gimpprogress.c
* app/plug_in.h: keep only a gimp_progress * for each plugin, not
a whole bunch of GtkWidgets.
* app/scale_tool.c
* app/rotate_tool.c
* app/shear_tool.c
* app/perspective_tool.c: progress bar during operation.
De-sensitise the dialog to discourage the user from running
two transforms in parallel.
* app/transform_core.c: recalculate grid coords when bounding box
changes. Only initialise the action area of the dialog once,
to avoid multiple "ok" / "reset" buttons appearing. Undraw
transform tool with correct matrix to get rid of handle
remains on screen. Call a progress function as we apply the
transform matrix. A few new i18n markups. Invalidate
floating selection marching ants after applying matrix.
* app/transform_core.h: transform_core_do() takes an optional
progress callback argument (and data).
* plug-ins/oilify/oilify.c: send progress bar updates after every
pixel region, not only if they processed a multiple of 5
pixels (which was quite unlikely, and therefore gave a jerky
progress indication).
1999-01-11 08:57:33 +08:00
|
|
|
|
2005-02-27 23:06:40 +08:00
|
|
|
if (dither)
|
2012-04-24 01:11:08 +08:00
|
|
|
rbd.seed = g_rand_new ();
|
2005-02-16 22:54:56 +08:00
|
|
|
|
2012-04-24 01:11:08 +08:00
|
|
|
while (gegl_buffer_iterator_next (iter))
|
2005-02-27 23:06:40 +08:00
|
|
|
{
|
2012-04-24 01:11:08 +08:00
|
|
|
gfloat *dest = iter->data[0];
|
|
|
|
gint endx = roi->x + roi->width;
|
|
|
|
gint endy = roi->y + roi->height;
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
if (rbd.seed)
|
|
|
|
{
|
|
|
|
GRand *dither_rand = g_rand_new_with_seed (g_rand_int (rbd.seed));
|
|
|
|
|
|
|
|
for (y = roi->y; y < endy; y++)
|
|
|
|
for (x = roi->x; x < endx; x++)
|
|
|
|
{
|
2013-06-23 19:10:44 +08:00
|
|
|
GimpRGB color = { 0.0, 0.0, 0.0, 1.0 };
|
2012-04-24 01:11:08 +08:00
|
|
|
gint i = g_rand_int (dither_rand);
|
|
|
|
|
|
|
|
gradient_render_pixel (x, y, &color, &rbd);
|
|
|
|
|
|
|
|
*dest++ = color.r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
|
|
|
|
*dest++ = color.g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
|
|
|
|
*dest++ = color.b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
|
|
|
|
*dest++ = color.a + (gdouble) (i & 0xff) / 256.0 / 256.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_rand_free (dither_rand);
|
|
|
|
}
|
2005-02-27 23:06:40 +08:00
|
|
|
else
|
2012-04-24 01:11:08 +08:00
|
|
|
{
|
|
|
|
for (y = roi->y; y < endy; y++)
|
|
|
|
for (x = roi->x; x < endx; x++)
|
|
|
|
{
|
2013-06-23 19:10:44 +08:00
|
|
|
GimpRGB color = { 0.0, 0.0, 0.0, 1.0 };
|
2012-04-24 01:11:08 +08:00
|
|
|
|
|
|
|
gradient_render_pixel (x, y, &color, &rbd);
|
|
|
|
|
|
|
|
*dest++ = color.r;
|
|
|
|
*dest++ = color.g;
|
|
|
|
*dest++ = color.b;
|
|
|
|
*dest++ = color.a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done += roi->width * roi->height;
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress,
|
|
|
|
(gdouble) done / (gdouble) total);
|
2005-02-27 23:06:40 +08:00
|
|
|
}
|
2005-02-16 22:54:56 +08:00
|
|
|
|
2005-02-27 23:06:40 +08:00
|
|
|
if (dither)
|
|
|
|
g_rand_free (rbd.seed);
|
|
|
|
}
|
2006-09-20 06:17:06 +08:00
|
|
|
|
2012-05-29 04:55:03 +08:00
|
|
|
#ifdef USE_GRADIENT_CACHE
|
|
|
|
g_free (rbd.gradient_cache);
|
|
|
|
#endif
|
|
|
|
|
2006-09-20 06:17:06 +08:00
|
|
|
g_object_unref (rbd.gradient);
|
2012-03-27 08:47:06 +08:00
|
|
|
|
|
|
|
if (rbd.dist_buffer)
|
|
|
|
g_object_unref (rbd.dist_buffer);
|
2012-05-29 04:55:03 +08:00
|
|
|
|
|
|
|
GIMP_TIMER_END("gradient_fill_region");
|
2005-02-16 22:54:56 +08:00
|
|
|
}
|