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>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <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"/>.
/// </remarks>
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
/// bounding box of the shape not necessarily the bounds of the whole image
/// </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 />
public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
{
return new ImageBrushApplicator(this.image, region);
}
@ -40,7 +40,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The image brush applicator.
/// </summary>
private class ImageBrushApplicator : IBrushApplicator<TColor>
private class ImageBrushApplicator : BrushApplicator<TColor>
{
/// <summary>
/// The source pixel accessor.
@ -86,7 +86,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>
/// The color
/// </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)
point = point - this.offset;
@ -97,7 +97,7 @@ namespace ImageSharp.Drawing.Brushes
}
/// <inheritdoc />
public void Dispose()
public override void Dispose()
{
this.source.Dispose();
}

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

@ -95,7 +95,7 @@ namespace ImageSharp.Drawing.Brushes
}
/// <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);
}
@ -103,7 +103,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The pattern brush applicator.
/// </summary>
private class PatternBrushApplicator : IBrushApplicator<TColor>
private class PatternBrushApplicator : BrushApplicator<TColor>
{
/// <summary>
/// The patter x-length.
@ -139,7 +139,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>
/// The color
/// </returns>
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
}
/// <inheritdoc />
public void Dispose()
public override void Dispose()
{
// 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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -13,14 +13,19 @@ namespace ImageSharp.Drawing.Processors
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <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>
{
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public abstract void Dispose();
/// <summary>
/// Gets the color for a single pixel.
/// </summary>
/// <param name="point">The point.</param>
/// <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; }
/// <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);
}
@ -63,7 +63,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The recolor brush applicator.
/// </summary>
private class RecolorBrushApplicator : IBrushApplicator<TColor>
private class RecolorBrushApplicator : BrushApplicator<TColor>
{
/// <summary>
/// The source pixel accessor.
@ -113,7 +113,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>
/// The color
/// </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)
TColor result = this.source[(int)point.X, (int)point.Y];
@ -130,9 +130,8 @@ namespace ImageSharp.Drawing.Brushes
}
/// <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;
/// <inheritdoc />
public IBrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region)
{
return new SolidBrushApplicator(this.color);
}
@ -48,7 +48,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The solid brush applicator.
/// </summary>
private class SolidBrushApplicator : IBrushApplicator<TColor>
private class SolidBrushApplicator : BrushApplicator<TColor>
{
/// <summary>
/// The solid color.
@ -71,13 +71,13 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>
/// The color
/// </returns>
public TColor GetColor(Vector2 point)
public override TColor GetColor(Vector2 point)
{
return this.color;
}
/// <inheritdoc />
public void Dispose()
public override void Dispose()
{
// noop
}

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

@ -125,7 +125,7 @@ namespace ImageSharp.Drawing.Pens
private class SolidPenApplicator : IPenApplicator<TColor>
{
private readonly IBrushApplicator<TColor> brush;
private readonly BrushApplicator<TColor> brush;
private readonly float halfWidth;
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);
}
public RectangleF RequiredRegion
public override RectangleF RequiredRegion
{
get;
}
public void Dispose()
public override void Dispose()
{
this.brush.Dispose();
}
public ColoredPointInfo<TColor> GetColor(PointInfo info)
public override ColoredPointInfo<TColor> GetColor(PointInfo info)
{
var result = default(ColoredPointInfo<TColor>);
result.Color = this.brush.GetColor(info.SearchPoint);
@ -166,7 +166,7 @@ namespace ImageSharp.Drawing.Pens
private class PatternPenApplicator : IPenApplicator<TColor>
{
private readonly IBrushApplicator<TColor> brush;
private readonly BrushApplicator<TColor> 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<TColor> GetColor(PointInfo info)
public override ColoredPointInfo<TColor> GetColor(PointInfo info)
{
var infoResult = default(ColoredPointInfo<TColor>);
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.
/// </summary>
/// <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>
{
/// <summary>
@ -21,13 +21,18 @@ namespace ImageSharp.Drawing.Processors
/// <value>
/// The required region.
/// </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>
/// Gets a <see cref="ColoredPointInfo{TColor}" /> from a point represented by a <see cref="PointInfo" />.
/// </summary>
/// <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>
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
// and skip using the IBrushApplicator<TColor>?.
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(
minY,

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

@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Processors
}
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(
minY,

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

@ -67,7 +67,7 @@ namespace ImageSharp.Drawing.Processors
int maxIntersections = this.poly.MaxIntersections;
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(
minY,

Loading…
Cancel
Save