static void cdisplay_lcms_update_profile_label (CdisplayLcms *lcms, const gchar *name) { GimpColorConfig *config; GimpColorManaged *managed; GtkWidget *label; GimpColorProfile *profile = NULL; const gchar *text; const gchar *tooltip; config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms)); managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms)); label = g_object_get_data (G_OBJECT (lcms), name); if (! label) return; if (strcmp (name, "rgb-profile") == 0) { profile = gimp_color_managed_get_color_profile (managed); if (profile) g_object_ref (profile); } else if (g_str_has_prefix (name, "display-profile")) { profile = cdisplay_lcms_get_display_profile (lcms); } else if (strcmp (name, "printer-profile") == 0) { profile = gimp_color_config_get_simulation_color_profile (config, NULL); } else { g_return_if_reached (); } if (profile) { text = gimp_color_profile_get_label (profile); tooltip = gimp_color_profile_get_summary (profile); } else { text = _("None"); tooltip = NULL; } gtk_label_set_text (GTK_LABEL (label), text); gimp_help_set_help_data (label, tooltip, NULL); if (profile) g_object_unref (profile); }
GtkWidget * gimp_color_profile_label_new (GimpColorProfile *profile) { GtkWidget *expander; GtkWidget *view; g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL); expander = gtk_expander_new (gimp_color_profile_get_label (profile)); view = gimp_color_profile_view_new (); gimp_color_profile_view_set_profile (GIMP_COLOR_PROFILE_VIEW (view), profile); gtk_container_add (GTK_CONTAINER (expander), view); gtk_widget_show (view); return expander; }
/** * gimp_color_profile_combo_box_set_active: * @combo: a #GimpColorProfileComboBox * @filename: filename of the profile to select * @label: label to use when adding a new entry (can be %NULL) * * Selects a color profile from the @combo and makes it the active * item. If the profile is not listed in the @combo, then it is added * with the given @label (or @filename in case that @label is %NULL). * * Since: 2.4 **/ void gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo, const gchar *filename, const gchar *label) { GtkTreeModel *model; GtkTreeIter iter; g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo)); if (filename && ! (label && *label)) { GFile *file; GimpColorProfile *profile; GError *error = NULL; file = g_file_new_for_path (filename); profile = gimp_color_profile_new_from_file (file, &error); g_object_unref (file); if (! profile) { g_message ("%s", error->message); g_clear_error (&error); } else { label = gimp_color_profile_get_label (profile); g_object_unref (profile); } } if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model), filename, label, &iter)) { gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter); } }
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 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); } }
static GtkWidget * color_profile_combo_box_new (ProfileDialog *dialog) { GtkWidget *combo; GtkWidget *chooser; gchar *history; GimpColorProfile *profile; gboolean to_gray; gchar *label; GError *error = NULL; chooser = gimp_color_profile_chooser_dialog_new (_("Select Destination Profile"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN); history = gimp_personal_rc_file ("profilerc"); combo = gimp_color_profile_combo_box_new (chooser, history); g_free (history); switch (dialog->dialog_type) { case COLOR_PROFILE_DIALOG_ASSIGN_PROFILE: case COLOR_PROFILE_DIALOG_CONVERT_TO_PROFILE: to_gray = (gimp_image_get_base_type (dialog->image) == GIMP_GRAY); break; case COLOR_PROFILE_DIALOG_CONVERT_TO_RGB: to_gray = FALSE; break; case COLOR_PROFILE_DIALOG_CONVERT_TO_GRAY: to_gray = TRUE; break; default: g_return_val_if_reached (NULL); } profile = dialog->builtin_profile; if (to_gray) { label = g_strdup_printf (_("Built-in grayscale (%s)"), gimp_color_profile_get_label (profile)); profile = gimp_color_config_get_gray_color_profile (dialog->config, &error); } else { label = g_strdup_printf (_("Built-in RGB (%s)"), gimp_color_profile_get_label (profile)); profile = gimp_color_config_get_rgb_color_profile (dialog->config, &error); } gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo), NULL, label); g_free (label); if (profile) { GFile *file; if (to_gray) { file = g_file_new_for_path (dialog->config->gray_profile); label = g_strdup_printf (_("Preferred grayscale (%s)"), gimp_color_profile_get_label (profile)); } else { file = g_file_new_for_path (dialog->config->rgb_profile); label = g_strdup_printf (_("Preferred RGB (%s)"), gimp_color_profile_get_label (profile)); } g_object_unref (profile); gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo), file, label); g_object_unref (file); g_free (label); } else if (error) { gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog), GIMP_MESSAGE_ERROR, "%s", error->message); g_clear_error (&error); } gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo), NULL, NULL); return combo; }
static void colorsel_cmyk_config_changed (ColorselCmyk *module) { GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module); GimpColorConfig *config = module->config; cmsUInt32Number flags = 0; GimpColorProfile rgb_profile = NULL; GimpColorProfile cmyk_profile = NULL; gchar *label; gchar *summary; gchar *text; if (module->rgb2cmyk) { cmsDeleteTransform (module->rgb2cmyk); module->rgb2cmyk = NULL; } if (module->cmyk2rgb) { cmsDeleteTransform (module->cmyk2rgb); module->cmyk2rgb = NULL; } gtk_label_set_text (GTK_LABEL (module->name_label), _("Profile: (none)")); gimp_help_set_help_data (module->name_label, NULL, NULL); if (! config) goto out; rgb_profile = gimp_color_config_get_rgb_color_profile (config, NULL); cmyk_profile = gimp_color_config_get_cmyk_color_profile (config, NULL); if (! rgb_profile) rgb_profile = gimp_color_profile_new_srgb (); if (! cmyk_profile) goto out; label = gimp_color_profile_get_label (cmyk_profile); summary = gimp_color_profile_get_summary (cmyk_profile); text = g_strdup_printf (_("Profile: %s"), label); gtk_label_set_text (GTK_LABEL (module->name_label), text); gimp_help_set_help_data (module->name_label, summary, NULL); g_free (text); g_free (label); g_free (summary); if (config->display_intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC) { flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } module->rgb2cmyk = cmsCreateTransform (rgb_profile, TYPE_RGB_DBL, cmyk_profile, TYPE_CMYK_DBL, config->display_intent, flags); module->cmyk2rgb = cmsCreateTransform (cmyk_profile, TYPE_CMYK_DBL, rgb_profile, TYPE_RGB_DBL, config->display_intent, flags); out: if (rgb_profile) gimp_color_profile_close (rgb_profile); if (cmyk_profile) gimp_color_profile_close (cmyk_profile); if (! module->in_destruction) colorsel_cmyk_set_color (selector, &selector->rgb, &selector->hsv); }
gboolean gimp_image_convert_color_profile (GimpImage *image, GimpColorProfile *dest_profile, GimpColorRenderingIntent intent, gboolean bpc, GimpProgress *progress, GError **error) { GimpColorProfile *src_profile; GimpColorProfile *builtin_profile; const Babl *layer_format; 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, error)) return FALSE; src_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image)); if (gimp_color_profile_is_equal (src_profile, dest_profile)) { g_object_unref (src_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")); layer_format = gimp_image_get_layer_format (image, FALSE); if (gimp_babl_format_get_linear (layer_format)) builtin_profile = gimp_color_profile_new_linear_rgb (); else builtin_profile = gimp_color_profile_new_srgb (); if (gimp_color_profile_is_equal (dest_profile, builtin_profile)) { /* don't tag the image with the built-in profile */ gimp_image_set_color_profile (image, NULL, NULL); } else { gimp_image_set_color_profile (image, dest_profile, NULL); } g_object_unref (builtin_profile); /* 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); g_object_unref (src_profile); return TRUE; }
static GtkWidget * color_profile_combo_box_new (ProfileDialog *dialog) { GtkWidget *combo; GtkWidget *chooser; gchar *history; GimpColorProfile *profile; gchar *label; GError *error = NULL; chooser = gimp_color_profile_chooser_dialog_new (_("Select destination profile")); history = gimp_personal_rc_file ("profilerc"); combo = gimp_color_profile_combo_box_new (chooser, history); g_free (history); profile = gimp_image_get_builtin_color_profile (dialog->image); if (gimp_image_get_base_type (dialog->image) == GIMP_GRAY) { label = g_strdup_printf (_("Built-in grayscale (%s)"), gimp_color_profile_get_label (profile)); profile = gimp_color_config_get_gray_color_profile (dialog->config, &error); } else { label = g_strdup_printf (_("Built-in RGB (%s)"), gimp_color_profile_get_label (profile)); profile = gimp_color_config_get_rgb_color_profile (dialog->config, &error); } gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo), NULL, label); g_free (label); if (profile) { GFile *file = g_file_new_for_path (dialog->config->rgb_profile); if (gimp_image_get_base_type (dialog->image) == GIMP_GRAY) { label = g_strdup_printf (_("Preferred grayscale (%s)"), gimp_color_profile_get_label (profile)); } else { label = g_strdup_printf (_("Preferred RGB (%s)"), gimp_color_profile_get_label (profile)); } g_object_unref (profile); gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo), file, label); g_object_unref (file); g_free (label); } else if (error) { gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog), GIMP_MESSAGE_ERROR, "%s", error->message); g_clear_error (&error); } gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo), NULL, NULL); return combo; }