@@ -129,8 +129,8 @@ public void IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provid
129
129
PngFilterMethod . Adaptive ,
130
130
PngBitDepth . Bit8 ,
131
131
interlaceMode ,
132
- appendPixelType : true ,
133
- appendPngColorType : true ) ;
132
+ appendPngColorType : true ,
133
+ appendPixelType : true ) ;
134
134
}
135
135
}
136
136
@@ -321,7 +321,7 @@ public void WritesFileMarker<TPixel>(TestImageProvider<TPixel> provider)
321
321
where TPixel : unmanaged, IPixel < TPixel >
322
322
{
323
323
using Image < TPixel > image = provider . GetImage ( ) ;
324
- using var ms = new MemoryStream ( ) ;
324
+ using MemoryStream ms = new ( ) ;
325
325
image . Save ( ms , PngEncoder ) ;
326
326
327
327
byte [ ] data = ms . ToArray ( ) . Take ( 8 ) . ToArray ( ) ;
@@ -344,13 +344,13 @@ public void WritesFileMarker<TPixel>(TestImageProvider<TPixel> provider)
344
344
[ MemberData ( nameof ( RatioFiles ) ) ]
345
345
public void Encode_PreserveRatio ( string imagePath , int xResolution , int yResolution , PixelResolutionUnit resolutionUnit )
346
346
{
347
- var testFile = TestFile . Create ( imagePath ) ;
347
+ TestFile testFile = TestFile . Create ( imagePath ) ;
348
348
using Image < Rgba32 > input = testFile . CreateRgba32Image ( ) ;
349
- using var memStream = new MemoryStream ( ) ;
349
+ using MemoryStream memStream = new ( ) ;
350
350
input . Save ( memStream , PngEncoder ) ;
351
351
352
352
memStream . Position = 0 ;
353
- using var output = Image . Load < Rgba32 > ( memStream ) ;
353
+ using Image < Rgba32 > output = Image . Load < Rgba32 > ( memStream ) ;
354
354
ImageMetadata meta = output . Metadata ;
355
355
Assert . Equal ( xResolution , meta . HorizontalResolution ) ;
356
356
Assert . Equal ( yResolution , meta . VerticalResolution ) ;
@@ -361,13 +361,13 @@ public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolut
361
361
[ MemberData ( nameof ( PngBitDepthFiles ) ) ]
362
362
public void Encode_PreserveBits ( string imagePath , PngBitDepth pngBitDepth )
363
363
{
364
- var testFile = TestFile . Create ( imagePath ) ;
364
+ TestFile testFile = TestFile . Create ( imagePath ) ;
365
365
using Image < Rgba32 > input = testFile . CreateRgba32Image ( ) ;
366
- using var memStream = new MemoryStream ( ) ;
366
+ using MemoryStream memStream = new ( ) ;
367
367
input . Save ( memStream , PngEncoder ) ;
368
368
369
369
memStream . Position = 0 ;
370
- using var output = Image . Load < Rgba32 > ( memStream ) ;
370
+ using Image < Rgba32 > output = Image . Load < Rgba32 > ( memStream ) ;
371
371
PngMetadata meta = output . Metadata . GetPngMetadata ( ) ;
372
372
373
373
Assert . Equal ( pngBitDepth , meta . BitDepth ) ;
@@ -380,8 +380,8 @@ public void Encode_PreserveBits(string imagePath, PngBitDepth pngBitDepth)
380
380
public void Encode_WithPngTransparentColorBehaviorClear_Works ( PngColorType colorType )
381
381
{
382
382
// arrange
383
- var image = new Image < Rgba32 > ( 50 , 50 ) ;
384
- var encoder = new PngEncoder ( )
383
+ Image < Rgba32 > image = new ( 50 , 50 ) ;
384
+ PngEncoder encoder = new ( )
385
385
{
386
386
TransparentColorMode = PngTransparentColorMode . Clear ,
387
387
ColorType = colorType
@@ -391,7 +391,7 @@ public void Encode_WithPngTransparentColorBehaviorClear_Works(PngColorType color
391
391
{
392
392
for ( int y = 0 ; y < image . Height ; y ++ )
393
393
{
394
- System . Span < Rgba32 > rowSpan = accessor . GetRowSpan ( y ) ;
394
+ Span < Rgba32 > rowSpan = accessor . GetRowSpan ( y ) ;
395
395
396
396
// Half of the test image should be transparent.
397
397
if ( y > 25 )
@@ -407,12 +407,12 @@ public void Encode_WithPngTransparentColorBehaviorClear_Works(PngColorType color
407
407
} ) ;
408
408
409
409
// act
410
- using var memStream = new MemoryStream ( ) ;
410
+ using MemoryStream memStream = new ( ) ;
411
411
image . Save ( memStream , encoder ) ;
412
412
413
413
// assert
414
414
memStream . Position = 0 ;
415
- using var actual = Image . Load < Rgba32 > ( memStream ) ;
415
+ using Image < Rgba32 > actual = Image . Load < Rgba32 > ( memStream ) ;
416
416
Rgba32 expectedColor = Color . Blue ;
417
417
if ( colorType is PngColorType . Grayscale or PngColorType . GrayscaleWithAlpha )
418
418
{
@@ -424,7 +424,7 @@ public void Encode_WithPngTransparentColorBehaviorClear_Works(PngColorType color
424
424
{
425
425
for ( int y = 0 ; y < accessor . Height ; y ++ )
426
426
{
427
- System . Span < Rgba32 > rowSpan = accessor . GetRowSpan ( y ) ;
427
+ Span < Rgba32 > rowSpan = accessor . GetRowSpan ( y ) ;
428
428
429
429
if ( y > 25 )
430
430
{
@@ -443,15 +443,15 @@ public void Encode_WithPngTransparentColorBehaviorClear_Works(PngColorType color
443
443
[ MemberData ( nameof ( PngTrnsFiles ) ) ]
444
444
public void Encode_PreserveTrns ( string imagePath , PngBitDepth pngBitDepth , PngColorType pngColorType )
445
445
{
446
- var testFile = TestFile . Create ( imagePath ) ;
446
+ TestFile testFile = TestFile . Create ( imagePath ) ;
447
447
using Image < Rgba32 > input = testFile . CreateRgba32Image ( ) ;
448
448
PngMetadata inMeta = input . Metadata . GetPngMetadata ( ) ;
449
449
Assert . True ( inMeta . HasTransparency ) ;
450
450
451
- using var memStream = new MemoryStream ( ) ;
451
+ using MemoryStream memStream = new ( ) ;
452
452
input . Save ( memStream , PngEncoder ) ;
453
453
memStream . Position = 0 ;
454
- using var output = Image . Load < Rgba32 > ( memStream ) ;
454
+ using Image < Rgba32 > output = Image . Load < Rgba32 > ( memStream ) ;
455
455
PngMetadata outMeta = output . Metadata . GetPngMetadata ( ) ;
456
456
Assert . True ( outMeta . HasTransparency ) ;
457
457
@@ -501,8 +501,8 @@ public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixe
501
501
PngFilterMethod . Adaptive ,
502
502
PngBitDepth . Bit8 ,
503
503
interlaceMode ,
504
- appendPixelType : true ,
505
- appendPngColorType : true ) ;
504
+ appendPngColorType : true ,
505
+ appendPixelType : true ) ;
506
506
}
507
507
}
508
508
@@ -523,8 +523,8 @@ static void RunTest(string serialized)
523
523
PngFilterMethod . Adaptive ,
524
524
PngBitDepth . Bit8 ,
525
525
interlaceMode ,
526
- appendPixelType : true ,
527
- appendPngColorType : true ) ;
526
+ appendPngColorType : true ,
527
+ appendPixelType : true ) ;
528
528
}
529
529
}
530
530
@@ -538,13 +538,27 @@ static void RunTest(string serialized)
538
538
public void EncodeFixesInvalidOptions ( )
539
539
{
540
540
// https://github.com/SixLabors/ImageSharp/issues/935
541
- using var ms = new MemoryStream ( ) ;
542
- var testFile = TestFile . Create ( TestImages . Png . Issue935 ) ;
541
+ using MemoryStream ms = new ( ) ;
542
+ TestFile testFile = TestFile . Create ( TestImages . Png . Issue935 ) ;
543
543
using Image < Rgba32 > image = testFile . CreateRgba32Image ( PngDecoder . Instance ) ;
544
544
545
545
image . Save ( ms , new PngEncoder { ColorType = PngColorType . RgbWithAlpha } ) ;
546
546
}
547
547
548
+ // https://github.com/SixLabors/ImageSharp/issues/2469
549
+ [ Theory ]
550
+ [ WithFile ( TestImages . Png . Issue2469 , PixelTypes . Rgba32 ) ]
551
+ public void Issue2469_Quantized_Encode_Artifacts < TPixel > ( TestImageProvider < TPixel > provider )
552
+ where TPixel : unmanaged, IPixel < TPixel >
553
+ {
554
+ using Image < TPixel > image = provider . GetImage ( PngDecoder . Instance ) ;
555
+ PngEncoder encoder = new ( ) { BitDepth = PngBitDepth . Bit8 , ColorType = PngColorType . Palette } ;
556
+
557
+ string actualOutputFile = provider . Utility . SaveTestOutputFile ( image , "png" , encoder ) ;
558
+ using Image < Rgba32 > encoded = Image . Load < Rgba32 > ( actualOutputFile ) ;
559
+ encoded . CompareToReferenceOutput ( ImageComparer . Exact , provider ) ;
560
+ }
561
+
548
562
private static void TestPngEncoderCore < TPixel > (
549
563
TestImageProvider < TPixel > provider ,
550
564
PngColorType pngColorType ,
@@ -563,7 +577,7 @@ private static void TestPngEncoderCore<TPixel>(
563
577
where TPixel : unmanaged, IPixel < TPixel >
564
578
{
565
579
using Image < TPixel > image = provider . GetImage ( ) ;
566
- var encoder = new PngEncoder
580
+ PngEncoder encoder = new ( )
567
581
{
568
582
ColorType = pngColorType ,
569
583
FilterMethod = pngFilterMethod ,
0 commit comments