Browse Source

Merge pull request #1212 from SixLabors/js/fix-1211

Swap buffers when encoding PNG with Filtered Adam7 Palette mode
pull/1574/head
James Jackson-South 6 years ago
committed by GitHub
parent
commit
ef5d70e4bd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  2. 10
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

4
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -1081,6 +1081,10 @@ namespace SixLabors.ImageSharp.Formats.Png
// encode data // encode data
IManagedByteBuffer r = this.EncodeAdam7IndexedPixelRow(destSpan); IManagedByteBuffer r = this.EncodeAdam7IndexedPixelRow(destSpan);
deflateStream.Write(r.Array, 0, resultLength); deflateStream.Write(r.Array, 0, resultLength);
IManagedByteBuffer temp = this.currentScanline;
this.currentScanline = this.previousScanline;
this.previousScanline = temp;
} }
} }
} }

10
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -199,12 +199,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
return; return;
} }
foreach (var filterMethod in PngFilterMethods)
{
foreach (PngInterlaceMode interlaceMode in InterlaceMode) foreach (PngInterlaceMode interlaceMode in InterlaceMode)
{ {
TestPngEncoderCore( TestPngEncoderCore(
provider, provider,
pngColorType, pngColorType,
PngFilterMethod.Adaptive, (PngFilterMethod)filterMethod[0],
pngBitDepth, pngBitDepth,
interlaceMode, interlaceMode,
appendPngColorType: true, appendPngColorType: true,
@ -212,6 +214,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
appendPngBitDepth: true); appendPngBitDepth: true);
} }
} }
}
[Theory] [Theory]
[WithTestPatternImages(24, 24, PixelTypes.Rgba32, PngColorType.Rgb, PngBitDepth.Bit8)] [WithTestPatternImages(24, 24, PixelTypes.Rgba32, PngColorType.Rgb, PngBitDepth.Bit8)]
@ -231,13 +234,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
[WithTestPatternImages(24, 24, PixelTypes.Rgba64, PngColorType.GrayscaleWithAlpha, PngBitDepth.Bit16)] [WithTestPatternImages(24, 24, PixelTypes.Rgba64, PngColorType.GrayscaleWithAlpha, PngBitDepth.Bit16)]
public void WorksWithAllBitDepthsAndExcludeAllFilter<TPixel>(TestImageProvider<TPixel> provider, PngColorType pngColorType, PngBitDepth pngBitDepth) public void WorksWithAllBitDepthsAndExcludeAllFilter<TPixel>(TestImageProvider<TPixel> provider, PngColorType pngColorType, PngBitDepth pngBitDepth)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{
foreach (var filterMethod in PngFilterMethods)
{ {
foreach (PngInterlaceMode interlaceMode in InterlaceMode) foreach (PngInterlaceMode interlaceMode in InterlaceMode)
{ {
TestPngEncoderCore( TestPngEncoderCore(
provider, provider,
pngColorType, pngColorType,
PngFilterMethod.Adaptive, (PngFilterMethod)filterMethod[0],
pngBitDepth, pngBitDepth,
interlaceMode, interlaceMode,
appendPngColorType: true, appendPngColorType: true,
@ -246,6 +251,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
optimizeMethod: PngChunkFilter.ExcludeAll); optimizeMethod: PngChunkFilter.ExcludeAll);
} }
} }
}
[Theory] [Theory]
[WithBlankImages(1, 1, PixelTypes.A8, PngColorType.GrayscaleWithAlpha, PngBitDepth.Bit8)] [WithBlankImages(1, 1, PixelTypes.A8, PngColorType.GrayscaleWithAlpha, PngBitDepth.Bit8)]

Loading…
Cancel
Save