diff --git a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp index 2ebf76af40..ec154fbe6c 100644 --- a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp @@ -75,9 +75,9 @@ private: int template_window_half_size_; int search_window_half_size_; - IT fixed_point_mult_; + int fixed_point_mult_; int almost_template_window_size_sq_bin_shift_; - std::vector almost_dist2weight_; + std::vector almost_dist2weight_; void calcDistSumsForFirstElementInRow( int i, Array2d& dist_sums, @@ -119,7 +119,8 @@ FastNlMeansDenoisingInvoker::FastNlMeansDenoisingInvoker( const IT max_estimate_sum_value = (IT)search_window_size_ * (IT)search_window_size_ * (IT)pixelInfo::sampleMax(); - fixed_point_mult_ = std::numeric_limits::max() / max_estimate_sum_value; + fixed_point_mult_ = (int)std::min(std::numeric_limits::max() / max_estimate_sum_value, + std::numeric_limits::max()); // precalc weight for every possible l2 dist between blocks // additional optimization of precalced weights to replace division(averaging) by binary shift @@ -136,7 +137,7 @@ FastNlMeansDenoisingInvoker::FastNlMeansDenoisingInvoker( for (int almost_dist = 0; almost_dist < almost_max_dist; almost_dist++) { double dist = almost_dist * almost_dist2actual_dist_multiplier; - IT weight = (IT)round(fixed_point_mult_ * D::template calcWeight(dist, h)); + int weight = (int)round(fixed_point_mult_ * D::template calcWeight(dist, h)); if (weight < WEIGHT_THRESHOLD * fixed_point_mult_) weight = 0; @@ -238,8 +239,8 @@ void FastNlMeansDenoisingInvoker::operator() (const Range& range) for (int x = 0; x < search_window_size_; x++) { int almostAvgDist = dist_sums_row[x] >> almost_template_window_size_sq_bin_shift_; - IT weight = almost_dist2weight_[almostAvgDist]; - weights_sum += weight; + int weight = almost_dist2weight_[almostAvgDist]; + weights_sum += (IT)weight; T p = cur_row_ptr[border_size_ + search_window_x + x]; incWithWeight(estimation, weight, p); diff --git a/modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp b/modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp index dbb4c5eb33..4d66efe46e 100644 --- a/modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp @@ -253,39 +253,39 @@ public: template struct incWithWeight_ { - static inline void f(IT* estimation, IT weight, T p) + static inline void f(IT* estimation, int weight, T p) { - estimation[0] += weight * p; + estimation[0] += (IT)weight * p; } }; template struct incWithWeight_, IT> { - static inline void f(IT* estimation, IT weight, Vec p) + static inline void f(IT* estimation, int weight, Vec p) { - estimation[0] += weight * p[0]; - estimation[1] += weight * p[1]; + estimation[0] += (IT)weight * p[0]; + estimation[1] += (IT)weight * p[1]; } }; template struct incWithWeight_, IT> { - static inline void f(IT* estimation, IT weight, Vec p) + static inline void f(IT* estimation, int weight, Vec p) { - estimation[0] += weight * p[0]; - estimation[1] += weight * p[1]; - estimation[2] += weight * p[2]; + estimation[0] += (IT)weight * p[0]; + estimation[1] += (IT)weight * p[1]; + estimation[2] += (IT)weight * p[2]; } }; template struct incWithWeight_, IT> { - static inline void f(IT* estimation, IT weight, Vec p) + static inline void f(IT* estimation, int weight, Vec p) { - estimation[0] += weight * p[0]; - estimation[1] += weight * p[1]; - estimation[2] += weight * p[2]; - estimation[3] += weight * p[3]; + estimation[0] += (IT)weight * p[0]; + estimation[1] += (IT)weight * p[1]; + estimation[2] += (IT)weight * p[2]; + estimation[3] += (IT)weight * p[3]; } }; diff --git a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp index f1a334040c..f9c1264b25 100644 --- a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp @@ -81,9 +81,9 @@ private: int search_window_half_size_; int temporal_window_half_size_; - IT fixed_point_mult_; + int fixed_point_mult_; int almost_template_window_size_sq_bin_shift; - std::vector almost_dist2weight; + std::vector almost_dist2weight; void calcDistSumsForFirstElementInRow(int i, Array3d& dist_sums, Array4d& col_dist_sums, @@ -127,7 +127,8 @@ FastNlMeansMultiDenoisingInvoker::FastNlMeansMultiDenoisingInvoke main_extended_src_ = extended_srcs_[temporal_window_half_size_]; const IT max_estimate_sum_value = (IT)temporal_window_size_ * (IT)search_window_size_ * (IT)search_window_size_ * (IT)pixelInfo::sampleMax(); - fixed_point_mult_ = std::numeric_limits::max() / max_estimate_sum_value; + fixed_point_mult_ = (int)std::min(std::numeric_limits::max() / max_estimate_sum_value, + std::numeric_limits::max()); // precalc weight for every possible l2 dist between blocks // additional optimization of precalced weights to replace division(averaging) by binary shift @@ -147,7 +148,7 @@ FastNlMeansMultiDenoisingInvoker::FastNlMeansMultiDenoisingInvoke for (int almost_dist = 0; almost_dist < almost_max_dist; almost_dist++) { double dist = almost_dist * almost_dist2actual_dist_multiplier; - IT weight = (IT)round(fixed_point_mult_ * D::template calcWeight(dist, h)); + int weight = (int)round(fixed_point_mult_ * D::template calcWeight(dist, h)); if (weight < WEIGHT_THRESHOLD * fixed_point_mult_) weight = 0; @@ -266,8 +267,8 @@ void FastNlMeansMultiDenoisingInvoker::operator() (const Range& r { int almostAvgDist = dist_sums_row[x] >> almost_template_window_size_sq_bin_shift; - IT weight = almost_dist2weight[almostAvgDist]; - weights_sum += weight; + int weight = almost_dist2weight[almostAvgDist]; + weights_sum += (IT)weight; T p = cur_row_ptr[border_size_ + search_window_x + x]; incWithWeight(estimation, weight, p);