From 9cbed7b359139f89e1a1d879c3273217f0d4b5a8 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Tue, 21 Mar 2023 18:23:47 -0400 Subject: [PATCH] LibGfx/JPEG: Support for images with four components This patch adds support for properly read images with four components, basically CMYK or YCCK. However, we still lack color spaces transformations for this type of image. So, it just postpones failure. --- .../Libraries/LibGfx/ImageFormats/JPEGLoader.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index 85afc901d8..05dd008c6c 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -115,6 +115,8 @@ struct Macroblock { i32 cr[64] = { 0 }; i32 b[64]; }; + + i32 k[64] = { 0 }; }; struct MacroblockMeta { @@ -197,7 +199,7 @@ struct ICCMultiChunkState { struct Scan { // B.2.3 - Scan header syntax - Vector components; + Vector components; u8 spectral_selection_start {}; // Ss u8 spectral_selection_end {}; // Se @@ -242,12 +244,12 @@ struct JPEGLoadingContext { Scan current_scan; - Vector components; + Vector components; RefPtr bitmap; u16 dc_restart_interval { 0 }; HashMap dc_tables; HashMap ac_tables; - Array previous_dc_values {}; + Array previous_dc_values {}; MacroblockMeta mblock_meta; OwnPtr stream; @@ -316,8 +318,12 @@ static inline i32* get_component(Macroblock& block, unsigned component) return block.y; case 1: return block.cb; - default: + case 2: return block.cr; + case 3: + return block.k; + default: + VERIFY_NOT_REACHED(); } } @@ -1020,7 +1026,7 @@ static ErrorOr read_start_of_frame(Stream& stream, JPEGLoadingContext& con set_macroblock_metadata(context); auto component_count = TRY(stream.read_value()); - if (component_count != 1 && component_count != 3) { + if (component_count != 1 && component_count != 3 && component_count != 4) { dbgln_if(JPEG_DEBUG, "Unsupported number of components in SOF: {}!", component_count); return Error::from_string_literal("Unsupported number of components in SOF"); }