1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 22:35:09 +00:00
Commit graph

28 commits

Author SHA1 Message Date
Linus Groh
9c08bb9555 AK: Remove try_ prefix from FixedArray creation functions 2023-01-28 22:41:36 +01:00
Tim Schumacher
f0b035b66c LibCompress: Switch ZlibCompressor to a constructor pattern
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.
2023-01-03 10:01:09 +00:00
Moustafa Raafat
ae2abcebbb Everywhere: Use C++ concepts instead of requires clauses 2022-12-09 11:25:30 +00:00
Andreas Kling
b3b51a5001 LibGfx: Use a FixedArray for the dummy scanline in PNGWriter
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-08 13:01:11 +00:00
Andreas Kling
e19c8897ee LibGfx: Propagate errors that occur internally in PNGWriter
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-08 13:01:11 +00:00
Andreas Kling
d88c7fee32 LibGfx+Userland: Make PNGWriter::encode() return ErrorOr<ByteBuffer>
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-08 13:01:11 +00:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
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-12-06 08:54:33 +01:00
Karol Kosek
cf69763b54 LibGfx: Compress PNGs with a better compression level
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-30 23:21:42 +02:00
Karol Kosek
6901d3dcec LibGfx: Default-initialize dummy scanline
This should make the CI happier now.
2022-07-10 21:39:28 +03:00
Karol Kosek
b5420b8a9a LibGfx: Implement PNG filtering on write
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-10 15:01:07 +02:00
Karol Kosek
98a90d79de LibGfx: Move PNG header and paeth_predictor function to a shared header 2022-07-10 15:01:07 +02:00
Karol Kosek
ebc20f7ac3 LibGfx: Use enum instead of magic numbers for PNG Color and Filter types 2022-07-10 15:01:07 +02:00
Karol Kosek
9aafaec259 LibGfx: Use ZlibCompressor for compressing PNG files
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-06-30 12:26:49 +01:00
Sam Atkins
45cf40653a Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
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-24 22:36:09 +01:00
Marcus Nilsson
6523f03d47 LibGfx: Change return type of Adler32 checksums in PNGWriter
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.
2022-01-13 17:59:58 +01:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Ali Mohammad Pur
3a9f00c59b Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report
failure instead.
2021-09-06 01:53:26 +02:00
Gunnar Beutner
079dec11d3 LibGfx: Fix writing PNG headers on x86_64
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-01 11:56:01 +02:00
Gunnar Beutner
e4538ce8ef LibGfx: Fix a spelling mistake in a variable name 2021-08-01 11:56:01 +02:00
Aziz Berkay Yesilyurt
d1028f8aed LibGfx: Use clear_with capacity instead of clear in PNGWriter
Same vector was cleared up and filled in continuously.
2021-07-14 13:37:18 +02:00
Aziz Berkay Yesilyurt
b70f2b00a3 LibGfx: Store the size of the chunk from start in PNGWriter
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-14 13:37:18 +02:00
Aziz Berkay Yesilyurt
db36ddc763 LibGfx: Prevent a copy in PNGWriter by storing type data at start 2021-07-14 13:37:18 +02:00
Aziz Berkay Yesilyurt
d84c4b94da LibGfx: Prevent frequent memory allocations in PNGWriter 2021-07-14 13:37:18 +02:00
Aziz Berkay Yesilyurt
97859aaff1 LibGfx: Use ByteBuffer instead of Vector<u8> in PNGWriter
This is the first step towards reducing the number of copies in
PNGWriter by switching to ByteBuffer as underlying storage.
2021-07-14 13:37:18 +02:00
Andreas Kling
dc65f54c06 AK: Rename Vector::append(Vector) => Vector::extend(Vector)
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
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-22 11:22:27 +02:00
Andreas Kling
6793574003 LibGfx: Improve PNG encoder API somewhat
This is still far from ideal, but let's at least make it take a
Gfx::Bitmap const&.
2021-04-19 23:49:16 +02:00
Pierre
a1d7739607 LibGfx: adding a very simple PNG writer
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.
2021-01-22 20:39:25 +01:00