Browse Source

Merge branch 'master' into js/imageframe-configuration

pull/593/head
James Jackson-South 8 years ago
parent
commit
8efc750877
  1. 28
      src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs
  2. 3
      src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs
  3. 2
      src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs

28
src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs

@ -6,11 +6,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.ImageSharp.Processing.Transforms.Resamplers;
using SixLabors.Primitives;
@ -56,12 +56,12 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
Guard.MustBeGreaterThan(tempWidth, 0, nameof(tempWidth));
Guard.MustBeGreaterThan(tempHeight, 0, nameof(tempHeight));
(Size size, Rectangle rectangle) locationBounds = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options, tempWidth, tempHeight);
(Size size, Rectangle rectangle) = ResizeHelper.CalculateTargetLocationAndBounds(sourceSize, options, tempWidth, tempHeight);
this.Sampler = options.Sampler;
this.Width = locationBounds.size.Width;
this.Height = locationBounds.size.Height;
this.ResizeRectangle = locationBounds.rectangle;
this.Width = size.Width;
this.Height = size.Height;
this.ResizeRectangle = rectangle;
this.Compand = options.Compand;
}
@ -167,13 +167,13 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
float center = ((i + .5F) * ratio) - .5F;
// Keep inside bounds.
int left = (int)Math.Ceiling(center - radius);
int left = (int)MathF.Ceiling(center - radius);
if (left < 0)
{
left = 0;
}
int right = (int)Math.Floor(center + radius);
int right = (int)MathF.Floor(center + radius);
if (right > sourceSize - 1)
{
right = sourceSize - 1;
@ -245,7 +245,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
// Handle resize dimensions identical to the original
if (source.Width == destination.Width && source.Height == destination.Height && sourceRectangle == this.ResizeRectangle)
{
// the cloned will be blank here copy all the pixel data over
// The cloned will be blank here copy all the pixel data over
source.GetPixelSpan().CopyTo(destination.GetPixelSpan());
return;
}
@ -306,7 +306,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
source.Width,
(int y, IBuffer<Vector4> tempRowBuffer) =>
{
Span<Vector4> firstPassRow = firstPassPixels.GetRowSpan(y);
ref Vector4 firstPassRow = ref MemoryMarshal.GetReference(firstPassPixels.GetRowSpan(y));
Span<TPixel> sourceRow = source.GetPixelRowSpan(y);
Span<Vector4> tempRowSpan = tempRowBuffer.Span;
@ -317,7 +317,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
for (int x = minX; x < maxX; x++)
{
WeightsWindow window = this.horizontalWeights.Weights[x - startX];
firstPassRow[x] = window.ComputeExpandedWeightedRowSum(tempRowSpan, sourceX);
Unsafe.Add(ref firstPassRow, x) = window.ComputeExpandedWeightedRowSum(tempRowSpan, sourceX);
}
}
else
@ -325,7 +325,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
for (int x = minX; x < maxX; x++)
{
WeightsWindow window = this.horizontalWeights.Weights[x - startX];
firstPassRow[x] = window.ComputeWeightedRowSum(tempRowSpan, sourceX);
Unsafe.Add(ref firstPassRow, x) = window.ComputeWeightedRowSum(tempRowSpan, sourceX);
}
}
});
@ -339,7 +339,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{
// Ensure offsets are normalized for cropping and padding.
WeightsWindow window = this.verticalWeights.Weights[y - startY];
Span<TPixel> targetRow = destination.GetPixelRowSpan(y);
ref TPixel targetRow = ref MemoryMarshal.GetReference(destination.GetPixelRowSpan(y));
if (this.Compand)
{
@ -349,7 +349,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
Vector4 destinationVector = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY);
destinationVector = destinationVector.Compress();
ref TPixel pixel = ref targetRow[x];
ref TPixel pixel = ref Unsafe.Add(ref targetRow, x);
pixel.PackFromVector4(destinationVector);
}
}
@ -360,7 +360,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
// Destination color components
Vector4 destinationVector = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY);
ref TPixel pixel = ref targetRow[x];
ref TPixel pixel = ref Unsafe.Add(ref targetRow, x);
pixel.PackFromVector4(destinationVector);
}
}

3
src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs

@ -2,10 +2,9 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Processors
namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{
/// <summary>
/// Holds the <see cref="WeightsWindow"/> values in an optimized contigous memory region.

2
src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs

@ -7,7 +7,7 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Processors
namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{
/// <summary>
/// Points to a collection of of weights allocated in <see cref="WeightsBuffer"/>.

Loading…
Cancel
Save