109 ,
m_data(static_cast<std::size_t>(w) * h * ch)
176 ,
m_data(data_span.begin(), data_span.end())
229 [[nodiscard]]
constexpr bool isValid() const noexcept
244 auto safe_multiply = [](std::size_t a, std::size_t b, std::size_t& out_result)
constexpr ->
bool {
245 if (a != 0 && b > std::numeric_limits<std::size_t>::max() / a) {
254 std::size_t pixel_count = 0;
260 std::size_t expected_size = 0;
261 if (!safe_multiply(pixel_count,
m_channels, expected_size)) {
267 return m_data.size() == expected_size;
274 return m_data.size() *
sizeof(float);
292 template <
typename Self>
293 [[nodiscard]]
constexpr auto getBuffer(
this Self&& self)
noexcept {
294 return std::span{self.m_data};
305 template <
typename Self>
306 [[nodiscard]]
auto&
operator()(
this Self&& self, std::size_t
y, std::size_t
x, std::size_t c)
noexcept {
307 assert(
y < self.m_height);
308 assert(
x < self.m_width);
309 assert(c < self.m_channels);
310 const std::size_t idx = (
y * self.m_width +
x) * self.m_channels + c;
311 return self.m_data[idx];
320 template <
typename Self>
321 [[nodiscard]]
auto getMdSpan(
this Self&& self)
noexcept {
322 using ValueType = std::remove_reference_t<
decltype(self.m_data[0])>;
323 return std::mdspan<ValueType, std::dextents<std::size_t, 3>>(
324 self.m_data.data(), self.m_height, self.m_width, self.m_channels
346 { t.m_width } -> std::convertible_to<Common::ImageDim>;
347 { t.m_height } -> std::convertible_to<Common::ImageDim>;
348 { t.m_channels } -> std::convertible_to<Common::ImageChan>;
351 { t.isValid() } -> std::same_as<bool>;
355 { t.getBuffer() } -> std::convertible_to<std::span<const float>>;
365 { t.getBuffer() } -> std::convertible_to<std::span<float>>;
A concept that constrains a type to behave like an image container.
Extends ImageLike to require read/write access.
Common type definitions for all image types in CaptureMoment.
std::size_t ImageSize
Type for data size (element count).
std::uint8_t ImageChan
Type for channel count.
std::int32_t ImageCoord
Type for pixel coordinates (x, y).
PixelFormat
Enumerates the supported pixel storage formats in memory.
@ RGBA_F32
4-channel format: Red, Green, Blue, Alpha in 32-bit float.
std::size_t ImageDim
Type for image dimensions (width, height).
Manages the lifecycle of a single IWorkingImage instance.
Represents a rectangular region of an image and its pixel data.
constexpr ImageCoord x() const noexcept
constexpr ImageDim height() const noexcept
ImageRegion()=default
Default constructor. Creates an empty, invalid ImageRegion.
constexpr ImageChan channels() const noexcept
constexpr ImageCoord y() const noexcept
constexpr PixelFormat format() const noexcept
ImageDim m_width
Width of this image region in pixels.
ImageDim m_height
Height of this image region in pixels.
constexpr ImageDim width() const noexcept
constexpr ImageSize getDataSize() const noexcept
Returns the total number of float elements in the pixel data buffer.
constexpr auto getBuffer(this Self &&self) noexcept
Provides read-only access to the pixel data buffer as a std::span.
std::vector< float > m_data
Pixel data (row-major layout).
ImageRegion(ImageDim w, ImageDim h, ImageChan ch, PixelFormat fmt=PixelFormat::RGBA_F32)
Constructs an ImageRegion and allocates uninitialized memory.
ImageRegion(std::span< const float > data_span, ImageDim w, ImageDim h, ImageChan ch, ImageCoord x=0, ImageCoord y=0, PixelFormat fmt=PixelFormat::RGBA_F32)
Constructs an ImageRegion by copying data from a span (Deep Copy).
ImageCoord m_x
X-coordinate of the top-left corner of this region in the full source image.
ImageCoord m_y
Y-coordinate of the top-left corner of this region in the full source image.
ImageRegion(std::vector< float > &&data, ImageDim w, ImageDim h, ImageChan ch, ImageCoord x=0, ImageCoord y=0, PixelFormat fmt=PixelFormat::RGBA_F32)
Constructs an ImageRegion by moving existing pixel data (Zero-Copy).
auto & operator()(this Self &&self, std::size_t y, std::size_t x, std::size_t c) noexcept
Provides unchecked access to a specific pixel's channel value.
auto getMdSpan(this Self &&self) noexcept
Returns std::mdspan (3D: Height, Width, Channels).
PixelFormat m_format
Format specifying how pixels are stored.
constexpr bool isValid() const noexcept
Validates the integrity of the ImageRegion (Overflow-Safe Version).
ImageChan m_channels
Number of color channels per pixel.
constexpr ImageSize sizeInBytes() const noexcept
Calculates the total size in bytes of the pixel data buffer.