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.
This commit is contained in:
@ -54,6 +54,7 @@ AM_CPPFLAGS = \
|
|||||||
-I$(top_srcdir) \
|
-I$(top_srcdir) \
|
||||||
$(GEGL_CFLAGS) \
|
$(GEGL_CFLAGS) \
|
||||||
$(GTK_CFLAGS) \
|
$(GTK_CFLAGS) \
|
||||||
|
$(LCMS_CFLAGS) \
|
||||||
-I$(includedir)
|
-I$(includedir)
|
||||||
|
|
||||||
lib_LTLIBRARIES = libgimpwidgets-@GIMP_API_VERSION@.la
|
lib_LTLIBRARIES = libgimpwidgets-@GIMP_API_VERSION@.la
|
||||||
@ -272,6 +273,7 @@ libgimpwidgets_@GIMP_API_VERSION@_la_LIBADD = \
|
|||||||
$(libgimpconfig) \
|
$(libgimpconfig) \
|
||||||
$(GEGL_LIBS) \
|
$(GEGL_LIBS) \
|
||||||
$(GTK_LIBS) \
|
$(GTK_LIBS) \
|
||||||
|
$(LCMS_LIBS) \
|
||||||
$(libm)
|
$(libm)
|
||||||
|
|
||||||
|
|
||||||
|
@ -402,6 +402,7 @@ EXPORTS
|
|||||||
gimp_unit_store_set_resolution
|
gimp_unit_store_set_resolution
|
||||||
gimp_unit_store_set_resolutions
|
gimp_unit_store_set_resolutions
|
||||||
gimp_widget_get_color_profile
|
gimp_widget_get_color_profile
|
||||||
|
gimp_widget_get_color_transform
|
||||||
gimp_widget_get_monitor
|
gimp_widget_get_monitor
|
||||||
gimp_widgets_error_quark
|
gimp_widgets_error_quark
|
||||||
gimp_widgets_init
|
gimp_widgets_init
|
||||||
|
@ -31,10 +31,13 @@
|
|||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <lcms2.h>
|
||||||
|
|
||||||
#include <gegl.h>
|
#include <gegl.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "libgimpcolor/gimpcolor.h"
|
#include "libgimpcolor/gimpcolor.h"
|
||||||
|
#include "libgimpconfig/gimpconfig.h"
|
||||||
|
|
||||||
#include "gimpwidgetstypes.h"
|
#include "gimpwidgetstypes.h"
|
||||||
|
|
||||||
@ -455,3 +458,154 @@ gimp_widget_get_color_profile (GtkWidget *widget)
|
|||||||
|
|
||||||
return profile;
|
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;
|
||||||
|
}
|
||||||
|
@ -30,23 +30,29 @@ G_BEGIN_DECLS
|
|||||||
/* For information look into the C source or the html documentation */
|
/* For information look into the C source or the html documentation */
|
||||||
|
|
||||||
|
|
||||||
GtkWidget * gimp_table_attach_aligned (GtkTable *table,
|
GtkWidget * gimp_table_attach_aligned (GtkTable *table,
|
||||||
gint column,
|
gint column,
|
||||||
gint row,
|
gint row,
|
||||||
const gchar *label_text,
|
const gchar *label_text,
|
||||||
gfloat xalign,
|
gfloat xalign,
|
||||||
gfloat yalign,
|
gfloat yalign,
|
||||||
GtkWidget *widget,
|
GtkWidget *widget,
|
||||||
gint colspan,
|
gint colspan,
|
||||||
gboolean left_align);
|
gboolean left_align);
|
||||||
|
|
||||||
void gimp_label_set_attributes (GtkLabel *label,
|
void gimp_label_set_attributes (GtkLabel *label,
|
||||||
...);
|
...);
|
||||||
|
|
||||||
gint gimp_widget_get_monitor (GtkWidget *widget);
|
gint gimp_widget_get_monitor (GtkWidget *widget);
|
||||||
gint gimp_get_monitor_at_pointer (GdkScreen **screen);
|
gint gimp_get_monitor_at_pointer (GdkScreen **screen);
|
||||||
|
|
||||||
GimpColorProfile gimp_widget_get_color_profile (GtkWidget *widget);
|
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
|
G_END_DECLS
|
||||||
|
Reference in New Issue
Block a user