void edit_paste_as_new_layer_cmd_callback (GtkAction *action, gpointer data) { Gimp *gimp; GimpImage *image; GimpBuffer *buffer; return_if_no_gimp (gimp, data); return_if_no_image (image, data); buffer = gimp_clipboard_get_buffer (gimp); if (buffer) { GimpLayer *layer; layer = gimp_layer_new_from_buffer (gimp_buffer_get_buffer (buffer), image, gimp_image_get_layer_format (image, TRUE), _("Clipboard"), GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); g_object_unref (buffer); gimp_image_add_layer (image, layer, GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE); gimp_image_flush (image); } else { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING, _("There is no image data in the clipboard to paste.")); } }
/** * gimp_layer_new_from_buffer: * @buffer: The buffer to make the new layer from. * @dest_image: The image the new layer will be added to. * @format: The #Babl format of the new layer. * @name: The new layer's name. * @opacity: The new layer's opacity. * @mode: The new layer's mode. * * Copies %buffer to a layer taking into consideration the * possibility of transforming the contents to meet the requirements * of the target image type * * Return value: The new layer. **/ GimpLayer * gimp_layer_new_from_buffer (GimpBuffer *buffer, GimpImage *dest_image, const Babl *format, const gchar *name, gdouble opacity, GimpLayerModeEffects mode) { g_return_val_if_fail (GIMP_IS_BUFFER (buffer), NULL); g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL); g_return_val_if_fail (format != NULL, NULL); return gimp_layer_new_from_gegl_buffer (gimp_buffer_get_buffer (buffer), dest_image, format, name, opacity, mode, gimp_buffer_get_color_profile (buffer)); }
/** * gimp_seamless_clone_tool_start: * @sc: The GimpSeamlessCloneTool to initialize for usage on the given * display * @display: The display to initialize the tool for * * A utility function to initialize a tool for working on a given * display. At the beginning of each function, we can check if the event's * display is the same as the tool's one, and if not call this. This is * not required by the gimptool interface or anything like that, but * this is a convenient way to do all the initialization work in one * place, and this is how the base class (GimpDrawTool) does that */ static void gimp_seamless_clone_tool_start (GimpSeamlessCloneTool *sc, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (sc); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); /* First handle the paste - we need to make sure we have one in order * to do anything else. */ if (sc->paste == NULL) { GimpBuffer *buffer = gimp_clipboard_get_buffer (tool->tool_info->gimp); if (! buffer) { gimp_tool_push_status (tool, display, "%s", _("There is no image data in the clipboard to paste.")); return; } sc->paste = gegl_buffer_dup (gimp_buffer_get_buffer (buffer)); g_object_unref (buffer); sc->width = gegl_buffer_get_width (sc->paste); sc->height = gegl_buffer_get_height (sc->paste); } /* Free resources which are relevant only for the previous display */ gimp_seamless_clone_tool_stop (sc, TRUE); tool->display = display; gimp_seamless_clone_tool_create_filter (sc, drawable); gimp_draw_tool_start (GIMP_DRAW_TOOL (sc), display); sc->tool_state = SC_STATE_RENDER_WAIT; }
static void gimp_pattern_clipboard_buffer_changed (Gimp *gimp, GimpPattern *pattern) { if (pattern->mask) { gimp_temp_buf_unref (pattern->mask); pattern->mask = NULL; } if (gimp->global_buffer) { GimpBuffer *buffer = gimp->global_buffer; gint width; gint height; width = MIN (gimp_buffer_get_width (buffer), 2048); height = MIN (gimp_buffer_get_height (buffer), 2048); pattern->mask = gimp_temp_buf_new (width, height, gimp_buffer_get_format (buffer)); gegl_buffer_get (gimp_buffer_get_buffer (buffer), GEGL_RECTANGLE (0, 0, width, height), 1.0, NULL, gimp_temp_buf_get_data (pattern->mask), GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); } else { pattern->mask = gimp_temp_buf_new (16, 16, babl_format ("R'G'B' u8")); memset (gimp_temp_buf_get_data (pattern->mask), 255, 16 * 16 * 3); } gimp_data_dirty (GIMP_DATA (pattern)); }
static void gimp_brush_clipboard_buffer_changed (Gimp *gimp, GimpBrush *brush) { gint width; gint height; if (brush->mask) { gimp_temp_buf_unref (brush->mask); brush->mask = NULL; } if (brush->pixmap) { gimp_temp_buf_unref (brush->pixmap); brush->pixmap = NULL; } if (gimp->global_buffer) { GeglBuffer *buffer = gimp_buffer_get_buffer (gimp->global_buffer); const Babl *format = gegl_buffer_get_format (buffer); GeglBuffer *dest_buffer; width = MIN (gimp_buffer_get_width (gimp->global_buffer), 512); height = MIN (gimp_buffer_get_height (gimp->global_buffer), 512); brush->mask = gimp_temp_buf_new (width, height, babl_format ("Y u8")); brush->pixmap = gimp_temp_buf_new (width, height, babl_format ("R'G'B' u8")); /* copy the alpha channel into the brush's mask */ if (babl_format_has_alpha (format)) { dest_buffer = gimp_temp_buf_create_buffer (brush->mask); gegl_buffer_set_format (dest_buffer, babl_format ("A u8")); gegl_buffer_copy (buffer, NULL, dest_buffer, NULL); g_object_unref (dest_buffer); } else { memset (gimp_temp_buf_get_data (brush->mask), 255, width * height); } /* copy the color channels into the brush's pixmap */ dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap); gegl_buffer_copy (buffer, NULL, dest_buffer, NULL); g_object_unref (dest_buffer); } else { width = 17; height = 17; brush->mask = gimp_temp_buf_new (width, height, babl_format ("Y u8")); gimp_temp_buf_data_clear (brush->mask); } brush->x_axis.x = width / 2; brush->x_axis.y = 0; brush->y_axis.x = 0; brush->y_axis.y = height / 2; gimp_data_dirty (GIMP_DATA (brush)); }