mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 08:36:15 +00:00
LibGfx/TIFF: Don't use SamplesPerPixel to infer the "type" of image
The number of samples is not a good measure to deduce the type of image we are decoding. As per the TIFF spec, the PhotometricInterpretation tag is required and we should use that instead.
This commit is contained in:
committed by
Andreas Kling
parent
022fce75a6
commit
a443d2955a
@@ -90,14 +90,15 @@ private:
|
||||
ErrorOr<Color> read_color(BigEndianInputBitStream& stream)
|
||||
{
|
||||
auto bits_per_sample = *m_metadata.bits_per_sample();
|
||||
if (m_metadata.samples_per_pixel().value_or(3) == 3) {
|
||||
if (m_metadata.photometric_interpretation() == PhotometricInterpretation::RGB) {
|
||||
auto const first_component = TRY(read_component(stream, bits_per_sample[0]));
|
||||
auto const second_component = TRY(read_component(stream, bits_per_sample[1]));
|
||||
auto const third_component = TRY(read_component(stream, bits_per_sample[2]));
|
||||
return Color(first_component, second_component, third_component);
|
||||
}
|
||||
|
||||
if (*m_metadata.samples_per_pixel() == 1) {
|
||||
if (*m_metadata.photometric_interpretation() == PhotometricInterpretation::WhiteIsZero
|
||||
|| *m_metadata.photometric_interpretation() == PhotometricInterpretation::BlackIsZero) {
|
||||
auto luminosity = TRY(read_component(stream, bits_per_sample[0]));
|
||||
|
||||
if (m_metadata.photometric_interpretation() == PhotometricInterpretation::WhiteIsZero)
|
||||
@@ -106,7 +107,7 @@ private:
|
||||
return Color(luminosity, luminosity, luminosity);
|
||||
}
|
||||
|
||||
return Error::from_string_literal("Unsupported number of sample per pixel");
|
||||
return Error::from_string_literal("Unsupported value for PhotometricInterpretation");
|
||||
}
|
||||
|
||||
template<CallableAs<ErrorOr<ReadonlyBytes>, u32> StripDecoder>
|
||||
|
||||
Reference in New Issue
Block a user