1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 23:35:08 +00:00
Commit graph

241 commits

Author SHA1 Message Date
Lucas CHOLLET
271d0015fe LibGfx/JPEGXL: Add support for x4 and x8 upsampling
All the logic is exactly the same as for x2 upsampling, so this commit
essentially boils down to adding arrays for default weights and the
logic to select the correct array.
2023-07-24 10:28:36 -04:00
Lucas CHOLLET
9975bdb2d1 LibGfx/JPEGXL: Align the stream to byte boundary before reading a frame
As this is stated in the spec, all frames are byte-aligned.
2023-07-22 08:52:57 -04:00
Lucas CHOLLET
a2955501d3 LibGfx/JPEGXL: Don't decode the header twice
This is something I missed when I ported the JPEG XL decoder to the new
plugin interface (decoding the header at creation). First sorry because
that's entirely my fault, second sorry because a test should have caught
that.
2023-07-21 22:25:56 -04:00
Lucas CHOLLET
65565d377b LibGfx/JPEGXL: Accept images with high bit depth
Instead of rejecting them, we truncate each value to 8 bits. This is
clearly a hack, but given the lack of support of variable bit-depth in
`Bitmap` this is the only sensible change.

This allows us to display "Iceberg" on https://jpegxl.info/art/.
2023-07-21 19:34:21 -04:00
Lucas CHOLLET
e8a63eeb0e LibGfx/JPEGXL: Add a JPEG-XL decoder :^)
JPEG-XL is a new image format standardized by the same committee as the
original JPEG image format. It has all the nice feature of recent
formats, and great compression ratios. For more details, look at:
https://jpegxl.info/

This decoder is far from being feature-complete, as it features a grand
total of 60 FIXMEs and TODOs but anyway, it's still a good start.

I developed this decoder in the Serenity way, I just try to decode a
specific image while staying as close as possible to the specification.

Considering that the format supports a lot of options, and that we
basically support only one possibility for each of them, I'm pretty sure
that we can only decode the image I've developed this decoder for.

Which is:
0aff 3ffa 9101 0688 0001 004c 384b bc41
5ced 86e5 2a19 0696 03e5 4920 8038 000b
2023-07-21 10:47:34 -06:00
Lucas CHOLLET
b918dcd4db LibGfx/TGA: Compute the number of pixels with a wider type
Both width and height are stored in an u16 inside the TGA header,
computing the total number of pixel without using another type can
easily lead to overflows.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55309&q=serenity&can=2
2023-07-19 06:52:45 +02:00
Lucas CHOLLET
806808f406 LibGfx: Provide a default implementation for animation-related methods
Most image decoders that we have only support non-animated images,
providing a default implementation for them allows to remove quite some
code.
2023-07-18 14:34:35 +01:00
Lucas CHOLLET
7acb656826 LibGfx: Comment ImageDecoderPlugin's interface
This is done as an effort to unify the behavior of every plugin. See
#19893 for more details.
2023-07-18 14:34:35 +01:00
Lucas CHOLLET
4291288a31 LibGfx: Remove ImageDecoderPlugin::initialize()
No plugin is currently overriding the default implementation, which is a
no-op. So we can safely delete it.
2023-07-18 14:34:35 +01:00
Lucas CHOLLET
3752facfbc LibGfx: Don't assume that image decoder plugin creation succeeds
An image with an incorrect header should fail at this step, so we have
to handle that without crashing.

This should have been done in 7b72bf29.
2023-07-18 14:34:35 +01:00
Lucas CHOLLET
38dd4168be LibGfx/ICO: Decode the header in create() and remove initialize()
This is done as a part of #19893.
2023-07-17 20:17:08 +01:00
Lucas CHOLLET
5d94bb4fcc LibGfx/PNG: Remove the useless HeaderDecoded state 2023-07-17 06:49:03 +01:00
Lucas CHOLLET
a173275afa LibGfx/PNG: Reject files that doesn't start with a IHDr chunk 2023-07-17 06:49:03 +01:00
Lucas CHOLLET
8d907b6535 LibGfx/PNG: Don't use a loop to read chunks in decode_png_ihdr()
This chunk is the first one, so we can remove that loop.
2023-07-17 06:49:03 +01:00
Lucas CHOLLET
ff6d82c3e7 LibGfx/PNG: Decode the header in create() and remove initialize()
This is done as a part of #19893. As `create()` is now the last user of
`decode_png_ihdr()`, we can easily make it return an `ErrorOr`.
2023-07-17 06:49:03 +01:00
Lucas CHOLLET
07f72b6d41 LibGfx/PNG: Don't try to guess if IHDR has been decoded 2023-07-17 06:49:03 +01:00
Lucas CHOLLET
07d3232f2d LibGfx/PNG: Use PNG specific vocabulary over a generic name 2023-07-17 06:49:03 +01:00
Lucas CHOLLET
0520490577 LibGfx/DDS: Read the header in create() and remove initialize()
This is done as a part of #19893.
2023-07-17 06:44:37 +01:00
Lucas CHOLLET
aa9470880f LibGfx/DDS: Prefer static constexpr Array over Vector<u32> 2023-07-17 06:44:37 +01:00
Lucas CHOLLET
742897519d LibGfx/DDS: Move the code to read the header in its own function 2023-07-17 06:44:37 +01:00
Lucas CHOLLET
76efdaeecd LibGfx/DDS: Save the format in the context
This allows us to simplify the signature of a few functions.
2023-07-17 06:44:37 +01:00
Lucas CHOLLET
4cb7573582 LibGfx/DDS: Only use a FixedMemoryStream
This allows us to drop the data pointer in the `DDSLoadingContext`.
2023-07-17 06:44:37 +01:00
Lucas CHOLLET
8946c0c104 LibGfx/DDS: Don't double-check the magic number
This is already done in `decode_dds()`.
2023-07-17 06:44:37 +01:00
Lucas CHOLLET
c336cef065 LibGfx/BMP: Decode the header in create() and remove initialize()
This is done as a part of #19893.
2023-07-17 06:39:57 +01:00
Lucas CHOLLET
7b72bf2910 LibGfx: Don't assume that image decoder plugin creation succeeds
An image with an incorrect header should fail at this step, so we have
to handle that without crashing.
2023-07-17 06:39:57 +01:00
Lucas CHOLLET
35dcd16ea6 LibGfx/TinyVG: Decode the header in create() and remove initialize()
This is done as a part of #19893.
2023-07-16 20:39:51 +02:00
MacDue
cf05da131f LibGfx/TinyVG: Close polygon path in OutlineFillPolygon 2023-07-15 21:36:28 +02:00
MacDue
a853f7b133 LibGfx/TinyVG: Map gradients to equivalent SVG gradients 2023-07-15 21:36:28 +02:00
MacDue
fb61082a6c LibGfx/TinyVG: Don't move fill/stroke styles that are used in a loop 2023-07-15 21:36:28 +02:00
MacDue
bebfb81c85 LibGfx/TinyVG: Parse and ignore line_width in paths
TinyVG allows varying the line width along a path, this is not supported
in LibGfx so we just ignore this (but still need to parse the field).
2023-07-15 21:36:28 +02:00
Lucas CHOLLET
500097de82 LibGfx/GIF: Decode the header in create()
Again, header includes the logical screen descriptor here. This is done
as a part of #19893.
2023-07-15 09:44:30 +02:00
Lucas CHOLLET
294217586b LibGfx/GIF: Move the code to read the header to its own function
By header, I include the logical screen descriptor here, so all the
information that is not specific to each frame.
2023-07-15 09:44:30 +02:00
Lucas CHOLLET
b8bc84a3e8 LibGfx/GIF: Only use a FixedMemoryStream
This allows us to drop the data pointer in the `GIFLoadingContext`.
2023-07-15 09:44:30 +02:00
Lucas CHOLLET
1192e46c09 LibGfx/GIF: Don't read the header twice
This is already done in `load_gif_frame_descriptors()`. As the method
`initialize()` is now empty, we can delete it.
2023-07-15 09:44:30 +02:00
Lucas CHOLLET
8ef5170bd5 LibGfx/WebP: Remove a typo
:redthakis:
2023-07-15 09:34:07 +02:00
Lucas CHOLLET
4adef05e6d LibGfx/WebP: Decode the first chunk in create()
And remove `initialize()`.

This is done as a part of #19893.
2023-07-15 09:34:07 +02:00
MacDue
57c81c1719 LibGfx: Lazily load TinyVG image data
This matches the behavior of other decoders, and ensures just getting
the size (e.g. for the `file` command) does not read the whole file.
2023-07-14 06:51:05 +02:00
MacDue
753cf04be8 LibGfx: Allow requesting vector graphic frames from ImageDecoder
Only supported for plugins that set is_vector() to true. This returns
the frames as Gfx::VectorGraphics, which allows painting/rasterizing
them with arbitrary transforms and scales.
2023-07-14 06:51:05 +02:00
Lucas CHOLLET
b14d51ba1b LibGfx/QOI: Decode the header in create() and remove initialize()
This is done as a part of #19893.
2023-07-14 06:17:12 +02:00
Lucas CHOLLET
5fd1ee0365 LibGfx/QOI: Remove useless parameters from member functions
Both `decode_[header,image]_and_update_context()` used to take a
`Stream&` as parameter, but they are always called with the field
`m_context.stream` so no need to take it as a parameter.
2023-07-14 06:17:12 +02:00
Lucas CHOLLET
1ae772c7d3 LibGfx/JPEG: Decode the header in create()
This is done as a part of #19893.
2023-07-14 06:16:56 +02:00
Lucas CHOLLET
2f125b86aa LibGfx/JPEG: Remove the unused method initialize() 2023-07-14 06:16:56 +02:00
Lucas CHOLLET
92fa1efc76 LibGfx/TGA: Decode the header in create() and remove initialize()
This is done as a part of #19893.
2023-07-12 23:37:32 +02:00
Lucas CHOLLET
a05516bb3e LibGfx/TGA: Make TGAImageDecoderPlugin::decode_tga_header() fallible 2023-07-12 23:37:32 +02:00
Lucas CHOLLET
e0ff3fbfad LibGfx/TGA: Default initialize the TGAHeader in the context 2023-07-12 23:37:32 +02:00
Nico Weber
8c13b83a84 LibGfx/PNGWriter: Use a better limit for scanline capactiy
One scanline is width pixels long, not height pixels.

No measurable performance difference, but it annoys me every time I look
at this file.
2023-07-12 07:51:54 +01:00
Lucas CHOLLET
9ff706339b LibGfx/PortableFormat: Read the header during initialization
This is done as a part of #19893.
2023-07-11 14:16:33 +01:00
Lucas CHOLLET
f3ff9c26bc LibGfx/PortableFormat: Simplify the State enum
This enum used to store very precise state about the decoding process,
let's simplify that by only including two steps: HeaderDecoder and
BitmapDecoded.
2023-07-11 14:16:33 +01:00
Lucas CHOLLET
f6ce06d56b LibGfx/PortableFormat: Extract header reading in its own function 2023-07-11 14:16:33 +01:00
Lucas CHOLLET
e72293fbc7 LibGfx/PortableFormat: Remove PortableImageDecoderPlugin::initialize() 2023-07-11 14:16:33 +01:00