1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <glib-object.h>
23
#include "libgimpbase/gimpbase.h"
25
#include "core-types.h"
27
#include "base/pixel-region.h"
28
#include "base/siox.h"
29
#include "base/tile-manager.h"
31
#include "gimpchannel.h"
32
#include "gimpdrawable.h"
33
#include "gimpdrawable-foreground-extract.h"
34
#include "gimpimage.h"
35
#include "gimpimage-colormap.h"
36
#include "gimpprogress.h"
38
#include "gimp-intl.h"
41
/* public functions */
44
gimp_drawable_foreground_extract (GimpDrawable *drawable,
45
GimpForegroundExtractMode mode,
47
GimpProgress *progress)
50
const gdouble sensitivity[3] = { SIOX_DEFAULT_SENSITIVITY_L,
51
SIOX_DEFAULT_SENSITIVITY_A,
52
SIOX_DEFAULT_SENSITIVITY_B };
54
g_return_if_fail (GIMP_IS_DRAWABLE (mask));
55
g_return_if_fail (mode == GIMP_FOREGROUND_EXTRACT_SIOX);
58
gimp_drawable_foreground_extract_siox_init (drawable,
60
gimp_item_width (GIMP_ITEM (mask)),
61
gimp_item_height (GIMP_ITEM (mask)));
65
gimp_drawable_foreground_extract_siox (mask, state,
66
SIOX_REFINEMENT_RECALCULATE,
67
SIOX_DEFAULT_SMOOTHNESS,
72
gimp_drawable_foreground_extract_siox_done (state);
77
gimp_drawable_foreground_extract_siox_init (GimpDrawable *drawable,
84
const guchar *colormap = NULL;
89
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
90
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
92
image = gimp_item_get_image (GIMP_ITEM (drawable));
94
if (gimp_image_base_type (image) == GIMP_INDEXED)
95
colormap = gimp_image_get_colormap (image);
97
gimp_item_offsets (GIMP_ITEM (drawable), &offset_x, &offset_y);
99
intersect = gimp_rectangle_intersect (offset_x, offset_y,
100
gimp_item_width (GIMP_ITEM (drawable)),
101
gimp_item_height (GIMP_ITEM (drawable)),
103
&x, &y, &width, &height);
107
* Clear the mask outside the rectangle that we are working on?
113
return siox_init (gimp_drawable_get_tiles (drawable), colormap,
115
x, y, width, height);
119
gimp_drawable_foreground_extract_siox (GimpDrawable *mask,
121
SioxRefinementType refinement,
123
const gdouble sensitivity[3],
125
GimpProgress *progress)
130
g_return_if_fail (GIMP_IS_DRAWABLE (mask));
131
g_return_if_fail (gimp_drawable_bytes (mask) == 1);
133
g_return_if_fail (state != NULL);
135
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
138
gimp_progress_start (progress, _("Foreground Extraction"), FALSE);
140
if (GIMP_IS_CHANNEL (mask))
142
gimp_channel_bounds (GIMP_CHANNEL (mask), &x1, &y1, &x2, &y2);
148
x2 = gimp_item_width (GIMP_ITEM (mask));
149
y2 = gimp_item_height (GIMP_ITEM (mask));
152
siox_foreground_extract (state, refinement,
153
gimp_drawable_get_tiles (mask), x1, y1, x2, y2,
154
smoothness, sensitivity, multiblob,
155
(SioxProgressFunc) gimp_progress_set_value,
159
gimp_progress_end (progress);
161
gimp_drawable_update (mask, x1, y1, x2, y2);
165
gimp_drawable_foreground_extract_siox_done (SioxState *state)
167
g_return_if_fail (state != NULL);