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

« back to all changes in this revision

Viewing changes to app/core/gimpdrawable-offset.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
44
44
void
45
45
gimp_drawable_offset (GimpDrawable   *drawable,
46
46
                      GimpContext    *context,
47
 
                      gboolean        wrap_around,
48
 
                      GimpOffsetType  fill_type,
49
 
                      gint            offset_x,
50
 
                      gint            offset_y)
 
47
                      gboolean        wrap_around,
 
48
                      GimpOffsetType  fill_type,
 
49
                      gint            offset_x,
 
50
                      gint            offset_y)
51
51
{
52
52
  GimpItem    *item;
53
53
  PixelRegion  srcPR, destPR;
69
69
    {
70
70
      /*  avoid modulo operation on negative values  */
71
71
      while (offset_x < 0)
72
 
        offset_x += width;
 
72
        offset_x += width;
73
73
      while (offset_y < 0)
74
 
        offset_y += height;
 
74
        offset_y += height;
75
75
 
76
76
      offset_x %= width;
77
77
      offset_y %= height;
115
115
  /*  Copy the center region  */
116
116
  if (width && height)
117
117
    {
118
 
      pixel_region_init (&srcPR, gimp_drawable_data (drawable),
119
 
                         src_x, src_y, width, height, FALSE);
 
118
      pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
 
119
                         src_x, src_y, width, height, FALSE);
120
120
      pixel_region_init (&destPR, new_tiles,
121
 
                         dest_x, dest_y, width, height, TRUE);
 
121
                         dest_x, dest_y, width, height, TRUE);
122
122
 
123
123
      copy_region (&srcPR, &destPR);
124
124
    }
127
127
  if (wrap_around == TRUE)
128
128
    {
129
129
      if (offset_x >= 0 && offset_y >= 0)
130
 
        {
131
 
          src_x = gimp_item_width  (item) - offset_x;
132
 
          src_y = gimp_item_height (item) - offset_y;
133
 
        }
 
130
        {
 
131
          src_x = gimp_item_width  (item) - offset_x;
 
132
          src_y = gimp_item_height (item) - offset_y;
 
133
        }
134
134
      else if (offset_x >= 0 && offset_y < 0)
135
 
        {
136
 
          src_x = gimp_item_width (item) - offset_x;
137
 
          src_y = 0;
138
 
        }
 
135
        {
 
136
          src_x = gimp_item_width (item) - offset_x;
 
137
          src_y = 0;
 
138
        }
139
139
      else if (offset_x < 0 && offset_y >= 0)
140
 
        {
141
 
          src_x = 0;
142
 
          src_y = gimp_item_height (item) - offset_y;
143
 
        }
 
140
        {
 
141
          src_x = 0;
 
142
          src_y = gimp_item_height (item) - offset_y;
 
143
        }
144
144
      else if (offset_x < 0 && offset_y < 0)
145
 
        {
146
 
          src_x = 0;
147
 
          src_y = 0;
148
 
        }
 
145
        {
 
146
          src_x = 0;
 
147
          src_y = 0;
 
148
        }
149
149
 
150
150
      dest_x = (src_x + offset_x) % gimp_item_width (item);
151
151
      if (dest_x < 0)
152
 
        dest_x = gimp_item_width (item) + dest_x;
 
152
        dest_x = gimp_item_width (item) + dest_x;
153
153
 
154
154
      dest_y = (src_y + offset_y) % gimp_item_height (item);
155
155
      if (dest_y < 0)
156
 
        dest_y = gimp_item_height (item) + dest_y;
 
156
        dest_y = gimp_item_height (item) + dest_y;
157
157
 
158
158
      /*  intersecting region  */
159
159
      if (offset_x != 0 && offset_y != 0)
160
 
        {
161
 
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
162
 
                             src_x, src_y,
163
 
                             ABS (offset_x), ABS (offset_y),
164
 
                             FALSE);
165
 
          pixel_region_init (&destPR, new_tiles,
166
 
                             dest_x, dest_y,
167
 
                             ABS (offset_x), ABS (offset_y),
168
 
                             TRUE);
169
 
          copy_region (&srcPR, &destPR);
170
 
        }
 
160
        {
 
161
          pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
 
162
                             src_x, src_y,
 
163
                             ABS (offset_x), ABS (offset_y),
 
164
                             FALSE);
 
165
          pixel_region_init (&destPR, new_tiles,
 
166
                             dest_x, dest_y,
 
167
                             ABS (offset_x), ABS (offset_y),
 
168
                             TRUE);
 
169
          copy_region (&srcPR, &destPR);
 
170
        }
171
171
 
172
172
      /*  X offset  */
173
173
      if (offset_x != 0)
174
 
        {
175
 
          if (offset_y >= 0)
176
 
            {
177
 
              pixel_region_init (&srcPR, gimp_drawable_data (drawable),
178
 
                                 src_x, 0, ABS (offset_x),
179
 
                                 gimp_item_height (item) - ABS (offset_y),
180
 
                                 FALSE);
181
 
              pixel_region_init (&destPR, new_tiles,
182
 
                                 dest_x, dest_y + offset_y,
183
 
                                 ABS (offset_x),
184
 
                                 gimp_item_height (item) - ABS (offset_y),
185
 
                                 TRUE);
186
 
            }
187
 
          else if (offset_y < 0)
188
 
            {
189
 
              pixel_region_init (&srcPR, gimp_drawable_data (drawable),
190
 
                                 src_x, src_y - offset_y,
191
 
                                 ABS (offset_x),
192
 
                                 gimp_item_height (item) - ABS (offset_y),
193
 
                                 FALSE);
194
 
              pixel_region_init (&destPR, new_tiles,
195
 
                                 dest_x, 0,
196
 
                                 ABS (offset_x),
197
 
                                 gimp_item_height (item) - ABS (offset_y),
198
 
                                 TRUE);
199
 
            }
 
174
        {
 
175
          if (offset_y >= 0)
 
176
            {
 
177
              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
 
178
                                 src_x, 0, ABS (offset_x),
 
179
                                 gimp_item_height (item) - ABS (offset_y),
 
180
                                 FALSE);
 
181
              pixel_region_init (&destPR, new_tiles,
 
182
                                 dest_x, dest_y + offset_y,
 
183
                                 ABS (offset_x),
 
184
                                 gimp_item_height (item) - ABS (offset_y),
 
185
                                 TRUE);
 
186
            }
 
187
          else if (offset_y < 0)
 
188
            {
 
189
              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
 
190
                                 src_x, src_y - offset_y,
 
191
                                 ABS (offset_x),
 
192
                                 gimp_item_height (item) - ABS (offset_y),
 
193
                                 FALSE);
 
194
              pixel_region_init (&destPR, new_tiles,
 
195
                                 dest_x, 0,
 
196
                                 ABS (offset_x),
 
197
                                 gimp_item_height (item) - ABS (offset_y),
 
198
                                 TRUE);
 
199
            }
200
200
 
201
 
          copy_region (&srcPR, &destPR);
202
 
        }
 
201
          copy_region (&srcPR, &destPR);
 
202
        }
203
203
 
204
204
      /*  X offset  */
205
205
      if (offset_y != 0)
206
 
        {
207
 
          if (offset_x >= 0)
208
 
            {
209
 
              pixel_region_init (&srcPR, gimp_drawable_data (drawable),
210
 
                                 0, src_y,
211
 
                                 gimp_item_width (item) - ABS (offset_x),
212
 
                                 ABS (offset_y), FALSE);
213
 
              pixel_region_init (&destPR, new_tiles, dest_x + offset_x, dest_y,
214
 
                                 gimp_item_width (item) - ABS (offset_x),
215
 
                                 ABS (offset_y), TRUE);
216
 
            }
217
 
          else if (offset_x < 0)
218
 
            {
219
 
              pixel_region_init (&srcPR, gimp_drawable_data (drawable),
220
 
                                 src_x - offset_x, src_y,
221
 
                                 gimp_item_width (item) - ABS (offset_x),
222
 
                                 ABS (offset_y), FALSE);
223
 
              pixel_region_init (&destPR, new_tiles, 0, dest_y,
224
 
                                 gimp_item_width (item) - ABS (offset_x),
225
 
                                 ABS (offset_y), TRUE);
226
 
            }
 
206
        {
 
207
          if (offset_x >= 0)
 
208
            {
 
209
              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
 
210
                                 0, src_y,
 
211
                                 gimp_item_width (item) - ABS (offset_x),
 
212
                                 ABS (offset_y), FALSE);
 
213
              pixel_region_init (&destPR, new_tiles, dest_x + offset_x, dest_y,
 
214
                                 gimp_item_width (item) - ABS (offset_x),
 
215
                                 ABS (offset_y), TRUE);
 
216
            }
 
217
          else if (offset_x < 0)
 
218
            {
 
219
              pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
 
220
                                 src_x - offset_x, src_y,
 
221
                                 gimp_item_width (item) - ABS (offset_x),
 
222
                                 ABS (offset_y), FALSE);
 
223
              pixel_region_init (&destPR, new_tiles, 0, dest_y,
 
224
                                 gimp_item_width (item) - ABS (offset_x),
 
225
                                 ABS (offset_y), TRUE);
 
226
            }
227
227
 
228
 
          copy_region (&srcPR, &destPR);
229
 
        }
 
228
          copy_region (&srcPR, &destPR);
 
229
        }
230
230
    }
231
231
  /*  Otherwise, fill the vacated regions  */
232
232
  else
233
233
    {
234
234
      if (fill_type == GIMP_OFFSET_BACKGROUND)
235
 
        {
236
 
          GimpRGB color;
237
 
 
238
 
          gimp_context_get_background (context, &color);
239
 
 
240
 
          gimp_rgb_get_uchar (&color, &fill[0], &fill[1], &fill[2]);
241
 
 
242
 
          if (gimp_drawable_has_alpha (drawable))
243
 
            fill[gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
244
 
        }
 
235
        {
 
236
          GimpRGB color;
 
237
 
 
238
          gimp_context_get_background (context, &color);
 
239
 
 
240
          gimp_rgb_get_uchar (&color, &fill[0], &fill[1], &fill[2]);
 
241
 
 
242
          if (gimp_drawable_has_alpha (drawable))
 
243
            fill[gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
 
244
        }
245
245
 
246
246
      if (offset_x >= 0 && offset_y >= 0)
247
 
        {
248
 
          dest_x = 0;
249
 
          dest_y = 0;
250
 
        }
 
247
        {
 
248
          dest_x = 0;
 
249
          dest_y = 0;
 
250
        }
251
251
      else if (offset_x >= 0 && offset_y < 0)
252
 
        {
253
 
          dest_x = 0;
254
 
          dest_y = gimp_item_height (item) + offset_y;
255
 
        }
 
252
        {
 
253
          dest_x = 0;
 
254
          dest_y = gimp_item_height (item) + offset_y;
 
255
        }
256
256
      else if (offset_x < 0 && offset_y >= 0)
257
 
        {
258
 
          dest_x = gimp_item_width (item) + offset_x;
259
 
          dest_y = 0;
260
 
        }
 
257
        {
 
258
          dest_x = gimp_item_width (item) + offset_x;
 
259
          dest_y = 0;
 
260
        }
261
261
      else if (offset_x < 0 && offset_y < 0)
262
 
        {
263
 
          dest_x = gimp_item_width (item) + offset_x;
264
 
          dest_y = gimp_item_height (item) + offset_y;
265
 
        }
 
262
        {
 
263
          dest_x = gimp_item_width (item) + offset_x;
 
264
          dest_y = gimp_item_height (item) + offset_y;
 
265
        }
266
266
 
267
267
      /*  intersecting region  */
268
268
      if (offset_x != 0 && offset_y != 0)
269
 
        {
270
 
          pixel_region_init (&destPR, new_tiles, dest_x, dest_y,
271
 
                             ABS (offset_x), ABS (offset_y), TRUE);
272
 
          color_region (&destPR, fill);
273
 
        }
 
269
        {
 
270
          pixel_region_init (&destPR, new_tiles, dest_x, dest_y,
 
271
                             ABS (offset_x), ABS (offset_y), TRUE);
 
272
          color_region (&destPR, fill);
 
273
        }
274
274
 
275
275
      /*  X offset  */
276
276
      if (offset_x != 0)
277
 
        {
278
 
          if (offset_y >= 0)
279
 
            pixel_region_init (&destPR, new_tiles,
280
 
                               dest_x, dest_y + offset_y,
281
 
                               ABS (offset_x),
282
 
                               gimp_item_height (item) - ABS (offset_y),
283
 
                               TRUE);
284
 
          else if (offset_y < 0)
285
 
            pixel_region_init (&destPR, new_tiles,
286
 
                               dest_x, 0,
287
 
                               ABS (offset_x),
288
 
                               gimp_item_height (item) - ABS (offset_y),
289
 
                               TRUE);
 
277
        {
 
278
          if (offset_y >= 0)
 
279
            pixel_region_init (&destPR, new_tiles,
 
280
                               dest_x, dest_y + offset_y,
 
281
                               ABS (offset_x),
 
282
                               gimp_item_height (item) - ABS (offset_y),
 
283
                               TRUE);
 
284
          else if (offset_y < 0)
 
285
            pixel_region_init (&destPR, new_tiles,
 
286
                               dest_x, 0,
 
287
                               ABS (offset_x),
 
288
                               gimp_item_height (item) - ABS (offset_y),
 
289
                               TRUE);
290
290
 
291
 
          color_region (&destPR, fill);
292
 
        }
 
291
          color_region (&destPR, fill);
 
292
        }
293
293
 
294
294
      /*  X offset  */
295
295
      if (offset_y != 0)
296
 
        {
297
 
          if (offset_x >= 0)
298
 
            pixel_region_init (&destPR, new_tiles,
299
 
                               dest_x + offset_x,
300
 
                               dest_y,
301
 
                               gimp_item_width (item) - ABS (offset_x),
302
 
                               ABS (offset_y),
303
 
                               TRUE);
304
 
          else if (offset_x < 0)
305
 
            pixel_region_init (&destPR, new_tiles,
306
 
                               0, dest_y,
307
 
                               gimp_item_width (item) - ABS (offset_x),
308
 
                               ABS (offset_y),
309
 
                               TRUE);
 
296
        {
 
297
          if (offset_x >= 0)
 
298
            pixel_region_init (&destPR, new_tiles,
 
299
                               dest_x + offset_x,
 
300
                               dest_y,
 
301
                               gimp_item_width (item) - ABS (offset_x),
 
302
                               ABS (offset_y),
 
303
                               TRUE);
 
304
          else if (offset_x < 0)
 
305
            pixel_region_init (&destPR, new_tiles,
 
306
                               0, dest_y,
 
307
                               gimp_item_width (item) - ABS (offset_x),
 
308
                               ABS (offset_y),
 
309
                               TRUE);
310
310
 
311
 
          color_region (&destPR, fill);
312
 
        }
 
311
          color_region (&destPR, fill);
 
312
        }
313
313
    }
314
314
 
315
315
  gimp_drawable_set_tiles (drawable, gimp_item_is_attached (item),