A fast approximation of the sRGB gamma function

Approximate formula

$$ \Gamma_{\rm approx.}(x) := 1.138 \sqrt{ x } - 0.138 x $$

Evaluation

The definition of a gamma function error depends on the purpose. The absolute error of \( \Gamma_{\rm approx.} ( {\Gamma_{\rm precise}}^{-1}(x) ) \) and \( {\Gamma_{\rm precise}}^{-1}( \Gamma_{\rm approx.} (x) ) \) are shown below. Blue lines indicate proposed approximation and green ones indicate \( x^{1 \over 2.2} \) for comparison. Gamma corrected values are mapped from [0, 1] to [0, 255].

The proposed approximation has less error than \( x^{1 \over 2.2} \), at least those definitions of the error!

Implementation details

If your hardware has inverse_sqrt and inverse_sqrt(0) returns a finite value, Using

fused_multiply_add(inverse_sqrt(x), 1.138, -0.138) * x

costs only a few (~6) [CG]PU cycles.

cd ../

Yasuhiro Fujii <y-fujii at mimosa-pudica.net>