Commit d71cd602 authored by Michael Natterer's avatar Michael Natterer 😴

app: add color-profile-dialog.c as replacement for the lcms plug-in's GUI

Uncomment and implement the menu items and actions to invoke the
dialog. This new code also does the (alomst) right thing to linear
images, unlike the lcms plug-in.
parent cac04aed
......@@ -56,6 +56,7 @@
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "dialogs/color-profile-dialog.h"
#include "dialogs/convert-precision-dialog.h"
#include "dialogs/convert-type-dialog.h"
#include "dialogs/grid-dialog.h"
......@@ -74,6 +75,8 @@
#define IMAGE_CONVERT_PRECISION_DIALOG_KEY "image-convert-precision-dialog"
#define IMAGE_CONVERT_TYPE_DIALOG_KEY "image-convert-type-dialog"
#define IMAGE_PROFILE_CONVERT_DIALOG_KEY "image-profile-convert-dialog"
#define IMAGE_PROFILE_ASSIGN_DIALOG_KEY "image-profile-assign-dialog"
typedef struct
......@@ -292,24 +295,82 @@ image_convert_precision_cmd_callback (GtkAction *action,
gimp_image_flush (image);
}
static void
image_profile_assign_dialog_unset (GimpImage *image)
{
g_object_set_data (G_OBJECT (image), IMAGE_PROFILE_ASSIGN_DIALOG_KEY, NULL);
}
void
image_color_profile_assign_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GimpImage *image;
GimpDisplay *display;
GtkWidget *widget;
GtkWidget *dialog;
return_if_no_image (image, data);
return_if_no_display (display, data);
return_if_no_widget (widget, data);
g_message ("FIXME: implement image_color_profile_assign_cmd_callback()");
dialog = g_object_get_data (G_OBJECT (image),
IMAGE_PROFILE_ASSIGN_DIALOG_KEY);
if (! dialog)
{
dialog = color_profile_assign_dialog_new (image,
action_data_get_context (data),
widget,
GIMP_PROGRESS (display));
g_object_set_data (G_OBJECT (image),
IMAGE_PROFILE_ASSIGN_DIALOG_KEY, dialog);
g_signal_connect_object (dialog, "destroy",
G_CALLBACK (image_profile_assign_dialog_unset),
image, G_CONNECT_SWAPPED);
}
gtk_window_present (GTK_WINDOW (dialog));
}
static void
image_profile_convert_dialog_unset (GimpImage *image)
{
g_object_set_data (G_OBJECT (image), IMAGE_PROFILE_CONVERT_DIALOG_KEY, NULL);
}
void
image_color_profile_convert_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GimpImage *image;
GimpDisplay *display;
GtkWidget *widget;
GtkWidget *dialog;
return_if_no_image (image, data);
return_if_no_display (display, data);
return_if_no_widget (widget, data);
dialog = g_object_get_data (G_OBJECT (image),
IMAGE_PROFILE_CONVERT_DIALOG_KEY);
if (! dialog)
{
dialog = color_profile_convert_dialog_new (image,
action_data_get_context (data),
widget,
GIMP_PROGRESS (display));
g_object_set_data (G_OBJECT (image),
IMAGE_PROFILE_CONVERT_DIALOG_KEY, dialog);
g_message ("FIXME: implement image_color_profile_convert_cmd_callback()");
g_signal_connect_object (dialog, "destroy",
G_CALLBACK (image_profile_convert_dialog_unset),
image, G_CONNECT_SWAPPED);
}
gtk_window_present (GTK_WINDOW (dialog));
}
void
......
......@@ -26,6 +26,8 @@ libappdialogs_a_sources = \
action-search-dialog.h \
channel-options-dialog.c \
channel-options-dialog.h \
color-profile-dialog.c \
color-profile-dialog.h \
convert-precision-dialog.c \
convert-precision-dialog.h \
convert-type-dialog.c \
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* color-profile-dialog.h
* Copyright (C) 2015 Michael Natterer <mitch@gimp.org>
*
* Partly based on the lcms plug-in
* Copyright (C) 2006, 2007 Sven Neumann <sven@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "dialogs-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-color-profile.h"
#include "core/gimpprogress.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpviewabledialog.h"
#include "color-profile-dialog.h"
#include "gimp-intl.h"
typedef struct
{
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *combo;
GimpImage *image;
GimpProgress *progress;
GimpColorConfig *config;
gboolean convert;
GimpColorRenderingIntent intent;
gboolean bpc;
} ProfileDialog;
static ProfileDialog * color_profile_dialog_new (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpProgress *progress,
gboolean convert);
static GtkWidget * color_profile_combo_box_new (ProfileDialog *dialog);
static void color_profile_dialog_response (GtkWidget *widget,
gint response_id,
ProfileDialog *dialog);
static void color_profile_dialog_free (ProfileDialog *dialog);
/* defaults */
static GimpColorRenderingIntent saved_intent = -1;
static gboolean saved_bpc = FALSE;
/* public functions */
GtkWidget *
color_profile_assign_dialog_new (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpProgress *progress)
{
ProfileDialog *dialog;
dialog = color_profile_dialog_new (image, context, parent, progress, FALSE);
return dialog ? dialog->dialog : NULL;
}
GtkWidget *
color_profile_convert_dialog_new (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpProgress *progress)
{
ProfileDialog *dialog;
dialog = color_profile_dialog_new (image, context, parent, progress, TRUE);
return dialog ? dialog->dialog : NULL;
}
/* private functions */
static ProfileDialog *
color_profile_dialog_new (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpProgress *progress,
gboolean convert)
{
ProfileDialog *dialog;
GtkWidget *frame;
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->image = image;
dialog->progress = progress;
dialog->config = image->gimp->config->color_management;
dialog->convert = convert;
if (saved_intent == -1)
{
dialog->intent = dialog->config->display_intent;
dialog->bpc = (dialog->intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC);
}
else
{
dialog->intent = saved_intent;
dialog->bpc = saved_bpc;
}
if (convert)
{
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);
}
else
{
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);
}
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 = gtk_label_new (gimp_color_profile_get_label (src_profile));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_widget_show (label);
g_object_unref (src_profile);
frame = gimp_frame_new (convert ? _("Convert to") : _("Assign"));
gtk_box_pack_start (GTK_BOX (dialog->main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
dialog->combo = color_profile_combo_box_new (dialog);
gtk_container_add (GTK_CONTAINER (frame), dialog->combo);
gtk_widget_show (dialog->combo);
if (convert)
{
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;
}
static GtkWidget *
color_profile_combo_box_new (ProfileDialog *dialog)
{
GtkWidget *combo;
GtkWidget *chooser;
gchar *history;
gchar *label;
GFile *rgb_file = NULL;
GimpColorProfile *profile = NULL;
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_color_config_get_rgb_color_profile (dialog->config, &error);
if (profile)
{
rgb_file = g_file_new_for_path (dialog->config->rgb_profile);
}
else if (error)
{
gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog),
GIMP_MESSAGE_ERROR,
"%s", error->message);
g_clear_error (&error);
}
if (! profile)
profile = gimp_image_get_builtin_color_profile (dialog->image);
label = g_strdup_printf (_("RGB workspace (%s)"),
gimp_color_profile_get_label (profile));
g_object_unref (profile);
gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
rgb_file, label);
if (rgb_file)
g_object_unref (rgb_file);
g_free (label);
gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
NULL, NULL);
return combo;
}
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 = gimp_color_config_get_rgb_color_profile (dialog->config,
&error);
if (! dest_profile)
{
if (error)
{
success = FALSE;
}
else
{
dest_profile = gimp_image_get_builtin_color_profile (dialog->image);
}
}
}
if (success)
{
if (dialog->convert)
{
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;
}
}
else
{
success = gimp_image_set_color_profile (dialog->image,
dest_profile,
&error);
}
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 void
color_profile_dialog_free (ProfileDialog *dialog)
{
g_slice_free (ProfileDialog, dialog);
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* color-profile-dialog.h
* Copyright (C) 2015 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __COLOR_PROFILE_DIALOG_H__
#define __COLOR_PROFILE_DIALOG_H__
GtkWidget * color_profile_assign_dialog_new (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpProgress *progress);
GtkWidget * color_profile_convert_dialog_new (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpProgress *progress);
#endif /* __COLOR_PROFILE_DIALOG_H__ */
......@@ -348,11 +348,9 @@
<separator />
</menu>
<menu action="image-color-management-menu" name="Color Management">
<!-- disabled until the actions are implemented
<menuitem action="image-color-profile-assign" />
<menuitem action="image-color-profile-convert" />
-->
<menuitem action="image-color-profile-discard" />
<menuitem action="image-color-profile-assign" />
<menuitem action="image-color-profile-convert" />
<menuitem action="image-color-profile-discard" />
</menu>
<separator />
<menu action="image-transform-menu" name="Transform">
......
......@@ -179,6 +179,7 @@ app/core/gimpunit.c
app/dialogs/about-dialog.c
app/dialogs/action-search-dialog.c
app/dialogs/channel-options-dialog.c
app/dialogs/color-profile-dialog.c
app/dialogs/convert-precision-dialog.c
app/dialogs/convert-type-dialog.c
app/dialogs/data-delete-dialog.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment