Commit 5157dba5 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

Another step towards color management:

2005-02-21  Sven Neumann  <sven@gimp.org>

	Another step towards color management:

	* modules/Makefile.am
	* modules/cdisplay_lcms.c: added new color display module that
	implements color management for the image displays. Still work
	in progress...

	* modules/cdisplay_proof.c: no need to include <string.h> here.

	* libgimpconfig/gimpcolorconfig.[ch]: added new property
	"display-module" to configure the display color management module.

	* app/display/gimpdisplayshell-filter.[ch]
	* app/display/gimpdisplayshell.c: create the configured color
	management display filter for each display.
parent 0c777837
2005-02-21 Sven Neumann <sven@gimp.org>
Another step towards color management:
* modules/Makefile.am
* modules/cdisplay_lcms.c: added new color display module that
implements color management for the image displays. Still work
in progress...
* modules/cdisplay_proof.c: no need to include <string.h> here.
* libgimpconfig/gimpcolorconfig.[ch]: added new property
"display-module" to configure the display color management module.
* app/display/gimpdisplayshell-filter.[ch]
* app/display/gimpdisplayshell.c: create the configured color
management display filter for each display.
2005-02-20 Sven Neumann <sven@gimp.org>
* plug-ins/gimpressionist/presets.c (get_object_name): use
......
......@@ -20,10 +20,13 @@
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "config/gimpcoreconfig.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-filter.h"
......@@ -69,6 +72,37 @@ gimp_display_shell_filter_set (GimpDisplayShell *shell,
gimp_display_shell_filter_changed (NULL, shell);
}
GimpColorDisplayStack *
gimp_display_shell_filter_new (GimpColorConfig *config)
{
g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
if (config->display_module)
{
GType type = g_type_from_name (config->display_module);
if (g_type_is_a (type, GIMP_TYPE_COLOR_DISPLAY))
{
GimpColorDisplay *display = gimp_color_display_new (type);
if (display)
{
GimpColorDisplayStack *stack = gimp_color_display_stack_new ();
g_object_set (display, "config", config, NULL);
gimp_color_display_stack_add (stack, display);
g_object_unref (display);
return stack;
}
}
}
return NULL;
}
/* private functions */
......
......@@ -23,5 +23,7 @@
void gimp_display_shell_filter_set (GimpDisplayShell *shell,
GimpColorDisplayStack *stack);
GimpColorDisplayStack * gimp_display_shell_filter_new (GimpColorConfig *config);
#endif /* __GIMP_DISPLAY_SHELL_FILTER_H__ */
......@@ -29,6 +29,7 @@
#include "display-types.h"
#include "tools/tools-types.h"
#include "config/gimpcoreconfig.h"
#include "config/gimpdisplayconfig.h"
#include "core/gimp.h"
......@@ -569,6 +570,7 @@ gimp_display_shell_new (GimpDisplay *gdisp,
{
GimpDisplayShell *shell;
GimpDisplayConfig *display_config;
GimpColorConfig *color_config;
GtkWidget *main_vbox;
GtkWidget *disp_vbox;
GtkWidget *upper_hbox;
......@@ -1007,6 +1009,10 @@ gimp_display_shell_new (GimpDisplay *gdisp,
gtk_widget_show (main_vbox);
color_config = gdisp->gimage->gimp->config->color_management;
gimp_display_shell_filter_set (shell,
gimp_display_shell_filter_new (color_config));
gimp_display_shell_connect (shell);
gimp_display_shell_title_init (shell);
......
......@@ -25,6 +25,11 @@ GimpColorConfig
</para>
<!-- ##### ARG GimpColorConfig:display-module ##### -->
<para>
</para>
<!-- ##### ARG GimpColorConfig:display-profile ##### -->
<para>
......
......@@ -100,6 +100,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -144,6 +146,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -188,6 +192,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -234,6 +240,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -278,6 +286,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -323,6 +333,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -369,6 +381,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -413,6 +427,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -459,6 +475,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -506,6 +524,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -550,6 +570,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -596,6 +618,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -642,6 +666,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......@@ -686,6 +712,8 @@ gimpconfig-params
name:
@\
name:
@\
name:
@\
name:
@blurb:
......
......@@ -68,9 +68,12 @@ enum
PROP_PRINTER_PROFILE,
PROP_DISPLAY_RENDERING_INTENT,
PROP_SIMULATION_RENDERING_INTENT,
PROP_DISPLAY_MODULE
#if 0
PROP_OPEN_BEHAVIOUR_NO_PROFILE,
PROP_OPEN_BEHAVIOUR_RGB_PROFILE,
PROP_OPEN_BEHAVIOUR_CMYK_PROFILE
#endif
};
......@@ -173,6 +176,10 @@ gimp_color_config_class_init (GimpColorConfigClass *klass)
GIMP_TYPE_COLOR_RENDERING_INTENT,
GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
0);
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_DISPLAY_MODULE,
"display-module", NULL,
"CdisplayLcms",
0);
#if 0
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_OPEN_BEHAVIOUR_NO_PROFILE,
"open-behaviour-no-profile",
......@@ -243,6 +250,9 @@ gimp_color_config_set_property (GObject *object,
case PROP_SIMULATION_RENDERING_INTENT:
color_config->simulation_intent = g_value_get_enum (value);
break;
case PROP_DISPLAY_MODULE:
color_config->display_module = g_value_dup_string (value);
break;
#if 0
case PROP_OPEN_BEHAVIOUR_NO_PROFILE:
color_config->open_behaviour_no_profile = g_value_get_enum (value);
......@@ -291,6 +301,9 @@ gimp_color_config_get_property (GObject *object,
case PROP_SIMULATION_RENDERING_INTENT:
g_value_set_enum (value, color_config->simulation_intent);
break;
case PROP_DISPLAY_MODULE:
g_value_set_string (value, color_config->display_module);
break;
#if 0
case PROP_OPEN_BEHAVIOUR_NO_PROFILE:
g_value_set_enum (value, color_config->open_behaviour_no_profile);
......
......@@ -44,6 +44,8 @@ struct _GimpColorConfig
gchar *printer_profile;
GimpColorRenderingIntent display_intent;
GimpColorRenderingIntent simulation_intent;
gchar *display_module;
};
struct _GimpColorConfigClass
......
......@@ -21,6 +21,7 @@ EXTRA_DIST = \
makefile.msc
if HAVE_LCMS
cdisplay_lcms_module = libcdisplay_lcms.la
cdisplay_proof_module = libcdisplay_proof.la
endif
......@@ -35,12 +36,12 @@ lib_LTLIBRARIES = \
libcdisplay_colorblind.la \
libcdisplay_gamma.la \
libcdisplay_highcontrast.la \
$(cdisplay_lcms_module) \
$(cdisplay_proof_module) \
libcontroller_midi.la \
$(controller_linux_input_module)
modules_libadd = $(libgimpmodule) $(libgimpwidgets) $(GTK_LIBS)
colorsel_libadd = $(libgimpcolor) $(modules_libadd)
......@@ -71,6 +72,10 @@ libcdisplay_highcontrast_la_SOURCES = cdisplay_highcontrast.c
libcdisplay_highcontrast_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcdisplay_highcontrast_la_LIBADD = $(cdisplay_libadd)
libcdisplay_lcms_la_SOURCES = cdisplay_lcms.c
libcdisplay_lcms_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcdisplay_lcms_la_LIBADD = $(cdisplay_libadd) $(LCMS_LIBS)
libcdisplay_proof_la_SOURCES = cdisplay_proof.c
libcdisplay_proof_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcdisplay_proof_la_LIBADD = $(cdisplay_libadd) $(LCMS_LIBS)
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#ifdef HAVE_LCMS_LCMS_H
#include <lcms/lcms.h>
#else
#include <lcms.h>
#endif
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpmodule/gimpmodule.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimp/libgimp-intl.h"
#define CDISPLAY_TYPE_LCMS (cdisplay_lcms_type)
#define CDISPLAY_LCMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_LCMS, CdisplayLcms))
#define CDISPLAY_LCMS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_LCMS, CdisplayLcmsClass))
#define CDISPLAY_IS_LCMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_LCMS))
#define CDISPLAY_IS_LCMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_LCMS))
typedef struct _CdisplayLcms CdisplayLcms;
typedef struct _CdisplayLcmsClass CdisplayLcmsClass;
struct _CdisplayLcms
{
GimpColorDisplay parent_instance;
GimpColorConfig *config;
cmsHTRANSFORM transform;
};
struct _CdisplayLcmsClass
{
GimpColorDisplayClass parent_instance;
};
enum
{
PROP_0,
PROP_CONFIG
};
static GType cdisplay_lcms_get_type (GTypeModule *module);
static void cdisplay_lcms_class_init (CdisplayLcmsClass *klass);
static void cdisplay_lcms_init (CdisplayLcms *lcms);
static void cdisplay_lcms_finalize (GObject *object);
static void cdisplay_lcms_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void cdisplay_lcms_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void cdisplay_lcms_convert (GimpColorDisplay *display,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl);
static void cdisplay_lcms_changed (GimpColorDisplay *display);
static void cdisplay_lcms_set_config (CdisplayLcms *lcms,
GimpColorConfig *config);
static const GimpModuleInfo cdisplay_lcms_info =
{
GIMP_MODULE_ABI_VERSION,
N_("Color management display filter using ICC color profiles"),
"Sven Neumann",
"v0.1",
"(c) 2005, released under the GPL",
"2005"
};
static GType cdisplay_lcms_type = 0;
static GimpColorDisplayClass *parent_class = NULL;
G_MODULE_EXPORT const GimpModuleInfo *
gimp_module_query (GTypeModule *module)
{
return &cdisplay_lcms_info;
}
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module)
{
cdisplay_lcms_get_type (module);
return TRUE;
}
static GType
cdisplay_lcms_get_type (GTypeModule *module)
{
if (! cdisplay_lcms_type)
{
static const GTypeInfo display_info =
{
sizeof (CdisplayLcmsClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) cdisplay_lcms_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (CdisplayLcms),
0, /* n_preallocs */
(GInstanceInitFunc) cdisplay_lcms_init,
};
cdisplay_lcms_type =
g_type_module_register_type (module, GIMP_TYPE_COLOR_DISPLAY,
"CdisplayLcms", &display_info, 0);
}
return cdisplay_lcms_type;
}
static void
cdisplay_lcms_class_init (CdisplayLcmsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = cdisplay_lcms_finalize;
object_class->get_property = cdisplay_lcms_get_property;
object_class->set_property = cdisplay_lcms_set_property;
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, PROP_CONFIG,
"config", NULL,
GIMP_TYPE_COLOR_CONFIG,
0);
display_class->name = _("Color Management");
display_class->help_id = "gimp-colordisplay-lcms";
display_class->convert = cdisplay_lcms_convert;
display_class->changed = cdisplay_lcms_changed;
cmsErrorAction (LCMS_ERROR_IGNORE);
}
static void
cdisplay_lcms_init (CdisplayLcms *lcms)
{
lcms->config = NULL;
lcms->transform = NULL;
}
static void
cdisplay_lcms_finalize (GObject *object)
{
CdisplayLcms *lcms = CDISPLAY_LCMS (object);
cdisplay_lcms_set_config (lcms, NULL);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
cdisplay_lcms_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CdisplayLcms *lcms = CDISPLAY_LCMS (object);
switch (property_id)
{
case PROP_CONFIG:
g_value_set_object (value, lcms->config);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
cdisplay_lcms_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CdisplayLcms *lcms = CDISPLAY_LCMS (object);
switch (property_id)
{
case PROP_CONFIG:
cdisplay_lcms_set_config (lcms, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
cdisplay_lcms_convert (GimpColorDisplay *display,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl)
{
CdisplayLcms *lcms = CDISPLAY_LCMS (display);
gint y;
if (bpp != 3)
return;
if (! lcms->transform)
return;
for (y = 0; y < height; y++, buf += bpl)
cmsDoTransform (lcms->transform, buf, buf, width);
}
static void
cdisplay_lcms_changed (GimpColorDisplay *display)
{
CdisplayLcms *lcms = CDISPLAY_LCMS (display);
GimpColorConfig *config = lcms->config;
cmsHPROFILE src_profile = NULL;
cmsHPROFILE dest_profile = NULL;
cmsHPROFILE proof_profile = NULL;
if (lcms->transform)
{
cmsDeleteTransform (lcms->transform);
lcms->transform = NULL;
}
if (! config)
return;
switch (config->mode)
{
case GIMP_COLOR_MANAGEMENT_OFF:
return;
case GIMP_COLOR_MANAGEMENT_SOFTPROOF:
if (config->printer_profile)
proof_profile = cmsOpenProfileFromFile (config->printer_profile, "r");
/* fallthru */
case GIMP_COLOR_MANAGEMENT_DISPLAY:
/* this should be taken from the image */
src_profile = cmsCreate_sRGBProfile ();
if (config->display_profile)
dest_profile = cmsOpenProfileFromFile (config->display_profile,"r");
break;
}
if (proof_profile)
{
lcms->transform = cmsCreateProofingTransform (src_profile, TYPE_RGB_8,
(dest_profile ?
dest_profile :
src_profile), TYPE_RGB_8,
proof_profile,
config->display_intent,
config->simulation_intent,
cmsFLAGS_SOFTPROOFING);
cmsCloseProfile (proof_profile);
}
else if (dest_profile)
{
lcms->transform = cmsCreateTransform (src_profile, TYPE_RGB_8,
dest_profile, TYPE_RGB_8,
config->display_intent,
0);
}
if (dest_profile)
cmsCloseProfile (dest_profile);
cmsCloseProfile (src_profile);
}
static void
cdisplay_lcms_set_config (CdisplayLcms *lcms,
GimpColorConfig *config)
{
if (config == lcms->config)
return;
if (lcms->config)
{
g_signal_handlers_disconnect_by_func (lcms->config,
G_CALLBACK (gimp_color_display_changed),
lcms);
g_object_unref (lcms->config);
}
lcms->config = config;
if (lcms->config)
{
g_object_ref (lcms->config);
g_signal_connect_swapped (lcms->config, "notify",
G_CALLBACK (gimp_color_display_changed),
lcms);
}
gimp_color_display_changed (GIMP_COLOR_DISPLAY (lcms));