From e80851464864cf83ec52ff2cfbaa2480acdcd088 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 18 Jun 2018 16:40:29 +1000 Subject: [PATCH] All tests now pass --- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 38 +++++++++++++++---- .../Drawing/Text/DrawTextOnImageTests.cs | 13 ++++--- .../Tests/TestEnvironmentTests.cs | 4 +- tests/Images/External | 2 +- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 2c516b829..d816a0fd2 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -5,8 +5,6 @@ using System; using System.Buffers.Binary; using System.IO; using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; @@ -394,7 +392,6 @@ namespace SixLabors.ImageSharp.Formats.Png switch (this.pngColorType) { case PngColorType.Palette: - // TODO: Use Span copy! Buffer.BlockCopy(this.palettePixelData, row * this.rawScanline.Length(), this.rawScanline.Array, 0, this.rawScanline.Length()); break; case PngColorType.Grayscale: @@ -646,12 +643,37 @@ namespace SixLabors.ImageSharp.Formats.Png this.rawScanline = this.memoryAllocator.AllocateCleanManagedByteBuffer(this.bytesPerScanline); this.result = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); - if (this.pngColorType != PngColorType.Palette) + switch (this.pngFilterMethod) { - this.sub = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); - this.up = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); - this.average = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); - this.paeth = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + case PngFilterMethod.None: + break; + + case PngFilterMethod.Sub: + + this.sub = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + break; + + case PngFilterMethod.Up: + + this.up = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + break; + + case PngFilterMethod.Average: + + this.average = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + break; + + case PngFilterMethod.Paeth: + + this.paeth = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + break; + case PngFilterMethod.Adaptive: + + this.sub = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.up = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.average = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + this.paeth = this.memoryAllocator.AllocateCleanManagedByteBuffer(resultLength); + break; } byte[] buffer; diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs index a9c7a6ebb..13e0bbadf 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawTextOnImageTests.cs @@ -84,12 +84,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } var textOptions = new TextGraphicsOptions - { - Antialias = true, - ApplyKerning = true, - VerticalAlignment = VerticalAlignment.Top, - HorizontalAlignment = HorizontalAlignment.Left, - }; + { + Antialias = true, + ApplyKerning = true, + VerticalAlignment = VerticalAlignment.Top, + HorizontalAlignment = HorizontalAlignment.Left, + }; + TPixel color = NamedColors.Black; provider.VerifyOperation( diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs index 9db55281e..40338e859 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests } [Theory] - [InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))] + [InlineData("lol/foo.png", typeof(PngEncoder))] [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceEncoder))] [InlineData("lol/Baz.JPG", typeof(JpegEncoder))] [InlineData("lol/Baz.gif", typeof(GifEncoder))] @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests } [Theory] - [InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))] + [InlineData("lol/foo.png", typeof(PngDecoder))] [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] diff --git a/tests/Images/External b/tests/Images/External index 0e6407be7..147306294 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 0e6407be7081341526f815a4d70e7912db276a98 +Subproject commit 147306294437dc03f6e640f5db2dcd496a43ced7