/* --------------------------------------- * gap_image_remove_all_guides * --------------------------------------- */ void gap_image_remove_all_guides(gint32 image_id) { gint32 guide_id; while(TRUE) { guide_id = 0; /* 0 starts find at 1st guide */ guide_id = gimp_image_find_next_guide(image_id, guide_id); if (guide_id < 1) { break; } gimp_image_delete_guide(image_id, guide_id); } } /* end gap_image_remove_all_guides */
static void guillotine (gint32 image_ID) { gint guide; gint image_width; gint image_height; gboolean guides_found = FALSE; GList *hguides, *hg; GList *vguides, *vg; image_width = gimp_image_width (image_ID); image_height = gimp_image_height (image_ID); hguides = g_list_append (NULL, GINT_TO_POINTER (0)); hguides = g_list_append (hguides, GINT_TO_POINTER (image_height)); vguides = g_list_append (NULL, GINT_TO_POINTER (0)); vguides = g_list_append (vguides, GINT_TO_POINTER (image_width)); for (guide = gimp_image_find_next_guide (image_ID, 0); guide > 0; guide = gimp_image_find_next_guide (image_ID, guide)) { gint position = gimp_image_get_guide_position (image_ID, guide); switch (gimp_image_get_guide_orientation (image_ID, guide)) { case GIMP_ORIENTATION_HORIZONTAL: if (! g_list_find (hguides, GINT_TO_POINTER (position))) { hguides = g_list_insert_sorted (hguides, GINT_TO_POINTER (position), guide_sort_func); guides_found = TRUE; } break; case GIMP_ORIENTATION_VERTICAL: if (! g_list_find (vguides, GINT_TO_POINTER (position))) { vguides = g_list_insert_sorted (vguides, GINT_TO_POINTER (position), guide_sort_func); guides_found = TRUE; } break; case GIMP_ORIENTATION_UNKNOWN: g_assert_not_reached (); break; } } if (guides_found) { gchar *filename; gint h, v, hpad, vpad; gint x, y; gchar *hformat; gchar *format; filename = gimp_image_get_filename (image_ID); if (!filename) filename = g_strdup (_("Untitled")); /* get the number horizontal and vertical slices */ h = g_list_length (hguides); v = g_list_length (vguides); /* need the number of digits of h and v for the padding */ hpad = log10(h) + 1; vpad = log10(v) + 1; /* format for the x-y coordinates in the filename */ hformat = g_strdup_printf ("%%0%i", MAX (hpad, vpad)); format = g_strdup_printf ("-%si-%si", hformat, hformat); /* Do the actual dup'ing and cropping... this isn't a too naive a * way to do this since we got copy-on-write tiles, either. */ for (y = 0, hg = hguides; hg && hg->next; y++, hg = hg->next) { for (x = 0, vg = vguides; vg && vg->next; x++, vg = vg->next) { gint32 new_image = gimp_image_duplicate (image_ID); GString *new_filename; gchar *fileextension; gchar *fileindex; gint pos; if (new_image == -1) { g_warning ("Couldn't create new image."); return; } gimp_image_undo_disable (new_image); gimp_image_crop (new_image, GPOINTER_TO_INT (vg->next->data) - GPOINTER_TO_INT (vg->data), GPOINTER_TO_INT (hg->next->data) - GPOINTER_TO_INT (hg->data), GPOINTER_TO_INT (vg->data), GPOINTER_TO_INT (hg->data)); new_filename = g_string_new (filename); /* show the rough coordinates of the image in the title */ fileindex = g_strdup_printf (format, x, y); /* get the position of the file extension - last . in filename */ fileextension = strrchr (new_filename->str, '.'); pos = fileextension - new_filename->str; /* insert the coordinates before the extension */ g_string_insert (new_filename, pos, fileindex); g_free (fileindex); gimp_image_set_filename (new_image, new_filename->str); g_string_free (new_filename, TRUE); while ((guide = gimp_image_find_next_guide (new_image, 0))) gimp_image_delete_guide (new_image, guide); gimp_image_undo_enable (new_image); gimp_display_new (new_image); } } g_free (filename); g_free (hformat); g_free (format); } g_list_free (hguides); g_list_free (vguides); }
/* The main rotate function */ static void rotate (void) { GimpDrawable *drawable; gint32 *layers; gint i; gint nlayers; gint32 guide_ID; GuideInfo *guide; GList *guides = NULL; GList *list; if (rotvals.angle == 0) return; /* if there's a selection and we try to rotate the whole image */ /* create an error message and exit */ if (rotvals.everything) { if (! gimp_selection_is_empty (image_ID)) { gimp_message (_("You can not rotate the whole image if there's a selection.")); gimp_drawable_detach (active_drawable); return; } if (gimp_item_is_layer (active_drawable->drawable_id) && gimp_layer_is_floating_sel (active_drawable->drawable_id)) { gimp_message (_("You can not rotate the whole image if there's a floating selection.")); gimp_drawable_detach (active_drawable); return; } } else /* if we are trying to rotate a channel or a mask, create an error message and exit */ { if (! gimp_item_is_layer (active_drawable->drawable_id)) { gimp_message (_("Sorry, channels and masks can not be rotated.")); gimp_drawable_detach (active_drawable); return; } } gimp_progress_init (_("Rotating")); gimp_image_undo_group_start (image_ID); if (rotvals.everything) /* rotate the whole image */ { gint32 width = gimp_image_width (image_ID); gint32 height = gimp_image_height (image_ID); gimp_drawable_detach (active_drawable); layers = gimp_image_get_layers (image_ID, &nlayers); for (i = 0; i < nlayers; i++) { drawable = gimp_drawable_get (layers[i]); rotate_drawable (drawable); gimp_drawable_detach (drawable); } g_free (layers); /* build a list of all guides and remove them */ guide_ID = 0; while ((guide_ID = gimp_image_find_next_guide (image_ID, guide_ID)) != 0) { guide = g_new (GuideInfo, 1); guide->ID = guide_ID; guide->orientation = gimp_image_get_guide_orientation (image_ID, guide_ID); guide->position = gimp_image_get_guide_position (image_ID, guide_ID); guides = g_list_prepend (guides, guide); } for (list = guides; list; list = list->next) { guide = (GuideInfo *) list->data; gimp_image_delete_guide (image_ID, guide->ID); } /* if rotation is not 180 degrees, resize the image */ /* Do it now after the guides are removed, since */ /* gimp_image_resize() moves the guides. */ if (rotvals.angle != 2) gimp_image_resize (image_ID, height, width, 0, 0); /* add the guides back to the image */ if (guides) { switch (rotvals.angle) { case 1: for (list = guides; list; list = list->next) { guide = (GuideInfo *)list->data; if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL) gimp_image_add_vguide (image_ID, height - guide->position); else gimp_image_add_hguide (image_ID, guide->position); g_free (guide); } break; case 2: for (list = guides; list; list = list->next) { guide = (GuideInfo *)list->data; if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL) gimp_image_add_hguide (image_ID, height - guide->position); else gimp_image_add_vguide (image_ID, width - guide->position); g_free (guide); } break; case 3: for (list = guides; list; list = list->next) { guide = (GuideInfo *)list->data; if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL) gimp_image_add_vguide (image_ID, guide->position); else gimp_image_add_hguide (image_ID, width - guide->position); g_free (guide); } break; default: break; } g_list_free (guides); } } else /* rotate only the active layer */ { /* check for active selection and float it */ if (! gimp_selection_is_empty (image_ID) && ! gimp_layer_is_floating_sel (active_drawable->drawable_id)) { active_drawable = gimp_drawable_get (gimp_selection_float (image_ID, active_drawable->drawable_id, 0, 0)); } rotate_drawable (active_drawable); gimp_drawable_detach (active_drawable); } gimp_image_undo_group_end (image_ID); return; }