11 using WorldStone::Vector;
16 "Image view copy must be possible");
18 "Image view copy must be possible");
20 "Must be able to convert to an ImageView to an ImageView of const values.");
22 static_assert(std::is_assignable<decltype(
ImageView<uint8_t>().
operator()(0, 0)), uint8_t>::value,
23 "Must be able to assign values using operator()(size_t,size_t)");
28 "Must not be able to assign using operator()(size_t,size_t) on an ImageView<const Color>");
32 const size_t size = 10_z;
33 const uint8_t initColor = 0;
34 Vector<uint8_t> buffer(size * size, initColor);
35 SUBCASE(
"Using a valid view")
40 CHECK(view.
buffer ==
nullptr);
41 view.
buffer = buffer.data();
44 CHECK(view.
width == 0);
59 for (
int x = 0; x < size; x++)
61 for (
int y = 0; y < size; y++)
63 CHECK(view(x, y) == initColor);
66 const uint8_t testColor = 5;
67 view(0, 0) = testColor;
68 CHECK(buffer[0] == testColor);
69 CHECK(view(0, 0) == testColor);
70 view(0, 1) = testColor;
71 CHECK(buffer[0 + 1 * size] == testColor);
72 CHECK(view(0, 1) == testColor);
75 CHECK(viewOnConst(0, 1) == testColor);
77 SUBCASE(
"Check invalid views")
82 view = {
nullptr, size, size, size};
83 CHECK(!view.isValid());
84 view = {buffer.data(), 0, size, size};
85 CHECK(!view.isValid());
86 view = {buffer.data(), size, 0, size};
87 CHECK(!view.isValid());
88 view = {buffer.data(), size, size, 0};
89 CHECK(!view.isValid());
91 view = {buffer.data(), size + 1, size, size};
92 CHECK(!view.isValid());
100 SUBCASE(
"Asking for an image of valid dimensions")
104 CHECK(newImageView.
width == 256);
105 CHECK(newImageView.
height == 128);
107 CHECK(imageProvider.
getImage(0) == newImageView);
108 newImageView = imageProvider.
getNewImage(1024, 2048);
109 CHECK(newImageView.width == 1024);
110 CHECK(newImageView.height == 2048);
115 CHECK(imageBuffer.size() >= newImageView.width * newImageView.height);
116 CHECK(imageBuffer.data() == newImageView.buffer);
119 CHECK(!imageProvider.
getImage(1).isValid());
122 SUBCASE(
"Asking for an image of invalid dimensions returns invalid ImageView")
125 CHECK(!invalidImageView.
isValid());
126 invalidImageView = imageProvider.
getNewImage(0, 256);
127 CHECK(!invalidImageView.isValid());
Color * buffer
Pointer to the memory considered as the first pixel.
size_t stride
Actual width of the buffer scanlines.
bool isValid() const
Checks if the view seems to be valid based on its characteristics.
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.
size_t height
Number of scanlines of the image.
TEST_CASE("DCC decoding BaalSpirit.dcc")
Try to decode BaalSpirit.dcc.
Implements image manipulation helpers.
ImageView< Color > getNewImage(size_t width, size_t height) override
Allocates a new Image of dimensions width * height.