gimp/app/base/boundary.c

559 lines
13 KiB
C
Raw Normal View History

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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1997-11-25 06:05:25 +08:00
*/
#include "config.h"
1997-11-25 06:05:25 +08:00
#include <string.h>
#include <glib.h>
#include "apptypes.h"
1997-11-25 06:05:25 +08:00
#include "appenv.h"
#include "errors.h"
#include "boundary.h"
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
#include "pixel_region.h"
new ui for the "Layer Offset" dialog. 1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de> * app/channel_ops.[ch]: new ui for the "Layer Offset" dialog. * app/channels_dialog.c * app/layers_dialog.c: major code cleanup: Folded some callbacks into common ones, "widget" instead of "w", indentation, ... * app/commands.c * app/interface.[ch] * app/global_edit.c: the query boxes must be shown by the caller now. There's no need to split up the string for the message box manually as the Gtk 1.2 label widget handles newlines corectly. Added the "edge_lock" toggle to the "Shrink Selection" dialog. Nicer spacings for the query and message boxes. * app/ink.c: tried to grab the pointer in the blob preview but failed. Left the code there as a reminder (commented out). * app/menus.c: reordered <Image>/Select. I was bored and grep-ed the sources for ancient or deprecated stuff: * app/about_dialog.[ch] * app/actionarea.[ch] * app/app_procs.c * app/brush_edit.c * app/brush_select.c * app/color_select.c * app/convert.c * app/devices.c * app/gdisplay.c * app/gdisplay_ops.c * app/histogram_tool.[ch] * app/info_window.c * app/install.c * app/ops_buttons.c * app/palette.c * app/palette_select.c * app/paths_dialog.c * app/pattern_select.c * app/resize.c * app/scale_toolc.c * app/text_tool.c: s/container_border_width/container_set_border_width/g, s/sprintf/g_snprintf/g, replaced some constant string lengths with strlen(x). * app/bezier_select.c * app/blend.c * app/boundary.c * app/errors.[ch] * app/free_select.c * app/gimpbrushlist.c * app/gimprc.c * app/iscissors.c * app/main.c * app/patterns.[ch] * app/text_tool.c: namespace fanaticism: prefixed all gimp error functions with "gimp_" and formated the messages more uniformly. * app/gradient.c * app/gradient_select.c: same stuff as above for the ui code. There are still some sub-dialogs which need cleanup. Did some cleanup in most of these files: prototypes, removed tons of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
#include "tile.h"
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
#include "tile_manager.h"
1997-11-25 06:05:25 +08:00
/* half intensity for mask */
#define HALF_WAY 127
/* BoundSeg array growth parameter */
#define MAX_SEGS_INC 2048
1997-11-25 06:05:25 +08:00
/* The array of vertical segments */
static gint *vert_segs = NULL;
1997-11-25 06:05:25 +08:00
/* The array of segments */
static BoundSeg *tmp_segs = NULL;
static gint num_segs = 0;
static gint max_segs = 0;
1997-11-25 06:05:25 +08:00
/* static empty segment arrays */
static gint *empty_segs_n = NULL;
static gint num_empty_n = 0;
static gint *empty_segs_c = NULL;
static gint num_empty_c = 0;
static gint *empty_segs_l = NULL;
static gint num_empty_l = 0;
static gint max_empty_segs = 0;
1997-11-25 06:05:25 +08:00
/* global state variables--improve parameter efficiency */
static PixelRegion *cur_PR = NULL;
1997-11-25 06:05:25 +08:00
/* local function prototypes */
static void find_empty_segs (PixelRegion *maskPR,
gint scanline,
gint empty_segs[],
gint max_empty,
gint *num_empty,
BoundaryType type,
gint x1,
gint y1,
gint x2,
gint y2);
static void make_seg (gint x1,
gint y1,
gint x2,
gint y2,
gboolean open);
static void allocate_vert_segs (void);
1997-11-25 06:05:25 +08:00
static void allocate_empty_segs (void);
static void process_horiz_seg (gint x1,
gint y1,
gint x2,
gint y2,
gboolean open);
static void make_horiz_segs (gint start,
gint end,
gint scanline,
gint empty[],
gint num_empty,
gint top);
static void generate_boundary (BoundaryType type,
gint x1,
gint y1,
gint x2,
gint y2);
1997-11-25 06:05:25 +08:00
/* Function definitions */
static void
find_empty_segs (PixelRegion *maskPR,
gint scanline,
gint empty_segs[],
gint max_empty,
gint *num_empty,
1997-11-25 06:05:25 +08:00
BoundaryType type,
gint x1,
gint y1,
gint x2,
gint y2)
1997-11-25 06:05:25 +08:00
{
unsigned char *data;
int x;
int start, end;
int val, last;
int tilex;
Tile *tile = NULL;
int endx, l_num_empty, dstep = 0;
build color_cmds, lut_funcs, and pixel_processor feedback in the splash * app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor * app/app_procs.c: feedback in the splash screen when loading parasites. * app/boundary.c: Optimized find_empty_segs. * app/brightness_contrast.[ch] * app/levels.[ch] * app/posterize.[ch]: moved pdb and lut calculation code. These files now contain only GUI functions. * app/channel.c: Optimized channel_bounds (fewer compares, better use of registers). Use color_region instead of channel_*_segment in channel_combine_rect. Optimized channel_combine_ellipse by skipping pixels inside of the ellipse. Use pixel_region_process_parallel in channel_combine_mask. Use a GimpLut in channel_invert, and channel_sharpen. * app/invert.c * app/equalize.c: moved the lut functions to lut_funcs.c * app/gimpdrawable.c, app/gimpdrawableP.h * app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix variables/includes. * app/gimplut.[ch]: added new function gimp_lut_process_inline that operates on a single PixelRegion. * app/gimpparasite.[ch]: new functions to save/load parasiterc * app/parasitelist.[ch]: new functions to save/load ParasiteLists in/from files. * libgimp/parasite.[ch]: new functions to load/save parasites. * app/internal_procs.c: get some procs from new location in color_cmds.h. * app/pixel_region.[ch]: moved pixel_regions_process_parallel related functions to a new file. * app/color_cmds.[ch]: new files for PDB definitions/implementations of color correction functions. * app/lut_funcs.[ch]: new files to hold lut creation functions. * app/pixel_processor.[ch]: new files that contain the pixel_regions_process_parallel routines. Added some new capabilities that are currently unused.
1999-04-09 14:00:11 +08:00
1997-11-25 06:05:25 +08:00
data = NULL;
start = 0;
end = 0;
*num_empty = 0;
if (scanline < maskPR->y || scanline >= (maskPR->y + maskPR->h))
{
empty_segs[(*num_empty)++] = 0;
empty_segs[(*num_empty)++] = G_MAXINT;
return;
}
if (type == WithinBounds)
{
if (scanline < y1 || scanline >= y2)
{
empty_segs[(*num_empty)++] = 0;
empty_segs[(*num_empty)++] = G_MAXINT;
return;
}
start = x1;
end = x2;
}
else if (type == IgnoreBounds)
{
start = maskPR->x;
end = maskPR->x + maskPR->w;
if (scanline < y1 || scanline >= y2)
x2 = -1;
}
tilex = -1;
empty_segs[(*num_empty)++] = 0;
last = -1;
build color_cmds, lut_funcs, and pixel_processor feedback in the splash * app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor * app/app_procs.c: feedback in the splash screen when loading parasites. * app/boundary.c: Optimized find_empty_segs. * app/brightness_contrast.[ch] * app/levels.[ch] * app/posterize.[ch]: moved pdb and lut calculation code. These files now contain only GUI functions. * app/channel.c: Optimized channel_bounds (fewer compares, better use of registers). Use color_region instead of channel_*_segment in channel_combine_rect. Optimized channel_combine_ellipse by skipping pixels inside of the ellipse. Use pixel_region_process_parallel in channel_combine_mask. Use a GimpLut in channel_invert, and channel_sharpen. * app/invert.c * app/equalize.c: moved the lut functions to lut_funcs.c * app/gimpdrawable.c, app/gimpdrawableP.h * app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix variables/includes. * app/gimplut.[ch]: added new function gimp_lut_process_inline that operates on a single PixelRegion. * app/gimpparasite.[ch]: new functions to save/load parasiterc * app/parasitelist.[ch]: new functions to save/load ParasiteLists in/from files. * libgimp/parasite.[ch]: new functions to load/save parasites. * app/internal_procs.c: get some procs from new location in color_cmds.h. * app/pixel_region.[ch]: moved pixel_regions_process_parallel related functions to a new file. * app/color_cmds.[ch]: new files for PDB definitions/implementations of color correction functions. * app/lut_funcs.[ch]: new files to hold lut creation functions. * app/pixel_processor.[ch]: new files that contain the pixel_regions_process_parallel routines. Added some new capabilities that are currently unused.
1999-04-09 14:00:11 +08:00
l_num_empty = *num_empty;
for (x = start; x < end;)
1997-11-25 06:05:25 +08:00
{
/* Check to see if we must advance to next tile */
if ((x / TILE_WIDTH) != tilex)
{
if (tile)
tile_release (tile, FALSE);
tile = tile_manager_get_tile (maskPR->tiles, x, scanline, TRUE, FALSE);
data = (guchar *) tile_data_pointer (tile,
x % TILE_WIDTH,
scanline % TILE_HEIGHT) + (tile_bpp(tile) - 1);
1998-08-12 01:35:34 +08:00
1997-11-25 06:05:25 +08:00
tilex = x / TILE_WIDTH;
dstep = tile_bpp (tile);
1997-11-25 06:05:25 +08:00
}
build color_cmds, lut_funcs, and pixel_processor feedback in the splash * app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor * app/app_procs.c: feedback in the splash screen when loading parasites. * app/boundary.c: Optimized find_empty_segs. * app/brightness_contrast.[ch] * app/levels.[ch] * app/posterize.[ch]: moved pdb and lut calculation code. These files now contain only GUI functions. * app/channel.c: Optimized channel_bounds (fewer compares, better use of registers). Use color_region instead of channel_*_segment in channel_combine_rect. Optimized channel_combine_ellipse by skipping pixels inside of the ellipse. Use pixel_region_process_parallel in channel_combine_mask. Use a GimpLut in channel_invert, and channel_sharpen. * app/invert.c * app/equalize.c: moved the lut functions to lut_funcs.c * app/gimpdrawable.c, app/gimpdrawableP.h * app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix variables/includes. * app/gimplut.[ch]: added new function gimp_lut_process_inline that operates on a single PixelRegion. * app/gimpparasite.[ch]: new functions to save/load parasiterc * app/parasitelist.[ch]: new functions to save/load ParasiteLists in/from files. * libgimp/parasite.[ch]: new functions to load/save parasites. * app/internal_procs.c: get some procs from new location in color_cmds.h. * app/pixel_region.[ch]: moved pixel_regions_process_parallel related functions to a new file. * app/color_cmds.[ch]: new files for PDB definitions/implementations of color correction functions. * app/lut_funcs.[ch]: new files to hold lut creation functions. * app/pixel_processor.[ch]: new files that contain the pixel_regions_process_parallel routines. Added some new capabilities that are currently unused.
1999-04-09 14:00:11 +08:00
endx = x + (TILE_WIDTH - (x%TILE_WIDTH));
endx = MIN (end, endx);
build color_cmds, lut_funcs, and pixel_processor feedback in the splash * app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor * app/app_procs.c: feedback in the splash screen when loading parasites. * app/boundary.c: Optimized find_empty_segs. * app/brightness_contrast.[ch] * app/levels.[ch] * app/posterize.[ch]: moved pdb and lut calculation code. These files now contain only GUI functions. * app/channel.c: Optimized channel_bounds (fewer compares, better use of registers). Use color_region instead of channel_*_segment in channel_combine_rect. Optimized channel_combine_ellipse by skipping pixels inside of the ellipse. Use pixel_region_process_parallel in channel_combine_mask. Use a GimpLut in channel_invert, and channel_sharpen. * app/invert.c * app/equalize.c: moved the lut functions to lut_funcs.c * app/gimpdrawable.c, app/gimpdrawableP.h * app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix variables/includes. * app/gimplut.[ch]: added new function gimp_lut_process_inline that operates on a single PixelRegion. * app/gimpparasite.[ch]: new functions to save/load parasiterc * app/parasitelist.[ch]: new functions to save/load ParasiteLists in/from files. * libgimp/parasite.[ch]: new functions to load/save parasites. * app/internal_procs.c: get some procs from new location in color_cmds.h. * app/pixel_region.[ch]: moved pixel_regions_process_parallel related functions to a new file. * app/color_cmds.[ch]: new files for PDB definitions/implementations of color correction functions. * app/lut_funcs.[ch]: new files to hold lut creation functions. * app/pixel_processor.[ch]: new files that contain the pixel_regions_process_parallel routines. Added some new capabilities that are currently unused.
1999-04-09 14:00:11 +08:00
if (type == IgnoreBounds && (endx > x1 || x < x2))
{
for (; x < endx; x++)
{
if (*data > HALF_WAY)
if (x >= x1 && x < x2)
val = -1;
else
val = 1;
else
val = -1;
data += dstep;
if (last != val)
empty_segs[l_num_empty++] = x;
last = val;
}
build color_cmds, lut_funcs, and pixel_processor feedback in the splash * app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor * app/app_procs.c: feedback in the splash screen when loading parasites. * app/boundary.c: Optimized find_empty_segs. * app/brightness_contrast.[ch] * app/levels.[ch] * app/posterize.[ch]: moved pdb and lut calculation code. These files now contain only GUI functions. * app/channel.c: Optimized channel_bounds (fewer compares, better use of registers). Use color_region instead of channel_*_segment in channel_combine_rect. Optimized channel_combine_ellipse by skipping pixels inside of the ellipse. Use pixel_region_process_parallel in channel_combine_mask. Use a GimpLut in channel_invert, and channel_sharpen. * app/invert.c * app/equalize.c: moved the lut functions to lut_funcs.c * app/gimpdrawable.c, app/gimpdrawableP.h * app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix variables/includes. * app/gimplut.[ch]: added new function gimp_lut_process_inline that operates on a single PixelRegion. * app/gimpparasite.[ch]: new functions to save/load parasiterc * app/parasitelist.[ch]: new functions to save/load ParasiteLists in/from files. * libgimp/parasite.[ch]: new functions to load/save parasites. * app/internal_procs.c: get some procs from new location in color_cmds.h. * app/pixel_region.[ch]: moved pixel_regions_process_parallel related functions to a new file. * app/color_cmds.[ch]: new files for PDB definitions/implementations of color correction functions. * app/lut_funcs.[ch]: new files to hold lut creation functions. * app/pixel_processor.[ch]: new files that contain the pixel_regions_process_parallel routines. Added some new capabilities that are currently unused.
1999-04-09 14:00:11 +08:00
}
else
{
for (; x < endx; x++)
{
if (*data > HALF_WAY)
val = 1;
else
val = -1;
data += dstep;
if (last != val)
empty_segs[l_num_empty++] = x;
last = val;
}
}
1997-11-25 06:05:25 +08:00
}
build color_cmds, lut_funcs, and pixel_processor feedback in the splash * app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor * app/app_procs.c: feedback in the splash screen when loading parasites. * app/boundary.c: Optimized find_empty_segs. * app/brightness_contrast.[ch] * app/levels.[ch] * app/posterize.[ch]: moved pdb and lut calculation code. These files now contain only GUI functions. * app/channel.c: Optimized channel_bounds (fewer compares, better use of registers). Use color_region instead of channel_*_segment in channel_combine_rect. Optimized channel_combine_ellipse by skipping pixels inside of the ellipse. Use pixel_region_process_parallel in channel_combine_mask. Use a GimpLut in channel_invert, and channel_sharpen. * app/invert.c * app/equalize.c: moved the lut functions to lut_funcs.c * app/gimpdrawable.c, app/gimpdrawableP.h * app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix variables/includes. * app/gimplut.[ch]: added new function gimp_lut_process_inline that operates on a single PixelRegion. * app/gimpparasite.[ch]: new functions to save/load parasiterc * app/parasitelist.[ch]: new functions to save/load ParasiteLists in/from files. * libgimp/parasite.[ch]: new functions to load/save parasites. * app/internal_procs.c: get some procs from new location in color_cmds.h. * app/pixel_region.[ch]: moved pixel_regions_process_parallel related functions to a new file. * app/color_cmds.[ch]: new files for PDB definitions/implementations of color correction functions. * app/lut_funcs.[ch]: new files to hold lut creation functions. * app/pixel_processor.[ch]: new files that contain the pixel_regions_process_parallel routines. Added some new capabilities that are currently unused.
1999-04-09 14:00:11 +08:00
*num_empty = l_num_empty;
1997-11-25 06:05:25 +08:00
if (last > 0)
empty_segs[(*num_empty)++] = x;
empty_segs[(*num_empty)++] = G_MAXINT;
if (tile)
tile_release (tile, FALSE);
1997-11-25 06:05:25 +08:00
}
static void
make_seg (gint x1,
gint y1,
gint x2,
gint y2,
gboolean open)
1997-11-25 06:05:25 +08:00
{
if (num_segs >= max_segs)
{
max_segs += MAX_SEGS_INC;
tmp_segs = (BoundSeg *) g_realloc ((void *) tmp_segs,
sizeof (BoundSeg) * max_segs);
if (!tmp_segs)
1999-09-23 19:49:16 +08:00
gimp_fatal_error ("make_seg(): Unable to reallocate segments array for mask boundary.");
1997-11-25 06:05:25 +08:00
}
tmp_segs[num_segs].x1 = x1;
tmp_segs[num_segs].y1 = y1;
tmp_segs[num_segs].x2 = x2;
tmp_segs[num_segs].y2 = y2;
tmp_segs[num_segs].open = open;
num_segs ++;
}
static void
allocate_vert_segs (void)
{
gint i;
1997-11-25 06:05:25 +08:00
/* allocate and initialize the vert_segs array */
vert_segs = (gint *) g_realloc ((void *) vert_segs,
(cur_PR->w + cur_PR->x + 1) * sizeof (gint));
1997-11-25 06:05:25 +08:00
for (i = 0; i <= (cur_PR->w + cur_PR->x); i++)
vert_segs[i] = -1;
}
static void
allocate_empty_segs (void)
{
gint need_num_segs;
1997-11-25 06:05:25 +08:00
/* find the maximum possible number of empty segments given the current mask */
need_num_segs = cur_PR->w + 3;
1997-11-25 06:05:25 +08:00
if (need_num_segs > max_empty_segs)
{
max_empty_segs = need_num_segs;
empty_segs_n = (gint *) g_realloc (empty_segs_n, sizeof (gint) * max_empty_segs);
empty_segs_c = (gint *) g_realloc (empty_segs_c, sizeof (gint) * max_empty_segs);
empty_segs_l = (gint *) g_realloc (empty_segs_l, sizeof (gint) * max_empty_segs);
1997-11-25 06:05:25 +08:00
if (!empty_segs_n || !empty_segs_l || !empty_segs_c)
1999-09-23 19:49:16 +08:00
gimp_fatal_error ("allocate_empty_segs(): Unable to reallocate empty segments array for mask boundary.");
1997-11-25 06:05:25 +08:00
}
}
static void
process_horiz_seg (gint x1,
gint y1,
gint x2,
gint y2,
gboolean open)
1997-11-25 06:05:25 +08:00
{
/* This procedure accounts for any vertical segments that must be
drawn to close in the horizontal segments. */
if (vert_segs[x1] >= 0)
{
make_seg (x1, vert_segs[x1], x1, y1, !open);
vert_segs[x1] = -1;
}
else
vert_segs[x1] = y1;
if (vert_segs[x2] >= 0)
{
make_seg (x2, vert_segs[x2], x2, y2, open);
vert_segs[x2] = -1;
}
else
vert_segs[x2] = y2;
make_seg (x1, y1, x2, y2, open);
}
static void
make_horiz_segs (gint start,
gint end,
gint scanline,
gint empty[],
gint num_empty,
gint top)
1997-11-25 06:05:25 +08:00
{
gint empty_index;
gint e_s, e_e; /* empty segment start and end values */
1997-11-25 06:05:25 +08:00
for (empty_index = 0; empty_index < num_empty; empty_index += 2)
{
e_s = *empty++;
e_e = *empty++;
if (e_s <= start && e_e >= end)
process_horiz_seg (start, scanline, end, scanline, top);
else if ((e_s > start && e_s < end) ||
(e_e < end && e_e > start))
process_horiz_seg (MAX (e_s, start), scanline,
MIN (e_e, end), scanline, top);
1997-11-25 06:05:25 +08:00
}
}
static void
generate_boundary (BoundaryType type,
gint x1,
gint y1,
gint x2,
gint y2)
1997-11-25 06:05:25 +08:00
{
gint scanline;
gint i;
gint start, end;
gint *tmp_segs;
1997-11-25 06:05:25 +08:00
start = 0;
end = 0;
/* array for determining the vertical line segments which must be drawn */
allocate_vert_segs ();
/* make sure there is enough space for the empty segment array */
allocate_empty_segs ();
num_segs = 0;
if (type == WithinBounds)
{
start = y1;
end = y2;
}
else if (type == IgnoreBounds)
{
start = cur_PR->y;
end = cur_PR->y + cur_PR->h;
}
/* Find the empty segments for the previous and current scanlines */
find_empty_segs (cur_PR, start - 1, empty_segs_l,
max_empty_segs, &num_empty_l,
type, x1, y1, x2, y2);
find_empty_segs (cur_PR, start, empty_segs_c,
max_empty_segs, &num_empty_c,
type, x1, y1, x2, y2);
for (scanline = start; scanline < end; scanline++)
{
/* find the empty segment list for the next scanline */
find_empty_segs (cur_PR, scanline + 1, empty_segs_n,
max_empty_segs, &num_empty_n,
type, x1, y1, x2, y2);
/* process the segments on the current scanline */
for (i = 1; i < num_empty_c - 1; i += 2)
{
make_horiz_segs (empty_segs_c [i], empty_segs_c [i+1],
scanline, empty_segs_l, num_empty_l, 1);
make_horiz_segs (empty_segs_c [i], empty_segs_c [i+1],
scanline+1, empty_segs_n, num_empty_n, 0);
}
/* get the next scanline of empty segments, swap others */
tmp_segs = empty_segs_l;
empty_segs_l = empty_segs_c;
num_empty_l = num_empty_c;
empty_segs_c = empty_segs_n;
num_empty_c = num_empty_n;
empty_segs_n = tmp_segs;
}
}
BoundSeg *
find_mask_boundary (PixelRegion *maskPR,
int *num_elems,
BoundaryType type,
int x1,
int y1,
int x2,
int y2)
{
BoundSeg * new_segs = NULL;
/* The mask paramater can be any PixelRegion. If the region
* has more than 1 bytes/pixel, the last byte of each pixel is
* used to determine the boundary outline.
*/
cur_PR = maskPR;
/* Calculate the boundary */
generate_boundary (type, x1, y1, x2, y2);
/* Set the number of X segments */
*num_elems = num_segs;
/* Make a copy of the boundary */
if (num_segs)
{
new_segs = (BoundSeg *) g_malloc (sizeof (BoundSeg) * num_segs);
memcpy (new_segs, tmp_segs, (sizeof (BoundSeg) * num_segs));
}
/* Return the new boundary */
return new_segs;
}
/************************/
/* Sorting a Boundary */
static int find_segment (BoundSeg *, int, int, int);
static int
find_segment (BoundSeg *segs,
gint ns,
gint x,
gint y)
1997-11-25 06:05:25 +08:00
{
gint index;
1997-11-25 06:05:25 +08:00
for (index = 0; index < ns; index++)
if (((segs[index].x1 == x && segs[index].y1 == y) || (segs[index].x2 == x && segs[index].y2 == y)) &&
segs[index].visited == FALSE)
return index;
return -1;
}
BoundSeg *
sort_boundary (BoundSeg *segs,
gint ns,
gint *num_groups)
1997-11-25 06:05:25 +08:00
{
gint i;
gint index;
gint x, y;
gint startx, starty;
gint empty = (num_segs == 0);
1997-11-25 06:05:25 +08:00
BoundSeg *new_segs;
index = 0;
new_segs = NULL;
for (i = 0; i < ns; i++)
segs[i].visited = FALSE;
num_segs = 0;
*num_groups = 0;
while (! empty)
{
empty = TRUE;
/* find the index of a non-visited segment to start a group */
for (i = 0; i < ns; i++)
if (segs[i].visited == FALSE)
{
index = i;
empty = FALSE;
i = ns;
}
if (! empty)
{
make_seg (segs[index].x1, segs[index].y1,
segs[index].x2, segs[index].y2,
segs[index].open);
segs[index].visited = TRUE;
startx = segs[index].x1;
starty = segs[index].y1;
x = segs[index].x2;
y = segs[index].y2;
while ((index = find_segment (segs, ns, x, y)) != -1)
{
/* make sure ordering is correct */
if (x == segs[index].x1 && y == segs[index].y1)
{
make_seg (segs[index].x1, segs[index].y1,
segs[index].x2, segs[index].y2,
segs[index].open);
x = segs[index].x2;
y = segs[index].y2;
}
else
{
make_seg (segs[index].x2, segs[index].y2,
segs[index].x1, segs[index].y1,
segs[index].open);
x = segs[index].x1;
y = segs[index].y1;
}
segs[index].visited = TRUE;
}
if (x != startx || y != starty)
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-30 00:35:47 +08:00
g_message ("sort_boundary(): Unconnected boundary group!");
1997-11-25 06:05:25 +08:00
/* Mark the end of a group */
*num_groups = *num_groups + 1;
make_seg (-1, -1, -1, -1, 0);
}
}
/* Make a copy of the boundary */
if (num_segs)
{
new_segs = (BoundSeg *) g_malloc (sizeof (BoundSeg) * num_segs);
memcpy (new_segs, tmp_segs, (sizeof (BoundSeg) * num_segs));
}
/* Return the new boundary */
return new_segs;
}