3
3
4
4
using SixLabors . ImageSharp . Formats . Jpeg ;
5
5
using SixLabors . ImageSharp . PixelFormats ;
6
+ using SixLabors . ImageSharp . Processing ;
6
7
using SixLabors . ImageSharp . Tests . TestUtilities ;
7
8
using SixLabors . ImageSharp . Tests . TestUtilities . ImageComparison ;
8
9
@@ -87,7 +88,7 @@ public void EncodeBaseline_NonInterleavedMode<TPixel>(TestImageProvider<TPixel>
87
88
{
88
89
using Image < TPixel > image = provider . GetImage ( ) ;
89
90
90
- var encoder = new JpegEncoder
91
+ JpegEncoder encoder = new ( )
91
92
{
92
93
Quality = quality ,
93
94
ColorType = colorType ,
@@ -164,8 +165,8 @@ public void EncodeBaseline_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvid
164
165
[ InlineData ( JpegEncodingColor . YCbCrRatio444 ) ]
165
166
public async Task Encode_IsCancellable ( JpegEncodingColor colorType )
166
167
{
167
- var cts = new CancellationTokenSource ( ) ;
168
- using var pausedStream = new PausedStream ( new MemoryStream ( ) ) ;
168
+ CancellationTokenSource cts = new ( ) ;
169
+ using PausedStream pausedStream = new ( new MemoryStream ( ) ) ;
169
170
pausedStream . OnWaiting ( s =>
170
171
{
171
172
// after some writing
@@ -181,14 +182,37 @@ public async Task Encode_IsCancellable(JpegEncodingColor colorType)
181
182
}
182
183
} ) ;
183
184
184
- using var image = new Image < Rgba32 > ( 5000 , 5000 ) ;
185
+ using Image < Rgba32 > image = new ( 5000 , 5000 ) ;
185
186
await Assert . ThrowsAsync < TaskCanceledException > ( async ( ) =>
186
187
{
187
- var encoder = new JpegEncoder ( ) { ColorType = colorType } ;
188
+ JpegEncoder encoder = new ( ) { ColorType = colorType } ;
188
189
await image . SaveAsync ( pausedStream , encoder , cts . Token ) ;
189
190
} ) ;
190
191
}
191
192
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
+
192
216
/// <summary>
193
217
/// Anton's SUPER-SCIENTIFIC tolerance threshold calculation
194
218
/// </summary>
@@ -225,7 +249,7 @@ private static void TestJpegEncoderCore<TPixel>(TestImageProvider<TPixel> provid
225
249
{
226
250
using Image < TPixel > image = provider . GetImage ( ) ;
227
251
228
- var encoder = new JpegEncoder
252
+ JpegEncoder encoder = new ( )
229
253
{
230
254
Quality = quality ,
231
255
ColorType = colorType
0 commit comments