/** * gimp_color_profile_new_srgb: * * 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 #GimpColorProfile. * * Since: 2.10 **/ GimpColorProfile * gimp_color_profile_new_srgb (void) { static GimpColorProfile *profile = NULL; const guint8 *data; gsize length; if (G_UNLIKELY (profile == NULL)) { cmsHPROFILE lcms_profile = gimp_color_profile_new_srgb_internal (); profile = gimp_color_profile_new_from_lcms_profile (lcms_profile, NULL); cmsCloseProfile (lcms_profile); #if 0 /* for testing the code to get the colorants and make a new profile */ { GimpMatrix3 matrix; if (gimp_color_profile_get_rgb_matrix_colorants (profile, &matrix)) { GimpColorProfile *test; g_printerr ("Profile Red colorant XYZ: %1.8f, %1.8f, %1.8f \n", matrix.coeff[0][0], matrix.coeff[0][1], matrix.coeff[0][2]); g_printerr ("Profile Green colorant XYZ: %1.8f, %1.8f, %1.8f \n", matrix.coeff[1][0], matrix.coeff[1][1], matrix.coeff[1][2]); g_printerr ("Profile Blue colorant XYZ: %1.8f, %1.8f, %1.8f \n", matrix.coeff[2][0], matrix.coeff[2][1], matrix.coeff[2][2]); test = gimp_color_profile_new_foobar (profile); g_object_unref (test); } } #endif } data = gimp_color_profile_get_icc_profile (profile, &length); return gimp_color_profile_new_from_icc_profile (data, length, NULL); }
static GimpColorProfile * gimp_color_profile_new_from_color_profile (GimpColorProfile *profile, gboolean linear) { GimpColorProfile *new_profile; cmsHPROFILE target_profile; GimpMatrix3 matrix = { 0, }; cmsCIEXYZ *whitepoint; cmsToneCurve *curve; const gchar *model; gchar *new_model; g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL); if (gimp_color_profile_is_rgb (profile)) { if (! gimp_color_profile_get_rgb_matrix_colorants (profile, &matrix)) return NULL; } else if (! gimp_color_profile_is_gray (profile)) { return NULL; } whitepoint = cmsReadTag (profile->priv->lcms_profile, cmsSigMediaWhitePointTag); target_profile = cmsCreateProfilePlaceholder (0); cmsSetProfileVersion (target_profile, 4.3); cmsSetDeviceClass (target_profile, cmsSigDisplayClass); cmsSetPCS (target_profile, cmsSigXYZData); cmsWriteTag (target_profile, cmsSigMediaWhitePointTag, whitepoint); if (linear) { /* linear light */ curve = cmsBuildGamma (NULL, 1.00); gimp_color_profile_set_tag (target_profile, cmsSigProfileDescriptionTag, "linear TRC variant generated by GIMP"); } else { cmsFloat64Number srgb_parameters[5] = { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; /* sRGB curve */ curve = cmsBuildParametricToneCurve (NULL, 4, srgb_parameters); gimp_color_profile_set_tag (target_profile, cmsSigProfileDescriptionTag, "sRGB TRC variant generated by GIMP"); } if (gimp_color_profile_is_rgb (profile)) { cmsCIEXYZ red; cmsCIEXYZ green; cmsCIEXYZ blue; cmsSetColorSpace (target_profile, cmsSigRgbData); red.X = matrix.coeff[0][0]; red.Y = matrix.coeff[0][1]; red.Z = matrix.coeff[0][2]; green.X = matrix.coeff[1][0]; green.Y = matrix.coeff[1][1]; green.Z = matrix.coeff[1][2]; blue.X = matrix.coeff[2][0]; blue.Y = matrix.coeff[2][1]; blue.Z = matrix.coeff[2][2]; cmsWriteTag (target_profile, cmsSigRedColorantTag, &red); cmsWriteTag (target_profile, cmsSigGreenColorantTag, &green); cmsWriteTag (target_profile, cmsSigBlueColorantTag, &blue); cmsWriteTag (target_profile, cmsSigRedTRCTag, curve); cmsWriteTag (target_profile, cmsSigGreenTRCTag, curve); cmsWriteTag (target_profile, cmsSigBlueTRCTag, curve); } else { cmsSetColorSpace (target_profile, cmsSigGrayData); cmsWriteTag (target_profile, cmsSigGrayTRCTag, curve); } cmsFreeToneCurve (curve); model = gimp_color_profile_get_model (profile); if (model && g_str_has_prefix (model, "Generated from '")) { /* don't add multiple "Generated from 'foo'" */ new_model = g_strdup (model); } else { new_model = g_strdup_printf ("Generated from '%s'", gimp_color_profile_get_description (profile)); } gimp_color_profile_set_tag (target_profile, cmsSigDeviceMfgDescTag, "GIMP"); gimp_color_profile_set_tag (target_profile, cmsSigDeviceModelDescTag, new_model); gimp_color_profile_set_tag (target_profile, cmsSigCopyrightTag, "Public Domain"); g_free (new_model); new_profile = gimp_color_profile_new_from_lcms_profile (target_profile, NULL); cmsCloseProfile (target_profile); return new_profile; }