1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

LibGfx: Don't reject SOF2 JPEGs that don't use spectral approximation

Precisely, we now accept every SOF2 image but error on scans that has a
spectral approximation parameter different of 0.
This commit is contained in:
Lucas CHOLLET 2023-02-26 00:16:08 -05:00 committed by Linus Groh
parent 342c94c4d7
commit 89e8f4692d

View file

@ -574,6 +574,7 @@ static inline bool is_supported_marker(Marker const marker)
case JPEG_DRI: case JPEG_DRI:
case JPEG_EOI: case JPEG_EOI:
case JPEG_SOF0: case JPEG_SOF0:
case JPEG_SOF2:
case JPEG_SOI: case JPEG_SOI:
case JPEG_SOS: case JPEG_SOS:
return true; return true;
@ -649,8 +650,8 @@ static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPEGLoadingC
current_scan.spectral_selection_end, current_scan.spectral_selection_end,
current_scan.successive_approximation); current_scan.successive_approximation);
// The three values should be fixed for baseline JPEGs utilizing sequential DCT. // FIXME: Support SOF2 jpegs with current_scan.successive_approximation != 0
if (current_scan.spectral_selection_start != 0 || current_scan.spectral_selection_end != 63 || current_scan.successive_approximation != 0) { if (current_scan.spectral_selection_start > 63 || current_scan.spectral_selection_end > 63 || current_scan.successive_approximation != 0) {
dbgln_if(JPEG_DEBUG, "{}: ERROR! Start of Selection: {}, End of Selection: {}, Successive Approximation: {}!", dbgln_if(JPEG_DEBUG, "{}: ERROR! Start of Selection: {}, End of Selection: {}, Successive Approximation: {}!",
TRY(stream.tell()), TRY(stream.tell()),
current_scan.spectral_selection_start, current_scan.spectral_selection_start,
@ -1292,6 +1293,7 @@ static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPEGLoadingContext
dbgln_if(JPEG_DEBUG, "{}: Unexpected marker {:x}!", TRY(stream.tell()), marker); dbgln_if(JPEG_DEBUG, "{}: Unexpected marker {:x}!", TRY(stream.tell()), marker);
return Error::from_string_literal("Unexpected marker"); return Error::from_string_literal("Unexpected marker");
case JPEG_SOF0: case JPEG_SOF0:
case JPEG_SOF2:
TRY(read_start_of_frame(stream, context)); TRY(read_start_of_frame(stream, context));
context.state = JPEGLoadingContext::FrameDecoded; context.state = JPEGLoadingContext::FrameDecoded;
return {}; return {};