mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
LibGfx/WebPWriter: Correctly fill in alpha_is_used hint
This commit is contained in:
parent
0e2e7cd1be
commit
7d93f7fc99
Notes:
sideshowbarker
2024-07-16 23:08:48 +09:00
Author: https://github.com/nico
Commit: 7d93f7fc99
Pull-request: https://github.com/SerenityOS/serenity/pull/24246
Reviewed-by: https://github.com/LucasChollet
1 changed files with 12 additions and 1 deletions
|
@ -64,6 +64,15 @@ static ErrorOr<void> write_VP8L_header(Stream& stream, unsigned width, unsigned
|
|||
return {};
|
||||
}
|
||||
|
||||
static bool are_all_pixels_opaque(Bitmap const& bitmap)
|
||||
{
|
||||
for (ARGB32 pixel : bitmap) {
|
||||
if ((pixel >> 24) != 0xff)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static ErrorOr<void> write_VP8L_image_data(Stream& stream, Bitmap const& bitmap)
|
||||
{
|
||||
LittleEndianOutputBitStream bit_stream { MaybeOwned<Stream>(stream) };
|
||||
|
@ -249,10 +258,12 @@ static ErrorOr<void> align_to_two(AllocatingMemoryStream& stream)
|
|||
|
||||
ErrorOr<void> WebPWriter::encode(Stream& stream, Bitmap const& bitmap, Options const& options)
|
||||
{
|
||||
bool alpha_is_used_hint = !are_all_pixels_opaque(bitmap);
|
||||
|
||||
// The chunk headers need to know their size, so we either need a SeekableStream or need to buffer the data. We're doing the latter.
|
||||
// FIXME: The whole writing-and-reading-into-buffer over-and-over is awkward and inefficient.
|
||||
AllocatingMemoryStream vp8l_header_stream;
|
||||
TRY(write_VP8L_header(vp8l_header_stream, bitmap.width(), bitmap.height(), true));
|
||||
TRY(write_VP8L_header(vp8l_header_stream, bitmap.width(), bitmap.height(), alpha_is_used_hint));
|
||||
auto vp8l_header_bytes = TRY(vp8l_header_stream.read_until_eof());
|
||||
|
||||
AllocatingMemoryStream vp8l_data_stream;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue