33
44using SixLabors . ImageSharp . Formats . Jpeg ;
55using SixLabors . ImageSharp . PixelFormats ;
6+ using SixLabors . ImageSharp . Processing ;
67using SixLabors . ImageSharp . Tests . TestUtilities ;
78using SixLabors . ImageSharp . Tests . TestUtilities . ImageComparison ;
89
@@ -87,7 +88,7 @@ public void EncodeBaseline_NonInterleavedMode<TPixel>(TestImageProvider<TPixel>
8788 {
8889 using Image < TPixel > image = provider . GetImage ( ) ;
8990
90- var encoder = new JpegEncoder
91+ JpegEncoder encoder = new ( )
9192 {
9293 Quality = quality ,
9394 ColorType = colorType ,
@@ -164,8 +165,8 @@ public void EncodeBaseline_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvid
164165 [ InlineData ( JpegEncodingColor . YCbCrRatio444 ) ]
165166 public async Task Encode_IsCancellable ( JpegEncodingColor colorType )
166167 {
167- var cts = new CancellationTokenSource ( ) ;
168- using var pausedStream = new PausedStream ( new MemoryStream ( ) ) ;
168+ CancellationTokenSource cts = new ( ) ;
169+ using PausedStream pausedStream = new ( new MemoryStream ( ) ) ;
169170 pausedStream . OnWaiting ( s =>
170171 {
171172 // after some writing
@@ -181,14 +182,37 @@ public async Task Encode_IsCancellable(JpegEncodingColor colorType)
181182 }
182183 } ) ;
183184
184- using var image = new Image < Rgba32 > ( 5000 , 5000 ) ;
185+ using Image < Rgba32 > image = new ( 5000 , 5000 ) ;
185186 await Assert . ThrowsAsync < TaskCanceledException > ( async ( ) =>
186187 {
187- var encoder = new JpegEncoder ( ) { ColorType = colorType } ;
188+ JpegEncoder encoder = new ( ) { ColorType = colorType } ;
188189 await image . SaveAsync ( pausedStream , encoder , cts . Token ) ;
189190 } ) ;
190191 }
191192
193+ // https://github.com/SixLabors/ImageSharp/issues/2595
194+ [ Theory ]
195+ [ WithFile ( TestImages . Jpeg . Baseline . ForestBridgeDifferentComponentsQuality , PixelTypes . Bgra32 ) ]
196+ [ WithFile ( TestImages . Jpeg . Baseline . ForestBridgeDifferentComponentsQuality , PixelTypes . Rgb24 ) ]
197+ public static void Issue2595 < TPixel > ( TestImageProvider < TPixel > provider )
198+ where TPixel : unmanaged, IPixel < TPixel >
199+ {
200+ using Image < TPixel > image = provider . GetImage ( ) ;
201+ image . Mutate ( x => x . Crop ( 132 , 1606 ) ) ;
202+
203+ int [ ] quality = new int [ ] { 100 , 50 } ;
204+ JpegEncodingColor [ ] colors = new [ ] { JpegEncodingColor . YCbCrRatio444 , JpegEncodingColor . YCbCrRatio420 } ;
205+ for ( int i = 0 ; i < quality . Length ; i ++ )
206+ {
207+ int q = quality [ i ] ;
208+ for ( int j = 0 ; j < colors . Length ; j ++ )
209+ {
210+ JpegEncodingColor c = colors [ j ] ;
211+ image . VerifyEncoder ( provider , "jpeg" , $ "{ q } -{ c } ", new JpegEncoder ( ) { Quality = q , ColorType = c } , GetComparer ( q , c ) ) ;
212+ }
213+ }
214+ }
215+
192216 /// <summary>
193217 /// Anton's SUPER-SCIENTIFIC tolerance threshold calculation
194218 /// </summary>
@@ -225,7 +249,7 @@ private static void TestJpegEncoderCore<TPixel>(TestImageProvider<TPixel> provid
225249 {
226250 using Image < TPixel > image = provider . GetImage ( ) ;
227251
228- var encoder = new JpegEncoder
252+ JpegEncoder encoder = new ( )
229253 {
230254 Quality = quality ,
231255 ColorType = colorType
0 commit comments