@@ -67,16 +67,13 @@ public void MetadataIsParsedCorrectly(
6767 string imagePath ,
6868 int expectedPixelSize ,
6969 bool exifProfilePresent ,
70- bool iccProfilePresent )
71- {
72- TestMetadataImpl (
70+ bool iccProfilePresent ) => TestMetadataImpl (
7371 useIdentify ,
7472 JpegDecoder ,
7573 imagePath ,
7674 expectedPixelSize ,
7775 exifProfilePresent ,
7876 iccProfilePresent ) ;
79- }
8077
8178 [ Theory ]
8279 [ MemberData ( nameof ( RatioFiles ) ) ]
@@ -133,15 +130,45 @@ public void Decode_VerifyQuality(string imagePath, int quality)
133130 var testFile = TestFile . Create ( imagePath ) ;
134131 using ( var stream = new MemoryStream ( testFile . Bytes , false ) )
135132 {
136- var decoder = new JpegDecoder ( ) ;
137- using ( Image < Rgba32 > image = decoder . Decode < Rgba32 > ( Configuration . Default , stream ) )
133+ using ( Image < Rgba32 > image = JpegDecoder . Decode < Rgba32 > ( Configuration . Default , stream ) )
138134 {
139135 JpegMetadata meta = image . Metadata . GetJpegMetadata ( ) ;
140136 Assert . Equal ( quality , meta . Quality ) ;
141137 }
142138 }
143139 }
144140
141+ [ Theory ]
142+ [ InlineData ( TestImages . Jpeg . Baseline . Floorplan , JpegColorType . Luminance ) ]
143+ [ InlineData ( TestImages . Jpeg . Baseline . Jpeg420Small , JpegColorType . YCbCrRatio420 ) ]
144+ [ InlineData ( TestImages . Jpeg . Baseline . Jpeg444 , JpegColorType . YCbCrRatio444 ) ]
145+ [ InlineData ( TestImages . Jpeg . Baseline . JpegRgb , JpegColorType . Rgb ) ]
146+ public void Identify_DetectsCorrectColorType ( string imagePath , JpegColorType expectedColorType )
147+ {
148+ var testFile = TestFile . Create ( imagePath ) ;
149+ using ( var stream = new MemoryStream ( testFile . Bytes , false ) )
150+ {
151+ IImageInfo image = JpegDecoder . Identify ( Configuration . Default , stream ) ;
152+ JpegMetadata meta = image . Metadata . GetJpegMetadata ( ) ;
153+ Assert . Equal ( expectedColorType , meta . ColorType ) ;
154+ }
155+ }
156+
157+ [ Theory ]
158+ [ WithFile ( TestImages . Jpeg . Baseline . Floorplan , PixelTypes . Rgba32 , JpegColorType . Luminance ) ]
159+ [ WithFile ( TestImages . Jpeg . Baseline . Jpeg420Small , PixelTypes . Rgba32 , JpegColorType . YCbCrRatio420 ) ]
160+ [ WithFile ( TestImages . Jpeg . Baseline . Jpeg444 , PixelTypes . Rgba32 , JpegColorType . YCbCrRatio444 ) ]
161+ [ WithFile ( TestImages . Jpeg . Baseline . JpegRgb , PixelTypes . Rgba32 , JpegColorType . Rgb ) ]
162+ public void Decode_DetectsCorrectColorType < TPixel > ( TestImageProvider < TPixel > provider , JpegColorType expectedColorType )
163+ where TPixel : unmanaged, IPixel < TPixel >
164+ {
165+ using ( Image < TPixel > image = provider . GetImage ( JpegDecoder ) )
166+ {
167+ JpegMetadata meta = image . Metadata . GetJpegMetadata ( ) ;
168+ Assert . Equal ( expectedColorType , meta . ColorType ) ;
169+ }
170+ }
171+
145172 private static void TestImageInfo ( string imagePath , IImageDecoder decoder , bool useIdentify , Action < IImageInfo > test )
146173 {
147174 var testFile = TestFile . Create ( imagePath ) ;
@@ -161,9 +188,7 @@ private static void TestMetadataImpl(
161188 string imagePath ,
162189 int expectedPixelSize ,
163190 bool exifProfilePresent ,
164- bool iccProfilePresent )
165- {
166- TestImageInfo (
191+ bool iccProfilePresent ) => TestImageInfo (
167192 imagePath ,
168193 decoder ,
169194 useIdentify ,
@@ -207,7 +232,6 @@ private static void TestMetadataImpl(
207232 Assert . Null ( iccProfile ) ;
208233 }
209234 } ) ;
210- }
211235
212236 [ Theory ]
213237 [ InlineData ( false ) ]
@@ -237,9 +261,7 @@ public void IgnoreMetadata_ControlsWhetherMetadataIsParsed(bool ignoreMetadata)
237261 [ Theory ]
238262 [ InlineData ( false ) ]
239263 [ InlineData ( true ) ]
240- public void Decoder_Reads_Correct_Resolution_From_Jfif ( bool useIdentify )
241- {
242- TestImageInfo (
264+ public void Decoder_Reads_Correct_Resolution_From_Jfif ( bool useIdentify ) => TestImageInfo (
243265 TestImages . Jpeg . Baseline . Floorplan ,
244266 JpegDecoder ,
245267 useIdentify ,
@@ -248,14 +270,11 @@ public void Decoder_Reads_Correct_Resolution_From_Jfif(bool useIdentify)
248270 Assert . Equal ( 300 , imageInfo . Metadata . HorizontalResolution ) ;
249271 Assert . Equal ( 300 , imageInfo . Metadata . VerticalResolution ) ;
250272 } ) ;
251- }
252273
253274 [ Theory ]
254275 [ InlineData ( false ) ]
255276 [ InlineData ( true ) ]
256- public void Decoder_Reads_Correct_Resolution_From_Exif ( bool useIdentify )
257- {
258- TestImageInfo (
277+ public void Decoder_Reads_Correct_Resolution_From_Exif ( bool useIdentify ) => TestImageInfo (
259278 TestImages . Jpeg . Baseline . Jpeg420Exif ,
260279 JpegDecoder ,
261280 useIdentify ,
@@ -264,6 +283,5 @@ public void Decoder_Reads_Correct_Resolution_From_Exif(bool useIdentify)
264283 Assert . Equal ( 72 , imageInfo . Metadata . HorizontalResolution ) ;
265284 Assert . Equal ( 72 , imageInfo . Metadata . VerticalResolution ) ;
266285 } ) ;
267- }
268286 }
269287}
0 commit comments