23#ifndef VCL_SPACE_CORE_IMAGE_H
24#define VCL_SPACE_CORE_IMAGE_H
29#include <vclib/base.h>
50 enum class ColorSpace { UNKNOWN, LINEAR, SRGB };
55 ColorSpace mColorSpace = ColorSpace::UNKNOWN;
88 std::size_t size = w *
h;
92 if (format == Color::Format::ABGR) {
96 for (uint
i = 0;
i <
h;
i++) {
97 for (uint
j = 0;
j < w;
j++) {
99 mImg(
i,
j) = c.abgr();
127 bool isNull()
const {
return mImg.empty(); }
133 int height()
const {
return mImg.rows(); }
139 int width()
const {
return mImg.cols(); }
145 std::size_t
sizeInBytes()
const {
return mImg.rows() * mImg.cols() * 4; }
177 const unsigned char*
data()
const
179 return reinterpret_cast<const unsigned char*
>(mImg.data());
192 for (uint
i = 0;
i < mImg.rows();
i++) {
193 std::reverse(mImg.data(
i), mImg.data(
i) + mImg.cols());
197 for (uint
i = 0;
i < mImg.rows() / 2;
i++) {
198 uint
mir = mImg.rows() -
i - 1;
200 mImg.data(
i), mImg.data(
i) + mImg.cols(), mImg.data(
mir));
212 vcl::serialize(
os, mColorSpace);
222 vcl::deserialize(is, mColorSpace);
235concept ImageConcept = std::derived_from<std::remove_cvref_t<T>, Image>;
A class representing a box in N-dimensional space.
Definition box.h:46
void deserialize(std::istream &is)
Deserializes the box from the given input stream.
Definition box.h:476
void serialize(std::ostream &os) const
Serializes the box to the given output stream.
Definition box.h:466
The Color class represents a 32 bit color.
Definition color.h:48
ColorABGR
ABGR enum with some standard colors.
Definition color.h:84
Format
Color format enumeration.
Definition color.h:77
A class for representing and manipulating 2D images.
Definition image.h:48
void serialize(std::ostream &os) const
Serializes the image data to an output stream.
Definition image.h:209
ColorSpace & colorSpace()
Gets a reference to the image's color space property.
Definition image.h:157
const unsigned char * data() const
Provides direct, read-only access to the raw pixel data.
Definition image.h:177
Image(const Array2< uint > &img)
Constructs an Image by copying an existing Array2 of pixels.
Definition image.h:114
int width() const
Gets the width of the image in pixels.
Definition image.h:139
Color pixel(uint i, uint j) const
Retrieves the color of a specific pixel.
Definition image.h:166
void deserialize(std::istream &is)
Deserializes image data from an input stream.
Definition image.h:219
std::size_t sizeInBytes() const
Calculates the total size of the image data in bytes.
Definition image.h:145
int height() const
Gets the height of the image in pixels.
Definition image.h:133
void mirror(bool horizontal=false, bool vertical=true)
Flips the image horizontally and/or vertically in-place.
Definition image.h:189
ColorSpace colorSpace() const
Gets the color space of the image.
Definition image.h:151
bool isNull() const
Checks if the image is null or empty.
Definition image.h:127
Image()
Default constructor. Creates an empty, null image.
Definition image.h:61
Image(const void *data, uint w, uint h, bool yFlip=false, Color::Format format=Color::Format::ABGR)
Constructs an Image from a raw pixel buffer.
Definition image.h:79
Image(Array2< uint > &&img)
Constructs an Image by moving an existing Array2 of pixels.
Definition image.h:120
A concept that is satisfied if a type T is or derives from vcl::Image.
Definition image.h:235