ladybird/Tests
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
..
AK AK+Everywhere: Remove JsonValue APIs with implicit default values 2024-01-21 15:47:53 -07:00
JSSpecCompiler JSSpecCompiler: Always treat trailing MemberAccess as punctuation 2024-01-21 14:57:10 -07:00
Kernel LibFileSystem+Everywhere: Return ByteString from read_link() 2024-01-16 08:42:34 +00:00
LibAudio LibAudio: Test reading and writing of wav files 2024-01-08 07:20:11 -07:00
LibC LibFileSystem+Everywhere: Return ByteString from read_link() 2024-01-16 08:42:34 +00:00
LibCompress Tests/LibCompress: Add a reproducer of oss-fuzz issue 58046 2024-01-13 15:17:08 -07:00
LibCore AK+LibCore: Add BufferedSocket::can_read_up_to_delimiter() 2024-01-21 21:13:58 +01:00
LibCpp Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibCrypto LibCrypto: Add support for the POSIX cksum algorithm 2024-01-18 18:01:26 +03:30
LibDiff LibDiff: Fix wrong index used when prepending context lines 2023-09-11 12:10:50 +01:00
LibEDID AK: Rename AK::FixedPoint::round to rint and fix a rounding error 2023-08-14 14:20:45 -06:00
LibELF LibFileSystem+Everywhere: Return ByteString from read_link() 2024-01-16 08:42:34 +00:00
LibGfx LibGfx+Tests: Improve calculation of restart interval 2024-01-30 14:50:43 +01:00
LibGL Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibGLSL Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibIMAP Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibJS Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibLocale LibLocale+LibJS+ClockSettings: Make date time format APIs infallible 2023-08-23 05:29:21 +02:00
LibMarkdown Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibPDF Tests: Add a pdf with text rotation 2024-01-18 14:01:30 +01:00
LibRegex LibRegex: Correct And/Or and inversion interplay semantics 2024-01-11 11:36:09 +01:00
LibSQL LibSQL: Add a helper to convert a SQL::Value to a UnixDateTime 2024-01-10 23:26:40 +01:00
LibTest LibTest: Add more numeric generators 2024-01-12 16:42:51 -07:00
LibTextCodec LibTextCodec+Everywhere: Port Decoders to new Strings 2023-02-19 17:15:47 +01:00
LibThreading LibThreading: Improve resiliancy of timed threading tests 2023-05-24 00:25:35 +02:00
LibTimeZone LibTimeZone+Userland: Change timezone functions to use UnixDateTime 2023-05-24 23:18:07 +02:00
LibTLS Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibTTF LibGfx/OpenType: Ensure Cmap subtable offset is within expected range 2023-11-11 22:20:17 +01:00
LibUnicode LibUnicode: Add IDNA::to_ascii 2023-12-10 08:04:58 -05:00
LibVideo Tests: Add regression tests for fixed OSS-Fuzz test cases 2023-10-24 07:30:04 +02:00
LibWasm Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibWeb LibWeb: Account for CSS transform in Element::getClientRects() 2024-01-30 14:50:25 +01:00
LibWebView LibWebView: Fix sanitizing about scheme URLs 2024-01-13 13:41:09 -05:00
LibXML LibXML: Actually append resolved references when parsing content 2023-07-23 16:09:12 +02:00
Spreadsheet Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
UserspaceEmulator Everywhere: Remove references to UserspaceEmulator 2024-01-29 20:20:55 +00:00
Utilities Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
CMakeLists.txt LibWebView: Protect URL highlighting against partially-typed URLs 2023-10-28 19:03:19 +02:00