public RecolorToolContentRenderer(BitmapLayer activeLayer, RecolorToolChanges changes) : base(activeLayer.Width, activeLayer.Height, changes) { IRenderer <ColorAlpha8> renderer2; this.sampleSource = activeLayer.Surface; byte x = (byte)Math.Round((double)(changes.Tolerance * 255.0), MidpointRounding.AwayFromZero); byte tolerance = ByteUtil.FastScale(x, x); if (changes.SamplingMode == RecolorToolSamplingMode.SecondaryColor) { this.basisColor = changes.BasisColor; } else { this.basisColor = GetBasisColor(changes, this.sampleSource); } IRenderer <ColorAlpha8> stencilSource = new FillStencilByColorRenderer(this.sampleSource, this.basisColor, tolerance, this); if (changes.Antialiasing) { renderer2 = new FeatheredMaskRenderer(this.sampleSource, changes.BasisColor, stencilSource, tolerance, this); } else { renderer2 = stencilSource; } IRenderer <ColorAlpha8> first = changes.RenderCache.CreateMaskRenderer(activeLayer.Size(), this); this.maskRenderer = new MultiplyRendererAlpha8(first, renderer2); }
private IRenderer <ColorAlpha8> CreateMaskRenderer() { IRenderer <ColorAlpha8> renderer; byte x = (byte)Math.Round((double)(this.changes.Tolerance * 255.0), MidpointRounding.AwayFromZero); byte tolerance = ByteUtil.FastScale(x, x); PointInt32 pt = this.changes.OriginPointInt32; if (!this.sampleSource.Bounds <ColorBgra>().Contains(pt)) { return(new FillRendererAlpha8(this.sampleSource.Width, this.sampleSource.Height, ColorAlpha8.Transparent)); } ColorBgra pointSlow = this.sampleSource.GetPointSlow(pt); base.ThrowIfCancellationRequested(); if (this.changes.FloodMode == FloodMode.Global) { renderer = new FillStencilByColorRenderer(this.sampleSource, pointSlow, tolerance, this); } else { RectInt32 num5; BitVector2D source = new BitVector2D(this.sampleSource.Width, this.sampleSource.Height); BitVector2DStruct stencilBuffer = new BitVector2DStruct(source); source.Clear(true); base.ThrowIfCancellationRequested(); foreach (RectInt32 num6 in this.changes.ClippingMask.EnumerateInteriorScans()) { source.Set(num6, false); base.ThrowIfCancellationRequested(); } BitVector2D other = source.Clone(); base.ThrowIfCancellationRequested(); FloodFillAlgorithm.FillStencilFromPoint <BitVector2DStruct>(this.sampleSource, stencilBuffer, pt, tolerance, this, out num5); base.ThrowIfCancellationRequested(); source.Xor(other); base.ThrowIfCancellationRequested(); renderer = new BitVector2DToAlpha8Renderer <BitVector2DStruct>(stencilBuffer); } if (this.changes.Antialiasing) { return(new FeatheredMaskRenderer(this.sampleSource, pointSlow, renderer, tolerance, this)); } return(renderer); }