Commit Graph

177 Commits

Author SHA1 Message Date
Filiph Siitam Sandström
fd694e8672 AK+Lagom: Make it possible to build for iOS
This commit makes it possible to build AK and most of Lagom for iOS,
based on the work for the Ladybird build demoed on discord:
https://discord.com/channels/830522505605283862/830525031720943627/1211987732646068314
2024-03-03 13:13:42 -07:00
Lucas CHOLLET
a3d48319fe LibCompress/Deflate: Remove three useless FIXMEs 2024-01-14 21:22:35 +01:00
Lucas CHOLLET
830e6472e6 LibCompress/Deflate: Simplify DeflateDecompressor::decompress_all() 2024-01-14 21:22:35 +01:00
Ali Mohammad Pur
57ea3e160a LibCompress: Use a __FILE__-relative path for the brotli dictionary file
This makes it so the generated assembly doesn't depend on
compile-specific search paths, also making it possible to build with
LTO.
2024-01-10 09:40:51 +01:00
Tim Schumacher
707a36dd79 LibCompress/Brotli: Update the lookback buffer with uncompressed data
We previously skipped updating the lookback buffer when copying
uncompressed data, which resulted in a wrong total byte count.
With a wrong total byte count, our decompressor implementation
ended up choosing a wrong offset into the dictionary.
2024-01-03 17:54:36 +01:00
Lucas CHOLLET
d748edd994 LibCompress: Add a PackBits decoder
This compression scheme was quite popular during the 80's, and we can
still find it in use inside file formats such as TIFF or PDF.
2023-12-27 17:40:11 +01:00
Tim Schumacher
a1cf2708ee LibCompress: Implement the XZ BCJ filter for ARM64 2023-12-14 08:59:23 -07:00
Idan Horowitz
b749167506 LibCompress: Fix off-by-one error in generate_huffman_lengths
Previously we would calculate the index of the first parent node as
heap.size() (which is initialized to non_zero_freqs), so in the edge
case in which all symbols had a non-zero frequency, we would use the
Size-index entry in the array for both the first symbol's leaf node,
and the first parent node.

The result would either be a non-optimal huffman code (bad), or an
illegal huffman code that would then go on to crash due to an error
check in CanonicalCode::from_bytes. (worse)

We now store parent nodes starting at heap.size() - 1, which eliminates
the potential overlap, and resolves the issue.
2023-12-04 00:06:38 +01:00
Lucas CHOLLET
2a5cb5becb LibCompress: Add LZWDecoder::decode_all()
This method takes bytes as input and decompress everything to a
ByteBuffer. It uses two control codes (clear and end of data) as
described in the GIF, TIFF and PDF specifications.
2023-12-01 12:58:14 +01:00
Lucas CHOLLET
86ee7d219e LibCompress/LZW: Use its own debug flag
The file still used the `GIF_DEBUG` flag from when it was a part of the
GIF decoder. Let's give `LZWDecoder` its own flag.
2023-11-12 13:56:27 +01:00
Lucas CHOLLET
fcaebe56d7 LibCompress/LZW: Use a parameter to choose when to change the code size
Some users of the LZW algorithm use a different value to determine when
the size of the code changes. GIF increments the size when the number of
elements in the table is equal to 2^code_size while TIFF does it for a
count of 2^code_size - 1.

This patch adds the parameter m_offset_for_size_change with a default
value of 0 and our decoder will increment the code size when we reach
a table length of 2^code_size + m_offset_for_size_change. This allows us
to support both situations.
2023-11-12 13:56:27 +01:00
Lucas CHOLLET
0c0d7e8fd3 LibCompress/LZW: Support BigEndianInputBitStream
Let's templatize the LZWDecoder, so it can take both BigEndian and
LittleEndian variant.
2023-11-12 13:56:27 +01:00
Tim Schumacher
a2f60911fe AK: Rename GenericTraits to DefaultTraits
This feels like a more fitting name for something that provides the
default values for Traits.
2023-11-09 10:05:51 -05:00
Lucas CHOLLET
5e2b049de8 LibCompress/LZW: Use a LittleEndianBitStream
No need to manually implement bit stream logic when we have a helper for
this task.
2023-11-08 18:19:34 +01:00
Lucas CHOLLET
00ad8419cf LibGfx+LibCompress: Extract the LZW decoder and move it to LibCompress
Let's put this state-of-the-art decoder from the 80's in its own file in
order to reuse it with other formats, such as TIFF or PDF.
2023-11-08 18:19:34 +01:00
Tim Schumacher
25642dfe87 LibCompress: Implement correct validation of last filters 2023-10-29 22:00:59 +01:00
Tim Schumacher
786e654dfd LibCompress: Implement the XZ delta filter 2023-10-29 22:00:59 +01:00
Tim Schumacher
f0b08e9dea LibCompress: Process XZ filters in reverse order
XZ writes filters in the order that they are used during compression, so
we need to process them in the reverse order while decompression.

This wasn't noticed earlier because we only supported the LZMA2 filter.
2023-10-29 22:00:59 +01:00
Tim Ledbetter
2f26a7bb12 LibCompress: Avoid buffer overrun when building canonical Huffman code
Previously, decompressing a DEFLATE stream an invalid canonical
Huffman code could cause a buffer overrun. We now return an error in
this case.
2023-10-10 13:24:05 +02:00
Tim Schumacher
127f6ed6eb LibCompress: Fix a typo in m_read_final_block 2023-10-09 23:40:10 +02:00
kleines Filmröllchen
062e0db46c LibCore: Make MappedFile OwnPtr-based
Since it will become a stream in a little bit, it should behave like all
non-trivial stream classes, who are not primarily intended to have
shared ownership to make closing behavior more predictable. Across all
uses of MappedFile, there is only one use case of shared mapped files in
LibVideo, which now uses the thin SharedMappedFile wrapper.
2023-09-27 03:22:56 +02:00
Tim Schumacher
dbc25f18ec LibCompress: Let BrotliDecompressionStream take a MaybeOwned 2023-08-23 12:03:37 +01:00
Tim Schumacher
8a853278d0 LibCompress: Port ZlibDecompressor to AK::Stream 2023-08-23 12:03:37 +01:00
Tim Schumacher
90780d9ade LibCompress: Let GzipDecompressor take a MaybeOwned<Stream> 2023-08-23 12:03:37 +01:00
Lucas CHOLLET
3fdf5072ec LibCompress/Brotli: Remove CanonicalCode::clear()
This function was used in a single place and don't provide a huge
benefit over simply recreating the object.
2023-07-22 07:10:47 +02:00
Lucas CHOLLET
bb834ed765 LibCompress: Add a constructor to Brotli::CanonicalCode
This constructor will be used by the JPEG-XL decoder to support a
non-standard special case. Other user should only use other
constructors.
2023-07-21 10:47:34 -06:00
Lucas CHOLLET
96eace8390 LibCompress: Move CanonicalCode in the Brotli namespace
The class was an inner class of `BrotliDecompressionStream`, let's move
it outside the `Stream` object in order to ease the access to user only
interested in this part.
2023-07-21 10:47:34 -06:00
Lucas CHOLLET
9248fd7f33 LibCompress: Move CanonicalCode's initializers inside CanonicalCode
These routines:
 - read_prefix_code
 - read_simple_prefix_code
 - read_complex_prefix_code

 were methods of `BrotliDecompressionStream` taking a `CanonicalCode` as
 an out parameter. This patch puts them in `CanonicalCode` as static
 methods.
2023-07-21 10:47:34 -06:00
Lucas CHOLLET
d2dd4142d1 LibCompress: Make CanonicalCode::read_symbol const 2023-07-21 10:47:34 -06:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Tim Schumacher
60ac254df6 AK: Use hashing to accelerate searching a CircularBuffer 2023-07-06 15:06:20 +01:00
Tim Schumacher
42d01b21d8 AK: Rewrite the hint-based CircularBuffer::find_copy_in_seekback
This now searches the memory in blocks, which should be slightly more
efficient. However, it doesn't make much difference (e.g. ~1% in LZMA
compression) in most real-world applications, as the non-hint function
is more expensive by orders of magnitude.
2023-07-06 15:06:20 +01:00
Tim Schumacher
046a9faeb3 AK: Split up CircularBuffer::find_copy_in_seekback
The "operation modes" of this function have very different focuses, and
trying to combine both in a way where we share the most amount of code
probably results in the worst performance.

Instead, split up the function into "existing distances" and "no
existing distances" so that we can optimize either case separately.
2023-07-06 15:06:20 +01:00
Tim Schumacher
9e82ad758e AK: Move parts for searching CircularBuffer into a new class
We will be adding extra logic to the CircularBuffer to optimize
searching, but this would negatively impact the performance of
CircularBuffer users that don't need that functionality.
2023-07-06 15:06:20 +01:00
tgsm
c30775522e LibCompress/Gzip: Replace usage of DeprecatedString 2023-06-17 06:44:16 +02:00
Tim Schumacher
d4b0e64825 LibCompress: Move two shared LZMA magic numbers into a common place 2023-05-19 23:40:33 +02:00
Tim Schumacher
a01968ee6d LibCompress: Handle arbitrarily long FF-chains in the LZMA encoder 2023-05-19 23:40:33 +02:00
Tim Schumacher
cb93186350 LibCompress: Add debug logging for handling LZMA direct bits 2023-05-19 23:40:33 +02:00
Tim Schumacher
df071d8a76 LibCompress: Add a lot of debug logging to LZMA 2023-05-17 09:08:53 +02:00
Tim Schumacher
85a54cc796 LibCompress: Add an LZMA encoder 2023-05-17 09:08:53 +02:00
Tim Schumacher
9ab3646bc7 LibCompress: Use the variable for LZMA "normalized to real distance"
The variable already existed, but I forgot to use it earlier.
2023-05-17 09:08:53 +02:00
Tim Schumacher
42514c6961 LibCompress: Decode the LZMA match type in a separate function
This should keep the `read_some` function a bit flatter and shorter, and
make it easier to match the match type decoding process with the
specification.
2023-05-17 09:08:53 +02:00
Tim Schumacher
4a37bac374 LibCompress: Make LzmaHeader a POD-like type
This allows us to initialize the struct using an aggregate initializer.
2023-05-17 09:08:53 +02:00
Tim Schumacher
440d8f908f LibCompress: Extract the LZMA state to a separate class
We will also need this in the compressor, as it needs to do the exact
same calculations in reverse.
2023-05-17 09:08:53 +02:00
Lucas CHOLLET
8c34959b53 AK: Add the Input word to input-only buffered streams
This concerns both `BufferedSeekable` and `BufferedFile`.
2023-05-09 11:18:46 +02:00
Tim Schumacher
dffef6bb71 LibCompress: Remove special casing for looping DEFLATE seekbacks
The `copy_from_seekback` method already handles this exactly as DEFLATE
expects, but it is slightly more optimized.
2023-05-04 20:01:16 +02:00
Tim Schumacher
4098335600 LibCompress: Error on truncated uncompressed DEFLATE blocks 2023-04-12 14:02:13 -04:00
Tim Schumacher
e11e7309dd LibCompress: Replace usages of the Endian bytes accessor 2023-04-12 07:33:15 -04:00
Tim Schumacher
381da77ffb LibCompress: Mark some XZ-related variables and functions as const 2023-04-08 15:18:59 -07:00
Tim Schumacher
e9789e9f36 LibCompress: Move loading XZ blocks into its own function 2023-04-08 15:18:59 -07:00