Browse Source

Reuse Crc

af/merge-core
James Jackson-South 10 years ago
parent
commit
17bd270bee
  1. 13
      src/ImageSharp/Formats/Png/PngEncoderCore.cs

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

@ -35,6 +35,11 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
private readonly byte[] chunkDataBuffer = new byte[16]; private readonly byte[] chunkDataBuffer = new byte[16];
/// <summary>
/// Reusable crc for validating chunks.
/// </summary>
private readonly Crc32 crc = new Crc32();
/// <summary> /// <summary>
/// Contains the raw pixel data from an indexed image. /// Contains the raw pixel data from an indexed image.
/// </summary> /// </summary>
@ -717,15 +722,15 @@ namespace ImageSharp.Formats
stream.Write(data, offset, length); stream.Write(data, offset, length);
} }
Crc32 crc32 = new Crc32(); this.crc.Reset();
crc32.Update(this.chunkTypeBuffer); this.crc.Update(this.chunkTypeBuffer);
if (data != null && length > 0) if (data != null && length > 0)
{ {
crc32.Update(data, offset, length); this.crc.Update(data, offset, length);
} }
WriteInteger(stream, (uint)crc32.Value); WriteInteger(stream, (uint)this.crc.Value);
} }
} }
} }
Loading…
Cancel
Save