Browse Source

Update BinaryThresholdProcessor{TPixel}.cs

af/octree-no-pixelmap
James Jackson-South 6 years ago
parent
commit
f367f34229
  1. 23
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs

23
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs

@ -42,18 +42,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
Configuration configuration = this.Configuration; Configuration configuration = this.Configuration;
var interest = Rectangle.Intersect(sourceRectangle, source.Bounds()); var interest = Rectangle.Intersect(sourceRectangle, source.Bounds());
int startY = interest.Y;
int endY = interest.Bottom;
int startX = interest.X;
int endX = interest.Right;
bool isAlphaOnly = typeof(TPixel) == typeof(A8); bool isAlphaOnly = typeof(TPixel) == typeof(A8);
var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY); var operation = new RowIntervalOperation(interest, source, upper, lower, threshold, isAlphaOnly);
var operation = new RowIntervalOperation(source, upper, lower, threshold, startX, endX, isAlphaOnly);
ParallelRowIterator.IterateRows( ParallelRowIterator.IterateRows(
configuration, configuration,
workingRect, interest,
in operation); in operation);
} }
@ -66,26 +60,25 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
private readonly TPixel upper; private readonly TPixel upper;
private readonly TPixel lower; private readonly TPixel lower;
private readonly byte threshold; private readonly byte threshold;
private readonly int startX; private readonly int minX;
private readonly int endX; private readonly int maxX;
private readonly bool isAlphaOnly; private readonly bool isAlphaOnly;
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public RowIntervalOperation( public RowIntervalOperation(
Rectangle bounds,
ImageFrame<TPixel> source, ImageFrame<TPixel> source,
TPixel upper, TPixel upper,
TPixel lower, TPixel lower,
byte threshold, byte threshold,
int startX,
int endX,
bool isAlphaOnly) bool isAlphaOnly)
{ {
this.source = source; this.source = source;
this.upper = upper; this.upper = upper;
this.lower = lower; this.lower = lower;
this.threshold = threshold; this.threshold = threshold;
this.startX = startX; this.minX = bounds.X;
this.endX = endX; this.maxX = bounds.Right;
this.isAlphaOnly = isAlphaOnly; this.isAlphaOnly = isAlphaOnly;
} }
@ -98,7 +91,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
{ {
Span<TPixel> row = this.source.GetPixelRowSpan(y); Span<TPixel> row = this.source.GetPixelRowSpan(y);
for (int x = this.startX; x < this.endX; x++) for (int x = this.minX; x < this.maxX; x++)
{ {
ref TPixel color = ref row[x]; ref TPixel color = ref row[x];
color.ToRgba32(ref rgba); color.ToRgba32(ref rgba);

Loading…
Cancel
Save