diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
index 87fd2582a..0b27539c2 100644
--- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
@@ -28,9 +28,9 @@ namespace SixLabors.ImageSharp.Formats.Png
///
/// Gets the compression level 1-9.
- /// Defaults to 6.
+ /// Defaults to .
///
- int CompressionLevel { get; }
+ PngCompressionLevel CompressionLevel { get; }
///
/// Gets the threshold of characters in text metadata, when compression should be used.
diff --git a/src/ImageSharp/Formats/Png/PngCompressionLevel.cs b/src/ImageSharp/Formats/Png/PngCompressionLevel.cs
new file mode 100644
index 000000000..1d93884a3
--- /dev/null
+++ b/src/ImageSharp/Formats/Png/PngCompressionLevel.cs
@@ -0,0 +1,81 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+namespace SixLabors.ImageSharp.Formats.Png
+{
+ ///
+ /// Provides enumeration of available PNG compression levels.
+ ///
+ public enum PngCompressionLevel
+ {
+ ///
+ /// Level 0. Equivalent to .
+ ///
+ Level0 = 0,
+
+ ///
+ /// No compression. Equivalent to .
+ ///
+ NoCompression = Level0,
+
+ ///
+ /// Level 1. Equivalent to .
+ ///
+ Level1 = 1,
+
+ ///
+ /// Best speed compression level.
+ ///
+ BestSpeed = Level1,
+
+ ///
+ /// Level 2.
+ ///
+ Level2 = 2,
+
+ ///
+ /// Level 3.
+ ///
+ Level3 = 3,
+
+ ///
+ /// Level 4.
+ ///
+ Level4 = 4,
+
+ ///
+ /// Level 5.
+ ///
+ Level5 = 5,
+
+ ///
+ /// Level 6. Equivalent to .
+ ///
+ Level6 = 6,
+
+ ///
+ /// The default compression level. Equivalent to .
+ ///
+ DefaultCompression = Level6,
+
+ ///
+ /// Level 7.
+ ///
+ Level7 = 7,
+
+ ///
+ /// Level 8.
+ ///
+ Level8 = 8,
+
+ ///
+ /// Level 9. Equivalent to .
+ ///
+ Level9 = 9,
+
+ ///
+ /// Best compression level. Equivalent to .
+ ///
+ BestCompression = Level9,
+ }
+}
diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs
index e654036a8..95c02b348 100644
--- a/src/ImageSharp/Formats/Png/PngEncoder.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoder.cs
@@ -13,43 +13,25 @@ namespace SixLabors.ImageSharp.Formats.Png
///
public sealed class PngEncoder : IImageEncoder, IPngEncoderOptions
{
- ///
- /// Gets or sets the number of bits per sample or per palette index (not per pixel).
- /// Not all values are allowed for all values.
- ///
+ ///
public PngBitDepth? BitDepth { get; set; }
- ///
- /// Gets or sets the color type.
- ///
+ ///
public PngColorType? ColorType { get; set; }
- ///
- /// Gets or sets the filter method.
- ///
+ ///
public PngFilterMethod? FilterMethod { get; set; }
- ///
- /// Gets or sets the compression level 1-9.
- /// Defaults to 6.
- ///
- public int CompressionLevel { get; set; } = 6;
+ ///
+ public PngCompressionLevel CompressionLevel { get; set; } = PngCompressionLevel.DefaultCompression;
- ///
- /// Gets or sets the threshold of characters in text metadata, when compression should be used.
- /// Defaults to 1024.
- ///
+ ///
public int TextCompressionThreshold { get; set; } = 1024;
- ///
- /// Gets or sets the gamma value, that will be written the image.
- ///
+ ///
public float? Gamma { get; set; }
- ///
- /// Gets or sets quantizer for reducing the color count.
- /// Defaults to the .
- ///
+ ///
public IQuantizer Quantizer { get; set; }
///
@@ -57,9 +39,7 @@ namespace SixLabors.ImageSharp.Formats.Png
///
public byte Threshold { get; set; } = byte.MaxValue;
- ///
- /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image.
- ///
+ ///
public PngInterlaceMode? InterlaceMethod { get; set; }
///
diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
index dd6c66cb7..a6ac86d54 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
@@ -31,52 +31,31 @@ namespace SixLabors.ImageSharp.Formats.Png
this.InterlaceMethod = source.InterlaceMethod;
}
- ///
- /// Gets or sets the number of bits per sample or per palette index (not per pixel).
- /// Not all values are allowed for all values.
- ///
+ ///
public PngBitDepth? BitDepth { get; set; }
- ///
- /// Gets or sets the color type.
- ///
+ ///
public PngColorType? ColorType { get; set; }
- ///
- /// Gets the filter method.
- ///
+ ///
public PngFilterMethod? FilterMethod { get; }
- ///
- /// Gets the compression level 1-9.
- /// Defaults to 6.
- ///
- public int CompressionLevel { get; }
+ ///
+ public PngCompressionLevel CompressionLevel { get; } = PngCompressionLevel.DefaultCompression;
///
public int TextCompressionThreshold { get; }
- ///
- /// Gets or sets the gamma value, that will be written the image.
- ///
- ///
- /// The gamma value of the image.
- ///
+ ///
public float? Gamma { get; set; }
- ///
- /// Gets or sets the quantizer for reducing the color count.
- ///
+ ///
public IQuantizer Quantizer { get; set; }
- ///
- /// Gets the transparency threshold.
- ///
+ ///
public byte Threshold { get; }
- ///
- /// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image.
- ///
+ ///
public PngInterlaceMode? InterlaceMethod { get; set; }
}
}
diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
index c723b463f..182933033 100644
--- a/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
+++ b/src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
@@ -46,9 +46,10 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
///
/// The memory allocator to use for buffer allocations.
/// The stream to compress.
- /// The compression level.
- public ZlibDeflateStream(MemoryAllocator memoryAllocator, Stream stream, int compressionLevel)
+ /// The compression level.
+ public ZlibDeflateStream(MemoryAllocator memoryAllocator, Stream stream, PngCompressionLevel level)
{
+ int compressionLevel = (int)level;
this.rawStream = stream;
// Write the zlib header : http://tools.ietf.org/html/rfc1950
diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
index fb5dc9a63..2d5b2e25d 100644
--- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
@@ -65,9 +65,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
///
/// All types except Palette
///
- public static readonly TheoryData CompressionLevels = new TheoryData
+ public static readonly TheoryData CompressionLevels
+ = new TheoryData
{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+ PngCompressionLevel.Level0,
+ PngCompressionLevel.Level1,
+ PngCompressionLevel.Level2,
+ PngCompressionLevel.Level3,
+ PngCompressionLevel.Level4,
+ PngCompressionLevel.Level5,
+ PngCompressionLevel.Level6,
+ PngCompressionLevel.Level7,
+ PngCompressionLevel.Level8,
+ PngCompressionLevel.Level9,
};
public static readonly TheoryData PaletteSizes = new TheoryData
@@ -150,7 +160,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
[Theory]
[WithTestPatternImages(nameof(CompressionLevels), 24, 24, PixelTypes.Rgba32)]
- public void WorksWithAllCompressionLevels(TestImageProvider provider, int compressionLevel)
+ public void WorksWithAllCompressionLevels(TestImageProvider provider, PngCompressionLevel compressionLevel)
where TPixel : unmanaged, IPixel
{
foreach (PngInterlaceMode interlaceMode in InterlaceMode)
@@ -547,7 +557,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
PngFilterMethod pngFilterMethod,
PngBitDepth bitDepth,
PngInterlaceMode interlaceMode,
- int compressionLevel = 6,
+ PngCompressionLevel compressionLevel = PngCompressionLevel.DefaultCompression,
int paletteSize = 255,
bool appendPngColorType = false,
bool appendPngFilterMethod = false,