@@ -1006,6 +1006,78 @@ public void Decode_MalformedIccProfile_ThrowsWithStrict()
10061006 } ) ;
10071007 }
10081008
1009+ /// <summary>
1010+ /// Missing sample-depth tags use the TIFF default in Decode and Identify under every integrity mode.
1011+ /// </summary>
1012+ /// <param name="path">The stored bilevel TIFF without BitsPerSample, with or without SamplesPerPixel.</param>
1013+ [ Theory ]
1014+ [ InlineData ( BilevelWithoutBitsPerSampleUncompressed ) ]
1015+ [ InlineData ( BilevelWithoutBitsPerSampleFax4 ) ]
1016+ [ InlineData ( BilevelWithoutSampleTags ) ]
1017+ public void TiffDecoder_CanDecode_BilevelWithoutBitsPerSample ( string path )
1018+ {
1019+ using Image < L8 > expected = Image . Load < L8 > ( TestFile . Create ( Fax4Compressed ) . Bytes ) ;
1020+ byte [ ] data = TestFile . Create ( path ) . Bytes ;
1021+
1022+ foreach ( SegmentIntegrityHandling integrity in Enum . GetValues < SegmentIntegrityHandling > ( ) )
1023+ {
1024+ DecoderOptions options = new ( ) { SegmentIntegrityHandling = integrity } ;
1025+ using Image < L8 > actual = Image . Load < L8 > ( options , data ) ;
1026+ ImageInfo info = Image . Identify ( options , data ) ;
1027+
1028+ ImageComparer . Exact . VerifySimilarity ( expected , actual ) ;
1029+ TiffFrameMetadata metadata = actual . Frames . RootFrame . Metadata . GetTiffMetadata ( ) ;
1030+ Assert . Equal ( new TiffBitsPerSample ( 1 , 0 , 0 ) , metadata . BitsPerSample ) ;
1031+ Assert . Equal ( TiffBitsPerPixel . Bit1 , metadata . BitsPerPixel ) ;
1032+ Assert . Equal ( 1 , info . PixelType . BitsPerPixel ) ;
1033+ Assert . Equal ( TiffBitsPerPixel . Bit1 , info . FrameMetadataCollection [ 0 ] . GetTiffMetadata ( ) . BitsPerPixel ) ;
1034+ }
1035+ }
1036+
1037+ /// <summary>
1038+ /// A missing sample-depth tag must not reduce an unsupported sample count to a supported layout.
1039+ /// </summary>
1040+ /// <param name="path">The stored TIFF with zero or five declared samples per pixel.</param>
1041+ [ Theory ]
1042+ [ InlineData ( MissingBitsPerSampleWithZeroSamples ) ]
1043+ [ InlineData ( MissingBitsPerSampleWithFiveSamples ) ]
1044+ public void TiffDecoder_WithoutBitsPerSample_RejectsUnsupportedSampleCounts ( string path )
1045+ {
1046+ byte [ ] data = TestFile . Create ( path ) . Bytes ;
1047+
1048+ foreach ( SegmentIntegrityHandling integrity in Enum . GetValues < SegmentIntegrityHandling > ( ) )
1049+ {
1050+ DecoderOptions options = new ( ) { SegmentIntegrityHandling = integrity } ;
1051+ Assert . Throws < NotSupportedException > ( ( ) => Image . Identify ( options , data ) ) ;
1052+ Assert . Throws < NotSupportedException > ( ( ) =>
1053+ {
1054+ using Image < L8 > image = Image . Load < L8 > ( options , data ) ;
1055+ } ) ;
1056+ }
1057+ }
1058+
1059+ /// <summary>
1060+ /// A present but unusable sample-depth tag must not inherit a valid default layout.
1061+ /// </summary>
1062+ /// <param name="path">The stored TIFF with an empty or zero-valued BitsPerSample entry.</param>
1063+ [ Theory ]
1064+ [ InlineData ( EmptyBitsPerSample ) ]
1065+ [ InlineData ( ZeroBitsPerSample ) ]
1066+ public void TiffDecoder_PresentInvalidBitsPerSample_IsNotDefaulted ( string path )
1067+ {
1068+ byte [ ] data = TestFile . Create ( path ) . Bytes ;
1069+
1070+ foreach ( SegmentIntegrityHandling integrity in Enum . GetValues < SegmentIntegrityHandling > ( ) )
1071+ {
1072+ DecoderOptions options = new ( ) { SegmentIntegrityHandling = integrity } ;
1073+ Assert . Throws < NotSupportedException > ( ( ) =>
1074+ {
1075+ using Image < L8 > image = Image . Load < L8 > ( options , data ) ;
1076+ } ) ;
1077+ }
1078+ }
1079+
10091080 private static byte [ ] CreateTiffWithMalformedIccProfile ( )
10101081 => CorruptedMetadataImageFactory . CreateImageWithMalformedIccProfile ( new TiffEncoder ( ) ) ;
1082+
10111083}
0 commit comments