diff --git a/rtengine/boxblur.h b/rtengine/boxblur.h index 805575b77..71452ceae 100644 --- a/rtengine/boxblur.h +++ b/rtengine/boxblur.h @@ -35,6 +35,8 @@ namespace rtengine template void boxblur (T** src, A** dst, int radx, int rady, int W, int H) { //box blur image; box range = (radx,rady) + assert(2*radx+1 < W); + assert(2*rady+1 < H); AlignedBuffer* buffer = new AlignedBuffer (W * H); float* temp = buffer->data; diff --git a/rtengine/guidedfilter.cc b/rtengine/guidedfilter.cc index 3000e1d5d..f6b702a73 100644 --- a/rtengine/guidedfilter.cc +++ b/rtengine/guidedfilter.cc @@ -110,7 +110,7 @@ void guidedFilter(const array2D &guide, const array2D &src, array2 const auto f_mean = [](array2D &d, array2D &s, int rad) -> void { - rad = min(rad, s.width() / 2, s.height() / 2); + rad = LIM(rad, 0, (min(s.width(), s.height()) - 1) / 2 - 1); boxblur(s, d, rad, rad, s.width(), s.height()); };