diff options
author | Benjamin Otte <otte@redhat.com> | 2021-10-25 22:55:34 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2021-10-28 03:41:09 +0200 |
commit | abbd7f0c92e35ebf2001c15e75519ad524a079c8 (patch) | |
tree | 3c1c4b41e14de01156c32e49d50d873bb9160bad | |
parent | c70a8def57de758d6a156e6fe71847017ad845a6 (diff) | |
download | gtk+-abbd7f0c92e35ebf2001c15e75519ad524a079c8.tar.gz |
colorspace: Add gdk_color_space_get_named ()wip/otte/colorspace
And add a bunch of common color spaces
-rw-r--r-- | gdk/gdkcolorspace.c | 83 | ||||
-rw-r--r-- | gdk/gdkcolorspace.h | 2 | ||||
-rw-r--r-- | gdk/gdkenums.h | 44 |
3 files changed, 129 insertions, 0 deletions
diff --git a/gdk/gdkcolorspace.c b/gdk/gdkcolorspace.c index 4f8d9a74af..08065b9fd8 100644 --- a/gdk/gdkcolorspace.c +++ b/gdk/gdkcolorspace.c @@ -159,6 +159,89 @@ gdk_color_space_get_srgb (void) return srgb_profile; } +GdkColorSpace * +gdk_color_space_get_named (GdkNamedColorSpace name) +{ + static GdkColorSpace *space_array[GDK_NAMED_COLOR_SPACE_N_SPACES]; + static GdkColorSpace **color_spaces; + + g_return_val_if_fail (name < GDK_NAMED_COLOR_SPACE_N_SPACES, gdk_color_space_get_srgb ()); + + if (g_once_init_enter (&color_spaces)) + { + static const cmsCIExyY D65 = { 0.3127, 0.3290, 1.0 }; + static const cmsFloat64Number srgb_tonecurve[5] = { 2.4, 1. / 1.055, 0.055 / 1.055, 1. / 12.92, 0.04045 }; + static const cmsFloat64Number rec709_tonecurve[5] = { 1.0 / 0.45, 1.0 / 1.099, 0.099 / 1.099, 1.0 / 4.5, 0.081 }; + cmsToneCurve *curve; + cmsHPROFILE lcms_profile; + + space_array[GDK_NAMED_COLOR_SPACE_SRGB] = g_object_ref (gdk_color_space_get_srgb ()); + + curve = cmsBuildGamma (NULL, 1.0); + lcms_profile = cmsCreateRGBProfile (&D65, + &(cmsCIExyYTRIPLE) { + { 0.640, 0.330, 1.0 }, + { 0.300, 0.600, 1.0 }, + { 0.150, 0.060, 1.0 } + }, + (cmsToneCurve*[3]) { curve, curve, curve }); + cmsFreeToneCurve (curve); + space_array[GDK_NAMED_COLOR_SPACE_SRGB_LINEAR] = gdk_lcms_color_space_new_from_lcms_profile (lcms_profile); + + space_array[GDK_NAMED_COLOR_SPACE_XYZ_D50] = gdk_lcms_color_space_new_from_lcms_profile (cmsCreateXYZProfile ()); + /* XXX: This needs a D65 whitepoint here */ + space_array[GDK_NAMED_COLOR_SPACE_XYZ_D65] = gdk_lcms_color_space_new_from_lcms_profile (cmsCreateXYZProfile ()); + + curve = cmsBuildParametricToneCurve (NULL, 4, srgb_tonecurve); + lcms_profile = cmsCreateRGBProfile (&D65, + &(cmsCIExyYTRIPLE) { + { 0.680, 0.320, 1.0 }, + { 0.265, 0.690, 1.0 }, + { 0.150, 0.060, 1.0 } + }, + (cmsToneCurve*[3]) { curve, curve, curve }); + cmsFreeToneCurve (curve); + space_array[GDK_NAMED_COLOR_SPACE_DISPLAY_P3] = gdk_lcms_color_space_new_from_lcms_profile (lcms_profile); + + curve = cmsBuildGamma(NULL, 2.19921875); + lcms_profile = cmsCreateRGBProfile (&D65, + &(cmsCIExyYTRIPLE) { + { 0.640, 0.330, 1.0 }, + { 0.210, 0.710, 1.0 }, + { 0.150, 0.060, 1.0 } + }, + (cmsToneCurve*[3]) { curve, curve, curve }); + cmsFreeToneCurve (curve); + space_array[GDK_NAMED_COLOR_SPACE_A98_RGB] = gdk_lcms_color_space_new_from_lcms_profile (lcms_profile); + + curve = cmsBuildParametricToneCurve (NULL, 4, rec709_tonecurve); + lcms_profile = cmsCreateRGBProfile (cmsD50_xyY (), + &(cmsCIExyYTRIPLE) { + { 0.734699, 0.265301, 1.0 }, + { 0.159597, 0.840403, 1.0 }, + { 0.036598, 0.000105, 1.0 } + }, + (cmsToneCurve*[3]) { curve, curve, curve }); + cmsFreeToneCurve (curve); + space_array[GDK_NAMED_COLOR_SPACE_PROPHOTO_RGB] = gdk_lcms_color_space_new_from_lcms_profile (lcms_profile); + + curve = cmsBuildParametricToneCurve (NULL, 4, rec709_tonecurve); + lcms_profile = cmsCreateRGBProfile (&D65, + &(cmsCIExyYTRIPLE) { + { 0.708, 0.292, 1.0 }, + { 0.170, 0.797, 1.0 }, + { 0.131, 0.046, 1.0 } + }, + (cmsToneCurve*[3]) { curve, curve, curve }); + cmsFreeToneCurve (curve); + space_array[GDK_NAMED_COLOR_SPACE_REC2020] = gdk_lcms_color_space_new_from_lcms_profile (lcms_profile); + + g_once_init_leave (&color_spaces, space_array); + } + + return color_spaces[name]; +} + /** * gdk_color_space_supports_format: * @self: a `GdkColorSpace` diff --git a/gdk/gdkcolorspace.h b/gdk/gdkcolorspace.h index acf91b41e5..0eaff7c4d6 100644 --- a/gdk/gdkcolorspace.h +++ b/gdk/gdkcolorspace.h @@ -47,6 +47,8 @@ GType gdk_color_space_get_type (void) G_GNUC_CO GDK_AVAILABLE_IN_4_6 GdkColorSpace * gdk_color_space_get_srgb (void) G_GNUC_CONST; +GDK_AVAILABLE_IN_4_6 +GdkColorSpace * gdk_color_space_get_named (GdkNamedColorSpace name) G_GNUC_CONST; GDK_AVAILABLE_IN_4_6 GdkColorSpace * gdk_color_space_new_from_icc_profile (GBytes *icc_profile, diff --git a/gdk/gdkenums.h b/gdk/gdkenums.h index 11654a513f..c8b28b6a44 100644 --- a/gdk/gdkenums.h +++ b/gdk/gdkenums.h @@ -331,6 +331,50 @@ typedef enum { GDK_MEMORY_N_FORMATS } GdkMemoryFormat; +/** + * GdkNamedColorSpace: + * @GDK_NAMED_COLOR_SPACE_SRGB: the sRGB color space, + * see gdk_color_space_get_srgb() for details + * @GDK_NAMED_COLOR_SPACE_SRGB_LINEAR: the same sRGB color space, but + * with a linear light tone curve + * @GDK_NAMED_COLOR_SPACE_XYZ_D50: the CIE XYZ color space, with the D50 + * white point + * @GDK_NAMED_COLOR_SPACE_XYZ_D65: the CIE CYZ color space, with the D65 + * white point + * @GDK_NAMED_COLOR_SPACE_DISPLAY_P3: the [DCI P3](https://en.wikipedia.org/wiki/DCI-P3) + * color space with a D65 whitepoint as created by Apple + * @GDK_NAMED_COLOR_SPACE_A98_RGB: the [Adobe 1998 RGB](https://en.wikipedia.org/wiki/Adobe_RGB_color_space) + * color space + * @GDK_NAMED_COLOR_SPACE_PROPHOTO_RGB: the [ProPhoto RGB](https://en.wikipedia.org/wiki/ProPhoto_RGB_color_space) + * color space + * @GDK_NAMED_COLOR_SPACE_REC2020: the [Rec 2020](https://en.wikipedia.org/wiki/Rec._2020) + * color space + * @GDK_NAMED_COLOR_SPACE_N_SPACES: The number of named color spaces. + * This value will change as more color spaces get added, so do not + * rely on its concrete integer. + * + * + * The list of predefined color spaces. GDK provides the common + * color spaces used by CSS and other standards so applications can make + * use of them. + * + * More color spaces may be added in the future. + * + * Since: 4.6 + **/ +typedef enum { + GDK_NAMED_COLOR_SPACE_SRGB, + GDK_NAMED_COLOR_SPACE_SRGB_LINEAR, + GDK_NAMED_COLOR_SPACE_XYZ_D50, + GDK_NAMED_COLOR_SPACE_XYZ_D65, + GDK_NAMED_COLOR_SPACE_DISPLAY_P3, + GDK_NAMED_COLOR_SPACE_A98_RGB, + GDK_NAMED_COLOR_SPACE_PROPHOTO_RGB, + GDK_NAMED_COLOR_SPACE_REC2020, + + GDK_NAMED_COLOR_SPACE_N_SPACES +} GdkNamedColorSpace; + G_END_DECLS #endif /* __GDK_ENUMS_H__ */ |