Browse Source

Refactor ImageFrame<TPixel>

pull/1108/head
Sergio Pedri 6 years ago
parent
commit
d2741422fc
  1. 44
      src/ImageSharp/ImageFrame{TPixel}.cs
  2. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

44
src/ImageSharp/ImageFrame{TPixel}.cs

@ -263,15 +263,7 @@ namespace SixLabors.ImageSharp
ParallelRowIterator.IterateRows(
this.Bounds(),
configuration,
rows =>
{
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixel> sourceRow = this.GetPixelRowSpan(y);
Span<TPixel2> targetRow = target.GetPixelRowSpan(y);
PixelOperations<TPixel>.Instance.To(configuration, sourceRow, targetRow);
}
});
new RowIntervalAction<TPixel2>(this, target, configuration));
return target;
}
@ -293,5 +285,39 @@ namespace SixLabors.ImageSharp
span.Fill(value);
}
}
/// <summary>
/// A <see langword="struct"/> implementing the clone logic for <see cref="ImageFrame{TPixel}"/>.
/// </summary>
private readonly struct RowIntervalAction<TPixel2> : IRowIntervalAction
where TPixel2 : struct, IPixel<TPixel2>
{
private readonly ImageFrame<TPixel> source;
private readonly ImageFrame<TPixel2> target;
private readonly Configuration configuration;
[MethodImpl(InliningOptions.ShortMethod)]
public RowIntervalAction(
ImageFrame<TPixel> source,
ImageFrame<TPixel2> target,
Configuration configuration)
{
this.source = source;
this.target = target;
this.configuration = configuration;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows)
{
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixel> sourceRow = this.source.GetPixelRowSpan(y);
Span<TPixel2> targetRow = this.target.GetPixelRowSpan(y);
PixelOperations<TPixel>.Instance.To(this.configuration, sourceRow, targetRow);
}
}
}
}
}

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private readonly int targetWidth;
private readonly int targetHeight;
private readonly IResampler resampler;
private Rectangle targetRectangle;
private readonly Rectangle targetRectangle;
private readonly bool compand;
// The following fields are not immutable but are optionally created on demand.

Loading…
Cancel
Save