summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/PNGWriter.cpp
AgeCommit message (Collapse)Author
2023-01-28AK: Remove `try_` prefix from FixedArray creation functionsLinus Groh
2023-01-03LibCompress: Switch `ZlibCompressor` to a constructor patternTim Schumacher
We don't have anything fallible in the constructor yet, but what's there should be fallible and once we switch to Core::Stream it will be fallible.
2022-12-09Everywhere: Use C++ concepts instead of requires clausesMoustafa Raafat
2022-12-08LibGfx: Use a FixedArray for the dummy scanline in PNGWriterAndreas Kling
PNGWriter sets up one dummy scanline with the same width as the other scanlines in order to allow addressing the "previous scanline" without complicating the code. By using a FixedArray instead of a VLA, we sidestep the risk of stack overflow and instead get something that can signal OOM.
2022-12-08LibGfx: Propagate errors that occur internally in PNGWriterAndreas Kling
This patch basically uses the TRY() macro throughout PNGWriter instead of relying on the MUST()'ing wrappers in Vector and ByteBuffer. One FIXME was killed in the making of this patch. :^)
2022-12-08LibGfx+Userland: Make PNGWriter::encode() return ErrorOr<ByteBuffer>Andreas Kling
This is a first step towards handling PNG encoding failures instead of just falling over and crashing the program. This initial step will cause encode() to return an error if the final ByteBuffer copy fails to allocate. There are more potential failures that will be surfaced by subsequent commits. Two FIXMEs were killed in the making of this patch. :^)
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-07-30LibGfx: Compress PNGs with a better compression levelKarol Kosek
While for a general purpose encoder a good balance between compression speed and size by default is important, in case of PNG it don't matter that much, as it was said in #14594. Also note that it's not the best we can have. We use zlib's compression level, which has a range of 0-4, while our deflate implementation ranges from 0 to 5.
2022-07-10LibGfx: Default-initialize dummy scanlineKarol Kosek
This should make the CI happier now.
2022-07-10LibGfx: Implement PNG filtering on writeKarol Kosek
Is it another great upgrade to our PNG encoder like in 9aafaec259? Well, not really - it's not a 2x or 55x improvement like you saw there, but still it saves something: - a screenshot of a blank Serenity desktop dropped from about 45 KiB to 40 KiB. - re-encoding NASA photo of the Earth to PNG again saves about 25% (16.5 MiB -> 12.3 MiB), compared to not using filters. [1]: https://commons.wikimedia.org/wiki/File:The_Blue_Marble_(remastered).jpg
2022-07-10LibGfx: Move PNG header and paeth_predictor function to a shared headerKarol Kosek
2022-07-10LibGfx: Use enum instead of magic numbers for PNG Color and Filter typesKarol Kosek
2022-06-30LibGfx: Use ZlibCompressor for compressing PNG filesKarol Kosek
Previously we were hand-writing all the Zlib and raw Deflated data structures here, but now PNGs will be compressed using ZlibCompressor which will actually try to compress something! :^) Note that we don't do any filtering that should help compress data even more, but even now the results are pretty good: - screenshots of my Serenity desktop are take now about 55 KiB, where previously it was 3 MiB. - re-encoding NASA photo of the Earth[1] to PNG shows a 2x improvement (34.3 MiB -> 16.5 MiB). [1]: https://commons.wikimedia.org/wiki/File:The_Blue_Marble_(remastered).jpg
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-13LibGfx: Change return type of Adler32 checksums in PNGWriterMarcus Nilsson
The two Adler32 checksums are u16 and these two getters were mistakenly left as u32 when PNGChunk::add_as_big_endian() was templated leading to corrupted IDAT fields in our PNGs.
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-09-06Everywhere: Use OOM-safe ByteBuffer APIs where possibleAli Mohammad Pur
If we can easily communicate failure, let's avoid asserting and report failure instead.
2021-08-01LibGfx: Fix writing PNG headers on x86_64Gunnar Beutner
m_data.size() returns a size_t which is a 64-bit type on x86_64. This resulted in us incorrectly using zero in the PNG header.
2021-08-01LibGfx: Fix a spelling mistake in a variable nameGunnar Beutner
2021-07-14LibGfx: Use clear_with capacity instead of clear in PNGWriterAziz Berkay Yesilyurt
Same vector was cleared up and filled in continuously.
2021-07-14LibGfx: Store the size of the chunk from start in PNGWriterAziz Berkay Yesilyurt
Before this change PNGWriter::add_chunk used to make a copy of PNGChunk's ByteBuffer to prepend the size of the data. With this change, 4-byte space is saved from the beginning and written at the end of the operation. Avoiding this copy yields significant speed up.
2021-07-14LibGfx: Prevent a copy in PNGWriter by storing type data at startAziz Berkay Yesilyurt
2021-07-14LibGfx: Prevent frequent memory allocations in PNGWriterAziz Berkay Yesilyurt
2021-07-14LibGfx: Use ByteBuffer instead of Vector<u8> in PNGWriterAziz Berkay Yesilyurt
This is the first step towards reducing the number of copies in PNGWriter by switching to ByteBuffer as underlying storage.
2021-06-12AK: Rename Vector::append(Vector) => Vector::extend(Vector)Andreas Kling
Let's make it a bit more clear when we're appending the elements from one vector to the end of another vector.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-19LibGfx: Improve PNG encoder API somewhatAndreas Kling
This is still far from ideal, but let's at least make it take a Gfx::Bitmap const&.
2021-01-22LibGfx: adding a very simple PNG writerPierre
With this patch it is possible to create PNG files. Only minimal options are supported. The PNG is created with one big IDAT chunk containing only non-compressible DEFLATE blocks.