Commit graph

18 commits

Author SHA1 Message Date
Lucas CHOLLET
cfaa51203f LibGfx/JPEG: Use a smaller type to store coefficients
No need to store them in `i32`, the JPEG norm specifies that they are
not bigger than 16 bits for extended JPEGs. So, in this patch, we
replace `i32` with `i16`. It almost divides memory usage by two :^)
2023-04-06 12:00:08 +01:00
Lucas CHOLLET
6bc30099f2 LibGfx/JPEG: Add YCCK and CMYK to RGB color transformations
It means that we now fully support JPEGs with four components :^).
2023-04-03 17:12:27 +01:00
Lucas CHOLLET
9cbed7b359 LibGfx/JPEG: Support for images with four components
This patch adds support for properly read images with four components,
basically CMYK or YCCK. However, we still lack color spaces
transformations for this type of image. So, it just postpones failure.
2023-04-03 17:12:27 +01:00
Lucas CHOLLET
261d36351d LibGfx/JPEG: Replace C-style array by Array 2023-04-03 17:12:27 +01:00
Lucas CHOLLET
df12e70541 LibGfx/JPEG: Bring IDCT and YCbCr conversion closer to specification
As mentioned in F.2.1.5 - Inverse DCT (IDCT), the decoder needs to
perform a level shift by adding 128. This used to be done in
`ycbcr_to_rgb` after the conversion. Now, we do it in `inverse_dct` in
order to ensure that the task is done unconditionally.

Consequences of this are that we are no longer required to explicitly
do it for RGB images and also, the `ycbcr_to_rgb` function is exactly
like the specification.
2023-04-03 17:12:27 +01:00
Lucas CHOLLET
f42d850211 LibGfx/JPEG: Don't reject SOF2 image with successive approximations
It means full SOF2 JPEG support, yay!
2023-04-03 17:06:21 +01:00
Lucas CHOLLET
fbad9a70fc LibGfx/JPEG: Support refinement scans
These scans are only present in progressive JPEGs and contains bits to
increase the precision of values acquired in previous scans.
2023-04-03 17:06:21 +01:00
Lucas CHOLLET
8806e66f66 LibGfx/JPEG: Handle ZRL as a special case
When reading the stream, interpreted as a normal value 0xF0 means skip
15 values and assign the 16th to 0. On the other hand, the marker ZRL
- which has the value 0xF0, means skip 16 values. For baseline JPEGs,
ZRL doesn't need to be interpreted differently as writing the 16th value
has no consequence. This is no longer the case with refining scans.
That's why this patch implement correctly ZRL.
2023-04-03 17:06:21 +01:00
Lucas CHOLLET
731c876ff7 LibGfx/JPEG: Change the loop over AC coefficients
We used to skip over zero coefficient by modifying the loop counter. It
is unfortunately impossible to perform this with SOF2 images as only
coefficients with a zero-history should be skipped.
This induces no behavior change for the user of the function.
2023-04-03 17:06:21 +01:00
Lucas CHOLLET
902d0ab58e LibGfx/JPEG: Still iterate over AC coefficients of a EOB targeted block
This commit is nonsense for anything else than SOF2 images with spectral
approximation. For this particular case, skips like EOB or ZRL only
apply to coefficients with a zero-history. This commit prepares the code
to handle this behavior.
2023-04-03 17:06:21 +01:00
Lucas CHOLLET
ef98b06dff LibGfx/JPEG: Split spectral_approximation
This `u8` is actually two values of 4 bits. Let's store them separately
to avoid confusion.
2023-04-03 17:06:21 +01:00
Lucas CHOLLET
cb0c8634d4 LibGfx/JPEG: Use a basic Stream instead of a SeekableStream
Only one use `seek` remains, as it is a bit more complex to remove.
2023-04-03 09:19:15 -04:00
Lucas CHOLLET
dc9e783608 LibGfx/JPEG: Remove the ensure_bounds_okay function
This function has probably been added when we weren't as good with error
propagations as we are now. We can safely remove it and let future
calls to `read` fail if the file is corrupted.

This can be tested with the following bytes (already used in 9191829a):
ffd8ffc000000800080ef701101200ffda00030100
2023-04-03 09:19:15 -04:00
Lucas CHOLLET
3f9c5af553 LibGfx/JPEG: More support for scans with a single component
Introduced in 2c98eff, support for non-interleaved scans was not working
for frames with a number of MCU per line or column that is odd. Indeed,
the decoder assumed that they have scans that include a fabricated MCU
like scans with multiple components.

This patch makes the decoder handle images with a number of MCU per line
or column that is odd. To do so, as in the current decoder state we do
not know if components are interleaved at allocation time, we skip over
falsely-created macroblocks when filling them. As stated in 2c98eff,
this is probably not a good solution and a whole refactor will be
welcome.

It also comes with a test that open a square image with a side of 600px,
meaning 75 MCUs.
2023-03-25 21:31:21 +01:00
Lucas CHOLLET
b820f9ffbd LibGfx/JPEG: Rename mb_index to macroblock_index 2023-03-25 21:31:21 +01:00
Lucas CHOLLET
3d7888f309 LibGfx/JPEG: Log components present in a scan 2023-03-25 21:31:21 +01:00
Lucas CHOLLET
f66de973ff LibGfx/JPEG: Replace a FIXME with some explanations
Calling the `ycbcr_to_rgb` function still looks unsuitable for this
usage, but it does the job correctly.
2023-03-22 08:57:51 +01:00
Lucas CHOLLET
496b7ffb2b LibGfx: Move all image loaders and writers to a subdirectory 2023-03-21 22:39:25 +01:00
Renamed from Userland/Libraries/LibGfx/JPEGLoader.cpp (Browse further)