diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-15 15:01:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-16 17:49:42 +0200 |
commit | 24376e7759163ee80ff11065fe4a79ecb0796145 (patch) | |
tree | 0013e27e887af8c12447a1f5fc0d55f2a4ca4def /Userland/Libraries/LibGfx | |
parent | fcaf98361f6d3fbdf2d04bf3a6b06886e304bad3 (diff) | |
download | serenity-24376e7759163ee80ff11065fe4a79ecb0796145.zip |
LibGfx: Avoid copying ByteBuffers while loading PNG images
This wasn't much of a problem before because copying the ByteBuffer
merely copied the RefPtr but now that ByteBuffer behaves like Vector
this causes unnecessary allocations.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/PNGLoader.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index 2e866ffb8b..31d62d9e5d 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -101,7 +101,7 @@ struct PNGLoadingContext { bool has_alpha() const { return color_type & 4 || palette_transparency_data.size() > 0; } Vector<Scanline> scanlines; RefPtr<Gfx::Bitmap> bitmap; - ByteBuffer decompression_buffer; + ByteBuffer* decompression_buffer { nullptr }; Vector<u8> compressed_data; Vector<PaletteEntry> palette_data; Vector<u8> palette_transparency_data; @@ -580,7 +580,7 @@ static bool decode_png_chunks(PNGLoadingContext& context) static bool decode_png_bitmap_simple(PNGLoadingContext& context) { - Streamer streamer(context.decompression_buffer.data(), context.decompression_buffer.size()); + Streamer streamer(context.decompression_buffer->data(), context.decompression_buffer->size()); for (int y = 0; y < context.height; ++y) { u8 filter; @@ -726,7 +726,7 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in static bool decode_png_adam7(PNGLoadingContext& context) { - Streamer streamer(context.decompression_buffer.data(), context.decompression_buffer.size()); + Streamer streamer(context.decompression_buffer->data(), context.decompression_buffer->size()); context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); if (!context.bitmap) return false; @@ -759,7 +759,7 @@ static bool decode_png_bitmap(PNGLoadingContext& context) context.state = PNGLoadingContext::State::Error; return false; } - context.decompression_buffer = result.value(); + context.decompression_buffer = &result.value(); context.compressed_data.clear(); context.scanlines.ensure_capacity(context.height); @@ -777,7 +777,7 @@ static bool decode_png_bitmap(PNGLoadingContext& context) return false; } - context.decompression_buffer.clear(); + context.decompression_buffer = nullptr; context.state = PNGLoadingContext::State::BitmapDecoded; return true; |