/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
files in the program, then also delete it here.
*/
+
+/* @file src/transfer_function.cc
+ * @brief TransferFunction
+ */
+
+
#include "transfer_function.h"
#include <cmath>
-using std::pow;
-using std::map;
-using std::pair;
+
using std::make_pair;
+using std::pair;
+using std::pow;
using std::shared_ptr;
+using std::vector;
using namespace dcp;
-TransferFunction::~TransferFunction ()
+
+vector<double> const&
+TransferFunction::lut (double from, double to, int bit_depth, bool inverse) const
{
boost::mutex::scoped_lock lm (_mutex);
- for (map<pair<int, bool>, double*>::const_iterator i = _luts.begin(); i != _luts.end(); ++i) {
- delete[] i->second;
+ auto const descriptor = LUTDescriptor{from, to, bit_depth, inverse};
+
+ auto i = _luts.find(descriptor);
+ if (i != _luts.end()) {
+ return i->second;
}
- _luts.clear ();
+ _luts[descriptor] = make_lut(from, to, bit_depth, inverse);
+ return _luts[descriptor];
}
-double const *
-TransferFunction::lut (int bit_depth, bool inverse) const
+
+bool
+TransferFunction::LUTDescriptor::operator==(TransferFunction::LUTDescriptor const& other) const
{
- boost::mutex::scoped_lock lm (_mutex);
+ return from == other.from && to == other.to && bit_depth == other.bit_depth && inverse == other.inverse;
+}
- map<pair<int, bool>, double*>::const_iterator i = _luts.find (make_pair (bit_depth, inverse));
- if (i != _luts.end ()) {
- return i->second;
- }
- _luts[make_pair(bit_depth, inverse)] = make_lut (bit_depth, inverse);
- return _luts[make_pair(bit_depth, inverse)];
+std::size_t
+TransferFunction::LUTDescriptorHasher::operator()(TransferFunction::LUTDescriptor const& desc) const
+{
+ return std::hash<double>()(desc.from) ^
+ std::hash<double>()(desc.to) ^
+ std::hash<int>()(desc.bit_depth) ^
+ std::hash<bool>()(desc.inverse);
}
+