diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index d06992edf1..f0ccfe6170 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -417,6 +417,15 @@ TEST_CASE(test_jpeg_grayscale_with_app14) TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 80, 80 })); } +TEST_CASE(test_jpeg_grayscale_with_weird_mcu_and_reset_marker) +{ + auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpg/grayscale_mcu.jpg"sv))); + EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + + TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 320, 240 })); +} + TEST_CASE(test_jpeg_malformed_header) { Array test_inputs = { diff --git a/Tests/LibGfx/test-inputs/jpg/grayscale_mcu.jpg b/Tests/LibGfx/test-inputs/jpg/grayscale_mcu.jpg new file mode 100644 index 0000000000..c75b0f4f39 Binary files /dev/null and b/Tests/LibGfx/test-inputs/jpg/grayscale_mcu.jpg differ diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index d3477f879f..a9b2aef925 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -1301,6 +1301,11 @@ static ErrorOr read_start_of_frame(JPEGStream& stream, JPEGLoadingContext& component.sampling_factors.horizontal = subsample_factors >> 4; component.sampling_factors.vertical = subsample_factors & 0x0F; + if (component_count == 1) { + // 4.8.2 Minimum coded unit: "If the compressed image data is non-interleaved, the MCU is defined to be one data unit." + component.sampling_factors = { 1, 1 }; + } + dbgln_if(JPEG_DEBUG, "Component subsampling: {}, {}", component.sampling_factors.horizontal, component.sampling_factors.vertical); if (i == 0) {