diff --git a/src/ImageSharp.Drawing/Brushes/IBrush.cs b/src/ImageSharp.Drawing/Brushes/IBrush.cs index 1eea302a5..b28180204 100644 --- a/src/ImageSharp.Drawing/Brushes/IBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/IBrush.cs @@ -14,7 +14,7 @@ namespace ImageSharp.Drawing /// /// The pixel format. /// - /// A brush is a simple class that will return an that will perform the + /// A brush is a simple class that will return an that will perform the /// logic for converting a pixel location to a . /// public interface IBrush @@ -32,6 +32,6 @@ namespace ImageSharp.Drawing /// The when being applied to things like shapes would usually be the /// bounding box of the shape not necessarily the bounds of the whole image /// - IBrushApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region); + BrushApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs index 5daf03b93..9ce235a84 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs @@ -32,7 +32,7 @@ namespace ImageSharp.Drawing.Brushes } /// - public IBrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { return new ImageBrushApplicator(this.image, region); } @@ -40,7 +40,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The image brush applicator. /// - private class ImageBrushApplicator : IBrushApplicator + private class ImageBrushApplicator : BrushApplicator { /// /// The source pixel accessor. @@ -86,7 +86,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color /// - public TColor GetColor(Vector2 point) + public override TColor GetColor(Vector2 point) { // Offset the requested pixel by the value in the rectangle (the shapes position) point = point - this.offset; @@ -97,7 +97,7 @@ namespace ImageSharp.Drawing.Brushes } /// - public void Dispose() + public override void Dispose() { this.source.Dispose(); } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs index 76b11236a..7749f5ba8 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs @@ -95,7 +95,7 @@ namespace ImageSharp.Drawing.Brushes } /// - public IBrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { return new PatternBrushApplicator(this.pattern, this.stride); } @@ -103,7 +103,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The pattern brush applicator. /// - private class PatternBrushApplicator : IBrushApplicator + private class PatternBrushApplicator : BrushApplicator { /// /// The patter x-length. @@ -139,7 +139,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color /// - public TColor GetColor(Vector2 point) + public override TColor GetColor(Vector2 point) { int x = (int)point.X % this.xLength; int y = (int)point.Y % this.stride; @@ -148,7 +148,7 @@ namespace ImageSharp.Drawing.Brushes } /// - public void Dispose() + public override void Dispose() { // noop } diff --git a/src/ImageSharp.Drawing/Brushes/Processors/IBrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs similarity index 61% rename from src/ImageSharp.Drawing/Brushes/Processors/IBrushApplicator.cs rename to src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 9b09f87db..885be5715 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/IBrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -13,14 +13,19 @@ namespace ImageSharp.Drawing.Processors /// /// The pixel format. /// - public interface IBrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush + public abstract class BrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush where TColor : struct, IPackedPixel, IEquatable { + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public abstract void Dispose(); + /// /// Gets the color for a single pixel. /// /// The point. /// The color - TColor GetColor(Vector2 point); + public abstract TColor GetColor(Vector2 point); } } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs index 35f72c5bf..7149f22a0 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs @@ -55,7 +55,7 @@ namespace ImageSharp.Drawing.Brushes public TColor TargetColor { get; } /// - public IBrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threshold); } @@ -63,7 +63,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The recolor brush applicator. /// - private class RecolorBrushApplicator : IBrushApplicator + private class RecolorBrushApplicator : BrushApplicator { /// /// The source pixel accessor. @@ -113,7 +113,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color /// - public TColor GetColor(Vector2 point) + public override TColor GetColor(Vector2 point) { // Offset the requested pixel by the value in the rectangle (the shapes position) TColor result = this.source[(int)point.X, (int)point.Y]; @@ -130,9 +130,8 @@ namespace ImageSharp.Drawing.Brushes } /// - public void Dispose() + public override void Dispose() { - // we didn't make the lock on the PixelAccessor we shouldn't release it. } } } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs index ac3986bba..c3e311399 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs @@ -40,7 +40,7 @@ namespace ImageSharp.Drawing.Brushes public TColor Color => this.color; /// - public IBrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { return new SolidBrushApplicator(this.color); } @@ -48,7 +48,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The solid brush applicator. /// - private class SolidBrushApplicator : IBrushApplicator + private class SolidBrushApplicator : BrushApplicator { /// /// The solid color. @@ -71,13 +71,13 @@ namespace ImageSharp.Drawing.Brushes /// /// The color /// - public TColor GetColor(Vector2 point) + public override TColor GetColor(Vector2 point) { return this.color; } /// - public void Dispose() + public override void Dispose() { // noop } diff --git a/src/ImageSharp.Drawing/Pens/Pen{TColor}.cs b/src/ImageSharp.Drawing/Pens/Pen{TColor}.cs index 0af039ac7..ebe027374 100644 --- a/src/ImageSharp.Drawing/Pens/Pen{TColor}.cs +++ b/src/ImageSharp.Drawing/Pens/Pen{TColor}.cs @@ -125,7 +125,7 @@ namespace ImageSharp.Drawing.Pens private class SolidPenApplicator : IPenApplicator { - private readonly IBrushApplicator brush; + private readonly BrushApplicator brush; private readonly float halfWidth; public SolidPenApplicator(PixelAccessor sourcePixels, IBrush brush, RectangleF region, float width) @@ -135,17 +135,17 @@ namespace ImageSharp.Drawing.Pens this.RequiredRegion = RectangleF.Outset(region, width); } - public RectangleF RequiredRegion + public override RectangleF RequiredRegion { get; } - public void Dispose() + public override void Dispose() { this.brush.Dispose(); } - public ColoredPointInfo GetColor(PointInfo info) + public override ColoredPointInfo GetColor(PointInfo info) { var result = default(ColoredPointInfo); result.Color = this.brush.GetColor(info.SearchPoint); @@ -166,7 +166,7 @@ namespace ImageSharp.Drawing.Pens private class PatternPenApplicator : IPenApplicator { - private readonly IBrushApplicator brush; + private readonly BrushApplicator brush; private readonly float halfWidth; private readonly float[] pattern; private readonly float totalLength; @@ -188,17 +188,17 @@ namespace ImageSharp.Drawing.Pens this.RequiredRegion = RectangleF.Outset(region, width); } - public RectangleF RequiredRegion + public override RectangleF RequiredRegion { get; } - public void Dispose() + public override void Dispose() { this.brush.Dispose(); } - public ColoredPointInfo GetColor(PointInfo info) + public override ColoredPointInfo GetColor(PointInfo info) { var infoResult = default(ColoredPointInfo); infoResult.DistanceFromElement = float.MaxValue; // is really outside the element diff --git a/src/ImageSharp.Drawing/Pens/Processors/IPenApplicator.cs b/src/ImageSharp.Drawing/Pens/Processors/IPenApplicator.cs index 7159dfeec..adc7a28d7 100644 --- a/src/ImageSharp.Drawing/Pens/Processors/IPenApplicator.cs +++ b/src/ImageSharp.Drawing/Pens/Processors/IPenApplicator.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Drawing.Processors /// primitive that converts a into a color and a distance away from the drawable part of the path. /// /// The type of the color. - public interface IPenApplicator : IDisposable + public abstract class IPenApplicator : IDisposable where TColor : struct, IPackedPixel, IEquatable { /// @@ -21,13 +21,18 @@ namespace ImageSharp.Drawing.Processors /// /// The required region. /// - RectangleF RequiredRegion { get; } + public abstract RectangleF RequiredRegion { get; } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public abstract void Dispose(); /// /// Gets a from a point represented by a . /// /// The information to extract color details about. /// Returns the color details and distance from a solid bit of the line. - ColoredPointInfo GetColor(PointInfo info); + public abstract ColoredPointInfo GetColor(PointInfo info); } } diff --git a/src/ImageSharp.Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processors/FillProcessor.cs index 309d3670f..9219f9f99 100644 --- a/src/ImageSharp.Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillProcessor.cs @@ -62,7 +62,7 @@ namespace ImageSharp.Drawing.Processors // for example If brush is SolidBrush then we could just get the color upfront // and skip using the IBrushApplicator?. using (PixelAccessor sourcePixels = source.Lock()) - using (IBrushApplicator applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle)) + using (BrushApplicator applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle)) { Parallel.For( minY, diff --git a/src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs index d0655341b..489d27423 100644 --- a/src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs @@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Processors } using (PixelAccessor sourcePixels = source.Lock()) - using (IBrushApplicator applicator = this.fillColor.CreateApplicator(sourcePixels, rect)) + using (BrushApplicator applicator = this.fillColor.CreateApplicator(sourcePixels, rect)) { Parallel.For( minY, diff --git a/src/ImageSharp.Drawing/Processors/FillShapeProcessorFast.cs b/src/ImageSharp.Drawing/Processors/FillShapeProcessorFast.cs index d192dc6c3..9fae2ca8d 100644 --- a/src/ImageSharp.Drawing/Processors/FillShapeProcessorFast.cs +++ b/src/ImageSharp.Drawing/Processors/FillShapeProcessorFast.cs @@ -67,7 +67,7 @@ namespace ImageSharp.Drawing.Processors int maxIntersections = this.poly.MaxIntersections; using (PixelAccessor sourcePixels = source.Lock()) - using (IBrushApplicator applicator = this.fillColor.CreateApplicator(sourcePixels, rect)) + using (BrushApplicator applicator = this.fillColor.CreateApplicator(sourcePixels, rect)) { Parallel.For( minY,