/// <summary> /// Initializes a new instance of the <see cref="PaletteQuantizer"/> class. /// </summary> /// <param name="palette">The color palette.</param> /// <param name="options">The quantizer options defining quantization rules.</param> public PaletteQuantizer(ReadOnlyMemory <Color> palette, QuantizerOptions options) { Guard.MustBeGreaterThan(palette.Length, 0, nameof(palette)); Guard.NotNull(options, nameof(options)); this.colorPalette = palette; this.Options = options; }
public PaletteQuantizer(Configuration configuration, QuantizerOptions options, ReadOnlyMemory <TPixel> palette) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(options, nameof(options)); this.Configuration = configuration; this.Options = options; this.pixelMap = new EuclideanPixelMap <TPixel>(configuration, palette); }
public PaletteQuantizer( Configuration configuration, QuantizerOptions options, EuclideanPixelMap <TPixel> pixelMap) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(options, nameof(options)); this.Configuration = configuration; this.Options = options; this.pixelMap = pixelMap; }
public OctreeFrameQuantizer(Configuration configuration, QuantizerOptions options) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(options, nameof(options)); this.Configuration = configuration; this.Options = options; this.colors = this.Options.MaxColors; this.octree = new Octree(ImageMaths.GetBitsNeededForColorDepth(this.colors).Clamp(1, 8)); this.pixelMap = default; this.isDithering = !(this.Options.Dither is null); }
public OctreeQuantizer(Configuration configuration, QuantizerOptions options) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(options, nameof(options)); this.Configuration = configuration; this.Options = options; this.maxColors = this.Options.MaxColors; this.octree = new Octree(Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.maxColors), 1, 8)); this.paletteOwner = configuration.MemoryAllocator.Allocate <TPixel>(this.maxColors, AllocationOptions.Clean); this.palette = default; this.pixelMap = default; this.isDithering = !(this.Options.Dither is null); this.isDisposed = false; }
public WuFrameQuantizer(Configuration configuration, QuantizerOptions options) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(options, nameof(options)); this.Configuration = configuration; this.Options = options; this.memoryAllocator = this.Configuration.MemoryAllocator; this.moments = this.memoryAllocator.Allocate <Moment>(TableLength, AllocationOptions.Clean); this.tag = this.memoryAllocator.Allocate <byte>(TableLength, AllocationOptions.Clean); this.colors = this.Options.MaxColors; this.colorCube = new Box[this.colors]; this.isDisposed = false; this.pixelMap = default; this.isDithering = this.isDithering = !(this.Options.Dither is null); }
/// <inheritdoc /> public IQuantizer <TPixel> CreatePixelSpecificQuantizer <TPixel>(Configuration configuration, QuantizerOptions options) where TPixel : unmanaged, IPixel <TPixel> => new OctreeQuantizer <TPixel>(configuration, options);
/// <summary> /// Initializes a new instance of the <see cref="OctreeQuantizer"/> class. /// </summary> /// <param name="options">The quantizer options defining quantization rules.</param> public OctreeQuantizer(QuantizerOptions options) { Guard.NotNull(options, nameof(options)); this.Options = options; }
/// <inheritdoc /> public IQuantizer <TPixel> CreatePixelSpecificQuantizer <TPixel>(Configuration configuration, QuantizerOptions options) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(options, nameof(options)); // The palette quantizer can reuse the same pixel map across multiple frames // since the palette is unchanging. This allows a reduction of memory usage across // multi frame gifs using a global palette. int length = Math.Min(this.colorPalette.Length, options.MaxColors); var palette = new TPixel[length]; Color.ToPixel(configuration, this.colorPalette.Span, palette.AsSpan()); var pixelMap = new EuclideanPixelMap <TPixel>(configuration, palette); return(new PaletteQuantizer <TPixel>(configuration, options, pixelMap)); }
/// <inheritdoc /> public IFrameQuantizer <TPixel> CreateFrameQuantizer <TPixel>(Configuration configuration, QuantizerOptions options) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(options, nameof(options)); int length = Math.Min(this.Palette.Span.Length, options.MaxColors); var palette = new TPixel[length]; Color.ToPixel(configuration, this.Palette.Span, palette.AsSpan()); return(new PaletteFrameQuantizer <TPixel>(configuration, options, palette)); }
/// <summary> /// Initializes a new instance of the <see cref="WebSafePaletteQuantizer" /> class. /// </summary> /// <param name="options">The quantizer options defining quantization rules.</param> public WebSafePaletteQuantizer(QuantizerOptions options) : base(Color.WebSafePalette, options) { }
/// <inheritdoc /> public IFrameQuantizer <TPixel> CreateFrameQuantizer <TPixel>(Configuration configuration, QuantizerOptions options) where TPixel : unmanaged, IPixel <TPixel> => new WuFrameQuantizer <TPixel>(configuration, options);
/// <inheritdoc /> public IFrameQuantizer <TPixel> CreateFrameQuantizer <TPixel>(Configuration configuration, QuantizerOptions options) where TPixel : struct, IPixel <TPixel> => new OctreeFrameQuantizer <TPixel>(configuration, options);