//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp.Formats
{
using System;
using System.IO;
using ImageSharp.Quantizers;
///
/// Image encoder for writing image data to a stream in png format.
///
public class PngEncoder : IImageEncoder
{
///
/// Gets or sets the quality of output for images.
///
public int Quality { get; set; }
///
/// Gets or sets the png color type
///
public PngColorType PngColorType { get; set; } = PngColorType.RgbWithAlpha;
///
/// Gets or sets the compression level 1-9.
/// Defaults to 6.
///
public int CompressionLevel { get; set; } = 6;
///
/// Gets or sets the gamma value, that will be written
/// the the stream, when the property
/// is set to true. The default value is 2.2F.
///
/// The gamma value of the image.
public float Gamma { get; set; } = 2.2F;
///
/// Gets or sets quantizer for reducing the color count.
///
public IQuantizer Quantizer { get; set; }
///
/// Gets or sets the transparency threshold.
///
public byte Threshold { get; set; } = 0;
///
/// Gets or sets a value indicating whether this instance should write
/// gamma information to the stream. The default value is false.
///
public bool WriteGamma { get; set; }
///
public void Encode(Image image, Stream stream)
where TColor : struct, IPixel
{
PngEncoderCore encoder = new PngEncoderCore
{
CompressionLevel = this.CompressionLevel,
Gamma = this.Gamma,
Quality = this.Quality,
PngColorType = this.PngColorType,
Quantizer = this.Quantizer,
WriteGamma = this.WriteGamma,
Threshold = this.Threshold
};
encoder.Encode(image, stream);
}
}
}