1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 01:55:08 +00:00
Commit graph

42 commits

Author SHA1 Message Date
Tim Schumacher
a3f73e7d85 AK: Rename Stream::read_entire_buffer to Stream::read_until_filled
No functional changes.
2023-03-13 15:16:20 +00:00
Lucas CHOLLET
a47d775be6 LibGfx/JPEG: Support RGB JPEGs
By default, JPEGs use YCbCr to encode colors however other encoding
exist. This patch adds the logic to determine which transformation is
needed and support for RGB encoded JPEGs :^).
2023-03-10 22:22:36 +01:00
Lucas CHOLLET
c60338e187 LibGfx/JPEG: Decode the App14 segment
This half-standardized application specific segment is used for color
transform information. It means that the decoder is know informed if the
image uses YCbCr, RGB, CMYK or even YCCK.
2023-03-10 22:22:36 +01:00
Lucas CHOLLET
00808c5eba LibGfx/JPEG: Use decimal instead of hexadecimal for APP markers 2023-03-10 22:22:36 +01:00
Lucas CHOLLET
89e8f4692d LibGfx: Don't reject SOF2 JPEGs that don't use spectral approximation
Precisely, we now accept every SOF2 image but error on scans that has a
spectral approximation parameter different of 0.
2023-03-04 23:39:41 +00:00
Lucas CHOLLET
342c94c4d7 LibGfx/JPEG: Check for element presence in HashMaps before dereferencing
This patch replaces vague checks with more precise ones and uses `get`
instead of `find` to retrieve an element of a hashmap.
2023-03-04 23:39:41 +00:00
Lucas CHOLLET
18064fdb92 LibGfx/JPEG: Don't call add_ac if not necessary
Calling it was harmless as add_ac iterates over the spectral selection,
hence it won't do anything if not needed. However, this patch remains
useful as it prevents dereferencing the iterator returned by find, in
case the AC table isn't defined yet. This case happens with SOF2 images
and is (pretty harmless as read only but still) undefined behavior.
2023-03-04 23:39:41 +00:00
Lucas CHOLLET
1926a86336 LibGfx/JPEG: Support End-Of-Bands run
This patch brings support for SOF2 JPEGs that only use spectral
selection :^)

We still don't have achieved full support for SOF2 images, but as an
example, we decode progressive JPEG from Cloudinary.
2023-03-04 23:39:41 +00:00
Lucas CHOLLET
e5385cdf24 LibGfx/JPEG: Link the actual chapter instead of the summary section 2023-03-04 23:39:41 +00:00
Lucas CHOLLET
6b8b45c8a3 LibGfx/JPEG: Replace magic numbers with their specified name 2023-03-04 23:39:41 +00:00
Lucas CHOLLET
a139c77c71 LibGfx: Bubble up allocation failure instead of panicking 2023-02-28 08:33:01 +00:00
Lucas CHOLLET
f70a7b763f LibGfx: Don't return after the first scan
Finally, it brings support for SOF0 images with several scans.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
2c98eff558 LibGfx: Consider component interleaving when reading a scan
Scan with only one component are by definition not interleaved, meaning
that each value is linearly ordered in the stream. Grayscale images
were supported thanks to a hack, by forcing the subsampling to 1.

Now we properly support grayscale image with other subsampling (even if
it doesn't make sense) and more generally scans with only one component
and any sampling factors.

While this solution is more general than the last one it also feels a
bit hackish. We should probably refactor the way we iterate over
components and macroblocks. But that's work for latter, especially when
we will add support for other subsampling than 4-2-2.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
893659c6aa LibGfx: Move HuffmanStream from the context to the Scan object
Huffman streams are encountered in the scan segment. They have nothing
to do outside this segment, hence they shouldn't outlive the scan.

Please note that this patch changes behavior. The stream is now reset
after each scan.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
ae124c19ef LibGfx: Don't assume that a scan include all components for the image
A scan can contain fewer components that the full image. However, if
there is multiple components, they have to follow the ordering of the
frame header. It means that we can loop over components of the image
and skip those that doesn't correspond.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
947698f29f LibGfx: Consider EOI as a supported marker
For now, we exit after the first scan without needing to parse `EOI`.
However, to read scans in a loop we will need to properly detect and
parse `EOI`.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
698605444b LibGfx: Remove restrictive checks
These checks are only valid for mono-scan SOF0 images, with tables
defined before the start of frame segment.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
d3231ca323 LibGfx: Log spectral information 2023-02-27 13:39:22 +01:00
Lucas CHOLLET
3719f94c63 LibGfx: Log image dimensions only once 2023-02-27 13:39:22 +01:00
Lucas CHOLLET
f98668f8b2 LibGfx: Only iterate components of the current scan
A scan can have fewer components than what the final image contains.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
9fa375b844 LibGfx: Differentiate scan-level and frame-level data for components
This patch brings us closer to the spec point of view. And while it
makes no functional changes, it reduces the number of places where you
can misuse scan-specific data and improve support for multiple scans.
2023-02-27 13:39:22 +01:00
Lucas CHOLLET
508ae37c6e LibGfx: Move scan-related information to its own struct
Putting them directly in the context isn't good for neither readability,
comprehension nor spec compliance.
2023-02-27 13:39:22 +01:00
MacDue
6cf8eeb7a4 LibGfx: Return bool not ErrorOr<bool> from ImageDecoderPlugin::sniff()
Nobody made use of the ErrorOr return value and it just added more
chance of confusion, since it was not clear if failing to sniff an
image should return an error or false. The answer was false, if you
returned Error you'd crash the ImageDecoder.
2023-02-26 19:43:17 +01:00
Lucas CHOLLET
ad13c45c28 LibGfx: Log the underlying error when failing to decode a macroblock 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
cf6bceeb2c LibGfx: Don't assume that scans are always full when filling macroblocks
In other words: only consider coefficient of the current scan when
adding coefficients to a macroblock. Information about which
coefficients are present in the stream are passed through the spectral
information in the context.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
d421967394 LibGfx: Save spectral information in the context
These variables are useless for baseline JPEG, but they will become
useful for other encodings.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
3a8c52cabc LibGfx: Put code to add AC coefficients to a macroblock in a function 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
48f7b93a23 LibGfx: Put code to add the DC coefficient to a macroblock in a function 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
e38cd8eb4e LibGfx: Don't store the size of a Vector in an external variable 2023-02-22 09:22:45 +01:00
Lucas CHOLLET
8ed630a7ec LibGfx: Put the code to reset the encoder in its own function
With it, we can also add a spec reference. And it will remind to anyone
who wants to add support for a new coding to not forget to update it.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
3fefb696a3 LibGfx: Make decode_huffman_stream take macroblocks by reference
In progressive mode, this functions will need to be called multiple time
on the same macroblocks, so it shouldn't create the vector every
time it's called.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
bae37676c2 LibGfx: Prepare the decoder to handle multiples scans
This means that we should read markers in a loop instead of quiting on
the first scan. This is useless for now as `SOF0` frames only have one
scan, but this is a step forward `SOF2` support.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
c0c48afe06 LibGfx: Return from scan_huffman_stream before JPEG_EOI
As a JPEG file can contain multiples scans, we should return from
`scan_huffman_stream` on all new markers (except restart markers) and
not only `JPEG_EOI`.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
f1aa189027 LibGfx: Factorize handling of miscellaneous and tables segments
Miscellaneous and tables segments can also be placed between scans,
placing this code in a function will allow us to avoid duplication when
we get there.
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
90573652fd LibGfx: Rename "skip_marker_with_length" to "skip_segment"
As it, in fact, does not skip a marker but a segment :^).
2023-02-22 09:22:45 +01:00
Lucas CHOLLET
fa24f13452 LibGfx: Bring variables names closer to spec
Rename "reset_marker" to "restart_marker" as described by the spec. It
also concerns disambiguate the situation as the DRI was also called a
reset marker.
2023-02-19 23:39:59 +01:00
Lucas CHOLLET
51000961f2 LibGfx: Add a spec reference for JPEG constants definitions 2023-02-19 23:39:59 +01:00
Lucas CHOLLET
71afef6466 LibGfx: Remove some magic variables in JPEGLoader 2023-02-19 23:39:59 +01:00
Lucas CHOLLET
c8213c24dd LibGfx: Rename is_valid_marker() to is_supported_marker() 2023-02-19 23:39:59 +01:00
Lucas CHOLLET
85287fcc1e LibGfx: Rename all JPG_* macros to JPEG_* in JPEGLoader 2023-02-19 11:31:45 +01:00
Lucas CHOLLET
841e359341 LibGfx: Correctly handle JPEG image with restart markers
Restart markers are supposed to be applied every restart interval.
However, in these loops macroblocks are counted taking the luma sampling
factor into consideration. Meaning that we need to correct this factor
when testing if we should reset the DC.

Also, the decoder was discarding the first byte of every scan with a set
restart interval, as `0 % n == 0` is always true.
2023-02-19 07:59:58 +00:00
Lucas CHOLLET
856d0202f2 LibGfx: Rename JPGLoader to JPEGLoader
The patch also contains modifications on several classes, functions or
files that are related to the `JPGLoader`.

Renaming include:
 - JPGLoader{.h, .cpp}
 - JPGImageDecoderPlugin
 - JPGLoadingContext
 - JPG_DEBUG
 - decode_jpg
 - FuzzJPGLoader.cpp
 - Few string literals or texts
2023-02-18 23:56:24 +01:00
Renamed from Userland/Libraries/LibGfx/JPGLoader.cpp (Browse further)