Generate bindings of Image::to_rgb8/to_rgba8/to_rgba8_premultiplied f… (#6405)

ChangeLog: [C++] Add `Image::to_rgb8/to_rgba8/to_rgba8_premultiplied` pixel buffer accessors.

Fixes #6399
This commit is contained in:
Simon Hausmann 2024-10-01 10:55:11 +02:00 committed by GitHub
parent 4b880a7b49
commit 7db5024c52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 125 additions and 0 deletions

View file

@ -200,6 +200,31 @@ TEST_CASE("Image")
}
}
TEST_CASE("Image buffer access")
{
using namespace slint;
auto img = Image::load_from_path(SOURCE_DIR "/redpixel.png");
REQUIRE(!img.to_rgb8().has_value());
{
auto rgb = img.to_rgba8();
REQUIRE(rgb.has_value());
REQUIRE(rgb->width() == 1);
REQUIRE(rgb->height() == 1);
REQUIRE(*rgb->begin() == Rgba8Pixel { 255, 0, 0, 255 });
}
{
auto rgb = img.to_rgba8_premultiplied();
REQUIRE(rgb.has_value());
REQUIRE(rgb->width() == 1);
REQUIRE(rgb->height() == 1);
REQUIRE(*rgb->begin() == Rgba8Pixel { 255, 0, 0, 255 });
}
}
TEST_CASE("SharedVector")
{
using namespace slint;

BIN
api/cpp/tests/redpixel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B