static GimpBuffer * gimp_edit_extract (GimpImage *image, GimpPickable *pickable, GimpContext *context, gboolean cut_pixels, GError **error) { GeglBuffer *buffer; gint offset_x; gint offset_y; if (cut_pixels) gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT, C_("undo-type", "Cut")); /* Cut/copy the mask portion from the image */ buffer = gimp_selection_extract (GIMP_SELECTION (gimp_image_get_mask (image)), pickable, context, cut_pixels, FALSE, &offset_x, &offset_y, error); if (cut_pixels) gimp_image_undo_group_end (image); if (buffer) { GimpBuffer *gimp_buffer; gdouble res_x; gdouble res_y; gimp_buffer = gimp_buffer_new (buffer, _("Global Buffer"), offset_x, offset_y, FALSE); g_object_unref (buffer); gimp_image_get_resolution (image, &res_x, &res_y); gimp_buffer_set_resolution (gimp_buffer, res_x, res_y); gimp_buffer_set_unit (gimp_buffer, gimp_image_get_unit (image)); if (GIMP_IS_COLOR_MANAGED (pickable)) { GimpColorProfile *profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (pickable)); if (profile) gimp_buffer_set_color_profile (gimp_buffer, profile); } return gimp_buffer; } return NULL; }
GeglBuffer * gimp_drawable_transform_cut (GimpDrawable *drawable, GimpContext *context, gint *offset_x, gint *offset_y, gboolean *new_layer) { GimpImage *image; GeglBuffer *buffer; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (offset_x != NULL, NULL); g_return_val_if_fail (offset_y != NULL, NULL); g_return_val_if_fail (new_layer != NULL, NULL); image = gimp_item_get_image (GIMP_ITEM (drawable)); /* extract the selected mask if there is a selection */ if (! gimp_channel_is_empty (gimp_image_get_mask (image))) { gint x, y, w, h; /* set the keep_indexed flag to FALSE here, since we use * gimp_layer_new_from_buffer() later which assumes that the buffer * are either RGB or GRAY. Eeek!!! (Sven) */ if (gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &w, &h)) { buffer = gimp_selection_extract (GIMP_SELECTION (gimp_image_get_mask (image)), GIMP_PICKABLE (drawable), context, TRUE, FALSE, TRUE, offset_x, offset_y, NULL); /* clear the selection */ gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE); *new_layer = TRUE; } else { buffer = NULL; *new_layer = FALSE; } } else /* otherwise, just copy the layer */ { buffer = gimp_selection_extract (GIMP_SELECTION (gimp_image_get_mask (image)), GIMP_PICKABLE (drawable), context, FALSE, TRUE, GIMP_IS_LAYER (drawable), offset_x, offset_y, NULL); *new_layer = FALSE; } return buffer; }