From 5c60126377aefbf089ccf365df0880d3006b3c63 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 4 Aug 2024 17:35:33 +0200 Subject: [PATCH] Add check, if YcbcrSubSampling has a value --- .../Formats/Tiff/TiffDecoderOptionsParser.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs index 864452fd26..c3ff758ac1 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs @@ -633,21 +633,22 @@ internal static class TiffDecoderOptionsParser case TiffCompression.Jpeg: { options.CompressionType = TiffDecoderCompressionType.Jpeg; - if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.JpegTables is null) - { - // Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data. - options.PhotometricInterpretation = TiffPhotometricInterpretation.Rgb; - options.ColorType = TiffColorType.Rgb; - } // Some tiff encoder set this to values different from [1, 1]. The jpeg decoder already handles this, // so we set this always to [1, 1], see: https://github.com/SixLabors/ImageSharp/issues/2679 - if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr) + if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.YcbcrSubSampling != null) { options.YcbcrSubSampling[0] = 1; options.YcbcrSubSampling[1] = 1; } + if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.JpegTables is null) + { + // Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data. + options.PhotometricInterpretation = TiffPhotometricInterpretation.Rgb; + options.ColorType = TiffColorType.Rgb; + } + break; }