diff --git a/ChangeLog b/ChangeLog index 885d3e663e..e4e5d290d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2006-09-26 Sven Neumann + + * 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 * plug-ins/uri/uri-backend-libcurl.c: while downloading, use the diff --git a/app/dialogs/grid-dialog.c b/app/dialogs/grid-dialog.c index 23accb3739..65f4b2e889 100644 --- a/app/dialogs/grid-dialog.c +++ b/app/dialogs/grid-dialog.c @@ -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); diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c index 1aef3bad40..c7e3ed16dd 100644 --- a/app/dialogs/preferences-dialog.c +++ b/app/dialogs/preferences-dialog.c @@ -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); diff --git a/app/widgets/gimpcolordialog.c b/app/widgets/gimpcolordialog.c index d57829e069..5b4693301e 100644 --- a/app/widgets/gimpcolordialog.c +++ b/app/widgets/gimpcolordialog.c @@ -23,10 +23,14 @@ #include #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), diff --git a/app/widgets/gimpcoloreditor.c b/app/widgets/gimpcoloreditor.c index 948bdb6d95..d4030d49be 100644 --- a/app/widgets/gimpcoloreditor.c +++ b/app/widgets/gimpcoloreditor.c @@ -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); diff --git a/app/widgets/gimpcolorpanel.c b/app/widgets/gimpcolorpanel.c index b53b98f270..e13ee944bb 100644 --- a/app/widgets/gimpcolorpanel.c +++ b/app/widgets/gimpcolorpanel.c @@ -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), diff --git a/app/widgets/gimpgrideditor.c b/app/widgets/gimpgrideditor.c index 4ab2cee556..1c8390091b 100644 --- a/app/widgets/gimpgrideditor.c +++ b/app/widgets/gimpgrideditor.c @@ -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); diff --git a/app/widgets/gimpgrideditor.h b/app/widgets/gimpgrideditor.h index 1e14d16228..b389c89a56 100644 --- a/app/widgets/gimpgrideditor.h +++ b/app/widgets/gimpgrideditor.h @@ -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__ */ diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c index 47f8912827..24b9fd3482 100644 --- a/app/widgets/gimppropwidgets.c +++ b/app/widgets/gimppropwidgets.c @@ -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); diff --git a/app/widgets/gimptoolbox-color-area.c b/app/widgets/gimptoolbox-color-area.c index 92d8d027e9..b3ee16d88f 100644 --- a/app/widgets/gimptoolbox-color-area.c +++ b/app/widgets/gimptoolbox-color-area.c @@ -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", diff --git a/libgimpwidgets/gimpcolornotebook.c b/libgimpwidgets/gimpcolornotebook.c index dcf19b5c68..7f9c3f0cb2 100644 --- a/libgimpwidgets/gimpcolornotebook.c +++ b/libgimpwidgets/gimpcolornotebook.c @@ -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, diff --git a/libgimpwidgets/gimpcolorselection.c b/libgimpwidgets/gimpcolorselection.c index 04145bc4ed..11cbb482b9 100644 --- a/libgimpwidgets/gimpcolorselection.c +++ b/libgimpwidgets/gimpcolorselection.c @@ -25,6 +25,7 @@ #include #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 */ diff --git a/libgimpwidgets/gimpcolorselection.h b/libgimpwidgets/gimpcolorselection.h index 8c74e936ed..aa11a0df4f 100644 --- a/libgimpwidgets/gimpcolorselection.h +++ b/libgimpwidgets/gimpcolorselection.h @@ -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 diff --git a/libgimpwidgets/gimpcolorselector.c b/libgimpwidgets/gimpcolorselector.c index 2a6489dbe5..a0765f9d15 100644 --- a/libgimpwidgets/gimpcolorselector.c +++ b/libgimpwidgets/gimpcolorselector.c @@ -29,6 +29,7 @@ #include #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); +} diff --git a/libgimpwidgets/gimpcolorselector.h b/libgimpwidgets/gimpcolorselector.h index d965115c0b..44e04e0e8f 100644 --- a/libgimpwidgets/gimpcolorselector.h +++ b/libgimpwidgets/gimpcolorselector.h @@ -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 diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def index 77cbacc4d0..2192125884 100644 --- a/libgimpwidgets/gimpwidgets.def +++ b/libgimpwidgets/gimpwidgets.def @@ -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 diff --git a/libgimpwidgets/gimpwidgetstypes.h b/libgimpwidgets/gimpwidgetstypes.h index dc3dcc4183..91de1d8441 100644 --- a/libgimpwidgets/gimpwidgetstypes.h +++ b/libgimpwidgets/gimpwidgetstypes.h @@ -22,7 +22,7 @@ #ifndef __GIMP_WIDGETS_TYPES_H__ #define __GIMP_WIDGETS_TYPES_H__ -#include +#include #include diff --git a/modules/Makefile.am b/modules/Makefile.am index 2a5054200b..4bcc75047a 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -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) diff --git a/modules/cdisplay_lcms.c b/modules/cdisplay_lcms.c index e3f8db8981..adb1c85b8b 100644 --- a/modules/cdisplay_lcms.c +++ b/modules/cdisplay_lcms.c @@ -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 diff --git a/modules/colorsel_cmyk_lcms.c b/modules/colorsel_cmyk_lcms.c new file mode 100644 index 0000000000..2401898539 --- /dev/null +++ b/modules/colorsel_cmyk_lcms.c @@ -0,0 +1,423 @@ +/* GIMP CMYK ColorSelector using littleCMS + * Copyright (C) 2006 Sven Neumann + * + * 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 /* lcms.h uses the "inline" keyword */ + +#ifdef HAVE_LCMS_LCMS_H +#include +#else +#include +#endif + +#include + +#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 ", + "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); +}