diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-02-20 00:28:17 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-22 09:22:45 +0100 |
commit | 8ed630a7ecd7e1b8fa38cdefd5e709925aacdefd (patch) | |
tree | 7baea863e092388098ff07af560e7b12b32f1986 /Userland/Libraries/LibGfx | |
parent | 3fefb696a36325f3938a4c5ef8839d41e83001a8 (diff) | |
download | serenity-8ed630a7ecd7e1b8fa38cdefd5e709925aacdefd.zip |
LibGfx: Put the code to reset the encoder in its own function
With it, we can also add a spec reference. And it will remind to anyone
who wants to add support for a new coding to not forget to update it.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/JPEGLoader.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGfx/JPEGLoader.cpp b/Userland/Libraries/LibGfx/JPEGLoader.cpp index c6557d0cd6..5fab0ca8ba 100644 --- a/Userland/Libraries/LibGfx/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPEGLoader.cpp @@ -363,6 +363,31 @@ static ErrorOr<void> build_macroblocks(JPEGLoadingContext& context, Vector<Macro return {}; } +static bool is_dct_based(StartOfFrame::FrameType frame_type) +{ + return frame_type == StartOfFrame::FrameType::Baseline_DCT + || frame_type == StartOfFrame::FrameType::Extended_Sequential_DCT + || frame_type == StartOfFrame::FrameType::Progressive_DCT + || frame_type == StartOfFrame::FrameType::Differential_Sequential_DCT + || frame_type == StartOfFrame::FrameType::Differential_Progressive_DCT + || frame_type == StartOfFrame::FrameType::Progressive_DCT_Arithmetic + || frame_type == StartOfFrame::FrameType::Differential_Sequential_DCT_Arithmetic + || frame_type == StartOfFrame::FrameType::Differential_Progressive_DCT_Arithmetic; +} + +static void reset_decoder(JPEGLoadingContext& context) +{ + // E.2.4 Control procedure for decoding a restart interval + if (is_dct_based(context.frame.type)) { + context.previous_dc_values[0] = 0; + context.previous_dc_values[1] = 0; + context.previous_dc_values[2] = 0; + return; + } + + VERIFY_NOT_REACHED(); +} + static ErrorOr<void> decode_huffman_stream(JPEGLoadingContext& context, Vector<Macroblock>& macroblocks) { if constexpr (JPEG_DEBUG) { @@ -385,9 +410,7 @@ static ErrorOr<void> decode_huffman_stream(JPEGLoadingContext& context, Vector<M u32 i = vcursor * context.mblock_meta.hpadded_count + hcursor; if (context.dc_restart_interval > 0) { if (i != 0 && i % (context.dc_restart_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; + reset_decoder(context); // Restart markers are stored in byte boundaries. Advance the huffman stream cursor to // the 0th bit of the next byte. |