8#include "geometry/axis_aligned_rectangle.hpp"
9#include "geometry/extent.hpp"
19hi_warning_ignore_msvc(26401);
22hi_warning_ignore_msvc(26409);
24namespace hi::inline
v1 {
42 [[nodiscard]] T
const *
data() const noexcept
49 [[nodiscard]] T *
data() noexcept
60 return _pixels[columnNr];
69 return _pixels[columnNr];
80 hi_assert(columnNr >= 0 && columnNr < _width);
81 return _pixels[columnNr];
92 hi_assert(columnNr >= 0 && columnNr < _width);
93 return _pixels[columnNr];
113 using value_type = T;
117 pixel_map() noexcept : _pixels(
nullptr), _width(0), _height(0), _stride(0), _self_allocated(true) {}
126 _pixels(pixels), _width(width), _height(height), _stride(stride), _self_allocated(
false)
132 if (pixels ==
nullptr) {
133 _self_allocated =
true;
134 _pixels =
new T[_height * _stride];
163 if (_self_allocated) {
174 _pixels(other._pixels),
175 _width(other._width),
176 _height(other._height),
177 _stride(other._stride),
178 _self_allocated(other._self_allocated)
180 if (_self_allocated) {
181 _pixels =
new T[_height * _stride];
184 hilet src_row = other[y];
185 auto dst_row = (*this)[y];
187 dst_row[x] = src_row[x];
194 _pixels(other._pixels),
195 _width(other._width),
196 _height(other._height),
197 _stride(other._stride),
198 _self_allocated(other._self_allocated)
201 other._self_allocated =
false;
204 [[nodiscard]]
operator bool() const noexcept
206 return _pixels !=
nullptr;
228 hi_return_on_self_assignment(other);
230 _pixels = other._pixels;
231 _width = other._width;
232 _height = other._height;
233 _stride = other._stride;
234 _self_allocated = other._self_allocated;
236 if (_self_allocated) {
237 _pixels =
new T[_height * _stride];
240 hilet src_row = other[y];
241 auto dst_row = (*this)[y];
243 dst_row[x] = src_row[x];
253 if (_self_allocated) {
256 _pixels = other._pixels;
257 _width = other._width;
258 _height = other._height;
259 _stride = other._stride;
260 _self_allocated = other._self_allocated;
261 other._self_allocated =
false;
265 extent2 extent() const noexcept
267 return {narrow_cast<float>(_width), narrow_cast<float>(_height)};
280 hi_assert((x + width <= _width) && (y + height <= _height));
282 hilet offset = y * _stride + x;
284 return pixel_map{_pixels + offset, width, height, _stride};
291 narrow_cast<std::size_t>(
rectangle.left()),
292 narrow_cast<std::size_t>(
rectangle.bottom()),
297 pixel_row<T>
const operator[](
std::size_t rowNr)
const noexcept
299 return {_pixels + (rowNr * _stride), _width};
302 pixel_row<T> operator[](
std::size_t rowNr)
noexcept
304 return {_pixels + (rowNr * _stride), _width};
307 pixel_row<T>
const at(
std::size_t rowNr)
const noexcept
310 return (*
this)[rowNr];
316 return (*
this)[rowNr];
339 bool _self_allocated;
343void copy(pixel_map<T>
const& src, pixel_map<T>& dst)
noexcept
349 hilet src_row = src[y];
350 auto dst_row = dst[y];
352 dst_row[x] = src_row[x];
357template<
int KERNEL_SIZE,
typename KERNEL>
358void horizontalFilterRow(pixel_row<uint8_t> row, KERNEL kernel)
noexcept;
360template<
int KERNEL_SIZE,
typename T,
typename KERNEL>
361void horizontalFilter(pixel_map<T>& pixels, KERNEL kernel)
noexcept;
#define hi_assert(expression)
Assert if expression is true.
Definition assert.hpp:86
Utilities used by the HikoGUI library itself.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
void rotate90(pixel_map< T > &dst, pixel_map< T > const &src) noexcept
void makeTransparentBorder(pixel_map< T > &pixel_map) noexcept
Make a 1 pixel border on the edge of the pixel_map transparent By copying the pixel value from just b...
void rotate270(pixel_map< T > &dst, pixel_map< T > const &src) noexcept
void mergeMaximum(pixel_map< uint8_t > &dst, pixel_map< uint8_t > const &src) noexcept
This is a RGBA floating point color.
Definition color.hpp:39
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:20
constexpr float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:147
constexpr float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:140
A 2D canvas of pixels.
Definition pixel_map.hpp:111
pixel_map() noexcept
Construct an empty pixel-map.
Definition pixel_map.hpp:117
pixel_map(std::size_t width, std::size_t height, std::size_t stride) noexcept
Construct an pixel-map without a memory association.
Definition pixel_map.hpp:152
pixel_map(T *pixels, std::size_t width, std::size_t height, std::size_t stride) noexcept
Construct an pixel-map from memory received from an API.
Definition pixel_map.hpp:125
pixel_map(pixel_map const &other) noexcept
Copy constructor of other.
Definition pixel_map.hpp:173
pixel_map(std::size_t width, std::size_t height) noexcept
Construct an pixel-map without a memory association.
Definition pixel_map.hpp:159
pixel_map & operator=(pixel_map const &other)
Disallowing copying so that life-time of selfAllocated pixels is easy to understand.
Definition pixel_map.hpp:226
pixel_map submap(std::size_t x, std::size_t y, std::size_t width, std::size_t height) const noexcept
Get a (smaller) view of the map.
Definition pixel_map.hpp:277
pixel_map(T *pixels, std::size_t width, std::size_t height) noexcept
Construct an pixel-map from memory received from an API.
Definition pixel_map.hpp:144
A row of pixels.
Definition pixel_map.hpp:29
T * data() noexcept
Get a pointer to the pixel data.
Definition pixel_map.hpp:49
T & operator[](std::size_t columnNr) noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:67
T const & at(std::size_t columnNr) const noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:78
T const & operator[](std::size_t columnNr) const noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:58
T const * data() const noexcept
Get a pointer to the pixel data.
Definition pixel_map.hpp:42
T & at(std::size_t columnNr) noexcept
Get a access to a pixel in the row.
Definition pixel_map.hpp:90