1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-12 02:30:30 +09:00
Commit graph

26 commits

Author SHA1 Message Date
Nico Weber
633f509eb4 LibGfx/WebP: Move TransformType to WebPSharedLossless.h 2024-05-31 22:39:25 +02:00
Nico Weber
b50702f490 LibGfx/WebP: Move ImageKind to WebPSharedLossless.h 2024-05-31 22:39:25 +02:00
Nico Weber
286cc6f905 LibGfx/WebPLoader: Prefix a few dbgln_if()s with chunk name 2024-05-31 22:39:25 +02:00
Nico Weber
756a8fa02d LibGfx/WebP: Move kCodeLengthCodeOrder to WebPSharedLossless.h
...and make it an Array while at it.

(This makes it look a little less like the spec, but that seems
worth it.)

No behavior change.
2024-05-26 19:02:49 +02:00
Nico Weber
ed2658d72c LibGfx/WebP: Move some to-be-shared code to WebPSharedLossless.h
No behavior change. No measurable performance different either.

(I tried `hyperfine 'Build/lagom/bin/image --no-output foo.webp'`
for a few input images before and after this change, and I didn't
see a difference. I also tried if moving both
Gfx::CanonicalCode::read_symbol() and
Compress::CanonicalCode::read_symbol() inline, and that didn't
help either.)
2024-05-20 13:17:34 -04:00
Nico Weber
c174adc6b1 LibGfx/WebPLossless: Remove a useless non-spec comment
There's already a spec comment saying the same thing a few lines
further down, just move that up.

No behavior change.
2024-05-07 11:10:06 -04:00
Nico Weber
7b3cc2e055 LibGfx/WebPLossless: Add spec ref about color indexing modifying width
No behavior change. This got clarified here:
4688320
2024-05-07 11:10:06 -04:00
Nico Weber
26b3e31f2e LibGfx/WebPLossless: Make width_bits reading look more like in the spec
No behavior change.
2024-05-07 11:10:06 -04:00
Nico Weber
c1b289c144 LibGfx/WebPLossless: Add spec note about combining predicted values
No behavior change. This got clarified in the spec in
4638649
2024-05-07 11:10:06 -04:00
Nico Weber
3662eea0ac LibGfx/WebPLossless: Update spec comments for reading max_symbol
This used to be misleading in the spec, but that was fixed in
4674031

Update the comments to match.

Also, a check we already had got added to the spec in
4674032
so add a citation for that.

No behavior change.
2024-05-07 11:10:06 -04:00
Nico Weber
a511f5507c LibGfx/WebPLossless: Add spec comment about transform order
This used to not be mentioned in the spec, but it got added
based on our feedback:
4637757
2024-05-07 11:10:06 -04:00
Nico Weber
e69a0fa7d3 LibGfx/WebPLossless: Add a spec comment
No behavior change. Makes things flow better with the comment I'm
about to add in the next commit.
2024-05-07 11:10:06 -04:00
Nico Weber
5897e9bd29 LibGfx/WebPLossless: Move around a spec comment
That way, we don't need a comment that wasn't from the spec.
No behavior change.
2024-05-07 11:10:06 -04:00
Nico Weber
076a8e5d0b LibGfx/WebPLossless: Remove "AMENDED" in spec comments
No behavior change. This corresponds to this spec change:
4567695
2024-05-07 11:10:06 -04:00
Nico Weber
05bb657b8b LibGfx/WebPLossless: Replace num_code_lengths check with VERIFY
No behavior change. This corresponds to this spec change:
4779444
2024-05-07 11:10:06 -04:00
Nico Weber
d0a2cf2dce LibGfx/WebPWriter: Implement basic lossless webp writing
This doesn't use any transforms yet (in particular not the predictor
transform), and doesn't do anything else that actually compresses the
data.

It also give all 256 values code length 8 unconditionally. This means
the huffman trees are not data-dependent at all and provide no
compression. It also means we can just write out the image data
unmodified.

So the output is fairly large. But it _is_ a valid lossless webp file.

Possible follow-ups, to improve compression later:
1. Use actual byte distributions to create huffman trees, to get
   huffman compression.
2. If the distribution has just 1 element, write a simple code length
   code (that way, images that have alpha 0xff everywhere need to store
   no data for alpha).
3. Add backref support, to get full deflate(ish) compression of pixels.
4. Add predictor transform.
5. Consider writing different sets of prefix codes for every 16x16 tile
   (by writing a meta prefix code image).

(It might be nice to make the follow-ups optional, so that this can also
be used as a webp example file generator.)
2024-05-06 17:32:19 +02:00
Nico Weber
dd020a108a LibGfx/WebP: Rename two variables to be a bit clearer
No behavior change.
2024-05-04 13:46:53 +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
Nico Weber
7cb12e057f LibGfx/WebPLossless: Fix out-of-bounds write in color indexing transform
If a lossless webp has 3 or 4 colors, it uses 2 bits per pixel to
store an offset into a "color index" (which the spec explicitly does
not call palette since it says the 'color cache' is more like that).
This way, it can pack 4 pixels into a single pixel.

If the width of the output image wasn't evenly divisble by 4,
we used to write out-of-bounds in the last few columns of each
row, since we used to always write all 4 pixels.

Found by clusterfuzz. Probably fixes
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66082

While here, spruce up the comments very slightly.
2024-03-20 09:09:47 +01:00
Nico Weber
b37f3c86fd LibGfx/WebPLoaderLossless: Fix grammar-o in comment 2024-01-29 09:12:06 -05:00
Tim Schumacher
197331c922 AK: Reject BitStream reads beyond EOF by default
The only exception to this is the lossless WebP decoder, which
legitimately relies on this behavior, even upstream.
2023-12-01 12:48:18 +01:00
Andreas Kling
a396bb0c0b LibGfx: Remove indexed palette formats from Bitmap and Painter
Nobody was actually using these formats anymore, and this simplifies
and shrinks the code. :^)
2023-10-12 07:39:05 +02:00
Sergey Bugaev
8ebddc1ff6 LibGfx: Misc 32-bit build fixes 2023-09-06 07:21:07 -06:00
Nico Weber
e19892a099 WebP/Lossless: Set alpha to 0xff if is_alpha_used is false in header
simple-vp8l-alpha-used-false.webp is a copy of simple-vp8l.webp,
with the byte at offset 0x18 changed from 0x10 to 0x00 -- that
is, the bit in the VP8L header that stores `is_alpha_used` is cleared.

We would already allocated a BGRx8888 instead of a BGRA8888 bitmap,
but keep actual alpha data in the `x` channel.

That lead to at least `image` still writing a PNG with an alpha channel.
So explicitly set the alpha channel to 0xff when is_alpha_used is false,
to make sure all consumers of decoded lossless webp data have behavior
consistent with other webp readers.

In practice, webp encoders usually don't write files that have
`is_alpha_used` set to false and then write actual alpha data to their
output. So this is rarely observable. However, for example for
lossy+ALPH webp files, the lossless webp used to store the ALPH channel
has `is_alpha_used` set to false and all channels but green are 0
(since the lossless green channel stores the alpha channel of a
lossy+ALPH webp). So if we dump such a bitmap to a standalone webp
file (e.g. with the temporary debugging code in fc3249a1ca),
then without this commit here, `image` would convert that webp to
a fully transparent webp, while other webp software would correctly
display the green image with opaque alpha.
2023-06-18 18:47:47 +02:00
Nico Weber
65c7145e69 LibGfx/WebP: Move lossless decoder to its own file
Pure code move (except of removing `static` on the two public functions
in the new header), not behavior change.
2023-05-08 12:52:05 +02:00