Commit Graph

2193 Commits

Author SHA1 Message Date
Nico Weber
b364a58753 LibGfx/JPEG2000: Read COC marker segments, both in main and tile headers
Not yet used for anything.
2024-04-25 09:00:46 -04:00
Nico Weber
8eb3d436e6 LibGfx/JPEG2000: Extract CodingStyleParameters
This is the data shared between COD and COC marker segments.

No behavior change.
2024-04-25 09:00:46 -04:00
Nico Weber
3735f2cbed LibGfx/JPEG2000: Read COD on tile headers too
I haven't seen this in the wild yet, but it is allowed per spec
and easy to do.
2024-04-25 09:00:46 -04:00
Timothy Flynn
ec492a1a08 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There are a couple of weird cases where clang-format now thinks that a
pointer access in an initializer list, e.g. `m_member(ptr->foo)`, is a
lambda return statement, and it puts spaces around the `->`.
2024-04-24 16:50:01 -04:00
Daniel Bertalan
cc92c3f551 LibCrypto+LibGfx: Fix GCC 14 compile errors
The C++ standard does not allow specifying the template parameters in
constructor declarations, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97202#c8.

Converting constructors have a higher priority that user-defined
conversion functions; let's constrain `Gfx::Size<T>(Gfx::Size<U>)` to
only be considered when `U` is convertible to `T`. This lets us fall
back to conversion operators in the case of `UISize` -> `IntSize`, for
instance. Clang is still okay without this, but MSVC would error out
similarly: https://godbolt.org/z/PTbeYPM7s

Note that a not-yet-committed patch is required for full compilation:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114784#c3
2024-04-20 15:52:29 -06:00
Nico Weber
0c935f8f42 LibGfx/JPEG2000: Support reading raw jpeg2000 codestreams
Most JPEG2000 files put the codestream in an ISOBMFF box structure
(which is useful for including metadata that's bigger than the
~65k marker segment data limit, such as large ICC profiles), but
some files just store the codestream directly, for example
https://sembiance.com/fileFormatSamples/image/jpeg2000/balloon.j2c

See https://www.iana.org/assignments/media-types/image/j2c for the
mime type.

The main motivation is to be able to use the test data in J.10 in
the spec as a test case.
2024-04-19 12:42:34 -04:00
Nico Weber
5695acf328 LibGfx/JPEG2000: Add comment mentioning J.10 2024-04-19 12:42:34 -04:00
Nico Weber
1a232ba2a6 LibGfx/JPEG2000: Check SIZ marker (w, h) against JP2 header (w, h) 2024-04-19 12:42:34 -04:00
Andrew Kaster
6d4ba21832 LibIPC+Userland: Make IPC::File always own its file descriptor
Add factory functions to distinguish between when the owner of the File
wants to transfer ownership to the new IPC object (adopt) or to send a
copy of the same fd to the IPC peer (clone).

This behavior is more intuitive than the previous behavior. Previously,
an IPC::File would default to a shallow clone of the file descriptor,
only *actually* calling dup(2) for the fd when encoding or it into an
IPC MessageBuffer. Now the dup(2) for the fd is explicit in the clone_fd
factory function.
2024-04-19 06:34:07 -04:00
Dan Klishch
5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Nico Weber
ca3a62a6bb LibGfx: Add a comment to QMArithmeticDecoder.h 2024-04-19 10:59:11 +02:00
Nico Weber
ea441fea95 LibGfx: Move QMArithmeticDecoder to its own file
It will be used by the JPEG2000 decoder as well.

Pure code move, no behavior change.
2024-04-19 10:59:11 +02:00
Nico Weber
5ff75ce5fb LibGfx/JBIG2: Rename JBIG2::ArithmeticDecoder to QMArithmeticDecoder
In preparation of moving it to its own file.

No behavior change.
2024-04-19 10:59:11 +02:00
Daniel Bertalan
d282066ba4 LibGfx: Spell IPCEncode::encode definitions instead of abusing concepts
The original approach failed to link with LLVM 18 because of the changed
symbol mangling.
2024-04-18 13:14:33 -06:00
Nico Weber
7296b0fa43 LibGfx/JPEG2000: Implement tag trees
A tag tree is a data structure used for deserializing JPEG2000
packet headers.

We don't use them for anything yet, except from tests.

The implementation feels a bit awkward to me, but we can always polish
it later.

The spec thankfully includes two concrete examples. The code is
correct enough to pass those -- I added them as test.
2024-04-16 00:40:16 +02:00
Nico Weber
69fa1d1b6e LibGfx/WebP: Remove a bounds check that is never hit
No behavior change.
2024-04-15 15:53:52 +02:00
Nico Weber
04c6af7dfd LibGfx/WebP: Add two spec comments 2024-04-15 15:53:52 +02:00
Andreas Kling
217cb01708 LibGfx: Clip out-of-bounds pixel accesses in Painter::draw_rect() 2024-04-14 18:05:48 +02:00
Nico Weber
f9fa41cadf LibGfx/JPEG2000: Use streams instead of manual offsets
No behavior change for valid images. More cryptic errors for invalid
images, but on the flipside quite a bit less code.
2024-04-10 10:51:04 -04:00
Nico Weber
2c9c996130 LibGfx/JPEG2000: Fix off-by-one in reading comment data 😬
For text, we always ended up with a leading \0 byte (on little-endian),
which prints as nothing. Since that's the only thing we do with this
data, no actual behavior change.
2024-04-10 10:51:04 -04:00
Nico Weber
b2d7c405cd LibGfx/JPEG2000: Remove needless "AK::" qualifiers 2024-04-10 10:51:04 -04:00
Nico Weber
f91d8472ee LibGfx/JPEG2000: Make unimplemented markers in tile-part header fatal 2024-04-09 15:52:00 -04:00
Nico Weber
dbe179f0d5 LibGfx/JPEG2000: Decode tile-part QCD and QCC marker segment data 2024-04-09 15:52:00 -04:00
Nico Weber
8ba7c23165 LibGfx/JPEG2000: Decode QCC marker segment data
I haven't seen any images that set this in the main header, but
Tests/LibGfx/test-inputs/jpeg2000/buggie-gray.jpf sets it in a tile-part
header.
2024-04-09 15:52:00 -04:00
Nico Weber
072457edd8 LibGfx/JPEG2000: Decode tile-part COM marker segment data
We don't do anything with this (except log the contents if
JPEG2000_DEBUG is 1).
2024-04-09 15:52:00 -04:00
Nico Weber
38be93c9a1 LibGfx/JPEG2000: Store some tile and tile part data on context 2024-04-09 15:52:00 -04:00
Nico Weber
0df01dea4a LibGfx/JPEG2000: Add two spec comments 2024-04-09 15:52:00 -04:00
Nico Weber
7b7ef7dcc7 LibGfx/JPEG2000: Allow COD, COC, QCD, QCC, RGN only in first tile-part
(The FIXME was incomplete, it didn't mention RGN also only being valid
in a tile's first tile-part header.)
2024-04-09 15:52:00 -04:00
Nico Weber
1df5c01bfb LibGfx/JPEG2000: Make unimplemented markers in main header fatal
We now implement decoding enough marker segments that we can do this.
2024-04-09 15:52:00 -04:00
Nico Weber
b9677be8a7 LibGfx/JPEG2000: Decode COM marker segment data
We don't do anything with this (except log the contents if
JPEG2000_DEBUG is 1).

The motivation is that we now decode all marker segments that are
used in all JPEG2000 files I've seen so far, allowing us to make
remaining unknown marker types fatal.
2024-04-09 15:52:00 -04:00
Nico Weber
e05791f5dd LibGfx/JPEG2000: Decode QCD marker segment data
We now decode all required main header marker segments :^)
2024-04-09 15:52:00 -04:00
Nico Weber
99c1c685fc LibGfx/JPEG2000: Decode COD marker segment data 2024-04-09 15:52:00 -04:00
Nico Weber
d8811a83c9 LibGfx/JPEG2000: Decode SIZ marker segment data 2024-04-09 15:52:00 -04:00
Nico Weber
259c3fc7d3 LibGfx/JPEG2000: Check tile_part_length ("Psot") validity 2024-04-09 15:52:00 -04:00
Nico Weber
1393719f10 LibGfx/JPEG2000: Fix typo in an error mesage 2024-04-09 10:19:21 +02:00
Nico Weber
6bad4ea275 LibGfx/JPEG2000: Add parsing loop for tile-part headers
We don't interpret most of the marker data yet.

(We do have to interpret the SOT header to be able to skip the
tile data.)
2024-04-09 10:19:21 +02:00
Nico Weber
9eae6b3a90 LibGfx/JPEG2000: Add parsing loop for main header
We don't interpret any of the marker data yet.
2024-04-09 10:19:21 +02:00
Nico Weber
6c9d3f8c46 LibGfx/JPEG2000: Add constants for markers 2024-04-09 10:19:21 +02:00
Matthew Olsson
ff00d21d58 Everywhere: Mark a bunch of function parameters as NOESCAPE
This fixes the relevant warnings when running LibJSGCVerifier. Note that
the analysis is only performed over LibJS-adjacent code, but could be
performed over the entire codebase. That will have to wait for a future
commit.
2024-04-09 09:10:44 +02:00
Nico Weber
aada06757b LibGfx/JBIG2: Add early out to composite_bitbuffer()
The halftone region decoding procedure can draw patterns completely
outside the page bitmap. I haven't seen this in practice yet (not
many files use pattern/halftone segments), but it seems like it's
possible in theory and seems like a good thing to check for.
2024-04-08 06:27:51 +02:00
Nico Weber
438be7e2ca LibGfx/JBIG2: Implement halftone_region_decoding_procedure() and Annex C
Annex C describes how to read a grayscale bitmap with n bits per pixel:
It's encoded as n bilevel bitmaps, where each bilevel bitmap stores one
bit of the grayscale value (using a en.wikipedia.org/wiki/Gray_code,
which is named after Frank Gray and doesn't normally have much to do
with grayscale images).

A halftone region stores a grayscale bitmap and a linear coordinate
system the grayscale bitmap is in.  The grayscale bitmap is overlaid
the halftone region using the coordinate system, and each sample in
the grayscale bitmap is used as an index into a pattern dictionary
and the bitmap at that index is drawn at the current location.
This allows for efficient compression of ordered dithering
(but not error-diffusion dithering).

This does not yet implement halftone region decoding for MMR bitmaps.

The halftone region decoding procedure is the only way to call the
generic region decoding procedure with a skip pattern. This does
include code to compute the skip pattern, but support for that
is not yet implemented in the generic region decoding procedure,
so it'll error out when encountered. (I haven't yet found a file
using this feature, not a way to create such a file yet.)
2024-04-08 06:27:51 +02:00
Nico Weber
9d2c115c1c LibGfx/JBIG2: Implement decode_immediate_halftone_region()
...and stub out halftone_region_decoding_procedure().
2024-04-08 06:27:51 +02:00
Nico Weber
ca5b06cc4f LibGfx/JBIG2: Implement pattern_dictionary_decoding_procedure()
A pattern dictionary stores n bitmaps with the same dimensions w x h.
They're stored in a single bitmap of width `n * w` that's then cut
into n stripes.
2024-04-08 06:27:51 +02:00
Nico Weber
d27722ee00 LibGfx/JBIG2: Implement decode_pattern_dictionary()
It calls pattern_dictionary_decoding_procedure(), which is stubbed out.

No real behavior change yet.
2024-04-08 06:27:51 +02:00
Nico Weber
825b4d4e94 LibGfx/JBIG2: Tweak decode_immediate_generic_region()
Set context only for non-MMR.

No behavior change.
2024-04-08 06:27:51 +02:00
Lucas CHOLLET
cb5f30ae98 LibGfx/TIFF: Prevent recursion when following IFD pointers
Fixes oss-fuzz 66587.
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66587&sort=-opened&q=proj%3Aserenity%20TIFF&can=1
2024-04-07 06:45:38 +02:00
Nico Weber
2d4964b945 LibGfx/JBIG2: Support custom adaptive template pixels in refinement
The implementation is very similar to #23831.

I created the test exactly like in #23713, except that I replaced the
last four lines in the ini file with:

```
-txt -Param -rATX1 10
-txt -Param -rATY1 -1
-txt -Param -rATX2 4
-txt -Param -rATY2 15
```
2024-04-05 21:32:18 +02:00
Nico Weber
154d0bb458 LibGfx/JBIG2: Extract check_valid_adaptive_template_pixel()
No behavior change.
2024-04-05 21:32:18 +02:00
Nico Weber
a0a14296f9 LibGfx/JBIG2: Implement support for custom adaptive template pixels
...in the generic region decoding procedure (not yet in the generic
refinement region procedure). Not yet for EXTTEMPLATE though.

I haven't seen these being used in the wild, but:
* I want to optimize this code some, and it's probably good if it
  is feature complete (and well-tested) before being optimized
* Other PDF engines implement support for this
* The Pattern/Halftone feature (which we don't yet implement either,
  but which I'd like to implement because see previous two bullets)
  calls the generic region decoding procedure with custom adaptive
  template pixels
2024-04-04 11:44:50 -04:00
Timothy Flynn
683c08744a Userland: Avoid some conversions from rvalue strings to StringView
These are all actually fine, there is no UAF here. But once e.g.
`ByteString::view() &&` is deleted, these instances won't compile.
2024-04-04 11:23:21 +02:00