1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
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
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
#include <glib-object.h>
|
1999-09-02 09:41:18 +08:00
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.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
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/tile.h"
|
2001-11-10 00:54:56 +08:00
|
|
|
#include "base/tile-manager.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
#include "gimp.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
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-12-12 02:53:03 +08:00
|
|
|
GimpGradient *gradient;
|
2003-07-22 22:24:11 +08:00
|
|
|
gboolean reverse;
|
2001-12-12 02:53:03 +08:00
|
|
|
gdouble offset;
|
|
|
|
gdouble sx, sy;
|
|
|
|
GimpBlendMode blend_mode;
|
|
|
|
GimpGradientType gradient_type;
|
|
|
|
GimpRGB fg, bg;
|
|
|
|
gdouble dist;
|
|
|
|
gdouble vec[2];
|
2004-06-13 09:57:26 +08:00
|
|
|
GimpRepeatMode repeat;
|
1997-11-25 06:05:25 +08:00
|
|
|
} RenderBlendData;
|
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
PixelRegion *PR;
|
|
|
|
guchar *row_data;
|
2001-12-03 21:44:59 +08:00
|
|
|
gint bytes;
|
|
|
|
gint width;
|
2003-07-21 09:13:35 +08:00
|
|
|
gboolean dither;
|
|
|
|
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);
|
|
|
|
static gdouble gradient_calc_radial_factor (gdouble dist,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_linear_factor (gdouble dist,
|
|
|
|
gdouble *vec,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_bilinear_factor (gdouble dist,
|
|
|
|
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);
|
|
|
|
|
|
|
|
static gdouble gradient_calc_shapeburst_angular_factor (gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_shapeburst_spherical_factor (gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gradient_calc_shapeburst_dimpled_factor (gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
|
2004-06-13 18:52:42 +08:00
|
|
|
static void gradient_precalc_shapeburst (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PixelRegion *PR,
|
|
|
|
gdouble dist,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress);
|
2003-12-01 22:32:42 +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);
|
|
|
|
|
|
|
|
static void gradient_fill_region (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-12-01 22:32:42 +08:00
|
|
|
PixelRegion *PR,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpBlendMode blend_mode,
|
|
|
|
GimpGradientType gradient_type,
|
|
|
|
gdouble offset,
|
2004-06-13 09:17:57 +08:00
|
|
|
GimpRepeatMode repeat,
|
2003-12-01 22:32:42 +08:00
|
|
|
gboolean reverse,
|
|
|
|
gboolean supersample,
|
|
|
|
gint max_depth,
|
|
|
|
gdouble threshold,
|
|
|
|
gboolean dither,
|
|
|
|
gdouble sx,
|
|
|
|
gdouble sy,
|
|
|
|
gdouble ex,
|
|
|
|
gdouble ey,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-03-12 04:01:14 +08:00
|
|
|
/* variables for the shapeburst algs */
|
2001-11-10 00:54:56 +08:00
|
|
|
|
2001-03-12 04:01:14 +08:00
|
|
|
static PixelRegion distR =
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
2001-03-12 04:01:14 +08:00
|
|
|
NULL, /* data */
|
|
|
|
NULL, /* tiles */
|
|
|
|
0, /* rowstride */
|
|
|
|
0, 0, /* w, h */
|
|
|
|
0, 0, /* x, y */
|
|
|
|
4, /* bytes */
|
|
|
|
0 /* process count */
|
|
|
|
};
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1999-04-09 06:25:54 +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,
|
2003-07-22 22:24:11 +08:00
|
|
|
GimpBlendMode blend_mode,
|
|
|
|
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
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
1997-11-25 06:05:25 +08:00
|
|
|
TileManager *buf_tiles;
|
2000-12-31 13:31:43 +08:00
|
|
|
PixelRegion bufPR;
|
|
|
|
gint bytes;
|
2004-10-20 06:52:04 +08:00
|
|
|
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-04-15 07:37:34 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
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
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-10 00:54:56 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
|
|
|
return;
|
1999-01-11 07:36:29 +08:00
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
gimp_set_busy (gimage->gimp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-12-01 22:32:42 +08:00
|
|
|
bytes = gimp_drawable_bytes (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Always create an alpha temp buf (for generality) */
|
2003-12-01 22:32:42 +08:00
|
|
|
if (! gimp_drawable_has_alpha (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
bytes += 1;
|
|
|
|
}
|
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
buf_tiles = tile_manager_new (width, height, bytes);
|
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gradient_fill_region (gimage, drawable, context,
|
2004-10-20 06:52:04 +08:00
|
|
|
&bufPR, width, height,
|
2003-07-22 22:24:11 +08:00
|
|
|
blend_mode, gradient_type, offset, repeat, reverse,
|
2003-07-21 09:13:35 +08:00
|
|
|
supersample, max_depth, threshold, dither,
|
2004-10-20 06:52:04 +08:00
|
|
|
(startx - x), (starty - y),
|
|
|
|
(endx - x), (endy - y),
|
2004-08-11 02:47:21 +08:00
|
|
|
progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
if (distR.tiles)
|
|
|
|
{
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (distR.tiles);
|
2001-11-10 00:54:56 +08:00
|
|
|
distR.tiles = NULL;
|
|
|
|
}
|
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, FALSE);
|
2003-10-06 22:40:12 +08:00
|
|
|
gimp_drawable_apply_region (drawable, &bufPR,
|
|
|
|
TRUE, _("Blend"),
|
|
|
|
opacity, paint_mode,
|
2004-10-20 06:52:04 +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 */
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (buf_tiles);
|
1999-01-11 07:36:29 +08:00
|
|
|
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
gimp_unset_busy (gimage->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,
|
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble vec[2];
|
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.0;
|
|
|
|
}
|
|
|
|
else if ((x != 0) || (y != 0))
|
|
|
|
{
|
|
|
|
/* Calculate offset from the start in pixels */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
r = sqrt (x * x + y * 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)
|
|
|
|
rat = 1.0;
|
|
|
|
else if (rat < -1.0)
|
|
|
|
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
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
rat = CLAMP (rat, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1997-11-25 06:05:25 +08:00
|
|
|
rat = 0.5;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return rat;
|
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,
|
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble ang0, ang1;
|
|
|
|
gdouble ang;
|
|
|
|
gdouble rat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((x != 0) || (y != 0))
|
|
|
|
{
|
2003-05-06 02:45:58 +08:00
|
|
|
ang0 = atan2 (axis[0], axis[1]) + G_PI;
|
|
|
|
ang1 = atan2 (x, y) + G_PI;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
ang = ang1 - ang0;
|
|
|
|
|
|
|
|
if (ang < 0.0)
|
1999-08-05 07:22:29 +08:00
|
|
|
ang += (2.0 * G_PI);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-05 07:22:29 +08:00
|
|
|
rat = ang / (2.0 * 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
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
rat = CLAMP (rat, 0.0, 1.0);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.5; /* We are on middle point */
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return rat;
|
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,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* 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)
|
|
|
|
rat = 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
|
|
|
rat = (rat >= 1.0) ? 1.0 : 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
rat = (rat - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return rat;
|
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,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* 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)
|
|
|
|
rat = 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
|
|
|
rat = (rat >= 1.0) ? 1.0 : 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
rat = (rat - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return rat;
|
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,
|
|
|
|
gdouble *vec,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-05-06 02:45:58 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
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)
|
1999-09-26 03:49:58 +08:00
|
|
|
rat = 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
|
|
|
rat = (rat >= 1.0) ? 1.0 : 0.0;
|
|
|
|
else if (rat < 0.0)
|
|
|
|
rat = rat / (1.0 - offset);
|
1999-09-26 03:49:58 +08:00
|
|
|
else
|
|
|
|
rat = (rat - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return rat;
|
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,
|
|
|
|
gdouble *vec,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble r;
|
|
|
|
gdouble rat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* 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)
|
1997-11-25 06:05:25 +08:00
|
|
|
rat = 0.0;
|
2003-05-06 02:45:58 +08:00
|
|
|
else if (offset == 1.0)
|
|
|
|
rat = (rat == 1.0) ? 1.0 : 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2003-05-06 02:45:58 +08:00
|
|
|
rat = (fabs (rat) - offset) / (1.0 - offset);
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return rat;
|
2001-01-02 02:35:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble
|
2003-12-01 22:32:42 +08:00
|
|
|
gradient_calc_spiral_factor (gdouble dist,
|
|
|
|
gdouble *axis,
|
|
|
|
gdouble offset,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gboolean clockwise)
|
1999-01-05 07:56:37 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble ang0, ang1;
|
|
|
|
gdouble ang, r;
|
|
|
|
gdouble rat;
|
1999-01-05 07:56:37 +08:00
|
|
|
|
|
|
|
if (dist == 0.0)
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
rat = 0.0;
|
|
|
|
}
|
1999-01-05 07:56:37 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (x != 0.0 || y != 0.0)
|
|
|
|
{
|
1999-08-05 07:22:29 +08:00
|
|
|
ang0 = atan2 (axis[0], axis[1]) + G_PI;
|
|
|
|
ang1 = atan2 (x, y) + G_PI;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
|
|
|
if (clockwise)
|
1999-01-05 07:56:37 +08:00
|
|
|
ang = ang1 - ang0;
|
2003-12-01 22:32:42 +08:00
|
|
|
else
|
|
|
|
ang = ang0 - ang1;
|
1999-01-05 07:56:37 +08:00
|
|
|
|
|
|
|
if (ang < 0.0)
|
1999-08-05 07:22:29 +08:00
|
|
|
ang += (2.0 * G_PI);
|
1999-01-05 07:56:37 +08:00
|
|
|
|
|
|
|
r = sqrt (x * x + y * y) / dist;
|
1999-08-05 07:22:29 +08:00
|
|
|
rat = ang / (2.0 * G_PI) + r + offset;
|
1999-01-05 07:56:37 +08:00
|
|
|
rat = fmod (rat, 1.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rat = 0.5 ; /* We are on the middle point */
|
|
|
|
}
|
|
|
|
|
|
|
|
return rat;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_shapeburst_angular_factor (gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gint ix, iy;
|
|
|
|
Tile *tile;
|
|
|
|
gfloat value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-03-14 02:11:40 +08:00
|
|
|
ix = (gint) CLAMP (x, 0.0, distR.w - 0.7);
|
|
|
|
iy = (gint) CLAMP (y, 0.0, distR.h - 0.7);
|
1998-08-16 03:17:36 +08:00
|
|
|
tile = tile_manager_get_tile (distR.tiles, ix, iy, TRUE, FALSE);
|
2004-03-14 02:11:40 +08:00
|
|
|
value = 1.0 - *((gfloat *) tile_data_pointer (tile,
|
|
|
|
ix % TILE_WIDTH,
|
|
|
|
iy % TILE_HEIGHT));
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_release (tile, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_shapeburst_spherical_factor (gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gint ix, iy;
|
|
|
|
Tile *tile;
|
|
|
|
gfloat value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-03-14 02:11:40 +08:00
|
|
|
ix = (gint) CLAMP (x, 0.0, distR.w - 0.7);
|
|
|
|
iy = (gint) CLAMP (y, 0.0, distR.h - 0.7);
|
1998-08-16 03:17:36 +08:00
|
|
|
tile = tile_manager_get_tile (distR.tiles, ix, iy, TRUE, FALSE);
|
2003-12-01 22:32:42 +08:00
|
|
|
value = *((gfloat *) tile_data_pointer (tile,
|
|
|
|
ix % TILE_WIDTH,
|
|
|
|
iy % TILE_HEIGHT));
|
1999-08-05 07:22:29 +08:00
|
|
|
value = 1.0 - sin (0.5 * G_PI * value);
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_release (tile, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
static gdouble
|
|
|
|
gradient_calc_shapeburst_dimpled_factor (gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
gint ix, iy;
|
|
|
|
Tile *tile;
|
|
|
|
gfloat value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-03-14 02:11:40 +08:00
|
|
|
ix = (gint) CLAMP (x, 0.0, distR.w - 0.7);
|
|
|
|
iy = (gint) CLAMP (y, 0.0, distR.h - 0.7);
|
1998-08-16 03:17:36 +08:00
|
|
|
tile = tile_manager_get_tile (distR.tiles, ix, iy, TRUE, FALSE);
|
2004-03-14 02:11:40 +08:00
|
|
|
value = *((gfloat *) tile_data_pointer (tile,
|
|
|
|
ix % TILE_WIDTH,
|
|
|
|
iy % TILE_HEIGHT));
|
1999-08-05 07:22:29 +08:00
|
|
|
value = cos (0.5 * G_PI * value);
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_release (tile, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-11 02:47:21 +08:00
|
|
|
gradient_precalc_shapeburst (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
PixelRegion *PR,
|
|
|
|
gdouble dist,
|
|
|
|
GimpProgress *progress)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 10:45:02 +08:00
|
|
|
GimpChannel *mask;
|
2001-01-02 02:35:09 +08:00
|
|
|
PixelRegion tempR;
|
|
|
|
gfloat max_iteration;
|
|
|
|
gfloat *distp;
|
|
|
|
gint size;
|
|
|
|
gpointer pr;
|
|
|
|
guchar white[1] = { OPAQUE_OPACITY };
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* allocate the distance map */
|
2001-01-02 02:35:09 +08:00
|
|
|
distR.tiles = tile_manager_new (PR->w, PR->h, sizeof (gfloat));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* allocate the selection mask copy */
|
|
|
|
tempR.tiles = tile_manager_new (PR->w, PR->h, 1);
|
|
|
|
pixel_region_init (&tempR, tempR.tiles, 0, 0, PR->w, PR->h, TRUE);
|
|
|
|
|
2003-09-03 23:13:19 +08:00
|
|
|
mask = gimp_image_get_mask (gimage);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* If the gimage 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
|
|
|
{
|
|
|
|
PixelRegion maskR;
|
2000-12-29 23:22:01 +08:00
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint offx, offy;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &offx, &offy);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
pixel_region_init (&maskR, gimp_drawable_data (GIMP_DRAWABLE (mask)),
|
1998-01-22 15:02:57 +08:00
|
|
|
x1 + offx, y1 + offy, (x2 - x1), (y2 - y1), FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* copy the mask to the temp mask */
|
|
|
|
copy_region (&maskR, &tempR);
|
|
|
|
}
|
|
|
|
/* otherwise... */
|
|
|
|
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))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PixelRegion drawableR;
|
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
pixel_region_init (&drawableR, gimp_drawable_data (drawable),
|
2001-01-02 02:35:09 +08:00
|
|
|
PR->x, PR->y, PR->w, PR->h, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
extract_alpha_region (&drawableR, NULL, &tempR);
|
|
|
|
}
|
|
|
|
else
|
2001-01-02 02:35:09 +08:00
|
|
|
{
|
|
|
|
/* Otherwise, just fill the shapeburst to white */
|
|
|
|
color_region (&tempR, white);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pixel_region_init (&tempR, tempR.tiles, 0, 0, PR->w, PR->h, TRUE);
|
|
|
|
pixel_region_init (&distR, distR.tiles, 0, 0, PR->w, PR->h, TRUE);
|
2004-08-11 02:47:21 +08:00
|
|
|
max_iteration = shapeburst_region (&tempR, &distR,
|
|
|
|
progress ?
|
|
|
|
gimp_progress_update_and_flush : NULL,
|
|
|
|
progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* normalize the shapeburst with the max iteration */
|
|
|
|
if (max_iteration > 0)
|
|
|
|
{
|
|
|
|
pixel_region_init (&distR, distR.tiles, 0, 0, PR->w, PR->h, TRUE);
|
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
for (pr = pixel_regions_register (1, &distR);
|
|
|
|
pr != NULL;
|
|
|
|
pr = pixel_regions_process (pr))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-02 02:35:09 +08:00
|
|
|
distp = (gfloat *) distR.data;
|
|
|
|
size = distR.w * distR.h;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
while (size--)
|
|
|
|
*distp++ /= max_iteration;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixel_region_init (&distR, distR.tiles, 0, 0, PR->w, PR->h, FALSE);
|
|
|
|
}
|
|
|
|
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (tempR.tiles);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-07-22 22:24:11 +08:00
|
|
|
gradient_render_pixel (double x,
|
|
|
|
double y,
|
|
|
|
GimpRGB *color,
|
2001-01-02 02:35:09 +08:00
|
|
|
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:
|
2001-11-10 00:54:56 +08:00
|
|
|
factor = gradient_calc_linear_factor (rbd->dist, rbd->vec, rbd->offset,
|
1999-09-26 03:49:58 +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:
|
2001-11-10 00:54:56 +08:00
|
|
|
factor = gradient_calc_bilinear_factor (rbd->dist, rbd->vec, rbd->offset,
|
|
|
|
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:
|
2001-11-10 00:54:56 +08:00
|
|
|
factor = gradient_calc_radial_factor (rbd->dist, rbd->offset,
|
|
|
|
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,
|
|
|
|
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:
|
2001-11-10 00:54:56 +08:00
|
|
|
factor = gradient_calc_conical_sym_factor (rbd->dist, rbd->vec, rbd->offset,
|
|
|
|
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:
|
2001-11-10 00:54:56 +08:00
|
|
|
factor = gradient_calc_conical_asym_factor (rbd->dist, rbd->vec, rbd->offset,
|
|
|
|
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:
|
1999-09-26 03:49:58 +08:00
|
|
|
factor = gradient_calc_shapeburst_angular_factor (x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SHAPEBURST_SPHERICAL:
|
1999-09-26 03:49:58 +08:00
|
|
|
factor = gradient_calc_shapeburst_spherical_factor (x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SHAPEBURST_DIMPLED:
|
1999-09-26 03:49:58 +08:00
|
|
|
factor = gradient_calc_shapeburst_dimpled_factor (x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SPIRAL_CLOCKWISE:
|
1999-01-05 07:56:37 +08:00
|
|
|
factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset,
|
|
|
|
x - rbd->sx, y - rbd->sy,TRUE);
|
|
|
|
break;
|
|
|
|
|
2003-08-27 02:12:42 +08:00
|
|
|
case GIMP_GRADIENT_SPIRAL_ANTICLOCKWISE:
|
1999-01-05 07:56:37 +08:00
|
|
|
factor = gradient_calc_spiral_factor (rbd->dist, rbd->vec, rbd->offset,
|
|
|
|
x - rbd->sx, y - rbd->sy,FALSE);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
|
2001-12-12 02:53:03 +08:00
|
|
|
if (rbd->blend_mode == GIMP_CUSTOM_MODE)
|
2001-01-21 00:28:05 +08:00
|
|
|
{
|
2003-07-22 22:24:11 +08:00
|
|
|
gimp_gradient_get_color_at (rbd->gradient, factor, rbd->reverse, color);
|
2001-01-21 00:28:05 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Blend values */
|
|
|
|
|
2003-07-22 22:24:11 +08:00
|
|
|
if (rbd->reverse)
|
|
|
|
factor = 1.0 - factor;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
color->r = rbd->fg.r + (rbd->bg.r - rbd->fg.r) * factor;
|
|
|
|
color->g = rbd->fg.g + (rbd->bg.g - rbd->fg.g) * factor;
|
|
|
|
color->b = rbd->fg.b + (rbd->bg.b - rbd->fg.b) * factor;
|
|
|
|
color->a = rbd->fg.a + (rbd->bg.a - rbd->fg.a) * factor;
|
|
|
|
|
2001-12-12 02:53:03 +08:00
|
|
|
if (rbd->blend_mode == GIMP_FG_BG_HSV_MODE)
|
2003-05-21 02:29:13 +08:00
|
|
|
{
|
2003-12-01 22:32:42 +08:00
|
|
|
GimpHSV hsv = *((GimpHSV *) color);
|
2003-05-21 02:29:13 +08:00
|
|
|
|
|
|
|
gimp_hsv_to_rgb (&hsv, color);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-12-01 22:32:42 +08:00
|
|
|
gradient_put_pixel (gint x,
|
|
|
|
gint y,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer put_pixel_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-13 09:17:57 +08:00
|
|
|
PutPixelData *ppd = put_pixel_data;
|
2001-01-02 02:35:09 +08:00
|
|
|
guchar *data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Paint */
|
|
|
|
|
|
|
|
data = ppd->row_data + ppd->bytes * x;
|
|
|
|
|
|
|
|
if (ppd->bytes >= 3)
|
|
|
|
{
|
2003-07-21 09:13:35 +08:00
|
|
|
if (ppd->dither)
|
|
|
|
{
|
|
|
|
gdouble dither_prob;
|
|
|
|
gdouble ftmp;
|
|
|
|
gint itmp;
|
|
|
|
|
|
|
|
ftmp = color->r * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (ppd->dither_rand) < dither_prob)
|
|
|
|
color->r += (1.0 / 255.0);
|
|
|
|
|
|
|
|
ftmp = color->g * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (ppd->dither_rand) < dither_prob)
|
|
|
|
color->g += (1.0 / 255.0);
|
|
|
|
|
|
|
|
ftmp = color->b * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-22 22:24:11 +08:00
|
|
|
if (g_rand_double (ppd->dither_rand) < dither_prob)
|
2003-07-21 09:13:35 +08:00
|
|
|
color->b += (1.0 / 255.0);
|
|
|
|
|
|
|
|
ftmp = color->a * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-22 22:24:11 +08:00
|
|
|
if (g_rand_double (ppd->dither_rand) < dither_prob)
|
2003-07-21 09:13:35 +08:00
|
|
|
color->a += (1.0 / 255.0);
|
|
|
|
|
|
|
|
if (color->r > 1.0) color->r = 1.0;
|
|
|
|
if (color->g > 1.0) color->g = 1.0;
|
|
|
|
if (color->b > 1.0) color->b = 1.0;
|
|
|
|
if (color->a > 1.0) color->a = 1.0;
|
|
|
|
}
|
|
|
|
|
2001-01-23 08:53:12 +08:00
|
|
|
*data++ = color->r * 255.0;
|
|
|
|
*data++ = color->g * 255.0;
|
|
|
|
*data++ = color->b * 255.0;
|
|
|
|
*data++ = color->a * 255.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Convert to grayscale */
|
2003-11-17 22:58:31 +08:00
|
|
|
gdouble gray = gimp_rgb_intensity (color);
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (ppd->dither)
|
|
|
|
{
|
|
|
|
gdouble dither_prob;
|
|
|
|
gdouble ftmp;
|
|
|
|
gint itmp;
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
ftmp = gray * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (ppd->dither_rand) < dither_prob)
|
|
|
|
gray += (1.0 / 255.0);
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
ftmp = color->a * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (ppd->dither_rand) < dither_prob)
|
|
|
|
color->a += (1.0 / 255.0);
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-24 19:10:47 +08:00
|
|
|
if (gray > 1.0) gray = 1.0;
|
2003-07-21 09:13:35 +08:00
|
|
|
if (color->a > 1.0) color->a = 1.0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
*data++ = gray * 255.0;
|
2001-01-23 08:53:12 +08:00
|
|
|
*data++ = color->a * 255.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint whole row if we are on the rightmost pixel */
|
|
|
|
|
|
|
|
if (x == (ppd->width - 1))
|
2003-07-21 09:13:35 +08:00
|
|
|
pixel_region_set_row (ppd->PR, 0, y, ppd->width, ppd->row_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-12 04:01:14 +08:00
|
|
|
gradient_fill_region (GimpImage *gimage,
|
2000-12-31 13:31:43 +08:00
|
|
|
GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2000-12-31 13:31:43 +08:00
|
|
|
PixelRegion *PR,
|
2001-01-02 02:35:09 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
2001-12-12 02:53:03 +08:00
|
|
|
GimpBlendMode blend_mode,
|
|
|
|
GimpGradientType gradient_type,
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble offset,
|
2001-12-12 02:53:03 +08:00
|
|
|
GimpRepeatMode repeat,
|
2003-07-22 22:24:11 +08:00
|
|
|
gboolean reverse,
|
|
|
|
gboolean supersample,
|
2001-01-02 02:35:09 +08:00
|
|
|
gint max_depth,
|
|
|
|
gdouble threshold,
|
2003-07-21 09:13:35 +08:00
|
|
|
gboolean dither,
|
2001-01-02 02:35:09 +08:00
|
|
|
gdouble sx,
|
|
|
|
gdouble sy,
|
|
|
|
gdouble ex,
|
|
|
|
gdouble ey,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
RenderBlendData rbd;
|
2000-12-31 13:31:43 +08:00
|
|
|
gint x, y;
|
|
|
|
gint endx, endy;
|
2001-08-19 19:21:48 +08:00
|
|
|
gpointer pr;
|
2000-12-31 13:31:43 +08:00
|
|
|
guchar *data;
|
2001-01-02 02:35:09 +08:00
|
|
|
GimpRGB color;
|
2003-07-21 09:13:35 +08:00
|
|
|
GRand *dither_rand = NULL;
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
rbd.gradient = gimp_context_get_gradient (context);
|
2003-07-22 22:24:11 +08:00
|
|
|
rbd.reverse = reverse;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_context_get_foreground (context, &rbd.fg);
|
|
|
|
gimp_context_get_background (context, &rbd.bg);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
switch (blend_mode)
|
|
|
|
{
|
2001-12-12 02:53:03 +08:00
|
|
|
case GIMP_FG_BG_RGB_MODE:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2001-12-12 02:53:03 +08:00
|
|
|
case GIMP_FG_BG_HSV_MODE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Convert to HSV */
|
2003-05-21 02:29:13 +08:00
|
|
|
{
|
|
|
|
GimpHSV fg_hsv;
|
|
|
|
GimpHSV bg_hsv;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-05-21 02:29:13 +08:00
|
|
|
gimp_rgb_to_hsv (&rbd.fg, &fg_hsv);
|
|
|
|
gimp_rgb_to_hsv (&rbd.bg, &bg_hsv);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
memcpy (&rbd.fg, &fg_hsv, sizeof (GimpRGB));
|
|
|
|
memcpy (&rbd.bg, &bg_hsv, sizeof (GimpRGB));
|
2003-05-21 02:29:13 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 06:54:26 +08:00
|
|
|
case GIMP_FG_TRANSPARENT_MODE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Color does not change, just the opacity */
|
|
|
|
|
|
|
|
rbd.bg = rbd.fg;
|
2003-12-01 22:32:42 +08:00
|
|
|
rbd.bg.a = GIMP_OPACITY_TRANSPARENT;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2001-12-12 02:53:03 +08:00
|
|
|
case GIMP_CUSTOM_MODE:
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
rbd.vec[0] = (ex - sx) / rbd.dist;
|
|
|
|
rbd.vec[1] = (ey - sy) / rbd.dist;
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2004-08-11 02:47:21 +08:00
|
|
|
gradient_precalc_shapeburst (gimage, drawable, PR, rbd.dist, progress);
|
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.blend_mode = blend_mode;
|
|
|
|
rbd.gradient_type = gradient_type;
|
2004-06-13 09:17:57 +08:00
|
|
|
rbd.repeat = repeat;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (dither)
|
|
|
|
dither_rand = g_rand_new ();
|
|
|
|
|
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
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
ppd.PR = PR;
|
|
|
|
ppd.row_data = g_malloc (width * PR->bytes);
|
|
|
|
ppd.bytes = PR->bytes;
|
|
|
|
ppd.width = width;
|
|
|
|
ppd.dither = dither;
|
|
|
|
ppd.dither_rand = dither_rand;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-23 08:53:12 +08:00
|
|
|
gimp_adaptive_supersample_area (0, 0, (width - 1), (height - 1),
|
|
|
|
max_depth, threshold,
|
|
|
|
gradient_render_pixel, &rbd,
|
|
|
|
gradient_put_pixel, &ppd,
|
2004-08-11 08:34:34 +08:00
|
|
|
progress ?
|
|
|
|
gimp_progress_update_and_flush : NULL,
|
2004-08-11 02:47:21 +08:00
|
|
|
progress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-02 02:35:09 +08:00
|
|
|
g_free (ppd.row_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-11 02:47:21 +08:00
|
|
|
gint max_progress = PR->w * PR->h;
|
|
|
|
gint curr_progress = 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
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
for (pr = pixel_regions_register (1, PR);
|
2001-01-02 02:35:09 +08:00
|
|
|
pr != NULL;
|
2001-11-10 00:54:56 +08:00
|
|
|
pr = pixel_regions_process (pr))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
data = PR->data;
|
|
|
|
endx = PR->x + PR->w;
|
|
|
|
endy = PR->y + PR->h;
|
|
|
|
|
|
|
|
for (y = PR->y; y < endy; y++)
|
2001-11-10 00:54:56 +08:00
|
|
|
{
|
|
|
|
for (x = PR->x; x < endx; x++)
|
|
|
|
{
|
|
|
|
gradient_render_pixel (x, y, &color, &rbd);
|
|
|
|
|
|
|
|
if (PR->bytes >= 3)
|
|
|
|
{
|
2003-07-21 09:13:35 +08:00
|
|
|
if (dither)
|
|
|
|
{
|
|
|
|
gdouble dither_prob;
|
|
|
|
gdouble ftmp;
|
|
|
|
gint itmp;
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
ftmp = color.r * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (dither_rand) < dither_prob)
|
|
|
|
color.r += (1.0 / 255.0);
|
|
|
|
|
|
|
|
ftmp = color.g * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (dither_rand) < dither_prob)
|
|
|
|
color.g += (1.0 / 255.0);
|
|
|
|
|
|
|
|
ftmp = color.b * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (dither_rand) < dither_prob)
|
|
|
|
color.b += (1.0 / 255.0);
|
|
|
|
|
|
|
|
ftmp = color.a * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (dither_rand) < dither_prob)
|
|
|
|
color.a += (1.0 / 255.0);
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (color.r > 1.0) color.r = 1.0;
|
|
|
|
if (color.g > 1.0) color.g = 1.0;
|
|
|
|
if (color.b > 1.0) color.b = 1.0;
|
|
|
|
if (color.a > 1.0) color.a = 1.0;
|
|
|
|
}
|
|
|
|
|
2001-11-10 00:54:56 +08:00
|
|
|
*data++ = color.r * 255.0;
|
|
|
|
*data++ = color.g * 255.0;
|
|
|
|
*data++ = color.b * 255.0;
|
|
|
|
*data++ = color.a * 255.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Convert to grayscale */
|
2003-11-17 22:58:31 +08:00
|
|
|
gdouble gray = gimp_rgb_intensity (&color);
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (dither)
|
|
|
|
{
|
|
|
|
gdouble dither_prob;
|
|
|
|
gdouble ftmp;
|
|
|
|
gint itmp;
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
ftmp = gray * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (dither_rand) < dither_prob)
|
|
|
|
gray += (1.0 / 255.0);
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
ftmp = color.a * 255.0;
|
|
|
|
itmp = ftmp;
|
|
|
|
dither_prob = ftmp - itmp;
|
2003-12-01 22:32:42 +08:00
|
|
|
|
2003-07-21 09:13:35 +08:00
|
|
|
if (g_rand_double (dither_rand) < dither_prob)
|
|
|
|
color.a += (1.0 / 255.0);
|
2003-07-22 22:24:11 +08:00
|
|
|
|
2003-07-24 19:10:47 +08:00
|
|
|
if (gray > 1.0) gray = 1.0;
|
2003-07-21 09:13:35 +08:00
|
|
|
if (color.a > 1.0) color.a = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*data++ = gray * 255.0;
|
2001-11-10 00:54:56 +08:00
|
|
|
*data++ = color.a * 255.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
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
2004-06-13 09:17:57 +08:00
|
|
|
{
|
2004-08-11 02:47:21 +08:00
|
|
|
curr_progress += PR->w * PR->h;
|
|
|
|
|
2004-08-11 08:34:34 +08:00
|
|
|
gimp_progress_set_value (progress,
|
|
|
|
(gdouble) curr_progress /
|
|
|
|
(gdouble) max_progress);
|
2004-06-13 09:17:57 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2003-07-21 09:13:35 +08:00
|
|
|
|
|
|
|
if (dither)
|
|
|
|
g_rand_free (dither_rand);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|