コード例 #1
0
        public void SinglePixelOpaque()
        {
            Configuration config    = Configuration.Default;
            var           quantizer = new WuQuantizer(false);

            using (var image = new Image <Rgba32>(config, 1, 1, Rgba32.Black))
                using (IQuantizedFrame <Rgba32> result = quantizer.CreateFrameQuantizer <Rgba32>(config).QuantizeFrame(image.Frames[0]))
                {
                    Assert.Equal(1, result.Palette.Length);
                    Assert.Equal(1, result.GetPixelSpan().Length);

                    Assert.Equal(Rgba32.Black, result.Palette.Span[0]);
                    Assert.Equal(0, result.GetPixelSpan()[0]);
                }
        }
コード例 #2
0
        /// <inheritdoc />
        protected override void OnFrameApply(ImageFrame <TPixel> source)
        {
            Configuration configuration = this.Configuration;

            using (IFrameQuantizer <TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer <TPixel>(configuration))
                using (IQuantizedFrame <TPixel> quantized = frameQuantizer.QuantizeFrame(source))
                {
                    int paletteCount = quantized.Palette.Length - 1;

                    // Not parallel to remove "quantized" closure allocation.
                    // We can operate directly on the source here as we've already read it to get the
                    // quantized result
                    for (int y = 0; y < source.Height; y++)
                    {
                        Span <TPixel>       row = source.GetPixelRowSpan(y);
                        ReadOnlySpan <byte> quantizedPixelSpan = quantized.GetPixelSpan();

                        ReadOnlySpan <TPixel> paletteSpan = quantized.Palette.Span;

                        int yy = y * source.Width;

                        for (int x = 0; x < source.Width; x++)
                        {
                            int i = x + yy;
                            row[x] = paletteSpan[Math.Min(paletteCount, quantizedPixelSpan[i])];
                        }
                    }
                }
        }
コード例 #3
0
        public void WuQuantizerYieldsCorrectTransparentPixel <TPixel>(TestImageProvider <TPixel> provider, bool dither)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                Assert.True(image[0, 0].Equals(default(TPixel)));

                var quantizer = new WuQuantizer(dither);

                foreach (ImageFrame <TPixel> frame in image.Frames)
                {
                    IQuantizedFrame <TPixel> quantized =
                        quantizer.CreateFrameQuantizer <TPixel>(this.Configuration).QuantizeFrame(frame);

                    int index = this.GetTransparentIndex(quantized);
                    Assert.Equal(index, quantized.GetPixelSpan()[0]);
                }
            }
        }
コード例 #4
0
 public static ReadOnlySpan <byte> GetRowSpan <TPixel>(this IQuantizedFrame <TPixel> frame, int rowIndex)
     where TPixel : struct, IPixel <TPixel>
 => frame.GetPixelSpan().Slice(rowIndex * frame.Width, frame.Width);