static GtkWidget * lcms_icc_combo_box_new (GimpColorConfig *config, const gchar *filename) { GtkWidget *combo; GtkWidget *dialog; gchar *history; gchar *label; gchar *name; const gchar *rgb_filename = NULL; cmsHPROFILE profile = NULL; dialog = gimp_color_profile_chooser_dialog_new (_("Select destination profile")); history = gimp_personal_rc_file ("profilerc"); combo = gimp_color_profile_combo_box_new (dialog, history); g_free (history); if (config->rgb_profile) { GError *error = NULL; profile = gimp_lcms_profile_open_from_file (config->rgb_profile, &error); if (! profile) { g_message ("%s", error->message); g_clear_error (&error); } else if (! gimp_lcms_profile_is_rgb (profile)) { g_message (_("Color profile '%s' is not for RGB color space."), gimp_filename_to_utf8 (config->rgb_profile)); cmsCloseProfile (profile); profile = NULL; } else { rgb_filename = config->rgb_profile; } } if (! profile) profile = gimp_lcms_create_srgb_profile (); name = gimp_lcms_profile_get_label (profile); label = g_strdup_printf (_("RGB workspace (%s)"), name); g_free (name); cmsCloseProfile (profile); gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo), rgb_filename, label); g_free (label); gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), filename, NULL); return combo; }
static GtkWidget * lcms_icc_profile_src_label_new (gint32 image, cmsHPROFILE profile) { GtkWidget *vbox; GtkWidget *label; gchar *name; gchar *text; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); name = gimp_image_get_name (image); text = g_strdup_printf (_("The image '%s' has an embedded color profile:"), name); g_free (name); label = g_object_new (GTK_TYPE_LABEL, "label", text, "wrap", TRUE, "justify", GTK_JUSTIFY_LEFT, "xalign", 0.0, "yalign", 0.0, NULL); g_free (text); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); name = gimp_lcms_profile_get_label (profile); label = g_object_new (GTK_TYPE_LABEL, "label", name, "wrap", TRUE, "justify", GTK_JUSTIFY_LEFT, "xalign", 0.0, "yalign", 0.0, "xpad", 24, NULL); g_free (name); gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); return vbox; }
/** * 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: GIMP 2.4 **/ void gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo, const gchar *filename, const gchar *label) { GtkTreeModel *model; GtkTreeIter iter; gchar *l = NULL; 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)) { cmsHPROFILE profile; GError *error = NULL; profile = gimp_lcms_profile_open_from_file (filename, &error); if (! profile) { g_message ("%s", error->message); g_clear_error (&error); } else { l = gimp_lcms_profile_get_label (profile); cmsCloseProfile (profile); } } else { l = g_strdup (label); } if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model), filename, l, &iter)) { gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter); } g_free (l); }
void gimp_color_profile_view_set_profile (GimpColorProfileView *view, GimpColorProfile profile) { GtkTextBuffer *buffer; GtkTextIter iter; gchar *label; gchar *summary; g_return_if_fail (GIMP_IS_COLOR_PROFILE_VIEW (view)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); gtk_text_buffer_set_text (buffer, "", 0); view->priv->profile = profile; if (! profile) return; gtk_text_buffer_get_start_iter (buffer, &iter); label = gimp_lcms_profile_get_label (profile); summary = gimp_lcms_profile_get_summary (profile); if (label && strlen (label)) { gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, label, -1, "strong", NULL); gtk_text_buffer_insert (buffer, &iter, "\n", 1); } if (summary) gtk_text_buffer_insert (buffer, &iter, summary, -1); g_free (label); g_free (summary); }
static GtkWidget * lcms_icc_profile_dest_label_new (cmsHPROFILE profile) { GtkWidget *label; gchar *name; gchar *text; name = gimp_lcms_profile_get_label (profile); text = g_strdup_printf (_("Convert the image to the RGB working space (%s)?"), name); g_free (name); label = g_object_new (GTK_TYPE_LABEL, "label", text, "wrap", TRUE, "justify", GTK_JUSTIFY_LEFT, "xalign", 0.0, "yalign", 0.0, NULL); g_free (text); return label; }
static gboolean lcms_image_apply_profile (gint32 image, cmsHPROFILE src_profile, cmsHPROFILE dest_profile, GFile *file, GimpColorRenderingIntent intent, gboolean bpc) { gchar *src_label; gchar *dest_label; gint32 saved_selection = -1; gimp_image_undo_group_start (image); if (! lcms_image_set_profile (image, dest_profile, file)) { gimp_image_undo_group_end (image); return FALSE; } src_label = gimp_lcms_profile_get_label (src_profile); dest_label = gimp_lcms_profile_get_label (dest_profile); gimp_progress_init_printf (_("Converting from '%s' to '%s'"), src_label, dest_label); g_printerr ("lcms: converting from '%s' to '%s'\n", src_label, dest_label); g_free (dest_label); g_free (src_label); if (! gimp_selection_is_empty (image)) { saved_selection = gimp_selection_save (image); gimp_selection_none (image); } switch (gimp_image_base_type (image)) { case GIMP_RGB: lcms_image_transform_rgb (image, src_profile, dest_profile, intent, bpc); break; case GIMP_GRAY: g_warning ("colorspace conversion not implemented for " "grayscale images"); break; case GIMP_INDEXED: lcms_image_transform_indexed (image, src_profile, dest_profile, intent, bpc); break; } if (saved_selection != -1) { gimp_image_select_item (image, GIMP_CHANNEL_OP_REPLACE, saved_selection); gimp_image_remove_channel (image, saved_selection); } gimp_progress_update (1.0); gimp_image_undo_group_end (image); return TRUE; }
static GimpPDBStatusType lcms_icc_apply (GimpColorConfig *config, GimpRunMode run_mode, gint32 image, GFile *file, GimpColorRenderingIntent intent, gboolean bpc, gboolean *dont_ask) { GimpPDBStatusType status = GIMP_PDB_SUCCESS; cmsHPROFILE src_profile = NULL; cmsHPROFILE dest_profile = NULL; GError *error = NULL; g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (image != -1, GIMP_PDB_CALLING_ERROR); if (file) g_object_ref (file); else if (config->rgb_profile) file = g_file_new_for_path (config->rgb_profile); if (file) { GError *error = NULL; dest_profile = gimp_lcms_profile_open_from_file (file, &error); if (! dest_profile) { g_message ("%s", error->message); g_clear_error (&error); return GIMP_PDB_EXECUTION_ERROR; } if (! gimp_lcms_profile_is_rgb (dest_profile)) { g_message (_("Color profile '%s' is not for RGB color space."), gimp_file_get_utf8_name (file)); cmsCloseProfile (dest_profile); g_object_unref (file); return GIMP_PDB_EXECUTION_ERROR; } } src_profile = lcms_image_get_profile (config, image, &error); if (error) { g_message ("%s", error->message); g_clear_error (&error); } if (! src_profile && ! dest_profile) return GIMP_PDB_SUCCESS; if (! src_profile) src_profile = gimp_lcms_create_srgb_profile (); if (! dest_profile) dest_profile = gimp_lcms_create_srgb_profile (); if (gimp_lcms_profile_is_equal (src_profile, dest_profile)) { gchar *src_label = gimp_lcms_profile_get_label (src_profile); gchar *dest_label = gimp_lcms_profile_get_label (dest_profile); cmsCloseProfile (src_profile); cmsCloseProfile (dest_profile); g_printerr ("lcms: skipping conversion because profiles seem to be equal:\n"); g_printerr (" %s\n", src_label); g_printerr (" %s\n", dest_label); g_free (src_label); g_free (dest_label); if (file) g_object_unref (file); return GIMP_PDB_SUCCESS; } if (run_mode == GIMP_RUN_INTERACTIVE && ! lcms_icc_apply_dialog (image, src_profile, dest_profile, dont_ask)) { status = GIMP_PDB_CANCEL; } if (status == GIMP_PDB_SUCCESS && ! lcms_image_apply_profile (image, src_profile, dest_profile, file, intent, bpc)) { status = GIMP_PDB_EXECUTION_ERROR; } cmsCloseProfile (src_profile); cmsCloseProfile (dest_profile); if (file) g_object_unref (file); return status; }
static GimpPDBStatusType lcms_dialog (GimpColorConfig *config, gint32 image, gboolean apply, LcmsValues *values) { GimpColorProfileComboBox *box; GtkWidget *dialog; GtkWidget *main_vbox; GtkWidget *frame; GtkWidget *label; GtkWidget *combo; cmsHPROFILE src_profile; gchar *name; gboolean success = FALSE; gboolean run; GError *error = NULL; src_profile = lcms_image_get_profile (config, image, &error); if (error) { g_message ("%s", error->message); g_clear_error (&error); } if (! src_profile) src_profile = gimp_lcms_create_srgb_profile (); gimp_ui_init (PLUG_IN_BINARY, FALSE); dialog = gimp_dialog_new (apply ? _("Convert to ICC Color Profile") : _("Assign ICC Color Profile"), PLUG_IN_ROLE, NULL, 0, gimp_standard_help_func, apply ? PLUG_IN_PROC_APPLY : PLUG_IN_PROC_SET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, apply ? GTK_STOCK_CONVERT : _("_Assign"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gimp_window_set_transient (GTK_WINDOW (dialog)); main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), main_vbox, TRUE, TRUE, 0); gtk_widget_show (main_vbox); frame = gimp_frame_new (_("Current Color Profile")); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); name = gimp_lcms_profile_get_label (src_profile); label = gtk_label_new (name); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_container_add (GTK_CONTAINER (frame), label); gtk_widget_show (label); g_free (name); frame = gimp_frame_new (apply ? _("Convert to") : _("Assign")); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); combo = lcms_icc_combo_box_new (config, NULL); gtk_container_add (GTK_CONTAINER (frame), combo); gtk_widget_show (combo); box = GIMP_COLOR_PROFILE_COMBO_BOX (combo); if (apply) { GtkWidget *vbox; GtkWidget *hbox; GtkWidget *toggle; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (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), values->intent, G_CALLBACK (gimp_int_combo_box_get_active), &values->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), values->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), &values->bpc); } while ((run = gimp_dialog_run (GIMP_DIALOG (dialog))) == GTK_RESPONSE_OK) { gchar *filename = gimp_color_profile_combo_box_get_active (box); GFile *file = NULL; cmsHPROFILE dest_profile; gtk_widget_set_sensitive (dialog, FALSE); if (filename) file = g_file_new_for_path (filename); if (file) { GError *error = NULL; dest_profile = gimp_lcms_profile_open_from_file (file, &error); if (! dest_profile) { g_message ("%s", error->message); g_clear_error (&error); } } else { dest_profile = gimp_lcms_create_srgb_profile (); } if (dest_profile) { if (gimp_lcms_profile_is_rgb (dest_profile)) { if (apply) success = lcms_image_apply_profile (image, src_profile, dest_profile, file, values->intent, values->bpc); else success = lcms_image_set_profile (image, dest_profile, file); } else { gimp_message (_("Destination profile is not for RGB color space.")); } cmsCloseProfile (dest_profile); } if (file) g_object_unref (file); if (success) break; else gtk_widget_set_sensitive (dialog, TRUE); } gtk_widget_destroy (dialog); cmsCloseProfile (src_profile); return (run ? (success ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR) : GIMP_PDB_CANCEL); }