modules/Makefile.am new CMYK color-selector that uses littleCMS for the

2006-09-26  Sven Neumann  <sven@gimp.org>

	* modules/Makefile.am
	* modules/colorsel_cmyk_lcms.c: new CMYK color-selector that
uses
	littleCMS for the RGB <-> CMYK conversion. This is built instead
	of the standard CMYK color-selector if lcms is available.

	* libgimpwidgets/gimpcolornotebook.c
	* libgimpwidgets/gimpcolorselection.[ch]
	* libgimpwidgets/gimpcolorselector.[ch]
	* libgimpwidgets/gimpwidgets.def: added API to set the color
	management configuration on color selectors.

	* libgimpwidgets/gimpwidgetstypes.h: include
	libgimpconfig/gimpconfigtypes.h.

	* app/dialogs/grid-dialog.c
	* app/dialogs/preferences-dialog.c
	* app/widgets/gimpcolordialog.c
	* app/widgets/gimpcoloreditor.c
	* app/widgets/gimpcolorpanel.c
	* app/widgets/gimpgrideditor.[ch]
	* app/widgets/gimppropwidgets.c
	* app/widgets/gimptoolbox-color-area.c: set the color management
	configuration on (hopefully) all color selectors.

	* modules/cdisplay_lcms.c: use a GimpHintBox widget.
This commit is contained in:
Sven Neumann 2006-09-26 08:55:41 +00:00 committed by Sven Neumann
parent 03251e6b6a
commit ba9efb3433
20 changed files with 654 additions and 46 deletions

View File

@ -1,3 +1,31 @@
2006-09-26 Sven Neumann <sven@gimp.org>
* modules/Makefile.am
* modules/colorsel_cmyk_lcms.c: new CMYK color-selector that uses
littleCMS for the RGB <-> CMYK conversion. This is built instead
of the standard CMYK color-selector if lcms is available.
* libgimpwidgets/gimpcolornotebook.c
* libgimpwidgets/gimpcolorselection.[ch]
* libgimpwidgets/gimpcolorselector.[ch]
* libgimpwidgets/gimpwidgets.def: added API to set the color
management configuration on color selectors.
* libgimpwidgets/gimpwidgetstypes.h: include
libgimpconfig/gimpconfigtypes.h.
* app/dialogs/grid-dialog.c
* app/dialogs/preferences-dialog.c
* app/widgets/gimpcolordialog.c
* app/widgets/gimpcoloreditor.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpgrideditor.[ch]
* app/widgets/gimppropwidgets.c
* app/widgets/gimptoolbox-color-area.c: set the color management
configuration on (hopefully) all color selectors.
* modules/cdisplay_lcms.c: use a GimpHintBox widget.
2006-09-25 Michael Natterer <mitch@gimp.org>
* plug-ins/uri/uri-backend-libcurl.c: while downloading, use the

View File

@ -103,9 +103,8 @@ grid_dialog_new (GimpImage *image,
G_CALLBACK (grid_dialog_response),
dialog);
editor = gimp_grid_editor_new (grid,
image->xresolution,
image->yresolution);
editor = gimp_grid_editor_new (grid, context,
image->xresolution, image->yresolution);
gtk_container_set_border_width (GTK_CONTAINER (editor), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
editor);

View File

@ -1078,7 +1078,8 @@ prefs_color_button_add (GObject *config,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *button = gimp_prop_color_button_new (config, property_name, title,
GtkWidget *button = gimp_prop_color_button_new (config, property_name,
title,
60, 20,
GIMP_COLOR_AREA_FLAT);
@ -1921,6 +1922,7 @@ prefs_dialog_new (Gimp *gimp,
/* Grid */
editor = gimp_grid_editor_new (core_config->default_grid,
gimp_get_user_context (gimp),
core_config->default_image->xresolution,
core_config->default_image->yresolution);

View File

@ -23,10 +23,14 @@
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpmarshal.h"
#include "core/gimpviewable.h"
@ -258,6 +262,9 @@ gimp_color_dialog_new (GimpViewable *viewable,
NULL);
g_return_val_if_fail (color != NULL, NULL);
if (! context)
g_warning ("gimp_color_dialog_new() called with a NULL context");
role = dialog_identifier ? dialog_identifier : "gimp-color-selector";
dialog = g_object_new (GIMP_TYPE_COLOR_DIALOG,
@ -284,6 +291,11 @@ gimp_color_dialog_new (GimpViewable *viewable,
gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (dialog->selection),
show_alpha);
if (context)
gimp_color_selection_set_config (GIMP_COLOR_SELECTION (dialog->selection),
context->gimp->config->color_management);
gimp_color_selection_set_color (GIMP_COLOR_SELECTION (dialog->selection),
color);
gimp_color_selection_set_old_color (GIMP_COLOR_SELECTION (dialog->selection),

View File

@ -31,6 +31,9 @@
#include "widgets-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "gimpcoloreditor.h"
@ -445,6 +448,9 @@ gimp_color_editor_set_context (GimpDocked *docked,
gimp_context_get_foreground (editor->context, &rgb);
gimp_color_editor_fg_changed (editor->context, &rgb, editor);
}
gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (editor->notebook),
context->gimp->config->color_management);
}
gimp_fg_bg_editor_set_context (GIMP_FG_BG_EDITOR (editor->fg_bg), context);

View File

@ -157,7 +157,7 @@ gimp_color_panel_clicked (GtkButton *button)
if (! panel->color_dialog)
{
panel->color_dialog =
gimp_color_dialog_new (NULL, NULL,
gimp_color_dialog_new (NULL, panel->context,
GIMP_COLOR_BUTTON (button)->title,
NULL, NULL,
GTK_WIDGET (button),

View File

@ -28,9 +28,11 @@
#include "widgets-types.h"
#include "core/gimpcontext.h"
#include "core/gimpgrid.h"
#include "core/gimpmarshal.h"
#include "gimpcolorpanel.h"
#include "gimpgrideditor.h"
#include "gimppropwidgets.h"
@ -47,6 +49,7 @@ enum
{
PROP_0,
PROP_GRID,
PROP_CONTEXT,
PROP_XRESOLUTION,
PROP_YRESOLUTION
};
@ -86,6 +89,11 @@ gimp_grid_editor_class_init (GimpGridEditorClass *klass)
GIMP_TYPE_GRID,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("context", NULL, NULL,
GIMP_TYPE_CONTEXT,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_XRESOLUTION,
g_param_spec_double ("xresolution", NULL, NULL,
GIMP_MIN_RESOLUTION,
@ -120,6 +128,9 @@ gimp_grid_editor_set_property (GObject *object,
case PROP_GRID:
editor->grid = GIMP_GRID (g_value_dup_object (value));
break;
case PROP_CONTEXT:
editor->context = GIMP_CONTEXT (g_value_dup_object (value));
break;
case PROP_XRESOLUTION:
editor->xresolution = g_value_get_double (value);
break;
@ -145,6 +156,9 @@ gimp_grid_editor_get_property (GObject *object,
case PROP_GRID:
g_value_set_object (value, editor->grid);
break;
case PROP_CONTEXT:
g_value_set_object (value, editor->context);
break;
case PROP_XRESOLUTION:
g_value_set_double (value, editor->xresolution);
break;
@ -200,6 +214,8 @@ gimp_grid_editor_constructor (GType type,
GRID_EDITOR_COLOR_BUTTON_WIDTH,
GRID_EDITOR_COLOR_BUTTON_HEIGHT,
GIMP_COLOR_AREA_FLAT);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button),
editor->context);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("_Foreground color:"), 0.0, 0.5,
color_button, 1, TRUE);
@ -209,6 +225,8 @@ gimp_grid_editor_constructor (GType type,
GRID_EDITOR_COLOR_BUTTON_WIDTH,
GRID_EDITOR_COLOR_BUTTON_HEIGHT,
GIMP_COLOR_AREA_FLAT);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button),
editor->context);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("_Background color:"), 0.0, 0.5,
color_button, 1, TRUE);
@ -293,18 +311,26 @@ gimp_grid_editor_finalize (GObject *object)
editor->grid = NULL;
}
if (editor->context)
{
g_object_unref (editor->context);
editor->context = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
GtkWidget *
gimp_grid_editor_new (GimpGrid *grid,
gdouble xresolution,
gdouble yresolution)
gimp_grid_editor_new (GimpGrid *grid,
GimpContext *context,
gdouble xresolution,
gdouble yresolution)
{
g_return_val_if_fail (GIMP_IS_GRID (grid), NULL);
return g_object_new (GIMP_TYPE_GRID_EDITOR,
"grid", grid,
"context", context,
"xresolution", xresolution,
"yresolution", yresolution,
NULL);

View File

@ -41,6 +41,7 @@ struct _GimpGridEditor
GtkVBox parent_instance;
GimpGrid *grid;
GimpContext *context;
gdouble xresolution;
gdouble yresolution;
};
@ -53,9 +54,10 @@ struct _GimpGridEditorClass
GType gimp_grid_editor_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_grid_editor_new (GimpGrid *grid,
gdouble xresolution,
gdouble yresolution);
GtkWidget * gimp_grid_editor_new (GimpGrid *grid,
GimpContext *context,
gdouble xresolution,
gdouble yresolution);
#endif /* __GIMP_GRID_EDITOR_H__ */

View File

@ -181,6 +181,7 @@ static void gimp_prop_color_button_notify (GObject *config,
* gimp_prop_color_button_new:
* @config: #GimpConfig object to which property is attached.
* @property_name: Name of #GimpRGB property.
* @conext: #GimpContext to take the color management config from
* @title: Title of the #GimpColorPanel that is to be created
* @width: Width of color button.
* @height: Height of color button.
@ -215,7 +216,6 @@ gimp_prop_color_button_new (GObject *config,
NULL);
button = gimp_color_panel_new (title, value, type, width, height);
g_free (value);
set_param_spec (G_OBJECT (button), button, param_spec);

View File

@ -148,7 +148,8 @@ color_area_color_clicked (GimpFgBgEditor *editor,
toplevel_factory = gimp_dialog_factory_from_name ("toplevel");
color_dialog = gimp_color_dialog_new (NULL, NULL, NULL, NULL, NULL,
color_dialog = gimp_color_dialog_new (NULL, context,
NULL, NULL, NULL,
GTK_WIDGET (editor),
toplevel_factory,
"gimp-toolbox-color-dialog",

View File

@ -57,6 +57,9 @@ static void gimp_color_notebook_set_color (GimpColorSelector *selector,
const GimpHSV *hsv);
static void gimp_color_notebook_set_channel (GimpColorSelector *selector,
GimpColorSelectorChannel channel);
static void gimp_color_notebook_set_config (GimpColorSelector *selector,
GimpColorConfig *config);
static void gimp_color_notebook_switch_page (GtkNotebook *gtk_notebook,
GtkNotebookPage *page,
@ -99,6 +102,7 @@ gimp_color_notebook_class_init (GimpColorNotebookClass *klass)
selector_class->set_show_alpha = gimp_color_notebook_set_show_alpha;
selector_class->set_color = gimp_color_notebook_set_color;
selector_class->set_channel = gimp_color_notebook_set_channel;
selector_class->set_config = gimp_color_notebook_set_config;
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("tab-border",
@ -288,6 +292,21 @@ gimp_color_notebook_set_channel (GimpColorSelector *selector,
notebook);
}
static void
gimp_color_notebook_set_config (GimpColorSelector *selector,
GimpColorConfig *config)
{
GimpColorNotebook *notebook = GIMP_COLOR_NOTEBOOK (selector);
GList *list;
for (list = notebook->selectors; list; list = g_list_next (list))
{
GimpColorSelector *child = list->data;
gimp_color_selector_set_config (child, config);
}
}
static void
gimp_color_notebook_switch_page (GtkNotebook *gtk_notebook,
GtkNotebookPage *page,

View File

@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "gimpwidgetstypes.h"
@ -65,6 +66,17 @@ enum
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_CONFIG
};
static void gimp_color_selection_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_color_selection_switch_page (GtkWidget *widget,
GtkNotebookPage *page,
@ -103,6 +115,18 @@ static guint selection_signals[LAST_SIGNAL] = { 0 };
static void
gimp_color_selection_class_init (GimpColorSelectionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = gimp_color_selection_set_property;
klass->color_changed = NULL;
g_object_class_install_property (object_class, PROP_CONFIG,
g_param_spec_object ("config",
NULL, NULL,
GIMP_TYPE_COLOR_CONFIG,
G_PARAM_WRITABLE));
selection_signals[COLOR_CHANGED] =
g_signal_new ("color-changed",
G_TYPE_FROM_CLASS (klass),
@ -112,7 +136,6 @@ gimp_color_selection_class_init (GimpColorSelectionClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
klass->color_changed = NULL;
}
static void
@ -278,6 +301,27 @@ gimp_color_selection_init (GimpColorSelection *selection)
selection);
}
static void
gimp_color_selection_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpColorSelection *selection = GIMP_COLOR_SELECTION (object);
switch (property_id)
{
case PROP_CONFIG:
gimp_color_selection_set_config (selection, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/**
* gimp_color_selection_new:
*
@ -444,6 +488,27 @@ gimp_color_selection_color_changed (GimpColorSelection *selection)
g_signal_emit (selection, selection_signals[COLOR_CHANGED], 0);
}
/**
* gimp_color_selection_set_config:
* @selection:
* @config:
*
* Sets the color management configuration to use with this color selection.
*
* Since: GIMP 2.4
*/
void
gimp_color_selection_set_config (GimpColorSelection *selection,
GimpColorConfig *config)
{
g_return_if_fail (GIMP_IS_COLOR_SELECTION (selection));
g_return_if_fail (config == NULL || GIMP_IS_COLOR_CONFIG (config));
gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (selection->notebook),
config);
gimp_color_selector_set_config (GIMP_COLOR_SELECTOR (selection->scales),
config);
}
/* private functions */

View File

@ -94,6 +94,9 @@ void gimp_color_selection_reset (GimpColorSelection *selection);
void gimp_color_selection_color_changed (GimpColorSelection *selection);
void gimp_color_selection_set_config (GimpColorSelection *selection,
GimpColorConfig *config);
G_END_DECLS

View File

@ -29,6 +29,7 @@
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "gimpwidgetstypes.h"
@ -86,6 +87,7 @@ gimp_color_selector_class_init (GimpColorSelectorClass *klass)
klass->set_channel = NULL;
klass->color_changed = NULL;
klass->channel_changed = NULL;
klass->set_config = NULL;
}
static void
@ -239,3 +241,27 @@ gimp_color_selector_channel_changed (GimpColorSelector *selector)
g_signal_emit (selector, selector_signals[CHANNEL_CHANGED], 0,
selector->channel);
}
/**
* gimp_color_selector_set_config:
* @selector:
* @config:
*
* Sets the color management configuration to use with this color selector.
*
* Since: GIMP 2.4
*/
void
gimp_color_selector_set_config (GimpColorSelector *selector,
GimpColorConfig *config)
{
GimpColorSelectorClass *selector_class;
g_return_if_fail (GIMP_IS_COLOR_SELECTOR (selector));
g_return_if_fail (config == NULL || GIMP_IS_COLOR_CONFIG (config));
selector_class = GIMP_COLOR_SELECTOR_GET_CLASS (selector);
if (selector_class->set_config)
selector_class->set_config (selector, config);
}

View File

@ -88,8 +88,11 @@ struct _GimpColorSelectorClass
void (* channel_changed) (GimpColorSelector *selector,
GimpColorSelectorChannel channel);
/* another virtual function */
void (* set_config) (GimpColorSelector *selector,
GimpColorConfig *config);
/* Padding for future expansion */
void (* _gimp_reserved1) (void);
void (* _gimp_reserved2) (void);
void (* _gimp_reserved3) (void);
void (* _gimp_reserved4) (void);
@ -117,6 +120,9 @@ void gimp_color_selector_set_channel (GimpColorSelector *selector,
void gimp_color_selector_color_changed (GimpColorSelector *selector);
void gimp_color_selector_channel_changed (GimpColorSelector *selector);
void gimp_color_selector_set_config (GimpColorSelector *selector,
GimpColorConfig *config);
G_END_DECLS

View File

@ -68,6 +68,7 @@ EXPORTS
gimp_color_select_get_type
gimp_color_selection_color_changed
gimp_color_selection_get_color
gimp_color_selection_set_config
gimp_color_selection_get_old_color
gimp_color_selection_get_show_alpha
gimp_color_selection_get_type
@ -83,6 +84,7 @@ EXPORTS
gimp_color_selector_new
gimp_color_selector_set_channel
gimp_color_selector_set_color
gimp_color_selector_set_config
gimp_color_selector_set_show_alpha
gimp_color_selector_set_toggles_sensitive
gimp_color_selector_set_toggles_visible

View File

@ -22,7 +22,7 @@
#ifndef __GIMP_WIDGETS_TYPES_H__
#define __GIMP_WIDGETS_TYPES_H__
#include <libgimpbase/gimpbasetypes.h>
#include <libgimpconfig/gimpconfigtypes.h>
#include <libgimpwidgets/gimpwidgetsenums.h>

View File

@ -21,8 +21,11 @@ EXTRA_DIST = \
makefile.msc
if HAVE_LCMS
colorsel_cmyk_module = libcolorsel_cmyk_lcms.la
cdisplay_lcms_module = libcdisplay_lcms.la
cdisplay_proof_module = libcdisplay_proof.la
else
colorsel_cmyk_module = libcolorsel_cmyk.la
endif
if HAVE_LINUX_INPUT
@ -30,7 +33,7 @@ controller_linux_input_module = libcontroller_linux_input.la
endif
lib_LTLIBRARIES = \
libcolorsel_cmyk.la \
$(colorsel_cmyk_module) \
libcolorsel_triangle.la \
libcolorsel_water.la \
libcdisplay_colorblind.la \
@ -52,6 +55,10 @@ libcolorsel_cmyk_la_SOURCES = colorsel_cmyk.c
libcolorsel_cmyk_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcolorsel_cmyk_la_LIBADD = $(colorsel_libadd)
libcolorsel_cmyk_lcms_la_SOURCES = colorsel_cmyk_lcms.c
libcolorsel_cmyk_lcms_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcolorsel_cmyk_lcms_la_LIBADD = $(libgimpconfig) $(colorsel_libadd) $(LCMS_LIBS)
libcolorsel_triangle_la_SOURCES = colorsel_triangle.c
libcolorsel_triangle_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcolorsel_triangle_la_LIBADD = $(colorsel_libadd)

View File

@ -264,9 +264,7 @@ cdisplay_lcms_configure (GimpColorDisplay *display)
CdisplayLcms *lcms = CDISPLAY_LCMS (display);
GObject *config = G_OBJECT (lcms->config);
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *image;
GtkWidget *hint;
GtkWidget *table;
cmsHPROFILE profile;
const gchar *name;
@ -278,29 +276,11 @@ cdisplay_lcms_configure (GimpColorDisplay *display)
vbox = gtk_vbox_new (FALSE, 12);
hbox = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
image = gtk_image_new_from_stock (GIMP_STOCK_INFO, GTK_ICON_SIZE_DIALOG);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
label = g_object_new (GTK_TYPE_LABEL,
"label", _("This filter takes its configuration "
"from the Color Management section "
"in the Preferences dialog."),
"wrap", TRUE,
"justify", GTK_JUSTIFY_LEFT,
"xalign", 0.0,
"yalign", 0.5,
NULL);
gimp_label_set_attributes (GTK_LABEL (label),
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-1);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
hint = gimp_hint_box_new (_("This filter takes its configuration "
"from the Color Management section "
"in the Preferences dialog."));
gtk_box_pack_start (GTK_BOX (vbox), hint, FALSE, FALSE, 0);
gtk_widget_show (hint);
table = gtk_table_new (5, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
@ -460,14 +440,15 @@ cdisplay_lcms_set_config (CdisplayLcms *lcms,
static cmsHPROFILE
cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms)
{
GimpColorConfig *config = lcms->config;
GimpColorConfig *config = lcms->config;
cmsHPROFILE profile = NULL;
/* this should be taken from the image */
if (config->rgb_profile)
return cmsOpenProfileFromFile (config->rgb_profile, "r");
profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
return cmsCreate_sRGBProfile ();
return profile ? profile : cmsCreate_sRGBProfile ();
}
static cmsHPROFILE

View File

@ -0,0 +1,423 @@
/* GIMP CMYK ColorSelector using littleCMS
* 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "config.h"
#include <glib.h> /* lcms.h uses the "inline" keyword */
#ifdef HAVE_LCMS_LCMS_H
#include <lcms/lcms.h>
#else
#include <lcms.h>
#endif
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpmodule/gimpmodule.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimp/libgimp-intl.h"
/* definitions and variables */
#define COLORSEL_TYPE_CMYK (colorsel_cmyk_type)
#define COLORSEL_CMYK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLORSEL_TYPE_CMYK, ColorselCmyk))
#define COLORSEL_CMYK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COLORSEL_TYPE_CMYK, ColorselCmykClass))
#define COLORSEL_IS_CMYK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLORSEL_TYPE_CMYK))
#define COLORSEL_IS_CMYK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COLORSEL_TYPE_CMYK))
typedef struct _ColorselCmyk ColorselCmyk;
typedef struct _ColorselCmykClass ColorselCmykClass;
struct _ColorselCmyk
{
GimpColorSelector parent_instance;
GimpColorConfig *config;
cmsHTRANSFORM rgb2cmyk;
cmsHTRANSFORM cmyk2rgb;
GimpCMYK cmyk;
GtkAdjustment *adj[4];
GtkWidget *name_label;
};
struct _ColorselCmykClass
{
GimpColorSelectorClass parent_class;
};
static GType colorsel_cmyk_get_type (GTypeModule *module);
static void colorsel_cmyk_class_init (ColorselCmykClass *klass);
static void colorsel_cmyk_init (ColorselCmyk *cmyk);
static void colorsel_cmyk_dispose (GObject *object);
static void colorsel_cmyk_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
static void colorsel_cmyk_set_config (GimpColorSelector *selector,
GimpColorConfig *config);
static void colorsel_cmyk_adj_update (GtkAdjustment *adj,
ColorselCmyk *module);
static void colorsel_cmyk_config_changed (ColorselCmyk *module);
static const GimpModuleInfo colorsel_cmyk_info =
{
GIMP_MODULE_ABI_VERSION,
N_("CMYK color selector (using color profile)"),
"Sven Neumann <sven@gimp.org>",
"v0.1",
"(c) 2006, released under the GPL",
"September 2006"
};
static GType colorsel_cmyk_type = 0;
static GObjectClass *parent_class = NULL;
G_MODULE_EXPORT const GimpModuleInfo *
gimp_module_query (GTypeModule *module)
{
return &colorsel_cmyk_info;
}
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module)
{
colorsel_cmyk_get_type (module);
return TRUE;
}
static GType
colorsel_cmyk_get_type (GTypeModule *module)
{
if (! colorsel_cmyk_type)
{
static const GTypeInfo select_info =
{
sizeof (ColorselCmykClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) colorsel_cmyk_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (ColorselCmyk),
0, /* n_preallocs */
(GInstanceInitFunc) colorsel_cmyk_init,
};
colorsel_cmyk_type =
g_type_module_register_type (module,
GIMP_TYPE_COLOR_SELECTOR,
"ColorselCmyk",
&select_info, 0);
}
return colorsel_cmyk_type;
}
static void
colorsel_cmyk_class_init (ColorselCmykClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->dispose = colorsel_cmyk_dispose;
selector_class->name = _("CMYK");
selector_class->help_id = "gimp-colorselector-cmyk";
selector_class->stock_id = GTK_STOCK_PRINT; /* FIXME */
selector_class->set_color = colorsel_cmyk_set_color;
selector_class->set_config = colorsel_cmyk_set_config;
}
static void
colorsel_cmyk_init (ColorselCmyk *module)
{
GtkWidget *table;
GtkObject *adj;
gint i;
static const gchar * const cmyk_labels[] =
{
/* Cyan */
N_("_C"),
/* Magenta */
N_("_M"),
/* Yellow */
N_("_Y"),
/* Key (Black) */
N_("_K")
};
static const gchar * const cmyk_tips[] =
{
N_("Cyan"),
N_("Magenta"),
N_("Yellow"),
N_("Black")
};
module->config = NULL;
module->rgb2cmyk = NULL;
module->cmyk2rgb = NULL;
gtk_box_set_spacing (GTK_BOX (module), 6);
table = gtk_table_new (4, 4, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 0);
gtk_box_pack_start (GTK_BOX (module), table, FALSE, FALSE, 0);
gtk_widget_show (table);
for (i = 0; i < 4; i++)
{
adj = gimp_scale_entry_new (GTK_TABLE (table), 1, i,
gettext (cmyk_labels[i]),
-1, -1,
0.0,
0.0, 100.0,
1.0, 10.0,
0,
TRUE, 0.0, 0.0,
gettext (cmyk_tips[i]),
NULL);
g_signal_connect (adj, "value-changed",
G_CALLBACK (colorsel_cmyk_adj_update),
module);
module->adj[i] = GTK_ADJUSTMENT (adj);
}
module->name_label = gtk_label_new (NULL);
gtk_misc_set_alignment (GTK_MISC (module->name_label), 0.0, 0.5);
gimp_label_set_attributes (GTK_LABEL (module->name_label),
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-1);
gtk_box_pack_start (GTK_BOX (module), module->name_label, FALSE, FALSE, 0);
gtk_widget_show (module->name_label);
}
static void
colorsel_cmyk_dispose (GObject *object)
{
colorsel_cmyk_set_config (GIMP_COLOR_SELECTOR (object), NULL);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
colorsel_cmyk_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
ColorselCmyk *module = COLORSEL_CMYK (selector);
if (module->rgb2cmyk)
{
gdouble rgb_values[3];
gdouble cmyk_values[4];
rgb_values[0] = rgb->r;
rgb_values[1] = rgb->g;
rgb_values[2] = rgb->b;
cmsDoTransform (module->rgb2cmyk, rgb_values, cmyk_values, 1);
module->cmyk.c = cmyk_values[0] / 100.0;
module->cmyk.m = cmyk_values[1] / 100.0;
module->cmyk.y = cmyk_values[2] / 100.0;
module->cmyk.k = cmyk_values[3] / 100.0;
}
else
{
gimp_rgb_to_cmyk (rgb, 1.0, &module->cmyk);
}
gtk_adjustment_set_value (module->adj[0], module->cmyk.c * 100.0);
gtk_adjustment_set_value (module->adj[1], module->cmyk.m * 100.0);
gtk_adjustment_set_value (module->adj[2], module->cmyk.y * 100.0);
gtk_adjustment_set_value (module->adj[3], module->cmyk.k * 100.0);
}
static void
colorsel_cmyk_set_config (GimpColorSelector *selector,
GimpColorConfig *config)
{
ColorselCmyk *module = COLORSEL_CMYK (selector);
if (config == module->config)
return;
if (module->config)
{
g_signal_handlers_disconnect_by_func (module->config,
G_CALLBACK (colorsel_cmyk_config_changed),
module);
g_object_unref (module->config);
}
module->config = config;
if (module->config)
{
g_object_ref (module->config);
g_signal_connect_swapped (module->config, "notify",
G_CALLBACK (colorsel_cmyk_config_changed),
module);
}
colorsel_cmyk_config_changed (module);
}
static void
colorsel_cmyk_adj_update (GtkAdjustment *adj,
ColorselCmyk *module)
{
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
gint i;
for (i = 0; i < 4; i++)
if (module->adj[i] == adj)
break;
switch (i)
{
case 0:
module->cmyk.c = adj->value / 100.0;
break;
case 1:
module->cmyk.m = adj->value / 100.0;
break;
case 2:
module->cmyk.y = adj->value / 100.0;
break;
case 3:
module->cmyk.k = adj->value / 100.0;
break;
default:
return;
}
if (module->cmyk2rgb)
{
gdouble cmyk_values[4];
gdouble rgb_values[3];
cmyk_values[0] = module->cmyk.c * 100.0;
cmyk_values[1] = module->cmyk.m * 100.0;
cmyk_values[2] = module->cmyk.y * 100.0;
cmyk_values[3] = module->cmyk.k * 100.0;
cmsDoTransform (module->cmyk2rgb, cmyk_values, rgb_values, 1);
selector->rgb.r = rgb_values[0];
selector->rgb.g = rgb_values[1];
selector->rgb.b = rgb_values[2];
}
else
{
gimp_cmyk_to_rgb (&module->cmyk, &selector->rgb);
}
gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
gimp_color_selector_color_changed (selector);
}
static cmsHPROFILE
color_config_get_rgb_profile (GimpColorConfig *config)
{
cmsHPROFILE profile = NULL;
if (config->rgb_profile)
profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
return profile ? profile : cmsCreate_sRGBProfile ();
}
static void
colorsel_cmyk_config_changed (ColorselCmyk *module)
{
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
GimpColorConfig *config = module->config;
cmsHPROFILE rgb_profile;
cmsHPROFILE cmyk_profile;
const gchar *name;
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)"));
if (! config || config->mode == GIMP_COLOR_MANAGEMENT_OFF)
goto out;
if (! config->cmyk_profile ||
! (cmyk_profile = cmsOpenProfileFromFile (config->cmyk_profile, "r")))
goto out;
name = cmsTakeProductName (cmyk_profile);
if (! g_utf8_validate (name, -1, NULL))
name = _("(invalid UTF-8 string)");
text = g_strdup_printf (_("Profile: %s"), name);
gtk_label_set_text (GTK_LABEL (module->name_label), text);
g_free (text);
rgb_profile = color_config_get_rgb_profile (config);
module->rgb2cmyk = cmsCreateTransform (rgb_profile, TYPE_RGB_DBL,
cmyk_profile, TYPE_CMYK_DBL,
INTENT_PERCEPTUAL,
0);
module->cmyk2rgb = cmsCreateTransform (cmyk_profile, TYPE_CMYK_DBL,
rgb_profile, TYPE_RGB_DBL,
INTENT_PERCEPTUAL,
0);
cmsCloseProfile (rgb_profile);
cmsCloseProfile (cmyk_profile);
out:
gimp_color_selector_set_color (selector, &selector->rgb, &selector->hsv);
}