diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-03-25 17:14:57 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-03-25 17:14:57 +0000 |
commit | cd86a2c8d798c98b2f5d7656971fc4553b4ed172 (patch) | |
tree | 6218a52f6e09f0cb0ff15c0a0b130da920328e8e /lib/pm_gamma.h | |
parent | e488b82f0f446576138084a1bd57b7b4406e8db0 (diff) | |
download | netpbm-mirror-cd86a2c8d798c98b2f5d7656971fc4553b4ed172.tar.gz netpbm-mirror-cd86a2c8d798c98b2f5d7656971fc4553b4ed172.tar.xz netpbm-mirror-cd86a2c8d798c98b2f5d7656971fc4553b4ed172.zip |
Copy Development as new Advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3186 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/pm_gamma.h')
-rw-r--r-- | lib/pm_gamma.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/pm_gamma.h b/lib/pm_gamma.h index 6630e05c..00d551fc 100644 --- a/lib/pm_gamma.h +++ b/lib/pm_gamma.h @@ -15,18 +15,28 @@ extern "C" { 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 + /* Here are parameters of the gamma transfer function for the Netpbm + formats. This is ITU-R Recommendation BT.709, FKA CIE Rec 709. It is + also ITU-R Recommendation BT.601, FKA CCIR 601. + + 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. + + The standard actually defines the linear expansion as 4.500, which + means there is a discontinuity at linear intensity .018. We instead + use ~4.514 to make a continuous function. This may have been simply + a mistake when this code was written or based on an actual benefit + to having a continuous function -- The history is not clear. + + Note that the discrepancy is below the precision of a maxval 255 + image. */ float const gamma = 2.2; float const oneOverGamma = 1.0 / gamma; float const linearCutoff = 0.018; - float const linearExpansion = + float const linearExpansion = (1.099 * pow(linearCutoff, oneOverGamma) - 0.099) / linearCutoff; float brightness; @@ -49,9 +59,9 @@ pm_ungamma709(float const brightness) { float const gamma = 2.2; float const oneOverGamma = 1.0 / gamma; float const linearCutoff = 0.018; - float const linearExpansion = + float const linearExpansion = (1.099 * pow(linearCutoff, oneOverGamma) - 0.099) / linearCutoff; - + float intensity; if (brightness < linearCutoff * linearExpansion) |