diff options
author | Richard Hughes <richard@hughsie.com> | 2013-01-01 12:14:05 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2013-01-01 17:17:33 +0000 |
commit | bf02aa25829442a0f0d3ebfbd6af5bd6872cbb26 (patch) | |
tree | 076c22f80b7742bdf50e062b54c3db2d8982bb8e /client | |
parent | f871ac48ba90d232a44147c7eab0b345846f3a01 (diff) | |
download | colord-bf02aa25829442a0f0d3ebfbd6af5bd6872cbb26.tar.gz |
Add the ability to generate Rec. 709 gamma curves
You'll need lcms2 from git master if you want to be able to register a custom
cmsSigParametricCurveType like the Rec. 709 curve.
Diffstat (limited to 'client')
-rw-r--r-- | client/cd-create-profile.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/client/cd-create-profile.c b/client/cd-create-profile.c index 8ca5ba3..84a1d72 100644 --- a/client/cd-create-profile.c +++ b/client/cd-create-profile.c @@ -24,6 +24,7 @@ #include <glib/gi18n.h> #include <locale.h> #include <lcms2.h> +#include <lcms2_plugin.h> #include <stdlib.h> #include <math.h> @@ -463,6 +464,60 @@ cd_util_build_srgb_gamma (void) return cmsBuildParametricToneCurve (NULL, 4, params); } +#define LCMS_CURVE_PLUGIN_TYPE_REC709 1024 + +/** + * cd_util_lcms_rec709_trc_cb: + **/ +static double +cd_util_lcms_rec709_trc_cb (int type, const double params[], double x) +{ + gdouble val = 0.f; + + switch (type) { + case -LCMS_CURVE_PLUGIN_TYPE_REC709: + if (x < params[4]) + val = x * params[3]; + else + val = params[1] * pow (x, (1.f / params[0])) + params[2]; + break; + case LCMS_CURVE_PLUGIN_TYPE_REC709: + if (x <= (params[3] * params[4])) + val = x / params[3]; + else + val = pow (((x + params[2]) / params[1]), params[0]); + break; + } + return val; +} + +/* add Rec. 709 TRC curve type */ +cmsPluginParametricCurves cd_util_lcms_rec709_trc = { + { cmsPluginMagicNumber, /* 'acpp' */ + 2000, /* minimum version */ + cmsPluginParametricCurveSig, /* type */ + NULL }, /* no more plugins */ + 1, /* number functions */ + {LCMS_CURVE_PLUGIN_TYPE_REC709}, /* function types */ + {5}, /* parameter count */ + cd_util_lcms_rec709_trc_cb /* evaluator */ +}; + +/** + * cd_util_build_rec709_gamma: + **/ +static cmsToneCurve * +cd_util_build_rec709_gamma (void) +{ + cmsFloat64Number params[5]; + params[0] = 1.0 / 0.45; + params[1] = 1.099; + params[2] = 0.099; + params[3] = 4.500; + params[4] = 0.018; + return cmsBuildParametricToneCurve (NULL, LCMS_CURVE_PLUGIN_TYPE_REC709, params); +} + /** * cd_util_create_standard_space: **/ @@ -490,6 +545,10 @@ cd_util_create_standard_space (CdUtilPrivate *priv, transfer[0] = cd_util_build_srgb_gamma (); transfer[1] = transfer[0]; transfer[2] = transfer[0]; + } else if (g_strcmp0 (values[0], "Rec709") == 0) { + transfer[0] = cd_util_build_rec709_gamma (); + transfer[1] = transfer[0]; + transfer[2] = transfer[0]; } else { tgamma = atof (values[0]); transfer[0] = cmsBuildGamma (NULL, tgamma); @@ -646,6 +705,8 @@ main (int argc, char **argv) /* setup LCMS */ cmsSetLogErrorHandler (cd_fix_profile_error_cb); + ret = cmsPlugin (&cd_util_lcms_rec709_trc); + g_assert (ret); /* add commands */ priv = g_new0 (CdUtilPrivate, 1); |