|
|
@ -6,6 +6,7 @@ |
|
|
namespace ImageSharp.Formats |
|
|
namespace ImageSharp.Formats |
|
|
{ |
|
|
{ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Buffers; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
@ -111,8 +112,7 @@ namespace ImageSharp.Formats |
|
|
/// Thrown if the image is larger than the maximum allowable size.
|
|
|
/// Thrown if the image is larger than the maximum allowable size.
|
|
|
/// </exception>
|
|
|
/// </exception>
|
|
|
public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) |
|
|
public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) |
|
|
where TColor : struct, IPackedPixel<TPacked> |
|
|
where TColor : struct, IPackedPixel<TPacked> where TPacked : struct |
|
|
where TPacked : struct |
|
|
|
|
|
{ |
|
|
{ |
|
|
Image<TColor, TPacked> currentImage = image; |
|
|
Image<TColor, TPacked> currentImage = image; |
|
|
this.currentStream = stream; |
|
|
this.currentStream = stream; |
|
|
@ -182,8 +182,7 @@ namespace ImageSharp.Formats |
|
|
/// <param name="image">The image to read to.</param>
|
|
|
/// <param name="image">The image to read to.</param>
|
|
|
/// <param name="data">The data containing physical data.</param>
|
|
|
/// <param name="data">The data containing physical data.</param>
|
|
|
private void ReadPhysicalChunk<TColor, TPacked>(Image<TColor, TPacked> image, byte[] data) |
|
|
private void ReadPhysicalChunk<TColor, TPacked>(Image<TColor, TPacked> image, byte[] data) |
|
|
where TColor : struct, IPackedPixel<TPacked> |
|
|
where TColor : struct, IPackedPixel<TPacked> where TPacked : struct |
|
|
where TPacked : struct |
|
|
|
|
|
{ |
|
|
{ |
|
|
data.ReverseBytes(0, 4); |
|
|
data.ReverseBytes(0, 4); |
|
|
data.ReverseBytes(4, 4); |
|
|
data.ReverseBytes(4, 4); |
|
|
@ -244,8 +243,7 @@ namespace ImageSharp.Formats |
|
|
/// <param name="dataStream">The <see cref="MemoryStream"/> containing data.</param>
|
|
|
/// <param name="dataStream">The <see cref="MemoryStream"/> containing data.</param>
|
|
|
/// <param name="pixels"> The pixel data.</param>
|
|
|
/// <param name="pixels"> The pixel data.</param>
|
|
|
private void ReadScanlines<TColor, TPacked>(MemoryStream dataStream, PixelAccessor<TColor, TPacked> pixels) |
|
|
private void ReadScanlines<TColor, TPacked>(MemoryStream dataStream, PixelAccessor<TColor, TPacked> pixels) |
|
|
where TColor : struct, IPackedPixel<TPacked> |
|
|
where TColor : struct, IPackedPixel<TPacked> where TPacked : struct |
|
|
where TPacked : struct |
|
|
|
|
|
{ |
|
|
{ |
|
|
this.bytesPerPixel = this.CalculateBytesPerPixel(); |
|
|
this.bytesPerPixel = this.CalculateBytesPerPixel(); |
|
|
this.bytesPerScanline = this.CalculateScanlineLength() + 1; |
|
|
this.bytesPerScanline = this.CalculateScanlineLength() + 1; |
|
|
@ -270,13 +268,13 @@ namespace ImageSharp.Formats |
|
|
/// <param name="compressedStream">The compressed pixel data stream.</param>
|
|
|
/// <param name="compressedStream">The compressed pixel data stream.</param>
|
|
|
/// <param name="pixels">The image pixel accessor.</param>
|
|
|
/// <param name="pixels">The image pixel accessor.</param>
|
|
|
private void DecodePixelData<TColor, TPacked>(Stream compressedStream, PixelAccessor<TColor, TPacked> pixels) |
|
|
private void DecodePixelData<TColor, TPacked>(Stream compressedStream, PixelAccessor<TColor, TPacked> pixels) |
|
|
where TColor : struct, IPackedPixel<TPacked> |
|
|
where TColor : struct, IPackedPixel<TPacked> where TPacked : struct |
|
|
where TPacked : struct |
|
|
|
|
|
{ |
|
|
{ |
|
|
// TODO: ArrayPool<byte>.Shared.Rent(this.bytesPerScanline)
|
|
|
byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline); |
|
|
byte[] previousScanline = new byte[this.bytesPerScanline]; |
|
|
byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline); |
|
|
byte[] scanline = new byte[this.bytesPerScanline]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
for (int y = 0; y < this.header.Height; y++) |
|
|
for (int y = 0; y < this.header.Height; y++) |
|
|
{ |
|
|
{ |
|
|
compressedStream.Read(scanline, 0, this.bytesPerScanline); |
|
|
compressedStream.Read(scanline, 0, this.bytesPerScanline); |
|
|
@ -326,6 +324,12 @@ namespace ImageSharp.Formats |
|
|
scanline = temp; |
|
|
scanline = temp; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
ArrayPool<byte>.Shared.Return(previousScanline); |
|
|
|
|
|
ArrayPool<byte>.Shared.Return(scanline); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Processes the de-filtered scanline filling the image pixel data
|
|
|
/// Processes the de-filtered scanline filling the image pixel data
|
|
|
@ -618,10 +622,7 @@ namespace ImageSharp.Formats |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Calculates the length of the given chunk.
|
|
|
/// Calculates the length of the given chunk.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="chunk">he chunk.</param>
|
|
|
/// <param name="chunk">The chunk.</param>
|
|
|
/// <returns>
|
|
|
|
|
|
/// The <see cref="int"/> representing the chunk length.
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
/// <exception cref="ImageFormatException">
|
|
|
/// <exception cref="ImageFormatException">
|
|
|
/// Thrown if the input stream is not valid.
|
|
|
/// Thrown if the input stream is not valid.
|
|
|
/// </exception>
|
|
|
/// </exception>
|
|
|
|