Browse Source

Update FlipProcessor

af/octree-no-pixelmap
James Jackson-South 7 years ago
parent
commit
7f1c2d6e4a
  1. 4
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs
  2. 24
      src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs

4
src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs

@ -60,8 +60,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
Configuration configuration = this.Configuration; Configuration configuration = this.Configuration;
MemoryAllocator allocator = configuration.MemoryAllocator; MemoryAllocator allocator = configuration.MemoryAllocator;
using (IMemoryOwner<TPixel> rowColors = allocator.Allocate<TPixel>(interest.Width)) using IMemoryOwner<TPixel> rowColors = allocator.Allocate<TPixel>(interest.Width);
{
rowColors.GetSpan().Fill(vignetteColor); rowColors.GetSpan().Fill(vignetteColor);
ParallelRowIterator.IterateRows<RowIntervalAction, float>( ParallelRowIterator.IterateRows<RowIntervalAction, float>(
@ -69,7 +68,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
configuration, configuration,
new RowIntervalAction(configuration, interest, rowColors, this.blender, center, maxDistance, blendPercent, source)); new RowIntervalAction(configuration, interest, rowColors, this.blender, center, maxDistance, blendPercent, source));
} }
}
private readonly struct RowIntervalAction : IRowIntervalAction<float> private readonly struct RowIntervalAction : IRowIntervalAction<float>
{ {

24
src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs

@ -3,7 +3,9 @@
using System; using System;
using System.Buffers; using System.Buffers;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Processing.Processors.Transforms
@ -53,9 +55,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private void FlipX(ImageFrame<TPixel> source, Configuration configuration) private void FlipX(ImageFrame<TPixel> source, Configuration configuration)
{ {
int height = source.Height; int height = source.Height;
using IMemoryOwner<TPixel> tempBuffer = configuration.MemoryAllocator.Allocate<TPixel>(source.Width);
using (IMemoryOwner<TPixel> tempBuffer = configuration.MemoryAllocator.Allocate<TPixel>(source.Width))
{
Span<TPixel> temp = tempBuffer.Memory.Span; Span<TPixel> temp = tempBuffer.Memory.Span;
for (int yTop = 0; yTop < height / 2; yTop++) for (int yTop = 0; yTop < height / 2; yTop++)
@ -68,7 +68,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
temp.CopyTo(bottomRow); temp.CopyTo(bottomRow);
} }
} }
}
/// <summary> /// <summary>
/// Swaps the image at the Y-axis, which goes vertically through the middle at half of the width of the image. /// Swaps the image at the Y-axis, which goes vertically through the middle at half of the width of the image.
@ -80,13 +79,24 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
ParallelRowIterator.IterateRows( ParallelRowIterator.IterateRows(
source.Bounds(), source.Bounds(),
configuration, configuration,
rows => new RowIntervalAction(source));
}
private readonly struct RowIntervalAction : IRowIntervalAction
{
private readonly ImageFrame<TPixel> source;
[MethodImpl(InliningOptions.ShortMethod)]
public RowIntervalAction(ImageFrame<TPixel> source) => this.source = source;
[MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows)
{ {
for (int y = rows.Min; y < rows.Max; y++) for (int y = rows.Min; y < rows.Max; y++)
{ {
source.GetPixelRowSpan(y).Reverse(); this.source.GetPixelRowSpan(y).Reverse();
}
} }
});
} }
} }
} }

Loading…
Cancel
Save