From d8f19f31cece296e18bd4b51c23c6dfebc8829eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 23 Nov 2015 00:01:37 +0100 Subject: [PATCH] libgimpcolor: add a function to check if a profile is linear RGB --- libgimpcolor/gimpcolorprofile.c | 46 +++++++++++++++++++++++++++++++++ libgimpcolor/gimpcolorprofile.h | 1 + 2 files changed, 47 insertions(+) diff --git a/libgimpcolor/gimpcolorprofile.c b/libgimpcolor/gimpcolorprofile.c index 33b1152173..14a80ebbc6 100644 --- a/libgimpcolor/gimpcolorprofile.c +++ b/libgimpcolor/gimpcolorprofile.c @@ -4,6 +4,7 @@ * gimpcolorprofile.c * Copyright (C) 2014 Michael Natterer * Elle Stone + * Øyvind Kolås * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1291,3 +1292,48 @@ gimp_color_profile_get_format (const Babl *format, return output_format; } + +/** + * gimp_color_profile_is_linear: + * @profile: a #GimpColorProfile + * + * This function determines is the ICC profile represented by a GimpColorProfile + * is a linear RGB profile or not, some profiles that are LUTs though linear + * will also return FALSE; + * + * Return value: TRUE if the profile is a matrix shaping profile with linear + * TRCs. + * + * Since: 2.10 + **/ +gboolean +gimp_color_profile_is_linear (GimpColorProfile *profile) +{ + cmsHPROFILE prof; + cmsToneCurve *curve; + + if (!profile) + return FALSE; + prof = profile->priv->lcms_profile; + + if (!cmsIsMatrixShaper (prof)) + return FALSE; + + if(cmsIsCLUT(prof, INTENT_PERCEPTUAL, LCMS_USED_AS_INPUT)) + return FALSE; + + if(cmsIsCLUT(prof, INTENT_PERCEPTUAL, LCMS_USED_AS_OUTPUT)) + return FALSE; + + curve = cmsReadTag(prof, cmsSigRedTRCTag); + if (curve == NULL || !cmsIsToneCurveLinear (curve)) + return FALSE; + curve = cmsReadTag(prof, cmsSigGreenTRCTag); + if (curve == NULL || !cmsIsToneCurveLinear (curve)) + return FALSE; + curve = cmsReadTag(prof, cmsSigBlueTRCTag); + if (curve == NULL || !cmsIsToneCurveLinear (curve)) + return FALSE; + + return TRUE; +} diff --git a/libgimpcolor/gimpcolorprofile.h b/libgimpcolor/gimpcolorprofile.h index 3c290d7824..b184e7d07e 100644 --- a/libgimpcolor/gimpcolorprofile.h +++ b/libgimpcolor/gimpcolorprofile.h @@ -99,6 +99,7 @@ gboolean gimp_color_profile_is_equal (GimpColorProfile * GimpColorProfile *profile2); gboolean gimp_color_profile_is_rgb (GimpColorProfile *profile); +gboolean gimp_color_profile_is_linear (GimpColorProfile *profile); gboolean gimp_color_profile_is_cmyk (GimpColorProfile *profile); const Babl * gimp_color_profile_get_format (const Babl *format,