23#ifndef VCL_SPACE_CORE_IMAGE_H
24#define VCL_SPACE_CORE_IMAGE_H
29#include <vclib/base.h>
70 std::size_t size = w *
h;
74 if (format == Color::Format::ABGR) {
78 for (uint
i = 0;
i <
h;
i++) {
79 for (uint
j = 0;
j < w;
j++) {
81 mImg(
i,
j) = c.abgr();
94 Image(Array2<uint>&& img) : mImg(std::move(img)) {}
96 bool isNull()
const {
return mImg.empty(); }
98 int height()
const {
return mImg.rows(); }
100 int width()
const {
return mImg.cols(); }
102 std::size_t sizeInBytes()
const {
return mImg.rows() * mImg.cols() * 4; }
104 Color pixel(uint i, uint j)
const
109 const unsigned char* data()
const
111 return reinterpret_cast<const unsigned char*
>(mImg.data());
114 void mirror(
bool horizontal =
false,
bool vertical =
true)
117 for (uint i = 0; i < mImg.rows(); i++) {
118 std::reverse(mImg.data(i), mImg.data(i) + mImg.cols());
122 for (uint i = 0; i < mImg.rows() / 2; i++) {
123 uint mir = mImg.rows() - i - 1;
125 mImg.data(i), mImg.data(i) + mImg.cols(), mImg.data(mir));
130 void serialize(std::ostream& os)
const { mImg.
serialize(os); }
132 void deserialize(std::istream& is) { mImg.
deserialize(is); }
148concept 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
The Image class stores an Image in 4 bytes RGBA format.
Definition image.h:44
Image(const void *data, uint w, uint h, bool yFlip=false, Color::Format format=Color::Format::ABGR)
Construct an Image from a raw buffer, which is assumed to be in the given format (default: ABGR).
Definition image.h:61
A concept representing an Image.
Definition image.h:148