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; }
static void gimp_display_shell_drop_pixbuf (GtkWidget *widget, gint x, gint y, GdkPixbuf *pixbuf, gpointer data) { GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data); GimpImage *image = gimp_display_get_image (shell->display); GimpLayer *new_layer; gboolean has_alpha = FALSE; GIMP_LOG (DND, NULL); if (shell->display->gimp->busy) return; if (! image) { image = gimp_image_new_from_pixbuf (shell->display->gimp, pixbuf, _("Dropped Buffer")); gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0, G_OBJECT (gtk_widget_get_screen (widget)), gimp_widget_get_monitor (widget)); g_object_unref (image); return; } if (gdk_pixbuf_get_n_channels (pixbuf) == 2 || gdk_pixbuf_get_n_channels (pixbuf) == 4) { has_alpha = TRUE; } new_layer = gimp_layer_new_from_pixbuf (pixbuf, image, gimp_image_get_layer_format (image, has_alpha), _("Dropped Buffer"), GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); if (new_layer) { GimpItem *new_item = GIMP_ITEM (new_layer); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE, _("Drop New Layer")); gimp_display_shell_dnd_position_item (shell, image, new_item); gimp_image_add_layer (image, new_layer, GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE); gimp_image_undo_group_end (image); gimp_display_shell_dnd_flush (shell, image); } }
static gint32 layer_from_pixbuf (gint32 image, const gchar *layer_name, gint position, GdkPixbuf *pixbuf, gdouble progress_start, gdouble progress_scale) { gint32 layer = gimp_layer_new_from_pixbuf (image, layer_name, pixbuf, 100.0, GIMP_NORMAL_MODE, progress_start, progress_start + progress_scale); gimp_image_insert_layer (image, layer, -1, position); return layer; }
static gint32 load_image (const gchar *filename, GError **load_error) { gint32 image; gint32 layer; GdkPixbuf *pixbuf; gint width; gint height; GError *error = NULL; pixbuf = load_rsvg_pixbuf (filename, &load_vals, &error); if (! pixbuf) { /* Do not rely on librsvg setting GError on failure! */ g_set_error (load_error, error ? error->domain : 0, error ? error->code : 0, _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (filename), error ? error->message : _("Unknown reason")); g_clear_error (&error); return -1; } gimp_progress_init (_("Rendering SVG")); 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_image_set_filename (image, filename); gimp_image_set_resolution (image, load_vals.resolution, load_vals.resolution); layer = gimp_layer_new_from_pixbuf (image, _("Rendered SVG"), pixbuf, 100, GIMP_NORMAL_MODE, 0.0, 1.0); gimp_image_insert_layer (image, layer, -1, 0); gimp_image_undo_enable (image); return image; }
static void gimp_display_shell_drop_pixbuf (GtkWidget *widget, gint x, gint y, GdkPixbuf *pixbuf, gpointer data) { GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data); GimpImage *image = shell->display->image; GimpLayer *new_layer; GimpImageType image_type; gboolean new_image = FALSE; GIMP_LOG (DND, NULL); if (shell->display->gimp->busy) return; switch (gdk_pixbuf_get_n_channels (pixbuf)) { case 1: image_type = GIMP_GRAY_IMAGE; break; case 2: image_type = GIMP_GRAYA_IMAGE; break; case 3: image_type = GIMP_RGB_IMAGE; break; case 4: image_type = GIMP_RGBA_IMAGE; break; break; default: g_return_if_reached (); break; } if (! image) { image = gimp_create_image (shell->display->gimp, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), GIMP_IMAGE_TYPE_BASE_TYPE (image_type), FALSE); gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0); g_object_unref (image); gimp_image_undo_disable (image); new_image = TRUE; } new_layer = gimp_layer_new_from_pixbuf (pixbuf, image, image_type, _("Dropped Buffer"), GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); if (new_layer) { GimpItem *new_item = GIMP_ITEM (new_layer); new_item = GIMP_ITEM (new_layer); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE, _("Drop New Layer")); if (! new_image) gimp_display_shell_dnd_position_item (shell, new_item); gimp_image_add_layer (image, new_layer, -1); gimp_image_undo_group_end (image); gimp_display_shell_dnd_flush (shell, image); } if (new_image) gimp_image_undo_enable (image); }
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); } }
static gint32 webpage_capture (void) { gint32 image = -1; gchar *scheme; GtkWidget *window; GtkWidget *view; WebKitWebSettings *settings; char *ua_old; char *ua; if (webpagevals.pixbuf) { g_object_unref (webpagevals.pixbuf); webpagevals.pixbuf = NULL; } if (webpagevals.error) { g_error_free (webpagevals.error); webpagevals.error = NULL; } if ((!webpagevals.url) || (strlen (webpagevals.url) == 0)) { g_set_error (&webpagevals.error, 0, 0, _("No URL was specified")); return -1; } scheme = g_uri_parse_scheme (webpagevals.url); if (!scheme) { char *url; /* If we were not given a well-formed URL, make one. */ url = g_strconcat ("http://", webpagevals.url, NULL); g_free (webpagevals.url); webpagevals.url = url; g_free (scheme); } if (webpagevals.width < 32) { g_warning ("Width '%d' is too small. Clamped to 32.", webpagevals.width); webpagevals.width = 32; } else if (webpagevals.width > 8192) { g_warning ("Width '%d' is too large. Clamped to 8192.", webpagevals.width); webpagevals.width = 8192; } window = gtk_offscreen_window_new (); gtk_widget_show (window); view = webkit_web_view_new (); gtk_widget_show (view); gtk_widget_set_size_request (view, webpagevals.width, -1); gtk_container_add (GTK_CONTAINER (window), view); /* Append "GIMP/<GIMP_VERSION>" to the user agent string */ settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (view)); g_object_get (settings, "user-agent", &ua_old, NULL); ua = g_strdup_printf ("%s GIMP/%s", ua_old, GIMP_VERSION); g_object_set (settings, "user-agent", ua, NULL); g_free (ua_old); g_free (ua); /* Set font size */ g_object_set (settings, "default-font-size", webpagevals.font_size, NULL); g_signal_connect (view, "notify::progress", G_CALLBACK (notify_progress_cb), window); g_signal_connect (view, "load-error", G_CALLBACK (load_error_cb), window); g_signal_connect (view, "notify::load-status", G_CALLBACK (notify_load_status_cb), window); gimp_progress_init_printf (_("Downloading webpage '%s'"), webpagevals.url); webkit_web_view_open (WEBKIT_WEB_VIEW (view), webpagevals.url); gtk_main (); gtk_widget_destroy (window); gimp_progress_update (1.0); if (webpagevals.pixbuf) { gint width; gint height; gint32 layer; gimp_progress_init_printf (_("Transferring webpage image for '%s'"), webpagevals.url); width = gdk_pixbuf_get_width (webpagevals.pixbuf); height = gdk_pixbuf_get_height (webpagevals.pixbuf); image = gimp_image_new (width, height, GIMP_RGB); gimp_image_undo_disable (image); layer = gimp_layer_new_from_pixbuf (image, _("Webpage"), webpagevals.pixbuf, 100, GIMP_NORMAL_MODE, 0.0, 1.0); gimp_image_insert_layer (image, layer, -1, 0); gimp_image_undo_enable (image); g_object_unref (webpagevals.pixbuf); webpagevals.pixbuf = NULL; gimp_progress_update (1.0); } return image; }