app/core/Makefile.am new files split out of gimpchannel.[ch].

2003-09-04  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/gimpchannel-combine.[ch]: new files split out of
	gimpchannel.[ch].

	* app/core/gimpchannel.[ch]: removed the combine functions here.

	* app/core/gimpdrawable-bucket-fill.c
	* app/core/gimpimage-mask-select.c
	* tools/pdbgen/pdb/channel.pdb: changed #includes accordingly.

	* app/pdb/channel_cmds.c: regenerated.
This commit is contained in:
Michael Natterer 2003-09-04 12:18:40 +00:00 committed by Michael Natterer
parent 0186c13e6c
commit 3911d511cf
11 changed files with 60 additions and 2369 deletions

View File

@ -1,3 +1,17 @@
2003-09-04 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/gimpchannel-combine.[ch]: new files split out of
gimpchannel.[ch].
* app/core/gimpchannel.[ch]: removed the combine functions here.
* app/core/gimpdrawable-bucket-fill.c
* app/core/gimpimage-mask-select.c
* tools/pdbgen/pdb/channel.pdb: changed #includes accordingly.
* app/pdb/channel_cmds.c: regenerated.
2003-09-04 Sven Neumann <sven@gimp.org>
* app/core/gimpcontainer.[ch]: added new function

View File

@ -43,6 +43,8 @@ libappcore_a_sources = \
gimpbuffer.h \
gimpchannel.c \
gimpchannel.h \
gimpchannel-combine.c \
gimpchannel-combine.h \
gimpcontainer.c \
gimpcontainer.h \
gimpcontext.c \

File diff suppressed because it is too large Load Diff

View File

@ -16,231 +16,38 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_CHANNEL_H__
#define __GIMP_CHANNEL_H__
#include "gimpdrawable.h"
#ifndef __GIMP_CHANNEL_COMBINE_H__
#define __GIMP_CHANNEL_COMBINE_H__
/* Half way point where a region is no longer visible in a selection */
#define HALF_WAY 127
void gimp_channel_add_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value);
void gimp_channel_sub_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value);
void gimp_channel_combine_rect (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h);
void gimp_channel_combine_ellipse (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h,
gboolean antialias);
void gimp_channel_combine_mask (GimpChannel *mask,
GimpChannel *add_on,
GimpChannelOps op,
gint off_x,
gint off_y);
#define GIMP_TYPE_CHANNEL (gimp_channel_get_type ())
#define GIMP_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CHANNEL, GimpChannel))
#define GIMP_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CHANNEL, GimpChannelClass))
#define GIMP_IS_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CHANNEL))
#define GIMP_IS_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CHANNEL))
#define GIMP_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CHANNEL, GimpChannelClass))
typedef struct _GimpChannelClass GimpChannelClass;
struct _GimpChannel
{
GimpDrawable parent_instance;
GimpRGB color; /* Also stored the opacity */
gboolean show_masked; /* Show masked areas--as */
/* opposed to selected areas */
/* Selection mask variables */
gboolean boundary_known; /* is the current boundary valid */
BoundSeg *segs_in; /* outline of selected region */
BoundSeg *segs_out; /* outline of selected region */
gint num_segs_in; /* number of lines in boundary */
gint num_segs_out; /* number of lines in boundary */
gboolean empty; /* is the region empty? */
gboolean bounds_known; /* recalculate the bounds? */
gint x1, y1; /* coordinates for bounding box */
gint x2, y2; /* lower right hand coordinate */
};
struct _GimpChannelClass
{
GimpDrawableClass parent_class;
gboolean (* boundary) (GimpChannel *channel,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2);
gboolean (* bounds) (GimpChannel *channel,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
gint (* value) (GimpChannel *channel,
gint x,
gint y);
gboolean (* is_empty) (GimpChannel *channel);
void (* feather) (GimpChannel *channel,
gdouble radius_x,
gdouble radius_y,
gboolean push_undo);
void (* sharpen) (GimpChannel *channel,
gboolean push_undo);
void (* clear) (GimpChannel *channel,
const gchar *undo_desc,
gboolean push_undo);
void (* all) (GimpChannel *channel,
gboolean push_undo);
void (* invert) (GimpChannel *channel,
gboolean push_undo);
void (* border) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean push_undo);
void (* grow) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean push_undo);
void (* shrink) (GimpChannel *channel,
gint radius_x,
gint radius_y,
gboolean edge_lock,
gboolean push_undo);
const gchar *translate_desc;
const gchar *feather_desc;
const gchar *sharpen_desc;
const gchar *clear_desc;
const gchar *all_desc;
const gchar *invert_desc;
const gchar *border_desc;
const gchar *grow_desc;
const gchar *shrink_desc;
};
/* function declarations */
GType gimp_channel_get_type (void) G_GNUC_CONST;
GimpChannel * gimp_channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
const GimpRGB *color);
GimpChannel * gimp_channel_new_from_alpha (GimpImage *gimage,
GimpLayer *layer,
const gchar *name,
const GimpRGB *color);
GimpChannel * gimp_channel_new_from_component (GimpImage *gimage,
GimpChannelType type,
const gchar *name,
const GimpRGB *color);
gdouble gimp_channel_get_opacity (const GimpChannel *channel);
void gimp_channel_set_opacity (GimpChannel *channel,
gdouble opacity,
gboolean push_undo);
void gimp_channel_get_color (const GimpChannel *channel,
GimpRGB *color);
void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color,
gboolean push_undo);
gboolean gimp_channel_get_show_masked (GimpChannel *channel);
void gimp_channel_set_show_masked (GimpChannel *channel,
gboolean show_masked);
void gimp_channel_push_undo (GimpChannel *mask,
const gchar *undo_desc);
/* selection mask functions */
GimpChannel * gimp_channel_new_mask (GimpImage *gimage,
gint width,
gint height);
gboolean gimp_channel_boundary (GimpChannel *mask,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2);
gboolean gimp_channel_bounds (GimpChannel *mask,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
gint gimp_channel_value (GimpChannel *mask,
gint x,
gint y);
gboolean gimp_channel_is_empty (GimpChannel *mask);
void gimp_channel_add_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value);
void gimp_channel_sub_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value);
void gimp_channel_combine_rect (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h);
void gimp_channel_combine_ellipse (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h,
gboolean antialias);
void gimp_channel_combine_mask (GimpChannel *mask,
GimpChannel *add_on,
GimpChannelOps op,
gint off_x,
gint off_y);
void gimp_channel_feather (GimpChannel *mask,
gdouble radius_x,
gdouble radius_y,
gboolean push_undo);
void gimp_channel_sharpen (GimpChannel *mask,
gboolean push_undo);
void gimp_channel_clear (GimpChannel *mask,
const gchar *undo_desc,
gboolean push_undo);
void gimp_channel_all (GimpChannel *mask,
gboolean push_undo);
void gimp_channel_invert (GimpChannel *mask,
gboolean push_undo);
void gimp_channel_border (GimpChannel *mask,
gint radius_x,
gint radius_y,
gboolean push_undo);
void gimp_channel_grow (GimpChannel *mask,
gint radius_x,
gint radius_y,
gboolean push_undo);
void gimp_channel_shrink (GimpChannel *mask,
gint radius_x,
gint radius_y,
gboolean edge_lock,
gboolean push_undo);
void gimp_channel_load (GimpChannel *mask,
GimpChannel *channel,
gboolean push_undo);
#endif /* __GIMP_CHANNEL_H__ */
#endif /* __GIMP_CHANNEL_COMBINE_H__ */

View File

@ -25,6 +25,7 @@
#include "core-types.h"
#include "gimpchannel.h"
#include "gimpchannel-combine.h"
#include "gimpimage.h"
#include "gimpimage-contiguous-region.h"
#include "gimpimage-mask-select.h"

View File

@ -1570,463 +1570,6 @@ gimp_channel_is_empty (GimpChannel *channel)
return GIMP_CHANNEL_GET_CLASS (channel)->is_empty (channel);
}
void
gimp_channel_add_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value)
{
PixelRegion maskPR;
guchar *data;
gint val;
gint x2;
gpointer pr;
g_return_if_fail (GIMP_IS_CHANNEL (mask));
/* check horizontal extents... */
x2 = x + width;
x2 = CLAMP (x2, 0, GIMP_ITEM (mask)->width);
x = CLAMP (x, 0, GIMP_ITEM (mask)->width);
width = x2 - x;
if (!width)
return;
if (y < 0 || y > GIMP_ITEM (mask)->height)
return;
pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles,
x, y, width, 1, TRUE);
for (pr = pixel_regions_register (1, &maskPR);
pr != NULL;
pr = pixel_regions_process (pr))
{
data = maskPR.data;
width = maskPR.w;
while (width--)
{
val = *data + value;
if (val > 255)
val = 255;
*data++ = val;
}
}
}
void
gimp_channel_sub_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value)
{
PixelRegion maskPR;
guchar *data;
gint val;
gint x2;
gpointer pr;
g_return_if_fail (GIMP_IS_CHANNEL (mask));
/* check horizontal extents... */
x2 = x + width;
x2 = CLAMP (x2, 0, GIMP_ITEM (mask)->width);
x = CLAMP (x, 0, GIMP_ITEM (mask)->width);
width = x2 - x;
if (! width)
return;
if (y < 0 || y > GIMP_ITEM (mask)->height)
return;
pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles,
x, y, width, 1, TRUE);
for (pr = pixel_regions_register (1, &maskPR);
pr != NULL;
pr = pixel_regions_process (pr))
{
data = maskPR.data;
width = maskPR.w;
while (width--)
{
val = *data - value;
if (val < 0)
val = 0;
*data++ = val;
}
}
}
void
gimp_channel_combine_rect (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h)
{
gint x2, y2;
PixelRegion maskPR;
guchar color;
g_return_if_fail (GIMP_IS_CHANNEL (mask));
y2 = y + h;
x2 = x + w;
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);
if (x2 - x <= 0 || y2 - y <= 0)
return;
pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles,
x, y, x2 - x, y2 - y, TRUE);
if (op == GIMP_CHANNEL_OP_ADD || op == GIMP_CHANNEL_OP_REPLACE)
color = OPAQUE_OPACITY;
else
color = TRANSPARENT_OPACITY;
color_region (&maskPR, &color);
/* Determine new boundary */
if (mask->bounds_known && (op == GIMP_CHANNEL_OP_ADD) && !mask->empty)
{
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);
}
else if (op == GIMP_CHANNEL_OP_REPLACE || mask->empty)
{
mask->empty = FALSE;
mask->x1 = x;
mask->y1 = y;
mask->x2 = x + w;
mask->y2 = y + h;
}
else
mask->bounds_known = FALSE;
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);
}
void
gimp_channel_combine_ellipse (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h,
gboolean antialias)
{
gint i, j;
gint x0, x1, x2;
gint val, last;
gfloat a_sqr, b_sqr, aob_sqr;
gfloat w_sqr, h_sqr;
gfloat y_sqr;
gfloat t0, t1;
gfloat r;
gfloat cx, cy;
gfloat rad;
gfloat dist;
g_return_if_fail (GIMP_IS_CHANNEL (mask));
if (!w || !h)
return;
a_sqr = (w * w / 4.0);
b_sqr = (h * h / 4.0);
aob_sqr = a_sqr / b_sqr;
cx = x + w / 2.0;
cy = y + h / 2.0;
for (i = y; i < (y + h); i++)
{
if (i >= 0 && i < GIMP_ITEM (mask)->height)
{
/* Non-antialiased code */
if (!antialias)
{
y_sqr = (i + 0.5 - cy) * (i + 0.5 - cy);
rad = sqrt (a_sqr - a_sqr * y_sqr / (double) b_sqr);
x1 = ROUND (cx - rad);
x2 = ROUND (cx + rad);
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:
g_warning ("Only ADD, REPLACE, and SUBTRACT are valid for channel_combine!");
break;
}
}
/* antialiasing */
else
{
x0 = x;
last = 0;
h_sqr = (i + 0.5 - cy) * (i + 0.5 - cy);
for (j = x; j < (x + w); j++)
{
w_sqr = (j + 0.5 - cx) * (j + 0.5 - cx);
if (h_sqr != 0)
{
t0 = w_sqr / h_sqr;
t1 = a_sqr / (t0 + aob_sqr);
r = sqrt (t1 + t0 * t1);
rad = sqrt (w_sqr + h_sqr);
dist = rad - r;
}
else
dist = -1.0;
if (dist < -0.5)
val = 255;
else if (dist < 0.5)
val = (int) (255 * (1 - (dist + 0.5)));
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:
g_warning ("Only ADD, REPLACE, and SUBTRACT are valid for channel_combine!");
break;
}
}
if (last != val)
{
x0 = j;
last = val;
/* because we are symetric accross the y axis we can
skip ahead a bit if we are inside the ellipse*/
if (val == 255 && j < cx)
j = cx + (cx - j) - 1;
}
}
if (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:
g_warning ("Only ADD, REPLACE, and SUBTRACT are valid for channel_combine!");
break;
}
}
}
}
}
/* Determine new boundary */
if (mask->bounds_known && (op == GIMP_CHANNEL_OP_ADD) && !mask->empty)
{
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);
}
else if (op == GIMP_CHANNEL_OP_REPLACE || mask->empty)
{
mask->empty = FALSE;
mask->x1 = x;
mask->y1 = y;
mask->x2 = x + w;
mask->y2 = y + h;
}
else
mask->bounds_known = FALSE;
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);
}
static void
gimp_channel_combine_sub_region_add (gpointer unused,
PixelRegion *srcPR,
PixelRegion *destPR)
{
guchar *src, *dest;
gint x, y, val;
src = srcPR->data;
dest = destPR->data;
for (y = 0; y < srcPR->h; y++)
{
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;
}
}
static void
gimp_channel_combine_sub_region_sub (gpointer unused,
PixelRegion *srcPR,
PixelRegion *destPR)
{
guchar *src, *dest;
gint x, y;
src = srcPR->data;
dest = destPR->data;
for (y = 0; y < srcPR->h; y++)
{
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;
}
}
static void
gimp_channel_combine_sub_region_intersect (gpointer unused,
PixelRegion *srcPR,
PixelRegion *destPR)
{
guchar *src, *dest;
gint x, y;
src = srcPR->data;
dest = destPR->data;
for (y = 0; y < srcPR->h; y++)
{
for (x = 0; x < srcPR->w; x++)
{
dest[x] = MIN (dest[x], src[x]);
}
src += srcPR->rowstride;
dest += destPR->rowstride;
}
}
void
gimp_channel_combine_mask (GimpChannel *mask,
GimpChannel *add_on,
GimpChannelOps op,
gint off_x,
gint off_y)
{
PixelRegion srcPR, destPR;
gint x1, y1, x2, y2;
gint w, h;
g_return_if_fail (GIMP_IS_CHANNEL (mask));
g_return_if_fail (GIMP_IS_CHANNEL (add_on));
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);
w = (x2 - x1);
h = (y2 - y1);
pixel_region_init (&srcPR, GIMP_DRAWABLE (add_on)->tiles,
(x1 - off_x), (y1 - off_y), w, h, FALSE);
pixel_region_init (&destPR, GIMP_DRAWABLE (mask)->tiles,
x1, y1, w, h, TRUE);
switch (op)
{
case GIMP_CHANNEL_OP_ADD:
case GIMP_CHANNEL_OP_REPLACE:
pixel_regions_process_parallel ((p_func)
gimp_channel_combine_sub_region_add,
NULL, 2, &srcPR, &destPR);
break;
case GIMP_CHANNEL_OP_SUBTRACT:
pixel_regions_process_parallel ((p_func)
gimp_channel_combine_sub_region_sub,
NULL, 2, &srcPR, &destPR);
break;
case GIMP_CHANNEL_OP_INTERSECT:
pixel_regions_process_parallel ((p_func)
gimp_channel_combine_sub_region_intersect,
NULL, 2, &srcPR, &destPR);
break;
default:
g_warning ("%s: unknown operation type\n", G_GNUC_PRETTY_FUNCTION);
break;
}
mask->bounds_known = FALSE;
}
void
gimp_channel_feather (GimpChannel *channel,
gdouble radius_x,

View File

@ -180,35 +180,6 @@ gint gimp_channel_value (GimpChannel *mask,
gint y);
gboolean gimp_channel_is_empty (GimpChannel *mask);
void gimp_channel_add_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value);
void gimp_channel_sub_segment (GimpChannel *mask,
gint x,
gint y,
gint width,
gint value);
void gimp_channel_combine_rect (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h);
void gimp_channel_combine_ellipse (GimpChannel *mask,
GimpChannelOps op,
gint x,
gint y,
gint w,
gint h,
gboolean antialias);
void gimp_channel_combine_mask (GimpChannel *mask,
GimpChannel *add_on,
GimpChannelOps op,
gint off_x,
gint off_y);
void gimp_channel_feather (GimpChannel *mask,
gdouble radius_x,
gdouble radius_y,

View File

@ -32,6 +32,7 @@
#include "gimp.h"
#include "gimpchannel.h"
#include "gimpchannel-combine.h"
#include "gimpcontext.h"
#include "gimpdrawable.h"
#include "gimpdrawable-bucket-fill.h"

View File

@ -25,6 +25,7 @@
#include "core-types.h"
#include "gimpchannel.h"
#include "gimpchannel-combine.h"
#include "gimpimage.h"
#include "gimpimage-contiguous-region.h"
#include "gimpimage-mask-select.h"

View File

@ -28,6 +28,7 @@
#include "pdb-types.h"
#include "procedural_db.h"
#include "core/gimpchannel-combine.h"
#include "core/gimpchannel.h"
#include "core/gimpimage.h"

View File

@ -251,11 +251,14 @@ HELP
channels: (second - first)" }
}
%invoke = ( code => <<'CODE' );
%invoke = (
headers => [ qw("core/gimpchannel-combine.h") ],
code => <<'CODE'
{
gimp_channel_combine_mask (channel1, channel2, operation, offx, offy);
}
CODE
);
}
&channel_accessors('name', 'string', 'name', 0, [ undef, <<'CODE' ],