gboolean gimp_image_validate_icc_profile (GimpImage *image, const GimpParasite *icc_profile, GError **error) { GimpColorProfile *profile; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (icc_profile != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (strcmp (gimp_parasite_name (icc_profile), GIMP_ICC_PROFILE_PARASITE_NAME) != 0) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("ICC profile validation failed: " "Parasite's name is not 'icc-profile'")); return FALSE; } if (gimp_parasite_flags (icc_profile) != (GIMP_PARASITE_PERSISTENT | GIMP_PARASITE_UNDOABLE)) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("ICC profile validation failed: " "Parasite's flags are not (PERSISTENT | UNDOABLE)")); return FALSE; } if (gimp_image_get_base_type (image) == GIMP_GRAY) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("ICC profile validation failed: " "Cannot attach a color profile to a GRAY image")); return FALSE; } profile = gimp_lcms_profile_open_from_data (gimp_parasite_data (icc_profile), gimp_parasite_data_size (icc_profile), error); if (! profile) { g_prefix_error (error, _("ICC profile validation failed: ")); return FALSE; } if (! gimp_lcms_profile_is_rgb (profile)) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("ICC profile validation failed: " "Color profile is not for RGB color space")); cmsCloseProfile (profile); return FALSE; } cmsCloseProfile (profile); return TRUE; }
static gpointer jpeg_load_cmyk_transform (guint8 *profile_data, gsize profile_len) { GimpColorConfig *config = gimp_get_color_configuration (); GimpColorProfile cmyk_profile = NULL; GimpColorProfile rgb_profile = NULL; cmsUInt32Number flags = 0; cmsHTRANSFORM transform; /* try to load the embedded CMYK profile */ if (profile_data) { cmyk_profile = gimp_lcms_profile_open_from_data (profile_data, profile_len, NULL); if (cmyk_profile && ! gimp_lcms_profile_is_cmyk (cmyk_profile)) { gimp_lcms_profile_close (cmyk_profile); cmyk_profile = NULL; } } /* if that fails, try to load the CMYK profile configured in the prefs */ if (! cmyk_profile) cmyk_profile = gimp_color_config_get_cmyk_profile (config, NULL); /* bail out if we can't load any CMYK profile */ if (! cmyk_profile) { g_object_unref (config); return NULL; } /* try to load the RGB profile configured in the prefs */ rgb_profile = gimp_color_config_get_rgb_profile (config, NULL); /* make the real sRGB profile as a fallback */ if (! rgb_profile) rgb_profile = gimp_lcms_create_srgb_profile (); if (config->display_intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC) { flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } transform = cmsCreateTransform (cmyk_profile, TYPE_CMYK_8_REV, rgb_profile, TYPE_RGB_8, config->display_intent, flags); gimp_lcms_profile_close (cmyk_profile); gimp_lcms_profile_close (rgb_profile); g_object_unref (config); return transform; }
static cmsHPROFILE lcms_image_get_profile (GimpColorConfig *config, gint32 image, GError **error) { GimpParasite *parasite; cmsHPROFILE profile = NULL; g_return_val_if_fail (image != -1, NULL); parasite = gimp_image_get_parasite (image, "icc-profile"); if (parasite) { profile = gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite), gimp_parasite_data_size (parasite), error); if (! profile) g_prefix_error (error, _("Error parsing 'icc-profile': ")); gimp_parasite_free (parasite); } else if (config->rgb_profile) { GFile *file = g_file_new_for_path (config->rgb_profile); profile = gimp_lcms_profile_open_from_file (file, error); if (profile && ! gimp_lcms_profile_is_rgb (profile)) { g_set_error (error, 0, 0, _("Color profile '%s' is not for RGB color space"), gimp_file_get_utf8_name (file)); cmsCloseProfile (profile); profile = NULL; } g_object_unref (file); } return profile; }
/** * gimp_lcms_create_srgb_profile: * * This function is a replacement for cmsCreate_sRGBProfile() and * returns an sRGB profile that is functionally the same as the * ArgyllCMS sRGB.icm profile. "Functionally the same" means it has * the same red, green, and blue colorants and the V4 "chad" * equivalent of the ArgyllCMS V2 white point. The profile TRC is also * functionally equivalent to the ArgyllCMS sRGB.icm TRC and is the * same as the LCMS sRGB built-in profile TRC. * * The actual primaries in the sRGB specification are * red xy: {0.6400, 0.3300, 1.0} * green xy: {0.3000, 0.6000, 1.0} * blue xy: {0.1500, 0.0600, 1.0} * * The sRGB primaries given below are "pre-quantized" to compensate * for hexadecimal quantization during the profile-making process. * Unless the profile-making code compensates for this quantization, * the resulting profile's red, green, and blue colorants will deviate * slightly from the correct XYZ values. * * LCMS2 doesn't compensate for hexadecimal quantization. The * "pre-quantized" primaries below were back-calculated from the * ArgyllCMS sRGB.icm profile. The resulting sRGB profile's colorants * exactly matches the ArgyllCMS sRGB.icm profile colorants. * * Return value: the sRGB cmsHPROFILE. * * Since: GIMP 2.10 **/ GimpColorProfile gimp_lcms_create_srgb_profile (void) { static guint8 *profile_data = NULL; static gsize profile_length = 0; if (G_UNLIKELY (profile_data == NULL)) { GimpColorProfile profile; profile = gimp_lcms_create_srgb_profile_internal (); profile_data = gimp_lcms_profile_save_to_data (profile, &profile_length, NULL); cmsCloseProfile (profile); } return gimp_lcms_profile_open_from_data (profile_data, profile_length, NULL); }
GimpColorProfile gimp_image_get_profile (GimpImage *image, GError **error) { GimpColorConfig *config; const GimpParasite *parasite; GimpColorProfile *profile = NULL; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); config = image->gimp->config->color_management; parasite = gimp_image_get_icc_profile (image); if (parasite) { return gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite), gimp_parasite_data_size (parasite), error); } else if (config->rgb_profile) { profile = gimp_lcms_profile_open_from_file (config->rgb_profile, error); if (profile && ! gimp_lcms_profile_is_rgb (profile)) { g_set_error (error, GIMP_ERROR, GIMP_FAILED, _("Color profile '%s' is not for RGB color space"), gimp_filename_to_utf8 (config->rgb_profile)); cmsCloseProfile (profile); profile = NULL; } } return profile; }