Browse Source

Refactored RotateProcessor<TPixel>

pull/1574/head
Sergio Pedri 7 years ago
parent
commit
f8f771dd91
  1. 46
      src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor{TPixel}.cs

46
src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor{TPixel}.cs

@ -131,8 +131,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <param name="configuration">The configuration.</param> /// <param name="configuration">The configuration.</param>
private void Rotate180(ImageFrame<TPixel> source, ImageFrame<TPixel> destination, Configuration configuration) private void Rotate180(ImageFrame<TPixel> source, ImageFrame<TPixel> destination, Configuration configuration)
{ {
var operation = new Rotate180RowIntervalOperation(source.Width, source.Height, source, destination); var operation = new Rotate180RowOperation(source.Width, source.Height, source, destination);
ParallelRowIterator.IterateRowIntervals( ParallelRowIterator.IterateRows(
configuration, configuration,
source.Bounds(), source.Bounds(),
in operation); in operation);
@ -161,14 +161,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <param name="configuration">The configuration.</param> /// <param name="configuration">The configuration.</param>
private void Rotate90(ImageFrame<TPixel> source, ImageFrame<TPixel> destination, Configuration configuration) private void Rotate90(ImageFrame<TPixel> source, ImageFrame<TPixel> destination, Configuration configuration)
{ {
var operation = new Rotate90RowIntervalOperation(destination.Bounds(), source.Width, source.Height, source, destination); var operation = new Rotate90RowOperation(destination.Bounds(), source.Width, source.Height, source, destination);
ParallelRowIterator.IterateRowIntervals( ParallelRowIterator.IterateRows(
configuration, configuration,
source.Bounds(), source.Bounds(),
in operation); in operation);
} }
private readonly struct Rotate180RowIntervalOperation : IRowIntervalOperation private readonly struct Rotate180RowOperation : IRowOperation
{ {
private readonly int width; private readonly int width;
private readonly int height; private readonly int height;
@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private readonly ImageFrame<TPixel> destination; private readonly ImageFrame<TPixel> destination;
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rotate180RowIntervalOperation( public Rotate180RowOperation(
int width, int width,
int height, int height,
ImageFrame<TPixel> source, ImageFrame<TPixel> source,
@ -189,17 +189,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows) public void Invoke(int y)
{ {
for (int y = rows.Min; y < rows.Max; y++) Span<TPixel> sourceRow = this.source.GetPixelRowSpan(y);
{ Span<TPixel> targetRow = this.destination.GetPixelRowSpan(this.height - y - 1);
Span<TPixel> sourceRow = this.source.GetPixelRowSpan(y);
Span<TPixel> targetRow = this.destination.GetPixelRowSpan(this.height - y - 1);
for (int x = 0; x < this.width; x++) for (int x = 0; x < this.width; x++)
{ {
targetRow[this.width - x - 1] = sourceRow[x]; targetRow[this.width - x - 1] = sourceRow[x];
}
} }
} }
} }
@ -248,7 +245,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
} }
private readonly struct Rotate90RowIntervalOperation : IRowIntervalOperation private readonly struct Rotate90RowOperation : IRowOperation
{ {
private readonly Rectangle bounds; private readonly Rectangle bounds;
private readonly int width; private readonly int width;
@ -257,7 +254,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private readonly ImageFrame<TPixel> destination; private readonly ImageFrame<TPixel> destination;
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rotate90RowIntervalOperation( public Rotate90RowOperation(
Rectangle bounds, Rectangle bounds,
int width, int width,
int height, int height,
@ -272,18 +269,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows) public void Invoke(int y)
{ {
for (int y = rows.Min; y < rows.Max; y++) Span<TPixel> sourceRow = this.source.GetPixelRowSpan(y);
int newX = this.height - y - 1;
for (int x = 0; x < this.width; x++)
{ {
Span<TPixel> sourceRow = this.source.GetPixelRowSpan(y); if (this.bounds.Contains(newX, x))
int newX = this.height - y - 1;
for (int x = 0; x < this.width; x++)
{ {
if (this.bounds.Contains(newX, x)) this.destination[newX, x] = sourceRow[x];
{
this.destination[newX, x] = sourceRow[x];
}
} }
} }
} }

Loading…
Cancel
Save