From 05c8ad4e91e80507bf697938273c65a8dfbb8d53 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sat, 1 Jul 2023 23:56:23 -0400 Subject: [PATCH] LibGfx/JPEG: Write quantization tables in the zigzag ordering This is clearly something I missed during the first implementation. The specification is crystal clear about it: "The quantization elements shall be specified in zig-zag scan order." This patch fixes the weird behavior we had when using the quantization table. --- Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp index ba7eb37e46..a9b5e64d5e 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGWriter.cpp @@ -398,8 +398,8 @@ ErrorOr add_quantization_table(Stream& stream, QuantizationTable const& ta // Pq and Tq TRY(stream.write_value((0 << 4) | table.id)); - for (auto coefficient : table.table) - TRY(stream.write_value(coefficient)); + for (u8 i = 0; i < 64; ++i) + TRY(stream.write_value(table.table[zigzag_map[i]])); return {}; }