1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

LibGfx/JPEG: Handle ZRL as a special case

When reading the stream, interpreted as a normal value 0xF0 means skip
15 values and assign the 16th to 0. On the other hand, the marker ZRL
- which has the value 0xF0, means skip 16 values. For baseline JPEGs,
ZRL doesn't need to be interpreted differently as writing the 16th value
has no consequence. This is no longer the case with refining scans.
That's why this patch implement correctly ZRL.
This commit is contained in:
Lucas CHOLLET 2023-03-17 22:10:49 -04:00 committed by Linus Groh
parent 731c876ff7
commit 8806e66f66

View file

@ -395,20 +395,30 @@ static ErrorOr<void> add_ac(JPEGLoadingContext& context, Macroblock& macroblock,
u32 to_skip = 0;
Optional<u8> saved_symbol;
bool in_zrl = false;
for (int j = first_coefficient; j <= scan.spectral_selection_end; ++j) {
// 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.
if (scan.end_of_bands_run_count == 0 && !saved_symbol.has_value()) {
if (!in_zrl && scan.end_of_bands_run_count == 0 && !saved_symbol.has_value()) {
saved_symbol = TRY(get_next_symbol(scan.huffman_stream, ac_table));
if (!TRY(read_eob(scan, *saved_symbol))) {
to_skip = *saved_symbol >> 4;
in_zrl = *saved_symbol == JPEG_ZRL;
if (in_zrl) {
to_skip++;
saved_symbol.clear();
}
}
}
if (to_skip > 0) {
--to_skip;
if (to_skip == 0)
in_zrl = false;
continue;
}