Browse Source

Added missing using statement

pull/1068/head
Sergio Pedri 6 years ago
parent
commit
17ff3e1c72
  1. 99
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

99
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

@ -73,73 +73,74 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
ref Vector4 vectorSpanRef = ref MemoryMarshal.GetReference(vectorSpan); ref Vector4 vectorSpanRef = ref MemoryMarshal.GetReference(vectorSpan);
// Rent the shared buffer only once per parallel item // Rent the shared buffer only once per parallel item
IMemoryOwner<float> bins = configuration.MemoryAllocator.Allocate<float>(levels * 4); using (IMemoryOwner<float> bins = configuration.MemoryAllocator.Allocate<float>(levels * 4))
ref float binsRef = ref bins.GetReference();
ref int intensityBinRef = ref Unsafe.As<float, int>(ref binsRef);
ref float redBinRef = ref Unsafe.Add(ref binsRef, levels);
ref float blueBinRef = ref Unsafe.Add(ref redBinRef, levels);
ref float greenBinRef = ref Unsafe.Add(ref blueBinRef, levels);
for (int y = rows.Min; y < rows.Max; y++)
{ {
Span<TPixel> sourceRow = source.GetPixelRowSpan(y); ref float binsRef = ref bins.GetReference();
Span<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX, length); ref int intensityBinRef = ref Unsafe.As<float, int>(ref binsRef);
PixelOperations<TPixel>.Instance.ToVector4(configuration, targetRowSpan, vectorSpan); ref float redBinRef = ref Unsafe.Add(ref binsRef, levels);
ref float blueBinRef = ref Unsafe.Add(ref redBinRef, levels);
ref float greenBinRef = ref Unsafe.Add(ref blueBinRef, levels);
for (int x = startX; x < endX; x++) for (int y = rows.Min; y < rows.Max; y++)
{ {
int maxIntensity = 0; Span<TPixel> sourceRow = source.GetPixelRowSpan(y);
int maxIndex = 0; Span<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX, length);
PixelOperations<TPixel>.Instance.ToVector4(configuration, targetRowSpan, vectorSpan);
// Clear the current shared buffer before processing each target pixel for (int x = startX; x < endX; x++)
bins.Memory.Span.Clear();
for (int fy = 0; fy <= radius; fy++)
{ {
int fyr = fy - radius; int maxIntensity = 0;
int offsetY = y + fyr; int maxIndex = 0;
offsetY = offsetY.Clamp(0, maxY);
Span<TPixel> sourceOffsetRow = source.GetPixelRowSpan(offsetY); // Clear the current shared buffer before processing each target pixel
bins.Memory.Span.Clear();
for (int fx = 0; fx <= radius; fx++) for (int fy = 0; fy <= radius; fy++)
{ {
int fxr = fx - radius; int fyr = fy - radius;
int offsetX = x + fxr; int offsetY = y + fyr;
offsetX = offsetX.Clamp(0, maxX);
var vector = sourceOffsetRow[offsetX].ToVector4(); offsetY = offsetY.Clamp(0, maxY);
float sourceRed = vector.X; Span<TPixel> sourceOffsetRow = source.GetPixelRowSpan(offsetY);
float sourceBlue = vector.Z;
float sourceGreen = vector.Y;
int currentIntensity = (int)MathF.Round((sourceBlue + sourceGreen + sourceRed) / 3F * (levels - 1)); for (int fx = 0; fx <= radius; fx++)
{
int fxr = fx - radius;
int offsetX = x + fxr;
offsetX = offsetX.Clamp(0, maxX);
Unsafe.Add(ref intensityBinRef, currentIntensity)++; var vector = sourceOffsetRow[offsetX].ToVector4();
Unsafe.Add(ref redBinRef, currentIntensity) += sourceRed;
Unsafe.Add(ref blueBinRef, currentIntensity) += sourceBlue;
Unsafe.Add(ref greenBinRef, currentIntensity) += sourceGreen;
if (Unsafe.Add(ref intensityBinRef, currentIntensity) > maxIntensity) float sourceRed = vector.X;
{ float sourceBlue = vector.Z;
maxIntensity = Unsafe.Add(ref intensityBinRef, currentIntensity); float sourceGreen = vector.Y;
maxIndex = currentIntensity;
int currentIntensity = (int)MathF.Round((sourceBlue + sourceGreen + sourceRed) / 3F * (levels - 1));
Unsafe.Add(ref intensityBinRef, currentIntensity)++;
Unsafe.Add(ref redBinRef, currentIntensity) += sourceRed;
Unsafe.Add(ref blueBinRef, currentIntensity) += sourceBlue;
Unsafe.Add(ref greenBinRef, currentIntensity) += sourceGreen;
if (Unsafe.Add(ref intensityBinRef, currentIntensity) > maxIntensity)
{
maxIntensity = Unsafe.Add(ref intensityBinRef, currentIntensity);
maxIndex = currentIntensity;
}
} }
}
float red = MathF.Abs(Unsafe.Add(ref redBinRef, maxIndex) / maxIntensity); float red = MathF.Abs(Unsafe.Add(ref redBinRef, maxIndex) / maxIntensity);
float blue = MathF.Abs(Unsafe.Add(ref blueBinRef, maxIndex) / maxIntensity); float blue = MathF.Abs(Unsafe.Add(ref blueBinRef, maxIndex) / maxIntensity);
float green = MathF.Abs(Unsafe.Add(ref greenBinRef, maxIndex) / maxIntensity); float green = MathF.Abs(Unsafe.Add(ref greenBinRef, maxIndex) / maxIntensity);
float alpha = sourceRow[x].ToVector4().W; float alpha = sourceRow[x].ToVector4().W;
Unsafe.Add(ref vectorSpanRef, x) = new Vector4(red, green, blue, alpha); Unsafe.Add(ref vectorSpanRef, x) = new Vector4(red, green, blue, alpha);
}
} }
}
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, targetRowSpan); PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, targetRowSpan);
}
} }
}); });

Loading…
Cancel
Save