mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibGfx/TIFF: Support bilevel images missing baseline tags
Bilevel images are not required to have a BitsPerSample or a SamplesPerPixel tag.
This commit is contained in:
parent
eb142b1d28
commit
3c138b9580
Notes:
sideshowbarker
2024-07-16 17:12:03 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/3c138b9580 Pull-request: https://github.com/SerenityOS/serenity/pull/24237 Reviewed-by: https://github.com/nico ✅
1 changed files with 15 additions and 11 deletions
|
@ -108,20 +108,22 @@ public:
|
||||||
if (!m_metadata.rows_per_strip().has_value() && segment_byte_counts()->size() != 1 && !is_tiled())
|
if (!m_metadata.rows_per_strip().has_value() && segment_byte_counts()->size() != 1 && !is_tiled())
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: RowsPerStrip is not provided and impossible to deduce");
|
return Error::from_string_literal("TIFFImageDecoderPlugin: RowsPerStrip is not provided and impossible to deduce");
|
||||||
|
|
||||||
if (!m_metadata.bits_per_sample().has_value())
|
if (!is_bilevel(*m_metadata.photometric_interpretation())) {
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: Tag BitsPerSample is missing");
|
if (!m_metadata.bits_per_sample().has_value())
|
||||||
|
return Error::from_string_literal("TIFFImageDecoderPlugin: Tag BitsPerSample is missing");
|
||||||
|
|
||||||
if (!m_metadata.samples_per_pixel().has_value())
|
if (!m_metadata.samples_per_pixel().has_value())
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: Tag SamplesPerPixel is missing");
|
return Error::from_string_literal("TIFFImageDecoderPlugin: Tag SamplesPerPixel is missing");
|
||||||
|
|
||||||
if (any_of(*m_metadata.bits_per_sample(), [](auto bit_depth) { return bit_depth == 0 || bit_depth > 32; }))
|
if (any_of(*m_metadata.bits_per_sample(), [](auto bit_depth) { return bit_depth == 0 || bit_depth > 32; }))
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid value in BitsPerSample");
|
return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid value in BitsPerSample");
|
||||||
|
|
||||||
if (m_metadata.bits_per_sample()->size() != m_metadata.samples_per_pixel())
|
if (m_metadata.bits_per_sample()->size() != m_metadata.samples_per_pixel())
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid number of values in BitsPerSample");
|
return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid number of values in BitsPerSample");
|
||||||
|
|
||||||
if (*m_metadata.samples_per_pixel() < samples_for_photometric_interpretation())
|
if (*m_metadata.samples_per_pixel() < samples_for_photometric_interpretation())
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: Not enough values in BitsPerSample for given PhotometricInterpretation");
|
return Error::from_string_literal("TIFFImageDecoderPlugin: Not enough values in BitsPerSample for given PhotometricInterpretation");
|
||||||
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -132,6 +134,8 @@ public:
|
||||||
m_photometric_interpretation = m_metadata.photometric_interpretation().value();
|
m_photometric_interpretation = m_metadata.photometric_interpretation().value();
|
||||||
if (m_metadata.bits_per_sample().has_value())
|
if (m_metadata.bits_per_sample().has_value())
|
||||||
m_bits_per_sample = m_metadata.bits_per_sample().value();
|
m_bits_per_sample = m_metadata.bits_per_sample().value();
|
||||||
|
else if (is_bilevel(m_photometric_interpretation))
|
||||||
|
m_bits_per_sample.append(1);
|
||||||
if (m_metadata.image_width().has_value())
|
if (m_metadata.image_width().has_value())
|
||||||
m_image_width = m_metadata.image_width().value();
|
m_image_width = m_metadata.image_width().value();
|
||||||
if (m_metadata.predictor().has_value())
|
if (m_metadata.predictor().has_value())
|
||||||
|
@ -391,7 +395,7 @@ private:
|
||||||
{
|
{
|
||||||
// Section 8: Baseline Field Reference Guide
|
// Section 8: Baseline Field Reference Guide
|
||||||
// BitsPerSample must be 1, since this type of compression is defined only for bilevel images.
|
// BitsPerSample must be 1, since this type of compression is defined only for bilevel images.
|
||||||
if (m_metadata.bits_per_sample()->size() > 1)
|
if (m_bits_per_sample.size() > 1)
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT image with BitsPerSample greater than one");
|
return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT image with BitsPerSample greater than one");
|
||||||
if (!is_bilevel(*m_metadata.photometric_interpretation()))
|
if (!is_bilevel(*m_metadata.photometric_interpretation()))
|
||||||
return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT compression is used on a non bilevel image");
|
return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT compression is used on a non bilevel image");
|
||||||
|
|
Loading…
Reference in a new issue