@@ -620,39 +620,15 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
620
620
}
621
621
622
622
options . CompressionType = TiffDecoderCompressionType . OldJpeg ;
623
-
624
- if ( options . PhotometricInterpretation is TiffPhotometricInterpretation . YCbCr )
625
- {
626
- // Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
627
- options . PhotometricInterpretation = TiffPhotometricInterpretation . Rgb ;
628
- options . ColorType = TiffColorType . Rgb ;
629
- }
630
-
631
- if ( options . PhotometricInterpretation is TiffPhotometricInterpretation . YCbCr )
632
- {
633
- options . YcbcrSubSampling [ 0 ] = 1 ;
634
- options . YcbcrSubSampling [ 1 ] = 1 ;
635
- }
623
+ AdjustOptionsYCbCrJpegCompression ( options ) ;
636
624
637
625
break ;
638
626
}
639
627
640
628
case TiffCompression . Jpeg :
641
629
{
642
630
options . CompressionType = TiffDecoderCompressionType . Jpeg ;
643
-
644
- if ( options . PhotometricInterpretation is TiffPhotometricInterpretation . YCbCr && options . JpegTables is null )
645
- {
646
- // Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
647
- options . PhotometricInterpretation = TiffPhotometricInterpretation . Rgb ;
648
- options . ColorType = TiffColorType . Rgb ;
649
- }
650
-
651
- if ( options . PhotometricInterpretation is TiffPhotometricInterpretation . YCbCr )
652
- {
653
- options . YcbcrSubSampling [ 0 ] = 1 ;
654
- options . YcbcrSubSampling [ 1 ] = 1 ;
655
- }
631
+ AdjustOptionsYCbCrJpegCompression ( options ) ;
656
632
657
633
break ;
658
634
}
@@ -671,6 +647,24 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
671
647
}
672
648
}
673
649
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
+
674
668
private static bool IsBiColorCompression ( TiffCompression ? compression )
675
669
{
676
670
if ( compression is TiffCompression . Ccitt1D or TiffCompression . CcittGroup3Fax or
0 commit comments