[gimp] libgimpwidgets: add gimp_widget_get_color_transform()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpwidgets: add gimp_widget_get_color_transform()
- Date: Fri, 8 May 2015 23:23:37 +0000 (UTC)
commit f21f6e5a28fd087f23ca9351f1c99635098b6f36
Author: Michael Natterer <mitch gimp org>
Date: Sat May 9 01:20:50 2015 +0200
libgimpwidgets: add gimp_widget_get_color_transform()
Which returns a GimpColorTransform to transform a GimpColorManaged's
pixels to a GtkWidget's color space, using a GimpColorConfig's
settings. This is *unfinished* API and in the end will enable simple
display color management for the app, libgimp and plug-ins.
libgimpwidgets/Makefile.am | 2 +
libgimpwidgets/gimpwidgets.def | 1 +
libgimpwidgets/gimpwidgetsutils.c | 154 +++++++++++++++++++++++++++++++++++++
libgimpwidgets/gimpwidgetsutils.h | 40 ++++++----
4 files changed, 180 insertions(+), 17 deletions(-)
---
diff --git a/libgimpwidgets/Makefile.am b/libgimpwidgets/Makefile.am
index 3c0091c..c5357b4 100644
--- a/libgimpwidgets/Makefile.am
+++ b/libgimpwidgets/Makefile.am
@@ -54,6 +54,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir) \
$(GEGL_CFLAGS) \
$(GTK_CFLAGS) \
+ $(LCMS_CFLAGS) \
-I$(includedir)
lib_LTLIBRARIES = libgimpwidgets- GIMP_API_VERSION@.la
@@ -272,6 +273,7 @@ libgimpwidgets_ GIMP_API_VERSION@_la_LIBADD = \
$(libgimpconfig) \
$(GEGL_LIBS) \
$(GTK_LIBS) \
+ $(LCMS_LIBS) \
$(libm)
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index ca2a342..0ed3842 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -402,6 +402,7 @@ EXPORTS
gimp_unit_store_set_resolution
gimp_unit_store_set_resolutions
gimp_widget_get_color_profile
+ gimp_widget_get_color_transform
gimp_widget_get_monitor
gimp_widgets_error_quark
gimp_widgets_init
diff --git a/libgimpwidgets/gimpwidgetsutils.c b/libgimpwidgets/gimpwidgetsutils.c
index 4704918..988cdbe 100644
--- a/libgimpwidgets/gimpwidgetsutils.c
+++ b/libgimpwidgets/gimpwidgetsutils.c
@@ -31,10 +31,13 @@
#include <CoreServices/CoreServices.h>
#endif
+#include <lcms2.h>
+
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
+#include "libgimpconfig/gimpconfig.h"
#include "gimpwidgetstypes.h"
@@ -455,3 +458,154 @@ gimp_widget_get_color_profile (GtkWidget *widget)
return profile;
}
+
+static GimpColorProfile
+get_rgb_profile (GimpColorManaged *managed,
+ GimpColorConfig *config)
+{
+ GimpColorProfile profile = NULL;
+ const guint8 *data;
+ gsize len;
+
+ data = gimp_color_managed_get_icc_profile (managed, &len);
+
+ if (data)
+ profile = gimp_lcms_profile_open_from_data (data, len, NULL);
+
+ if (profile && ! gimp_lcms_profile_is_rgb (profile))
+ {
+ gimp_lcms_profile_close (profile);
+ profile = NULL;
+ }
+
+ if (! profile)
+ profile = gimp_color_config_get_rgb_profile (config, NULL);
+
+ return profile;
+}
+
+static GimpColorProfile
+get_display_profile (GtkWidget *widget,
+ GimpColorConfig *config)
+{
+ GimpColorProfile profile;
+
+ profile = gimp_widget_get_color_profile (widget);
+
+ if (! profile)
+ profile = gimp_color_config_get_display_profile (config, NULL);
+
+ return profile;
+}
+
+GimpColorTransform
+gimp_widget_get_color_transform (GtkWidget *widget,
+ GimpColorManaged *managed,
+ GimpColorConfig *config,
+ const Babl *src_format,
+ const Babl *dest_format)
+{
+ GimpColorTransform transform = NULL;
+ GimpColorProfile src_profile = NULL;
+ GimpColorProfile dest_profile = NULL;
+ GimpColorProfile proof_profile = NULL;
+ cmsUInt32Number lcms_src_format;
+ cmsUInt32Number lcms_dest_format;
+ cmsUInt16Number alarmCodes[cmsMAXCHANNELS] = { 0, };
+
+ g_return_val_if_fail (widget == NULL || GTK_IS_WIDGET (widget), NULL);
+ g_return_val_if_fail (GIMP_IS_COLOR_MANAGED (managed), NULL);
+ g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
+ g_return_val_if_fail (src_format != NULL, NULL);
+ g_return_val_if_fail (dest_format != NULL, NULL);
+
+ switch (config->mode)
+ {
+ case GIMP_COLOR_MANAGEMENT_OFF:
+ return NULL;
+
+ case GIMP_COLOR_MANAGEMENT_SOFTPROOF:
+ proof_profile = gimp_color_config_get_printer_profile (config, NULL);
+ /* fallthru */
+
+ case GIMP_COLOR_MANAGEMENT_DISPLAY:
+ src_profile = get_rgb_profile (managed, config);
+ dest_profile = get_display_profile (widget, config);
+ break;
+ }
+
+ src_format = gimp_lcms_get_format (src_format, &lcms_src_format);
+ dest_format = gimp_lcms_get_format (dest_format, &lcms_dest_format);
+
+ if (proof_profile)
+ {
+ cmsUInt32Number softproof_flags = 0;
+
+ if (! src_profile)
+ src_profile = gimp_lcms_create_srgb_profile ();
+
+ if (! dest_profile)
+ dest_profile = gimp_lcms_create_srgb_profile ();
+
+ softproof_flags |= cmsFLAGS_SOFTPROOFING;
+
+ if (config->simulation_use_black_point_compensation)
+ {
+ softproof_flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
+ }
+
+ if (config->simulation_gamut_check)
+ {
+ guchar r, g, b;
+
+ softproof_flags |= cmsFLAGS_GAMUTCHECK;
+
+ gimp_rgb_get_uchar (&config->out_of_gamut_color, &r, &g, &b);
+
+ alarmCodes[0] = (cmsUInt16Number) r * 256;
+ alarmCodes[1] = (cmsUInt16Number) g * 256;
+ alarmCodes[2] = (cmsUInt16Number) b * 256;
+
+ cmsSetAlarmCodes (alarmCodes);
+ }
+
+ transform =
+ cmsCreateProofingTransform (src_profile, lcms_src_format,
+ dest_profile, lcms_dest_format,
+ proof_profile,
+ config->simulation_intent,
+ config->display_intent,
+ softproof_flags);
+
+ gimp_lcms_profile_close (proof_profile);
+ }
+ else if (src_profile || dest_profile)
+ {
+ cmsUInt32Number display_flags = 0;
+
+ if (! src_profile)
+ src_profile = gimp_lcms_create_srgb_profile ();
+
+ if (! dest_profile)
+ dest_profile = gimp_lcms_create_srgb_profile ();
+
+ if (config->display_use_black_point_compensation)
+ {
+ display_flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
+ }
+
+ transform =
+ cmsCreateTransform (src_profile, lcms_src_format,
+ dest_profile, lcms_dest_format,
+ config->display_intent,
+ display_flags);
+ }
+
+ if (src_profile)
+ gimp_lcms_profile_close (src_profile);
+
+ if (dest_profile)
+ gimp_lcms_profile_close (dest_profile);
+
+ return transform;
+}
diff --git a/libgimpwidgets/gimpwidgetsutils.h b/libgimpwidgets/gimpwidgetsutils.h
index c57cc35..db97121 100644
--- a/libgimpwidgets/gimpwidgetsutils.h
+++ b/libgimpwidgets/gimpwidgetsutils.h
@@ -30,23 +30,29 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
-GtkWidget * gimp_table_attach_aligned (GtkTable *table,
- gint column,
- gint row,
- const gchar *label_text,
- gfloat xalign,
- gfloat yalign,
- GtkWidget *widget,
- gint colspan,
- gboolean left_align);
-
-void gimp_label_set_attributes (GtkLabel *label,
- ...);
-
-gint gimp_widget_get_monitor (GtkWidget *widget);
-gint gimp_get_monitor_at_pointer (GdkScreen **screen);
-
-GimpColorProfile gimp_widget_get_color_profile (GtkWidget *widget);
+GtkWidget * gimp_table_attach_aligned (GtkTable *table,
+ gint column,
+ gint row,
+ const gchar *label_text,
+ gfloat xalign,
+ gfloat yalign,
+ GtkWidget *widget,
+ gint colspan,
+ gboolean left_align);
+
+void gimp_label_set_attributes (GtkLabel *label,
+ ...);
+
+gint gimp_widget_get_monitor (GtkWidget *widget);
+gint gimp_get_monitor_at_pointer (GdkScreen **screen);
+
+GimpColorProfile gimp_widget_get_color_profile (GtkWidget *widget);
+
+GimpColorTransform gimp_widget_get_color_transform (GtkWidget *widget,
+ GimpColorManaged *managed,
+ GimpColorConfig *config,
+ const Babl *src_format,
+ const Babl *dest_format);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]