コード例 #1
0
        public PaletteFrameQuantizer(Configuration configuration, QuantizerOptions options, ReadOnlyMemory <TPixel> colors)
        {
            Guard.NotNull(configuration, nameof(configuration));
            Guard.NotNull(options, nameof(options));

            this.Configuration = configuration;
            this.Options       = options;

            this.palette  = colors;
            this.pixelMap = new EuclideanPixelMap <TPixel>(colors);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        /// <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));
        }
コード例 #7
0
 /// <inheritdoc/>
 public void Dispose()
 {
     this.pixelMap?.Dispose();
     this.pixelMap = null;
 }
コード例 #8
0
 /// <inheritdoc/>
 public bool Equals(EuclideanPixelMap <TPixel> other)
 => this.Palette.Equals(other.Palette);