1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

LibGfx/JPEG: Allow decoding more subsampling factors

We now allow all subsampling factors where the subsampling factors
of follow-on components evenly decode the ones of the first component.

In practice, this allows YCCK 2111, CMYK 2112, and CMYK 2111.
This commit is contained in:
Nico Weber 2024-01-14 18:48:43 -05:00 committed by Andrew Kaster
parent d99d086da3
commit 3616d14c80
2 changed files with 4 additions and 8 deletions

View file

@ -325,7 +325,7 @@ TEST_CASE(test_jpeg_ycck)
{ {
Array test_inputs = { Array test_inputs = {
TEST_INPUT("jpg/ycck-1111.jpg"sv), TEST_INPUT("jpg/ycck-1111.jpg"sv),
// TEST_INPUT("jpg/ycck-2111.jpg"sv), // FIXME: Enable once this decodes correctly TEST_INPUT("jpg/ycck-2111.jpg"sv),
TEST_INPUT("jpg/ycck-2112.jpg"sv), TEST_INPUT("jpg/ycck-2112.jpg"sv),
}; };

View file

@ -1287,12 +1287,9 @@ static ErrorOr<void> read_start_of_frame(JPEGStream& stream, JPEGLoadingContext&
return Error::from_string_literal("Unsupported luma subsampling factors"); return Error::from_string_literal("Unsupported luma subsampling factors");
} }
} else { } else {
// YCCK with just CC subsampled and K matching Y is fine.
auto const& y_component = context.components[0]; auto const& y_component = context.components[0];
bool channel_matches_y_factor = component.sampling_factors == y_component.sampling_factors; if (y_component.sampling_factors.horizontal % component.sampling_factors.horizontal != 0
bool k_channel_matches_y = context.color_transform == ColorTransform::YCCK && i == 3 && channel_matches_y_factor; || y_component.sampling_factors.vertical % component.sampling_factors.vertical != 0) {
if (((component.sampling_factors != SamplingFactors { 1, 1 }) && !k_channel_matches_y) || (i == 3 && !channel_matches_y_factor)) {
dbgln_if(JPEG_DEBUG, "Unsupported chroma subsampling factors: horizontal: {}, vertical: {}", dbgln_if(JPEG_DEBUG, "Unsupported chroma subsampling factors: horizontal: {}, vertical: {}",
component.sampling_factors.horizontal, component.sampling_factors.horizontal,
component.sampling_factors.vertical); component.sampling_factors.vertical);
@ -1589,8 +1586,7 @@ static void inverse_dct(JPEGLoadingContext const& context, Vector<Macroblock>& m
static void undo_subsampling(JPEGLoadingContext const& context, Vector<Macroblock>& macroblocks) static void undo_subsampling(JPEGLoadingContext const& context, Vector<Macroblock>& macroblocks)
{ {
// The first component has sampling factors of context.sampling_factors, while the others // The first component has sampling factors of context.sampling_factors, while the others
// are either 1x1 or for the 4th component also context.sampling_factors. See // divide the first component's sampling factors. This is enforced by read_start_of_frame().
// read_start_of_frame() which currently enforces these restrictions.
// This function undoes the subsampling by duplicating the values of the smaller components. // This function undoes the subsampling by duplicating the values of the smaller components.
// See https://www.w3.org/Graphics/JPEG/itu-t81.pdf, A.2 Order of source image data encoding. // See https://www.w3.org/Graphics/JPEG/itu-t81.pdf, A.2 Order of source image data encoding.
// //