serenity/Tests/LibGfx
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
..
test-inputs LibGfx+Tests: Improve calculation of restart interval 2024-01-30 14:50:43 +01:00
BenchmarkGfxPainter.cpp LibGfx+Tests: Remove code unnecessary after 9e7c16d0a4 2023-02-01 08:56:56 -05:00
BenchmarkJPEGLoader.cpp Tests: Move jpg test images into jpg/ subfolder 2023-06-19 06:42:00 -04:00
CMakeLists.txt LibGfx: Fix off-by-some in Painter::draw_scaled_bitmap_with_transform() 2024-01-10 09:38:13 +01:00
TestDeltaE.cpp LibGfx: Add DeltaE() function 2023-04-30 05:57:20 +02:00
TestFontHandling.cpp LibGfx: Allow extracting paths from fonts and add Gfx::Path::text() 2023-11-05 02:46:46 +01:00
TestGfxBitmap.cpp LibGfx: Fix serializing Gfx::Bitmaps 2023-10-15 20:34:29 +02:00
TestICCProfile.cpp LibGfx/ICC: Implement conversion between different connection spaces 2023-12-04 08:02:36 +00:00
TestImageDecoder.cpp LibGfx+Tests: Improve calculation of restart interval 2024-01-30 14:50:43 +01:00
TestPainter.cpp LibGfx: Fix off-by-some in Painter::draw_scaled_bitmap_with_transform() 2024-01-10 09:38:13 +01:00
TestParseISOBMFF.cpp LibGfx: Add initial ISO BMFF parsing and a utility to print file info 2023-07-27 12:02:37 +01:00
TestRect.cpp LibGfx: Add Rect::unite_{horizontally,vertically}() 2023-07-13 05:09:08 +02:00
TestScalingFunctions.cpp LibGfx+Everywhere: Change Gfx::Rect to be endpoint exclusive 2023-05-23 12:35:42 +02:00
TestWOFF.cpp LibGfx/WOFF: Ensure header totalSfntSize matches expected value 2023-10-24 07:29:09 +02:00
TestWOFF2.cpp LibGfx/WOFF2: Ensure numTables is within expected range 2023-10-26 08:39:26 +02:00