1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-10-30 03:32:34 +00:00
serenity/Tests/LibGfx/test-inputs
Nico Weber 69964e10f4 LibGfx+Tests: Improve calculation of restart interval
JPEGs can store a `restart_interval`, which controls how many
minimum coded units (MCUs) apart the stream state resets.
This can be used for error correction, decoding parts of a jpeg
in parallel, etc.

We tried to use

    u32 i = vcursor * context.mblock_meta.hpadded_count + hcursor;
    i % (context.dc_restart_interval *
         context.sampling_factors.vertical *
         context.sampling_factors.horizontal) == 0

to check if we hit a multiple of an MCU.

`hcursor` is the horizontal offset into 8x8 blocks, vcursor the
vertical offset, and hpadded_count stores how many 8x8 blocks
we have per row, padded to a multiple of the sampling factor.

This isn't quite right if hcursor isn't divisible by both
the vertical and horizontal sampling factor. Tweak things so
that they work.

Also rename `i` to `number_of_mcus_decoded_so_far` since that
what it is, at least now.

For the test case, I converted an existing image to a ppm:

    Build/lagom/bin/image -o out.ppm \
        Tests/LibGfx/test-inputs/jpg/12-bit.jpg

Then I resized it to 102x77px in Photoshop and saved it again.
Then I turned it into a jpeg like so:

    path/to/cjpeg \
        -outfile Tests/LibGfx/test-inputs/jpg/odd-restart.jpg \
        -sample 2x2,1x1,1x1 -quality 5 -restart 3B out.ppm

The trick here is to:

a) Pick a size that's not divisible by the data size width (8),
   and that when rounded to a block size (13) still isn't divisible
   by the subsample factor -- done by picking a width of 102.
b) Pick a huffman table that doesn't happen to contain the bit
   pattern for a restart marker, so that reading a restart marker
   from the bitstream as data causes a failure (-quality 5 happens
   to do this)
c) Pick a restart interval where we fail to skip it if our calculation
   is off (-restart 3B)

Together with #22987, fixes #22780.
2024-01-30 14:50:43 +01:00
..
bmp Tests: Add regression tests for fixed OSS-Fuzz test cases 2023-10-24 07:30:04 +02:00
dds LibGfx/DDSLoader: Allow image dimensions that are not divisible by 4 2023-10-06 22:18:27 +02:00
icc LibGfx/TIFF: Add support for the ICCProfile tag 2023-12-02 10:36:02 +01:00
ico LibGfx/ICO: Do not try to decode a mask if we already reached EOF 2024-01-07 12:32:02 -05:00
ilbm LibGfx/ILBMLoader: Properly display images with a bitplane mask 2024-01-18 13:59:17 +01:00
jpg LibGfx+Tests: Improve calculation of restart interval 2024-01-30 14:50:43 +01:00
jxl LibGfx/JPEGXL: Fix property 8 2023-08-01 05:35:01 +02:00
png Tests: Add a png in Display P3 that shows up as solid color in sRGB 2024-01-12 16:20:46 -07:00
pnm Tests: Add a pam cmyk test file 2024-01-26 07:36:53 +01:00
tga Tests: Move tga test images into tga/ subfolder 2023-06-19 06:42:00 -04:00
tiff LibGfx/TIFF: Add support for CMYK 2024-01-24 22:16:22 -07:00
tvg LibGfx/TinyVG: Avoid OOM if header contains a bogus color table size 2023-12-02 10:47:39 +01:00
webp Tests: Add test for webp with color index transform and alpha_used=false 2023-06-20 11:35:03 +02:00
woff LibGfx/WOFF: Ensure header totalSfntSize matches expected value 2023-10-24 07:29:09 +02:00
woff2 LibGfx/WOFF2: Ensure numTables is within expected range 2023-10-26 08:39:26 +02:00
download-animation.gif LibGfx: Move TestImageDecoder over to input file approach in 8cfabbcd93 2023-02-01 08:56:56 -05:00
loop_forever.avif LibGfx: Add initial ISO BMFF parsing and a utility to print file info 2023-07-27 12:02:37 +01:00
TestFont.font LibGfx: Move TestFontHandling over to input file approach in 8cfabbcd93 2023-02-01 08:56:56 -05:00