~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/core/gimpdrawable-foreground-extract.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <glib-object.h>
 
22
 
 
23
#include "libgimpbase/gimpbase.h"
 
24
 
 
25
#include "core-types.h"
 
26
 
 
27
#include "base/pixel-region.h"
 
28
#include "base/siox.h"
 
29
#include "base/tile-manager.h"
 
30
 
 
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"
 
37
 
 
38
#include "gimp-intl.h"
 
39
 
 
40
 
 
41
/*  public functions  */
 
42
 
 
43
void
 
44
gimp_drawable_foreground_extract (GimpDrawable              *drawable,
 
45
                                  GimpForegroundExtractMode  mode,
 
46
                                  GimpDrawable              *mask,
 
47
                                  GimpProgress              *progress)
 
48
{
 
49
  SioxState    *state;
 
50
  const gdouble sensitivity[3] = { SIOX_DEFAULT_SENSITIVITY_L,
 
51
                                   SIOX_DEFAULT_SENSITIVITY_A,
 
52
                                   SIOX_DEFAULT_SENSITIVITY_B };
 
53
 
 
54
  g_return_if_fail (GIMP_IS_DRAWABLE (mask));
 
55
  g_return_if_fail (mode == GIMP_FOREGROUND_EXTRACT_SIOX);
 
56
 
 
57
  state =
 
58
    gimp_drawable_foreground_extract_siox_init (drawable,
 
59
                                                0, 0,
 
60
                                                gimp_item_width (GIMP_ITEM (mask)),
 
61
                                                gimp_item_height (GIMP_ITEM (mask)));
 
62
 
 
63
  if (state)
 
64
    {
 
65
      gimp_drawable_foreground_extract_siox (mask, state,
 
66
                                             SIOX_REFINEMENT_RECALCULATE,
 
67
                                             SIOX_DEFAULT_SMOOTHNESS,
 
68
                                             sensitivity,
 
69
                                             FALSE,
 
70
                                             progress);
 
71
 
 
72
      gimp_drawable_foreground_extract_siox_done (state);
 
73
    }
 
74
}
 
75
 
 
76
SioxState *
 
77
gimp_drawable_foreground_extract_siox_init (GimpDrawable *drawable,
 
78
                                            gint          x,
 
79
                                            gint          y,
 
80
                                            gint          width,
 
81
                                            gint          height)
 
82
{
 
83
  GimpImage    *image;
 
84
  const guchar *colormap = NULL;
 
85
  gboolean      intersect;
 
86
  gint          offset_x;
 
87
  gint          offset_y;
 
88
 
 
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);
 
91
 
 
92
  image = gimp_item_get_image (GIMP_ITEM (drawable));
 
93
 
 
94
  if (gimp_image_base_type (image) == GIMP_INDEXED)
 
95
    colormap = gimp_image_get_colormap (image);
 
96
 
 
97
  gimp_item_offsets (GIMP_ITEM (drawable), &offset_x, &offset_y);
 
98
 
 
99
  intersect = gimp_rectangle_intersect (offset_x, offset_y,
 
100
                                        gimp_item_width (GIMP_ITEM (drawable)),
 
101
                                        gimp_item_height (GIMP_ITEM (drawable)),
 
102
                                        x, y, width, height,
 
103
                                        &x, &y, &width, &height);
 
104
 
 
105
 
 
106
  /* FIXME:
 
107
   * Clear the mask outside the rectangle that we are working on?
 
108
   */
 
109
 
 
110
  if (! intersect)
 
111
    return NULL;
 
112
 
 
113
  return siox_init (gimp_drawable_get_tiles (drawable), colormap,
 
114
                    offset_x, offset_y,
 
115
                    x, y, width, height);
 
116
}
 
117
 
 
118
void
 
119
gimp_drawable_foreground_extract_siox (GimpDrawable       *mask,
 
120
                                       SioxState          *state,
 
121
                                       SioxRefinementType  refinement,
 
122
                                       gint                smoothness,
 
123
                                       const gdouble       sensitivity[3],
 
124
                                       gboolean            multiblob,
 
125
                                       GimpProgress       *progress)
 
126
{
 
127
  gint x1, y1;
 
128
  gint x2, y2;
 
129
 
 
130
  g_return_if_fail (GIMP_IS_DRAWABLE (mask));
 
131
  g_return_if_fail (gimp_drawable_bytes (mask) == 1);
 
132
 
 
133
  g_return_if_fail (state != NULL);
 
134
 
 
135
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
 
136
 
 
137
  if (progress)
 
138
    gimp_progress_start (progress, _("Foreground Extraction"), FALSE);
 
139
 
 
140
  if (GIMP_IS_CHANNEL (mask))
 
141
    {
 
142
      gimp_channel_bounds (GIMP_CHANNEL (mask), &x1, &y1, &x2, &y2);
 
143
    }
 
144
  else
 
145
    {
 
146
      x1 = 0;
 
147
      y1 = 0;
 
148
      x2 = gimp_item_width (GIMP_ITEM (mask));
 
149
      y2 = gimp_item_height (GIMP_ITEM (mask));
 
150
    }
 
151
 
 
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,
 
156
                           progress);
 
157
 
 
158
  if (progress)
 
159
    gimp_progress_end (progress);
 
160
 
 
161
  gimp_drawable_update (mask, x1, y1, x2, y2);
 
162
}
 
163
 
 
164
void
 
165
gimp_drawable_foreground_extract_siox_done (SioxState *state)
 
166
{
 
167
  g_return_if_fail (state != NULL);
 
168
 
 
169
  siox_done (state);
 
170
}