/* ============================================================================ * gap_image_delete_immediate * delete image (with workaround to ensure that most of the * allocatd memory is freed) * ============================================================================ * The workaround disables undo and scales the image down to miniumum size * before calling the gimp_image_delete procedure. * this way memory resources for big layers will be freed up immediate. */ void gap_image_delete_immediate (gint32 image_id) { gboolean imageDeleteWorkaroundDefault = TRUE; if(gap_base_get_gimprc_gboolean_value("gap-image-delete-workaround" , imageDeleteWorkaroundDefault)) { if(gap_debug) { printf("gap_image_delete_immediate: SCALED down to 2x2 id = %d (workaround for gimp_image-delete problem)\n" , (int)image_id ); } gimp_image_undo_disable(image_id); //gimp_image_scale_full(image_id, 2, 2, 0 /*INTERPOLATION_NONE*/); gimp_context_push(); gimp_context_set_interpolation(0); gimp_image_scale(image_id, 2, 2); gimp_context_pop(); gimp_image_undo_enable(image_id); /* clear undo stack */ } gimp_image_delete(image_id); } /* end gap_image_delete_immediate */
static void file_open_handle_color_profile (GimpImage *image, GimpContext *context, GimpProgress *progress, GimpRunMode run_mode) { if (gimp_image_get_icc_parasite (image)) { gimp_image_undo_disable (image); switch (image->gimp->config->color_profile_policy) { case GIMP_COLOR_PROFILE_POLICY_ASK: if (run_mode == GIMP_RUN_INTERACTIVE) file_open_profile_apply_rgb (image, context, progress, GIMP_RUN_INTERACTIVE); break; case GIMP_COLOR_PROFILE_POLICY_KEEP: break; case GIMP_COLOR_PROFILE_POLICY_CONVERT: file_open_profile_apply_rgb (image, context, progress, GIMP_RUN_NONINTERACTIVE); break; } gimp_image_clean_all (image); gimp_image_undo_enable (image); } }
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 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; }
/* --------------------------------------- * gap_track_detail_on_top_layers_lastvals * --------------------------------------- * processing based on last values used in the same gimp session. * (uses defaults when called the 1.st time) * Intended for use in the player */ gint32 gap_track_detail_on_top_layers_lastvals(gint32 imageId) { gint32 rc; gboolean doProgress; FilterValues fiVals; /* clear undo stack */ if (gimp_image_undo_is_enabled(imageId)) { gimp_image_undo_disable(imageId); } doProgress = FALSE; gap_detail_tracking_get_values(&fiVals); rc = gap_track_detail_on_top_layers(imageId, doProgress, &fiVals); gimp_image_undo_enable(imageId); /* clear undo stack */ return(rc); } /* end gap_track_detail_on_top_layers_lastvals */
static GValueArray * image_undo_enable_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args, GError **error) { gboolean success = TRUE; GValueArray *return_vals; GimpImage *image; gboolean enabled = FALSE; image = gimp_value_get_image (&args->values[0], gimp); if (success) { #if 0 GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; if (plug_in) success = gimp_plug_in_cleanup_undo_enable (plug_in, image); #endif if (success) enabled = gimp_image_undo_enable (image); } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) g_value_set_boolean (&return_vals->values[1], enabled); return return_vals; }
static void snapshot_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { WebKitWebView *view = WEBKIT_WEB_VIEW (source_object); cairo_surface_t *surface; surface = webkit_web_view_get_snapshot_finish (view, result, &webpagevals.error); if (surface) { gint width; gint height; gint32 layer; width = cairo_image_surface_get_width (surface); height = cairo_image_surface_get_height (surface); webpagevals.image = gimp_image_new (width, height, GIMP_RGB); gimp_image_undo_disable (webpagevals.image); layer = gimp_layer_new_from_surface (webpagevals.image, _("Webpage"), surface, 0.25, 1.0); gimp_image_insert_layer (webpagevals.image, layer, -1, 0); gimp_image_undo_enable (webpagevals.image); cairo_surface_destroy (surface); } gimp_progress_update (1.0); gtk_main_quit (); }
static void gimp_display_shell_drop_drawable (GtkWidget *widget, gint x, gint y, GimpViewable *viewable, gpointer data) { GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data); GimpImage *image = shell->display->image; GType new_type; GimpItem *new_item; gboolean new_image = FALSE; GIMP_LOG (DND, NULL); if (shell->display->gimp->busy) return; if (! image) { GimpImage *src_image = gimp_item_get_image (GIMP_ITEM (viewable)); GimpDrawable *drawable = GIMP_DRAWABLE (viewable); GimpImageBaseType type; gdouble xres; gdouble yres; type = GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)); image = gimp_create_image (shell->display->gimp, gimp_item_width (GIMP_ITEM (viewable)), gimp_item_height (GIMP_ITEM (viewable)), type, TRUE); gimp_image_undo_disable (image); if (type == GIMP_INDEXED) gimp_image_set_colormap (image, gimp_image_get_colormap (src_image), gimp_image_get_colormap_size (src_image), FALSE); gimp_image_get_resolution (src_image, &xres, &yres); gimp_image_set_resolution (image, xres, yres); gimp_image_set_unit (image, gimp_image_get_unit (src_image)); gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0); g_object_unref (image); new_image = TRUE; } if (GIMP_IS_LAYER (viewable)) new_type = G_TYPE_FROM_INSTANCE (viewable); else new_type = GIMP_TYPE_LAYER; new_item = gimp_item_convert (GIMP_ITEM (viewable), image, new_type); if (new_item) { GimpLayer *new_layer = GIMP_LAYER (new_item); 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_item_set_visible (new_item, TRUE, FALSE); gimp_item_set_linked (new_item, FALSE, FALSE); 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 run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[MAX_EXTRACT_IMAGES + 1]; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 num_images; gint32 image_ID_extract[MAX_EXTRACT_IMAGES]; gint32 layer_ID_extract[MAX_EXTRACT_IMAGES]; gint j; gint32 layer; gint32 num_layers; gint32 image_ID; INIT_I18N (); run_mode = param[0].data.d_int32; image_ID = param[1].data.d_image; layer = param[2].data.d_drawable; *nreturn_vals = MAX_EXTRACT_IMAGES+1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; for (j = 0; j < MAX_EXTRACT_IMAGES; j++) { values[j+1].type = GIMP_PDB_IMAGE; values[j+1].data.d_int32 = -1; } switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &decovals); /* First acquire information with a dialog */ if (! decompose_dialog ()) return; break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ if (nparams != 4 && nparams != 5 && nparams != 6) { status = GIMP_PDB_CALLING_ERROR; } else { strncpy (decovals.extract_type, param[3].data.d_string, sizeof (decovals.extract_type)); decovals.extract_type[sizeof (decovals.extract_type)-1] = '\0'; decovals.as_layers = nparams > 4 ? param[4].data.d_int32 : FALSE; decovals.use_registration = (strcmp (name, PLUG_IN_PROC_REG) == 0); } break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &decovals); break; default: break; } /* Make sure that the drawable is RGB color */ if (gimp_drawable_type_with_alpha (layer) != GIMP_RGBA_IMAGE) { g_message ("Can only work on RGB images."); status = GIMP_PDB_CALLING_ERROR; } if (status == GIMP_PDB_SUCCESS) { gimp_progress_init (_("Decomposing")); num_images = decompose (image_ID, layer, decovals.extract_type, image_ID_extract, &num_layers, layer_ID_extract); if (num_images <= 0) { status = GIMP_PDB_EXECUTION_ERROR; } else { /* create decompose-data parasite */ GString *data = g_string_new (""); g_string_printf (data, "source=%d type=%s ", layer, decovals.extract_type); for (j = 0; j < num_layers; j++) g_string_append_printf (data, "%d ", layer_ID_extract[j]); for (j = 0; j < num_images; j++) { values[j+1].data.d_int32 = image_ID_extract[j]; gimp_image_undo_enable (image_ID_extract[j]); gimp_image_clean_all (image_ID_extract[j]); gimp_image_attach_new_parasite (image_ID_extract[j], "decompose-data", 0, data->len + 1, data->str); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_display_new (image_ID_extract[j]); } /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &decovals, sizeof (DecoVals)); } } values[0].data.d_status = status; }
static gint32 tile (gint32 image_id, gint32 drawable_id, gint32 *layer_id) { GimpPixelRgn src_rgn; GimpPixelRgn dest_rgn; GimpDrawable *drawable; GimpDrawable *new_layer; GimpImageBaseType image_type = GIMP_RGB; gint32 new_image_id = 0; gint old_width; gint old_height; gint i, j; gint progress; gint max_progress; gpointer pr; /* sanity check parameters */ if (tvals.new_width < 1 || tvals.new_height < 1) { *layer_id = -1; return -1; } /* initialize */ old_width = gimp_drawable_width (drawable_id); old_height = gimp_drawable_height (drawable_id); if (tvals.new_image) { /* create a new image */ switch (gimp_drawable_type (drawable_id)) { case GIMP_RGB_IMAGE: case GIMP_RGBA_IMAGE: image_type = GIMP_RGB; break; case GIMP_GRAY_IMAGE: case GIMP_GRAYA_IMAGE: image_type = GIMP_GRAY; break; case GIMP_INDEXED_IMAGE: case GIMP_INDEXEDA_IMAGE: image_type = GIMP_INDEXED; break; } new_image_id = gimp_image_new (tvals.new_width, tvals.new_height, image_type); gimp_image_undo_disable (new_image_id); *layer_id = gimp_layer_new (new_image_id, _("Background"), tvals.new_width, tvals.new_height, gimp_drawable_type (drawable_id), 100, GIMP_NORMAL_MODE); if (*layer_id == -1) return -1; gimp_image_insert_layer (new_image_id, *layer_id, -1, 0); new_layer = gimp_drawable_get (*layer_id); /* Get the source drawable */ drawable = gimp_drawable_get (drawable_id); } else { gimp_image_undo_group_start (image_id); gimp_image_resize (image_id, tvals.new_width, tvals.new_height, 0, 0); if (gimp_item_is_layer (drawable_id)) gimp_layer_resize (drawable_id, tvals.new_width, tvals.new_height, 0, 0); /* Get the source drawable */ drawable = gimp_drawable_get (drawable_id); new_layer = drawable; } /* progress */ progress = 0; max_progress = tvals.new_width * tvals.new_height; /* tile... */ for (i = 0; i < tvals.new_height; i += old_height) { gint height = old_height; if (height + i > tvals.new_height) height = tvals.new_height - i; for (j = 0; j < tvals.new_width; j += old_width) { gint width = old_width; gint c; if (width + j > tvals.new_width) width = tvals.new_width - j; gimp_pixel_rgn_init (&src_rgn, drawable, 0, 0, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&dest_rgn, new_layer, j, i, width, height, TRUE, FALSE); for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn), c = 0; pr != NULL; pr = gimp_pixel_rgns_process (pr), c++) { gint k; for (k = 0; k < src_rgn.h; k++) memcpy (dest_rgn.data + k * dest_rgn.rowstride, src_rgn.data + k * src_rgn.rowstride, src_rgn.w * src_rgn.bpp); progress += src_rgn.w * src_rgn.h; if (c % 16 == 0) gimp_progress_update ((gdouble) progress / (gdouble) max_progress); } } } gimp_drawable_update (new_layer->drawable_id, 0, 0, new_layer->width, new_layer->height); gimp_drawable_detach (drawable); if (tvals.new_image) { gimp_drawable_detach (new_layer); /* copy the colormap, if necessary */ if (image_type == GIMP_INDEXED) { guchar *cmap; gint ncols; cmap = gimp_image_get_colormap (image_id, &ncols); gimp_image_set_colormap (new_image_id, cmap, ncols); g_free (cmap); } gimp_image_undo_enable (new_image_id); } else { gimp_image_undo_group_end (image_id); } return new_image_id; }
GimpImage * gimp_image_duplicate (GimpImage *image) { GimpImage *new_image; GimpLayer *active_layer; GimpChannel *active_channel; GimpVectors *active_vectors; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); gimp_set_busy_until_idle (image->gimp); /* Create a new image */ new_image = gimp_create_image (image->gimp, gimp_image_get_width (image), gimp_image_get_height (image), gimp_image_get_base_type (image), gimp_image_get_precision (image), FALSE); gimp_image_undo_disable (new_image); /* Store the source uri to be used by the save dialog */ gimp_image_duplicate_save_source_uri (image, new_image); /* Copy the colormap if necessary */ gimp_image_duplicate_colormap (image, new_image); /* Copy resolution information */ gimp_image_duplicate_resolution (image, new_image); /* Copy the layers */ active_layer = gimp_image_duplicate_layers (image, new_image); /* Copy the channels */ active_channel = gimp_image_duplicate_channels (image, new_image); /* Copy any vectors */ active_vectors = gimp_image_duplicate_vectors (image, new_image); /* Copy floating layer */ gimp_image_duplicate_floating_sel (image, new_image); /* Copy the selection mask */ gimp_image_duplicate_mask (image, new_image); /* Set active layer, active channel, active vectors */ if (active_layer) gimp_image_set_active_layer (new_image, active_layer); if (active_channel) gimp_image_set_active_channel (new_image, active_channel); if (active_vectors) gimp_image_set_active_vectors (new_image, active_vectors); /* Copy state of all color components */ gimp_image_duplicate_components (image, new_image); /* Copy any guides */ gimp_image_duplicate_guides (image, new_image); /* Copy any sample points */ gimp_image_duplicate_sample_points (image, new_image); /* Copy the grid */ gimp_image_duplicate_grid (image, new_image); /* Copy the quick mask info */ gimp_image_duplicate_quick_mask (image, new_image); /* Copy parasites */ gimp_image_duplicate_parasites (image, new_image); gimp_image_undo_enable (new_image); return new_image; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[2]; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 image_ID; gint k; INIT_I18N (); run_mode = param[0].data.d_int32; *nreturn_vals = 2; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; values[1].type = GIMP_PDB_IMAGE; values[1].data.d_int32 = -1; switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &filmvals); /* First acquire information with a dialog */ if (! film_dialog (param[1].data.d_int32)) return; break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ /* Also we want to have some images to compose */ if ((nparams != 12) || (param[10].data.d_int32 < 1)) { status = GIMP_PDB_CALLING_ERROR; } else { filmvals.keep_height = (param[3].data.d_int32 <= 0); filmvals.film_height = (filmvals.keep_height ? 128 : param[3].data.d_int32); filmvals.film_color = param[4].data.d_color; filmvals.number_start = param[5].data.d_int32; g_strlcpy (filmvals.number_font, param[6].data.d_string, FONT_LEN); filmvals.number_color = param[7].data.d_color; filmvals.number_pos[0] = param[8].data.d_int32; filmvals.number_pos[1] = param[9].data.d_int32; filmvals.num_images = param[10].data.d_int32; if (filmvals.num_images > MAX_FILM_PICTURES) filmvals.num_images = MAX_FILM_PICTURES; for (k = 0; k < filmvals.num_images; k++) filmvals.image[k] = param[11].data.d_int32array[k]; } break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &filmvals); break; default: break; } if (! check_filmvals ()) status = GIMP_PDB_CALLING_ERROR; if (status == GIMP_PDB_SUCCESS) { gimp_progress_init (_("Composing images")); image_ID = film (); if (image_ID < 0) { status = GIMP_PDB_EXECUTION_ERROR; } else { values[1].data.d_int32 = image_ID; gimp_image_undo_enable (image_ID); gimp_image_clean_all (image_ID); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_display_new (image_ID); } /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &filmvals, sizeof (FilmVals)); } values[0].data.d_status = status; }
GimpImage * gimp_image_duplicate (GimpImage *image) { GimpImage *new_image; GimpLayer *floating_layer; GList *list; GimpLayer *active_layer = NULL; GimpChannel *active_channel = NULL; GimpVectors *active_vectors = NULL; GimpDrawable *new_floating_sel_drawable = NULL; GimpDrawable *floating_sel_drawable = NULL; gchar *filename; gint count; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); gimp_set_busy_until_idle (image->gimp); /* Create a new image */ new_image = gimp_create_image (image->gimp, image->width, image->height, image->base_type, FALSE); gimp_image_undo_disable (new_image); /* Store the folder to be used by the save dialog */ filename = gimp_image_get_filename (image); if (filename) { g_object_set_data_full (G_OBJECT (new_image), "gimp-image-dirname", g_path_get_dirname (filename), (GDestroyNotify) g_free); g_free (filename); } /* Copy the colormap if necessary */ if (new_image->base_type == GIMP_INDEXED) gimp_image_set_colormap (new_image, gimp_image_get_colormap (image), gimp_image_get_colormap_size (image), FALSE); /* Copy resolution information */ new_image->xresolution = image->xresolution; new_image->yresolution = image->yresolution; new_image->resolution_unit = image->resolution_unit; /* Copy floating layer */ floating_layer = gimp_image_floating_sel (image); if (floating_layer) { floating_sel_relax (floating_layer, FALSE); floating_sel_drawable = floating_layer->fs.drawable; floating_layer = NULL; } /* Copy the layers */ for (list = GIMP_LIST (image->layers)->list, count = 0; list; list = g_list_next (list)) { GimpLayer *layer = list->data; GimpLayer *new_layer; new_layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (layer), new_image, G_TYPE_FROM_INSTANCE (layer), FALSE)); /* Make sure the copied layer doesn't say: "<old layer> copy" */ gimp_object_set_name (GIMP_OBJECT (new_layer), gimp_object_get_name (GIMP_OBJECT (layer))); /* Make sure that if the layer has a layer mask, * its name isn't screwed up */ if (new_layer->mask) gimp_object_set_name (GIMP_OBJECT (new_layer->mask), gimp_object_get_name (GIMP_OBJECT (layer->mask))); if (gimp_image_get_active_layer (image) == layer) active_layer = new_layer; if (image->floating_sel == layer) floating_layer = new_layer; if (floating_sel_drawable == GIMP_DRAWABLE (layer)) new_floating_sel_drawable = GIMP_DRAWABLE (new_layer); if (floating_layer != new_layer) gimp_image_add_layer (new_image, new_layer, count++); } /* Copy the channels */ for (list = GIMP_LIST (image->channels)->list, count = 0; list; list = g_list_next (list)) { GimpChannel *channel = list->data; GimpChannel *new_channel; new_channel = GIMP_CHANNEL (gimp_item_convert (GIMP_ITEM (channel), new_image, G_TYPE_FROM_INSTANCE (channel), FALSE)); /* Make sure the copied channel doesn't say: "<old channel> copy" */ gimp_object_set_name (GIMP_OBJECT (new_channel), gimp_object_get_name (GIMP_OBJECT (channel))); if (gimp_image_get_active_channel (image) == channel) active_channel = (new_channel); if (floating_sel_drawable == GIMP_DRAWABLE (channel)) new_floating_sel_drawable = GIMP_DRAWABLE (new_channel); gimp_image_add_channel (new_image, new_channel, count++); } /* Copy any vectors */ for (list = GIMP_LIST (image->vectors)->list, count = 0; list; list = g_list_next (list)) { GimpVectors *vectors = list->data; GimpVectors *new_vectors; new_vectors = GIMP_VECTORS (gimp_item_convert (GIMP_ITEM (vectors), new_image, G_TYPE_FROM_INSTANCE (vectors), FALSE)); /* Make sure the copied vectors doesn't say: "<old vectors> copy" */ gimp_object_set_name (GIMP_OBJECT (new_vectors), gimp_object_get_name (GIMP_OBJECT (vectors))); if (gimp_image_get_active_vectors (image) == vectors) active_vectors = new_vectors; gimp_image_add_vectors (new_image, new_vectors, count++); } /* Copy the selection mask */ { TileManager *src_tiles; TileManager *dest_tiles; PixelRegion srcPR, destPR; src_tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (image->selection_mask)); dest_tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (new_image->selection_mask)); pixel_region_init (&srcPR, src_tiles, 0, 0, image->width, image->height, FALSE); pixel_region_init (&destPR, dest_tiles, 0, 0, image->width, image->height, TRUE); copy_region (&srcPR, &destPR); new_image->selection_mask->bounds_known = FALSE; new_image->selection_mask->boundary_known = FALSE; } if (floating_layer) floating_sel_attach (floating_layer, new_floating_sel_drawable); /* Set active layer, active channel, active vectors */ if (active_layer) gimp_image_set_active_layer (new_image, active_layer); if (active_channel) gimp_image_set_active_channel (new_image, active_channel); if (active_vectors) gimp_image_set_active_vectors (new_image, active_vectors); /* Copy state of all color channels */ for (count = 0; count < MAX_CHANNELS; count++) { new_image->visible[count] = image->visible[count]; new_image->active[count] = image->active[count]; } /* Copy any guides */ for (list = image->guides; list; list = g_list_next (list)) { GimpGuide *guide = list->data; gint position = gimp_guide_get_position (guide); switch (gimp_guide_get_orientation (guide)) { case GIMP_ORIENTATION_HORIZONTAL: gimp_image_add_hguide (new_image, position, FALSE); break; case GIMP_ORIENTATION_VERTICAL: gimp_image_add_vguide (new_image, position, FALSE); break; default: g_error ("Unknown guide orientation.\n"); } } /* Copy any sample points */ for (list = image->sample_points; list; list = g_list_next (list)) { GimpSamplePoint *sample_point = list->data; gimp_image_add_sample_point_at_pos (new_image, sample_point->x, sample_point->y, FALSE); } /* Copy the grid */ if (image->grid) gimp_image_set_grid (new_image, image->grid, FALSE); /* Copy the quick mask info */ new_image->quick_mask_state = image->quick_mask_state; new_image->quick_mask_inverted = image->quick_mask_inverted; new_image->quick_mask_color = image->quick_mask_color; /* Copy parasites */ if (image->parasites) { g_object_unref (new_image->parasites); new_image->parasites = gimp_parasite_list_copy (image->parasites); } gimp_image_undo_enable (new_image); return new_image; }
/* Main file load function */ gint32 load_thumbnail_image (const gchar *filename, gint *width, gint *height, GError **load_error) { FILE *f; struct stat st; PSDimage img_a; gint32 image_id = -1; GError *error = NULL; /* ----- Open PSD file ----- */ if (g_stat (filename, &st) == -1) return -1; IFDBG(1) g_debug ("Open file %s", gimp_filename_to_utf8 (filename)); f = g_fopen (filename, "rb"); if (f == NULL) { g_set_error (load_error, G_FILE_ERROR, g_file_error_from_errno (errno), _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (filename), g_strerror (errno)); return -1; } gimp_progress_init_printf (_("Opening thumbnail for '%s'"), gimp_filename_to_utf8 (filename)); /* ----- Read the PSD file Header block ----- */ IFDBG(2) g_debug ("Read header block"); if (read_header_block (&img_a, f, &error) < 0) goto load_error; gimp_progress_update (0.2); /* ----- Read the PSD file Colour Mode block ----- */ IFDBG(2) g_debug ("Read colour mode block"); if (read_color_mode_block (&img_a, f, &error) < 0) goto load_error; gimp_progress_update (0.4); /* ----- Read the PSD file Image Resource block ----- */ IFDBG(2) g_debug ("Read image resource block"); if (read_image_resource_block (&img_a, f, &error) < 0) goto load_error; gimp_progress_update (0.6); /* ----- Create GIMP image ----- */ IFDBG(2) g_debug ("Create GIMP image"); image_id = create_gimp_image (&img_a, filename); if (image_id < 0) goto load_error; /* ----- Add image resources ----- */ IFDBG(2) g_debug ("Add image resources"); if (add_image_resources (image_id, &img_a, f, &error) < 1) goto load_error; gimp_progress_update (1.0); gimp_image_clean_all (image_id); gimp_image_undo_enable (image_id); fclose (f); *width = img_a.columns; *height = img_a.rows; return image_id; /* ----- Process load errors ----- */ load_error: if (error) { g_set_error (load_error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Error loading PSD file: %s"), error->message); g_error_free (error); } /* Delete partially loaded image */ if (image_id > 0) gimp_image_delete (image_id); /* Close file if Open */ if (! (f == NULL)) fclose (f); return -1; }
void edit_undo_clear_cmd_callback (GtkAction *action, gpointer data) { GimpImage *image; GimpUndoStack *undo_stack; GimpUndoStack *redo_stack; GtkWidget *widget; GtkWidget *dialog; gchar *size; gint64 memsize; gint64 guisize; return_if_no_image (image, data); return_if_no_widget (widget, data); dialog = gimp_message_dialog_new (_("Clear Undo History"), GIMP_STOCK_WARNING, widget, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, gimp_standard_help_func, GIMP_HELP_EDIT_UNDO_CLEAR, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CLEAR, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); g_signal_connect_object (gtk_widget_get_toplevel (widget), "unmap", G_CALLBACK (gtk_widget_destroy), dialog, G_CONNECT_SWAPPED); g_signal_connect_object (image, "disconnect", G_CALLBACK (gtk_widget_destroy), dialog, G_CONNECT_SWAPPED); gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box, _("Really clear image's undo history?")); undo_stack = gimp_image_get_undo_stack (image); redo_stack = gimp_image_get_redo_stack (image); memsize = gimp_object_get_memsize (GIMP_OBJECT (undo_stack), &guisize); memsize += guisize; memsize += gimp_object_get_memsize (GIMP_OBJECT (redo_stack), &guisize); memsize += guisize; size = g_format_size (memsize); gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box, _("Clearing the undo history of this " "image will gain %s of memory."), size); g_free (size); if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK) { gimp_image_undo_disable (image); gimp_image_undo_enable (image); gimp_image_flush (image); } gtk_widget_destroy (dialog); }
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 run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[6]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 image_ID = -1; PopplerDocument *doc = NULL; GError *error = NULL; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; if (! g_thread_supported ()) g_thread_init (NULL); if (strcmp (name, LOAD_PROC) == 0) { PdfSelectedPages pages = { 0, NULL }; switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve last settings */ gimp_get_data (LOAD_PROC, &loadvals); doc = open_document (param[1].data.d_string, &error); if (!doc) { status = GIMP_PDB_EXECUTION_ERROR; break; } if (load_dialog (doc, &pages)) gimp_set_data (LOAD_PROC, &loadvals, sizeof(loadvals)); else status = GIMP_PDB_CANCEL; break; case GIMP_RUN_WITH_LAST_VALS: /* FIXME: implement last vals mode */ status = GIMP_PDB_EXECUTION_ERROR; break; case GIMP_RUN_NONINTERACTIVE: doc = open_document (param[1].data.d_string, &error); if (doc) { PopplerPage *test_page = poppler_document_get_page (doc, 0); if (test_page) { pages.n_pages = 1; pages.pages = g_new (gint, 1); pages.pages[0] = 0; g_object_unref (test_page); } else { status = GIMP_PDB_EXECUTION_ERROR; g_object_unref (doc); } } else { status = GIMP_PDB_EXECUTION_ERROR; } break; } if (status == GIMP_PDB_SUCCESS) { image_ID = load_image (doc, param[1].data.d_string, run_mode, loadvals.target, loadvals.resolution, &pages); if (image_ID != -1) { *nreturn_vals = 2; values[1].type = GIMP_PDB_IMAGE; values[1].data.d_image = image_ID; } else { status = GIMP_PDB_EXECUTION_ERROR; } } if (doc) g_object_unref (doc); g_free (pages.pages); } else if (strcmp (name, LOAD_THUMB_PROC) == 0) { if (nparams < 2) { status = GIMP_PDB_CALLING_ERROR; } else { gdouble width = 0; gdouble height = 0; gdouble scale; gint32 image = -1; gint num_pages = 0; GdkPixbuf *pixbuf = NULL; /* Possibly retrieve last settings */ gimp_get_data (LOAD_PROC, &loadvals); doc = open_document (param[0].data.d_string, &error); if (doc) { PopplerPage *page = poppler_document_get_page (doc, 0); if (page) { poppler_page_get_size (page, &width, &height); g_object_unref (page); } num_pages = poppler_document_get_n_pages (doc); pixbuf = get_thumbnail (doc, 0, param[1].data.d_int32); g_object_unref (doc); } if (pixbuf) { image = gimp_image_new (gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), GIMP_RGB); gimp_image_undo_disable (image); layer_from_pixbuf (image, "thumbnail", 0, pixbuf, 0.0, 1.0); g_object_unref (pixbuf); gimp_image_undo_enable (image); gimp_image_clean_all (image); } scale = loadvals.resolution / gimp_unit_get_factor (GIMP_UNIT_POINT); width *= scale; height *= scale; if (image != -1) { *nreturn_vals = 6; values[1].type = GIMP_PDB_IMAGE; values[1].data.d_image = image; values[2].type = GIMP_PDB_INT32; values[2].data.d_int32 = width; values[3].type = GIMP_PDB_INT32; values[3].data.d_int32 = height; values[4].type = GIMP_PDB_INT32; values[4].data.d_int32 = GIMP_RGB_IMAGE; values[5].type = GIMP_PDB_INT32; values[5].data.d_int32 = num_pages; } else { status = GIMP_PDB_EXECUTION_ERROR; } } } else { status = GIMP_PDB_CALLING_ERROR; } if (status != GIMP_PDB_SUCCESS && error) { *nreturn_vals = 2; values[1].type = GIMP_PDB_STRING; values[1].data.d_string = error->message; } values[0].data.d_status = status; }
static gint32 load_image (PopplerDocument *doc, const gchar *filename, GimpRunMode run_mode, GimpPageSelectorTarget target, guint32 resolution, PdfSelectedPages *pages) { gint32 image_ID = 0; gint32 *images = NULL; gint i; gdouble scale; gdouble doc_progress = 0; if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES) images = g_new0 (gint32, pages->n_pages); gimp_progress_init_printf (_("Opening '%s'"), gimp_filename_to_utf8 (filename)); scale = resolution / gimp_unit_get_factor (GIMP_UNIT_POINT); /* read the file */ for (i = 0; i < pages->n_pages; i++) { PopplerPage *page; gchar *page_label; gdouble page_width; gdouble page_height; GdkPixbuf *buf; gint width; gint height; page = poppler_document_get_page (doc, pages->pages[i]); poppler_page_get_size (page, &page_width, &page_height); width = page_width * scale; height = page_height * scale; g_object_get (G_OBJECT (page), "label", &page_label, NULL); if (! image_ID) { gchar *name; image_ID = gimp_image_new (width, height, GIMP_RGB); gimp_image_undo_disable (image_ID); if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES) name = g_strdup_printf (_("%s-%s"), filename, page_label); else name = g_strdup_printf (_("%s-pages"), filename); gimp_image_set_filename (image_ID, name); g_free (name); gimp_image_set_resolution (image_ID, resolution, resolution); } buf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); poppler_page_render_to_pixbuf (page, 0, 0, width, height, scale, 0, buf); layer_from_pixbuf (image_ID, page_label, i, buf, doc_progress, 1.0 / pages->n_pages); g_free (page_label); g_object_unref (buf); doc_progress = (double) (i + 1) / pages->n_pages; gimp_progress_update (doc_progress); if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES) { images[i] = image_ID; gimp_image_undo_enable (image_ID); gimp_image_clean_all (image_ID); image_ID = 0; } } if (image_ID) { gimp_image_undo_enable (image_ID); gimp_image_clean_all (image_ID); } if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES) { if (run_mode != GIMP_RUN_NONINTERACTIVE) { /* Display images in reverse order. The last will be * displayed by GIMP itself */ for (i = pages->n_pages - 1; i > 0; i--) gimp_display_new (images[i]); } image_ID = images[0]; g_free (images); } return image_ID; }
static void guillotine (gint32 image_ID) { gint guide; gint image_width; gint image_height; gboolean guides_found = FALSE; GList *hguides, *hg; GList *vguides, *vg; image_width = gimp_image_width (image_ID); image_height = gimp_image_height (image_ID); hguides = g_list_append (NULL, GINT_TO_POINTER (0)); hguides = g_list_append (hguides, GINT_TO_POINTER (image_height)); vguides = g_list_append (NULL, GINT_TO_POINTER (0)); vguides = g_list_append (vguides, GINT_TO_POINTER (image_width)); for (guide = gimp_image_find_next_guide (image_ID, 0); guide > 0; guide = gimp_image_find_next_guide (image_ID, guide)) { gint position = gimp_image_get_guide_position (image_ID, guide); switch (gimp_image_get_guide_orientation (image_ID, guide)) { case GIMP_ORIENTATION_HORIZONTAL: if (! g_list_find (hguides, GINT_TO_POINTER (position))) { hguides = g_list_insert_sorted (hguides, GINT_TO_POINTER (position), guide_sort_func); guides_found = TRUE; } break; case GIMP_ORIENTATION_VERTICAL: if (! g_list_find (vguides, GINT_TO_POINTER (position))) { vguides = g_list_insert_sorted (vguides, GINT_TO_POINTER (position), guide_sort_func); guides_found = TRUE; } break; case GIMP_ORIENTATION_UNKNOWN: g_assert_not_reached (); break; } } if (guides_found) { gchar *filename; gint h, v, hpad, vpad; gint x, y; gchar *hformat; gchar *format; filename = gimp_image_get_filename (image_ID); if (!filename) filename = g_strdup (_("Untitled")); /* get the number horizontal and vertical slices */ h = g_list_length (hguides); v = g_list_length (vguides); /* need the number of digits of h and v for the padding */ hpad = log10(h) + 1; vpad = log10(v) + 1; /* format for the x-y coordinates in the filename */ hformat = g_strdup_printf ("%%0%i", MAX (hpad, vpad)); format = g_strdup_printf ("-%si-%si", hformat, hformat); /* Do the actual dup'ing and cropping... this isn't a too naive a * way to do this since we got copy-on-write tiles, either. */ for (y = 0, hg = hguides; hg && hg->next; y++, hg = hg->next) { for (x = 0, vg = vguides; vg && vg->next; x++, vg = vg->next) { gint32 new_image = gimp_image_duplicate (image_ID); GString *new_filename; gchar *fileextension; gchar *fileindex; gint pos; if (new_image == -1) { g_warning ("Couldn't create new image."); return; } gimp_image_undo_disable (new_image); gimp_image_crop (new_image, GPOINTER_TO_INT (vg->next->data) - GPOINTER_TO_INT (vg->data), GPOINTER_TO_INT (hg->next->data) - GPOINTER_TO_INT (hg->data), GPOINTER_TO_INT (vg->data), GPOINTER_TO_INT (hg->data)); new_filename = g_string_new (filename); /* show the rough coordinates of the image in the title */ fileindex = g_strdup_printf (format, x, y); /* get the position of the file extension - last . in filename */ fileextension = strrchr (new_filename->str, '.'); pos = fileextension - new_filename->str; /* insert the coordinates before the extension */ g_string_insert (new_filename, pos, fileindex); g_free (fileindex); gimp_image_set_filename (new_image, new_filename->str); g_string_free (new_filename, TRUE); while ((guide = gimp_image_find_next_guide (new_image, 0))) gimp_image_delete_guide (new_image, guide); gimp_image_undo_enable (new_image); gimp_display_new (new_image); } } g_free (filename); g_free (hformat); g_free (format); } g_list_free (hguides); g_list_free (vguides); }
static void run ( const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[3]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; SeparateContext mysc; //enum separate_function func = SEP_NONE; run_mode = param[0].data.d_int32; /* setup for localization */ INIT_I18N (); cmsErrorAction( LCMS_ERROR_IGNORE ); mysc.filename = NULL; if( nparams != ( run_mode == GIMP_RUN_NONINTERACTIVE ? 2 : 1 ) ) status = GIMP_PDB_CALLING_ERROR; else if( run_mode == GIMP_RUN_NONINTERACTIVE ) { if( param[1].type != GIMP_PDB_STRING || strlen( param[1].data.d_string ) == 0 ) status = GIMP_PDB_CALLING_ERROR; else mysc.filename = g_strdup( param[1].data.d_string ); } else { gint size = gimp_get_data_size( "plug-in-separate-import/lastpath" ); if( size ) { mysc.filename = g_malloc( size ); gimp_get_data( "plug-in-separate-import/lastpath", mysc.filename ); } } if( status == GIMP_PDB_SUCCESS && ( run_mode == GIMP_RUN_NONINTERACTIVE || separate_import_dialog( &mysc ) ) ) { gint i, j, x, y; TIFF *in; guint32 width, height, stripSize, stripCount, stripHeight; gint16 bps, spp, step, planerConfig, photometric, inkset, resolutionUnit; float xres, yres; const gchar *layerNames[] = { "C", "M", "Y", "K" }; guchar *buf, *maskbuf[4], *srcbuf, *destbuf[4], *iccProfile; gint32 layers[5], masks[4]; GimpDrawable *drw[4]; GimpPixelRgn rgn[4]; GimpRGB primaries[4] = { { .180, .541, .870, 1.0 }, { .925, .149, .388, 1.0 }, { .929, .862, .129, 1.0 }, { 0, 0, 0, 1.0 } }; gchar *str = NULL; gchar *baseName = g_path_get_basename( gimp_filename_to_utf8( mysc.filename ) ); #ifdef G_OS_WIN32 { gchar *_filename = NULL; // win32 filename encoding(not UTF-8) _filename = g_win32_locale_filename_from_utf8( mysc.filename ); in = TIFFOpen( _filename ? _filename : mysc.filename, "r" ); g_free( _filename ); } #else in = TIFFOpen( mysc.filename, "r" ); #endif if( !in ) { str = g_strdup_printf( _( "Cannot open : \"%s\"" ), baseName ); gimp_message( str ); g_free( str ); status = GIMP_PDB_EXECUTION_ERROR; } else { if( ( TIFFGetField( in, TIFFTAG_BITSPERSAMPLE, &bps ) == FALSE || ( bps != 8 && bps != 16 ) ) || ( TIFFGetField( in, TIFFTAG_SAMPLESPERPIXEL, &spp ) == FALSE || spp != 4 ) || ( TIFFGetField( in, TIFFTAG_PHOTOMETRIC, &photometric ) == FALSE || photometric != PHOTOMETRIC_SEPARATED ) || ( TIFFGetField( in, TIFFTAG_PLANARCONFIG, &planerConfig ) == FALSE || planerConfig != PLANARCONFIG_CONTIG ) || ( TIFFGetField( in, TIFFTAG_INKSET, &inkset ) == TRUE && inkset != INKSET_CMYK ) ) { str = g_strdup_printf( _( "\"%s\" is unsupported." ), baseName ); gimp_message( str ); g_free( str ); status = GIMP_PDB_EXECUTION_ERROR; } else { stripCount = TIFFNumberOfStrips( in ); stripSize = TIFFStripSize( in ); TIFFGetField( in, TIFFTAG_IMAGEWIDTH, &width ); TIFFGetField( in, TIFFTAG_IMAGELENGTH, &height ); TIFFGetField( in, TIFFTAG_ROWSPERSTRIP, &stripHeight ); TIFFGetField( in, TIFFTAG_RESOLUTIONUNIT, &resolutionUnit ); TIFFGetField( in, TIFFTAG_XRESOLUTION, &xres ); TIFFGetField( in, TIFFTAG_YRESOLUTION, &yres ); #if 0 str = g_strdup_printf( "Photometric : %d BPS : %d SPP : %d\nInkset : %d StripCount : %d", photometric, bps, spp, inkset, stripCount ); gimp_message( str ); g_free( str ); #endif step = ( bps == 16 ) ? 2 : 1; buf = g_malloc( stripSize ); values[1].data.d_image = gimp_image_new( width, height, GIMP_RGB ); gimp_image_set_resolution( values[1].data.d_image, xres, yres ); gimp_context_push(); for( i = 0; i < 4; i++ ) { layers[i] = gimp_layer_new( values[1].data.d_image, layerNames[i], width, height, GIMP_RGBA_IMAGE, 100.0, GIMP_DARKEN_ONLY_MODE ); gimp_context_set_foreground( &primaries[i] ); gimp_drawable_fill( layers[i], GIMP_FOREGROUND_FILL ); gimp_image_add_layer( values[1].data.d_image, layers[i], i ); masks[i] = gimp_layer_create_mask( layers[i], GIMP_ADD_BLACK_MASK ); gimp_layer_add_mask( layers[i], masks[i] ); drw[i] = gimp_drawable_get( masks[i] ); maskbuf[i] = g_malloc( width * stripHeight ); } gimp_context_pop(); layers[4] = gimp_layer_new( values[1].data.d_image, _( "Background" ), width, height, GIMP_RGB_IMAGE, 100.0, GIMP_NORMAL_MODE ); gimp_drawable_fill( layers[4], GIMP_WHITE_FILL ); gimp_image_add_layer( values[1].data.d_image, layers[4], 4 ); str = g_strdup_printf( _( "Reading \"%s\"..." ), baseName ); gimp_progress_init( str ); g_free( str ); for( i = 0; i < stripCount; i++ ) { guint32 size = TIFFReadEncodedStrip( in, i, buf, stripSize ); guint32 rowCount = ( size < stripSize ? height % stripHeight : stripHeight ); srcbuf = buf; if( bps == 16 ) srcbuf++; for( j = 0; j < 4; j++ ) { gimp_pixel_rgn_init( &( rgn[j] ), drw[j], 0, stripHeight * i, width, rowCount, FALSE, FALSE ); destbuf[j] = maskbuf[j]; } for( y = 0; y < rowCount; y++ ) { for( x = 0; x < width; x++ ) { *destbuf[0]++ = *srcbuf; srcbuf += step; *destbuf[1]++ = *srcbuf; srcbuf += step; *destbuf[2]++ = *srcbuf; srcbuf += step; *destbuf[3]++ = *srcbuf; srcbuf += step; //srcbuf += spp > 4 ? spp - 4 : 0; } } gimp_pixel_rgn_set_rect( &( rgn[0] ), maskbuf[0], 0, stripHeight * i, width, rowCount ); gimp_pixel_rgn_set_rect( &( rgn[1] ), maskbuf[1], 0, stripHeight * i, width, rowCount ); gimp_pixel_rgn_set_rect( &( rgn[2] ), maskbuf[2], 0, stripHeight * i, width, rowCount ); gimp_pixel_rgn_set_rect( &( rgn[3] ), maskbuf[3], 0, stripHeight * i, width, rowCount ); gimp_progress_update( (gdouble)i / stripCount ); } g_free( buf ); for( i = 0; i < 4; i++ ) { g_free( maskbuf[i] ); gimp_drawable_detach( drw[i] ); } #ifdef ENABLE_COLOR_MANAGEMENT if ( TIFFGetField( in, TIFFTAG_ICCPROFILE, &width, &iccProfile ) ) { GimpParasite *parasite; parasite = gimp_parasite_new( CMYKPROFILE, 0, width, iccProfile ); gimp_image_parasite_attach( values[1].data.d_image, parasite ); gimp_parasite_free( parasite ); //g_free( iccProfile ); // This causes clash on TIFFClose( in ). } #endif } TIFFClose( in ); } g_free( baseName ); } else status = GIMP_PDB_CANCEL; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; if( status == GIMP_PDB_SUCCESS ) { *nreturn_vals = 2; values[1].type = GIMP_PDB_IMAGE; if( run_mode != GIMP_RUN_NONINTERACTIVE ) { gimp_image_undo_enable( values[1].data.d_image ); gimp_display_new( values[1].data.d_image ); gimp_displays_flush(); } gimp_set_data( "plug-in-separate-import/lastpath", mysc.filename, strlen( mysc.filename ) + 1 ); } else *nreturn_vals = 1; g_free( mysc.filename ); }
void gimp_image_import_color_profile (GimpImage *image, GimpContext *context, GimpProgress *progress, gboolean interactive) { GimpColorConfig *config = image->gimp->config->color_management; g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (GIMP_IS_CONTEXT (context)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); config = image->gimp->config->color_management; if (gimp_image_get_base_type (image) == GIMP_GRAY) return; if (config->mode == GIMP_COLOR_MANAGEMENT_OFF) return; if (gimp_image_get_color_profile (image)) { GimpColorProfilePolicy policy; GimpColorProfile *dest_profile = NULL; policy = image->gimp->config->color_profile_policy; if (policy == GIMP_COLOR_PROFILE_POLICY_ASK) { if (interactive) { gboolean dont_ask = FALSE; policy = gimp_query_profile_policy (image->gimp, image, context, &dest_profile, &dont_ask); if (dont_ask) { g_object_set (G_OBJECT (image->gimp->config), "color-profile-policy", policy, NULL); } } else { policy = GIMP_COLOR_PROFILE_POLICY_KEEP; } } if (policy == GIMP_COLOR_PROFILE_POLICY_CONVERT) { GimpColorRenderingIntent intent; gboolean bpc; if (! dest_profile) { dest_profile = gimp_image_get_builtin_color_profile (image); g_object_ref (dest_profile); } intent = config->display_intent; bpc = (intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC); gimp_image_undo_disable (image); gimp_image_convert_color_profile (image, dest_profile, intent, bpc, progress, NULL); gimp_image_clean_all (image); gimp_image_undo_enable (image); g_object_unref (dest_profile); } } }
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; }