Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Gagis committed Sep 22, 2023
1 parent 6d5a81f commit 10341b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/rasterimage/image_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ SOFTWARE.

#pragma once

#include <r4/rectangle.hpp>

#include "dimensioned.hpp"
#include "operations.hpp"

Expand Down Expand Up @@ -218,6 +220,12 @@ class image_span : public dimensioned
}
};

image_span(dimensions_type dimsensions, utki::span<pixel_type> span, size_t stride) :
dimensioned(dimensions),
span(span),
stride(stride)
{}

public:
using iterator = iterator_internal<false>;
using const_iterator = iterator_internal<true>;
Expand Down Expand Up @@ -289,6 +297,13 @@ class image_span : public dimensioned
return *utki::next(this->begin(), line_index);
}

image_span subspan(r4::rectangle<uint32_t> rect)
{
rect.intersect(r4::rectangle<uint32_t>({0, 0}, this->dims()));

return image_span(rect.d, this->span.subspan(rect.p.y() * this->stride + rect.p.x()), this->stride);
}

void clear(pixel_type val)
{
for (auto l : *this) {
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/src/image_span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,18 @@ const tst::set set("image_span", [](tst::suite& suite) {

tst::check(b == e, SL);
});

suite.add("subspan__rectangle", []() {
rasterimage::image<uint8_t, 4> img(rasterimage::dimensioned::dimensions_type{100, 200});

auto im = img.span();

decltype(im)::pixel_type expected = {10, 20, 30, 40};
im.clear(expected);

auto subim = im.subspan({1, 2, 2, 3});

subim.clear(0);
});
});
} // namespace

0 comments on commit 10341b8

Please sign in to comment.