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"
37
static void gimp_image_rotate_item_offset (GimpImage *gimage,
38
GimpRotationType rotate_type,
42
static void gimp_image_rotate_guides (GimpImage *gimage,
43
GimpRotationType rotate_type);
37
#include "gimpsamplepoint.h"
40
static void gimp_image_rotate_item_offset (GimpImage *image,
41
GimpRotationType rotate_type,
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);
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)
59
63
gint new_image_height;
60
64
gboolean size_changed;
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));
66
gimp_set_busy (gimage->gimp);
68
center_x = (gdouble) gimage->width / 2.0;
69
center_y = (gdouble) gimage->height / 2.0;
71
progress_max = (gimage->channels->num_children +
72
gimage->layers->num_children +
73
gimage->vectors->num_children +
70
gimp_set_busy (image->gimp);
72
center_x = (gdouble) image->width / 2.0;
73
center_y = (gdouble) image->height / 2.0;
75
progress_max = (image->channels->num_children +
76
image->layers->num_children +
77
image->vectors->num_children +
74
78
1 /* selection */);
76
g_object_freeze_notify (G_OBJECT (gimage));
80
g_object_freeze_notify (G_OBJECT (image));
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);
80
84
/* Resize the image (if needed) */
81
85
switch (rotate_type)
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;
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;
129
133
item->offset_y = 0;
131
135
gimp_item_translate (item,
132
(new_image_width - gimage->width) / 2,
133
(new_image_height - gimage->height) / 2,
136
(new_image_width - image->width) / 2,
137
(new_image_height - image->height) / 2,
137
141
gimp_progress_set_value (progress, progress_current++ / progress_max);
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);
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;
148
152
gimp_progress_set_value (progress, progress_current++ / progress_max);
150
154
/* Rotate all layers */
151
for (list = GIMP_LIST (gimage->layers)->list;
155
for (list = GIMP_LIST (image->layers)->list;
153
157
list = g_list_next (list))
157
item = (GimpItem *) list->data;
159
GimpItem *item = list->data;
159
163
gimp_item_offsets (item, &off_x, &off_y);
161
165
gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
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);
166
170
gimp_progress_set_value (progress, progress_current++ / progress_max);
169
173
/* Rotate all Guides */
170
gimp_image_rotate_guides (gimage, rotate_type);
174
gimp_image_rotate_guides (image, rotate_type);
176
/* Rotate all sample points */
177
gimp_image_rotate_sample_points (image, rotate_type);
172
179
/* Resize the image (if needed) */
173
180
if (size_changed)
175
gimp_image_undo_push_image_size (gimage, NULL);
182
gimp_image_undo_push_image_size (image, NULL);
177
g_object_set (gimage,
178
185
"width", new_image_width,
179
186
"height", new_image_height,
182
if (gimage->xresolution != gimage->yresolution)
189
if (image->xresolution != image->yresolution)
186
gimp_image_undo_push_image_resolution (gimage, NULL);
193
gimp_image_undo_push_image_resolution (image, NULL);
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;
194
gimp_image_undo_group_end (gimage);
201
gimp_image_undo_group_end (image);
196
203
if (size_changed)
197
gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
199
g_object_thaw_notify (G_OBJECT (gimage));
201
gimp_unset_busy (gimage->gimp);
204
gimp_viewable_size_changed (GIMP_VIEWABLE (image));
206
g_object_thaw_notify (G_OBJECT (image));
208
gimp_unset_busy (image->gimp);
206
gimp_image_rotate_item_offset (GimpImage *gimage,
207
GimpRotationType rotate_type,
213
gimp_image_rotate_item_offset (GimpImage *image,
214
GimpRotationType rotate_type,
241
gimp_image_rotate_guides (GimpImage *gimage,
248
gimp_image_rotate_guides (GimpImage *image,
242
249
GimpRotationType rotate_type)
246
253
/* Rotate all Guides */
247
for (list = gimage->guides; list; list = g_list_next (list))
249
GimpGuide *guide = list->data;
254
switch (guide->orientation)
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;
262
case GIMP_ORIENTATION_VERTICAL:
263
gimp_image_undo_push_image_guide (gimage, NULL, guide);
264
guide->orientation = GIMP_ORIENTATION_HORIZONTAL;
272
case GIMP_ROTATE_180:
273
switch (guide->orientation)
275
case GIMP_ORIENTATION_HORIZONTAL:
276
gimp_image_move_guide (gimage, guide,
277
gimage->height - guide->position, TRUE);
280
case GIMP_ORIENTATION_VERTICAL:
281
gimp_image_move_guide (gimage, guide,
282
gimage->width - guide->position, TRUE);
290
case GIMP_ROTATE_270:
291
switch (guide->orientation)
293
case GIMP_ORIENTATION_HORIZONTAL:
294
gimp_image_undo_push_image_guide (gimage, NULL, guide);
295
guide->orientation = GIMP_ORIENTATION_VERTICAL;
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;
254
for (list = image->guides; list; list = g_list_next (list))
256
GimpGuide *guide = list->data;
257
GimpOrientationType orientation = gimp_guide_get_orientation (guide);
258
gint position = gimp_guide_get_position (guide);
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);
271
case GIMP_ORIENTATION_VERTICAL:
272
gimp_image_undo_push_guide (image, NULL, guide);
273
gimp_guide_set_orientation (guide, GIMP_ORIENTATION_HORIZONTAL);
281
case GIMP_ROTATE_180:
284
case GIMP_ORIENTATION_HORIZONTAL:
285
gimp_image_move_guide (image, guide,
286
image->height - position, TRUE);
289
case GIMP_ORIENTATION_VERTICAL:
290
gimp_image_move_guide (image, guide,
291
image->width - position, TRUE);
299
case GIMP_ROTATE_270:
302
case GIMP_ORIENTATION_HORIZONTAL:
303
gimp_image_undo_push_guide (image, NULL, guide);
304
gimp_guide_set_orientation (guide, GIMP_ORIENTATION_VERTICAL);
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);
323
gimp_image_rotate_sample_points (GimpImage *image,
324
GimpRotationType rotate_type)
328
/* Rotate all sample points */
329
for (list = image->sample_points; list; list = g_list_next (list))
331
GimpSamplePoint *sample_point = list->data;
335
gimp_image_undo_push_sample_point (image, NULL, sample_point);
337
old_x = sample_point->x;
338
old_y = sample_point->y;
343
sample_point->x = old_y;
344
sample_point->y = image->height - old_x;
347
case GIMP_ROTATE_180:
348
sample_point->x = image->height - old_x;
349
sample_point->y = image->width - old_y;
352
case GIMP_ROTATE_270:
353
sample_point->x = image->width - old_y;
354
sample_point->y = old_x;