From 87979b1627b13942873e8156403cd1b232f4ea14 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 11 Apr 2026 19:48:46 +0300 Subject: [PATCH] LibImage: Don't allocate zlib stream to a contiguous buffer We can now pass multiple buffers to the decoder! --- userspace/libraries/LibImage/PNG.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/userspace/libraries/LibImage/PNG.cpp b/userspace/libraries/LibImage/PNG.cpp index 544f759f..6078b688 100644 --- a/userspace/libraries/LibImage/PNG.cpp +++ b/userspace/libraries/LibImage/PNG.cpp @@ -420,35 +420,18 @@ namespace LibImage } } - BAN::Vector zlib_stream_buf; - BAN::ConstByteSpan zlib_stream_span; - if (zlib_stream.empty()) { dwarnln_if(DEBUG_PNG, "PNG does not have zlib stream"); return BAN::Error::from_errno(EINVAL); } - if (zlib_stream.size() == 1) - zlib_stream_span = zlib_stream.front(); - else - { - for (auto stream : zlib_stream) - { - const size_t old_size = zlib_stream_buf.size(); - TRY(zlib_stream_buf.resize(old_size + stream.size())); - for (size_t i = 0; i < stream.size(); i++) - zlib_stream_buf[old_size + i] = stream[i]; - } - zlib_stream_span = zlib_stream_buf.span(); - } - uint64_t total_size = 0; for (auto stream : zlib_stream) total_size += stream.size(); dprintln_if(DEBUG_PNG, "PNG has {} byte zlib stream", total_size); - LibDEFLATE::Decompressor decompressor(zlib_stream_span, LibDEFLATE::StreamType::Zlib); + LibDEFLATE::Decompressor decompressor(zlib_stream.span(), LibDEFLATE::StreamType::Zlib); auto inflated_buffer = TRY(decompressor.decompress()); auto inflated_data = inflated_buffer.span();