Add duration() methods to CPL and Reel.
[libdcp.git] / src / gamma_transfer_function.cc
index b4aa20f1bdb839f680282b1a1d546556fc66925e..fe560f548962613d2c21fb32b3969f5c3d77c891 100644 (file)
 
 */
 
+/** @file  src/gamma_transfer_function.cc
+ *  @brief GammaTransferFunction class.
+ */
+
 #include "gamma_transfer_function.h"
 #include <cmath>
 
@@ -25,26 +29,27 @@ using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using namespace dcp;
 
-GammaTransferFunction::GammaTransferFunction (float gamma)
+GammaTransferFunction::GammaTransferFunction (double gamma)
        : _gamma (gamma)
 {
 
 }
 
-float *
-GammaTransferFunction::make_lut (int bit_depth) const
+double *
+GammaTransferFunction::make_lut (int bit_depth, bool inverse) const
 {
-       int const bit_length = pow (2, bit_depth);
-       float* lut = new float[int(std::pow(2.0f, bit_depth))];
+       int const bit_length = int(std::pow(2.0f, bit_depth));
+       double* lut = new double[bit_length];
+       double const gamma = inverse ? (1 / _gamma) : _gamma;
        for (int i = 0; i < bit_length; ++i) {
-               lut[i] = pow(float(i) / (bit_length - 1), _gamma);
+               lut[i] = pow(double(i) / (bit_length - 1), gamma);
        }
 
        return lut;
 }
 
 bool
-GammaTransferFunction::about_equal (shared_ptr<const TransferFunction> other, float epsilon) const
+GammaTransferFunction::about_equal (shared_ptr<const TransferFunction> other, double epsilon) const
 {
        shared_ptr<const GammaTransferFunction> o = dynamic_pointer_cast<const GammaTransferFunction> (other);
        if (!o) {