[gimp] Bug 756389 - Color-managing grayscale images
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 756389 - Color-managing grayscale images
- Date: Sun, 13 Dec 2015 18:44:37 +0000 (UTC)
commit b54a8d19399fb9035501ca81051c15d038f1f6f3
Author: Michael Natterer <mitch gimp org>
Date: Sun Dec 13 19:43:02 2015 +0100
Bug 756389 - Color-managing grayscale images
Add gimp_color_profile_new_srgb_gray() and
gimp_color_profile_new_linear_gray().
I know "srgb_gray" sounds odd but it's better than
"gray_with_srgb_trc"...
Please review, I have no clue if that code is right.
libgimpcolor/gimpcolor.def | 2 +
libgimpcolor/gimpcolorprofile.c | 148 +++++++++++++++++++++++++++++++-------
libgimpcolor/gimpcolorprofile.h | 4 +-
3 files changed, 125 insertions(+), 29 deletions(-)
---
diff --git a/libgimpcolor/gimpcolor.def b/libgimpcolor/gimpcolor.def
index 9f4dc8c..1b1e384 100644
--- a/libgimpcolor/gimpcolor.def
+++ b/libgimpcolor/gimpcolor.def
@@ -44,9 +44,11 @@ EXPORTS
gimp_color_profile_new_from_file
gimp_color_profile_new_from_icc_profile
gimp_color_profile_new_from_lcms_profile
+ gimp_color_profile_new_linear_gray
gimp_color_profile_new_linear_rgb
gimp_color_profile_new_linear_rgb_from_color_profile
gimp_color_profile_new_srgb
+ gimp_color_profile_new_srgb_gray
gimp_color_profile_new_srgb_gamma_from_color_profile
gimp_hsl_get_type
gimp_hsl_set
diff --git a/libgimpcolor/gimpcolorprofile.c b/libgimpcolor/gimpcolorprofile.c
index fd8b4fe..c60f7d5 100644
--- a/libgimpcolor/gimpcolorprofile.c
+++ b/libgimpcolor/gimpcolorprofile.c
@@ -1028,34 +1028,6 @@ gimp_color_profile_new_srgb (void)
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);
@@ -1217,6 +1189,126 @@ gimp_color_profile_new_adobe_rgb (void)
return gimp_color_profile_new_from_icc_profile (data, length, NULL);
}
+static cmsHPROFILE *
+gimp_color_profile_new_srgb_gray_internal (void)
+{
+ cmsHPROFILE profile;
+
+ /* white point is D65 from the sRGB specs */
+ cmsCIExyY whitepoint = { 0.3127, 0.3290, 1.0 };
+
+ cmsFloat64Number srgb_parameters[5] =
+ { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
+
+ cmsToneCurve *curve = cmsBuildParametricToneCurve (NULL, 4,
+ srgb_parameters);
+
+ profile = cmsCreateGrayProfile (&whitepoint, curve);
+
+ cmsFreeToneCurve (curve);
+
+ gimp_color_profile_set_tag (profile, cmsSigProfileDescriptionTag,
+ "GIMP built-in sRGB-Gamma Grayscale");
+ gimp_color_profile_set_tag (profile, cmsSigDeviceMfgDescTag,
+ "GIMP");
+ gimp_color_profile_set_tag (profile, cmsSigDeviceModelDescTag,
+ "sRGB-Gamma Grayscale");
+ gimp_color_profile_set_tag (profile, cmsSigCopyrightTag,
+ "Public Domain");
+
+ return profile;
+}
+
+/**
+ * gimp_color_profile_new_srgb_gray
+ *
+ * This function creates a grayscale #GimpColorProfile with an
+ * sRGB TRC. See gimp_color_profile_new_srgb().
+ *
+ * Return value: the sRGB-gamma grayscale #GimpColorProfile.
+ *
+ * Since: 2.10
+ **/
+GimpColorProfile *
+gimp_color_profile_new_srgb_gray (void)
+{
+ static GimpColorProfile *profile = NULL;
+
+ const guint8 *data;
+ gsize length;
+
+ if (G_UNLIKELY (profile == NULL))
+ {
+ cmsHPROFILE lcms_profile = gimp_color_profile_new_srgb_gray_internal ();
+
+ profile = gimp_color_profile_new_from_lcms_profile (lcms_profile, NULL);
+
+ cmsCloseProfile (lcms_profile);
+ }
+
+ data = gimp_color_profile_get_icc_profile (profile, &length);
+
+ return gimp_color_profile_new_from_icc_profile (data, length, NULL);
+}
+
+static cmsHPROFILE
+gimp_color_profile_new_linear_gray_internal (void)
+{
+ cmsHPROFILE profile;
+
+ /* white point is D65 from the sRGB specs */
+ cmsCIExyY whitepoint = { 0.3127, 0.3290, 1.0 };
+
+ cmsToneCurve *curve = cmsBuildGamma (NULL, 1.0);
+
+ profile = cmsCreateGrayProfile (&whitepoint, curve);
+
+ cmsFreeToneCurve (curve);
+
+ gimp_color_profile_set_tag (profile, cmsSigProfileDescriptionTag,
+ "GIMP built-in Linear Grayscale");
+ gimp_color_profile_set_tag (profile, cmsSigDeviceMfgDescTag,
+ "GIMP");
+ gimp_color_profile_set_tag (profile, cmsSigDeviceModelDescTag,
+ "Linear Grayscale");
+ gimp_color_profile_set_tag (profile, cmsSigCopyrightTag,
+ "Public Domain");
+
+ return profile;
+}
+
+/**
+ * gimp_color_profile_new_linear_gray:
+ *
+ * This function creates a profile for babl_model("Y"). Please
+ * somebody write someting smarter here.
+ *
+ * Return value: the linear grayscale #GimpColorProfile.
+ *
+ * Since: 2.10
+ **/
+GimpColorProfile *
+gimp_color_profile_new_linear_gray (void)
+{
+ static GimpColorProfile *profile = NULL;
+
+ const guint8 *data;
+ gsize length;
+
+ if (G_UNLIKELY (profile == NULL))
+ {
+ cmsHPROFILE lcms_profile = gimp_color_profile_new_linear_gray_internal ();
+
+ profile = gimp_color_profile_new_from_lcms_profile (lcms_profile, NULL);
+
+ cmsCloseProfile (lcms_profile);
+ }
+
+ data = gimp_color_profile_get_icc_profile (profile, &length);
+
+ return gimp_color_profile_new_from_icc_profile (data, length, NULL);
+}
+
/**
* gimp_color_profile_get_format:
* @format: a #Babl format
diff --git a/libgimpcolor/gimpcolorprofile.h b/libgimpcolor/gimpcolorprofile.h
index ec3b22d..34ebea4 100644
--- a/libgimpcolor/gimpcolorprofile.h
+++ b/libgimpcolor/gimpcolorprofile.h
@@ -66,9 +66,11 @@ GType gimp_color_profile_get_type (void) G_GNUC_CONST;
GimpColorProfile * gimp_color_profile_new_srgb (void);
GimpColorProfile * gimp_color_profile_new_linear_rgb (void);
-
GimpColorProfile * gimp_color_profile_new_adobe_rgb (void);
+GimpColorProfile * gimp_color_profile_new_srgb_gray (void);
+GimpColorProfile * gimp_color_profile_new_linear_gray (void);
+
GimpColorProfile *
gimp_color_profile_new_srgb_gamma_from_color_profile (GimpColorProfile *profile);
GimpColorProfile *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]