37 using reference = value_type&;
38 using const_reference = value_type
const&;
39 using pointer = value_type *;
40 using const_pointer = value_type
const *;
41 using row_type = std::span<value_type>;
42 using const_row_type = std::span<value_type const>;
43 using nc_value_type = std::remove_const_t<value_type>;
44 using size_type = size_t;
46 template<
typename PixmapView>
56 [[nodiscard]]
constexpr row_iterator(PixmapView *ptr,
size_t y) noexcept : _ptr(ptr), _y(y) {}
58 constexpr row_iterator &operator++()
noexcept { ++_y;
return *
this; }
59 constexpr row_iterator &operator++(
int)
noexcept {
auto tmp = *
this; ++_y;
return tmp; }
60 constexpr row_iterator &operator--()
noexcept { --_y;
return *
this; }
61 constexpr row_iterator &operator--(
int)
noexcept {
auto tmp = *
this; --_y;
return tmp; }
62 [[nodiscard]]
constexpr auto operator*()
const noexcept {
return (*_ptr)[_y]; }
66 template<
typename PixmapView>
75 [[nodiscard]]
constexpr row_range(PixmapView *ptr) noexcept : _ptr(ptr) {}
76 [[nodiscard]]
constexpr auto begin()
const noexcept {
return row_iterator{_ptr, 0_uz}; }
77 [[nodiscard]]
constexpr auto end()
const noexcept {
return row_iterator{_ptr, _ptr->height()}; }
86 [[nodiscard]] constexpr
pixmap_span() noexcept = default;
88 [[nodiscard]] constexpr
pixmap_span(value_type *data, size_type width, size_type height, size_type stride) noexcept :
89 _data(data), _width(width), _height(height), _stride(stride)
93 [[nodiscard]]
constexpr pixmap_span(value_type *data, size_type width, size_type height) noexcept :
98 template<std::same_as<std::remove_const_t<value_type>> O,
typename Allocator>
104 template<std::same_as<std::remove_const_t<value_type>> O,
typename Allocator>
105 [[nodiscard]]
constexpr pixmap_span(pixmap<O, Allocator>&
other) noexcept :
110 template<std::same_as<std::remove_const_t<value_type>> O,
typename Allocator>
111 [[nodiscard]]
constexpr pixmap_span(pixmap<O, Allocator>&&
other) =
delete;
113 [[nodiscard]]
constexpr bool empty() const noexcept
115 return _width == 0 and _height == 0;
118 [[nodiscard]]
constexpr size_type width() const noexcept
123 [[nodiscard]]
constexpr size_type height() const noexcept
128 [[nodiscard]]
constexpr size_type stride() const noexcept
133 [[nodiscard]]
constexpr pointer data() noexcept
138 [[nodiscard]]
constexpr const_pointer data() const noexcept
143 constexpr reference operator()(size_type x, size_type y)
noexcept
145 hi_axiom(x < _width);
146 hi_axiom(y < _height);
147 return _data[y * _stride + x];
150 constexpr const_reference operator()(size_type x, size_type y)
const noexcept
152 hi_axiom(x < _width);
153 hi_axiom(y < _height);
154 return _data[y * _stride + x];
157 [[nodiscard]]
constexpr row_type operator[](size_type y)
noexcept
159 hi_axiom(y < _height);
160 return {_data + y * _stride, _width};
163 [[nodiscard]]
constexpr const_row_type operator[](size_type y)
const noexcept
165 hi_axiom(y < _height);
166 return {_data + y * _stride, _width};
169 [[nodiscard]]
constexpr auto rows() noexcept
171 return row_range{
this};
174 [[nodiscard]]
constexpr auto rows() const noexcept
176 return row_range{
this};
179 [[nodiscard]]
constexpr pixmap_span subimage(size_type x, size_type y, size_type new_width, size_type new_height)
noexcept
181 return {_data + y * _stride + x, new_width, new_height, _stride};
184 [[nodiscard]]
constexpr pixmap_span<value_type const>
185 subimage(size_type x, size_type y, size_type new_width, size_type new_height)
const noexcept
187 return {_data + y * _stride + x, new_width, new_height, _stride};
190 constexpr friend void copy(pixmap_span src, pixmap_span<std::remove_const_t<value_type>> dst)
noexcept
192 hi_axiom(src.width() == dst.width());
193 hi_axiom(src.height() == dst.height());
195 if (src.width() == src.stride() and dst.width() == dst.stride()) {
196 std::copy(src.data(), src.data() + src.width() * src.height(), dst.data());
198 for (
auto y = 0_uz; y != src.height(); ++y) {
199 auto const src_line = src[y];
200 auto const dst_line = dst[y];
201 std::copy(src_line.begin(), src_line.end(), dst_line.begin());
206 constexpr friend void fill(pixmap_span dst, value_type value = value_type{})
noexcept
208 if (dst._width == dst._stride) {
209 std::fill_n(dst._data, dst._width, dst._height, value);
211 for (
auto line: dst.rows()) {
212 std::fill(line.begin(), line.end(), value);
218 value_type *_data =
nullptr;
219 size_type _width = 0;
220 size_type _height = 0;
221 size_type _stride = 0;