@@ -620,15 +620,33 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
620
620
}
621
621
622
622
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
+ }
624
629
625
630
break ;
626
631
}
627
632
628
633
case TiffCompression . Jpeg :
629
634
{
630
635
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
+ }
632
650
633
651
break ;
634
652
}
@@ -647,24 +665,6 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
647
665
}
648
666
}
649
667
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
-
668
668
private static bool IsBiColorCompression ( TiffCompression ? compression )
669
669
{
670
670
if ( compression is TiffCompression . Ccitt1D or TiffCompression . CcittGroup3Fax or
0 commit comments