LibImage: Don't allocate zlib stream to a contiguous buffer
We can now pass multiple buffers to the decoder!
This commit is contained in:
@@ -420,35 +420,18 @@ namespace LibImage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::Vector<uint8_t> zlib_stream_buf;
|
|
||||||
BAN::ConstByteSpan zlib_stream_span;
|
|
||||||
|
|
||||||
if (zlib_stream.empty())
|
if (zlib_stream.empty())
|
||||||
{
|
{
|
||||||
dwarnln_if(DEBUG_PNG, "PNG does not have zlib stream");
|
dwarnln_if(DEBUG_PNG, "PNG does not have zlib stream");
|
||||||
return BAN::Error::from_errno(EINVAL);
|
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;
|
uint64_t total_size = 0;
|
||||||
for (auto stream : zlib_stream)
|
for (auto stream : zlib_stream)
|
||||||
total_size += stream.size();
|
total_size += stream.size();
|
||||||
dprintln_if(DEBUG_PNG, "PNG has {} byte zlib stream", total_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_buffer = TRY(decompressor.decompress());
|
||||||
auto inflated_data = inflated_buffer.span();
|
auto inflated_data = inflated_buffer.span();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user