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-15 23:54:17 +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"
|
|
|
|
|
2009-10-10 21:46:31 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-08-29 22:46:32 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2006-08-29 22:46:32 +08:00
|
|
|
|
2003-09-04 20:18:40 +08:00
|
|
|
#include "core-types.h"
|
2002-08-20 18:22:23 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
#include "gegl/gimp-gegl-mask-combine.h"
|
|
|
|
|
2003-09-04 20:18:40 +08:00
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpchannel-combine.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_channel_combine_rect (GimpChannel *mask,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpChannelOps op,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-04-09 03:54:46 +08:00
|
|
|
GeglBuffer *buffer;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
if (! gimp_gegl_mask_combine_rect (buffer, op, x, y, w, h))
|
|
|
|
return;
|
2012-03-16 05:58:26 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0,
|
|
|
|
gimp_item_get_width (GIMP_ITEM (mask)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (mask)),
|
|
|
|
&x, &y, &w, &h);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Determine new boundary */
|
2009-10-11 05:01:59 +08:00
|
|
|
if (mask->bounds_known && (op == GIMP_CHANNEL_OP_ADD) && ! mask->empty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (x < mask->x1)
|
2006-04-12 20:49:29 +08:00
|
|
|
mask->x1 = x;
|
1997-11-25 06:05:25 +08:00
|
|
|
if (y < mask->y1)
|
2006-04-12 20:49:29 +08:00
|
|
|
mask->y1 = y;
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((x + w) > mask->x2)
|
2006-04-12 20:49:29 +08:00
|
|
|
mask->x2 = (x + w);
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((y + h) > mask->y2)
|
2006-04-12 20:49:29 +08:00
|
|
|
mask->y2 = (y + h);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-03-19 00:22:14 +08:00
|
|
|
else if (op == GIMP_CHANNEL_OP_REPLACE || mask->empty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
mask->empty = FALSE;
|
2002-08-30 00:48:17 +08:00
|
|
|
mask->x1 = x;
|
|
|
|
mask->y1 = y;
|
|
|
|
mask->x2 = x + w;
|
|
|
|
mask->y2 = y + h;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
2009-10-10 21:46:31 +08:00
|
|
|
{
|
|
|
|
mask->bounds_known = FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2008-11-03 08:09:01 +08:00
|
|
|
mask->x1 = CLAMP (mask->x1, 0, gimp_item_get_width (GIMP_ITEM (mask)));
|
|
|
|
mask->y1 = CLAMP (mask->y1, 0, gimp_item_get_height (GIMP_ITEM (mask)));
|
|
|
|
mask->x2 = CLAMP (mask->x2, 0, gimp_item_get_width (GIMP_ITEM (mask)));
|
|
|
|
mask->y2 = CLAMP (mask->y2, 0, gimp_item_get_height (GIMP_ITEM (mask)));
|
2003-10-06 20:17:11 +08:00
|
|
|
|
|
|
|
gimp_drawable_update (GIMP_DRAWABLE (mask), x, y, w, h);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-07-19 03:31:29 +08:00
|
|
|
/**
|
|
|
|
* gimp_channel_combine_ellipse:
|
|
|
|
* @mask: the channel with which to combine the ellipse
|
2004-07-19 22:25:59 +08:00
|
|
|
* @op: whether to replace, add to, or subtract from the current
|
|
|
|
* contents
|
2004-07-19 03:31:29 +08:00
|
|
|
* @x: x coordinate of upper left corner of ellipse
|
|
|
|
* @y: y coordinate of upper left corner of ellipse
|
|
|
|
* @w: width of ellipse bounding box
|
|
|
|
* @h: height of ellipse bounding box
|
|
|
|
* @antialias: if %TRUE, antialias the ellipse
|
|
|
|
*
|
2004-07-19 22:25:59 +08:00
|
|
|
* Mainly used for elliptical selections. If @op is
|
|
|
|
* %GIMP_CHANNEL_OP_REPLACE or %GIMP_CHANNEL_OP_ADD, sets pixels
|
|
|
|
* within the ellipse to 255. If @op is %GIMP_CHANNEL_OP_SUBTRACT,
|
|
|
|
* sets pixels within to zero. If @antialias is %TRUE, pixels that
|
|
|
|
* impinge on the edge of the ellipse are set to intermediate values,
|
|
|
|
* depending on how much they overlap.
|
2004-07-19 03:31:29 +08:00
|
|
|
**/
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_channel_combine_ellipse (GimpChannel *mask,
|
2004-07-19 03:31:29 +08:00
|
|
|
GimpChannelOps op,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
gboolean antialias)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-10-19 02:54:28 +08:00
|
|
|
gimp_channel_combine_ellipse_rect (mask, op, x, y, w, h,
|
|
|
|
w / 2.0, h / 2.0, antialias);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_channel_combine_ellipse_rect:
|
|
|
|
* @mask: the channel with which to combine the elliptic rect
|
|
|
|
* @op: whether to replace, add to, or subtract from the current
|
|
|
|
* contents
|
|
|
|
* @x: x coordinate of upper left corner of bounding rect
|
|
|
|
* @y: y coordinate of upper left corner of bounding rect
|
|
|
|
* @w: width of bounding rect
|
|
|
|
* @h: height of bounding rect
|
|
|
|
* @a: elliptic a-constant applied to corners
|
|
|
|
* @b: elliptic b-constant applied to corners
|
|
|
|
* @antialias: if %TRUE, antialias the elliptic corners
|
|
|
|
*
|
|
|
|
* Used for rounded cornered rectangles and ellipses. If @op is
|
|
|
|
* %GIMP_CHANNEL_OP_REPLACE or %GIMP_CHANNEL_OP_ADD, sets pixels
|
|
|
|
* within the ellipse to 255. If @op is %GIMP_CHANNEL_OP_SUBTRACT,
|
|
|
|
* sets pixels within to zero. If @antialias is %TRUE, pixels that
|
|
|
|
* impinge on the edge of the ellipse are set to intermediate values,
|
|
|
|
* depending on how much they overlap.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_channel_combine_ellipse_rect (GimpChannel *mask,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
gdouble a,
|
|
|
|
gdouble b,
|
|
|
|
gboolean antialias)
|
|
|
|
{
|
2013-04-09 03:54:46 +08:00
|
|
|
GeglBuffer *buffer;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
2006-10-19 02:54:28 +08:00
|
|
|
g_return_if_fail (a >= 0.0 && b >= 0.0);
|
2009-10-11 05:01:59 +08:00
|
|
|
g_return_if_fail (op != GIMP_CHANNEL_OP_INTERSECT);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-03-21 07:42:44 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
|
2012-03-17 19:45:58 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
if (! gimp_gegl_mask_combine_ellipse_rect (buffer, op, x, y, w, h,
|
|
|
|
a, b, antialias))
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0,
|
|
|
|
gimp_item_get_width (GIMP_ITEM (mask)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (mask)),
|
|
|
|
&x, &y, &w, &h);
|
2009-10-11 05:01:59 +08:00
|
|
|
|
2004-07-19 22:25:59 +08:00
|
|
|
/* determine new boundary */
|
2009-10-11 05:01:59 +08:00
|
|
|
if (mask->bounds_known && (op == GIMP_CHANNEL_OP_ADD) && ! mask->empty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-03-17 19:45:58 +08:00
|
|
|
if (x < mask->x1) mask->x1 = x;
|
|
|
|
if (y < mask->y1) mask->y1 = y;
|
|
|
|
|
|
|
|
if ((x + w) > mask->x2) mask->x2 = (x + w);
|
|
|
|
if ((y + h) > mask->y2) mask->y2 = (y + h);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-03-19 00:22:14 +08:00
|
|
|
else if (op == GIMP_CHANNEL_OP_REPLACE || mask->empty)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
mask->empty = FALSE;
|
2002-08-30 00:48:17 +08:00
|
|
|
mask->x1 = x;
|
|
|
|
mask->y1 = y;
|
|
|
|
mask->x2 = x + w;
|
|
|
|
mask->y2 = y + h;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
2004-07-19 22:25:59 +08:00
|
|
|
{
|
|
|
|
mask->bounds_known = FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
gimp_drawable_update (GIMP_DRAWABLE (mask), x, y, w, h);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_channel_combine_mask (GimpChannel *mask,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpChannel *add_on,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-04-09 03:54:46 +08:00
|
|
|
GeglBuffer *add_on_buffer;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (add_on));
|
|
|
|
|
2012-03-21 07:42:44 +08:00
|
|
|
add_on_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (add_on));
|
2012-03-19 10:15:30 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
gimp_channel_combine_buffer (mask, add_on_buffer,
|
|
|
|
op, off_x, off_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_channel_combine_buffer (GimpChannel *mask,
|
|
|
|
GeglBuffer *add_on_buffer,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y)
|
|
|
|
{
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
gint x, y, w, h;
|
2012-03-19 10:15:30 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (add_on_buffer));
|
2012-03-19 10:15:30 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
|
2012-03-19 10:15:30 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
if (! gimp_gegl_mask_combine_buffer (buffer, add_on_buffer,
|
|
|
|
op, off_x, off_y))
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-04-09 03:54:46 +08:00
|
|
|
gimp_rectangle_intersect (off_x, off_y,
|
|
|
|
gegl_buffer_get_width (add_on_buffer),
|
|
|
|
gegl_buffer_get_height (add_on_buffer),
|
|
|
|
0, 0,
|
|
|
|
gimp_item_get_width (GIMP_ITEM (mask)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (mask)),
|
|
|
|
&x, &y, &w, &h);
|
2001-01-29 10:45:02 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
mask->bounds_known = FALSE;
|
2003-10-06 20:17:11 +08:00
|
|
|
|
2005-09-07 18:08:02 +08:00
|
|
|
gimp_drawable_update (GIMP_DRAWABLE (mask), x, y, w, h);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|