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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user