/// <inheritdoc />
        protected override void OnFrameApply(ImageFrame <TPixel> source)
        {
            var interest = Rectangle.Intersect(source.Bounds(), this.SourceRectangle);

            Configuration configuration = this.Configuration;

            using IQuantizer <TPixel> frameQuantizer   = this.quantizer.CreatePixelSpecificQuantizer <TPixel>(configuration);
            using IndexedImageFrame <TPixel> quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(source, interest);

            ReadOnlySpan <TPixel> paletteSpan = quantized.Palette.Span;
            int offsetY = interest.Top;
            int offsetX = interest.Left;
            Buffer2D <TPixel> sourceBuffer = source.PixelBuffer;

            for (int y = interest.Y; y < interest.Height; y++)
            {
                Span <TPixel>       row          = sourceBuffer.DangerousGetRowSpan(y);
                ReadOnlySpan <byte> quantizedRow = quantized.DangerousGetRowSpan(y - offsetY);

                for (int x = interest.Left; x < interest.Right; x++)
                {
                    row[x] = paletteSpan[quantizedRow[x - offsetX]];
                }
            }
        }
Example #2
0
 public RowIntervalOperation(
     Rectangle bounds,
     ImageFrame <TPixel> source,
     IndexedImageFrame <TPixel> quantized)
 {
     this.bounds    = bounds;
     this.source    = source;
     this.quantized = quantized;
 }
Example #3
0
        /// <inheritdoc />
        protected override void OnFrameApply(ImageFrame <TPixel> source)
        {
            var interest = Rectangle.Intersect(source.Bounds(), this.SourceRectangle);

            Configuration configuration = this.Configuration;

            using IQuantizer <TPixel> frameQuantizer   = this.quantizer.CreatePixelSpecificQuantizer <TPixel>(configuration);
            using IndexedImageFrame <TPixel> quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(source, interest);

            var operation = new RowIntervalOperation(this.SourceRectangle, source, quantized);

            ParallelRowIterator.IterateRowIntervals(
                configuration,
                interest,
                in operation);
        }