static gint32 create_image (GdkPixbuf *pixbuf, GdkRegion *shape, const gchar *name) { gint32 image; gint32 layer; gdouble xres, yres; gchar *comment; gint width, height; gboolean status; status = gimp_progress_init (_("Importing screenshot")); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); image = gimp_image_new (width, height, GIMP_RGB); gimp_image_undo_disable (image); gimp_get_monitor_resolution (&xres, &yres); gimp_image_set_resolution (image, xres, yres); comment = gimp_get_default_comment (); if (comment) { GimpParasite *parasite; parasite = gimp_parasite_new ("gimp-comment", GIMP_PARASITE_PERSISTENT, strlen (comment) + 1, comment); gimp_image_parasite_attach (image, parasite); gimp_parasite_free (parasite); g_free (comment); } layer = gimp_layer_new_from_pixbuf (image, name ? name : _("Screenshot"), pixbuf, 100, GIMP_NORMAL_MODE, 0.0, 1.0); gimp_image_add_layer (image, layer, 0); if (shape && ! gdk_region_empty (shape)) { image_select_shape (image, shape); if (! gimp_selection_is_empty (image)) { gimp_layer_add_alpha (layer); gimp_edit_clear (layer); gimp_selection_none (image); } } gimp_image_undo_enable (image); return image; }
void edit_clear_cmd_callback (GtkAction *action, gpointer data) { GimpImage *image; GimpDrawable *drawable; return_if_no_drawable (image, drawable, data); gimp_edit_clear (image, drawable, action_data_get_context (data)); gimp_image_flush (image); }
/* -------------------------- * p_create_corpus_layer * -------------------------- * create the corpus layer that builds the reference pattern * for the resynthesizer call. The reference pattern is built * as duplicate of the original image reduced to the area around the current selection. * (grown by corpus_border_radius) * Note that the duplicate image has a selection, that includes the gorwn area * around the orignal selection, but EXCLUDES the original selection * (that is the area holding the object that has to be replaced * by pattern of the surrounding area) * returns the layer_id of the reference pattern. */ static gint32 p_create_corpus_layer(gint32 image_id, gint32 drawable_id, TransValues *val_ptr) { gint32 dup_image_id; gint32 channel_id; gint32 channel_2_id; GimpRGB bck_color; GimpRGB white_opaque_color; /* gboolean has_selection; */ gboolean non_empty; gint x1, y1, x2, y2; gint32 active_layer_stackposition; gint32 active_dup_layer_id; active_layer_stackposition = gap_layer_get_stackposition(image_id, drawable_id); dup_image_id = gimp_image_duplicate(image_id); channel_id = gimp_selection_save(dup_image_id); gimp_selection_grow(dup_image_id, val_ptr->corpus_border_radius); gimp_selection_invert(dup_image_id); gimp_context_get_background(&bck_color); channel_2_id = gimp_selection_save(dup_image_id); gimp_image_select_item(dup_image_id, GIMP_CHANNEL_OP_REPLACE, channel_id); gimp_rgba_set_uchar (&white_opaque_color, 255, 255, 255, 255); gimp_context_set_background(&white_opaque_color); gimp_edit_clear(channel_2_id); gimp_context_set_background(&bck_color); /* restore original background color */ gimp_selection_load(channel_2_id); gimp_selection_invert(dup_image_id); /* has_selection = */ gimp_selection_bounds(dup_image_id, &non_empty, &x1, &y1, &x2, &y2); gimp_image_crop(dup_image_id, (x2 - x1), (y2 - y1), x1, y1); gimp_selection_invert(dup_image_id); active_dup_layer_id = gap_layer_get_id_by_stackposition(dup_image_id, active_layer_stackposition); if (1==0) { /* debug code shows the duplicate image by adding a display */ gimp_display_new(dup_image_id); } return (active_dup_layer_id); } /* end p_create_corpus_layer */
static void export_merge (gint32 image_ID, gint32 *drawable_ID) { gint32 nlayers; gint32 nvisible = 0; gint32 i; gint32 *layers; gint32 merged; gint32 transp; layers = gimp_image_get_layers (image_ID, &nlayers); for (i = 0; i < nlayers; i++) { if (gimp_item_get_visible (layers[i])) nvisible++; } if (nvisible <= 1) { /* if there is only one (or zero) visible layer, add a new transparent layer that has the same size as the canvas. The merge that follows will ensure that the offset, opacity and size are correct */ transp = gimp_layer_new (image_ID, "-", gimp_image_width (image_ID), gimp_image_height (image_ID), gimp_drawable_type (*drawable_ID) | 1, 100.0, GIMP_NORMAL_MODE); gimp_image_insert_layer (image_ID, transp, -1, 1); gimp_selection_none (image_ID); gimp_edit_clear (transp); nvisible++; } if (nvisible > 1) { g_free (layers); merged = gimp_image_merge_visible_layers (image_ID, GIMP_CLIP_TO_IMAGE); if (merged != -1) *drawable_ID = merged; else return; /* shouldn't happen */ layers = gimp_image_get_layers (image_ID, &nlayers); /* make sure that the merged drawable matches the image size */ if (gimp_drawable_width (merged) != gimp_image_width (image_ID) || gimp_drawable_height (merged) != gimp_image_height (image_ID)) { gint off_x, off_y; gimp_drawable_offsets (merged, &off_x, &off_y); gimp_layer_resize (merged, gimp_image_width (image_ID), gimp_image_height (image_ID), off_x, off_y); } } /* remove any remaining (invisible) layers */ for (i = 0; i < nlayers; i++) { if (layers[i] != *drawable_ID) gimp_image_remove_layer (image_ID, layers[i]); } g_free (layers); }