diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
commit | 1fd361a1ea06e44286c213ca1f814f49306fdc43 (patch) | |
tree | 64c8c96cf54d8718847339a403e5e67b922e8c3f /lib/pm_gamma.h | |
download | netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.gz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.xz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.zip |
Create Subversion repository
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/pm_gamma.h')
-rw-r--r-- | lib/pm_gamma.h | 68 |
1 files changed, 68 insertions, 0 deletions
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 <math.h> + +#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 |