From 0175fff6595cf38c95a17ed54c4ace5ed07240c0 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 14 May 2024 18:42:31 -0400 Subject: [PATCH] LibGfx/WebPWriter: Extract compress_VP8L_image_data() function --- .../Libraries/LibGfx/ImageFormats/WebPWriter.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp index 28430792a31..e9bcc25a15a 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp @@ -191,6 +191,13 @@ static ErrorOr write_VP8L_image_data(Stream& stream, Bitmap const& bitmap) return {}; } +static ErrorOr compress_VP8L_image_data(Bitmap const& bitmap) +{ + AllocatingMemoryStream vp8l_data_stream; + TRY(write_VP8L_image_data(vp8l_data_stream, bitmap)); + return vp8l_data_stream.read_until_eof(); +} + static u8 vp8x_flags_from_header(VP8XHeader const& header) { u8 flags = 0; @@ -290,9 +297,7 @@ ErrorOr WebPWriter::encode(Stream& stream, Bitmap const& bitmap, Options c 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; - TRY(write_VP8L_image_data(vp8l_data_stream, bitmap)); - auto vp8l_data_bytes = TRY(vp8l_data_stream.read_until_eof()); + auto vp8l_data_bytes = TRY(compress_VP8L_image_data(bitmap)); AllocatingMemoryStream vp8l_chunk_stream; TRY(write_chunk_header(vp8l_chunk_stream, "VP8L"sv, vp8l_header_bytes.size() + vp8l_data_bytes.size())); @@ -428,9 +433,7 @@ ErrorOr WebPAnimationWriter::add_frame(Bitmap& bitmap, int duration_ms, In TRY(write_VP8L_header(vp8l_header_stream, bitmap.width(), bitmap.height(), true)); auto vp8l_header_bytes = TRY(vp8l_header_stream.read_until_eof()); - AllocatingMemoryStream vp8l_data_stream; - TRY(write_VP8L_image_data(vp8l_data_stream, bitmap)); - auto vp8l_data_bytes = TRY(vp8l_data_stream.read_until_eof()); + auto vp8l_data_bytes = TRY(compress_VP8L_image_data(bitmap)); AllocatingMemoryStream vp8l_chunk_stream; TRY(write_chunk_header(vp8l_chunk_stream, "VP8L"sv, vp8l_header_bytes.size() + vp8l_data_bytes.size()));