From de350d691faef0d04d8e23fb86b33337442efeb4 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Thu, 28 Nov 2024 13:17:20 +0200 Subject: [PATCH] resolve TODO: --- src/svgren/filter_applier.cpp | 83 +++++++++++++---------------------- 1 file changed, 30 insertions(+), 53 deletions(-) diff --git a/src/svgren/filter_applier.cpp b/src/svgren/filter_applier.cpp index 1f7daff..e65d3d4 100644 --- a/src/svgren/filter_applier.cpp +++ b/src/svgren/filter_applier.cpp @@ -39,21 +39,21 @@ SOFTWARE. using namespace svgren; -// TODO: rewrite using image_span namespace { void box_blur_horizontal( - image_type::pixel_type* dst, - const image_type::pixel_type* src, - unsigned dst_stride, - unsigned src_stride, - r4::vector2 dims, + image_span_type dst, // + image_span_type::const_image_span_type src, unsigned box_size, unsigned box_offset ) { + ASSERT(dst.dims() == src.dims()) + const auto& dims = src.dims(); + if (box_size == 0) { return; } + for (unsigned y = 0; y != dims.y(); ++y) { using std::min; using std::max; @@ -64,19 +64,17 @@ void box_blur_horizontal( int pos = int(i) - int(box_offset); pos = max(pos, 0); pos = min(pos, int(dims.x()) - 1); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sum += src[src_stride * y + pos].to(); + + sum += src[y][pos].to(); } for (unsigned x = 0; x != dims.x(); ++x) { int tmp = int(x) - int(box_offset); int last = max(tmp, 0); int next = min(tmp + int(box_size), int(dims.x()) - 1); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - dst[dst_stride * y + x] = (sum / box_size).to(); + dst[y][x] = (sum / box_size).to(); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sum += src[src_stride * y + next].to() - src[src_stride * y + last].to(); + sum += src[y][next].to() - src[y][last].to(); } } } @@ -84,15 +82,15 @@ void box_blur_horizontal( namespace { void box_blur_vertical( - image_type::pixel_type* dst, - const image_type::pixel_type* src, - unsigned dst_stride, - unsigned src_stride, - r4::vector2 dims, + image_span_type dst, // + image_span_type::const_image_span_type src, unsigned box_size, unsigned box_offset ) { + ASSERT(dst.dims() == src.dims()) + const auto& dims = src.dims(); + if (box_size == 0) { return; } @@ -107,19 +105,16 @@ void box_blur_vertical( pos = max(pos, 0); pos = min(pos, int(dims.y()) - 1); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sum += src[src_stride * pos + x].to(); + sum += src[pos][x].to(); } for (unsigned y = 0; y != dims.y(); ++y) { int tmp = int(y) - int(box_offset); int last = max(tmp, 0); int next = min(tmp + int(box_size), int(dims.y()) - 1); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - dst[dst_stride * y + x] = (sum / box_size).to(); + dst[y][x] = (sum / box_size).to(); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sum += src[src_stride * next + x].to() - src[src_stride * last + x].to(); + sum += src[next][x].to() - src[last][x].to(); } } } @@ -182,57 +177,39 @@ filter_result blur_surface( } box_blur_horizontal( - tmp.pixels().data(), - src.image_span.data(), - src.image_span.dims().x(), - src.image_span.stride_pixels(), - src.image_span.dims(), + tmp.span(), // + src.image_span, h_box_size[0], h_offset[0] ); box_blur_horizontal( - ret.surface.image_span.data(), - tmp.pixels().data(), - ret.surface.image_span.stride_pixels(), - src.image_span.dims().x(), - src.image_span.dims(), + ret.surface.image_span, // + tmp.span(), h_box_size[1], h_offset[1] ); box_blur_horizontal( - tmp.pixels().data(), - ret.surface.image_span.data(), - src.image_span.dims().x(), - ret.surface.image_span.stride_pixels(), - src.image_span.dims(), + tmp.span(), // + ret.surface.image_span, h_box_size[2], h_offset[2] ); box_blur_vertical( - ret.surface.image_span.data(), - tmp.pixels().data(), - ret.surface.image_span.stride_pixels(), - src.image_span.dims().x(), - src.image_span.dims(), + ret.surface.image_span, // + tmp.span(), v_box_size[0], v_offset[0] ); box_blur_vertical( - tmp.pixels().data(), - ret.surface.image_span.data(), - src.image_span.dims().x(), - ret.surface.image_span.stride_pixels(), - src.image_span.dims(), + tmp.span(), // + ret.surface.image_span, v_box_size[1], v_offset[1] ); box_blur_vertical( - ret.surface.image_span.data(), - tmp.pixels().data(), - ret.surface.image_span.stride_pixels(), - src.image_span.dims().x(), - src.image_span.dims(), + ret.surface.image_span, // + tmp.span(), v_box_size[2], v_offset[2] );