21 pixel_row(T *pixels,
ssize_t width) noexcept : _pixels(pixels), _width(width) {}
23 [[nodiscard]]
ssize_t width()
const noexcept
30 [[nodiscard]] T
const *
data() const noexcept
37 [[nodiscard]] T *
data() noexcept
48 return _pixels[columnNr];
57 return _pixels[columnNr];
66 [[nodiscard]] T
const &
at(
ssize_t columnNr)
const noexcept
68 tt_assert(columnNr >= 0 && columnNr < _width);
69 return _pixels[columnNr];
80 tt_assert(columnNr >= 0 && columnNr < _width);
81 return _pixels[columnNr];
103 pixel_map() noexcept : _pixels(
nullptr), _width(0), _height(0), _stride(0) {}
112 _pixels(pixels), _width(width), _height(height), _stride(stride)
115 tt_assert(_stride >= _width);
116 tt_assert(_width > 0);
117 tt_assert(_height > 0);
119 tt_assert(_width == 0);
120 tt_assert(_height == 0);
131 _pixels(
new T[width * height]), _width(width), _height(height), _stride(width), _self_allocated(
true)
134 tt_assert(_stride >= _width);
135 tt_assert(_width > 0);
136 tt_assert(_height > 0);
138 tt_assert(_width == 0);
139 tt_assert(_height == 0);
172 if (_self_allocated) {
183 if (_self_allocated) {
186 for (
ssize_t y = 0; y != _height; ++y) {
187 ttlet src_row = (*this)[y];
189 for (
ssize_t x = 0; x != _width; ++x) {
190 dst_row[x] = src_row[x];
196 return submap(0, 0, _width, _height);
201 _pixels(other._pixels), _width(other._width), _height(other._height), _stride(other._stride), _self_allocated(other._self_allocated)
203 tt_axiom(
this != &other);
204 other._self_allocated =
false;
207 [[nodiscard]]
operator bool() const noexcept
209 return _pixels !=
nullptr;
212 [[nodiscard]] ssize_t width() const noexcept
217 [[nodiscard]] ssize_t height() const noexcept
222 [[nodiscard]] ssize_t stride() const noexcept
234 if (_self_allocated) {
237 _pixels = other._pixels;
238 _width = other._width;
239 _height = other._height;
240 _stride = other._stride;
241 _self_allocated = other._self_allocated;
242 other._self_allocated =
false;
246 i32x4 extent() const noexcept
248 return {narrow_cast<int>(_width), narrow_cast<int>(_height)};
257 tt_axiom((
rect.left() >= 0) && (
rect.bottom() >= 0));
258 tt_assert((
rect.right() <= _width) && (
rect.top() <= _height));
260 ttlet offset =
rect.bottom() * _stride +
rect.left();
262 return {_pixels + offset,
rect.width(),
rect.height(), _stride};
279 return {_pixels + (rowNr * _stride), _width};
282 pixel_row<T> operator[](ssize_t rowNr)
noexcept
284 return {_pixels + (rowNr * _stride), _width};
287 pixel_row<T>
const at(ssize_t rowNr)
const noexcept
289 tt_assert(rowNr < _height);
290 return (*
this)[rowNr];
293 pixel_row<T> at(ssize_t rowNr)
noexcept
295 tt_assert(rowNr < _height);
296 return (*
this)[rowNr];
319 bool _self_allocated =
false;
323void copy(pixel_map<T>
const &src, pixel_map<T> &dst)
noexcept
325 ssize_t width =
std::min(src.width(), dst.width());
326 ssize_t height =
std::min(src.height(), dst.height());
328 for (ssize_t y = 0; y != height; ++y) {
329 ttlet src_row = src[y];
330 auto dst_row = dst[y];
331 for (ssize_t x = 0; x != width; ++x) {
332 dst_row[x] = src_row[x];
337template<
int KERNEL_SIZE,
typename KERNEL>
338void horizontalFilterRow(pixel_row<uint8_t> row, KERNEL kernel)
noexcept;
340template<
int KERNEL_SIZE,
typename T,
typename KERNEL>
341void horizontalFilter(pixel_map<T> &pixels, KERNEL kernel)
noexcept;
346void fill(pixel_map<T> &dst)
noexcept;
351void fill(pixel_map<T> &dst, T color)
noexcept;
356void rotate90(pixel_map<T> &dst, pixel_map<T>
const &src)
noexcept;
361void rotate270(pixel_map<T> &dst, pixel_map<T>
const &src)
noexcept;
365void mergeMaximum(pixel_map<uint8_t> &dst, pixel_map<uint8_t>
const &src)
noexcept;
373inline void makeTransparentBorder(pixel_map<T> &pixel_map)
noexcept;
A 2D canvas of pixels.
Definition pixel_map.hpp:99
pixel_map< T > submap(iaarect rect) const noexcept
Get a (smaller) view of the map.
Definition pixel_map.hpp:255
pixel_map(T *pixels, ssize_t width, ssize_t height) noexcept
Construct an pixel-map from memory received from an API.
Definition pixel_map.hpp:155
pixel_map(ssize_t width, ssize_t height) noexcept
Construct an pixel-map.
Definition pixel_map.hpp:130
pixel_map(i32x4 extent) noexcept
Construct an pixel-map.
Definition pixel_map.hpp:148
pixel_map() noexcept
Construct an empty pixel-map.
Definition pixel_map.hpp:103
pixel_map< T > submap(ssize_t x, ssize_t y, ssize_t width, ssize_t height) const noexcept
Get a (smaller) view of the map.
Definition pixel_map.hpp:272
pixel_map(T *pixels, i32x4 extent, ssize_t stride) noexcept
Construct an pixel-map from memory received from an API.
Definition pixel_map.hpp:168
pixel_map & operator=(pixel_map const &other)=delete
Disallowing copying so that life-time of selfAllocated pixels is easy to understand.
pixel_map(T *pixels, ssize_t width, ssize_t height, ssize_t stride) noexcept
Construct an pixel-map from memory received from an API.
Definition pixel_map.hpp:111
pixel_map(pixel_map const &other)=delete
Disallowing copying so that life-time of selfAllocated pixels is easy to understand.
pixel_map(T *pixels, i32x4 extent) noexcept
Construct an pixel-map from memory received from an API.
Definition pixel_map.hpp:161
A 4D vector.
Definition ivec.hpp:38
A row of pixels.
Definition pixel_map.hpp:19
T const * data() const noexcept
Get a pointer to the pixel data.
Definition pixel_map.hpp:30
T const & operator[](ssize_t columnNr) const noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:46
T * data() noexcept
Get a pointer to the pixel data.
Definition pixel_map.hpp:37
T const & at(ssize_t columnNr) const noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:66
T & at(ssize_t columnNr) noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:78
T & operator[](ssize_t columnNr) noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:55
Class which represents an rectangle.
Definition rect.hpp:16