Line data Source code
1 : /** 2 : * \file GainMaxColoredExpanderFilter.cpp 3 : */ 4 : 5 : #include "GainMaxColoredExpanderFilter.h" 6 : #include <ATK/Core/Utilities.h> 7 : #include <ATK/Utility/fmath.h> 8 : 9 : #include <cmath> 10 : #include <cstdint> 11 : #include <iostream> 12 : 13 : namespace ATK 14 : { 15 : template<typename DataType_> 16 14 : GainMaxColoredExpanderFilter<DataType_>::GainMaxColoredExpanderFilter(gsl::index nb_channels, size_t LUTsize, size_t LUTprecision) 17 14 : :Parent(nb_channels, LUTsize, LUTprecision) 18 : { 19 14 : } 20 : 21 : template<typename DataType_> 22 6 : void GainMaxColoredExpanderFilter<DataType_>::set_softness(DataType_ softness) 23 : { 24 6 : if (softness <= 0) 25 : { 26 1 : throw ATK::RuntimeError("Softness factor must be strictly positive value"); 27 : } 28 5 : this->softness = softness; 29 5 : start_recomputeLUT(); 30 5 : } 31 : 32 : template<typename DataType_> 33 1 : DataType_ GainMaxColoredExpanderFilter<DataType_>::get_softness() const 34 : { 35 1 : return softness; 36 : } 37 : 38 : template<typename DataType_> 39 4 : void GainMaxColoredExpanderFilter<DataType_>::set_max_reduction(DataType_ max_reduction) 40 : { 41 4 : if (max_reduction < 0) 42 : { 43 1 : throw ATK::RuntimeError("Maximum reduction factor must be positive value"); 44 : } 45 3 : this->max_reduction = max_reduction; 46 3 : start_recomputeLUT(); 47 3 : } 48 : 49 : template<typename DataType_> 50 1 : void GainMaxColoredExpanderFilter<DataType_>::set_max_reduction_db(DataType_ max_reduction_db) 51 : { 52 1 : this->max_reduction = static_cast<DataType_>(std::pow(10, max_reduction_db / 10)); 53 1 : start_recomputeLUT(); 54 1 : } 55 : 56 : template<typename DataType_> 57 2 : DataType_ GainMaxColoredExpanderFilter<DataType_>::get_max_reduction() const 58 : { 59 2 : return max_reduction; 60 : } 61 : 62 : template<typename DataType_> 63 3 : void GainMaxColoredExpanderFilter<DataType_>::set_color(DataType_ color) 64 : { 65 3 : this->color = color; 66 3 : start_recomputeLUT(); 67 3 : } 68 : 69 : template<typename DataType_> 70 1 : DataType_ GainMaxColoredExpanderFilter<DataType_>::get_color() const 71 : { 72 1 : return color; 73 : } 74 : 75 : template<typename DataType_> 76 4 : void GainMaxColoredExpanderFilter<DataType_>::set_quality(DataType_ quality) 77 : { 78 4 : if (quality <= 0) 79 : { 80 1 : throw ATK::RuntimeError("Quality factor must be a strictly positive value"); 81 : } 82 3 : this->quality = quality; 83 3 : start_recomputeLUT(); 84 3 : } 85 : 86 : template<typename DataType_> 87 1 : DataType_ GainMaxColoredExpanderFilter<DataType_>::get_quality() const 88 : { 89 1 : return quality; 90 : } 91 : 92 : template<typename DataType_> 93 1835440 : DataType_ GainMaxColoredExpanderFilter<DataType_>::computeGain( DataType_ value ) const 94 : { 95 1835440 : if(value == 0) 96 : { 97 83 : return static_cast<DataType_>(fmath::pow(max_reduction, 1 / (ratio - 1))); 98 : } 99 : 100 1835350 : DataType diff = static_cast<DataType_>(-5 * fmath::log10(value * value + fmath::pow(max_reduction, 2 / (ratio - 1)))); 101 1835350 : DataType additional_color = color * fmath::exp(- diff * diff * quality); 102 : 103 1835360 : return static_cast<DataType>(fmath::pow(10, -(std::sqrt(diff*diff + softness) + diff) / 40 * (ratio - 1))) + additional_color; 104 : } 105 : 106 : #if ATK_ENABLE_INSTANTIATION 107 : template class GainMaxColoredExpanderFilter<float>; 108 : template class GainFilter<GainMaxColoredExpanderFilter<float>>; 109 : #endif 110 : template class GainMaxColoredExpanderFilter<double>; 111 : template class GainFilter<GainMaxColoredExpanderFilter<double>>; 112 : }