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

« back to all changes in this revision

Viewing changes to app/core/gimpimage-rotate.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
24
24
 
25
25
#include "gimp.h"
26
26
#include "gimpcontext.h"
 
27
#include "gimpguide.h"
27
28
#include "gimpimage.h"
28
29
#include "gimpimage-rotate.h"
29
30
#include "gimpimage-guides.h"
 
31
#include "gimpimage-sample-points.h"
30
32
#include "gimpimage-undo.h"
31
33
#include "gimpimage-undo-push.h"
32
34
#include "gimpitem.h"
33
35
#include "gimplist.h"
34
36
#include "gimpprogress.h"
35
 
 
36
 
 
37
 
static void  gimp_image_rotate_item_offset (GimpImage        *gimage,
38
 
                                            GimpRotationType  rotate_type,
39
 
                                            GimpItem         *item,
40
 
                                            gint              off_x,
41
 
                                            gint              off_y);
42
 
static void  gimp_image_rotate_guides      (GimpImage        *gimage,
43
 
                                            GimpRotationType  rotate_type);
 
37
#include "gimpsamplepoint.h"
 
38
 
 
39
 
 
40
static void  gimp_image_rotate_item_offset   (GimpImage        *image,
 
41
                                              GimpRotationType  rotate_type,
 
42
                                              GimpItem         *item,
 
43
                                              gint              off_x,
 
44
                                              gint              off_y);
 
45
static void  gimp_image_rotate_guides        (GimpImage        *image,
 
46
                                              GimpRotationType  rotate_type);
 
47
static void  gimp_image_rotate_sample_points (GimpImage        *image,
 
48
                                              GimpRotationType  rotate_type);
44
49
 
45
50
 
46
51
void
47
 
gimp_image_rotate (GimpImage        *gimage,
 
52
gimp_image_rotate (GimpImage        *image,
48
53
                   GimpContext      *context,
49
54
                   GimpRotationType  rotate_type,
50
55
                   GimpProgress     *progress)
51
56
{
52
 
  GimpItem *item;
53
57
  GList    *list;
54
58
  gdouble   center_x;
55
59
  gdouble   center_y;
59
63
  gint      new_image_height;
60
64
  gboolean  size_changed;
61
65
 
62
 
  g_return_if_fail (GIMP_IS_IMAGE (gimage));
 
66
  g_return_if_fail (GIMP_IS_IMAGE (image));
63
67
  g_return_if_fail (GIMP_IS_CONTEXT (context));
64
68
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
65
69
 
66
 
  gimp_set_busy (gimage->gimp);
67
 
 
68
 
  center_x = (gdouble) gimage->width  / 2.0;
69
 
  center_y = (gdouble) gimage->height / 2.0;
70
 
 
71
 
  progress_max = (gimage->channels->num_children +
72
 
                  gimage->layers->num_children   +
73
 
                  gimage->vectors->num_children  +
 
70
  gimp_set_busy (image->gimp);
 
71
 
 
72
  center_x = (gdouble) image->width  / 2.0;
 
73
  center_y = (gdouble) image->height / 2.0;
 
74
 
 
75
  progress_max = (image->channels->num_children +
 
76
                  image->layers->num_children   +
 
77
                  image->vectors->num_children  +
74
78
                  1 /* selection */);
75
79
 
76
 
  g_object_freeze_notify (G_OBJECT (gimage));
 
80
  g_object_freeze_notify (G_OBJECT (image));
77
81
 
78
 
  gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_ROTATE, NULL);
 
82
  gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_ROTATE, NULL);
79
83
 
80
84
  /*  Resize the image (if needed)  */
81
85
  switch (rotate_type)
82
86
    {
83
87
    case GIMP_ROTATE_90:
84
88
    case GIMP_ROTATE_270:
85
 
      new_image_width  = gimage->height;
86
 
      new_image_height = gimage->width;
 
89
      new_image_width  = image->height;
 
90
      new_image_height = image->width;
87
91
      size_changed     = TRUE;
88
92
      break;
89
93
 
90
94
    case GIMP_ROTATE_180:
91
 
      new_image_width  = gimage->width;
92
 
      new_image_height = gimage->height;
 
95
      new_image_width  = image->width;
 
96
      new_image_height = image->height;
93
97
      size_changed     = FALSE;
94
98
     break;
95
99
 
99
103
    }
100
104
 
101
105
  /*  Rotate all channels  */
102
 
  for (list = GIMP_LIST (gimage->channels)->list;
 
106
  for (list = GIMP_LIST (image->channels)->list;
103
107
       list;
104
108
       list = g_list_next (list))
105
109
    {
106
 
      item = (GimpItem *) list->data;
 
110
      GimpItem *item = list->data;
107
111
 
108
112
      gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
109
113
 
115
119
    }
116
120
 
117
121
  /*  Rotate all vectors  */
118
 
  for (list = GIMP_LIST (gimage->vectors)->list;
 
122
  for (list = GIMP_LIST (image->vectors)->list;
119
123
       list;
120
124
       list = g_list_next (list))
121
125
    {
122
 
      item = (GimpItem *) list->data;
 
126
      GimpItem *item = list->data;
123
127
 
124
128
      gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
125
129
 
129
133
      item->offset_y = 0;
130
134
 
131
135
      gimp_item_translate (item,
132
 
                           (new_image_width  - gimage->width)  / 2,
133
 
                           (new_image_height - gimage->height) / 2,
134
 
                           FALSE);
 
136
                           (new_image_width  - image->width)  / 2,
 
137
                           (new_image_height - image->height) / 2,
 
138
                           FALSE);
135
139
 
136
140
      if (progress)
137
141
        gimp_progress_set_value (progress, progress_current++ / progress_max);
138
142
    }
139
143
 
140
144
  /*  Don't forget the selection mask!  */
141
 
  gimp_item_rotate (GIMP_ITEM (gimp_image_get_mask (gimage)), context,
 
145
  gimp_item_rotate (GIMP_ITEM (gimp_image_get_mask (image)), context,
142
146
                    rotate_type, center_x, center_y, FALSE);
143
147
 
144
 
  GIMP_ITEM (gimage->selection_mask)->offset_x = 0;
145
 
  GIMP_ITEM (gimage->selection_mask)->offset_y = 0;
 
148
  GIMP_ITEM (image->selection_mask)->offset_x = 0;
 
149
  GIMP_ITEM (image->selection_mask)->offset_y = 0;
146
150
 
147
151
  if (progress)
148
152
    gimp_progress_set_value (progress, progress_current++ / progress_max);
149
153
 
150
154
  /*  Rotate all layers  */
151
 
  for (list = GIMP_LIST (gimage->layers)->list;
 
155
  for (list = GIMP_LIST (image->layers)->list;
152
156
       list;
153
157
       list = g_list_next (list))
154
158
    {
155
 
      gint off_x, off_y;
156
 
 
157
 
      item = (GimpItem *) list->data;
 
159
      GimpItem *item = list->data;
 
160
      gint      off_x;
 
161
      gint      off_y;
158
162
 
159
163
      gimp_item_offsets (item, &off_x, &off_y);
160
164
 
161
165
      gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
162
166
 
163
 
      gimp_image_rotate_item_offset (gimage, rotate_type, item, off_x, off_y);
 
167
      gimp_image_rotate_item_offset (image, rotate_type, item, off_x, off_y);
164
168
 
165
169
      if (progress)
166
170
        gimp_progress_set_value (progress, progress_current++ / progress_max);
167
171
    }
168
172
 
169
173
  /*  Rotate all Guides  */
170
 
  gimp_image_rotate_guides (gimage, rotate_type);
 
174
  gimp_image_rotate_guides (image, rotate_type);
 
175
 
 
176
  /*  Rotate all sample points  */
 
177
  gimp_image_rotate_sample_points (image, rotate_type);
171
178
 
172
179
  /*  Resize the image (if needed)  */
173
180
  if (size_changed)
174
181
    {
175
 
      gimp_image_undo_push_image_size (gimage, NULL);
 
182
      gimp_image_undo_push_image_size (image, NULL);
176
183
 
177
 
      g_object_set (gimage,
 
184
      g_object_set (image,
178
185
                    "width",  new_image_width,
179
186
                    "height", new_image_height,
180
187
                    NULL);
181
188
 
182
 
      if (gimage->xresolution != gimage->yresolution)
 
189
      if (image->xresolution != image->yresolution)
183
190
        {
184
191
          gdouble tmp;
185
192
 
186
 
          gimp_image_undo_push_image_resolution (gimage, NULL);
 
193
          gimp_image_undo_push_image_resolution (image, NULL);
187
194
 
188
 
          tmp                 = gimage->xresolution;
189
 
          gimage->yresolution = gimage->xresolution;
190
 
          gimage->xresolution = tmp;
 
195
          tmp                = image->xresolution;
 
196
          image->yresolution = image->xresolution;
 
197
          image->xresolution = tmp;
191
198
        }
192
199
    }
193
200
 
194
 
  gimp_image_undo_group_end (gimage);
 
201
  gimp_image_undo_group_end (image);
195
202
 
196
203
  if (size_changed)
197
 
    gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
198
 
 
199
 
  g_object_thaw_notify (G_OBJECT (gimage));
200
 
 
201
 
  gimp_unset_busy (gimage->gimp);
 
204
    gimp_viewable_size_changed (GIMP_VIEWABLE (image));
 
205
 
 
206
  g_object_thaw_notify (G_OBJECT (image));
 
207
 
 
208
  gimp_unset_busy (image->gimp);
202
209
}
203
210
 
204
211
 
205
212
static void
206
 
gimp_image_rotate_item_offset (GimpImage        *gimage,
207
 
                               GimpRotationType  rotate_type,
208
 
                               GimpItem         *item,
209
 
                               gint              off_x,
210
 
                               gint              off_y)
 
213
gimp_image_rotate_item_offset (GimpImage        *image,
 
214
                               GimpRotationType  rotate_type,
 
215
                               GimpItem         *item,
 
216
                               gint              off_x,
 
217
                               gint              off_y)
211
218
{
212
219
  gint x = 0;
213
220
  gint y = 0;
215
222
  switch (rotate_type)
216
223
    {
217
224
    case GIMP_ROTATE_90:
218
 
      x = gimage->height - off_y - gimp_item_width (item);
 
225
      x = image->height - off_y - gimp_item_width (item);
219
226
      y = off_x;
220
227
      break;
221
228
 
222
229
    case GIMP_ROTATE_270:
223
230
      x = off_y;
224
 
      y = gimage->width - off_x - gimp_item_height (item);
 
231
      y = image->width - off_x - gimp_item_height (item);
225
232
      break;
226
233
 
227
234
    case GIMP_ROTATE_180:
238
245
}
239
246
 
240
247
static void
241
 
gimp_image_rotate_guides (GimpImage        *gimage,
 
248
gimp_image_rotate_guides (GimpImage        *image,
242
249
                          GimpRotationType  rotate_type)
243
250
{
244
251
  GList *list;
245
252
 
246
253
  /*  Rotate all Guides  */
247
 
  for (list = gimage->guides; list; list = g_list_next (list))
248
 
    {
249
 
      GimpGuide *guide = list->data;
250
 
 
251
 
      switch (rotate_type)
252
 
        {
253
 
        case GIMP_ROTATE_90:
254
 
          switch (guide->orientation)
255
 
            {
256
 
            case GIMP_ORIENTATION_HORIZONTAL:
257
 
              gimp_image_undo_push_image_guide (gimage, NULL, guide);
258
 
              guide->orientation = GIMP_ORIENTATION_VERTICAL;
259
 
              guide->position    = gimage->height - guide->position;
260
 
              break;
261
 
 
262
 
            case GIMP_ORIENTATION_VERTICAL:
263
 
              gimp_image_undo_push_image_guide (gimage, NULL, guide);
264
 
              guide->orientation = GIMP_ORIENTATION_HORIZONTAL;
265
 
              break;
266
 
 
267
 
            default:
268
 
              break;
269
 
            }
270
 
          break;
271
 
 
272
 
        case GIMP_ROTATE_180:
273
 
          switch (guide->orientation)
274
 
            {
275
 
            case GIMP_ORIENTATION_HORIZONTAL:
276
 
              gimp_image_move_guide (gimage, guide,
277
 
                                     gimage->height - guide->position, TRUE);
278
 
              break;
279
 
 
280
 
            case GIMP_ORIENTATION_VERTICAL:
281
 
              gimp_image_move_guide (gimage, guide,
282
 
                                     gimage->width - guide->position, TRUE);
283
 
              break;
284
 
 
285
 
            default:
286
 
              break;
287
 
            }
288
 
          break;
289
 
 
290
 
        case GIMP_ROTATE_270:
291
 
          switch (guide->orientation)
292
 
            {
293
 
            case GIMP_ORIENTATION_HORIZONTAL:
294
 
              gimp_image_undo_push_image_guide (gimage, NULL, guide);
295
 
              guide->orientation = GIMP_ORIENTATION_VERTICAL;
296
 
              break;
297
 
 
298
 
            case GIMP_ORIENTATION_VERTICAL:
299
 
              gimp_image_undo_push_image_guide (gimage, NULL, guide);
300
 
              guide->orientation = GIMP_ORIENTATION_HORIZONTAL;
301
 
              guide->position    = gimage->width - guide->position;
302
 
              break;
303
 
 
304
 
            default:
305
 
              break;
306
 
            }
307
 
          break;
308
 
        }
 
254
  for (list = image->guides; list; list = g_list_next (list))
 
255
    {
 
256
      GimpGuide           *guide       = list->data;
 
257
      GimpOrientationType  orientation = gimp_guide_get_orientation (guide);
 
258
      gint                 position    = gimp_guide_get_position (guide);
 
259
 
 
260
      switch (rotate_type)
 
261
        {
 
262
        case GIMP_ROTATE_90:
 
263
          switch (orientation)
 
264
            {
 
265
            case GIMP_ORIENTATION_HORIZONTAL:
 
266
              gimp_image_undo_push_guide (image, NULL, guide);
 
267
              gimp_guide_set_orientation (guide, GIMP_ORIENTATION_VERTICAL);
 
268
              gimp_guide_set_position (guide, image->height - position);
 
269
              break;
 
270
 
 
271
            case GIMP_ORIENTATION_VERTICAL:
 
272
              gimp_image_undo_push_guide (image, NULL, guide);
 
273
              gimp_guide_set_orientation (guide, GIMP_ORIENTATION_HORIZONTAL);
 
274
              break;
 
275
 
 
276
            default:
 
277
              break;
 
278
            }
 
279
          break;
 
280
 
 
281
        case GIMP_ROTATE_180:
 
282
          switch (orientation)
 
283
            {
 
284
            case GIMP_ORIENTATION_HORIZONTAL:
 
285
              gimp_image_move_guide (image, guide,
 
286
                                     image->height - position, TRUE);
 
287
              break;
 
288
 
 
289
            case GIMP_ORIENTATION_VERTICAL:
 
290
              gimp_image_move_guide (image, guide,
 
291
                                     image->width - position, TRUE);
 
292
              break;
 
293
 
 
294
            default:
 
295
              break;
 
296
            }
 
297
          break;
 
298
 
 
299
        case GIMP_ROTATE_270:
 
300
          switch (orientation)
 
301
            {
 
302
            case GIMP_ORIENTATION_HORIZONTAL:
 
303
              gimp_image_undo_push_guide (image, NULL, guide);
 
304
              gimp_guide_set_orientation (guide, GIMP_ORIENTATION_VERTICAL);
 
305
              break;
 
306
 
 
307
            case GIMP_ORIENTATION_VERTICAL:
 
308
              gimp_image_undo_push_guide (image, NULL, guide);
 
309
              gimp_guide_set_orientation (guide, GIMP_ORIENTATION_HORIZONTAL);
 
310
              gimp_guide_set_position (guide, image->width - position);
 
311
              break;
 
312
 
 
313
            default:
 
314
              break;
 
315
            }
 
316
          break;
 
317
        }
 
318
    }
 
319
}
 
320
 
 
321
 
 
322
static void
 
323
gimp_image_rotate_sample_points (GimpImage        *image,
 
324
                                 GimpRotationType  rotate_type)
 
325
{
 
326
  GList *list;
 
327
 
 
328
  /*  Rotate all sample points  */
 
329
  for (list = image->sample_points; list; list = g_list_next (list))
 
330
    {
 
331
      GimpSamplePoint *sample_point = list->data;
 
332
      gint             old_x;
 
333
      gint             old_y;
 
334
 
 
335
      gimp_image_undo_push_sample_point (image, NULL, sample_point);
 
336
 
 
337
      old_x = sample_point->x;
 
338
      old_y = sample_point->y;
 
339
 
 
340
      switch (rotate_type)
 
341
        {
 
342
        case GIMP_ROTATE_90:
 
343
          sample_point->x = old_y;
 
344
          sample_point->y = image->height - old_x;
 
345
          break;
 
346
 
 
347
        case GIMP_ROTATE_180:
 
348
          sample_point->x = image->height - old_x;
 
349
          sample_point->y = image->width - old_y;
 
350
          break;
 
351
 
 
352
        case GIMP_ROTATE_270:
 
353
          sample_point->x = image->width - old_y;
 
354
          sample_point->y = old_x;
 
355
          break;
 
356
        }
309
357
    }
310
358
}