Browse Source

fix span length issues related to Vector4 conversion

pull/744/head
Anton Firszov 7 years ago
parent
commit
b69baf57f4
  1. 12
      src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs
  2. 4
      src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs
  3. 4
      src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs
  4. 4
      src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs
  5. 2
      src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs
  6. 2
      tests/ImageSharp.Tests/Issues/Issue412.cs

12
src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs

@ -93,12 +93,12 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
PixelOperations<TPixel>.Instance.ToScaledVector4(background, backgroundSpan);
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source, sourceSpan);
PixelOperations<TPixel>.Instance.ToScaledVector4(background.Slice(0, background.Length), backgroundSpan);
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source.Slice(0, background.Length), sourceSpan);
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount);
PixelOperations<TPixel>.Instance.FromScaledVector4(destinationSpan, destination);
PixelOperations<TPixel>.Instance.FromScaledVector4(destinationSpan.Slice(0, background.Length), destination);
}
}
@ -127,12 +127,12 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
PixelOperations<TPixel>.Instance.ToScaledVector4(background, backgroundSpan);
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source, sourceSpan);
PixelOperations<TPixel>.Instance.ToScaledVector4(background.Slice(0, background.Length), backgroundSpan);
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source.Slice(0, background.Length), sourceSpan);
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount);
PixelOperations<TPixel>.Instance.FromScaledVector4(destinationSpan, destination);
PixelOperations<TPixel>.Instance.FromScaledVector4(destinationSpan.Slice(0, background.Length), destination);
}
}
}

4
src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs

@ -75,14 +75,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX);
PixelOperations<TPixel>.Instance.ToVector4(targetRowSpan, vectorSpan);
PixelOperations<TPixel>.Instance.ToVector4(targetRowSpan.Slice(0, length), vectorSpan);
for (int x = 0; x < width; x++)
{
DenseMatrixUtils.Convolve2D(in matrixY, in matrixX, source.PixelBuffer, vectorSpan, y, x, maxY, maxX, startX);
}
PixelOperations<TPixel>.Instance.FromVector4(vectorSpan, targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4(vectorSpan.Slice(0, length), targetRowSpan);
}
});

4
src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs

@ -93,14 +93,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX);
PixelOperations<TPixel>.Instance.ToVector4(targetRowSpan, vectorSpan);
PixelOperations<TPixel>.Instance.ToVector4(targetRowSpan.Slice(0, length), vectorSpan);
for (int x = 0; x < width; x++)
{
DenseMatrixUtils.Convolve(in matrix, sourcePixels, vectorSpan, y, x, maxY, maxX, startX);
}
PixelOperations<TPixel>.Instance.FromVector4(vectorSpan, targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4(vectorSpan.Slice(0, length), targetRowSpan);
}
});
}

4
src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs

@ -59,14 +59,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX);
PixelOperations<TPixel>.Instance.ToVector4(targetRowSpan, vectorSpan);
PixelOperations<TPixel>.Instance.ToVector4(targetRowSpan.Slice(0, length), vectorSpan);
for (int x = 0; x < width; x++)
{
DenseMatrixUtils.Convolve(in matrix, source.PixelBuffer, vectorSpan, y, x, maxY, maxX, startX);
}
PixelOperations<TPixel>.Instance.FromVector4(vectorSpan, targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4(vectorSpan.Slice(0, length), targetRowSpan);
}
});

2
src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs

@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
public virtual QuantizedFrame<TPixel> QuantizeFrame(ImageFrame<TPixel> image)
{
Guard.NotNull(image, nameof(image));
// Get the size of the source image
int height = image.Height;
int width = image.Width;

2
tests/ImageSharp.Tests/Issues/Issue412.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Issues
[WithBlankImages(40, 30, PixelTypes.Rgba32)]
public void AllPixelsExpectedToBeRedWhenAntialiasedDisabled<TPixel>(TestImageProvider<TPixel> provider) where TPixel : struct, IPixel<TPixel>
{
using (var image = provider.GetImage())
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(
context =>

Loading…
Cancel
Save