Sfoglia il codice sorgente

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.
Nico Weber 1 anno fa
parent
commit
27cc9e7386
1 ha cambiato i file con 4 aggiunte e 7 eliminazioni
  1. 4 7
      Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp

+ 4 - 7
Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp

@@ -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(vp8x_chunk_stream.write_until_depleted(vp8x_header_bytes));
+        TRY(write_VP8X_chunk(vp8x_chunk_stream, { .has_icc = true, .has_alpha = alpha_is_used_hint, .width = (u32)bitmap.width(), .height = (u32)bitmap.height() }));
         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());
     }
     }