2005-07-10 06:44:26 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "base/pixel-region.h"
|
2005-07-14 03:30:25 +08:00
|
|
|
#include "base/siox.h"
|
2005-07-10 06:44:26 +08:00
|
|
|
#include "base/tile-manager.h"
|
|
|
|
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpdrawable.h"
|
|
|
|
#include "gimpdrawable-foreground-extract.h"
|
|
|
|
#include "gimpimage.h"
|
2005-07-28 07:01:48 +08:00
|
|
|
#include "gimpimage-colormap.h"
|
2005-07-29 11:28:27 +08:00
|
|
|
#include "gimpprogress.h"
|
2005-08-06 23:09:31 +08:00
|
|
|
#include "gimp-utils.h"
|
2005-07-29 11:28:27 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
2005-07-10 06:44:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2005-07-29 10:35:12 +08:00
|
|
|
gimp_drawable_foreground_extract (GimpDrawable *drawable,
|
|
|
|
GimpForegroundExtractMode mode,
|
2005-07-29 11:28:27 +08:00
|
|
|
GimpDrawable *mask,
|
|
|
|
GimpProgress *progress)
|
2005-08-06 08:51:22 +08:00
|
|
|
{
|
2005-08-07 03:08:43 +08:00
|
|
|
const gint smoothness = SIOX_DEFAULT_SMOOTHNESS;
|
|
|
|
const gdouble limits[3] = { SIOX_DEFAULT_GRANULARITY_L,
|
|
|
|
SIOX_DEFAULT_GRANULARITY_A,
|
|
|
|
SIOX_DEFAULT_GRANULARITY_B };
|
|
|
|
|
2005-08-06 08:51:22 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (mask));
|
2005-08-07 03:08:43 +08:00
|
|
|
g_return_if_fail (mode == GIMP_FOREGROUND_EXTRACT_SIOX);
|
2005-08-06 08:51:22 +08:00
|
|
|
|
2005-08-07 03:08:43 +08:00
|
|
|
gimp_drawable_foreground_extract_siox (drawable, mask,
|
2005-08-06 08:51:22 +08:00
|
|
|
0, 0,
|
|
|
|
gimp_item_width (GIMP_ITEM (mask)),
|
|
|
|
gimp_item_height (GIMP_ITEM (mask)),
|
2005-08-07 03:08:43 +08:00
|
|
|
smoothness, limits,
|
2005-08-06 08:51:22 +08:00
|
|
|
progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-08-07 03:08:43 +08:00
|
|
|
gimp_drawable_foreground_extract_siox (GimpDrawable *drawable,
|
|
|
|
GimpDrawable *mask,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint smoothness,
|
|
|
|
const gdouble limits[3],
|
|
|
|
GimpProgress *progress)
|
2005-07-10 06:44:26 +08:00
|
|
|
{
|
2005-07-28 06:52:34 +08:00
|
|
|
GimpImage *gimage;
|
2005-08-06 08:51:22 +08:00
|
|
|
const guchar *colormap = NULL;
|
2005-08-06 23:09:31 +08:00
|
|
|
gboolean intersect;
|
2005-08-06 08:51:22 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2005-07-10 06:44:26 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (mask));
|
|
|
|
g_return_if_fail (gimp_drawable_bytes (mask) == 1);
|
|
|
|
|
2005-07-29 11:28:27 +08:00
|
|
|
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
|
|
|
|
|
2005-07-10 06:44:26 +08:00
|
|
|
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
|
|
|
|
|
2005-07-28 06:52:34 +08:00
|
|
|
if (gimp_image_base_type (gimage) == GIMP_INDEXED)
|
|
|
|
colormap = gimp_image_get_colormap (gimage);
|
|
|
|
|
2005-08-06 08:51:22 +08:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &offset_x, &offset_y);
|
2005-07-29 04:12:16 +08:00
|
|
|
|
2005-08-06 23:09:31 +08:00
|
|
|
intersect = gimp_rectangle_intersect (offset_x, offset_y,
|
|
|
|
gimp_item_width (GIMP_ITEM (drawable)),
|
|
|
|
gimp_item_height (GIMP_ITEM (drawable)),
|
|
|
|
x, y, width, height,
|
|
|
|
&x, &y, &width, &height);
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME:
|
|
|
|
* Clear the mask outside the rectangle that we are working on?
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (! intersect)
|
|
|
|
return;
|
|
|
|
|
2005-07-29 11:28:27 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_start (progress, _("Foreground Extraction..."), FALSE);
|
|
|
|
|
2005-08-07 03:08:43 +08:00
|
|
|
siox_foreground_extract (gimp_drawable_data (drawable), colormap,
|
|
|
|
offset_x, offset_y,
|
|
|
|
gimp_drawable_data (mask), x, y, width, height,
|
2005-08-07 04:01:22 +08:00
|
|
|
smoothness, limits,
|
2005-08-07 03:08:43 +08:00
|
|
|
(SioxProgressFunc) gimp_progress_set_value,
|
|
|
|
progress);
|
2005-07-10 06:44:26 +08:00
|
|
|
|
2005-07-29 11:28:27 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_end (progress);
|
|
|
|
|
2005-07-10 06:44:26 +08:00
|
|
|
gimp_drawable_update (mask,
|
|
|
|
0, 0,
|
|
|
|
gimp_item_width (GIMP_ITEM (mask)),
|
|
|
|
gimp_item_height (GIMP_ITEM (mask)));
|
|
|
|
}
|