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