Skip to content

Commit

Permalink
Merge pull request SixLabors#326 from SixLabors/image-frames
Browse files Browse the repository at this point in the history
 API Image frames refactor
  • Loading branch information
tocsoft authored Sep 12, 2017
2 parents a5f163c + 1cab98f commit 0810141
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/ImageSharp.Drawing/Brushes/IBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public interface IBrush<TPixel>
/// 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>
BrushApplicator<TPixel> CreateApplicator(ImageBase<TPixel> source, RectangleF region, GraphicsOptions options);
BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options);
}
}
10 changes: 5 additions & 5 deletions src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ public class ImageBrush<TPixel> : IBrush<TPixel>
/// <summary>
/// The image to paint.
/// </summary>
private readonly ImageBase<TPixel> image;
private readonly ImageFrame<TPixel> image;

/// <summary>
/// Initializes a new instance of the <see cref="ImageBrush{TPixel}"/> class.
/// </summary>
/// <param name="image">The image.</param>
public ImageBrush(ImageBase<TPixel> image)
public ImageBrush(ImageFrame<TPixel> image)
{
this.image = image;
}

/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator(ImageBase<TPixel> source, RectangleF region, GraphicsOptions options)
public BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
{
return new ImageBrushApplicator(source, this.image, region, options);
}
Expand All @@ -46,7 +46,7 @@ private class ImageBrushApplicator : BrushApplicator<TPixel>
/// <summary>
/// The source image.
/// </summary>
private readonly ImageBase<TPixel> source;
private readonly ImageFrame<TPixel> source;

/// <summary>
/// The y-length.
Expand Down Expand Up @@ -75,7 +75,7 @@ private class ImageBrushApplicator : BrushApplicator<TPixel>
/// <param name="image">The image.</param>
/// <param name="region">The region.</param>
/// <param name="options">The options</param>
public ImageBrushApplicator(ImageBase<TPixel> target, ImageBase<TPixel> image, RectangleF region, GraphicsOptions options)
public ImageBrushApplicator(ImageFrame<TPixel> target, ImageFrame<TPixel> image, RectangleF region, GraphicsOptions options)
: base(target, options)
{
this.source = image;
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal PatternBrush(PatternBrush<TPixel> brush)
}

/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator(ImageBase<TPixel> source, RectangleF region, GraphicsOptions options)
public BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
{
return new PatternBrushApplicator(source, this.pattern, this.patternVector, options);
}
Expand All @@ -115,7 +115,7 @@ private class PatternBrushApplicator : BrushApplicator<TPixel>
/// <param name="pattern">The pattern.</param>
/// <param name="patternVector">The patternVector.</param>
/// <param name="options">The options</param>
public PatternBrushApplicator(ImageBase<TPixel> source, Fast2DArray<TPixel> pattern, Fast2DArray<Vector4> patternVector, GraphicsOptions options)
public PatternBrushApplicator(ImageFrame<TPixel> source, Fast2DArray<TPixel> pattern, Fast2DArray<Vector4> patternVector, GraphicsOptions options)
: base(source, options)
{
this.pattern = pattern;
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class BrushApplicator<TPixel> : IDisposable // disposable will b
/// </summary>
/// <param name="target">The target.</param>
/// <param name="options">The options.</param>
internal BrushApplicator(ImageBase<TPixel> target, GraphicsOptions options)
internal BrushApplicator(ImageFrame<TPixel> target, GraphicsOptions options)
{
this.Target = target;

Expand All @@ -38,7 +38,7 @@ internal BrushApplicator(ImageBase<TPixel> target, GraphicsOptions options)
/// <summary>
/// Gets the destinaion
/// </summary>
protected ImageBase<TPixel> Target { get; }
protected ImageFrame<TPixel> Target { get; }

/// <summary>
/// Gets the blend percentage
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public RecolorBrush(TPixel sourceColor, TPixel targeTPixel, float threshold)
public TPixel TargeTPixel { get; }

/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator(ImageBase<TPixel> source, RectangleF region, GraphicsOptions options)
public BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
{
return new RecolorBrushApplicator(source, this.SourceColor, this.TargeTPixel, this.Threshold, options);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ private class RecolorBrushApplicator : BrushApplicator<TPixel>
/// <param name="targetColor">Color of the target.</param>
/// <param name="threshold">The threshold .</param>
/// <param name="options">The options</param>
public RecolorBrushApplicator(ImageBase<TPixel> source, TPixel sourceColor, TPixel targetColor, float threshold, GraphicsOptions options)
public RecolorBrushApplicator(ImageFrame<TPixel> source, TPixel sourceColor, TPixel targetColor, float threshold, GraphicsOptions options)
: base(source, options)
{
this.sourceColor = sourceColor.ToVector4();
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SolidBrush(TPixel color)
public TPixel Color => this.color;

/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator(ImageBase<TPixel> source, RectangleF region, GraphicsOptions options)
public BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
{
return new SolidBrushApplicator(source, this.color, options);
}
Expand All @@ -58,7 +58,7 @@ private class SolidBrushApplicator : BrushApplicator<TPixel>
/// <param name="source">The source image.</param>
/// <param name="color">The color.</param>
/// <param name="options">The options</param>
public SolidBrushApplicator(ImageBase<TPixel> source, TPixel color, GraphicsOptions options)
public SolidBrushApplicator(ImageFrame<TPixel> source, TPixel color, GraphicsOptions options)
: base(source, options)
{
this.Colors = new Buffer<TPixel>(source.Width);
Expand Down
6 changes: 4 additions & 2 deletions src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Numerics;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
Expand Down Expand Up @@ -58,7 +60,7 @@ public DrawImageProcessor(Image<TPixel> image, Size size, Point location, Graphi
public Point Location { get; }

/// <inheritdoc/>
protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
Image<TPixel> disposableImage = null;
Image<TPixel> targetImage = this.Image;
Expand Down Expand Up @@ -94,7 +96,7 @@ protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectan
Parallel.For(
minY,
maxY,
source.Configuration.ParallelOptions,
configuration.ParallelOptions,
y =>
{
Span<TPixel> background = sourcePixels.GetRowSpan(y).Slice(minX, width);
Expand Down
8 changes: 3 additions & 5 deletions src/ImageSharp.Drawing/Processors/FillProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
Expand Down Expand Up @@ -39,7 +40,7 @@ public FillProcessor(IBrush<TPixel> brush, GraphicsOptions options)
}

/// <inheritdoc/>
protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
Expand All @@ -65,9 +66,6 @@ protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectan

int width = maxX - minX;

// We could possibly do some optimization by having knowledge about the individual brushes operate
// for example If brush is SolidBrush<TPixel> then we could just get the color upfront
// and skip using the IBrushApplicator<TPixel>?.
using (var amount = new Buffer<float>(width))
using (BrushApplicator<TPixel> applicator = this.brush.CreateApplicator(source, sourceRectangle, this.options))
{
Expand All @@ -79,7 +77,7 @@ protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectan
Parallel.For(
minY,
maxY,
source.Configuration.ParallelOptions,
configuration.ParallelOptions,
y =>
{
int offsetY = y - startY;
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FillRegionProcessor(IBrush<TPixel> brush, Region region, GraphicsOptions
public GraphicsOptions Options { get; }

/// <inheritdoc/>
protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
Region region = this.Region;
Rectangle rect = region.Bounds;
Expand Down
3 changes: 2 additions & 1 deletion tests/ImageSharp.Tests/TestFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;

Expand Down Expand Up @@ -145,7 +146,7 @@ public Image<Rgba32> CreateImage()
/// </returns>
public Image<Rgba32> CreateImage(IImageDecoder decoder)
{
return ImageSharp.Image.Load(this.Image.Configuration, this.Bytes, decoder);
return ImageSharp.Image.Load(this.Image.GetConfiguration(), this.Bytes, decoder);
}
}
}

0 comments on commit 0810141

Please sign in to comment.