Browse Source

Move the png header to constants

af/merge-core
Jason Nelson 8 years ago
parent
commit
c77f612aab
  1. 11
      src/ImageSharp/Formats/Png/PngConstants.cs
  2. 12
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  3. 2
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

11
src/ImageSharp/Formats/Png/PngConstants.cs

@ -25,5 +25,16 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The list of file extensions that equate to a png.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "png" };
public static readonly byte[] HeaderBytes = {
0x89, // Set the high bit.
0x50, // P
0x4E, // N
0x47, // G
0x0D, // Line ending CRLF
0x0A, // Line ending CRLF
0x1A, // EOF
0x0A // LF
};
}
}

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

@ -167,17 +167,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.width = image.Width;
this.height = image.Height;
// Write the png header.
this.chunkDataBuffer[0] = 0x89; // Set the high bit.
this.chunkDataBuffer[1] = 0x50; // P
this.chunkDataBuffer[2] = 0x4E; // N
this.chunkDataBuffer[3] = 0x47; // G
this.chunkDataBuffer[4] = 0x0D; // Line ending CRLF
this.chunkDataBuffer[5] = 0x0A; // Line ending CRLF
this.chunkDataBuffer[6] = 0x1A; // EOF
this.chunkDataBuffer[7] = 0x0A; // LF
stream.Write(this.chunkDataBuffer, 0, 8);
stream.Write(PngConstants.HeaderBytes, 0, PngConstants.HeaderBytes.Length);
QuantizedFrame<TPixel> quantized = null;
if (this.pngColorType == PngColorType.Palette)

2
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
using System.IO.Compression;
using System.Text;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
// ReSharper disable InconsistentNaming

Loading…
Cancel
Save