From ef98b06dffef77c5c3c56e782b747cf9486e5fbc Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sun, 26 Feb 2023 01:53:24 -0500 Subject: [PATCH] LibGfx/JPEG: Split `spectral_approximation` This `u8` is actually two values of 4 bits. Let's store them separately to avoid confusion. --- .../LibGfx/ImageFormats/JPEGLoader.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index 7a1cc0502d..4728485b4c 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -199,9 +199,10 @@ struct Scan { // B.2.3 - Scan header syntax Vector components; - u8 spectral_selection_start {}; - u8 spectral_selection_end {}; - u8 successive_approximation {}; + u8 spectral_selection_start {}; // Ss + u8 spectral_selection_end {}; // Se + u8 successive_approximation_high {}; // Ah + u8 successive_approximation_low {}; // Al HuffmanStreamState huffman_stream; @@ -662,19 +663,23 @@ static ErrorOr read_start_of_scan(Stream& stream, JPEGLoadingContext& cont current_scan.spectral_selection_start = TRY(stream.read_value()); current_scan.spectral_selection_end = TRY(stream.read_value()); - current_scan.successive_approximation = TRY(stream.read_value()); + auto const successive_approximation = TRY(stream.read_value()); + current_scan.successive_approximation_high = successive_approximation >> 4; + current_scan.successive_approximation_low = successive_approximation & 0x0F; - dbgln_if(JPEG_DEBUG, "Start of Selection: {}, End of Selection: {}, Successive Approximation: {}", + dbgln_if(JPEG_DEBUG, "Start of Selection: {}, End of Selection: {}, Successive Approximation High: {}, Successive Approximation Low: {}", current_scan.spectral_selection_start, current_scan.spectral_selection_end, - current_scan.successive_approximation); + current_scan.successive_approximation_high, + current_scan.successive_approximation_low); // FIXME: Support SOF2 jpegs with current_scan.successive_approximation != 0 - if (current_scan.spectral_selection_start > 63 || current_scan.spectral_selection_end > 63 || current_scan.successive_approximation != 0) { - dbgln_if(JPEG_DEBUG, "ERROR! Start of Selection: {}, End of Selection: {}, Successive Approximation: {}!", + if (current_scan.spectral_selection_start > 63 || current_scan.spectral_selection_end > 63 || successive_approximation != 0) { + dbgln_if(JPEG_DEBUG, "ERROR! Start of Selection: {}, End of Selection: {}, Successive Approximation High: {}, Successive Approximation Low: {}!", current_scan.spectral_selection_start, current_scan.spectral_selection_end, - current_scan.successive_approximation); + current_scan.successive_approximation_high, + current_scan.successive_approximation_low); return Error::from_string_literal("Spectral selection is not [0,63] or successive approximation is not null"); }