Browse Source

Fix scanline lengths

pull/2588/head
James Jackson-South 3 years ago
parent
commit
6cda7b03c6
  1. 2
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  2. 18
      src/ImageSharp/Formats/Png/PngDecoderCore.cs

2
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -176,7 +176,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
{
if (image.Metadata.TryGetGifMetadata(out GifMetadata? gif))
{
return gif;
return (GifMetadata)gif.DeepClone();
}
if (image.Metadata.TryGetPngMetadata(out PngMetadata? png))

18
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -764,10 +764,12 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
{
cancellationToken.ThrowIfCancellationRequested();
int bytesPerFrameScanline = this.CalculateScanlineLength((int)frameControl.Width) + 1;
Span<byte> scanlineSpan = this.scanline.GetSpan()[..bytesPerFrameScanline];
Span<byte> scanSpan = this.scanline.GetSpan()[..bytesPerFrameScanline];
Span<byte> prevSpan = this.scanline.GetSpan()[..bytesPerFrameScanline];
while (currentRowBytesRead < bytesPerFrameScanline)
{
int bytesRead = compressedStream.Read(scanlineSpan, currentRowBytesRead, bytesPerFrameScanline - currentRowBytesRead);
int bytesRead = compressedStream.Read(scanSpan, currentRowBytesRead, bytesPerFrameScanline - currentRowBytesRead);
if (bytesRead <= 0)
{
return;
@ -778,25 +780,25 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
currentRowBytesRead = 0;
switch ((FilterType)scanlineSpan[0])
switch ((FilterType)scanSpan[0])
{
case FilterType.None:
break;
case FilterType.Sub:
SubFilter.Decode(scanlineSpan, this.bytesPerPixel);
SubFilter.Decode(scanSpan, this.bytesPerPixel);
break;
case FilterType.Up:
UpFilter.Decode(scanlineSpan, this.previousScanline.GetSpan());
UpFilter.Decode(scanSpan, prevSpan);
break;
case FilterType.Average:
AverageFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel);
AverageFilter.Decode(scanSpan, prevSpan, this.bytesPerPixel);
break;
case FilterType.Paeth:
PaethFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel);
PaethFilter.Decode(scanSpan, prevSpan, this.bytesPerPixel);
break;
default:
@ -804,7 +806,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
break;
}
this.ProcessDefilteredScanline(frameControl, currentRow, scanlineSpan, imageFrame, pngMetadata, blendRowBuffer);
this.ProcessDefilteredScanline(frameControl, currentRow, scanSpan, imageFrame, pngMetadata, blendRowBuffer);
this.SwapScanlineBuffers();
currentRow++;
}

Loading…
Cancel
Save