static GimpValueArray * image_convert_grayscale_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); if (success) { if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error)) { success = gimp_image_convert_type (image, GIMP_GRAY, 0, 0, FALSE, FALSE, FALSE, 0, NULL, NULL, error); } else { success = FALSE; } } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
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_type (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_literal (dialog->image->gimp, G_OBJECT (dialog->dialog), GIMP_MESSAGE_WARNING, 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); }
static GimpValueArray * image_convert_indexed_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; gint32 dither_type; gint32 palette_type; gint32 num_cols; gboolean alpha_dither; gboolean remove_unused; const gchar *palette; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); dither_type = g_value_get_enum (gimp_value_array_index (args, 1)); palette_type = g_value_get_enum (gimp_value_array_index (args, 2)); num_cols = g_value_get_int (gimp_value_array_index (args, 3)); alpha_dither = g_value_get_boolean (gimp_value_array_index (args, 4)); remove_unused = g_value_get_boolean (gimp_value_array_index (args, 5)); palette = g_value_get_string (gimp_value_array_index (args, 6)); if (success) { GimpPalette *pal = NULL; if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) && gimp_pdb_image_is_precision (image, GIMP_PRECISION_U8, error) && gimp_item_stack_is_flat (GIMP_ITEM_STACK (gimp_image_get_layers (image)))) { switch (palette_type) { case GIMP_MAKE_PALETTE: if (num_cols < 1 || num_cols > MAXNUMCOLORS) success = FALSE; break; case GIMP_CUSTOM_PALETTE: pal = gimp_pdb_get_palette (gimp, palette, FALSE, error); if (! pal) { success = FALSE; } else if (pal->n_colors > MAXNUMCOLORS) { g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Cannot convert to a palette " "with more than 256 colors.")); success = FALSE; } break; default: break; } } else { success = FALSE; } if (success) success = gimp_image_convert_type (image, GIMP_INDEXED, num_cols, dither_type, alpha_dither, FALSE, remove_unused, palette_type, pal, NULL, error); } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static void color_profile_dialog_response (GtkWidget *widget, gint response_id, ProfileDialog *dialog) { gboolean success = TRUE; GError *error = NULL; if (response_id == GTK_RESPONSE_OK) { GimpColorProfile *dest_profile = NULL; GFile *file; file = gimp_color_profile_combo_box_get_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (dialog->combo)); if (file) { dest_profile = gimp_color_profile_new_from_file (file, &error); if (! dest_profile) success = FALSE; g_object_unref (file); } else { dest_profile = g_object_ref (dialog->builtin_profile); } if (success) { switch (dialog->dialog_type) { case COLOR_PROFILE_DIALOG_ASSIGN_PROFILE: { gimp_image_undo_group_start (dialog->image, GIMP_UNDO_GROUP_PARASITE_ATTACH, _("Assign color profile")); success = gimp_image_set_color_profile (dialog->image, dest_profile, &error); if (success) { gimp_image_set_is_color_managed (dialog->image, TRUE, TRUE); /* omg... */ gimp_image_parasite_detach (dialog->image, "icc-profile-name"); } gimp_image_undo_group_end (dialog->image); if (! success) gimp_image_undo (dialog->image); } break; case COLOR_PROFILE_DIALOG_CONVERT_TO_PROFILE: { GimpProgress *progress; const gchar *label; label = gimp_color_profile_get_label (dest_profile); progress = gimp_progress_start (dialog->progress, FALSE, _("Converting to '%s'"), label); success = gimp_image_convert_color_profile (dialog->image, dest_profile, dialog->intent, dialog->bpc, progress, &error); if (progress) gimp_progress_end (progress); if (success) { saved_intent = dialog->intent; saved_bpc = dialog->bpc; } } break; case COLOR_PROFILE_DIALOG_CONVERT_TO_RGB: { GimpProgress *progress; const gchar *label; label = gimp_color_profile_get_label (dest_profile); progress = gimp_progress_start (dialog->progress, FALSE, _("Converting to RGB (%s)"), label); success = gimp_image_convert_type (dialog->image, GIMP_RGB, dest_profile, progress, &error); if (progress) gimp_progress_end (progress); } break; case COLOR_PROFILE_DIALOG_CONVERT_TO_GRAY: { GimpProgress *progress; const gchar *label; label = gimp_color_profile_get_label (dest_profile); progress = gimp_progress_start (dialog->progress, FALSE, _("Converting to grayscale (%s)"), label); success = gimp_image_convert_type (dialog->image, GIMP_GRAY, dest_profile, progress, &error); if (progress) gimp_progress_end (progress); } break; } if (success) gimp_image_flush (dialog->image); g_object_unref (dest_profile); } } if (success) { gtk_widget_destroy (dialog->dialog); } else { gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog), GIMP_MESSAGE_ERROR, "%s", error->message); g_clear_error (&error); } }