From 8ed630a7ecd7e1b8fa38cdefd5e709925aacdefd Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Mon, 20 Feb 2023 00:28:17 -0500 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/JPEGLoader.cpp | 29 +++++++++++++++++++++--- 1 file 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 build_macroblocks(JPEGLoadingContext& context, Vector decode_huffman_stream(JPEGLoadingContext& context, Vector& macroblocks) { if constexpr (JPEG_DEBUG) { @@ -385,9 +410,7 @@ static ErrorOr decode_huffman_stream(JPEGLoadingContext& context, Vector 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.