From 841e359341ceced7870d66c12586e434b48fee58 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sat, 18 Feb 2023 14:02:20 -0500 Subject: [PATCH] LibGfx: Correctly handle JPEG image with restart markers Restart markers are supposed to be applied every restart interval. However, in these loops macroblocks are counted taking the luma sampling factor into consideration. Meaning that we need to correct this factor when testing if we should reset the DC. Also, the decoder was discarding the first byte of every scan with a set restart interval, as `0 % n == 0` is always true. --- Userland/Libraries/LibGfx/JPEGLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/JPEGLoader.cpp b/Userland/Libraries/LibGfx/JPEGLoader.cpp index 31536717ea..3e914805fa 100644 --- a/Userland/Libraries/LibGfx/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPEGLoader.cpp @@ -383,7 +383,7 @@ static ErrorOr> decode_huffman_stream(JPEGLoadingContext& con for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) { u32 i = vcursor * context.mblock_meta.hpadded_count + hcursor; if (context.dc_reset_interval > 0) { - if (i % context.dc_reset_interval == 0) { + if (i != 0 && i % (context.dc_reset_interval * context.vsample_factor * context.hsample_factor) == 0) { context.previous_dc_values[0] = 0; context.previous_dc_values[1] = 0; context.previous_dc_values[2] = 0;