app: implement the "Convert to RGB Working Space" import dialog in the core

Add gimp_image_import_color_profile(), a GUI vtable entry
query_profile_policy() and a new dialog which returns the profile
policy and the profile to convert to. Get rid of the wrapper that
calls the lcms plug-in for that dialog, the plug-in is now completely
unused.

This commit doesn't add any new features, it's just the former lcms
plug-in dialog implemented in app/ (except the little fix that it is
now aware of linear vs. gamma images).
This commit is contained in:
Michael Natterer 2015-08-23 10:51:31 +02:00
parent dc51a89427
commit b51ee77ec0
13 changed files with 314 additions and 238 deletions

View File

@ -65,6 +65,7 @@ gimp_gui_init (Gimp *gimp)
gimp->gui.recent_list_add_file = NULL;
gimp->gui.recent_list_load = NULL;
gimp->gui.get_mount_operation = NULL;
gimp->gui.query_profile_policy = NULL;
}
void
@ -506,3 +507,22 @@ gimp_get_mount_operation (Gimp *gimp,
return g_mount_operation_new ();
}
GimpColorProfilePolicy
gimp_query_profile_policy (Gimp *gimp,
GimpImage *image,
GimpContext *context,
GimpColorProfile **dest_profile,
gboolean *dont_ask)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_COLOR_PROFILE_POLICY_KEEP);
g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_COLOR_PROFILE_POLICY_KEEP);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), GIMP_COLOR_PROFILE_POLICY_KEEP);
g_return_val_if_fail (dest_profile != NULL, GIMP_COLOR_PROFILE_POLICY_KEEP);
if (gimp->gui.query_profile_policy)
return gimp->gui.query_profile_policy (gimp, image, context,
dest_profile, dont_ask);
return GIMP_COLOR_PROFILE_POLICY_KEEP;
}

View File

@ -93,8 +93,16 @@ struct _GimpGui
const gchar *mime_type);
void (* recent_list_load) (Gimp *gimp);
GMountOperation * (* get_mount_operation) (Gimp *gimp,
GMountOperation
* (* get_mount_operation) (Gimp *gimp,
GimpProgress *progress);
GimpColorProfilePolicy
(* query_profile_policy) (Gimp *gimp,
GimpImage *image,
GimpContext *context,
GimpColorProfile **dest_profile,
gboolean *dont_ask);
};
@ -173,8 +181,16 @@ gboolean gimp_recent_list_add_file (Gimp *gimp,
const gchar *mime_type);
void gimp_recent_list_load (Gimp *gimp);
GMountOperation * gimp_get_mount_operation (Gimp *gimp,
GMountOperation
* gimp_get_mount_operation (Gimp *gimp,
GimpProgress *progress);
GimpColorProfilePolicy
gimp_query_profile_policy (Gimp *gimp,
GimpImage *image,
GimpContext *context,
GimpColorProfile **dest_profile,
gboolean *dont_ask);
#endif /* __GIMP_GUI_H__ */

View File

@ -38,6 +38,7 @@
#include "gegl/gimp-babl.h"
#include "gimp.h"
#include "gimpcontext.h"
#include "gimpdrawable.h"
#include "gimperror.h"
#include "gimpimage.h"
@ -406,6 +407,83 @@ gimp_image_convert_color_profile (GimpImage *image,
return TRUE;
}
void
gimp_image_import_color_profile (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
gboolean interactive)
{
GimpColorConfig *config = image->gimp->config->color_management;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
config = image->gimp->config->color_management;
if (gimp_image_get_base_type (image) == GIMP_GRAY)
return;
if (config->mode == GIMP_COLOR_MANAGEMENT_OFF)
return;
if (gimp_image_get_color_profile (image))
{
GimpColorProfilePolicy policy;
GimpColorProfile *dest_profile = NULL;
policy = image->gimp->config->color_profile_policy;
if (policy == GIMP_COLOR_PROFILE_POLICY_ASK)
{
if (interactive)
{
gboolean dont_ask = FALSE;
policy = gimp_query_profile_policy (image->gimp, image, context,
&dest_profile, &dont_ask);
if (dont_ask)
{
g_object_set (G_OBJECT (image->gimp->config),
"color-profile-policy", policy,
NULL);
}
}
else
{
policy = GIMP_COLOR_PROFILE_POLICY_KEEP;
}
}
if (policy == GIMP_COLOR_PROFILE_POLICY_CONVERT)
{
GimpColorRenderingIntent intent;
gboolean bpc;
if (! dest_profile)
{
dest_profile = gimp_image_get_builtin_color_profile (image);
g_object_ref (dest_profile);
}
intent = config->display_intent;
bpc = (intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC);
gimp_image_undo_disable (image);
gimp_image_convert_color_profile (image, dest_profile,
intent, bpc,
progress, NULL);
gimp_image_clean_all (image);
gimp_image_undo_enable (image);
g_object_unref (dest_profile);
}
}
}
/* private functions */

View File

@ -64,5 +64,10 @@ gboolean gimp_image_convert_color_profile (GimpImage
GimpProgress *progress,
GError **error);
void gimp_image_import_color_profile (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
gboolean interactive);
#endif /* __GIMP_IMAGE_COLOR_PROFILE_H__ */

View File

@ -28,6 +28,8 @@ libappdialogs_a_sources = \
channel-options-dialog.h \
color-profile-dialog.c \
color-profile-dialog.h \
color-profile-import-dialog.c \
color-profile-import-dialog.h \
convert-precision-dialog.c \
convert-precision-dialog.h \
convert-type-dialog.c \

View File

@ -0,0 +1,151 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* color-profile-import-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 "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "dialogs-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-color-profile.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpviewabledialog.h"
#include "widgets/gimpwidgets-constructors.h"
#include "color-profile-import-dialog.h"
#include "gimp-intl.h"
/* public functions */
GimpColorProfilePolicy
color_profile_import_dialog_run (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpColorProfile **dest_profile,
gboolean *dont_ask)
{
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *frame;
GtkWidget *label;
GtkWidget *toggle;
GimpColorProfile *src_profile;
GimpColorProfilePolicy policy;
gchar *text;
g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_COLOR_PROFILE_POLICY_KEEP);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), GIMP_COLOR_PROFILE_POLICY_KEEP);
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent),
GIMP_COLOR_PROFILE_POLICY_KEEP);
g_return_val_if_fail (dest_profile != NULL, GIMP_COLOR_PROFILE_POLICY_KEEP);
src_profile = gimp_image_get_color_profile (image);
*dest_profile = gimp_image_get_builtin_color_profile (image);
dialog =
gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context,
_("Convert to RGB Working Space?"),
"gimp-image-color-profile-import",
NULL,
_("Import the image from a color profile"),
parent,
gimp_standard_help_func,
GIMP_HELP_IMAGE_COLOR_PROFILE_IMPORT,
_("Keep"), GTK_RESPONSE_CANCEL,
_("Convert"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
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);
text = g_strdup_printf (_("The image '%s' has an embedded color profile"),
gimp_image_get_display_name (image));
frame = gimp_frame_new (text);
g_free (text);
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
label = gimp_color_profile_label_new (src_profile);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_widget_show (label);
frame = gimp_frame_new (_("Convert the image to the RGB working space?"));
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
label = gimp_color_profile_label_new (*dest_profile);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_widget_show (label);
if (dont_ask)
{
toggle = gtk_check_button_new_with_mnemonic (_("_Don't ask me again"));
gtk_box_pack_end (GTK_BOX (main_vbox), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), FALSE);
gtk_widget_show (toggle);
}
switch (gtk_dialog_run (GTK_DIALOG (dialog)))
{
case GTK_RESPONSE_OK:
policy = GIMP_COLOR_PROFILE_POLICY_CONVERT;
g_object_ref (*dest_profile);
break;
default:
policy = GIMP_COLOR_PROFILE_POLICY_KEEP;
break;
}
if (dont_ask)
{
*dont_ask = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle));
}
gtk_widget_destroy (dialog);
return policy;
}

View File

@ -1,8 +1,8 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* plug-in-icc-profile.h
* Copyright (C) 2006 Sven Neumann <sven@gimp.org>
* color-profile-import-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
@ -18,15 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PLUG_IN_ICC_PROFILE_H__
#define __PLUG_IN_ICC_PROFILE_H__
#ifndef __COLOR_PROFILE_IMPORT_DIALOG_H__
#define __COLOR_PROFILE_IMPORT_DIALOG_H__
gboolean plug_in_icc_profile_apply_rgb (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
GimpRunMode run_mode,
GError **error);
GimpColorProfilePolicy
color_profile_import_dialog_run (GimpImage *image,
GimpContext *context,
GtkWidget *parent,
GimpColorProfile **dest_profile,
gboolean *dont_ask);
#endif /* __PLUG_IN_ICC_PROFILE_H__ */
#endif /* __COLOR_PROFILE_IMPORT_DIALOG_H__ */

View File

@ -48,8 +48,6 @@
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginprocedure.h"
#include "plug-in/gimppluginerror.h"
#include "plug-in/plug-in-icc-profile.h"
#include "file-open.h"
#include "file-procedure.h"
@ -65,10 +63,6 @@ static void file_open_sanitize_image (GimpImage *image
static void file_open_convert_items (GimpImage *dest_image,
const gchar *basename,
GList *items);
static void file_open_handle_color_profile (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
GimpRunMode run_mode);
static GList * file_open_get_layers (const GimpImage *image,
gboolean merge_visible,
gint *n_visible);
@ -255,7 +249,9 @@ file_open_image (Gimp *gimp,
if (image)
{
file_open_handle_color_profile (image, context, progress, run_mode);
gimp_image_import_color_profile (image, context, progress,
run_mode == GIMP_RUN_INTERACTIVE ?
TRUE : FALSE);
if (file_open_file_proc_is_import (file_proc))
{
@ -775,81 +771,6 @@ file_open_convert_items (GimpImage *dest_image,
}
}
static void
file_open_profile_apply_rgb (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
GimpRunMode run_mode)
{
GimpColorConfig *config = image->gimp->config->color_management;
GError *error = NULL;
if (gimp_image_get_base_type (image) == GIMP_GRAY)
return;
if (config->mode == GIMP_COLOR_MANAGEMENT_OFF)
return;
if (! plug_in_icc_profile_apply_rgb (image, context, progress, run_mode,
&error))
{
if (error->domain == GIMP_PLUG_IN_ERROR &&
error->code == GIMP_PLUG_IN_NOT_FOUND)
{
gchar *msg = g_strdup_printf ("%s\n\n%s",
error->message,
_("Color management has been disabled. "
"It can be enabled again in the "
"Preferences dialog."));
g_object_set (config, "mode", GIMP_COLOR_MANAGEMENT_OFF, NULL);
gimp_message_literal (image->gimp, G_OBJECT (progress),
GIMP_MESSAGE_WARNING, msg);
g_free (msg);
}
else
{
gimp_message_literal (image->gimp, G_OBJECT (progress),
GIMP_MESSAGE_ERROR, error->message);
}
g_error_free (error);
}
}
static void
file_open_handle_color_profile (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
GimpRunMode run_mode)
{
if (gimp_image_get_color_profile (image))
{
gimp_image_undo_disable (image);
switch (image->gimp->config->color_profile_policy)
{
case GIMP_COLOR_PROFILE_POLICY_ASK:
if (run_mode == GIMP_RUN_INTERACTIVE)
file_open_profile_apply_rgb (image, context, progress,
GIMP_RUN_INTERACTIVE);
break;
case GIMP_COLOR_PROFILE_POLICY_KEEP:
break;
case GIMP_COLOR_PROFILE_POLICY_CONVERT:
file_open_profile_apply_rgb (image, context, progress,
GIMP_RUN_NONINTERACTIVE);
break;
}
gimp_image_clean_all (image);
gimp_image_undo_enable (image);
}
}
static GList *
file_open_get_layers (const GimpImage *image,
gboolean merge_visible,

View File

@ -76,6 +76,8 @@
#include "menus/menus.h"
#include "dialogs/color-profile-import-dialog.h"
#include "gui.h"
#include "gui-message.h"
#include "gui-vtable.h"
@ -144,9 +146,17 @@ static gboolean gui_recent_list_add_file (Gimp *gimp,
const gchar *mime_type);
static void gui_recent_list_load (Gimp *gimp);
static GMountOperation * gui_get_mount_operation (Gimp *gimp,
static GMountOperation
* gui_get_mount_operation (Gimp *gimp,
GimpProgress *progress);
static GimpColorProfilePolicy
gui_query_profile_policy (Gimp *gimp,
GimpImage *image,
GimpContext *context,
GimpColorProfile **dest_profile,
gboolean *dont_ask);
/* public functions */
@ -182,6 +192,7 @@ gui_vtable_init (Gimp *gimp)
gimp->gui.recent_list_add_file = gui_recent_list_add_file;
gimp->gui.recent_list_load = gui_recent_list_load;
gimp->gui.get_mount_operation = gui_get_mount_operation;
gimp->gui.query_profile_policy = gui_query_profile_policy;
}
@ -750,3 +761,14 @@ gui_get_mount_operation (Gimp *gimp,
return gtk_mount_operation_new (GTK_WINDOW (toplevel));
}
static GimpColorProfilePolicy
gui_query_profile_policy (Gimp *gimp,
GimpImage *image,
GimpContext *context,
GimpColorProfile **dest_profile,
gboolean *dont_ask)
{
return color_profile_import_dialog_run (image, context, NULL,
dest_profile, dont_ask);
}

View File

@ -72,10 +72,7 @@ libappplug_in_a_SOURCES = \
plug-in-params.c \
plug-in-params.h \
plug-in-rc.c \
plug-in-rc.h \
\
plug-in-icc-profile.c \
plug-in-icc-profile.h
plug-in-rc.h
#
# rules to generate built sources

View File

@ -1,138 +0,0 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* plug-in-icc-profile.c
* Copyright (C) 2006 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 <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "core/core-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpparamspecs.h"
#include "core/gimpprogress.h"
#include "pdb/gimppdb.h"
#include "pdb/gimpprocedure.h"
#include "gimppluginerror.h"
#include "plug-in-icc-profile.h"
#include "gimp-intl.h"
#define ICC_PROFILE_APPLY_RGB_PROC "plug-in-icc-profile-apply-rgb"
gboolean
plug_in_icc_profile_apply_rgb (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
GimpRunMode run_mode,
GError **error)
{
Gimp *gimp;
GimpProcedure *procedure;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
gimp = image->gimp;
if (gimp_image_get_base_type (image) == GIMP_GRAY)
{
g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_EXECUTION_FAILED,
_("Can't apply color profile to grayscale image (%s)"),
ICC_PROFILE_APPLY_RGB_PROC);
return FALSE;
}
procedure = gimp_pdb_lookup_procedure (gimp->pdb, ICC_PROFILE_APPLY_RGB_PROC);
if (procedure &&
procedure->num_args >= 2 &&
GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]))
{
GimpValueArray *return_vals;
GimpPDBStatusType status;
GimpColorProfilePolicy policy = GIMP_COLOR_PROFILE_POLICY_ASK;
gboolean success;
return_vals =
gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress, error,
ICC_PROFILE_APPLY_RGB_PROC,
GIMP_TYPE_INT32, run_mode,
GIMP_TYPE_IMAGE_ID,
gimp_image_get_ID (image),
G_TYPE_NONE);
status = g_value_get_enum (gimp_value_array_index (return_vals, 0));
switch (status)
{
case GIMP_PDB_SUCCESS:
policy = GIMP_COLOR_PROFILE_POLICY_CONVERT;
success = TRUE;
break;
case GIMP_PDB_CANCEL:
policy = GIMP_COLOR_PROFILE_POLICY_KEEP;
success = TRUE;
break;
default:
if (error && *error == NULL)
g_set_error (error,
GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_EXECUTION_FAILED,
_("Error running '%s'"), ICC_PROFILE_APPLY_RGB_PROC);
success = FALSE;
break;
}
if (success && gimp_value_array_length (return_vals) > 1)
{
GValue *value = gimp_value_array_index (return_vals, 1);
if (GIMP_VALUE_HOLDS_INT32 (value) && g_value_get_int (value))
{
g_object_set (G_OBJECT (gimp->config),
"color-profile-policy", policy,
NULL);
}
}
gimp_value_array_unref (return_vals);
return success;
}
g_set_error (error,
GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_NOT_FOUND,
_("Plug-In missing (%s)"), ICC_PROFILE_APPLY_RGB_PROC);
return FALSE;
}

View File

@ -150,6 +150,7 @@
#define GIMP_HELP_IMAGE_COLOR_PROFILE_ASSIGN "gimp-image-color-profile-assign"
#define GIMP_HELP_IMAGE_COLOR_PROFILE_CONVERT "gimp-image-color-profile-convert"
#define GIMP_HELP_IMAGE_COLOR_PROFILE_DISCARD "gimp-image-color-profile-discard"
#define GIMP_HELP_IMAGE_COLOR_PROFILE_IMPORT "gimp-image-color-profile-import"
#define GIMP_HELP_IMAGE_GRID "gimp-image-grid"
#define GIMP_HELP_IMAGE_PROPERTIES "gimp-image-properties"

View File

@ -180,6 +180,7 @@ 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/color-profile-import-dialog.c
app/dialogs/convert-precision-dialog.c
app/dialogs/convert-type-dialog.c
app/dialogs/data-delete-dialog.c
@ -326,7 +327,6 @@ app/plug-in/gimppluginprocedure.c
app/plug-in/gimppluginprocframe.c
app/plug-in/gimptemporaryprocedure.c
app/plug-in/plug-in-enums.c
app/plug-in/plug-in-icc-profile.c
app/plug-in/plug-in-rc.c
app/text/gimpfont.c