From 7e6deb22ff2ce4fa2586efb4e0e11f0791411597 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 10 Nov 2016 21:36:53 +1100 Subject: [PATCH] Less memory with sub filter encoding --- src/ImageSharp/Formats/Png/Filters/SubFilter.cs | 4 +--- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index 79ebcf835..833790f0e 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -44,11 +44,9 @@ namespace ImageSharp.Formats /// The bytes per pixel. /// The number of bytes per scanline /// The - public static byte[] Encode(byte[] scanline, int bytesPerPixel, int bytesPerScanline) + public static byte[] Encode(byte[] scanline, byte[] result, int bytesPerPixel, int bytesPerScanline) { // Sub(x) = Raw(x) - Raw(x-bpp) - byte[] result = new byte[bytesPerScanline + 1]; - fixed (byte* scan = scanline) fixed (byte* res = result) { diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 8e83d477e..098ad32bd 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -355,7 +355,7 @@ namespace ImageSharp.Formats Tuple[] candidates = new Tuple[4]; - byte[] sub = SubFilter.Encode(rawScanline, this.bytesPerPixel, bytesPerScanline); + byte[] sub = SubFilter.Encode(rawScanline, result, this.bytesPerPixel, bytesPerScanline); candidates[0] = new Tuple(sub, this.CalculateTotalVariation(sub)); byte[] up = UpFilter.Encode(rawScanline, previousScanline, result, bytesPerScanline);