1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:27:42 +00:00

LibGfx: Add PNGChunk::compress_and_add API

This commit is contained in:
Nico Weber 2023-03-15 11:00:56 +01:00 committed by Linus Groh
parent 75895bc892
commit 6e2d3fe0df

View file

@ -36,6 +36,7 @@ public:
ErrorOr<void> add_u8(u8);
ErrorOr<void> compress_and_add(ReadonlyBytes);
ErrorOr<void> add(ReadonlyBytes);
ErrorOr<void> store_type();
@ -83,6 +84,11 @@ ErrorOr<void> PNGChunk::add(T data)
return {};
}
ErrorOr<void> PNGChunk::compress_and_add(ReadonlyBytes uncompressed_bytes)
{
return add(TRY(Compress::ZlibCompressor::compress_all(uncompressed_bytes, Compress::ZlibCompressionLevel::Best)));
}
ErrorOr<void> PNGChunk::add(ReadonlyBytes bytes)
{
TRY(m_data.try_append(bytes));
@ -262,9 +268,7 @@ ErrorOr<void> PNGWriter::add_IDAT_chunk(Gfx::Bitmap const& bitmap)
TRY(uncompressed_block_data.try_append(best_filter.buffer));
}
auto zlib_buffer = TRY(Compress::ZlibCompressor::compress_all(uncompressed_block_data, Compress::ZlibCompressionLevel::Best));
TRY(png_chunk.add(zlib_buffer));
TRY(png_chunk.compress_and_add(uncompressed_block_data));
TRY(add_chunk(png_chunk));
return {};
}