@@ -139,8 +139,8 @@ public static bool VerifyAndParse(this TiffDecoderCore options, ExifProfile exif
139139 options . OldJpegCompressionStartOfImageMarker = jpegInterchangeFormatValue . Value ;
140140 }
141141
142- options . ParseColorType ( exifProfile ) ;
143142 options . ParseCompression ( frameMetadata . Compression , exifProfile ) ;
143+ options . ParseColorType ( exifProfile ) ;
144144
145145 bool isTiled = VerifyRequiredFieldsArePresent ( exifProfile , frameMetadata , options . PlanarConfiguration ) ;
146146
@@ -194,7 +194,9 @@ private static bool VerifyRequiredFieldsArePresent(ExifProfile exifProfile, Tiff
194194 }
195195 }
196196
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 ) )
198200 {
199201 TiffThrowHelper . ThrowNotSupported ( "The TIFF BitsPerSample entry is missing which is required to decode the image!" ) ;
200202 }
@@ -570,6 +572,11 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
570572 options . FaxCompressionOptions = FaxCompressionOptions . None ;
571573 }
572574
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+
573580 break ;
574581 }
575582
@@ -585,12 +592,18 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
585592 options . FaxCompressionOptions = FaxCompressionOptions . None ;
586593 }
587594
595+ options . BitsPerSample = new TiffBitsPerSample ( 1 , 0 , 0 ) ;
596+ options . BitsPerPixel = 1 ;
597+
588598 break ;
589599 }
590600
591601 case TiffCompression . Ccitt1D :
592602 {
593603 options . CompressionType = TiffDecoderCompressionType . HuffmanRle ;
604+ options . BitsPerSample = new TiffBitsPerSample ( 1 , 0 , 0 ) ;
605+ options . BitsPerPixel = 1 ;
606+
594607 break ;
595608 }
596609
@@ -645,4 +658,15 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
645658 }
646659 }
647660 }
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+ }
648672}
0 commit comments