diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-05-05 20:31:26 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-05-05 21:09:40 +0200 |
| commit | ad7244de981a7dd0b9b4f8f3d62d4704f1968012 (patch) | |
| tree | 2d5818563e35585b3a45d42b2a7ffd51584592fc /src | |
| parent | f755fd20c0c026128e23a165e3b524a275d6f803 (diff) | |
Use std::vector for LUTs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gamma_transfer_function.cc | 7 | ||||
| -rw-r--r-- | src/gamma_transfer_function.h | 2 | ||||
| -rw-r--r-- | src/identity_transfer_function.cc | 7 | ||||
| -rw-r--r-- | src/identity_transfer_function.h | 2 | ||||
| -rw-r--r-- | src/modified_gamma_transfer_function.cc | 7 | ||||
| -rw-r--r-- | src/modified_gamma_transfer_function.h | 2 | ||||
| -rw-r--r-- | src/rgb_xyz.cc | 12 | ||||
| -rw-r--r-- | src/s_gamut3_transfer_function.cc | 7 | ||||
| -rw-r--r-- | src/s_gamut3_transfer_function.h | 2 | ||||
| -rw-r--r-- | src/transfer_function.cc | 19 | ||||
| -rw-r--r-- | src/transfer_function.h | 12 |
11 files changed, 35 insertions, 44 deletions
diff --git a/src/gamma_transfer_function.cc b/src/gamma_transfer_function.cc index 1875221e..4ec09afb 100644 --- a/src/gamma_transfer_function.cc +++ b/src/gamma_transfer_function.cc @@ -41,9 +41,10 @@ #include <cmath> +using std::dynamic_pointer_cast; using std::pow; using std::shared_ptr; -using std::dynamic_pointer_cast; +using std::vector; using namespace dcp; @@ -54,11 +55,11 @@ GammaTransferFunction::GammaTransferFunction (double gamma) } -double * +vector<double> GammaTransferFunction::make_lut (int bit_depth, bool inverse) const { int const bit_length = int(std::pow(2.0f, bit_depth)); - auto lut = new double[bit_length]; + auto lut = vector<double>(bit_length); double const gamma = inverse ? (1 / _gamma) : _gamma; for (int i = 0; i < bit_length; ++i) { lut[i] = pow(double(i) / (bit_length - 1), gamma); diff --git a/src/gamma_transfer_function.h b/src/gamma_transfer_function.h index 8402d6af..bfd336df 100644 --- a/src/gamma_transfer_function.h +++ b/src/gamma_transfer_function.h @@ -58,7 +58,7 @@ public: bool about_equal (std::shared_ptr<const TransferFunction> other, double epsilon) const override; protected: - double * make_lut (int bit_depth, bool inverse) const override; + std::vector<double> make_lut (int bit_depth, bool inverse) const override; private: double _gamma; diff --git a/src/identity_transfer_function.cc b/src/identity_transfer_function.cc index c01e6698..c888bd3e 100644 --- a/src/identity_transfer_function.cc +++ b/src/identity_transfer_function.cc @@ -41,17 +41,18 @@ #include <cmath> +using std::dynamic_pointer_cast; using std::pow; using std::shared_ptr; -using std::dynamic_pointer_cast; +using std::vector; using namespace dcp; -double * +vector<double> IdentityTransferFunction::make_lut (int bit_depth, bool) const { int const bit_length = int(std::pow(2.0f, bit_depth)); - auto lut = new double[bit_length]; + auto lut = vector<double>(bit_length); for (int i = 0; i < bit_length; ++i) { lut[i] = double(i) / (bit_length - 1); } diff --git a/src/identity_transfer_function.h b/src/identity_transfer_function.h index de7a897a..3db71b30 100644 --- a/src/identity_transfer_function.h +++ b/src/identity_transfer_function.h @@ -49,7 +49,7 @@ public: bool about_equal (std::shared_ptr<const TransferFunction> other, double epsilon) const override; protected: - double * make_lut (int bit_depth, bool inverse) const override; + std::vector<double> make_lut (int bit_depth, bool inverse) const override; }; diff --git a/src/modified_gamma_transfer_function.cc b/src/modified_gamma_transfer_function.cc index 039e9284..e2cc1e86 100644 --- a/src/modified_gamma_transfer_function.cc +++ b/src/modified_gamma_transfer_function.cc @@ -41,9 +41,10 @@ #include <cmath> +using std::dynamic_pointer_cast; using std::pow; using std::shared_ptr; -using std::dynamic_pointer_cast; +using std::vector; using namespace dcp; @@ -57,11 +58,11 @@ ModifiedGammaTransferFunction::ModifiedGammaTransferFunction (double power, doub } -double * +vector<double> ModifiedGammaTransferFunction::make_lut (int bit_depth, bool inverse) const { int const bit_length = int(std::pow(2.0f, bit_depth)); - double* lut = new double[bit_length]; + auto lut = vector<double>(bit_length); if (inverse) { double const threshold = _threshold / _B; for (int i = 0; i < bit_length; ++i) { diff --git a/src/modified_gamma_transfer_function.h b/src/modified_gamma_transfer_function.h index 34904855..d4e9cf97 100644 --- a/src/modified_gamma_transfer_function.h +++ b/src/modified_gamma_transfer_function.h @@ -77,7 +77,7 @@ public: bool about_equal (std::shared_ptr<const TransferFunction>, double epsilon) const override; protected: - double * make_lut (int bit_depth, bool inverse) const override; + std::vector<double> make_lut (int bit_depth, bool inverse) const override; private: double _power; diff --git a/src/rgb_xyz.cc b/src/rgb_xyz.cc index a8766b8e..b8acc9b0 100644 --- a/src/rgb_xyz.cc +++ b/src/rgb_xyz.cc @@ -80,8 +80,8 @@ dcp::xyz_to_rgba ( int* xyz_y = xyz_image->data (1); int* xyz_z = xyz_image->data (2); - double const * lut_in = conversion.out()->lut (12, false); - double const * lut_out = conversion.in()->lut (16, true); + auto lut_in = conversion.out()->lut (12, false); + auto lut_out = conversion.in()->lut (16, true); boost::numeric::ublas::matrix<double> const matrix = conversion.xyz_to_rgb (); double fast_matrix[9] = { @@ -157,8 +157,8 @@ dcp::xyz_to_rgb ( int* xyz_y = xyz_image->data (1); int* xyz_z = xyz_image->data (2); - double const * lut_in = conversion.out()->lut (12, false); - double const * lut_out = conversion.in()->lut (16, true); + auto lut_in = conversion.out()->lut (12, false); + auto lut_out = conversion.in()->lut (16, true); auto const matrix = conversion.xyz_to_rgb (); double fast_matrix[9] = { @@ -276,8 +276,8 @@ dcp::rgb_to_xyz ( double x, y, z; } d; - auto const * lut_in = conversion.in()->lut (12, false); - auto const * lut_out = conversion.out()->lut (16, true); + auto lut_in = conversion.in()->lut (12, false); + auto lut_out = conversion.out()->lut (16, true); /* This is is the product of the RGB to XYZ matrix, the Bradford transform and the DCI companding */ double fast_matrix[9]; diff --git a/src/s_gamut3_transfer_function.cc b/src/s_gamut3_transfer_function.cc index edfbe2ad..b2e82b51 100644 --- a/src/s_gamut3_transfer_function.cc +++ b/src/s_gamut3_transfer_function.cc @@ -41,17 +41,18 @@ #include <cmath> +using std::dynamic_pointer_cast; using std::pow; using std::shared_ptr; -using std::dynamic_pointer_cast; +using std::vector; using namespace dcp; -double * +vector<double> SGamut3TransferFunction::make_lut (int bit_depth, bool inverse) const { int const bit_length = int(std::pow(2.0f, bit_depth)); - double* lut = new double[bit_length]; + auto lut = vector<double>(bit_length); if (inverse) { for (int i = 0; i < bit_length; ++i) { auto const p = static_cast<double>(i) / (bit_length - 1); diff --git a/src/s_gamut3_transfer_function.h b/src/s_gamut3_transfer_function.h index 0d297e8b..790cd6b1 100644 --- a/src/s_gamut3_transfer_function.h +++ b/src/s_gamut3_transfer_function.h @@ -49,7 +49,7 @@ public: bool about_equal (std::shared_ptr<const TransferFunction> other, double epsilon) const override; protected: - double * make_lut (int bit_depth, bool inverse) const override; + std::vector<double> make_lut (int bit_depth, bool inverse) const override; }; diff --git a/src/transfer_function.cc b/src/transfer_function.cc index 00968e2f..dd3512ec 100644 --- a/src/transfer_function.cc +++ b/src/transfer_function.cc @@ -41,27 +41,16 @@ #include <cmath> -using std::pow; +using std::make_pair; using std::map; using std::pair; -using std::make_pair; +using std::pow; using std::shared_ptr; +using std::vector; using namespace dcp; -TransferFunction::~TransferFunction () -{ - boost::mutex::scoped_lock lm (_mutex); - - for (auto const& i: _luts) { - delete[] i.second; - } - - _luts.clear (); -} - - -double const * +vector<double> const& TransferFunction::lut (int bit_depth, bool inverse) const { boost::mutex::scoped_lock lm (_mutex); diff --git a/src/transfer_function.h b/src/transfer_function.h index a52011ec..04678733 100644 --- a/src/transfer_function.h +++ b/src/transfer_function.h @@ -44,6 +44,7 @@ #include <boost/thread/mutex.hpp> #include <map> #include <memory> +#include <vector> namespace dcp { @@ -57,22 +58,19 @@ class TransferFunction public: TransferFunction () {} - TransferFunction (TransferFunction const&) = delete; - TransferFunction& operator= (TransferFunction const&) = delete; - - virtual ~TransferFunction (); + virtual ~TransferFunction () {} /** @return A look-up table (of size 2^bit_depth) whose values range from 0 to 1 */ - double const * lut (int bit_depth, bool inverse) const; + std::vector<double> const& lut (int bit_depth, bool inverse) const; virtual bool about_equal (std::shared_ptr<const TransferFunction> other, double epsilon) const = 0; protected: /** Make a LUT and return an array allocated by new */ - virtual double * make_lut (int bit_depth, bool inverse) const = 0; + virtual std::vector<double> make_lut (int bit_depth, bool inverse) const = 0; private: - mutable std::map<std::pair<int, bool>, double*> _luts; + mutable std::map<std::pair<int, bool>, std::vector<double>> _luts; /** mutex to protect _luts */ mutable boost::mutex _mutex; }; |
