static GimpValueArray * image_scale_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; gint32 new_width; gint32 new_height; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); new_width = g_value_get_int (gimp_value_array_index (args, 1)); new_height = g_value_get_int (gimp_value_array_index (args, 2)); if (success) { GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context); if (progress) gimp_progress_start (progress, FALSE, _("Scaling")); gimp_image_scale (image, new_width, new_height, pdb_context->interpolation, progress); if (progress) gimp_progress_end (progress); } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static void image_scale_callback (GtkWidget *dialog, GimpViewable *viewable, gint width, gint height, GimpUnit unit, GimpInterpolationType interpolation, gdouble xresolution, gdouble yresolution, GimpUnit resolution_unit, gpointer user_data) { GimpImage *image = GIMP_IMAGE (viewable); gdouble xres; gdouble yres; image_scale_unit = unit; image_scale_interp = interpolation; gimp_image_get_resolution (image, &xres, &yres); if (width > 0 && height > 0) { if (width == gimp_image_get_width (image) && height == gimp_image_get_height (image) && xresolution == xres && yresolution == yres && resolution_unit == gimp_image_get_unit (image)) return; gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_SCALE, _("Scale Image")); gimp_image_set_resolution (image, xresolution, yresolution); gimp_image_set_unit (image, resolution_unit); if (width != gimp_image_get_width (image) || height != gimp_image_get_height (image)) { GimpProgress *progress; progress = gimp_progress_start (GIMP_PROGRESS (user_data), _("Scaling"), FALSE); gimp_image_scale (image, width, height, interpolation, progress); if (progress) gimp_progress_end (progress); } gimp_image_undo_group_end (image); gimp_image_flush (image); } else { g_warning ("Scale Error: " "Both width and height must be greater than zero."); } }
static GimpValueArray * image_rotate_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; gint32 rotate_type; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); rotate_type = g_value_get_enum (gimp_value_array_index (args, 1)); if (success) { if (progress) gimp_progress_start (progress, FALSE, _("Rotating")); gimp_image_rotate (image, context, rotate_type, progress); if (progress) gimp_progress_end (progress); } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static void gimp_gegl_progress_notify (GObject *object, const GParamSpec *pspec, GimpProgress *progress) { const gchar *text; gdouble value; g_object_get (object, "progress", &value, NULL); text = g_object_get_data (object, "gimp-progress-text"); if (text) { if (value == 0.0) { gimp_progress_start (progress, text, FALSE); return; } else if (value == 1.0) { gimp_progress_end (progress); return; } } gimp_progress_set_value (progress, value); }
static void gimp_cage_tool_compute_coef (GimpCageTool *ct) { GimpCageConfig *config = ct->config; GimpProgress *progress; const Babl *format; GeglNode *gegl; GeglNode *input; GeglNode *output; GeglProcessor *processor; GeglBuffer *buffer; gdouble value; progress = gimp_progress_start (GIMP_PROGRESS (ct), _("Computing Cage Coefficients"), FALSE); if (ct->coef) { g_object_unref (ct->coef); ct->coef = NULL; } format = babl_format_n (babl_type ("float"), gimp_cage_config_get_n_points (config) * 2); gegl = gegl_node_new (); input = gegl_node_new_child (gegl, "operation", "gimp:cage-coef-calc", "config", ct->config, NULL); output = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer, "format", format, NULL); gegl_node_connect_to (input, "output", output, "input"); processor = gegl_node_new_processor (output, NULL); while (gegl_processor_work (processor, &value)) { if (progress) gimp_progress_set_value (progress, value); } if (progress) gimp_progress_end (progress); g_object_unref (processor); ct->coef = buffer; g_object_unref (gegl); ct->dirty_coef = FALSE; }
static GimpProgress * gimp_tool_progress_start (GimpProgress *progress, const gchar *message, gboolean cancelable) { GimpTool *tool = GIMP_TOOL (progress); GimpDisplayShell *shell; gint x, y, w, h; g_return_val_if_fail (GIMP_IS_DISPLAY (tool->display), NULL); g_return_val_if_fail (tool->progress == NULL, NULL); shell = gimp_display_get_shell (tool->display); gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h); tool->progress = gimp_canvas_progress_new (shell, GIMP_HANDLE_ANCHOR_CENTER, x + w / 2, y + h / 2); gimp_display_shell_add_item (shell, tool->progress); g_object_unref (tool->progress); gimp_progress_start (GIMP_PROGRESS (tool->progress), message, FALSE); gimp_widget_flush_expose (shell->canvas); tool->progress_display = tool->display; return progress; }
static void gimp_gegl_progress_callback (GObject *object, gdouble value, GimpProgress *progress) { const gchar *text; text = g_object_get_data (object, "gimp-progress-text"); if (text) { if (value == 0.0) { if (gimp_progress_is_active (progress)) gimp_progress_set_text (progress, "%s", text); else gimp_progress_start (progress, FALSE, "%s", text); return; } else if (value == 1.0) { gimp_progress_end (progress); return; } } gimp_progress_set_value (progress, value); }
static GimpProgress * gimp_display_shell_progress_start (GimpProgress *progress, const gchar *message, gboolean cancelable) { GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (progress); GimpStatusbar *statusbar = gimp_display_shell_get_statusbar (shell); return gimp_progress_start (GIMP_PROGRESS (statusbar), message, cancelable); }
static GimpProgress * gimp_display_progress_start (GimpProgress *progress, const gchar *message, gboolean cancelable) { GimpDisplay *display = GIMP_DISPLAY (progress); if (display->shell) return gimp_progress_start (GIMP_PROGRESS (display->shell), message, cancelable); return NULL; }
void gimp_plug_in_progress_start (GimpPlugIn *plug_in, const gchar *message, GimpObject *display) { GimpPlugInProcFrame *proc_frame; g_return_if_fail (GIMP_IS_PLUG_IN (plug_in)); g_return_if_fail (display == NULL || GIMP_IS_OBJECT (display)); proc_frame = gimp_plug_in_get_proc_frame (plug_in); if (! proc_frame->progress) { proc_frame->progress = gimp_new_progress (plug_in->manager->gimp, display); if (proc_frame->progress) { proc_frame->progress_created = TRUE; g_object_ref (proc_frame->progress); gimp_plug_in_progress_attach (proc_frame->progress); } } if (proc_frame->progress) { if (! proc_frame->progress_cancel_id) proc_frame->progress_cancel_id = g_signal_connect (proc_frame->progress, "cancel", G_CALLBACK (gimp_plug_in_progress_cancel_callback), plug_in); if (gimp_progress_is_active (proc_frame->progress)) { if (message) gimp_progress_set_text (proc_frame->progress, message); if (gimp_progress_get_value (proc_frame->progress) > 0.0) gimp_progress_set_value (proc_frame->progress, 0.0); } else { gimp_progress_start (proc_frame->progress, message ? message : "", TRUE); } } }
static void gimp_drawable_apply_operation_private (GimpDrawable *drawable, GimpProgress *progress, const gchar *undo_desc, GeglNode *operation, gboolean linear, TileManager *dest_tiles, const GeglRectangle *rect) { GeglNode *gegl; GeglNode *input; GeglNode *output; GeglProcessor *processor; gdouble value; gegl = gegl_node_new (); /* Disable caching on all children of the node unless explicitly re-enabled. */ g_object_set (gegl, "dont-cache", TRUE, NULL); input = gegl_node_new_child (gegl, "operation", "gimp:tilemanager-source", "tile-manager", gimp_drawable_get_tiles (drawable), "linear", linear, NULL); output = gegl_node_new_child (gegl, "operation", "gimp:tilemanager-sink", "tile-manager", dest_tiles, "linear", linear, NULL); gegl_node_add_child (gegl, operation); gegl_node_link_many (input, operation, output, NULL); processor = gegl_node_new_processor (output, rect); if (progress) gimp_progress_start (progress, undo_desc, FALSE); while (gegl_processor_work (processor, &value)) if (progress) gimp_progress_set_value (progress, value); g_object_unref (processor); g_object_unref (gegl); }
static void convert_dialog_response (GtkWidget *widget, gint response_id, IndexedDialog *dialog) { if (response_id == GTK_RESPONSE_OK) { GimpProgress *progress; GError *error = NULL; progress = gimp_progress_start (dialog->progress, _("Converting to indexed colors"), FALSE); /* Convert the image to indexed color */ if (! gimp_image_convert (dialog->image, GIMP_INDEXED, dialog->num_colors, dialog->dither_type, dialog->alpha_dither, dialog->remove_dups, dialog->palette_type, dialog->custom_palette, progress, &error)) { gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog), GIMP_MESSAGE_WARNING, "%s", error->message); g_clear_error (&error); if (progress) gimp_progress_end (progress); return; } if (progress) gimp_progress_end (progress); gimp_image_flush (dialog->image); /* Save defaults for next time */ saved_dither_type = dialog->dither_type; saved_alpha_dither = dialog->alpha_dither; saved_remove_dups = dialog->remove_dups; saved_num_colors = dialog->num_colors; saved_palette_type = dialog->palette_type; saved_palette = dialog->custom_palette; } gtk_widget_destroy (dialog->dialog); }
void gimp_drawable_foreground_extract_siox (GimpDrawable *mask, SioxState *state, SioxRefinementType refinement, gint smoothness, const gdouble sensitivity[3], gboolean multiblob, GimpProgress *progress) { GeglBuffer *buffer; gint x1, y1; gint x2, y2; g_return_if_fail (GIMP_IS_DRAWABLE (mask)); g_return_if_fail (babl_format_get_bytes_per_pixel (gimp_drawable_get_format (mask)) == 1); g_return_if_fail (state != NULL); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); if (progress) gimp_progress_start (progress, _("Foreground Extraction"), FALSE); if (GIMP_IS_CHANNEL (mask)) { gimp_channel_bounds (GIMP_CHANNEL (mask), &x1, &y1, &x2, &y2); } else { x1 = 0; y1 = 0; x2 = gimp_item_get_width (GIMP_ITEM (mask)); y2 = gimp_item_get_height (GIMP_ITEM (mask)); } buffer = gimp_drawable_get_buffer (mask); siox_foreground_extract (state, refinement, gimp_gegl_buffer_get_tiles (buffer), x1, y1, x2, y2, smoothness, sensitivity, multiblob, (SioxProgressFunc) gimp_progress_set_value, progress); if (progress) gimp_progress_end (progress); gimp_drawable_update (mask, x1, y1, x2, y2); }
static gboolean file_remote_copy_file (Gimp *gimp, GFile *src_file, GFile *dest_file, RemoteCopyMode mode, GimpProgress *progress, GError **error) { RemoteProgress remote_progress = { 0, }; gboolean success; GError *my_error = NULL; remote_progress.mode = mode; remote_progress.progress = progress; if (progress) { gimp_progress_start (progress, TRUE, _("Opening remote file")); remote_progress.cancellable = g_cancellable_new (); g_signal_connect (progress, "cancel", G_CALLBACK (file_remote_copy_file_cancel), &remote_progress); success = g_file_copy (src_file, dest_file, G_FILE_COPY_OVERWRITE, remote_progress.cancellable, file_remote_progress_callback, &remote_progress, &my_error); g_signal_handlers_disconnect_by_func (progress, file_remote_copy_file_cancel, &remote_progress); g_object_unref (remote_progress.cancellable); gimp_progress_set_value (progress, 1.0); gimp_progress_end (progress); } else { success = g_file_copy (src_file, dest_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &my_error); } return success; }
static void image_resize_callback (GtkWidget *dialog, GimpViewable *viewable, gint width, gint height, GimpUnit unit, gint offset_x, gint offset_y, GimpItemSet layer_set, gpointer data) { ImageResizeOptions *options = data; image_resize_unit = unit; if (width > 0 && height > 0) { GimpImage *image = GIMP_IMAGE (viewable); GimpDisplay *display = options->display; GimpContext *context = options->context; GimpProgress *progress; gtk_widget_destroy (dialog); if (width == gimp_image_get_width (image) && height == gimp_image_get_height (image)) return; progress = gimp_progress_start (GIMP_PROGRESS (display), _("Resizing"), FALSE); gimp_image_resize_with_layers (image, context, width, height, offset_x, offset_y, layer_set, progress); if (progress) gimp_progress_end (progress); gimp_image_flush (image); } else { g_warning ("Resize Error: " "Both width and height must be greater than zero."); } }
static GimpProgress * gimp_tool_progress_start (GimpProgress *progress, const gchar *message, gboolean cancelable) { GimpTool *tool = GIMP_TOOL (progress); GimpDisplayShell *shell; gint x, y; g_return_val_if_fail (GIMP_IS_DISPLAY (tool->display), NULL); g_return_val_if_fail (tool->progress == NULL, NULL); shell = gimp_display_get_shell (tool->display); x = shell->disp_width / 2; y = shell->disp_height / 2; gimp_display_shell_unzoom_xy (shell, x, y, &x, &y, FALSE); tool->progress = gimp_canvas_progress_new (shell, GIMP_HANDLE_ANCHOR_CENTER, x, y); gimp_display_shell_add_unrotated_item (shell, tool->progress); g_object_unref (tool->progress); gimp_progress_start (GIMP_PROGRESS (tool->progress), message, FALSE); gimp_widget_flush_expose (shell->canvas); tool->progress_display = tool->display; if (cancelable) { tool->progress_grab_widget = gtk_invisible_new (); gtk_widget_show (tool->progress_grab_widget); gtk_grab_add (tool->progress_grab_widget); g_signal_connect (tool->progress_grab_widget, "button-press-event", G_CALLBACK (gimp_tool_progress_button_press), tool); g_signal_connect (tool->progress_grab_widget, "key-press-event", G_CALLBACK (gimp_tool_progress_key_press), tool); } return progress; }
static GimpProgress * gimp_file_dialog_progress_start (GimpProgress *progress, const gchar *message, gboolean cancelable) { GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress); GimpProgress *retval; retval = gimp_progress_start (GIMP_PROGRESS (dialog->progress), message, cancelable); gtk_widget_show (dialog->progress); gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL, cancelable); return retval; }
static void convert_precision_dialog_response (GtkWidget *widget, gint response_id, ConvertDialog *dialog) { if (response_id == GTK_RESPONSE_OK) { GimpProgress *progress; GimpPrecision precision; const gchar *enum_desc; precision = gimp_babl_precision (dialog->component_type, dialog->linear); gimp_enum_get_value (GIMP_TYPE_PRECISION, precision, NULL, NULL, &enum_desc, NULL); progress = gimp_progress_start (dialog->progress, FALSE, _("Converting image to %s"), enum_desc); gimp_image_convert_precision (dialog->image, precision, dialog->layer_dither_type, dialog->text_layer_dither_type, dialog->mask_dither_type, progress); if (progress) gimp_progress_end (progress); gimp_image_flush (dialog->image); /* gegl:color-reduction only does 16 bits */ if (dialog->bits <= 16) { /* Save defaults for next time */ saved_layer_dither_type = dialog->layer_dither_type; saved_text_layer_dither_type = dialog->text_layer_dither_type; saved_mask_dither_type = dialog->mask_dither_type; } } gtk_widget_destroy (dialog->dialog); }
static void gimp_blend_tool_commit (GimpBlendTool *blend_tool) { GimpTool *tool = GIMP_TOOL (blend_tool); GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (tool); GimpPaintOptions *paint_options = GIMP_PAINT_OPTIONS (options); GimpContext *context = GIMP_CONTEXT (options); GimpImage *image = gimp_display_get_image (tool->display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpProgress *progress; gint off_x; gint off_y; progress = gimp_progress_start (GIMP_PROGRESS (tool), FALSE, _("Blending")); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); gimp_drawable_blend (drawable, context, gimp_context_get_gradient (context), gimp_context_get_paint_mode (context), options->gradient_type, gimp_context_get_opacity (context), options->offset, paint_options->gradient_options->gradient_repeat, paint_options->gradient_options->gradient_reverse, options->supersample, options->supersample_depth, options->supersample_threshold, options->dither, blend_tool->start_x - off_x, blend_tool->start_y - off_y, blend_tool->end_x - off_x, blend_tool->end_y - off_y, progress); if (progress) gimp_progress_end (progress); gimp_image_flush (image); }
void image_rotate_cmd_callback (GtkAction *action, gint value, gpointer data) { GimpDisplay *display; GimpProgress *progress; return_if_no_display (display, data); progress = gimp_progress_start (GIMP_PROGRESS (display), _("Rotating"), FALSE); gimp_image_rotate (display->image, action_data_get_context (data), (GimpRotationType) value, progress); if (progress) gimp_progress_end (progress); gimp_image_flush (display->image); }
void image_resize_to_selection_cmd_callback (GtkAction *action, gpointer data) { GimpDisplay *display; GimpProgress *progress; return_if_no_display (display, data); progress = gimp_progress_start (GIMP_PROGRESS (display), _("Resizing"), FALSE); gimp_image_resize_to_selection (display->image, action_data_get_context (data), progress); if (progress) gimp_progress_end (progress); gimp_image_flush (display->image); }
static GimpProgress * gimp_progress_dialog_progress_start (GimpProgress *progress, const gchar *message, gboolean cancelable) { GimpProgressDialog *dialog = GIMP_PROGRESS_DIALOG (progress); if (! dialog->box) return NULL; if (gimp_progress_start (GIMP_PROGRESS (dialog->box), message, cancelable)) { gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL, cancelable); gtk_window_present (GTK_WINDOW (dialog)); return progress; } return NULL; }
static void gimp_cage_tool_transform_progress (GObject *object, const GParamSpec *pspec, GimpCageTool *ct) { GimpProgress *progress = GIMP_PROGRESS (ct); gdouble value; g_object_get (object, "progress", &value, NULL); if (value == 0.0) { gimp_progress_start (progress, _("Cage Transform"), FALSE); } else if (value == 1.0) { gimp_progress_end (progress); } else { gimp_progress_set_value (progress, value); } }
static void convert_precision_dialog_response (GtkWidget *widget, gint response_id, ConvertDialog *dialog) { if (response_id == GTK_RESPONSE_OK) { GimpProgress *progress; progress = gimp_progress_start (dialog->progress, FALSE, _("Converting to lower bit depth")); gimp_image_convert_precision (dialog->image, dialog->precision, dialog->layer_dither_type, dialog->text_layer_dither_type, dialog->mask_dither_type, progress); if (progress) gimp_progress_end (progress); gimp_image_flush (dialog->image); /* gegl:color-reduction only does 16 bits */ if (dialog->bits <= 16) { /* Save defaults for next time */ saved_layer_dither_type = dialog->layer_dither_type; saved_text_layer_dither_type = dialog->text_layer_dither_type; saved_mask_dither_type = dialog->mask_dither_type; } } gtk_widget_destroy (dialog->dialog); }
static gboolean file_remote_copy_file (Gimp *gimp, GFile *src_file, GFile *dest_file, RemoteCopyMode mode, GimpProgress *progress, GError **error) { RemoteProgress remote_progress = { 0, }; gboolean success; GError *my_error = NULL; remote_progress.mode = mode; remote_progress.progress = progress; if (progress) { remote_progress.cancellable = g_cancellable_new (); gimp_progress_start (progress, TRUE, _("Connecting to server")); g_signal_connect (progress, "cancel", G_CALLBACK (file_remote_copy_file_cancel), &remote_progress); success = g_file_copy (src_file, dest_file, G_FILE_COPY_OVERWRITE, remote_progress.cancellable, file_remote_progress_callback, &remote_progress, &my_error); gimp_progress_set_value (progress, 1.0); } else { success = g_file_copy (src_file, dest_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &my_error); } if (! success && ! gimp->no_interface && my_error && my_error->domain == G_IO_ERROR && my_error->code == G_IO_ERROR_NOT_MOUNTED) { g_clear_error (&my_error); if (gimp_mount_enclosing_volume (gimp, mode == DOWNLOAD ? src_file : dest_file, progress, error)) { if (progress) { success = g_file_copy (src_file, dest_file, 0, remote_progress.cancellable, file_remote_progress_callback, &remote_progress, error); } else { success = g_file_copy (src_file, dest_file, 0, NULL, NULL, NULL, error); } } } if (progress) { g_signal_handlers_disconnect_by_func (progress, file_remote_copy_file_cancel, &remote_progress); gimp_progress_end (progress); g_object_unref (remote_progress.cancellable); } return success; }
gboolean gimp_image_convert_color_profile (GimpImage *image, GimpColorProfile *dest_profile, GimpColorRenderingIntent intent, gboolean bpc, GimpProgress *progress, GError **error) { GimpColorProfile *src_profile; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (dest_profile != NULL, FALSE); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! gimp_image_validate_color_profile (image, dest_profile, NULL, error)) return FALSE; src_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image)); if (! src_profile || gimp_color_profile_is_equal (src_profile, dest_profile)) return TRUE; if (progress) gimp_progress_start (progress, FALSE, _("Converting from '%s' to '%s'"), gimp_color_profile_get_label (src_profile), gimp_color_profile_get_label (dest_profile)); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT, _("Color profile conversion")); gimp_image_set_color_profile (image, dest_profile, NULL); /* omg... */ gimp_image_parasite_detach (image, "icc-profile-name"); switch (gimp_image_get_base_type (image)) { case GIMP_RGB: gimp_image_convert_profile_rgb (image, src_profile, dest_profile, intent, bpc, progress); break; case GIMP_GRAY: break; case GIMP_INDEXED: gimp_image_convert_profile_indexed (image, src_profile, dest_profile, intent, bpc, progress); break; } gimp_image_undo_group_end (image); if (progress) gimp_progress_end (progress); return TRUE; }
static GimpValueArray * xcf_save_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { XcfInfo info; GimpValueArray *return_vals; GimpImage *image; const gchar *filename; gboolean success = FALSE; gimp_set_busy (gimp); image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp); filename = g_value_get_string (gimp_value_array_index (args, 3)); info.fp = g_fopen (filename, "wb"); if (info.fp) { info.gimp = gimp; info.progress = progress; info.cp = 0; info.filename = filename; info.active_layer = NULL; info.active_channel = NULL; info.floating_sel_drawable = NULL; info.floating_sel = NULL; info.floating_sel_offset = 0; info.swap_num = 0; info.ref_count = NULL; info.compression = COMPRESS_RLE; if (progress) { gchar *name = g_filename_display_name (filename); gchar *msg = g_strdup_printf (_("Saving '%s'"), name); gimp_progress_start (progress, msg, FALSE); g_free (msg); g_free (name); } xcf_save_choose_format (&info, image); success = xcf_save_image (&info, image, error); if (success) { if (fclose (info.fp) == EOF) { int save_errno = errno; g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (save_errno), _("Error saving XCF file: %s"), g_strerror (save_errno)); success = FALSE; } } else { fclose (info.fp); } if (progress) gimp_progress_end (progress); } else { int save_errno = errno; g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (save_errno), _("Could not open '%s' for writing: %s"), gimp_filename_to_utf8 (filename), g_strerror (save_errno)); } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); gimp_unset_busy (gimp); return return_vals; }
static GimpValueArray * xcf_load_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { XcfInfo info; GimpValueArray *return_vals; GimpImage *image = NULL; const gchar *filename; gboolean success = FALSE; gchar id[14]; gimp_set_busy (gimp); filename = g_value_get_string (gimp_value_array_index (args, 1)); info.fp = g_fopen (filename, "rb"); if (info.fp) { info.gimp = gimp; info.progress = progress; info.cp = 0; info.filename = filename; info.tattoo_state = 0; info.active_layer = NULL; info.active_channel = NULL; info.floating_sel_drawable = NULL; info.floating_sel = NULL; info.floating_sel_offset = 0; info.swap_num = 0; info.ref_count = NULL; info.compression = COMPRESS_NONE; if (progress) { gchar *name = g_filename_display_name (filename); gchar *msg = g_strdup_printf (_("Opening '%s'"), name); gimp_progress_start (progress, msg, FALSE); g_free (msg); g_free (name); } success = TRUE; info.cp += xcf_read_int8 (info.fp, (guint8 *) id, 14); if (! g_str_has_prefix (id, "gimp xcf ")) { success = FALSE; } else if (strcmp (id + 9, "file") == 0) { info.file_version = 0; } else if (id[9] == 'v') { info.file_version = atoi (id + 10); } else { success = FALSE; } if (success) { if (info.file_version >= 0 && info.file_version < G_N_ELEMENTS (xcf_loaders)) { image = (*(xcf_loaders[info.file_version])) (gimp, &info, error); if (! image) success = FALSE; } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("XCF error: unsupported XCF file version %d " "encountered"), info.file_version); success = FALSE; } } fclose (info.fp); if (progress) gimp_progress_end (progress); } else { int save_errno = errno; g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (save_errno), _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (filename), g_strerror (save_errno)); } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) gimp_value_set_image (gimp_value_array_index (return_vals, 1), image); gimp_unset_busy (gimp); return return_vals; }
static GimpValueArray * xcf_save_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { XcfInfo info = { 0, }; GimpValueArray *return_vals; GimpImage *image; const gchar *uri; gchar *filename; GFile *file; gboolean success = FALSE; GError *my_error = NULL; gimp_set_busy (gimp); image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp); uri = g_value_get_string (gimp_value_array_index (args, 3)); #ifdef GIO_IS_FIXED file = g_file_new_for_uri (uri); #else file = g_file_new_for_path (uri); #endif filename = g_file_get_parse_name (file); info.output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, &my_error)); if (info.output) { info.gimp = gimp; info.seekable = G_SEEKABLE (info.output); info.progress = progress; info.filename = filename; info.compression = COMPRESS_RLE; if (progress) { gchar *name = g_filename_display_name (filename); gchar *msg = g_strdup_printf (_("Saving '%s'"), name); gimp_progress_start (progress, msg, FALSE); g_free (msg); g_free (name); } xcf_save_choose_format (&info, image); success = xcf_save_image (&info, image, error); g_object_unref (info.output); if (progress) gimp_progress_end (progress); } else { g_propagate_prefixed_error (error, my_error, _("Could not open '%s' for writing: "), filename); } g_free (filename); g_object_unref (file); return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); gimp_unset_busy (gimp); return return_vals; }
static GimpValueArray * xcf_load_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { XcfInfo info = { 0, }; GimpValueArray *return_vals; GimpImage *image = NULL; const gchar *uri; gchar *filename; GFile *file; gboolean success = FALSE; gchar id[14]; GError *my_error = NULL; gimp_set_busy (gimp); uri = g_value_get_string (gimp_value_array_index (args, 1)); #ifdef GIO_IS_FIXED file = g_file_new_for_uri (uri); #else file = g_file_new_for_path (uri); #endif filename = g_file_get_parse_name (file); info.input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error)); if (info.input) { info.gimp = gimp; info.seekable = G_SEEKABLE (info.input); info.progress = progress; info.filename = filename; info.compression = COMPRESS_NONE; if (progress) { gchar *name = g_filename_display_name (filename); gchar *msg = g_strdup_printf (_("Opening '%s'"), name); gimp_progress_start (progress, msg, FALSE); g_free (msg); g_free (name); } success = TRUE; info.cp += xcf_read_int8 (info.input, (guint8 *) id, 14); if (! g_str_has_prefix (id, "gimp xcf ")) { success = FALSE; } else if (strcmp (id + 9, "file") == 0) { info.file_version = 0; } else if (id[9] == 'v') { info.file_version = atoi (id + 10); } else { success = FALSE; } if (success) { if (info.file_version >= 0 && info.file_version < G_N_ELEMENTS (xcf_loaders)) { image = (*(xcf_loaders[info.file_version])) (gimp, &info, error); if (! image) success = FALSE; } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("XCF error: unsupported XCF file version %d " "encountered"), info.file_version); success = FALSE; } } g_object_unref (info.input); if (progress) gimp_progress_end (progress); } else { g_propagate_prefixed_error (error, my_error, _("Could not open '%s' for reading: "), filename); } g_free (filename); g_object_unref (file); return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) gimp_value_set_image (gimp_value_array_index (return_vals, 1), image); gimp_unset_busy (gimp); return return_vals; }