void edit_copy_cmd_callback (GtkAction *action, gpointer data) { GimpImage *image; GimpDrawable *drawable; GError *error = NULL; return_if_no_drawable (image, drawable, data); if (gimp_edit_copy (image, drawable, action_data_get_context (data), &error)) { GimpDisplay *display = action_data_get_display (data); if (display) gimp_message_literal (image->gimp, G_OBJECT (display), GIMP_MESSAGE_INFO, _("Copied pixels to the clipboard")); gimp_image_flush (image); } else { gimp_message_literal (image->gimp, G_OBJECT (action_data_get_display (data)), GIMP_MESSAGE_WARNING, error->message); g_clear_error (&error); } }
/* ----------------------- * p_tri_map_preprocessing * ----------------------- * prepare the tri mask for processing * - have bpp == 1 * - have same size and offset as the input drawable (that is a layer) * - pixel values >= 240 are set to value 240 (MATTING_USER_FOREGROUND) * - in case the input layer already has an alpha channel * all fully transparent (alpha == 0) pixels are also set 0 (MATTING_USER_BACKGROUND) * in the tri map to keep pixels fully transparent. (such pixels typicall do not * have a useful color information in the RGB channels) * * * in case the user provided the tri map as layer or channel that is NOT the layermask of the input layer * we create a new dummy layer with same size and offset as the input layer * and add a layermask to this dummy layer. * The layermask of the dummy layer is then filled with the intersecting grayscale copy * of the user-provided triMap drawable and will be used as tri map in the alpha matting processing. * * returns the dawable Id of the relevant TRI MAP that fulfills the conditons listed above. */ static gint32 p_tri_map_preprocessing (GimpDrawable *drawable, GapFgExtractValues *fgValPtr, gint32 *dummyLayerId) { gint32 prepocessedTriMapLayerId; gint32 inputLayerMaskId; gint32 imageId; *dummyLayerId = -1; imageId = gimp_drawable_get_image(drawable->drawable_id); inputLayerMaskId = gimp_layer_get_mask(drawable->drawable_id); if (fgValPtr->tri_map_drawable_id == inputLayerMaskId) { prepocessedTriMapLayerId = inputLayerMaskId; } else { gint offset_x; gint offset_y; gint32 dummyLayerMaskId; gint32 l_fsel_layer_id; *dummyLayerId = gimp_layer_new(imageId , "DUMMY" , drawable->width , drawable->height , GIMP_RGBA_IMAGE , 100.0 /* full opacity */ , GIMP_NORMAL_MODE /* normal mode */ ); /* get offsets of the input drawable (layer) within the image */ gimp_drawable_offsets (drawable->drawable_id, &offset_x, &offset_y); /* add dummy layer (of same size at same offsets) to the same image */ gimp_image_add_layer(imageId, *dummyLayerId, -1 /* stackposition */ ); gimp_layer_set_offsets(*dummyLayerId, offset_x, offset_y); /* create a new layermask (black is full transparent */ dummyLayerMaskId = gimp_layer_create_mask(*dummyLayerId, GIMP_ADD_BLACK_MASK); gimp_layer_add_mask(*dummyLayerId, dummyLayerMaskId); gimp_edit_copy(fgValPtr->tri_map_drawable_id); l_fsel_layer_id = gimp_edit_paste(dummyLayerMaskId, FALSE); gimp_floating_sel_anchor(l_fsel_layer_id); prepocessedTriMapLayerId = dummyLayerMaskId; } gap_fg_rgn_tri_map_normalize(drawable, prepocessedTriMapLayerId); return(prepocessedTriMapLayerId); } /* end p_tri_map_preprocessing */
static GimpValueArray * edit_copy_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpValueArray *return_vals; GimpDrawable *drawable; gboolean non_empty = FALSE; drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp); if (success) { if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, 0, error)) { GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); GError *my_error = NULL; non_empty = gimp_edit_copy (image, drawable, context, &my_error) != NULL; if (! non_empty) { gimp_message_literal (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING, my_error->message); g_clear_error (&my_error); } } else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) g_value_set_boolean (gimp_value_array_index (return_vals, 1), non_empty); return return_vals; }
static void border (gint32 image_ID) { GdkPixbuf *pixbuf = NULL; int texture_width; int texture_height; gdouble margin_x; gdouble margin_y; pixbuf = gdk_pixbuf_new_from_inline (-1, bvals.border->texture, FALSE, NULL); if (pixbuf) { texture_width = gdk_pixbuf_get_width (pixbuf); texture_height = gdk_pixbuf_get_height (pixbuf); gint32 texture_image = gimp_image_new (texture_width, texture_height, GIMP_RGB); gint32 texture_layer = gimp_layer_new_from_pixbuf (texture_image, "texture", pixbuf, 100, GIMP_NORMAL_MODE, 0, 0); gimp_image_add_layer (texture_image, texture_layer, -1); gint width = gimp_image_width (image_ID); gint height = gimp_image_height (image_ID); if (bvals.border->top || bvals.border->bottom || bvals.border->left || bvals.border->right) { width += bvals.border->left + bvals.border->right; height += bvals.border->top + bvals.border->bottom; gimp_image_resize (image_ID, width, height, bvals.border->left, bvals.border->top); } gint32 layer = gimp_layer_new (image_ID, "border", width, height, GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE); gimp_image_add_layer (image_ID, layer, -1); if (width > texture_width - bvals.border->length) margin_x = (texture_width - bvals.border->length) / 2; else margin_x = (gdouble) width / 2; if (height > texture_height - bvals.border->length) margin_y = (texture_height - bvals.border->length) / 2; else margin_y = (gdouble) height / 2; /* fix gimp_context_set_pattern ("Clipboard") only works on English versions of Gimp */ //gimp_context_set_pattern ("Clipboard"); INIT_I18N (); gimp_context_set_pattern (_("Clipboard")); if (width > margin_x * 2) { /* top */ gimp_rect_select (texture_image, margin_x, 0, texture_width - margin_x * 2, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, margin_x, 0, width - margin_x * 2, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* bottom */ gimp_rect_select (texture_image, margin_x, texture_height - margin_y, texture_width - margin_x * 2, texture_height, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, margin_x, height - margin_y, width - margin_x * 2, height, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); } if (height > margin_y * 2) { /* left */ gimp_rect_select (texture_image, 0, margin_y, margin_x, texture_height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, 0, margin_y, margin_x, height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* right */ gimp_rect_select (texture_image, texture_width - margin_x, margin_y, margin_x, texture_height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, width - margin_x, margin_y, margin_x, height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); } /* top left */ gimp_rect_select (texture_image, 0, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, 0, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* top right */ gimp_rect_select (texture_image, texture_width - margin_x, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, width - margin_x, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* bottom left */ gimp_rect_select (texture_image, 0, texture_height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, 0, height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* bottom right */ gimp_rect_select (texture_image, texture_width - margin_x, texture_height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, width - margin_x, height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); gimp_image_merge_down(image_ID, layer, GIMP_CLIP_TO_IMAGE); gimp_selection_none (image_ID); } }