mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +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:
parent
d99d086da3
commit
3616d14c80
Notes:
sideshowbarker
2024-07-17 10:10:18 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/3616d14c80 Pull-request: https://github.com/SerenityOS/serenity/pull/22758 Reviewed-by: https://github.com/LucasChollet ✅
|
@ -325,7 +325,7 @@ TEST_CASE(test_jpeg_ycck)
|
|||
{
|
||||
Array test_inputs = {
|
||||
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),
|
||||
};
|
||||
|
||||
|
|
|
@ -1287,12 +1287,9 @@ static ErrorOr<void> read_start_of_frame(JPEGStream& stream, JPEGLoadingContext&
|
|||
return Error::from_string_literal("Unsupported luma subsampling factors");
|
||||
}
|
||||
} else {
|
||||
// YCCK with just CC subsampled and K matching Y is fine.
|
||||
auto const& y_component = context.components[0];
|
||||
bool channel_matches_y_factor = component.sampling_factors == y_component.sampling_factors;
|
||||
bool k_channel_matches_y = context.color_transform == ColorTransform::YCCK && i == 3 && channel_matches_y_factor;
|
||||
|
||||
if (((component.sampling_factors != SamplingFactors { 1, 1 }) && !k_channel_matches_y) || (i == 3 && !channel_matches_y_factor)) {
|
||||
if (y_component.sampling_factors.horizontal % component.sampling_factors.horizontal != 0
|
||||
|| y_component.sampling_factors.vertical % component.sampling_factors.vertical != 0) {
|
||||
dbgln_if(JPEG_DEBUG, "Unsupported chroma subsampling factors: horizontal: {}, vertical: {}",
|
||||
component.sampling_factors.horizontal,
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
// read_start_of_frame() which currently enforces these restrictions.
|
||||
// divide the first component's sampling factors. This is enforced by read_start_of_frame().
|
||||
// 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.
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue