static void gimp_image_undo_constructed (GObject *object) { GimpImageUndo *image_undo = GIMP_IMAGE_UNDO (object); GimpImage *image; G_OBJECT_CLASS (parent_class)->constructed (object); image = GIMP_UNDO (object)->image; switch (GIMP_UNDO (object)->undo_type) { case GIMP_UNDO_IMAGE_TYPE: image_undo->base_type = gimp_image_get_base_type (image); break; case GIMP_UNDO_IMAGE_PRECISION: image_undo->precision = gimp_image_get_precision (image); break; case GIMP_UNDO_IMAGE_SIZE: image_undo->width = gimp_image_get_width (image); image_undo->height = gimp_image_get_height (image); break; case GIMP_UNDO_IMAGE_RESOLUTION: gimp_image_get_resolution (image, &image_undo->xresolution, &image_undo->yresolution); image_undo->resolution_unit = gimp_image_get_unit (image); break; case GIMP_UNDO_IMAGE_GRID: g_assert (GIMP_IS_GRID (image_undo->grid)); break; case GIMP_UNDO_IMAGE_COLORMAP: image_undo->num_colors = gimp_image_get_colormap_size (image); image_undo->colormap = g_memdup (gimp_image_get_colormap (image), GIMP_IMAGE_COLORMAP_SIZE); break; case GIMP_UNDO_IMAGE_METADATA: image_undo->metadata = gimp_metadata_duplicate (gimp_image_get_metadata (image)); break; case GIMP_UNDO_PARASITE_ATTACH: case GIMP_UNDO_PARASITE_REMOVE: g_assert (image_undo->parasite_name != NULL); image_undo->parasite = gimp_parasite_copy (gimp_image_parasite_find (image, image_undo->parasite_name)); break; default: g_assert_not_reached (); } }
static const gchar * gimp_display_shell_title_image_precision (GimpImage *image) { const gchar *name = ""; gimp_enum_get_value (GIMP_TYPE_PRECISION, gimp_image_get_precision (image), NULL, NULL, &name, NULL); return name; }
gboolean gimp_pdb_image_is_precision (GimpImage *image, GimpPrecision precision, GError **error) { g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (gimp_image_get_precision (image) == precision) return TRUE; g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Image '%s' (%d) has precision '%s', " "but an image of precision '%s' is expected"), gimp_image_get_display_name (image), gimp_image_get_ID (image), gimp_pdb_enum_value_get_nick (GIMP_TYPE_PRECISION, gimp_image_get_precision (image)), gimp_pdb_enum_value_get_nick (GIMP_TYPE_PRECISION, precision)); return FALSE; }
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 gimp_image_undo_pop (GimpUndo *undo, GimpUndoMode undo_mode, GimpUndoAccumulator *accum) { GimpImageUndo *image_undo = GIMP_IMAGE_UNDO (undo); GimpImage *image = undo->image; GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image); GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum); switch (undo->undo_type) { case GIMP_UNDO_IMAGE_TYPE: { GimpImageBaseType base_type; base_type = image_undo->base_type; image_undo->base_type = gimp_image_get_base_type (image); g_object_set (image, "base-type", base_type, NULL); gimp_image_colormap_changed (image, -1); if (image_undo->base_type != gimp_image_get_base_type (image)) accum->mode_changed = TRUE; } break; case GIMP_UNDO_IMAGE_PRECISION: { GimpPrecision precision; precision = image_undo->precision; image_undo->precision = gimp_image_get_precision (image); g_object_set (image, "precision", precision, NULL); if (image_undo->precision != gimp_image_get_precision (image)) accum->precision_changed = TRUE; } break; case GIMP_UNDO_IMAGE_SIZE: { gint width; gint height; gint previous_origin_x; gint previous_origin_y; gint previous_width; gint previous_height; width = image_undo->width; height = image_undo->height; previous_origin_x = image_undo->previous_origin_x; previous_origin_y = image_undo->previous_origin_y; previous_width = image_undo->previous_width; previous_height = image_undo->previous_height; /* Transform to a redo */ image_undo->width = gimp_image_get_width (image); image_undo->height = gimp_image_get_height (image); image_undo->previous_origin_x = -previous_origin_x; image_undo->previous_origin_y = -previous_origin_y; image_undo->previous_width = width; image_undo->previous_height = height; g_object_set (image, "width", width, "height", height, NULL); gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimp_image_get_mask (image))); if (gimp_image_get_width (image) != image_undo->width || gimp_image_get_height (image) != image_undo->height) { accum->size_changed = TRUE; accum->previous_origin_x = previous_origin_x; accum->previous_origin_y = previous_origin_y; accum->previous_width = previous_width; accum->previous_height = previous_height; } } break; case GIMP_UNDO_IMAGE_RESOLUTION: { gdouble xres; gdouble yres; gimp_image_get_resolution (image, &xres, &yres); if (ABS (image_undo->xresolution - xres) >= 1e-5 || ABS (image_undo->yresolution - yres) >= 1e-5) { private->xresolution = image_undo->xresolution; private->yresolution = image_undo->yresolution; image_undo->xresolution = xres; image_undo->yresolution = yres; accum->resolution_changed = TRUE; } }
void file_import_image (GimpImage *image, GimpContext *context, GFile *file, gboolean interactive, GimpProgress *progress) { GimpCoreConfig *config; g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (GIMP_IS_CONTEXT (context)); g_return_if_fail (G_IS_FILE (file)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); config = image->gimp->config; if (interactive && gimp_image_get_base_type (image) != GIMP_INDEXED) { if (config->import_promote_float) { GimpPrecision old_precision = gimp_image_get_precision (image); if (old_precision != GIMP_PRECISION_FLOAT_LINEAR) { gimp_image_convert_precision (image, GIMP_PRECISION_FLOAT_LINEAR, GEGL_DITHER_NONE, GEGL_DITHER_NONE, GEGL_DITHER_NONE, progress); if (config->import_promote_dither && old_precision == GIMP_PRECISION_U8_NON_LINEAR) { gimp_image_convert_dither_u8 (image, progress); } } } if (config->import_add_alpha) { GList *layers = gimp_image_get_layer_list (image); GList *list; for (list = layers; list; list = g_list_next (list)) { if (! gimp_viewable_get_children (list->data) && ! gimp_item_is_text_layer (list->data) && ! gimp_drawable_has_alpha (list->data)) { gimp_layer_add_alpha (list->data); } } g_list_free (layers); } } gimp_image_import_color_profile (image, context, progress, interactive); /* Remember the import source */ gimp_image_set_imported_file (image, file); /* We shall treat this file as an Untitled file */ gimp_image_set_file (image, NULL); }
void gimp_image_convert_precision (GimpImage *image, GimpPrecision precision, gint layer_dither_type, gint text_layer_dither_type, gint mask_dither_type, GimpProgress *progress) { GList *all_drawables; GList *list; const gchar *undo_desc = NULL; gint nth_drawable, n_drawables; g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (precision != gimp_image_get_precision (image)); g_return_if_fail (precision == GIMP_PRECISION_U8_GAMMA || gimp_image_get_base_type (image) != GIMP_INDEXED); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); all_drawables = g_list_concat (gimp_image_get_layer_list (image), gimp_image_get_channel_list (image)); n_drawables = g_list_length (all_drawables) + 1 /* + selection */; switch (precision) { case GIMP_PRECISION_U8_LINEAR: undo_desc = C_("undo-type", "Convert Image to 8 bit linear integer"); break; case GIMP_PRECISION_U8_GAMMA: undo_desc = C_("undo-type", "Convert Image to 8 bit gamma integer"); break; case GIMP_PRECISION_U16_LINEAR: undo_desc = C_("undo-type", "Convert Image to 16 bit linear integer"); break; case GIMP_PRECISION_U16_GAMMA: undo_desc = C_("undo-type", "Convert Image to 16 bit gamma integer"); break; case GIMP_PRECISION_U32_LINEAR: undo_desc = C_("undo-type", "Convert Image to 32 bit linear integer"); break; case GIMP_PRECISION_U32_GAMMA: undo_desc = C_("undo-type", "Convert Image to 32 bit gamma integer"); break; case GIMP_PRECISION_HALF_LINEAR: undo_desc = C_("undo-type", "Convert Image to 16 bit linear floating point"); break; case GIMP_PRECISION_HALF_GAMMA: undo_desc = C_("undo-type", "Convert Image to 16 bit gamma floating point"); break; case GIMP_PRECISION_FLOAT_LINEAR: undo_desc = C_("undo-type", "Convert Image to 32 bit linear floating point"); break; case GIMP_PRECISION_FLOAT_GAMMA: undo_desc = C_("undo-type", "Convert Image to 32 bit gamma floating point"); break; case GIMP_PRECISION_DOUBLE_LINEAR: undo_desc = C_("undo-type", "Convert Image to 64 bit linear floating point"); break; case GIMP_PRECISION_DOUBLE_GAMMA: undo_desc = C_("undo-type", "Convert Image to 64 bit gamma floating point"); break; } if (progress) gimp_progress_start (progress, FALSE, "%s", undo_desc); g_object_freeze_notify (G_OBJECT (image)); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT, undo_desc); /* Push the image precision to the stack */ gimp_image_undo_push_image_precision (image, NULL); /* Set the new precision */ g_object_set (image, "precision", precision, NULL); for (list = all_drawables, nth_drawable = 0; list; list = g_list_next (list), nth_drawable++) { GimpDrawable *drawable = list->data; gint dither_type; if (gimp_item_is_text_layer (GIMP_ITEM (drawable))) dither_type = text_layer_dither_type; else dither_type = layer_dither_type; gimp_drawable_convert_type (drawable, image, gimp_drawable_get_base_type (drawable), precision, dither_type, mask_dither_type, FALSE, TRUE); if (progress) gimp_progress_set_value (progress, (gdouble) nth_drawable / (gdouble) n_drawables); } g_list_free (all_drawables); /* convert the selection mask */ { GimpChannel *mask = gimp_image_get_mask (image); GeglBuffer *buffer; gimp_image_undo_push_mask_precision (image, NULL, mask); buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, gimp_image_get_width (image), gimp_image_get_height (image)), gimp_image_get_mask_format (image)); gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), NULL, GEGL_ABYSS_NONE, buffer, NULL); gimp_drawable_set_buffer (GIMP_DRAWABLE (mask), FALSE, NULL, buffer); g_object_unref (buffer); nth_drawable++; if (progress) gimp_progress_set_value (progress, (gdouble) nth_drawable / (gdouble) n_drawables); } gimp_image_undo_group_end (image); gimp_image_precision_changed (image); g_object_thaw_notify (G_OBJECT (image)); if (progress) gimp_progress_end (progress); }
GtkWidget * color_profile_dialog_new (ColorProfileDialogType dialog_type, GimpImage *image, GimpContext *context, GtkWidget *parent, GimpProgress *progress) { ProfileDialog *dialog; GtkWidget *frame; GtkWidget *vbox; GtkWidget *expander; GtkWidget *label; GimpColorProfile *src_profile; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); dialog = g_slice_new0 (ProfileDialog); dialog->dialog_type = dialog_type; dialog->image = image; dialog->progress = progress; dialog->config = image->gimp->config->color_management; if (saved_intent == -1) { dialog->intent = GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC; dialog->bpc = TRUE; } else { dialog->intent = saved_intent; dialog->bpc = saved_bpc; } switch (dialog_type) { const Babl *format; case COLOR_PROFILE_DIALOG_ASSIGN_PROFILE: dialog->dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context, _("Assign ICC Color Profile"), "gimp-image-color-profile-assign", NULL, _("Assign a color profile to the image"), parent, gimp_standard_help_func, GIMP_HELP_IMAGE_COLOR_PROFILE_ASSIGN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Assign"), GTK_RESPONSE_OK, NULL); dialog->builtin_profile = gimp_image_get_builtin_color_profile (dialog->image); break; case COLOR_PROFILE_DIALOG_CONVERT_TO_PROFILE: dialog->dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context, _("Convert to ICC Color Profile"), "gimp-image-color-profile-convert", NULL, _("Convert the image to a color profile"), parent, gimp_standard_help_func, GIMP_HELP_IMAGE_COLOR_PROFILE_CONVERT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONVERT, GTK_RESPONSE_OK, NULL); dialog->builtin_profile = gimp_image_get_builtin_color_profile (dialog->image); break; case COLOR_PROFILE_DIALOG_CONVERT_TO_RGB: dialog->dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context, _("RGB Conversion"), "gimp-image-convert-rgb", GIMP_STOCK_CONVERT_RGB, _("Convert Image to RGB"), parent, gimp_standard_help_func, GIMP_HELP_IMAGE_CONVERT_RGB, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONVERT, GTK_RESPONSE_OK, NULL); format = gimp_babl_format (GIMP_RGB, gimp_image_get_precision (dialog->image), TRUE); dialog->builtin_profile = gimp_babl_format_get_color_profile (format); break; case COLOR_PROFILE_DIALOG_CONVERT_TO_GRAY: dialog->dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context, _("Grayscale Conversion"), "gimp-image-convert-gray", GIMP_STOCK_CONVERT_GRAYSCALE, _("Convert Image to Grayscale"), parent, gimp_standard_help_func, GIMP_HELP_IMAGE_CONVERT_GRAYSCALE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONVERT, GTK_RESPONSE_OK, NULL); format = gimp_babl_format (GIMP_GRAY, gimp_image_get_precision (dialog->image), TRUE); dialog->builtin_profile = gimp_babl_format_get_color_profile (format); break; } gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); g_object_weak_ref (G_OBJECT (dialog->dialog), (GWeakNotify) color_profile_dialog_free, dialog); g_signal_connect (dialog->dialog, "response", G_CALLBACK (color_profile_dialog_response), dialog); dialog->main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (dialog->main_vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), dialog->main_vbox, TRUE, TRUE, 0); gtk_widget_show (dialog->main_vbox); frame = gimp_frame_new (_("Current Color Profile")); gtk_box_pack_start (GTK_BOX (dialog->main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); src_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image)); label = gimp_color_profile_label_new (src_profile); gtk_container_add (GTK_CONTAINER (frame), label); gtk_widget_show (label); frame = gimp_frame_new (dialog_type == COLOR_PROFILE_DIALOG_ASSIGN_PROFILE ? _("Assign") : _("Convert to")); gtk_box_pack_start (GTK_BOX (dialog->main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); dialog->combo = color_profile_combo_box_new (dialog); gtk_box_pack_start (GTK_BOX (vbox), dialog->combo, FALSE, FALSE, 0); gtk_widget_show (dialog->combo); expander = gtk_expander_new_with_mnemonic (_("Profile _details")); gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 0); gtk_widget_show (expander); dialog->dest_view = gimp_color_profile_view_new (); gtk_container_add (GTK_CONTAINER (expander), dialog->dest_view); gtk_widget_show (dialog->dest_view); g_signal_connect (dialog->combo, "changed", G_CALLBACK (color_profile_dest_changed), dialog); color_profile_dest_changed (dialog->combo, dialog); if (dialog_type == COLOR_PROFILE_DIALOG_CONVERT_TO_PROFILE) { GtkWidget *vbox; GtkWidget *hbox; GtkWidget *combo; GtkWidget *toggle; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (dialog->main_vbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); label = gtk_label_new_with_mnemonic (_("_Rendering Intent:")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); combo = gimp_enum_combo_box_new (GIMP_TYPE_COLOR_RENDERING_INTENT); gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0); gtk_widget_show (combo); gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), dialog->intent, G_CALLBACK (gimp_int_combo_box_get_active), &dialog->intent); gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); toggle = gtk_check_button_new_with_mnemonic (_("_Black Point Compensation")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), dialog->bpc); gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); gtk_widget_show (toggle); g_signal_connect (toggle, "toggled", G_CALLBACK (gimp_toggle_button_update), &dialog->bpc); } return dialog->dialog; }
void image_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); gboolean is_indexed = FALSE; gboolean is_u8_gamma = FALSE; gboolean aux = FALSE; gboolean lp = FALSE; gboolean sel = FALSE; gboolean groups = FALSE; gboolean profile = FALSE; if (image) { GimpContainer *layers; const gchar *action = NULL; switch (gimp_image_get_base_type (image)) { case GIMP_RGB: action = "image-convert-rgb"; break; case GIMP_GRAY: action = "image-convert-grayscale"; break; case GIMP_INDEXED: action = "image-convert-indexed"; break; } gimp_action_group_set_action_active (group, action, TRUE); switch (gimp_image_get_precision (image)) { case GIMP_PRECISION_U8_LINEAR: action = "image-convert-u8-linear"; break; case GIMP_PRECISION_U8_GAMMA: action = "image-convert-u8-gamma"; break; case GIMP_PRECISION_U16_LINEAR: action = "image-convert-u16-linear"; break; case GIMP_PRECISION_U16_GAMMA: action = "image-convert-u16-gamma"; break; case GIMP_PRECISION_U32_LINEAR: action = "image-convert-u32-linear"; break; case GIMP_PRECISION_U32_GAMMA: action = "image-convert-u32-gamma"; break; case GIMP_PRECISION_HALF_LINEAR: action = "image-convert-half-linear"; break; case GIMP_PRECISION_HALF_GAMMA: action = "image-convert-half-gamma"; break; case GIMP_PRECISION_FLOAT_LINEAR: action = "image-convert-float-linear"; break; case GIMP_PRECISION_FLOAT_GAMMA: action = "image-convert-float-gamma"; break; case GIMP_PRECISION_DOUBLE_LINEAR: action = "image-convert-double-linear"; break; case GIMP_PRECISION_DOUBLE_GAMMA: action = "image-convert-double-gamma"; break; } gimp_action_group_set_action_active (group, action, TRUE); is_indexed = (gimp_image_get_base_type (image) == GIMP_INDEXED); is_u8_gamma = (gimp_image_get_precision (image) == GIMP_PRECISION_U8_GAMMA); aux = (gimp_image_get_active_channel (image) != NULL); lp = ! gimp_image_is_empty (image); sel = ! gimp_channel_is_empty (gimp_image_get_mask (image)); layers = gimp_image_get_layers (image); groups = ! gimp_item_stack_is_flat (GIMP_ITEM_STACK (layers)); profile = (gimp_image_get_icc_parasite (image) != NULL); } #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) SET_SENSITIVE ("image-convert-rgb", image); SET_SENSITIVE ("image-convert-grayscale", image); SET_SENSITIVE ("image-convert-indexed", image && !groups && is_u8_gamma); SET_SENSITIVE ("image-convert-u8-gamma", image); SET_SENSITIVE ("image-convert-u8-linear", image && !is_indexed); SET_SENSITIVE ("image-convert-u16-gamma", image && !is_indexed); SET_SENSITIVE ("image-convert-u16-linear", image && !is_indexed); SET_SENSITIVE ("image-convert-u32-gamma", image && !is_indexed); SET_SENSITIVE ("image-convert-u32-linear", image && !is_indexed); SET_SENSITIVE ("image-convert-half-gamma", image && !is_indexed); SET_SENSITIVE ("image-convert-half-linear", image && !is_indexed); SET_SENSITIVE ("image-convert-float-gamma", image && !is_indexed); SET_SENSITIVE ("image-convert-float-linear", image && !is_indexed); SET_SENSITIVE ("image-convert-double-gamma", image && !is_indexed); SET_SENSITIVE ("image-convert-double-linear", image && !is_indexed); SET_SENSITIVE ("image-color-profile-assign", image); SET_SENSITIVE ("image-color-profile-convert", image); SET_SENSITIVE ("image-color-profile-discard", image && profile); SET_SENSITIVE ("image-flip-horizontal", image); SET_SENSITIVE ("image-flip-vertical", image); SET_SENSITIVE ("image-rotate-90", image); SET_SENSITIVE ("image-rotate-180", image); SET_SENSITIVE ("image-rotate-270", image); SET_SENSITIVE ("image-resize", image); SET_SENSITIVE ("image-resize-to-layers", image); SET_SENSITIVE ("image-resize-to-selection", image && sel); SET_SENSITIVE ("image-print-size", image); SET_SENSITIVE ("image-scale", image); SET_SENSITIVE ("image-crop-to-selection", image && sel); SET_SENSITIVE ("image-crop-to-content", image); SET_SENSITIVE ("image-duplicate", image); SET_SENSITIVE ("image-merge-layers", image && !aux && lp); SET_SENSITIVE ("image-flatten", image && !aux && lp); SET_SENSITIVE ("image-configure-grid", image); SET_SENSITIVE ("image-properties", image); #undef SET_SENSITIVE }
void gimp_image_convert_precision (GimpImage *image, GimpPrecision precision, gint layer_dither_type, gint text_layer_dither_type, gint mask_dither_type, GimpProgress *progress) { GimpColorProfile *old_profile; GimpColorProfile *new_profile = NULL; const Babl *old_format; const Babl *new_format; GList *all_drawables; GList *list; const gchar *undo_desc = NULL; GimpProgress *sub_progress = NULL; gint nth_drawable, n_drawables; g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (precision != gimp_image_get_precision (image)); g_return_if_fail (precision == GIMP_PRECISION_U8_GAMMA || gimp_image_get_base_type (image) != GIMP_INDEXED); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); all_drawables = g_list_concat (gimp_image_get_layer_list (image), gimp_image_get_channel_list (image)); n_drawables = g_list_length (all_drawables) + 1 /* + selection */; if (progress) sub_progress = gimp_sub_progress_new (progress); switch (precision) { case GIMP_PRECISION_U8_LINEAR: undo_desc = C_("undo-type", "Convert Image to 8 bit linear integer"); break; case GIMP_PRECISION_U8_GAMMA: undo_desc = C_("undo-type", "Convert Image to 8 bit gamma integer"); break; case GIMP_PRECISION_U16_LINEAR: undo_desc = C_("undo-type", "Convert Image to 16 bit linear integer"); break; case GIMP_PRECISION_U16_GAMMA: undo_desc = C_("undo-type", "Convert Image to 16 bit gamma integer"); break; case GIMP_PRECISION_U32_LINEAR: undo_desc = C_("undo-type", "Convert Image to 32 bit linear integer"); break; case GIMP_PRECISION_U32_GAMMA: undo_desc = C_("undo-type", "Convert Image to 32 bit gamma integer"); break; case GIMP_PRECISION_HALF_LINEAR: undo_desc = C_("undo-type", "Convert Image to 16 bit linear floating point"); break; case GIMP_PRECISION_HALF_GAMMA: undo_desc = C_("undo-type", "Convert Image to 16 bit gamma floating point"); break; case GIMP_PRECISION_FLOAT_LINEAR: undo_desc = C_("undo-type", "Convert Image to 32 bit linear floating point"); break; case GIMP_PRECISION_FLOAT_GAMMA: undo_desc = C_("undo-type", "Convert Image to 32 bit gamma floating point"); break; case GIMP_PRECISION_DOUBLE_LINEAR: undo_desc = C_("undo-type", "Convert Image to 64 bit linear floating point"); break; case GIMP_PRECISION_DOUBLE_GAMMA: undo_desc = C_("undo-type", "Convert Image to 64 bit gamma floating point"); break; } if (progress) gimp_progress_start (progress, FALSE, "%s", undo_desc); g_object_freeze_notify (G_OBJECT (image)); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT, undo_desc); /* Push the image precision to the stack */ gimp_image_undo_push_image_precision (image, NULL); old_profile = gimp_image_get_color_profile (image); old_format = gimp_image_get_layer_format (image, FALSE); /* Set the new precision */ g_object_set (image, "precision", precision, NULL); new_format = gimp_image_get_layer_format (image, FALSE); if (old_profile && gimp_babl_format_get_linear (old_format) != gimp_babl_format_get_linear (new_format)) { GimpColorProfile *new_profile; /* when converting between linear and gamma, we create a new * profile using the original profile's chromacities and * whitepoint, but a linear/sRGB-gamma TRC. */ if (gimp_babl_format_get_linear (new_format)) { new_profile = gimp_color_profile_new_linear_from_color_profile (old_profile); } else { new_profile = gimp_color_profile_new_srgb_trc_from_color_profile (old_profile); } /* if a new profile cannot be be generated, convert to the * builtin profile, which is better than leaving the user with * broken colors */ if (! new_profile) { new_profile = gimp_image_get_builtin_color_profile (image); g_object_ref (new_profile); } } for (list = all_drawables, nth_drawable = 0; list; list = g_list_next (list), nth_drawable++) { GimpDrawable *drawable = list->data; gint dither_type; if (gimp_item_is_text_layer (GIMP_ITEM (drawable))) dither_type = text_layer_dither_type; else dither_type = layer_dither_type; if (sub_progress) gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (sub_progress), nth_drawable, n_drawables); gimp_drawable_convert_type (drawable, image, gimp_drawable_get_base_type (drawable), precision, new_profile, dither_type, mask_dither_type, TRUE, sub_progress); } g_list_free (all_drawables); if (old_profile) { gimp_image_set_color_profile (image, new_profile, NULL); g_object_unref (new_profile); } /* convert the selection mask */ { GimpChannel *mask = gimp_image_get_mask (image); GeglBuffer *buffer; if (sub_progress) gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (sub_progress), nth_drawable, n_drawables); gimp_image_undo_push_mask_precision (image, NULL, mask); buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, gimp_image_get_width (image), gimp_image_get_height (image)), gimp_image_get_mask_format (image)); gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), NULL, GEGL_ABYSS_NONE, buffer, NULL); gimp_drawable_set_buffer (GIMP_DRAWABLE (mask), FALSE, NULL, buffer); g_object_unref (buffer); nth_drawable++; } if (sub_progress) gimp_progress_set_value (sub_progress, 1.0); gimp_image_undo_group_end (image); gimp_image_precision_changed (image); g_object_thaw_notify (G_OBJECT (image)); if (sub_progress) g_object_unref (sub_progress); if (progress) gimp_progress_end (progress); }
/* Decompose an image. It returns the number of new (gray) images. * The image IDs for the new images are returned in image_ID_dst. * On failure, -1 is returned. */ static gint32 decompose (gint32 image_ID, gint32 drawable_ID, const gchar *extract_type, gint32 *image_ID_dst, gint32 *nlayers, gint32 *layer_ID_dst) { const gchar *layername; gint j, extract_idx; gint height, width, num_layers; GeglBuffer *src_buffer; GeglBuffer *dst_buffer[MAX_EXTRACT_IMAGES]; GimpPrecision precision; gboolean requirments = FALSE, decomp_has_alpha = FALSE; extract_idx = -1; /* Search extract type */ for (j = 0; j < G_N_ELEMENTS (extract); j++) { if (g_ascii_strcasecmp (extract_type, extract[j].type) == 0) { extract_idx = j; break; } } if (extract_idx < 0) return -1; num_layers = extract[extract_idx].num_images; /* Sanity checks */ src_buffer = gimp_drawable_get_buffer (drawable_ID); precision = gimp_image_get_precision (image_ID); for (j = 0; j < num_layers; j++) { /* FIXME: Not 100% reliable */ decomp_has_alpha |= !g_strcmp0 ("alpha", extract[extract_idx].component[j].babl_name); decomp_has_alpha |= !g_strcmp0 ("A", extract[extract_idx].component[j].babl_name); } requirments |= (gimp_drawable_is_rgb (drawable_ID)); requirments |= (gimp_drawable_is_indexed (drawable_ID)); requirments |= (gimp_drawable_is_gray (drawable_ID) && gimp_drawable_has_alpha (drawable_ID) && (num_layers <= 2) && decomp_has_alpha); requirments &= (!decomp_has_alpha || gimp_drawable_has_alpha (drawable_ID)); if (!requirments) { g_message (_("Image not suitable for this decomposition")); return -1; } width = gegl_buffer_get_width (src_buffer); height = gegl_buffer_get_height (src_buffer); /* Create all new gray images */ for (j = 0; j < num_layers; j++) { gchar *filename; gdouble xres, yres; filename = generate_filename (image_ID, extract_idx, j); gimp_image_get_resolution (image_ID, &xres, &yres); if (decovals.as_layers) { layername = gettext (extract[extract_idx].component[j].channel_name); if (j == 0) image_ID_dst[j] = create_new_image (filename, layername, width, height, GIMP_GRAY, precision, xres, yres, layer_ID_dst + j); else layer_ID_dst[j] = create_new_layer (image_ID_dst[0], j, layername, width, height, GIMP_GRAY); } else { image_ID_dst[j] = create_new_image (filename, NULL, width, height, GIMP_GRAY, precision, xres, yres, layer_ID_dst + j); } g_free (filename); dst_buffer[j] = gimp_drawable_get_buffer (layer_ID_dst[j]); } copy_n_components (src_buffer, dst_buffer, extract[extract_idx]); if (decovals.use_registration) transfer_registration_color (src_buffer, dst_buffer, num_layers); gimp_progress_update (1.0); g_object_unref (src_buffer); for (j = 0; j < num_layers; j++) { g_object_unref (dst_buffer[j]); } *nlayers = num_layers; return (decovals.as_layers ? 1 : num_layers); }
static void gimp_image_prop_view_update (GimpImagePropView *view) { GimpImage *image = view->image; GimpImageBaseType type; GimpPrecision precision; GimpUnit unit; gdouble unit_factor; gint unit_digits; const gchar *desc; gchar format_buf[32]; gchar buf[256]; gdouble xres; gdouble yres; gimp_image_get_resolution (image, &xres, &yres); /* pixel size */ g_snprintf (buf, sizeof (buf), ngettext ("%d × %d pixel", "%d × %d pixels", gimp_image_get_height (image)), gimp_image_get_width (image), gimp_image_get_height (image)); gtk_label_set_text (GTK_LABEL (view->pixel_size_label), buf); /* print size */ unit = gimp_get_default_unit (); unit_digits = gimp_unit_get_digits (unit); g_snprintf (format_buf, sizeof (format_buf), "%%.%df × %%.%df %s", unit_digits + 1, unit_digits + 1, gimp_unit_get_plural (unit)); g_snprintf (buf, sizeof (buf), format_buf, gimp_pixels_to_units (gimp_image_get_width (image), unit, xres), gimp_pixels_to_units (gimp_image_get_height (image), unit, yres)); gtk_label_set_text (GTK_LABEL (view->print_size_label), buf); /* resolution */ unit = gimp_image_get_unit (image); unit_factor = gimp_unit_get_factor (unit); g_snprintf (format_buf, sizeof (format_buf), _("pixels/%s"), gimp_unit_get_abbreviation (unit)); g_snprintf (buf, sizeof (buf), _("%g × %g %s"), xres / unit_factor, yres / unit_factor, unit == GIMP_UNIT_INCH ? _("ppi") : format_buf); gtk_label_set_text (GTK_LABEL (view->resolution_label), buf); /* color type */ type = gimp_image_get_base_type (image); gimp_enum_get_value (GIMP_TYPE_IMAGE_BASE_TYPE, type, NULL, NULL, &desc, NULL); switch (type) { case GIMP_RGB: case GIMP_GRAY: g_snprintf (buf, sizeof (buf), "%s", desc); break; case GIMP_INDEXED: g_snprintf (buf, sizeof (buf), "%s (%d %s)", desc, gimp_image_get_colormap_size (image), _("colors")); break; } gtk_label_set_text (GTK_LABEL (view->colorspace_label), buf); /* precision */ precision = gimp_image_get_precision (image); gimp_enum_get_value (GIMP_TYPE_PRECISION, precision, NULL, NULL, &desc, NULL); gtk_label_set_text (GTK_LABEL (view->precision_label), desc); /* size in memory */ gimp_image_prop_view_label_set_memsize (view->memsize_label, GIMP_OBJECT (image)); /* undo / redo */ gimp_image_prop_view_label_set_undo (view->undo_label, gimp_image_get_undo_stack (image)); gimp_image_prop_view_label_set_undo (view->redo_label, gimp_image_get_redo_stack (image)); /* number of layers */ g_snprintf (buf, sizeof (buf), "%d", gimp_image_get_width (image) * gimp_image_get_height (image)); gtk_label_set_text (GTK_LABEL (view->pixels_label), buf); /* number of layers */ g_snprintf (buf, sizeof (buf), "%d", gimp_image_get_n_layers (image)); gtk_label_set_text (GTK_LABEL (view->layers_label), buf); /* number of channels */ g_snprintf (buf, sizeof (buf), "%d", gimp_image_get_n_channels (image)); gtk_label_set_text (GTK_LABEL (view->channels_label), buf); /* number of vectors */ g_snprintf (buf, sizeof (buf), "%d", gimp_image_get_n_vectors (image)); gtk_label_set_text (GTK_LABEL (view->vectors_label), buf); }
/** * gimp_image_scale_check: * @image: A #GimpImage. * @new_width: The new width. * @new_height: The new height. * @max_memsize: The maximum new memory size. * @new_memsize: The new memory size. * * Inventory the layer list in image and check that it may be * scaled to @new_height and @new_width without problems. * * Return value: #GIMP_IMAGE_SCALE_OK if scaling the image will shrink none * of its layers completely away, and the new image size * is smaller than @max_memsize. * #GIMP_IMAGE_SCALE_TOO_SMALL if scaling would remove some * existing layers. * #GIMP_IMAGE_SCALE_TOO_BIG if the new image size would * exceed the maximum specified in the preferences. **/ GimpImageScaleCheckType gimp_image_scale_check (const GimpImage *image, gint new_width, gint new_height, gint64 max_memsize, gint64 *new_memsize) { GList *drawables; GList *all_layers; GList *list; gint64 current_size; gint64 scalable_size; gint64 scaled_size; gint64 undo_size; gint64 redo_size; gint64 fixed_size; gint64 new_size; g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_IMAGE_SCALE_TOO_SMALL); g_return_val_if_fail (new_memsize != NULL, GIMP_IMAGE_SCALE_TOO_SMALL); current_size = gimp_object_get_memsize (GIMP_OBJECT (image), NULL); /* the part of the image's memsize that scales linearly with the image */ drawables = gimp_image_item_list_get_list (image, NULL, GIMP_ITEM_TYPE_LAYERS | GIMP_ITEM_TYPE_CHANNELS, GIMP_ITEM_SET_ALL); gimp_image_item_list_filter (NULL, drawables, TRUE, FALSE); drawables = g_list_prepend (drawables, gimp_image_get_mask (image)); scalable_size = 0; scaled_size = 0; for (list = drawables; list; list = g_list_next (list)) { GimpDrawable *drawable = list->data; gdouble width = gimp_item_get_width (GIMP_ITEM (drawable)); gdouble height = gimp_item_get_height (GIMP_ITEM (drawable)); scalable_size += gimp_drawable_estimate_memsize (drawable, width, height); scaled_size += gimp_drawable_estimate_memsize (drawable, width * new_width / gimp_image_get_width (image), height * new_height / gimp_image_get_height (image)); } g_list_free (drawables); scalable_size += gimp_projection_estimate_memsize (gimp_image_get_base_type (image), gimp_image_get_precision (image), gimp_image_get_width (image), gimp_image_get_height (image)); scaled_size += gimp_projection_estimate_memsize (gimp_image_get_base_type (image), gimp_image_get_precision (image), new_width, new_height); GIMP_LOG (IMAGE_SCALE, "scalable_size = %"G_GINT64_FORMAT" scaled_size = %"G_GINT64_FORMAT, scalable_size, scaled_size); undo_size = gimp_object_get_memsize (GIMP_OBJECT (gimp_image_get_undo_stack (image)), NULL); redo_size = gimp_object_get_memsize (GIMP_OBJECT (gimp_image_get_redo_stack (image)), NULL); /* the fixed part of the image's memsize w/o any undo information */ fixed_size = current_size - undo_size - redo_size - scalable_size; /* calculate the new size, which is: */ new_size = (fixed_size + /* the fixed part */ scaled_size); /* plus the part that scales... */ GIMP_LOG (IMAGE_SCALE, "old_size = %"G_GINT64_FORMAT" new_size = %"G_GINT64_FORMAT, current_size - undo_size - redo_size, new_size); *new_memsize = new_size; if (new_size > current_size && new_size > max_memsize) return GIMP_IMAGE_SCALE_TOO_BIG; all_layers = gimp_image_get_layer_list (image); for (list = all_layers; list; list = g_list_next (list)) { GimpItem *item = list->data; /* group layers are updated automatically */ if (gimp_viewable_get_children (GIMP_VIEWABLE (item))) continue; if (! gimp_item_check_scaling (item, new_width, new_height)) { g_list_free (all_layers); return GIMP_IMAGE_SCALE_TOO_SMALL; } } g_list_free (all_layers); return GIMP_IMAGE_SCALE_OK; }