Skip to content

Commit

Permalink
LibGfx/JPEG: Support for images with four components
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LucasChollet authored and linusg committed Apr 3, 2023
1 parent 261d363 commit 9cbed7b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ struct Macroblock {
i32 cr[64] = { 0 };
i32 b[64];
};

i32 k[64] = { 0 };
};

struct MacroblockMeta {
Expand Down Expand Up @@ -197,7 +199,7 @@ struct ICCMultiChunkState {

struct Scan {
// B.2.3 - Scan header syntax
Vector<ScanComponent, 3> components;
Vector<ScanComponent, 4> components;

u8 spectral_selection_start {}; // Ss
u8 spectral_selection_end {}; // Se
Expand Down Expand Up @@ -242,12 +244,12 @@ struct JPEGLoadingContext {

Scan current_scan;

Vector<Component, 3> components;
Vector<Component, 4> components;
RefPtr<Gfx::Bitmap> bitmap;
u16 dc_restart_interval { 0 };
HashMap<u8, HuffmanTableSpec> dc_tables;
HashMap<u8, HuffmanTableSpec> ac_tables;
Array<i32, 3> previous_dc_values {};
Array<i32, 4> previous_dc_values {};
MacroblockMeta mblock_meta;
OwnPtr<FixedMemoryStream> stream;

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -1020,7 +1026,7 @@ static ErrorOr<void> read_start_of_frame(Stream& stream, JPEGLoadingContext& con
set_macroblock_metadata(context);

auto component_count = TRY(stream.read_value<u8>());
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");
}
Expand Down

0 comments on commit 9cbed7b

Please sign in to comment.