From a443d2955a2b8f19477a3bd5f303bc4ff66f4f5b Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sat, 16 Dec 2023 20:13:50 -0500 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp index 18bc15af46..fef21de45f 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp @@ -90,14 +90,15 @@ private: ErrorOr 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, u32> StripDecoder>