34 using reference = value_type&;
35 using const_reference = value_type
const&;
36 using pointer = value_type *;
37 using const_pointer = value_type
const *;
38 using row_type = std::span<value_type>;
39 using const_row_type = std::span<value_type const>;
40 using nc_value_type = std::remove_const_t<value_type>;
41 using size_type = size_t;
43 template<
typename PixmapView>
53 [[nodiscard]]
constexpr row_iterator(PixmapView *ptr,
size_t y) noexcept : _ptr(ptr), _y(y) {}
55 constexpr row_iterator &operator++()
noexcept { ++_y;
return *
this; }
56 constexpr row_iterator &operator++(
int)
noexcept {
auto tmp = *
this; ++_y;
return tmp; }
57 constexpr row_iterator &operator--()
noexcept { --_y;
return *
this; }
58 constexpr row_iterator &operator--(
int)
noexcept {
auto tmp = *
this; --_y;
return tmp; }
59 [[nodiscard]]
constexpr auto operator*()
const noexcept {
return (*_ptr)[_y]; }
63 template<
typename PixmapView>
72 [[nodiscard]]
constexpr row_range(PixmapView *ptr) noexcept : _ptr(ptr) {}
73 [[nodiscard]]
constexpr auto begin()
const noexcept {
return row_iterator{_ptr, 0_uz}; }
74 [[nodiscard]]
constexpr auto end()
const noexcept {
return row_iterator{_ptr, _ptr->height()}; }
83 [[nodiscard]] constexpr
pixmap_span() noexcept = default;
85 [[nodiscard]] constexpr
pixmap_span(value_type *data, size_type width, size_type height, size_type stride) noexcept :
86 _data(data), _width(width), _height(height), _stride(stride)
90 [[nodiscard]]
constexpr pixmap_span(value_type *data, size_type width, size_type height) noexcept :
95 template<std::same_as<std::remove_const_t<value_type>> O,
typename Allocator>
101 template<std::same_as<std::remove_const_t<value_type>> O,
typename Allocator>
102 [[nodiscard]]
constexpr pixmap_span(pixmap<O, Allocator>&
other) noexcept :
107 template<std::same_as<std::remove_const_t<value_type>> O,
typename Allocator>
108 [[nodiscard]]
constexpr pixmap_span(pixmap<O, Allocator>&&
other) =
delete;
110 [[nodiscard]]
constexpr size_type empty() const noexcept
112 return _width == 0 and _height == 0;
115 [[nodiscard]]
constexpr size_type width() const noexcept
120 [[nodiscard]]
constexpr size_type height() const noexcept
125 [[nodiscard]]
constexpr size_type stride() const noexcept
130 [[nodiscard]]
constexpr pointer data() noexcept
135 [[nodiscard]]
constexpr const_pointer data() const noexcept
140 constexpr reference operator()(size_type x, size_type y)
noexcept
144 return _data[y * _stride + x];
147 constexpr const_reference operator()(size_type x, size_type y)
const noexcept
151 return _data[y * _stride + x];
154 [[nodiscard]]
constexpr row_type operator[](size_type y)
noexcept
157 return {_data + y * _stride, _width};
160 [[nodiscard]]
constexpr const_row_type operator[](size_type y)
const noexcept
163 return {_data + y * _stride, _width};
166 [[nodiscard]]
constexpr auto rows() noexcept
168 return row_range{
this};
171 [[nodiscard]]
constexpr auto rows() const noexcept
173 return row_range{
this};
176 [[nodiscard]]
constexpr pixmap_span subimage(size_type x, size_type y, size_type new_width, size_type new_height)
noexcept
178 return {_data + y * _stride + x, new_width, new_height, _stride};
181 [[nodiscard]]
constexpr pixmap_span<value_type const>
182 subimage(size_type x, size_type y, size_type new_width, size_type new_height)
const noexcept
184 return {_data + y * _stride + x, new_width, new_height, _stride};
187 constexpr friend void copy(pixmap_span src, pixmap_span<std::remove_const_t<value_type>> dst)
noexcept
189 hi_axiom(src.width() == dst.width());
190 hi_axiom(src.height() == dst.height());
192 if (src.width() == src.stride() and dst.width() == dst.stride()) {
193 std::copy(src.data(), src.data() + src.width() * src.height(), dst.data());
195 for (
auto y = 0_uz; y != src.height(); ++y) {
196 hilet src_line = src[y];
197 hilet dst_line = dst[y];
198 std::copy(src_line.begin(), src_line.end(), dst_line.begin());
203 constexpr friend void fill(pixmap_span dst, value_type value = value_type{})
noexcept
205 if (dst._width == dst._stride) {
206 std::fill_n(dst._data, dst._width, dst._height, value);
208 for (
auto line: dst.rows()) {
209 std::fill(line.begin(), line.end(), value);
215 value_type *_data =
nullptr;
216 size_type _width = 0;
217 size_type _height = 0;
218 size_type _stride = 0;