Browse Source

Take another Mb off the memory usage.

pull/23/head
James Jackson-South 10 years ago
parent
commit
79f1def8a5
  1. 48
      src/ImageSharp/Formats/Png/PngDecoderCore.cs

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

@ -129,35 +129,31 @@ namespace ImageSharp.Formats
throw new ImageFormatException("Image does not end with end chunk."); throw new ImageFormatException("Image does not end with end chunk.");
} }
if (currentChunk.Type == PngChunkTypes.Header) switch (currentChunk.Type)
{ {
case PngChunkTypes.Header:
this.ReadHeaderChunk(currentChunk.Data); this.ReadHeaderChunk(currentChunk.Data);
this.ValidateHeader(); this.ValidateHeader();
} break;
else if (currentChunk.Type == PngChunkTypes.Physical) case PngChunkTypes.Physical:
{
this.ReadPhysicalChunk(currentImage, currentChunk.Data); this.ReadPhysicalChunk(currentImage, currentChunk.Data);
} break;
else if (currentChunk.Type == PngChunkTypes.Data) case PngChunkTypes.Data:
{
dataStream.Write(currentChunk.Data, 0, currentChunk.Data.Length); dataStream.Write(currentChunk.Data, 0, currentChunk.Data.Length);
} break;
else if (currentChunk.Type == PngChunkTypes.Palette) case PngChunkTypes.Palette:
{
this.palette = currentChunk.Data; this.palette = currentChunk.Data;
image.Quality = this.palette.Length / 3; image.Quality = this.palette.Length / 3;
} break;
else if (currentChunk.Type == PngChunkTypes.PaletteAlpha) case PngChunkTypes.PaletteAlpha:
{
this.paletteAlpha = currentChunk.Data; this.paletteAlpha = currentChunk.Data;
} break;
else if (currentChunk.Type == PngChunkTypes.Text) case PngChunkTypes.Text:
{
this.ReadTextChunk(currentImage, currentChunk.Data); this.ReadTextChunk(currentImage, currentChunk.Data);
} break;
else if (currentChunk.Type == PngChunkTypes.End) case PngChunkTypes.End:
{
isEndChunkReached = true; isEndChunkReached = true;
break;
} }
} }
@ -262,18 +258,7 @@ namespace ImageSharp.Formats
dataStream.Position = 0; dataStream.Position = 0;
using (ZlibInflateStream compressedStream = new ZlibInflateStream(dataStream)) using (ZlibInflateStream compressedStream = new ZlibInflateStream(dataStream))
{ {
using (MemoryStream decompressedStream = new MemoryStream()) this.DecodePixelData(compressedStream, pixels);
{
compressedStream.CopyTo(decompressedStream);
decompressedStream.Flush();
decompressedStream.Position = 0;
this.DecodePixelData(decompressedStream, pixels);
//byte[] decompressedBytes = decompressedStream.ToArray();
//this.DecodePixelData(decompressedBytes, pixels);
}
//byte[] decompressedBytes = compressedStream.ToArray();
//this.DecodePixelData(decompressedBytes, pixels);
} }
} }
@ -298,6 +283,7 @@ namespace ImageSharp.Formats
FilterType filterType = (FilterType)scanline[0]; FilterType filterType = (FilterType)scanline[0];
byte[] defilteredScanline; byte[] defilteredScanline;
// TODO: It would be good if we can reduce the memory usage here. Each filter is creating a new row.
switch (filterType) switch (filterType)
{ {
case FilterType.None: case FilterType.None:

Loading…
Cancel
Save