Browse Source

Add default seed values

pull/1574/head
James Jackson-South 6 years ago
parent
commit
e54d1312d6
  1. 9
      src/ImageSharp/Formats/Png/Zlib/Adler32.cs
  2. 9
      src/ImageSharp/Formats/Png/Zlib/Crc32.cs
  3. 2
      src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs

9
src/ImageSharp/Formats/Png/Zlib/Adler32.cs

@ -17,6 +17,11 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// </summary>
internal static class Adler32
{
/// <summary>
/// The default initial seed value of a Adler32 checksum calculation.
/// </summary>
public const uint SeedValue = 1U;
#if SUPPORTS_RUNTIME_INTRINSICS
private const int MinBufferSize = 64;
#endif
@ -34,7 +39,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// <returns>The <see cref="uint"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static uint Calculate(ReadOnlySpan<byte> buffer)
=> Calculate(1U, buffer);
=> Calculate(SeedValue, buffer);
/// <summary>
/// Calculates the Adler32 checksum with the bytes taken from the span and seed.
@ -47,7 +52,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
{
if (buffer.IsEmpty)
{
return 1U;
return SeedValue;
}
#if SUPPORTS_RUNTIME_INTRINSICS

9
src/ImageSharp/Formats/Png/Zlib/Crc32.cs

@ -17,6 +17,11 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// </summary>
internal static partial class Crc32
{
/// <summary>
/// The default initial seed value of a Crc32 checksum calculation.
/// </summary>
public const uint SeedValue = 0U;
#if SUPPORTS_RUNTIME_INTRINSICS
private const int MinBufferSize = 64;
private const int ChunksizeMask = 15;
@ -36,7 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// <returns>The <see cref="uint"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static uint Calculate(ReadOnlySpan<byte> buffer)
=> Calculate(0U, buffer);
=> Calculate(SeedValue, buffer);
/// <summary>
/// Calculates the CRC checksum with the bytes taken from the span and seed.
@ -49,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
{
if (buffer.IsEmpty)
{
return 0U;
return SeedValue;
}
#if SUPPORTS_RUNTIME_INTRINSICS

2
src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs

@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// <summary>
/// Computes the checksum for the data stream.
/// </summary>
private uint adler = 1U;
private uint adler = Adler32.SeedValue;
/// <summary>
/// A value indicating whether this instance of the given entity has been disposed.

Loading…
Cancel
Save