Browse Source

Remove PngChunkTypeNames

af/merge-core
Jason Nelson 8 years ago
parent
commit
55366d3258
  1. 42
      src/ImageSharp/Formats/Png/PngChunkType.cs
  2. 60
      src/ImageSharp/Formats/Png/PngChunkTypeNames.cs
  3. 2
      tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs
  4. 12
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

42
src/ImageSharp/Formats/Png/PngChunkType.cs

@ -4,17 +4,57 @@
namespace SixLabors.ImageSharp.Formats.Png namespace SixLabors.ImageSharp.Formats.Png
{ {
/// <summary> /// <summary>
/// Contains a list of possible chunk types. /// Contains a list of of chunk types.
/// </summary> /// </summary>
internal enum PngChunkType : uint internal enum PngChunkType : uint
{ {
/// <summary>
/// The first chunk in a png file. Can only exists once. Contains
/// common information like the width and the height of the image or
/// the used compression method.
/// </summary>
Header = 1229472850U, // IHDR Header = 1229472850U, // IHDR
/// <summary>
/// The PLTE chunk contains from 1 to 256 palette entries, each a three byte
/// series in the RGB format.
/// </summary>
Palette = 1347179589U, // PLTE Palette = 1347179589U, // PLTE
/// <summary>
/// The IDAT chunk contains the actual image data. The image can contains more
/// than one chunk of this type. All chunks together are the whole image.
/// </summary>
Data = 1229209940U, // IDAT Data = 1229209940U, // IDAT
/// <summary>
/// This chunk must appear last. It marks the end of the PNG data stream.
/// The chunk's data field is empty.
/// </summary>
End = 1229278788U, // IEND End = 1229278788U, // IEND
/// <summary>
/// This chunk specifies that the image uses simple transparency:
/// either alpha values associated with palette entries (for indexed-color images)
/// or a single transparent color (for grayscale and true color images).
/// </summary>
PaletteAlpha = 1951551059U, // tRNS PaletteAlpha = 1951551059U, // tRNS
/// <summary>
/// Textual information that the encoder wishes to record with the image can be stored in
/// tEXt chunks. Each tEXt chunk contains a keyword and a text string.
/// </summary>
Text = 1950701684U, // tEXt Text = 1950701684U, // tEXt
/// <summary>
/// This chunk specifies the relationship between the image samples and the desired
/// display output intensity.
/// </summary>
Gamma = 1732332865U, // gAMA Gamma = 1732332865U, // gAMA
/// <summary>
/// The pHYs chunk specifies the intended pixel size or aspect ratio for display of the image.
/// </summary>
Physical = 1883789683U, // pHYs Physical = 1883789683U, // pHYs
} }
} }

60
src/ImageSharp/Formats/Png/PngChunkTypeNames.cs

@ -1,60 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Formats.Png
{
/// <summary>
/// Contains a list of possible chunk type identifier names.
/// </summary>
internal static class PngChunkTypeNames
{
/// <summary>
/// The first chunk in a png file. Can only exists once. Contains
/// common information like the width and the height of the image or
/// the used compression method.
/// </summary>
public const string Header = "IHDR";
/// <summary>
/// The PLTE chunk contains from 1 to 256 palette entries, each a three byte
/// series in the RGB format.
/// </summary>
public const string Palette = "PLTE";
/// <summary>
/// The IDAT chunk contains the actual image data. The image can contains more
/// than one chunk of this type. All chunks together are the whole image.
/// </summary>
public const string Data = "IDAT";
/// <summary>
/// This chunk must appear last. It marks the end of the PNG data stream.
/// The chunk's data field is empty.
/// </summary>
public const string End = "IEND";
/// <summary>
/// This chunk specifies that the image uses simple transparency:
/// either alpha values associated with palette entries (for indexed-color images)
/// or a single transparent color (for grayscale and true color images).
/// </summary>
public const string PaletteAlpha = "tRNS";
/// <summary>
/// Textual information that the encoder wishes to record with the image can be stored in
/// tEXt chunks. Each tEXt chunk contains a keyword and a text string.
/// </summary>
public const string Text = "tEXt";
/// <summary>
/// This chunk specifies the relationship between the image samples and the desired
/// display output intensity.
/// </summary>
public const string Gamma = "gAMA";
/// <summary>
/// The pHYs chunk specifies the intended pixel size or aspect ratio for display of the image.
/// </summary>
public const string Physical = "pHYs";
}
}

2
tests/ImageSharp.Tests/Formats/Png/PngChunkTests.cs → tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs

@ -6,7 +6,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Png namespace SixLabors.ImageSharp.Tests.Formats.Png
{ {
public class PngChunkTests public class PngChunkTypeTests
{ {
[Fact] [Fact]
public void ChunkTypeIdsAreCorrect() public void ChunkTypeIdsAreCorrect()

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

@ -242,10 +242,10 @@ namespace SixLabors.ImageSharp.Tests
} }
[Theory] [Theory]
[InlineData(PngChunkTypeNames.Header)] [InlineData("IHDR")] // Header
[InlineData(PngChunkTypeNames.Palette)] [InlineData("PLTE")] // Palette
// [InlineData(PngChunkTypes.Data)] //TODO: Figure out how to test this // [InlineData(PngChunkTypes.Data)] //TODO: Figure out how to test this
[InlineData(PngChunkTypeNames.End)] [InlineData("IEND")] // End
public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(string chunkName) public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(string chunkName)
{ {
using (var memStream = new MemoryStream()) using (var memStream = new MemoryStream())
@ -266,9 +266,9 @@ namespace SixLabors.ImageSharp.Tests
} }
[Theory] [Theory]
[InlineData(PngChunkTypeNames.Gamma)] [InlineData("gAMA")] // Gamma
[InlineData(PngChunkTypeNames.PaletteAlpha)] [InlineData("tRNS")] // PaletteAlpha
[InlineData(PngChunkTypeNames.Physical)] // It's ok to test physical as we don't throw for duplicate chunks. [InlineData("pHYs")] // Pysical: It's ok to test physical as we don't throw for duplicate chunks.
//[InlineData(PngChunkTypes.Text)] //TODO: Figure out how to test this //[InlineData(PngChunkTypes.Text)] //TODO: Figure out how to test this
public void Decode_IncorrectCRCForNonCriticalChunk_ExceptionIsThrown(string chunkName) public void Decode_IncorrectCRCForNonCriticalChunk_ExceptionIsThrown(string chunkName)
{ {

Loading…
Cancel
Save