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

@ -218,6 +218,48 @@ public:
cbindgen_private::types::slint_image_set_nine_slice_edges(&data, top, right, bottom, left);
}
/// Returns the pixel buffer for the Image if available in RGB format without alpha.
/// Returns nullopt if the pixels cannot be obtained, for example when the image was created
/// from borrowed OpenGL textures.
std::optional<SharedPixelBuffer<Rgb8Pixel>> to_rgb8() const
{
SharedPixelBuffer<Rgb8Pixel> result;
if (cbindgen_private ::types::slint_image_to_rgb8(&data, &result.m_data, &result.m_width,
&result.m_height)) {
return result;
} else {
return {};
}
}
/// Returns the pixel buffer for the Image if available in RGBA format.
/// Returns nullopt if the pixels cannot be obtained, for example when the image was created
/// from borrowed OpenGL textures.
std::optional<SharedPixelBuffer<Rgba8Pixel>> to_rgba8() const
{
SharedPixelBuffer<Rgba8Pixel> result;
if (cbindgen_private ::types::slint_image_to_rgba8(&data, &result.m_data, &result.m_width,
&result.m_height)) {
return result;
} else {
return {};
}
}
/// Returns the pixel buffer for the Image if available in RGBA format, with the alpha channel
/// pre-multiplied to the red, green, and blue channels. Returns nullopt if the pixels cannot be
/// obtained, for example when the image was created from borrowed OpenGL textures.
std::optional<SharedPixelBuffer<Rgba8Pixel>> to_rgba8_premultiplied() const
{
SharedPixelBuffer<Rgba8Pixel> result;
if (cbindgen_private ::types::slint_image_to_rgba8_premultiplied(
&data, &result.m_data, &result.m_width, &result.m_height)) {
return result;
} else {
return {};
}
}
/// Returns true if \a a refers to the same image as \a b; false otherwise.
friend bool operator==(const Image &a, const Image &b)
{