27 static_assert(std::is_trivially_copyable<Color>::value,
"Color must be trivially copyable for memcpy/memset");
35 ImageView(Color* _buffer,
size_t _width,
size_t _height,
size_t _stride)
43 bool operator==(
const ImageView& rhs)
const
48 bool operator!=(
const ImageView& rhs)
const {
return !(*
this == rhs); }
61 ImageView subView(
size_t xOffset,
size_t yOffset,
size_t subWidth,
size_t subHeight)
const
63 if (xOffset + subWidth >
width || yOffset + subHeight >
height)
return {};
64 return {
buffer + xOffset + yOffset *
stride, subWidth, subHeight, stride};
80 for (
size_t y = 0; y <
height; y++)
83 width *
sizeof(Color));
95 void fill(
size_t x,
size_t y,
size_t columns,
size_t rows, Color colorValue)
98 for (
size_t row = 0; row < rows; ++row)
100 for (
size_t column = 0; column < columns; column++)
102 lineStart[column] = colorValue;
115 void fillBytes(
size_t x,
size_t y,
size_t columns,
size_t rows, uint8_t byteValue)
118 for (
size_t row = 0; row < rows; ++row)
120 memset(dstPtr, byteValue, columns *
sizeof(Color));
129 template<
class Color>
139 template<
class Color>
146 Vector<Color> buffer;
147 Image(
size_t _width,
size_t _height)
148 : width(_width), height(_height), buffer(_width * _height)
152 Vector<Image> images;
158 if (!width || !height)
return {};
160 images.emplace_back(width, height);
161 return {images.back().buffer.data(), width, height, width};
170 Image& img = images[imageIndex];
171 return {img.buffer.data(), img.width, img.height, img.width};
176 const Image& img = images[imageIndex];
177 return {img.buffer.data(), img.width, img.height, img.width};
187 Image& img = images[imageIndex];
190 return std::move(img.buffer);
ImageView subView(size_t xOffset, size_t yOffset, size_t subWidth, size_t subHeight) const
Create an ImageView that is contained by the current view.
Color * buffer
Pointer to the memory considered as the first pixel.
Color & operator()(size_t x, size_t y) const
Access the pixel at the given coordinates.
void copyTo(ImageView destination) const
Copy (blits) the content of an image to another.
size_t stride
Actual width of the buffer scanlines.
ImageView< const Color > getImage(size_t imageIndex) const
bool isValid() const
Checks if the view seems to be valid based on its characteristics.
void fill(size_t x, size_t y, size_t columns, size_t rows, Color colorValue)
Fills a part of the image.
size_t width
Width of the image, can be dfferent from the one of the buffer.
size_t getImagesNumber() const
Vector< Color > moveImageBuffer(size_t imageIndex)
Move an image buffer out of the provider.
A simple image provider that allocates a new buffer for each call to getNewImage() ...
ImageView< Color > getImage(size_t imageIndex)
A view on an image buffer of type Color.
Just a placeholder to use if we ever want to implement our own vector type.
void fillBytes(size_t x, size_t y, size_t columns, size_t rows, uint8_t byteValue)
Fills a part of the image using a byte pattern.
size_t height
Number of scanlines of the image.
virtual ImageView< Color > getNewImage(size_t width, size_t height)=0
Returns an ImageView of dimensions width * height to be used by the consumer.
An interface of a class that can provide images views.
ImageView< Color > getNewImage(size_t width, size_t height) override
Allocates a new Image of dimensions width * height.