mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibGfx/JPEG: Still iterate over AC coefficients of a EOB targeted block
This commit is nonsense for anything else than SOF2 images with spectral approximation. For this particular case, skips like EOB or ZRL only apply to coefficients with a zero-history. This commit prepares the code to handle this behavior.
This commit is contained in:
parent
ef98b06dff
commit
902d0ab58e
Notes:
sideshowbarker
2024-07-17 00:16:31 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/902d0ab58e Pull-request: https://github.com/SerenityOS/serenity/pull/17907 Issue: https://github.com/SerenityOS/serenity/issues/4039 Reviewed-by: https://github.com/gmta Reviewed-by: https://github.com/nico ✅ Reviewed-by: https://github.com/trflynn89 ✅
|
@ -365,6 +365,12 @@ static ErrorOr<bool> read_eob(Scan& scan, u32 symbol)
|
|||
|
||||
scan.end_of_bands_run_count = additional_value + (1 << eob_base) - 1;
|
||||
|
||||
if (scan.end_of_bands_run_count >= 1) {
|
||||
// end_of_bands_run_count is decremented at the end of `build_macroblocks`.
|
||||
// This line compensate this effect.
|
||||
++scan.end_of_bands_run_count;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -390,6 +396,9 @@ static ErrorOr<void> add_ac(JPEGLoadingContext& context, Macroblock& macroblock,
|
|||
auto first_coefficient = max(1, scan.spectral_selection_start);
|
||||
|
||||
for (int j = first_coefficient; j <= scan.spectral_selection_end;) {
|
||||
if (scan.end_of_bands_run_count > 0)
|
||||
continue;
|
||||
|
||||
// AC symbols encode 2 pieces of information, the high 4 bits represent
|
||||
// number of zeroes to be stuffed before reading the coefficient. Low 4
|
||||
// bits represent the magnitude of the coefficient.
|
||||
|
@ -462,18 +471,18 @@ static ErrorOr<void> build_macroblocks(JPEGLoadingContext& context, Vector<Macro
|
|||
continue;
|
||||
}
|
||||
|
||||
// G.1.2.2 - Progressive encoding of AC coefficients with Huffman coding
|
||||
if (context.current_scan.end_of_bands_run_count > 0) {
|
||||
--context.current_scan.end_of_bands_run_count;
|
||||
continue;
|
||||
}
|
||||
|
||||
Macroblock& block = macroblocks[macroblock_index];
|
||||
|
||||
if (context.current_scan.spectral_selection_start == 0)
|
||||
TRY(add_dc(context, block, scan_component));
|
||||
if (context.current_scan.spectral_selection_end != 0)
|
||||
TRY(add_ac(context, block, scan_component));
|
||||
|
||||
// G.1.2.2 - Progressive encoding of AC coefficients with Huffman coding
|
||||
if (context.current_scan.end_of_bands_run_count > 0) {
|
||||
--context.current_scan.end_of_bands_run_count;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue