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-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"
|
|
|
|
|
2003-09-04 20:18:40 +08:00
|
|
|
#include <glib-object.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-09-04 20:18:40 +08:00
|
|
|
#include "core-types.h"
|
2002-08-20 18:22:23 +08:00
|
|
|
|
2003-09-04 20:18:40 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
2002-08-30 00:48:17 +08:00
|
|
|
|
2003-09-04 20:18:40 +08:00
|
|
|
#include "base/pixel-processor.h"
|
|
|
|
#include "base/pixel-region.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-09-04 20:18:40 +08:00
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpchannel-combine.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-01-29 10:45:02 +08:00
|
|
|
gimp_channel_add_segment (GimpChannel *mask,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2001-12-03 21:44:59 +08:00
|
|
|
gint width,
|
|
|
|
gint value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-29 00:19:55 +08:00
|
|
|
PixelRegion maskPR;
|
|
|
|
guchar *data;
|
|
|
|
gint val;
|
|
|
|
gint x2;
|
|
|
|
gpointer pr;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* check horizontal extents... */
|
|
|
|
x2 = x + width;
|
2003-05-08 19:52:31 +08:00
|
|
|
x2 = CLAMP (x2, 0, GIMP_ITEM (mask)->width);
|
|
|
|
x = CLAMP (x, 0, GIMP_ITEM (mask)->width);
|
1997-11-25 06:05:25 +08:00
|
|
|
width = x2 - x;
|
2002-08-30 00:48:17 +08:00
|
|
|
if (!width)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
if (y < 0 || y > GIMP_ITEM (mask)->height)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles,
|
|
|
|
x, y, width, 1, TRUE);
|
2002-08-30 00:48:17 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
for (pr = pixel_regions_register (1, &maskPR);
|
|
|
|
pr != NULL;
|
|
|
|
pr = pixel_regions_process (pr))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
data = maskPR.data;
|
|
|
|
width = maskPR.w;
|
|
|
|
while (width--)
|
|
|
|
{
|
|
|
|
val = *data + value;
|
|
|
|
if (val > 255)
|
|
|
|
val = 255;
|
|
|
|
*data++ = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-01-29 10:45:02 +08:00
|
|
|
gimp_channel_sub_segment (GimpChannel *mask,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2001-12-03 21:44:59 +08:00
|
|
|
gint width,
|
|
|
|
gint value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-29 00:19:55 +08:00
|
|
|
PixelRegion maskPR;
|
|
|
|
guchar *data;
|
|
|
|
gint val;
|
|
|
|
gint x2;
|
|
|
|
gpointer pr;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* check horizontal extents... */
|
|
|
|
x2 = x + width;
|
2003-05-08 19:52:31 +08:00
|
|
|
x2 = CLAMP (x2, 0, GIMP_ITEM (mask)->width);
|
|
|
|
x = CLAMP (x, 0, GIMP_ITEM (mask)->width);
|
1997-11-25 06:05:25 +08:00
|
|
|
width = x2 - x;
|
2002-08-30 00:48:17 +08:00
|
|
|
|
|
|
|
if (! width)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
if (y < 0 || y > GIMP_ITEM (mask)->height)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
2002-08-30 00:48:17 +08:00
|
|
|
pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles,
|
|
|
|
x, y, width, 1, TRUE);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
for (pr = pixel_regions_register (1, &maskPR);
|
|
|
|
pr != NULL;
|
|
|
|
pr = pixel_regions_process (pr))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
data = maskPR.data;
|
|
|
|
width = maskPR.w;
|
|
|
|
while (width--)
|
|
|
|
{
|
|
|
|
val = *data - value;
|
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
|
|
|
*data++ = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_channel_combine_rect (GimpChannel *mask,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-29 00:19:55 +08:00
|
|
|
gint x2, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
PixelRegion maskPR;
|
2000-12-29 00:19:55 +08:00
|
|
|
guchar color;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
y2 = y + h;
|
|
|
|
x2 = x + w;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
x = CLAMP (x, 0, GIMP_ITEM (mask)->width);
|
|
|
|
y = CLAMP (y, 0, GIMP_ITEM (mask)->height);
|
|
|
|
x2 = CLAMP (x2, 0, GIMP_ITEM (mask)->width);
|
|
|
|
y2 = CLAMP (y2, 0, GIMP_ITEM (mask)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-06 20:17:11 +08:00
|
|
|
w = x2 - x;
|
|
|
|
h = y2 - y;
|
|
|
|
|
|
|
|
if (w <= 0 || h <= 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles,
|
2003-10-06 20:17:11 +08:00
|
|
|
x, y, w, h, TRUE);
|
2002-03-19 00:22:14 +08:00
|
|
|
|
|
|
|
if (op == GIMP_CHANNEL_OP_ADD || op == GIMP_CHANNEL_OP_REPLACE)
|
2002-08-30 00:48:17 +08:00
|
|
|
color = OPAQUE_OPACITY;
|
1999-04-09 14:00:11 +08:00
|
|
|
else
|
2002-08-30 00:48:17 +08:00
|
|
|
color = TRANSPARENT_OPACITY;
|
2002-03-19 00:22:14 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
color_region (&maskPR, &color);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Determine new boundary */
|
2002-03-19 00:22:14 +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)
|
|
|
|
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);
|
|
|
|
}
|
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
|
|
|
|
mask->bounds_known = FALSE;
|
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
mask->x1 = CLAMP (mask->x1, 0, GIMP_ITEM (mask)->width);
|
|
|
|
mask->y1 = CLAMP (mask->y1, 0, GIMP_ITEM (mask)->height);
|
|
|
|
mask->x2 = CLAMP (mask->x2, 0, GIMP_ITEM (mask)->width);
|
|
|
|
mask->y2 = CLAMP (mask->y2, 0, GIMP_ITEM (mask)->height);
|
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
|
|
|
{
|
2000-12-29 00:19:55 +08:00
|
|
|
gint i, j;
|
2004-07-19 03:31:29 +08:00
|
|
|
gfloat a, b;
|
1999-08-22 19:45:31 +08:00
|
|
|
gfloat a_sqr, b_sqr, aob_sqr;
|
|
|
|
gfloat cx, cy;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CHANNEL (mask));
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!w || !h)
|
|
|
|
return;
|
|
|
|
|
2004-07-19 22:25:59 +08:00
|
|
|
a = w / 2.0;
|
|
|
|
b = h / 2.0;
|
|
|
|
|
|
|
|
a_sqr = SQR (a);
|
|
|
|
b_sqr = SQR (b);
|
2004-07-19 22:12:30 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
aob_sqr = a_sqr / b_sqr;
|
|
|
|
|
2004-07-19 22:25:59 +08:00
|
|
|
cx = x + a;
|
|
|
|
cy = y + b;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = y; i < (y + h); i++)
|
|
|
|
{
|
2003-05-08 19:52:31 +08:00
|
|
|
if (i >= 0 && i < GIMP_ITEM (mask)->height)
|
2004-07-19 03:31:29 +08:00
|
|
|
{
|
|
|
|
if (!antialias)
|
|
|
|
{
|
2004-07-19 22:25:59 +08:00
|
|
|
gfloat y_sqr = (i + 0.5 - cy) * (i + 0.5 - cy);
|
|
|
|
gfloat rad = sqrt (a_sqr - a_sqr * y_sqr / (gdouble) b_sqr);
|
|
|
|
gint x1 = ROUND (cx - rad);
|
|
|
|
gint x2 = ROUND (cx + rad);
|
2004-07-19 03:31:29 +08:00
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case GIMP_CHANNEL_OP_ADD:
|
|
|
|
case GIMP_CHANNEL_OP_REPLACE:
|
|
|
|
gimp_channel_add_segment (mask, x1, i, (x2 - x1), 255);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CHANNEL_OP_SUBTRACT:
|
|
|
|
gimp_channel_sub_segment (mask, x1, i, (x2 - x1), 255);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-19 22:25:59 +08:00
|
|
|
g_return_if_reached ();
|
2004-07-19 03:31:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-07-19 22:25:59 +08:00
|
|
|
else /* antialiasing */
|
2004-07-19 03:31:29 +08:00
|
|
|
{
|
2004-07-19 20:43:40 +08:00
|
|
|
/* algorithm changed 7-18-04, because the previous one did not
|
2004-07-19 03:31:29 +08:00
|
|
|
* work well for eccentric ellipses. The new algorithm
|
|
|
|
* measures the distance to the ellipse in the X and Y directions,
|
|
|
|
* and uses trigonometry to approximate the distance to the
|
|
|
|
* ellipse as the distance to the hypotenuse of a right triangle
|
|
|
|
* whose legs are the X and Y distances. (WES)
|
2004-07-19 20:43:40 +08:00
|
|
|
*/
|
2004-07-19 22:25:59 +08:00
|
|
|
|
|
|
|
gint val, last;
|
|
|
|
gint x0;
|
|
|
|
gfloat xj, yi;
|
|
|
|
gfloat xdist, ydist;
|
|
|
|
gfloat r;
|
|
|
|
gfloat dist;
|
|
|
|
|
2004-07-19 03:31:29 +08:00
|
|
|
x0 = x;
|
|
|
|
yi = ABS (i + 0.5 - cy);
|
|
|
|
|
2004-07-19 22:25:59 +08:00
|
|
|
last = 0;
|
|
|
|
|
2004-07-19 03:31:29 +08:00
|
|
|
for (j = x; j < (x + w); j++)
|
|
|
|
{
|
|
|
|
xj = ABS (j + 0.5 - cx);
|
|
|
|
|
|
|
|
if (yi < b)
|
|
|
|
xdist = xj - a * sqrt (1 - yi * yi / b_sqr);
|
|
|
|
else
|
2004-07-19 22:25:59 +08:00
|
|
|
xdist = 100.0; /* anything large will work */
|
2004-07-19 03:31:29 +08:00
|
|
|
|
|
|
|
if (xj < a)
|
|
|
|
ydist = yi - b * sqrt (1 - xj * xj / a_sqr);
|
|
|
|
else
|
2004-07-19 22:25:59 +08:00
|
|
|
ydist = 100.0; /* anything large will work */
|
|
|
|
|
2004-07-19 03:31:29 +08:00
|
|
|
r = hypot (xdist, ydist);
|
|
|
|
if (r < 0.001)
|
|
|
|
dist = 0.;
|
|
|
|
else
|
2004-07-19 22:25:59 +08:00
|
|
|
dist = xdist * ydist / r; /* trig formula for distance
|
|
|
|
* to hypotenuse
|
|
|
|
*/
|
2004-07-19 03:31:29 +08:00
|
|
|
|
2004-07-19 22:25:59 +08:00
|
|
|
if (xdist < 0.0)
|
2004-07-19 03:31:29 +08:00
|
|
|
dist *= -1;
|
|
|
|
|
|
|
|
if (dist < -0.5)
|
|
|
|
val = 255;
|
|
|
|
else if (dist < 0.5)
|
2004-07-19 22:25:59 +08:00
|
|
|
val = (gint) (255 * (1 - (dist + 0.5)));
|
2004-07-19 03:31:29 +08:00
|
|
|
else
|
|
|
|
val = 0;
|
|
|
|
|
|
|
|
if (last != val && last)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case GIMP_CHANNEL_OP_ADD:
|
|
|
|
case GIMP_CHANNEL_OP_REPLACE:
|
|
|
|
gimp_channel_add_segment (mask, x0, i, j - x0, last);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CHANNEL_OP_SUBTRACT:
|
|
|
|
gimp_channel_sub_segment (mask, x0, i, j - x0, last);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-07-19 22:25:59 +08:00
|
|
|
g_return_if_reached ();
|
2004-07-19 03:31:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last != val)
|
|
|
|
{
|
|
|
|
x0 = j;
|
|
|
|
last = val;
|
2004-07-19 22:25:59 +08:00
|
|
|
|
|
|
|
/* because we are symetric accross the y axis we can
|
|
|
|
* skip ahead a bit if we are inside the ellipse
|
|
|
|
*/
|
2004-07-19 03:31:29 +08:00
|
|
|
if (val == 255 && j < cx)
|
|
|
|
j = cx + (cx - j) - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
{
|
2002-03-19 00:22:14 +08:00
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case GIMP_CHANNEL_OP_ADD:
|
|
|
|
case GIMP_CHANNEL_OP_REPLACE:
|
|
|
|
gimp_channel_add_segment (mask, x0, i, j - x0, last);
|
|
|
|
break;
|
2002-08-30 00:48:17 +08:00
|
|
|
|
2002-03-19 00:22:14 +08:00
|
|
|
case GIMP_CHANNEL_OP_SUBTRACT:
|
|
|
|
gimp_channel_sub_segment (mask, x0, i, j - x0, last);
|
|
|
|
break;
|
2002-08-30 00:48:17 +08:00
|
|
|
|
2002-03-19 00:22:14 +08:00
|
|
|
default:
|
2004-07-19 22:25:59 +08:00
|
|
|
g_return_if_reached ();
|
2002-03-19 00:22:14 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-07-19 03:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-19 22:25:59 +08:00
|
|
|
/* determine new boundary */
|
2002-03-19 00:22:14 +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)
|
|
|
|
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);
|
|
|
|
}
|
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-05-08 19:52:31 +08:00
|
|
|
mask->x1 = CLAMP (mask->x1, 0, GIMP_ITEM (mask)->width);
|
|
|
|
mask->y1 = CLAMP (mask->y1, 0, GIMP_ITEM (mask)->height);
|
|
|
|
mask->x2 = CLAMP (mask->x2, 0, GIMP_ITEM (mask)->width);
|
|
|
|
mask->y2 = CLAMP (mask->y2, 0, GIMP_ITEM (mask)->height);
|
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
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_channel_combine_sub_region_add (gpointer unused,
|
2001-01-29 10:45:02 +08:00
|
|
|
PixelRegion *srcPR,
|
|
|
|
PixelRegion *destPR)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
guchar *src, *dest;
|
2000-12-29 00:19:55 +08:00
|
|
|
gint x, y, val;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
src = srcPR->data;
|
1999-04-09 14:00:11 +08:00
|
|
|
dest = destPR->data;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
for (y = 0; y < srcPR->h; y++)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
for (x = 0; x < srcPR->w; x++)
|
|
|
|
{
|
|
|
|
val = dest[x] + src[x];
|
|
|
|
if (val > 255)
|
|
|
|
dest[x] = 255;
|
|
|
|
else
|
|
|
|
dest[x] = val;
|
|
|
|
}
|
|
|
|
src += srcPR->rowstride;
|
|
|
|
dest += destPR->rowstride;
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_channel_combine_sub_region_sub (gpointer unused,
|
2001-01-29 10:45:02 +08:00
|
|
|
PixelRegion *srcPR,
|
|
|
|
PixelRegion *destPR)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
guchar *src, *dest;
|
2000-12-29 00:19:55 +08:00
|
|
|
gint x, y;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
src = srcPR->data;
|
1999-04-09 14:00:11 +08:00
|
|
|
dest = destPR->data;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
for (y = 0; y < srcPR->h; y++)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
for (x = 0; x < srcPR->w; x++)
|
|
|
|
{
|
|
|
|
if (src[x] > dest[x])
|
|
|
|
dest[x] = 0;
|
|
|
|
else
|
|
|
|
dest[x]-= src[x];
|
|
|
|
}
|
|
|
|
src += srcPR->rowstride;
|
|
|
|
dest += destPR->rowstride;
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_channel_combine_sub_region_intersect (gpointer unused,
|
2001-01-29 10:45:02 +08:00
|
|
|
PixelRegion *srcPR,
|
|
|
|
PixelRegion *destPR)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
guchar *src, *dest;
|
2000-12-29 00:19:55 +08:00
|
|
|
gint x, y;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
src = srcPR->data;
|
1999-04-09 14:00:11 +08:00
|
|
|
dest = destPR->data;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
for (y = 0; y < srcPR->h; y++)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
for (x = 0; x < srcPR->w; x++)
|
|
|
|
{
|
2000-01-26 07:06:12 +08:00
|
|
|
dest[x] = MIN (dest[x], src[x]);
|
1999-08-22 19:45:31 +08:00
|
|
|
}
|
2003-09-04 20:18:40 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
src += srcPR->rowstride;
|
|
|
|
dest += destPR->rowstride;
|
2003-09-04 20:18:40 +08:00
|
|
|
}
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2002-03-19 00:22:14 +08:00
|
|
|
gimp_channel_combine_mask (GimpChannel *mask,
|
|
|
|
GimpChannel *add_on,
|
|
|
|
GimpChannelOps op,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PixelRegion srcPR, destPR;
|
2000-12-29 00:19:55 +08:00
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint w, h;
|
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));
|
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
x1 = CLAMP (off_x, 0, GIMP_ITEM (mask)->width);
|
|
|
|
y1 = CLAMP (off_y, 0, GIMP_ITEM (mask)->height);
|
|
|
|
x2 = CLAMP (off_x + GIMP_ITEM (add_on)->width, 0,
|
|
|
|
GIMP_ITEM (mask)->width);
|
|
|
|
y2 = CLAMP (off_y + GIMP_ITEM (add_on)->height, 0,
|
|
|
|
GIMP_ITEM (mask)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
w = (x2 - x1);
|
|
|
|
h = (y2 - y1);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (add_on)->tiles,
|
|
|
|
(x1 - off_x), (y1 - off_y), w, h, FALSE);
|
2002-08-30 00:48:17 +08:00
|
|
|
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
|
|
|
|
x1, y1, w, h, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
switch (op)
|
1999-08-22 19:45:31 +08:00
|
|
|
{
|
2002-03-19 00:22:14 +08:00
|
|
|
case GIMP_CHANNEL_OP_ADD:
|
|
|
|
case GIMP_CHANNEL_OP_REPLACE:
|
2001-01-29 10:45:02 +08:00
|
|
|
pixel_regions_process_parallel ((p_func)
|
|
|
|
gimp_channel_combine_sub_region_add,
|
1999-08-22 19:45:31 +08:00
|
|
|
NULL, 2, &srcPR, &destPR);
|
|
|
|
break;
|
2002-08-30 00:48:17 +08:00
|
|
|
|
2002-03-19 00:22:14 +08:00
|
|
|
case GIMP_CHANNEL_OP_SUBTRACT:
|
2001-01-29 10:45:02 +08:00
|
|
|
pixel_regions_process_parallel ((p_func)
|
|
|
|
gimp_channel_combine_sub_region_sub,
|
1999-08-22 19:45:31 +08:00
|
|
|
NULL, 2, &srcPR, &destPR);
|
|
|
|
break;
|
2002-08-30 00:48:17 +08:00
|
|
|
|
2002-03-19 00:22:14 +08:00
|
|
|
case GIMP_CHANNEL_OP_INTERSECT:
|
1999-08-22 19:45:31 +08:00
|
|
|
pixel_regions_process_parallel ((p_func)
|
2001-01-29 10:45:02 +08:00
|
|
|
gimp_channel_combine_sub_region_intersect,
|
1999-08-22 19:45:31 +08:00
|
|
|
NULL, 2, &srcPR, &destPR);
|
|
|
|
break;
|
2002-08-30 00:48:17 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: unknown operation type", G_STRFUNC);
|
1999-08-22 19:45:31 +08:00
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
gimp_drawable_update (GIMP_DRAWABLE (mask), x1, y2, w, h);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|