Skip to content

Commit e8bbdf7

Browse files
committed
Always set YcbcrSubSampling to 1:1 for TiffCompression.Jpeg, fixes issue #2679
1 parent 363769d commit e8bbdf7

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,33 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
620620
}
621621

622622
options.CompressionType = TiffDecoderCompressionType.OldJpeg;
623-
AdjustOptionsYCbCrJpegCompression(options);
623+
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr)
624+
{
625+
// Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
626+
options.PhotometricInterpretation = TiffPhotometricInterpretation.Rgb;
627+
options.ColorType = TiffColorType.Rgb;
628+
}
624629

625630
break;
626631
}
627632

628633
case TiffCompression.Jpeg:
629634
{
630635
options.CompressionType = TiffDecoderCompressionType.Jpeg;
631-
AdjustOptionsYCbCrJpegCompression(options);
636+
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.JpegTables is null)
637+
{
638+
// Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
639+
options.PhotometricInterpretation = TiffPhotometricInterpretation.Rgb;
640+
options.ColorType = TiffColorType.Rgb;
641+
}
642+
643+
// Some tiff encoder set this to values different from [1, 1]. The jpeg decoder already handles this,
644+
// so we set this always to [1, 1], see: https://github.com/SixLabors/ImageSharp/issues/2679
645+
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr)
646+
{
647+
options.YcbcrSubSampling[0] = 1;
648+
options.YcbcrSubSampling[1] = 1;
649+
}
632650

633651
break;
634652
}
@@ -647,24 +665,6 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
647665
}
648666
}
649667

650-
private static void AdjustOptionsYCbCrJpegCompression(TiffDecoderCore options)
651-
{
652-
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr)
653-
{
654-
// Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
655-
options.PhotometricInterpretation = TiffPhotometricInterpretation.Rgb;
656-
options.ColorType = TiffColorType.Rgb;
657-
}
658-
659-
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr)
660-
{
661-
// Some tiff encoder set this to values different from [1, 1]. The jpeg decoder already handles this,
662-
// so we set this always to [1, 1], see: https://github.com/SixLabors/ImageSharp/issues/2679
663-
options.YcbcrSubSampling[0] = 1;
664-
options.YcbcrSubSampling[1] = 1;
665-
}
666-
}
667-
668668
private static bool IsBiColorCompression(TiffCompression? compression)
669669
{
670670
if (compression is TiffCompression.Ccitt1D or TiffCompression.CcittGroup3Fax or

0 commit comments

Comments
 (0)