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.
This commit is contained in:
Lucas CHOLLET 2023-02-18 14:02:20 -05:00 committed by Sam Atkins
parent 3d9ba87077
commit 841e359341

View file

@ -383,7 +383,7 @@ static ErrorOr<Vector<Macroblock>> 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;