Browse Source

A little cleanup

af/merge-core
James Jackson-South 9 years ago
parent
commit
ca513fd070
  1. 4
      src/ImageSharp.Drawing.Paths/DrawBeziers.cs
  2. 2
      src/ImageSharp.Drawing.Paths/DrawLines.cs
  3. 4
      src/ImageSharp.Drawing.Paths/DrawPath.cs
  4. 2
      src/ImageSharp.Drawing.Paths/DrawPolygon.cs
  5. 3
      src/ImageSharp.Drawing.Paths/DrawRectangle.cs
  6. 4
      src/ImageSharp.Drawing.Paths/DrawShape.cs
  7. 3
      src/ImageSharp.Drawing.Paths/FillPaths.cs
  8. 1
      src/ImageSharp.Drawing.Paths/FillPolygon.cs
  9. 1
      src/ImageSharp.Drawing.Paths/FillRectangle.cs
  10. 5
      src/ImageSharp.Drawing.Paths/FillShape.cs
  11. 9
      src/ImageSharp.Drawing.Paths/RectangleExtensions.cs
  12. 24
      src/ImageSharp.Drawing.Paths/ShapePath.cs
  13. 19
      src/ImageSharp.Drawing.Paths/ShapeRegion.cs
  14. 2
      src/ImageSharp.Drawing/DrawPath.cs
  15. 2
      src/ImageSharp.Drawing/FillRegion.cs
  16. 3
      src/ImageSharp.Drawing/PointInfo.cs
  17. 73
      src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
  18. 6
      src/ImageSharp.Drawing/Region.cs

4
src/ImageSharp.Drawing.Paths/DrawBeziers.cs

@ -10,10 +10,8 @@ namespace ImageSharp
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
using Path = SixLabors.Shapes.Path;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.

2
src/ImageSharp.Drawing.Paths/DrawLines.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>

4
src/ImageSharp.Drawing.Paths/DrawPath.cs

@ -6,11 +6,11 @@
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>

2
src/ImageSharp.Drawing.Paths/DrawPolygon.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>

3
src/ImageSharp.Drawing.Paths/DrawRectangle.cs

@ -10,9 +10,6 @@ namespace ImageSharp
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.

4
src/ImageSharp.Drawing.Paths/DrawShape.cs

@ -6,11 +6,11 @@
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>

3
src/ImageSharp.Drawing.Paths/FillPaths.cs

@ -6,10 +6,9 @@
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using SixLabors.Shapes;

1
src/ImageSharp.Drawing.Paths/FillPolygon.cs

@ -9,7 +9,6 @@ namespace ImageSharp
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using SixLabors.Shapes;

1
src/ImageSharp.Drawing.Paths/FillRectangle.cs

@ -9,7 +9,6 @@ namespace ImageSharp
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.

5
src/ImageSharp.Drawing.Paths/FillShape.cs

@ -6,10 +6,9 @@
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using SixLabors.Shapes;
@ -19,7 +18,7 @@ namespace ImageSharp
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>

9
src/ImageSharp.Drawing.Paths/RectangleExtensions.cs

@ -3,16 +3,9 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Processors
namespace ImageSharp.Drawing
{
using System;
using System.Buffers;
using System.Numerics;
using System.Threading.Tasks;
using Drawing;
using ImageSharp.Processing;
using SixLabors.Shapes;
using Rectangle = ImageSharp.Rectangle;
/// <summary>
/// Extension methods for helping to bridge Shaper2D and ImageSharp primitives.

24
src/ImageSharp.Drawing.Paths/ShapePath.cs

@ -9,16 +9,14 @@ namespace ImageSharp.Drawing
using System.Collections.Immutable;
using System.Numerics;
using ImageSharp.Drawing.Processors;
using SixLabors.Shapes;
using Rectangle = ImageSharp.Rectangle;
/// <summary>
/// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region.
/// A drawable mapping between a <see cref="IShape"/>/<see cref="IPath"/> and a drawable/fillable region.
/// </summary>
internal class ShapePath : ImageSharp.Drawing.Drawable
internal class ShapePath : Drawable
{
/// <summary>
/// The fillable shape
@ -59,9 +57,6 @@ namespace ImageSharp.Drawing
/// <summary>
/// Gets the drawable paths
/// </summary>
/// <value>
/// The paths.
/// </value>
public ImmutableArray<IPath> Paths { get; }
/// <inheritdoc/>
@ -78,12 +73,7 @@ namespace ImageSharp.Drawing
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try
{
int count = this.shape.FindIntersections(
start,
end,
innerbuffer,
length,
0);
int count = this.shape.FindIntersections(start, end, innerbuffer, length, 0);
for (int i = 0; i < count; i++)
{
@ -106,12 +96,7 @@ namespace ImageSharp.Drawing
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try
{
int count = this.shape.FindIntersections(
start,
end,
innerbuffer,
length,
0);
int count = this.shape.FindIntersections(start, end, innerbuffer, length, 0);
for (int i = 0; i < count; i++)
{
@ -133,6 +118,7 @@ namespace ImageSharp.Drawing
float distanceFromPath = float.MaxValue;
float distanceAlongPath = 0;
// ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < this.Paths.Length; i++)
{
SixLabors.Shapes.PointInfo p = this.Paths[i].Distance(point);

19
src/ImageSharp.Drawing.Paths/ShapeRegion.cs

@ -6,17 +6,14 @@
namespace ImageSharp.Drawing
{
using System.Buffers;
using System.Collections.Immutable;
using System.Numerics;
using ImageSharp.Drawing.Processors;
using SixLabors.Shapes;
using Rectangle = ImageSharp.Rectangle;
/// <summary>
/// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region.
/// A drawable mapping between a <see cref="IShape"/>/<see cref="IPath"/> and a drawable/fillable region.
/// </summary>
internal class ShapeRegion : Region
{
@ -58,12 +55,7 @@ namespace ImageSharp.Drawing
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try
{
int count = this.Shape.FindIntersections(
start,
end,
innerbuffer,
length,
0);
int count = this.Shape.FindIntersections(start, end, innerbuffer, length, 0);
for (int i = 0; i < count; i++)
{
@ -86,12 +78,7 @@ namespace ImageSharp.Drawing
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try
{
int count = this.Shape.FindIntersections(
start,
end,
innerbuffer,
length,
0);
int count = this.Shape.FindIntersections(start, end, innerbuffer, length, 0);
for (int i = 0; i < count; i++)
{

2
src/ImageSharp.Drawing/DrawPath.cs

@ -6,7 +6,7 @@
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;

2
src/ImageSharp.Drawing/FillRegion.cs

@ -6,7 +6,7 @@
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;

3
src/ImageSharp.Drawing/PointInfo.cs

@ -5,9 +5,6 @@
namespace ImageSharp.Drawing
{
using System;
using System.Numerics;
/// <summary>
/// Returns details about how far away from the inside of a shape and the color the pixel could be.
/// </summary>

73
src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs

@ -6,13 +6,11 @@
namespace ImageSharp.Drawing.Processors
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using ImageSharp.Processing;
using Pens;
using Rectangle = ImageSharp.Rectangle;
/// <summary>
/// Draws a path using the processor pipeline
@ -39,27 +37,18 @@ namespace ImageSharp.Drawing.Processors
}
/// <summary>
/// Gets the options.
/// Gets the graphics options.
/// </summary>
/// <value>
/// The options.
/// </value>
public GraphicsOptions Options { get; }
/// <summary>
/// Gets the pen.
/// </summary>
/// <value>
/// The pen.
/// </value>
public IPen<TColor> Pen { get; }
/// <summary>
/// Gets the path.
/// </summary>
/// <value>
/// The path.
/// </value>
public Drawable Path { get; }
/// <inheritdoc/>
@ -68,7 +57,7 @@ namespace ImageSharp.Drawing.Processors
using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (PenApplicator<TColor> applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds))
{
var rect = RectangleF.Ceiling(applicator.RequiredRegion);
Rectangle rect = RectangleF.Ceiling(applicator.RequiredRegion);
int polyStartY = rect.Y - PaddingFactor;
int polyEndY = rect.Bottom + PaddingFactor;
@ -98,49 +87,53 @@ namespace ImageSharp.Drawing.Processors
}
Parallel.For(
minY,
maxY,
this.ParallelOptions,
(int y) =>
{
int offsetY = y - polyStartY;
for (int x = minX; x < maxX; x++)
minY,
maxY,
this.ParallelOptions,
y =>
{
// TODO add find intersections code to skip and scan large regions of this.
int offsetX = x - startX;
var info = this.Path.GetPointInfo(offsetX, offsetY);
int offsetY = y - polyStartY;
var color = applicator.GetColor(offsetX, offsetY, info);
for (int x = minX; x < maxX; x++)
{
// TODO add find intersections code to skip and scan large regions of this.
int offsetX = x - startX;
PointInfo info = this.Path.GetPointInfo(offsetX, offsetY);
var opacity = this.Opacity(color.DistanceFromElement);
ColoredPointInfo<TColor> color = applicator.GetColor(offsetX, offsetY, info);
if (opacity > Constants.Epsilon)
{
int offsetColorX = x - minX;
float opacity = this.Opacity(color.DistanceFromElement);
Vector4 backgroundVector = sourcePixels[offsetX, offsetY].ToVector4();
Vector4 sourceVector = color.Color.ToVector4();
if (opacity > Constants.Epsilon)
{
Vector4 backgroundVector = sourcePixels[offsetX, offsetY].ToVector4();
Vector4 sourceVector = color.Color.ToVector4();
var finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
finalColor.W = backgroundVector.W;
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
finalColor.W = backgroundVector.W;
TColor packed = default(TColor);
packed.PackFromVector4(finalColor);
sourcePixels[offsetX, offsetY] = packed;
TColor packed = default(TColor);
packed.PackFromVector4(finalColor);
sourcePixels[offsetX, offsetY] = packed;
}
}
}
});
});
}
}
/// <summary>
/// Returns the correct opacity for the given distance.
/// </summary>
/// <param name="distance">Thw distance from the central point.</param>
/// <returns>The <see cref="float"/></returns>
private float Opacity(float distance)
{
if (distance <= 0)
{
return 1;
}
else if (this.Options.Antialias && distance < AntialiasFactor)
if (this.Options.Antialias && distance < AntialiasFactor)
{
return 1 - (distance / AntialiasFactor);
}

6
src/ImageSharp.Drawing/Region.cs

@ -16,17 +16,17 @@ namespace ImageSharp.Drawing
public abstract int MaxIntersections { get; }
/// <summary>
/// Gets the bounding box that entirly surrounds this region.
/// Gets the bounding box that entirely surrounds this region.
/// </summary>
/// <remarks>
/// This should always contains all possible points returned from eather <see cref="ScanX(int, float[], int, int)"/> or <see cref="ScanY(int, float[], int, int)"/>.
/// This should always contains all possible points returned from either <see cref="ScanX(int, float[], int, int)"/> or <see cref="ScanY(int, float[], int, int)"/>.
/// </remarks>
public abstract Rectangle Bounds { get; }
/// <summary>
/// Scans the X axis for intersections.
/// </summary>
/// <param name="x">The position along the X axies to find intersections.</param>
/// <param name="x">The position along the X axis to find intersections.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="length">The length.</param>
/// <param name="offset">The offset.</param>

Loading…
Cancel
Save