ladybird/Tests/LibGfx/test-inputs/jpg
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
..
12-bit-progressive.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
12-bit.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
big_image.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
buggie-cmyk.jpg Tests: Add a test cmyk jpeg file with an embedded color profile 2024-01-25 15:53:44 +01:00
gradient_empty_icc.jpg Tests: Add a test for JPEGs with an empty ICC profile 2023-07-05 17:41:17 +01:00
grayscale_app14.jpg Tests: Add a test for grayscale JPEGs with an App14 segment 2023-07-05 20:58:25 +01:00
grayscale_mcu.jpg LibGfx+Tests: Support grayscale jpegs with 2x2 sampling and MCU reset 2024-01-30 05:35:22 +01:00
odd-restart.jpg LibGfx+Tests: Improve calculation of restart interval 2024-01-30 14:50:43 +01:00
oss-fuzz-testcase-59785.jpg Tests: Add regression tests for fixed OSS-Fuzz test cases 2023-10-24 07:30:04 +02:00
oss-fuzz-testcase-62584.jpg Tests: Add regression tests for fixed OSS-Fuzz test cases 2023-10-24 07:30:04 +02:00
oss-fuzz-testcase-63815.jpg LibGfx/JPEG: Refill reservoir if necessary when discarding bits 2023-11-05 09:01:15 +01:00
rgb24.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
rgb_components.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
several_scans_odd_number_mcu.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
several_scans.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
spectral_selection.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
successive_approximation.jpg Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
ycck-1111.jpg Tests/LibGfx: Add YCCK jpeg test files 2023-12-29 08:17:10 +00:00
ycck-2111.jpg Tests/LibGfx: Add YCCK jpeg test files 2023-12-29 08:17:10 +00:00
ycck-2112.jpg Tests/LibGfx: Add YCCK jpeg test files 2023-12-29 08:17:10 +00:00