@@ -139,8 +139,8 @@ public static bool VerifyAndParse(this TiffDecoderCore options, ExifProfile exif
139
139
options . OldJpegCompressionStartOfImageMarker = jpegInterchangeFormatValue . Value ;
140
140
}
141
141
142
- options . ParseColorType ( exifProfile ) ;
143
142
options . ParseCompression ( frameMetadata . Compression , exifProfile ) ;
143
+ options . ParseColorType ( exifProfile ) ;
144
144
145
145
bool isTiled = VerifyRequiredFieldsArePresent ( exifProfile , frameMetadata , options . PlanarConfiguration ) ;
146
146
@@ -194,7 +194,9 @@ private static bool VerifyRequiredFieldsArePresent(ExifProfile exifProfile, Tiff
194
194
}
195
195
}
196
196
197
- if ( frameMetadata . BitsPerPixel == null )
197
+ // For BiColor compressed images, the BitsPerPixel value will be set explicitly to 1, so we don't throw in those cases.
198
+ // See: https://github.com/SixLabors/ImageSharp/issues/2587
199
+ if ( frameMetadata . BitsPerPixel == null && ! IsBiColorCompression ( frameMetadata . Compression ) )
198
200
{
199
201
TiffThrowHelper . ThrowNotSupported ( "The TIFF BitsPerSample entry is missing which is required to decode the image!" ) ;
200
202
}
@@ -570,6 +572,11 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
570
572
options . FaxCompressionOptions = FaxCompressionOptions . None ;
571
573
}
572
574
575
+ // Some encoders do not set the BitsPerSample correctly, so we set those values here to the required values:
576
+ // https://github.com/SixLabors/ImageSharp/issues/2587
577
+ options . BitsPerSample = new TiffBitsPerSample ( 1 , 0 , 0 ) ;
578
+ options . BitsPerPixel = 1 ;
579
+
573
580
break ;
574
581
}
575
582
@@ -585,12 +592,18 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
585
592
options . FaxCompressionOptions = FaxCompressionOptions . None ;
586
593
}
587
594
595
+ options . BitsPerSample = new TiffBitsPerSample ( 1 , 0 , 0 ) ;
596
+ options . BitsPerPixel = 1 ;
597
+
588
598
break ;
589
599
}
590
600
591
601
case TiffCompression . Ccitt1D :
592
602
{
593
603
options . CompressionType = TiffDecoderCompressionType . HuffmanRle ;
604
+ options . BitsPerSample = new TiffBitsPerSample ( 1 , 0 , 0 ) ;
605
+ options . BitsPerPixel = 1 ;
606
+
594
607
break ;
595
608
}
596
609
@@ -645,4 +658,15 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
645
658
}
646
659
}
647
660
}
661
+
662
+ private static bool IsBiColorCompression ( TiffCompression ? compression )
663
+ {
664
+ if ( compression is TiffCompression . Ccitt1D or TiffCompression . CcittGroup3Fax or
665
+ TiffCompression . CcittGroup4Fax )
666
+ {
667
+ return true ;
668
+ }
669
+
670
+ return false ;
671
+ }
648
672
}
0 commit comments