mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-18 07:22:22 +00:00
LibGfx/WebPWriter: Write VP8X chunk header and bytes at once
For VP8L it arguably makes sense to separate the two, but for fixed-size chunk like VP8X it doesn't. No behavior change.
This commit is contained in:
parent
0c8e76cbd7
commit
27cc9e7386
Notes:
sideshowbarker
2024-07-17 04:01:41 +09:00
Author: https://github.com/nico
Commit: 27cc9e7386
Pull-request: https://github.com/SerenityOS/serenity/pull/24269
Reviewed-by: https://github.com/LucasChollet ✅
Reviewed-by: https://github.com/trflynn89
1 changed files with 4 additions and 7 deletions
|
@ -200,7 +200,7 @@ struct VP8XHeader {
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://developers.google.com/speed/webp/docs/riff_container#extended_file_format
|
// https://developers.google.com/speed/webp/docs/riff_container#extended_file_format
|
||||||
static ErrorOr<void> write_VP8X_header(Stream& stream, VP8XHeader const& header)
|
static ErrorOr<void> write_VP8X_chunk(Stream& stream, VP8XHeader const& header)
|
||||||
{
|
{
|
||||||
if (header.width > (1 << 24) || header.height > (1 << 24))
|
if (header.width > (1 << 24) || header.height > (1 << 24))
|
||||||
return Error::from_string_literal("WebP dimensions too large for VP8X chunk");
|
return Error::from_string_literal("WebP dimensions too large for VP8X chunk");
|
||||||
|
@ -213,6 +213,8 @@ static ErrorOr<void> write_VP8X_header(Stream& stream, VP8XHeader const& header)
|
||||||
if (product >= (1ull << 32))
|
if (product >= (1ull << 32))
|
||||||
return Error::from_string_literal("WebP dimensions too large for VP8X chunk");
|
return Error::from_string_literal("WebP dimensions too large for VP8X chunk");
|
||||||
|
|
||||||
|
TRY(write_chunk_header(stream, "VP8X"sv, 10));
|
||||||
|
|
||||||
LittleEndianOutputBitStream bit_stream { MaybeOwned<Stream>(stream) };
|
LittleEndianOutputBitStream bit_stream { MaybeOwned<Stream>(stream) };
|
||||||
|
|
||||||
// Don't use bit_stream.write_bits() to write individual flags here:
|
// Don't use bit_stream.write_bits() to write individual flags here:
|
||||||
|
@ -311,13 +313,8 @@ ErrorOr<void> WebPWriter::encode(Stream& stream, Bitmap const& bitmap, Options c
|
||||||
TRY(align_to_two(iccp_chunk_stream));
|
TRY(align_to_two(iccp_chunk_stream));
|
||||||
iccp_chunk_bytes = TRY(iccp_chunk_stream.read_until_eof());
|
iccp_chunk_bytes = TRY(iccp_chunk_stream.read_until_eof());
|
||||||
|
|
||||||
AllocatingMemoryStream vp8x_header_stream;
|
|
||||||
TRY(write_VP8X_header(vp8x_header_stream, { .has_icc = true, .has_alpha = alpha_is_used_hint, .width = (u32)bitmap.width(), .height = (u32)bitmap.height() }));
|
|
||||||
auto vp8x_header_bytes = TRY(vp8x_header_stream.read_until_eof());
|
|
||||||
|
|
||||||
AllocatingMemoryStream vp8x_chunk_stream;
|
AllocatingMemoryStream vp8x_chunk_stream;
|
||||||
TRY(write_chunk_header(vp8x_chunk_stream, "VP8X"sv, vp8x_header_bytes.size()));
|
TRY(write_VP8X_chunk(vp8x_chunk_stream, { .has_icc = true, .has_alpha = alpha_is_used_hint, .width = (u32)bitmap.width(), .height = (u32)bitmap.height() }));
|
||||||
TRY(vp8x_chunk_stream.write_until_depleted(vp8x_header_bytes));
|
|
||||||
VERIFY(vp8x_chunk_stream.used_buffer_size() % 2 == 0);
|
VERIFY(vp8x_chunk_stream.used_buffer_size() % 2 == 0);
|
||||||
vp8x_chunk_bytes = TRY(vp8x_chunk_stream.read_until_eof());
|
vp8x_chunk_bytes = TRY(vp8x_chunk_stream.read_until_eof());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue