From 1fd361a1ea06e44286c213ca1f814f49306fdc43 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 19 Aug 2006 03:12:28 +0000 Subject: Create Subversion repository git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/pm_gamma.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lib/pm_gamma.h (limited to 'lib/pm_gamma.h') diff --git a/lib/pm_gamma.h b/lib/pm_gamma.h new file mode 100644 index 00000000..92b34145 --- /dev/null +++ b/lib/pm_gamma.h @@ -0,0 +1,68 @@ +#ifndef _PM_GAMMA_H_ +#define _PM_GAMMA_H_ + +#include "pm_config.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif +#if 0 +} /* to fake out automatic code indenters */ +#endif + +static __inline__ float +pm_gamma709(float const intensity) { + + /* Here are parameters of the gamma transfer function + for the Netpbm formats. This is CIE Rec 709. + + This transfer function is linear for sample values 0 .. .018 + and an exponential for larger sample values. + The exponential is slightly stretched and translated, though, + unlike the popular pure exponential gamma transfer function. + */ + float const gamma = 2.2; + float const oneOverGamma = 1.0 / gamma; + float const linearCutoff = 0.018; + float const linearExpansion = + (1.099 * pow(linearCutoff, oneOverGamma) - 0.099) / linearCutoff; + + float brightness; + + if (intensity < linearCutoff) + brightness = intensity * linearExpansion; + else + brightness = 1.099 * pow(intensity, oneOverGamma) - 0.099; + + return brightness; +} + + + +static __inline__ float +pm_ungamma709(float const brightness) { + + /* These are the same parameters as in pm_gamma, above */ + + float const gamma = 2.2; + float const oneOverGamma = 1.0 / gamma; + float const linearCutoff = 0.018; + float const linearExpansion = + (1.099 * pow(linearCutoff, oneOverGamma) - 0.099) / linearCutoff; + + float intensity; + + if (brightness < linearCutoff * linearExpansion) + intensity = brightness / linearExpansion; + else + intensity = pow((brightness + 0.099) / 1.099, gamma); + + return intensity; +} + +#ifdef __cplusplus +} +#endif +#endif -- cgit 1.4.1