Browse Source

use abstract base class instead of interface

af/merge-core
Scott Williams 9 years ago
parent
commit
9ae9041c8d
  1. 4
      src/ImageSharp.Drawing/Brushes/IBrush.cs
  2. 8
      src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
  3. 8
      src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
  4. 11
      src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
  5. 9
      src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
  6. 8
      src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs
  7. 16
      src/ImageSharp.Drawing/Pens/Pen{TColor}.cs
  8. 11
      src/ImageSharp.Drawing/Pens/Processors/IPenApplicator.cs
  9. 2
      src/ImageSharp.Drawing/Processors/FillProcessor.cs
  10. 2
      src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs
  11. 2
      src/ImageSharp.Drawing/Processors/FillShapeProcessorFast.cs

4
src/ImageSharp.Drawing/Brushes/IBrush.cs

@ -14,7 +14,7 @@ namespace ImageSharp.Drawing
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <remarks> /// <remarks>
/// A brush is a simple class that will return an <see cref="IBrushApplicator{TColor}" /> that will perform the /// A brush is a simple class that will return an <see cref="BrushApplicator{TColor}" /> that will perform the
/// logic for converting a pixel location to a <typeparamref name="TColor"/>. /// logic for converting a pixel location to a <typeparamref name="TColor"/>.
/// </remarks> /// </remarks>
public interface IBrush<TColor> public interface IBrush<TColor>
@ -32,6 +32,6 @@ namespace ImageSharp.Drawing
/// The <paramref name="region" /> when being applied to things like shapes would usually be the /// The <paramref name="region" /> when being applied to things like shapes would usually be the
/// bounding box of the shape not necessarily the bounds of the whole image /// bounding box of the shape not necessarily the bounds of the whole image
/// </remarks> /// </remarks>
IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> pixelSource, RectangleF region); BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> pixelSource, RectangleF region);
} }
} }

8
src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs

@ -32,7 +32,7 @@ namespace ImageSharp.Drawing.Brushes
} }
/// <inheritdoc /> /// <inheritdoc />
public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
{ {
return new ImageBrushApplicator(this.image, region); return new ImageBrushApplicator(this.image, region);
} }
@ -40,7 +40,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The image brush applicator. /// The image brush applicator.
/// </summary> /// </summary>
private class ImageBrushApplicator : IBrushApplicator<TColor> private class ImageBrushApplicator : BrushApplicator<TColor>
{ {
/// <summary> /// <summary>
/// The source pixel accessor. /// The source pixel accessor.
@ -86,7 +86,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
public TColor GetColor(Vector2 point) public override TColor GetColor(Vector2 point)
{ {
// Offset the requested pixel by the value in the rectangle (the shapes position) // Offset the requested pixel by the value in the rectangle (the shapes position)
point = point - this.offset; point = point - this.offset;
@ -97,7 +97,7 @@ namespace ImageSharp.Drawing.Brushes
} }
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public override void Dispose()
{ {
this.source.Dispose(); this.source.Dispose();
} }

8
src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs

@ -95,7 +95,7 @@ namespace ImageSharp.Drawing.Brushes
} }
/// <inheritdoc /> /// <inheritdoc />
public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
{ {
return new PatternBrushApplicator(this.pattern, this.stride); return new PatternBrushApplicator(this.pattern, this.stride);
} }
@ -103,7 +103,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The pattern brush applicator. /// The pattern brush applicator.
/// </summary> /// </summary>
private class PatternBrushApplicator : IBrushApplicator<TColor> private class PatternBrushApplicator : BrushApplicator<TColor>
{ {
/// <summary> /// <summary>
/// The patter x-length. /// The patter x-length.
@ -139,7 +139,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
public TColor GetColor(Vector2 point) public override TColor GetColor(Vector2 point)
{ {
int x = (int)point.X % this.xLength; int x = (int)point.X % this.xLength;
int y = (int)point.Y % this.stride; int y = (int)point.Y % this.stride;
@ -148,7 +148,7 @@ namespace ImageSharp.Drawing.Brushes
} }
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public override void Dispose()
{ {
// noop // noop
} }

11
src/ImageSharp.Drawing/Brushes/Processors/IBrushApplicator.cs → src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs

@ -1,4 +1,4 @@
// <copyright file="IBrushApplicator.cs" company="James Jackson-South"> // <copyright file="BrushApplicator.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -13,14 +13,19 @@ namespace ImageSharp.Drawing.Processors
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <seealso cref="System.IDisposable" /> /// <seealso cref="System.IDisposable" />
public interface IBrushApplicator<TColor> : IDisposable // disposable will be required if/when there is an ImageBrush public abstract class BrushApplicator<TColor> : IDisposable // disposable will be required if/when there is an ImageBrush
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public abstract void Dispose();
/// <summary> /// <summary>
/// Gets the color for a single pixel. /// Gets the color for a single pixel.
/// </summary> /// </summary>
/// <param name="point">The point.</param> /// <param name="point">The point.</param>
/// <returns>The color</returns> /// <returns>The color</returns>
TColor GetColor(Vector2 point); public abstract TColor GetColor(Vector2 point);
} }
} }

9
src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs

@ -55,7 +55,7 @@ namespace ImageSharp.Drawing.Brushes
public TColor TargetColor { get; } public TColor TargetColor { get; }
/// <inheritdoc /> /// <inheritdoc />
public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
{ {
return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threshold); return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threshold);
} }
@ -63,7 +63,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The recolor brush applicator. /// The recolor brush applicator.
/// </summary> /// </summary>
private class RecolorBrushApplicator : IBrushApplicator<TColor> private class RecolorBrushApplicator : BrushApplicator<TColor>
{ {
/// <summary> /// <summary>
/// The source pixel accessor. /// The source pixel accessor.
@ -113,7 +113,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
public TColor GetColor(Vector2 point) public override TColor GetColor(Vector2 point)
{ {
// Offset the requested pixel by the value in the rectangle (the shapes position) // Offset the requested pixel by the value in the rectangle (the shapes position)
TColor result = this.source[(int)point.X, (int)point.Y]; TColor result = this.source[(int)point.X, (int)point.Y];
@ -130,9 +130,8 @@ namespace ImageSharp.Drawing.Brushes
} }
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public override void Dispose()
{ {
// we didn't make the lock on the PixelAccessor we shouldn't release it.
} }
} }
} }

8
src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs

@ -40,7 +40,7 @@ namespace ImageSharp.Drawing.Brushes
public TColor Color => this.color; public TColor Color => this.color;
/// <inheritdoc /> /// <inheritdoc />
public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
{ {
return new SolidBrushApplicator(this.color); return new SolidBrushApplicator(this.color);
} }
@ -48,7 +48,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The solid brush applicator. /// The solid brush applicator.
/// </summary> /// </summary>
private class SolidBrushApplicator : IBrushApplicator<TColor> private class SolidBrushApplicator : BrushApplicator<TColor>
{ {
/// <summary> /// <summary>
/// The solid color. /// The solid color.
@ -71,13 +71,13 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
public TColor GetColor(Vector2 point) public override TColor GetColor(Vector2 point)
{ {
return this.color; return this.color;
} }
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public override void Dispose()
{ {
// noop // noop
} }

16
src/ImageSharp.Drawing/Pens/Pen{TColor}.cs

@ -125,7 +125,7 @@ namespace ImageSharp.Drawing.Pens
private class SolidPenApplicator : IPenApplicator<TColor> private class SolidPenApplicator : IPenApplicator<TColor>
{ {
private readonly IBrushApplicator<TColor> brush; private readonly BrushApplicator<TColor> brush;
private readonly float halfWidth; private readonly float halfWidth;
public SolidPenApplicator(PixelAccessor<TColor> sourcePixels, IBrush<TColor> brush, RectangleF region, float width) public SolidPenApplicator(PixelAccessor<TColor> sourcePixels, IBrush<TColor> brush, RectangleF region, float width)
@ -135,17 +135,17 @@ namespace ImageSharp.Drawing.Pens
this.RequiredRegion = RectangleF.Outset(region, width); this.RequiredRegion = RectangleF.Outset(region, width);
} }
public RectangleF RequiredRegion public override RectangleF RequiredRegion
{ {
get; get;
} }
public void Dispose() public override void Dispose()
{ {
this.brush.Dispose(); this.brush.Dispose();
} }
public ColoredPointInfo<TColor> GetColor(PointInfo info) public override ColoredPointInfo<TColor> GetColor(PointInfo info)
{ {
var result = default(ColoredPointInfo<TColor>); var result = default(ColoredPointInfo<TColor>);
result.Color = this.brush.GetColor(info.SearchPoint); result.Color = this.brush.GetColor(info.SearchPoint);
@ -166,7 +166,7 @@ namespace ImageSharp.Drawing.Pens
private class PatternPenApplicator : IPenApplicator<TColor> private class PatternPenApplicator : IPenApplicator<TColor>
{ {
private readonly IBrushApplicator<TColor> brush; private readonly BrushApplicator<TColor> brush;
private readonly float halfWidth; private readonly float halfWidth;
private readonly float[] pattern; private readonly float[] pattern;
private readonly float totalLength; private readonly float totalLength;
@ -188,17 +188,17 @@ namespace ImageSharp.Drawing.Pens
this.RequiredRegion = RectangleF.Outset(region, width); this.RequiredRegion = RectangleF.Outset(region, width);
} }
public RectangleF RequiredRegion public override RectangleF RequiredRegion
{ {
get; get;
} }
public void Dispose() public override void Dispose()
{ {
this.brush.Dispose(); this.brush.Dispose();
} }
public ColoredPointInfo<TColor> GetColor(PointInfo info) public override ColoredPointInfo<TColor> GetColor(PointInfo info)
{ {
var infoResult = default(ColoredPointInfo<TColor>); var infoResult = default(ColoredPointInfo<TColor>);
infoResult.DistanceFromElement = float.MaxValue; // is really outside the element infoResult.DistanceFromElement = float.MaxValue; // is really outside the element

11
src/ImageSharp.Drawing/Pens/Processors/IPenApplicator.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Drawing.Processors
/// primitive that converts a <see cref="PointInfo"/> into a color and a distance away from the drawable part of the path. /// primitive that converts a <see cref="PointInfo"/> into a color and a distance away from the drawable part of the path.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TColor">The type of the color.</typeparam>
public interface IPenApplicator<TColor> : IDisposable public abstract class IPenApplicator<TColor> : IDisposable
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
/// <summary> /// <summary>
@ -21,13 +21,18 @@ namespace ImageSharp.Drawing.Processors
/// <value> /// <value>
/// The required region. /// The required region.
/// </value> /// </value>
RectangleF RequiredRegion { get; } public abstract RectangleF RequiredRegion { get; }
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public abstract void Dispose();
/// <summary> /// <summary>
/// Gets a <see cref="ColoredPointInfo{TColor}" /> from a point represented by a <see cref="PointInfo" />. /// Gets a <see cref="ColoredPointInfo{TColor}" /> from a point represented by a <see cref="PointInfo" />.
/// </summary> /// </summary>
/// <param name="info">The information to extract color details about.</param> /// <param name="info">The information to extract color details about.</param>
/// <returns>Returns the color details and distance from a solid bit of the line.</returns> /// <returns>Returns the color details and distance from a solid bit of the line.</returns>
ColoredPointInfo<TColor> GetColor(PointInfo info); public abstract ColoredPointInfo<TColor> GetColor(PointInfo info);
} }
} }

2
src/ImageSharp.Drawing/Processors/FillProcessor.cs

@ -62,7 +62,7 @@ namespace ImageSharp.Drawing.Processors
// for example If brush is SolidBrush<TColor> then we could just get the color upfront // for example If brush is SolidBrush<TColor> then we could just get the color upfront
// and skip using the IBrushApplicator<TColor>?. // and skip using the IBrushApplicator<TColor>?.
using (PixelAccessor<TColor> sourcePixels = source.Lock()) using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (IBrushApplicator<TColor> applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle)) using (BrushApplicator<TColor> applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle))
{ {
Parallel.For( Parallel.For(
minY, minY,

2
src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs

@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Processors
} }
using (PixelAccessor<TColor> sourcePixels = source.Lock()) using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (IBrushApplicator<TColor> applicator = this.fillColor.CreateApplicator(sourcePixels, rect)) using (BrushApplicator<TColor> applicator = this.fillColor.CreateApplicator(sourcePixels, rect))
{ {
Parallel.For( Parallel.For(
minY, minY,

2
src/ImageSharp.Drawing/Processors/FillShapeProcessorFast.cs

@ -67,7 +67,7 @@ namespace ImageSharp.Drawing.Processors
int maxIntersections = this.poly.MaxIntersections; int maxIntersections = this.poly.MaxIntersections;
using (PixelAccessor<TColor> sourcePixels = source.Lock()) using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (IBrushApplicator<TColor> applicator = this.fillColor.CreateApplicator(sourcePixels, rect)) using (BrushApplicator<TColor> applicator = this.fillColor.CreateApplicator(sourcePixels, rect))
{ {
Parallel.For( Parallel.For(
minY, minY,

Loading…
Cancel
Save