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

« back to all changes in this revision

Viewing changes to app/core/gimpdrawable-combine.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
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
23
23
#include "core-types.h"
24
24
 
25
25
#include "base/pixel-region.h"
 
26
#include "base/tile-manager.h"
26
27
 
27
28
#include "paint-funcs/paint-funcs.h"
28
29
 
29
30
#include "gimpchannel.h"
30
31
#include "gimpdrawable-combine.h"
 
32
#include "gimpdrawableundo.h"
31
33
#include "gimpimage.h"
 
34
#include "gimpimage-undo.h"
32
35
 
33
36
 
34
37
void
42
45
                                 gint                  x,
43
46
                                 gint                  y)
44
47
{
45
 
  GimpImage       *gimage;
 
48
  GimpImage       *image;
46
49
  GimpItem        *item;
47
50
  GimpChannel     *mask;
48
51
  gint             x1, y1, x2, y2;
53
56
 
54
57
  item = GIMP_ITEM (drawable);
55
58
 
56
 
  gimage = gimp_item_get_image (item);
 
59
  image = gimp_item_get_image (item);
57
60
 
58
 
  mask = gimp_image_get_mask (gimage);
 
61
  mask = gimp_image_get_mask (image);
59
62
 
60
63
  /*  don't apply the mask to itself and don't apply an empty mask  */
61
64
  if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask))
78
81
  /*  get the layer offsets  */
79
82
  gimp_item_offsets (item, &offset_x, &offset_y);
80
83
 
81
 
  /*  make sure the image application coordinates are within gimage bounds  */
 
84
  /*  make sure the image application coordinates are within image bounds  */
82
85
  x1 = CLAMP (x, 0, gimp_item_width  (item));
83
86
  y1 = CLAMP (y, 0, gimp_item_height (item));
84
87
  x2 = CLAMP (x + src2PR->w, 0, gimp_item_width  (item));
98
101
 
99
102
  /*  If the calling procedure specified an undo step...  */
100
103
  if (push_undo)
101
 
    gimp_drawable_push_undo (drawable, undo_desc, x1, y1, x2, y2, NULL, FALSE);
 
104
    {
 
105
      GimpDrawableUndo *undo;
 
106
 
 
107
      gimp_drawable_push_undo (drawable, undo_desc, x1, y1, x2, y2, NULL, FALSE);
 
108
 
 
109
      undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image));
 
110
 
 
111
      if (undo)
 
112
        {
 
113
          PixelRegion tmp_srcPR;
 
114
          PixelRegion tmp_destPR;
 
115
 
 
116
          undo->paint_mode = mode;
 
117
          undo->opacity    = opacity;
 
118
          undo->src2_tiles = tile_manager_new (x2 - x1, y2 - y1,
 
119
                                               src2PR->bytes);
 
120
 
 
121
          tmp_srcPR = *src2PR;
 
122
          pixel_region_resize (&tmp_srcPR,
 
123
                               src2PR->x + (x1 - x), src2PR->y + (y1 - y),
 
124
                               x2 - x1, y2 - y1);
 
125
          pixel_region_init (&tmp_destPR, undo->src2_tiles,
 
126
                             0, 0,
 
127
                             x2 - x1, y2 - y1, TRUE);
 
128
 
 
129
          copy_region (&tmp_srcPR, &tmp_destPR);
 
130
        }
 
131
    }
102
132
 
103
133
  /* configure the pixel regions
104
134
   *  If an alternative to using the drawable's data as src1 was provided...
105
135
   */
106
136
  if (src1_tiles)
107
137
    pixel_region_init (&src1PR, src1_tiles,
108
 
                       x1, y1, (x2 - x1), (y2 - y1), FALSE);
 
138
                       x1, y1, (x2 - x1), (y2 - y1), FALSE);
109
139
  else
110
 
    pixel_region_init (&src1PR, gimp_drawable_data (drawable),
111
 
                       x1, y1, (x2 - x1), (y2 - y1), FALSE);
112
 
  pixel_region_init (&destPR, gimp_drawable_data (drawable),
113
 
                     x1, y1, (x2 - x1), (y2 - y1), TRUE);
 
140
    pixel_region_init (&src1PR, gimp_drawable_get_tiles (drawable),
 
141
                       x1, y1, (x2 - x1), (y2 - y1), FALSE);
 
142
  pixel_region_init (&destPR, gimp_drawable_get_tiles (drawable),
 
143
                     x1, y1, (x2 - x1), (y2 - y1), TRUE);
114
144
  pixel_region_resize (src2PR,
115
 
                       src2PR->x + (x1 - x), src2PR->y + (y1 - y),
116
 
                       (x2 - x1), (y2 - y1));
 
145
                       src2PR->x + (x1 - x), src2PR->y + (y1 - y),
 
146
                       (x2 - x1), (y2 - y1));
117
147
 
118
148
  if (mask)
119
149
    {
127
157
      my = y1 + offset_y;
128
158
 
129
159
      pixel_region_init (&maskPR,
130
 
                         gimp_drawable_data (GIMP_DRAWABLE (mask)),
131
 
                         mx, my,
132
 
                         (x2 - x1), (y2 - y1),
133
 
                         FALSE);
 
160
                         gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
 
161
                         mx, my,
 
162
                         (x2 - x1), (y2 - y1),
 
163
                         FALSE);
134
164
 
135
165
      combine_regions (&src1PR, src2PR, &destPR, &maskPR, NULL,
136
 
                       opacity * 255.999,
 
166
                       opacity * 255.999,
137
167
                       mode,
138
168
                       active_components,
139
169
                       operation);
141
171
  else
142
172
    {
143
173
      combine_regions (&src1PR, src2PR, &destPR, NULL, NULL,
144
 
                       opacity * 255.999,
 
174
                       opacity * 255.999,
145
175
                       mode,
146
176
                       active_components,
147
177
                       operation);
164
194
                                   gint          x,
165
195
                                   gint          y)
166
196
{
167
 
  GimpImage       *gimage;
 
197
  GimpImage       *image;
168
198
  GimpItem        *item;
169
199
  GimpChannel     *mask;
170
200
  gint             x1, y1, x2, y2;
175
205
 
176
206
  item = GIMP_ITEM (drawable);
177
207
 
178
 
  gimage = gimp_item_get_image (item);
 
208
  image = gimp_item_get_image (item);
179
209
 
180
 
  mask = gimp_image_get_mask (gimage);
 
210
  mask = gimp_image_get_mask (image);
181
211
 
182
212
  /*  don't apply the mask to itself and don't apply an empty mask  */
183
213
  if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask))
200
230
  /*  get the layer offsets  */
201
231
  gimp_item_offsets (item, &offset_x, &offset_y);
202
232
 
203
 
  /*  make sure the image application coordinates are within gimage bounds  */
 
233
  /*  make sure the image application coordinates are within image bounds  */
204
234
  x1 = CLAMP (x, 0, gimp_item_width (item));
205
235
  y1 = CLAMP (y, 0, gimp_item_height (item));
206
236
  x2 = CLAMP (x + src2PR->w, 0, gimp_item_width (item));
212
242
       *  we need to add the layer offset to transform coords
213
243
       *  into the mask coordinate system
214
244
       */
215
 
      x1 = CLAMP (x1, -offset_x, gimp_item_width (GIMP_ITEM (mask))-offset_x);
216
 
      y1 = CLAMP (y1, -offset_y, gimp_item_height(GIMP_ITEM (mask))-offset_y);
217
 
      x2 = CLAMP (x2, -offset_x, gimp_item_width (GIMP_ITEM (mask))-offset_x);
218
 
      y2 = CLAMP (y2, -offset_y, gimp_item_height(GIMP_ITEM (mask))-offset_y);
 
245
      x1 = CLAMP (x1, -offset_x, gimp_item_width  (GIMP_ITEM (mask))-offset_x);
 
246
      y1 = CLAMP (y1, -offset_y, gimp_item_height (GIMP_ITEM (mask))-offset_y);
 
247
      x2 = CLAMP (x2, -offset_x, gimp_item_width  (GIMP_ITEM (mask))-offset_x);
 
248
      y2 = CLAMP (y2, -offset_y, gimp_item_height (GIMP_ITEM (mask))-offset_y);
219
249
    }
220
250
 
221
251
  /*  If the calling procedure specified an undo step...  */
225
255
  /* configure the pixel regions
226
256
   *  If an alternative to using the drawable's data as src1 was provided...
227
257
   */
228
 
  pixel_region_init (&src1PR, gimp_drawable_data (drawable),
229
 
                     x1, y1, (x2 - x1), (y2 - y1), FALSE);
230
 
  pixel_region_init (&destPR, gimp_drawable_data (drawable),
231
 
                     x1, y1, (x2 - x1), (y2 - y1), TRUE);
 
258
  pixel_region_init (&src1PR, gimp_drawable_get_tiles (drawable),
 
259
                     x1, y1, (x2 - x1), (y2 - y1), FALSE);
 
260
  pixel_region_init (&destPR, gimp_drawable_get_tiles (drawable),
 
261
                     x1, y1, (x2 - x1), (y2 - y1), TRUE);
232
262
  pixel_region_resize (src2PR,
233
 
                       src2PR->x + (x1 - x), src2PR->y + (y1 - y),
234
 
                       (x2 - x1), (y2 - y1));
 
263
                       src2PR->x + (x1 - x), src2PR->y + (y1 - y),
 
264
                       (x2 - x1), (y2 - y1));
235
265
 
236
266
  if (mask)
237
267
    {
247
277
      my = y1 + offset_y;
248
278
 
249
279
      pixel_region_init (&mask2PR,
250
 
                         gimp_drawable_data (GIMP_DRAWABLE (mask)),
251
 
                         mx, my,
252
 
                         (x2 - x1), (y2 - y1),
253
 
                         FALSE);
254
 
 
255
 
      tempPR.bytes     = 1;
256
 
      tempPR.x         = 0;
257
 
      tempPR.y         = 0;
258
 
      tempPR.w         = x2 - x1;
259
 
      tempPR.h         = y2 - y1;
260
 
      tempPR.rowstride = tempPR.w * tempPR.bytes;
261
 
      tempPR.data      = temp_data = g_malloc (tempPR.h * tempPR.rowstride);
 
280
                         gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
 
281
                         mx, my,
 
282
                         (x2 - x1), (y2 - y1),
 
283
                         FALSE);
 
284
 
 
285
      temp_data = g_malloc ((y2 - y1) * (x2 - x1));
 
286
 
 
287
      pixel_region_init_data (&tempPR, temp_data, 1, x2 - x1,
 
288
                              0, 0, x2 - x1, y2 - y1);
262
289
 
263
290
      copy_region (&mask2PR, &tempPR);
264
291
 
265
 
      /* apparently, region operations can mutate some PR data. */
266
 
      tempPR.x    = 0;
267
 
      tempPR.y    = 0;
268
 
      tempPR.w    = x2 - x1;
269
 
      tempPR.h    = y2 - y1;
270
 
      tempPR.data = temp_data;
 
292
      pixel_region_init_data (&tempPR, temp_data, 1, x2 - x1,
 
293
                              0, 0, x2 - x1, y2 - y1);
271
294
 
272
295
      apply_mask_to_region (&tempPR, maskPR, OPAQUE_OPACITY);
273
296
 
274
 
      tempPR.x    = 0;
275
 
      tempPR.y    = 0;
276
 
      tempPR.w    = x2 - x1;
277
 
      tempPR.h    = y2 - y1;
278
 
      tempPR.data = temp_data;
 
297
      pixel_region_init_data (&tempPR, temp_data, 1, x2 - x1,
 
298
                              0, 0, x2 - x1, y2 - y1);
279
299
 
280
300
      combine_regions_replace (&src1PR, src2PR, &destPR, &tempPR, NULL,
281
301
                               opacity * 255.999,
287
307
  else
288
308
    {
289
309
      combine_regions_replace (&src1PR, src2PR, &destPR, maskPR, NULL,
290
 
                               opacity * 255.999,
 
310
                               opacity * 255.999,
291
311
                               active_components,
292
312
                               operation);
293
313
    }