Commit graph

132 commits

Author SHA1 Message Date
Tim Ledbetter
438e9e146c LibGfx/JPEG: Refill reservoir if necessary when discarding bits
This condition was hit 157 times out of the 109,233 JPEG images in the
Govdocs1 corpus. This change allows all of these
images to load correctly.
2023-11-05 09:01:15 +01:00
MacDue
50d33f79fa LibGfx: Allow extracting paths from fonts and add Gfx::Path::text()
This updates fonts so rather than rastering directly to a bitmap, you
can extract paths for glyphs. This is then used to implement a
Gfx::Path::text("some text", font) API, that if given a vector font
appends the path of the text to your Gfx::Path. This then allows
arbitrary manipulation of the text (rotation, skewing, etc), paving the
way for Word Art in Serenity.
2023-11-05 02:46:46 +01:00
Andrew Kaster
1567332e34 Userland+Tests: Remove uses of direct file loading for BitmapFont
Route them through Core::Resource APIs instead.
2023-10-29 13:12:28 -06:00
Tim Ledbetter
1a4df4ffe7 LibGfx/ICC: Avoid overflow when constructing NamedColor2TagData 2023-10-26 10:59:22 +02:00
Tim Ledbetter
52f78d07b8 LibGfx/WOFF2: Ensure numTables is within expected range
An error is now returned if `numTables` is zero or greater than 4096.
While this isn't explicitly mentioned in the specification, subsequent
calculations will be incorrect if the value falls outside this range.
2023-10-26 08:39:26 +02:00
Tim Ledbetter
2311e28d63 LibGfx/BMPLoader: Mitigate potential overflows when decoding bitmap DIB 2023-10-25 05:52:29 +02:00
Tim Ledbetter
e9be1bcd09 LibGfx/WOFF2: Reject fonts with a compressed size larger than 10MiB
This prevents a potential OOM condition when the header is malformed.
2023-10-24 13:45:01 +02:00
Tim Ledbetter
af633523af LibGfx/WOFF2: Tolerate incorrect totalSfntSize in WOFF2 header
The specification says that this value is for reference only, so we
should be able to load a file where this value is incorrect.
2023-10-24 13:45:01 +02:00
Tim Ledbetter
cb16c217b8 Tests: Add regression tests for fixed OSS-Fuzz test cases 2023-10-24 07:30:04 +02:00
Tim Ledbetter
c62dded5cc Tests: Move image decoder test PNG to its own folder 2023-10-24 07:30:04 +02:00
Tim Ledbetter
c2112cde76 LibGfx/WOFF: Ensure header totalSfntSize matches expected value 2023-10-24 07:29:09 +02:00
circl
d76ad23492 Tests/LibGfx: Add test for top-down BMP files 2023-10-19 08:31:36 +02:00
Aliaksandr Kalenik
c2eaa0eb1c LibGfx: Fix crash during rasterizing glyphs containing only one point
Fixes https://github.com/SerenityOS/serenity/issues/20179
2023-10-18 01:16:21 +02:00
Andrew Kaster
09e3921ff8 Tests: Load Resources via Core::Resource URIs in FontHandling tests 2023-10-17 11:02:01 -06:00
MacDue
95bf6ddb8e LibGfx: Fix serializing Gfx::Bitmaps
a396bb0 removed the palette field but did not update the allocation size
in `Bitmap::serialize_to_byte_buffer()`. This led to a few crashes (I
noticed this from a drag/drop crash in the file manager).

Fixes #21434
2023-10-15 20:34:29 +02:00
Sam Atkins
a1c24ef3ad LibGfx: Remove infallible BitmapFont::create() factory function
This was only used in TestFontHandling. So, let's remove it, and use
the "create" name for the fallible one.
2023-10-10 14:36:25 +02:00
Tim Ledbetter
b25efa219b LibGfx/DDSLoader: Allow image dimensions that are not divisible by 4 2023-10-06 22:18:27 +02:00
Nicolas Ramz
b8f8b22aa5 LibGfx/ILBM: Add support for uncompressed files 2023-09-14 21:00:54 +01:00
Andreas Kling
13db3c5ce0 LibGfx: Convert FontDatabase APIs to use FlyString 2023-09-06 11:29:03 -04:00
Andreas Kling
545d8336b8 LibGfx: Convert Font APIs to return String instead of DeprecatedString 2023-09-06 11:29:03 -04:00
Nicolas Ramz
0986533c11 Meta+Tests: Add a fuzzer and a test for the ILBM decoder 2023-08-15 18:36:11 +01:00
Lucas CHOLLET
00240cb0b3 LibGfx/JPEGXL: Fix property 8
The first implementation of this property was just plain wrong. Looks
like this property isn't used a lot as I found the issue by reviewing
the code and not because of a specific image.

The test image is a 32x32 mosaic of alternating black and yellow pixels,
it was generated using this code:

Bitdepth 8
RCT 1
Width 32
Height 32

if W-WW-NW+NWW > -300
 - Set -1000
 - Set 900
2023-08-01 05:35:01 +02:00
Zaggy1024
66c9696687 LibGfx: Add initial ISO BMFF parsing and a utility to print file info
Currently, the `isobmff` utility will only print the media file type
info from the FileTypeBox (major brand and compatible brands), as well
as the names and sizes of top-level boxes.
2023-07-27 12:02:37 +01:00
Lucas CHOLLET
fa379b6e86 Tests/LibGfx: Use a JPEG XL image with a RCT transformation
This image is exactly the same as the previous one, excepted the RCT
transformation. It has been generated with:

Width 64
Height 64
RCT 29
Upsample 2
Bitdepth 10

if N > 300
  - NE -6
  - W 6
2023-07-26 08:44:17 +02:00
Lucas CHOLLET
89e2431517 Tests/LibGfx: Add a first test for JPEG XL images
This image uses the modular encoding with a very simple prediction tree.
It also makes use of two features: upsampling (x2 factor) and a
non-standard bit depth (10 bits). The file has been generated on
https://jxl-art.surma.technology/ , with the following input:

Width 64
Height 64
Upsample 2
Bitdepth 10

if N > 300
  - NE -6
  - W 6
2023-07-22 08:52:57 -04:00
Lucas CHOLLET
7b4630932b Tests/LibGfx: Call ImageDecoder::size() before frame()
Reordering these calls allow us to ensure that all encoders are able to
return the size of the image before they are requested to decode the
whole bitmap.
2023-07-18 21:17:10 +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
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
MacDue
d2766bd5fe Tests/LibGfx: Test we can decode everything in TinyVG
This tests that we can successfully parse the "everything" TVG files,
which make use of every feature in TinyVG.

Test files taken from https://github.com/TinyVG/examples (MIT).
2023-07-15 21:36:28 +02:00
Andreas Kling
d620dd516c LibGfx: Add Rect::unite_{horizontally,vertically}()
These functions unite the rect with another rect, but only in one axis.
2023-07-13 05:09:08 +02:00
Lucas CHOLLET
aff38ae80f Tests: Add a test for grayscale JPEGs with an App14 segment
See af14ed6b2e for more details.

This test has been created by artificially adding an App14 segment to an
existing grayscale image.
2023-07-05 20:58:25 +01:00
Lucas CHOLLET
3d2e4ba482 Tests: Add a test for JPEGs with an empty ICC profile
No encoder should declare an ICC profile with a size of zero, but some
does. This image has one of these dummy declaration.
2023-07-05 17:41:17 +01:00
MacDue
c04e0494df Tests: Add simple .tvg decoding test
yak.tvg is the Twemoji bison we all know and love.
2023-07-03 23:54:51 +02:00
Sebastian Zaha
d52a2ff10e LibGfx: Fix error & crash in Rect::closest_to
Assertion fails if the point is outside of the rect. This was introduced
in introduced in #18970 and causes serenity to crash when changing to 2x
resolution for a monitor, if the cursor after resizing is outside of
the new screen.

Added test to reproduce.
2023-07-01 23:27:00 +02:00
Nico Weber
3dd6638177 ICC: Strip trailing nul characters from MultiLocalizedUnicodeTagData
Having those trailing nuls is invalid per spec, but it happens in
practice (in already checked-in test files, no less).
2023-06-26 19:24:34 +01:00
Nico Weber
da48238fbd Tests: Add test for webp with color index transform and alpha_used=false
This just works at the moment after e19892a099, but if we ever do
the FIXME in ColorIndexingTransform::transform(), this test will
remind us to think of this case there too.

catdog-alert-13-alpha-used-false.webp is identical to
catdog-alert-13.web but with the byte at offset 0x2a changed from
0x10 to 0x00  -- that is, the bit in the VP8L header that stores
`is_alpha_used` is cleared.

See the commit message of e19892a099 for more information.
2023-06-20 11:35:03 +02:00
Nico Weber
cee1f9ba5d Tests: Factor out some repetitive code in TestImageDecoder.cpp
No real behavior change, mostly a code size reduction.
(Some tests check some more things now.)
2023-06-20 06:58:29 +02:00
Nico Weber
282e8357ed Tests: Move pbm, pgm, ppm test images into pnm/ subfolder 2023-06-19 06:42:00 -04:00
Nico Weber
ba7d80fcde Tests: Move tga test images into tga/ subfolder 2023-06-19 06:42:00 -04:00
Nico Weber
5d0b170f72 Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
Nico Weber
df0a82668b Tests: Copy webp ICC test inputs into test-inputs/icc
Two files are used both as test inputs for the webp decoder test and
for the icc profile test.

Use redundant copies of these two files for the two usecases, since
different parts of the files are used in both tests (and we could
remove the unneeded parts later).
2023-06-19 06:42:00 -04:00
Nico Weber
1ea99097aa Tests: Move icc test inputs into icc/ subfolder 2023-06-19 06:42:00 -04:00
Nico Weber
c0fe9cee97 Tests: Move webp test images into webp/ subfolder 2023-06-19 06:42:00 -04: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
52d17afd7e WebP: Add test for vertical ALPH chunk filtering_method 2023-06-09 04:35:19 -07:00
Nico Weber
a77b6c470a WebP: Add test image for vertical image filtering
I opened smolkling.webp in Photoshop, added a layer mask with a vertical
gradient, replaced the leftmost column with completely transparent
pixels (because the leftmost column is vertically predicted with the
horizontal filter too), and saved it as webp. That wasn't enough to
get a horizontal filter for the ALPH chunk though, so I also ran

    cwebp \
        -alpha_filter best \
        smolkling.webp \
        -o Tests/LibGfx/test-inputs/smolkling-vertical-alpha.webp

That did the trick.
2023-06-09 04:35:19 -07:00
Nico Weber
b0916d2133 WebP: Add test for gradient ALPH chunk filtering_method 2023-06-09 04:35:19 -07:00
Nico Weber
ec7eb78841 WebP: Add test image for gradient image filtering
I opened smolkling.webp in Photoshop, added a layer mask, and
scribbled a shape vaguely looking like the letter "C" on it.
I then saved it as a lossy webp and that was enough to end up
with filter method ¯\_(ツ)_/¯
2023-06-09 04:35:19 -07:00
Nico Weber
816674de36 WebP: Add test for horizontal ALPH chunk filtering_method 2023-06-09 04:35:19 -07:00
Nico Weber
737786f9a8 WebP: Add test image for horizontal image filtering
I opened smolkling.webp in Photoshop, added a layer mask with a
horizontal gradient, and saved it as webp. That wasn't enough to
get a horizontal filter for the ALPH chunk though, so I also ran

    cwebp \
        -alpha_filter best \
        smolkling-ps.webp \
        -o Tests/LibGfx/test-inputs/smolkling-horizontal-alpha.webp

That did the trick.

(Looks like doing the same with a vertical or diagonal gradient
_also_ produces a webp file with filtering_method 1, i.e. horizontal.)
2023-06-09 04:35:19 -07:00