Exemplo n.º 1
0
        /// <summary>
        /// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param>
        /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
        /// <param name="options">The options for the encoder.</param>
        public void Encode <TColor>(Image <TColor> image, Stream stream, IPngEncoderOptions options)
            where TColor : struct, IPixel <TColor>
        {
            PngEncoderCore encode = new PngEncoderCore(options);

            encode.Encode(image, stream);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public void Encode <TColor>(Image <TColor> image, Stream stream, IEncoderOptions options)
            where TColor : struct, IPixel <TColor>
        {
            IPngEncoderOptions pngOptions = PngEncoderOptions.Create(options);

            this.Encode(image, stream, pngOptions);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
 /// </summary>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
 /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
 /// <param name="options">The options for the encoder.</param>
 public void Encode <TPixel>(Image <TPixel> image, Stream stream, IPngEncoderOptions options)
     where TPixel : struct, IPixel <TPixel>
 {
     using (var encode = new PngEncoderCore(options))
     {
         encode.Encode(image, stream);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PngEncoderCore"/> class.
 /// </summary>
 /// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
 /// <param name="options">The options for influencing the encoder</param>
 public PngEncoderCore(MemoryManager memoryManager, IPngEncoderOptions options)
 {
     this.memoryManager    = memoryManager;
     this.pngColorType     = options.PngColorType;
     this.compressionLevel = options.CompressionLevel;
     this.gamma            = options.Gamma;
     this.quantizer        = options.Quantizer;
     this.threshold        = options.Threshold;
     this.writeGamma       = options.WriteGamma;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PngEncoderCore"/> class.
 /// </summary>
 /// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
 /// <param name="options">The options for influencing the encoder</param>
 public PngEncoderCore(MemoryAllocator memoryAllocator, IPngEncoderOptions options)
 {
     this.memoryAllocator  = memoryAllocator;
     this.pngBitDepth      = options.BitDepth;
     this.pngColorType     = options.ColorType;
     this.pngFilterMethod  = options.FilterMethod;
     this.compressionLevel = options.CompressionLevel;
     this.gamma            = options.Gamma;
     this.quantizer        = options.Quantizer;
     this.threshold        = options.Threshold;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PngEncoderCore"/> class.
 /// </summary>
 /// <param name="options">The options for influencing the encoder</param>
 public PngEncoderCore(IPngEncoderOptions options)
 {
     this.ignoreMetadata   = options.IgnoreMetadata;
     this.paletteSize      = options.PaletteSize > 0 ? options.PaletteSize.Clamp(1, int.MaxValue) : int.MaxValue;
     this.pngColorType     = options.PngColorType;
     this.compressionLevel = options.CompressionLevel;
     this.gamma            = options.Gamma;
     this.quantizer        = options.Quantizer;
     this.threshold        = options.Threshold;
     this.writeGamma       = options.WriteGamma;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PngEncoderOptions"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 public PngEncoderOptions(IPngEncoderOptions source)
 {
     this.BitDepth                 = source.BitDepth;
     this.ColorType                = source.ColorType;
     this.FilterMethod             = source.FilterMethod;
     this.CompressionLevel         = source.CompressionLevel;
     this.TextCompressionThreshold = source.TextCompressionThreshold;
     this.Gamma                = source.Gamma;
     this.Quantizer            = source.Quantizer;
     this.Threshold            = source.Threshold;
     this.InterlaceMethod      = source.InterlaceMethod;
     this.ChunkFilter          = source.ChunkFilter;
     this.IgnoreMetadata       = source.IgnoreMetadata;
     this.TransparentColorMode = source.TransparentColorMode;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PngEncoderCore"/> class.
        /// </summary>
        /// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for buffer allocations.</param>
        /// <param name="options">The options for influencing the encoder</param>
        public PngEncoderCore(MemoryAllocator memoryAllocator, IPngEncoderOptions options)
        {
            this.memoryAllocator = memoryAllocator;
            this.pngBitDepth     = options.BitDepth;
            this.pngColorType    = options.ColorType;

            // Specification recommends default filter method None for paletted images and Paeth for others.
            this.pngFilterMethod = options.FilterMethod ?? (options.ColorType.Equals(PngColorType.Palette)
                ? PngFilterMethod.None
                : PngFilterMethod.Paeth);
            this.compressionLevel = options.CompressionLevel;
            this.gamma            = options.Gamma;
            this.quantizer        = options.Quantizer;
            this.threshold        = options.Threshold;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PngEncoderOptions"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        public PngEncoderOptions(IPngEncoderOptions source)
        {
            this.BitDepth  = source.BitDepth;
            this.ColorType = source.ColorType;

            // Specification recommends default filter method None for paletted images and Paeth for others.
            this.FilterMethod = source.FilterMethod ?? (source.ColorType == PngColorType.Palette
                ? PngFilterMethod.None
                : PngFilterMethod.Paeth);
            this.CompressionLevel         = source.CompressionLevel;
            this.TextCompressionThreshold = source.TextCompressionThreshold;
            this.Gamma           = source.Gamma;
            this.Quantizer       = source.Quantizer;
            this.Threshold       = source.Threshold;
            this.InterlaceMethod = source.InterlaceMethod;
        }
        /// <summary>
        /// Saves the image to the given stream with the png format.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="stream">The stream to save the image to.</param>
        /// <param name="options">The options for the encoder.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
        /// <returns>
        /// The <see cref="Image{TColor}"/>.
        /// </returns>
        public static Image <TColor> SaveAsPng <TColor>(this Image <TColor> source, Stream stream, IPngEncoderOptions options)
            where TColor : struct, IPixel <TColor>
        {
            PngEncoder encoder = new PngEncoder();

            encoder.Encode(source, stream, options);

            return(source);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PngEncoderCore"/> class.
 /// </summary>
 /// <param name="options">The options for the encoder.</param>
 public PngEncoderCore(IPngEncoderOptions options)
 {
     this.options = options ?? new PngEncoderOptions();
 }