Browse Source

rename FromVector4(...) to FromVector4Destructive(...)

pull/869/head
Anton Firszov 7 years ago
parent
commit
4a0b10080d
  1. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
  2. 4
      src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs
  3. 4
      src/ImageSharp/PixelFormats/PixelConversionModifiers.cs
  4. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs
  5. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs
  6. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs
  7. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs
  8. 2
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs
  9. 2
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs
  10. 18
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  11. 2
      src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs
  12. 2
      src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs
  13. 2
      src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs
  14. 2
      src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs
  15. 2
      src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs
  16. 2
      src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs
  17. 2
      src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
  18. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor.cs
  19. 4
      tests/ImageSharp.Benchmarks/Color/Bulk/FromVector4.cs
  20. 2
      tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs
  21. 12
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
  22. 2
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs

@ -173,7 +173,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
Span<TPixel> destRow = destination.GetPixelRowSpan(yy);
// TODO: Investigate if slicing is actually necessary
PixelOperations<TPixel>.Instance.FromVector4(this.configuration, this.rgbaBuffer.GetSpan().Slice(0, destRow.Length), destRow);
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, this.rgbaBuffer.GetSpan().Slice(0, destRow.Length), destRow);
}
}
}

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

@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.PixelFormats
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount);
Span<Vector4> sourceVectors = destinationSpan.Slice(0, background.Length);
PixelOperations<TPixel>.Instance.FromVector4(configuration, sourceVectors, destination, PixelConversionModifiers.Scale);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, sourceVectors, destination, PixelConversionModifiers.Scale);
}
}
@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.PixelFormats
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount);
Span<Vector4> sourceVectors = destinationSpan.Slice(0, background.Length);
PixelOperations<TPixel>.Instance.FromVector4(configuration, sourceVectors, destination, PixelConversionModifiers.Scale);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, sourceVectors, destination, PixelConversionModifiers.Scale);
}
}
}

4
src/ImageSharp/PixelFormats/PixelConversionModifiers.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// Flags responsible to select additional operations which could be effitiently applied in
/// <see cref="PixelOperations{TPixel}.ToVector4(SixLabors.ImageSharp.Configuration,System.ReadOnlySpan{TPixel},System.Span{System.Numerics.Vector4},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
/// or
/// <see cref="PixelOperations{TPixel}.FromVector4(SixLabors.ImageSharp.Configuration,System.Span{System.Numerics.Vector4},System.Span{TPixel},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
/// <see cref="PixelOperations{TPixel}.FromVector4Destructive(SixLabors.ImageSharp.Configuration,System.Span{System.Numerics.Vector4},System.Span{TPixel},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
/// knowing the pixel type.
/// </summary>
[Flags]
@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.PixelFormats
None = 0,
/// <summary>
/// Select <see cref="IPixel.ToScaledVector4"/> <see cref="IPixel.FromScaledVector4"/> instead the standard (non scaled) variants.
/// Select <see cref="IPixel.ToScaledVector4"/> and <see cref="IPixel.FromScaledVector4"/> instead the standard (non scaled) variants.
/// </summary>
Scale = 1 << 0,

2
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Argb32.PixelOperations.Generated.cs

@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.PixelFormats
}
/// <inheritdoc />
internal override void FromVector4(Configuration configuration, Span<Vector4> sourceVectors, Span<Argb32> destPixels, PixelConversionModifiers modifiers)
internal override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Argb32> destPixels, PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale));
}

2
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgr24.PixelOperations.Generated.cs

@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.PixelFormats
}
/// <inheritdoc />
internal override void FromVector4(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgr24> destPixels, PixelConversionModifiers modifiers)
internal override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgr24> destPixels, PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
}

2
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Bgra32.PixelOperations.Generated.cs

@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.PixelFormats
}
/// <inheritdoc />
internal override void FromVector4(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgra32> destPixels, PixelConversionModifiers modifiers)
internal override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Bgra32> destPixels, PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale));
}

2
src/ImageSharp/PixelFormats/PixelImplementations/Generated/Rgb24.PixelOperations.Generated.cs

@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.PixelFormats
}
/// <inheritdoc />
internal override void FromVector4(Configuration configuration, Span<Vector4> sourceVectors, Span<Rgb24> destPixels, PixelConversionModifiers modifiers)
internal override void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<Rgb24> destPixels, PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destPixels, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
}

2
src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.PixelOperations.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.PixelFormats
}
/// <inheritdoc />
internal override void FromVector4(
internal override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<Rgba32> destPixels,

2
src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.PixelOperations.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.PixelFormats
internal class PixelOperations : PixelOperations<RgbaVector>
{
/// <inheritdoc />
internal override void FromVector4(
internal override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<RgbaVector> destinationColors,

18
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs

@ -24,13 +24,17 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.
/// TODO: Rename to DestructiveFromVector4() + add explain behavior
/// The method is DESTRUCTIVE altering the contents of <paramref name="sourceVectors"/>.
/// </summary>
/// <remarks>
/// The destructive behavior is a design choice for performance reasons.
/// In a typical use case the contents of <paramref name="sourceVectors"/> are abandoned after the conversion.
/// </remarks>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination colors.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the conversion</param>
internal virtual void FromVector4(
internal virtual void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<TPixel> destPixels,
@ -43,13 +47,17 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.
/// TODO: Rename to DestructiveFromVector4() + add explain behavior
/// The method is DESTRUCTIVE altering the contents of <paramref name="sourceVectors"/>.
/// </summary>
/// <remarks>
/// The destructive behavior is a design choice for performance reasons.
/// In a typical use case the contents of <paramref name="sourceVectors"/> are abandoned after the conversion.
/// </remarks>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination colors.</param>
internal void FromVector4(Configuration configuration, Span<Vector4> sourceVectors, Span<TPixel> destPixels) =>
this.FromVector4(configuration, sourceVectors, destPixels, PixelConversionModifiers.None);
internal void FromVector4Destructive(Configuration configuration, Span<Vector4> sourceVectors, Span<TPixel> destPixels) =>
this.FromVector4Destructive(configuration, sourceVectors, destPixels, PixelConversionModifiers.None);
/// <summary>
/// Bulk version of <see cref="IPixel.ToVector4()"/> converting 'sourceColors.Length' pixels into 'destinationVectors'.

2
src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs

@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
}
/// <summary>
/// Provides an efficient default implementation for <see cref="PixelOperations{TPixel}.FromVector4(SixLabors.ImageSharp.Configuration,System.Span{System.Numerics.Vector4},System.Span{TPixel},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
/// Provides an efficient default implementation for <see cref="PixelOperations{TPixel}.FromVector4Destructive(SixLabors.ImageSharp.Configuration,System.Span{System.Numerics.Vector4},System.Span{TPixel},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
/// The method is works by internally converting to a <see cref="Rgba32"/> therefore it's not applicable for that type!
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]

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

@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
DenseMatrixUtils.Convolve2D(in matrixY, in matrixX, source.PixelBuffer, vectorSpan, y, x, maxY, maxX, startX);
}
PixelOperations<TPixel>.Instance.FromVector4(configuration, vectorSpan.Slice(0, length), targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan.Slice(0, length), targetRowSpan);
}
});

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

@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
DenseMatrixUtils.Convolve(in matrix, sourcePixels, vectorSpan, y, x, maxY, maxX, startX);
}
PixelOperations<TPixel>.Instance.FromVector4(configuration, vectorSpan.Slice(0, length), targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan.Slice(0, length), targetRowSpan);
}
});
}

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

@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
DenseMatrixUtils.Convolve(in matrix, source.PixelBuffer, vectorSpan, y, x, maxY, maxX, startX);
}
PixelOperations<TPixel>.Instance.FromVector4(configuration, vectorSpan.Slice(0, length), targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan.Slice(0, length), targetRowSpan);
}
});

2
src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
Vector4Utils.Transform(vectorSpan, ref matrix);
PixelOperations<TPixel>.Instance.FromVector4(configuration, vectorSpan, rowSpan);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, rowSpan);
}
});
}

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

@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
kernel.Convolve(point, x, ref ySpanRef, ref xSpanRef, source.PixelBuffer, vectorSpan);
}
PixelOperations<TPixel>.Instance.FromVector4(configuration, vectorSpan, targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, targetRowSpan);
}
});
}

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

@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
kernel.Convolve(point, x, ref ySpanRef, ref xSpanRef, source.PixelBuffer, vectorSpan);
}
PixelOperations<TPixel>.Instance.FromVector4(configuration, vectorSpan, targetRowSpan);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, vectorSpan, targetRowSpan);
}
});
}

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor.cs

@ -301,7 +301,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
Span<TPixel> targetRowSpan = destination.GetPixelRowSpan(y);
PixelOperations<TPixel>.Instance.FromVector4(configuration, tempRowSpan, targetRowSpan, conversionModifiers);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, tempRowSpan, targetRowSpan, conversionModifiers);
}
});
}

4
tests/ImageSharp.Benchmarks/Color/Bulk/FromVector4.cs

@ -61,13 +61,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk
[Benchmark]
public void PixelOperations_Base()
{
new PixelOperations<TPixel>().FromVector4(this.Configuration, this.source.GetSpan(), this.destination.GetSpan());
new PixelOperations<TPixel>().FromVector4Destructive(this.Configuration, this.source.GetSpan(), this.destination.GetSpan());
}
[Benchmark]
public void PixelOperations_Specialized()
{
PixelOperations<TPixel>.Instance.FromVector4(this.Configuration, this.source.GetSpan(), this.destination.GetSpan());
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.Configuration, this.source.GetSpan(), this.destination.GetSpan());
}
}

2
tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs

@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Benchmarks
destinationSpan[i] = PorterDuffFunctions.NormalSrcOver(backgroundSpan[i], sourceSpan[i], amount[i]);
}
PixelOperations<TPixel>.Instance.FromVector4(this.Configuration, destinationSpan, destination);
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.Configuration, destinationSpan, destination);
}
}

12
tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs

@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
TestOperation(
source,
expected,
(s, d) => Operations.FromVector4(this.Configuration, s, d.GetSpan())
(s, d) => Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan())
);
}
@ -129,7 +129,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
(s, d) =>
{
Span<TPixel> destPixels = d.GetSpan();
Operations.FromVector4(this.Configuration, (Span<Vector4>)s, destPixels, PixelConversionModifiers.Scale);
Operations.FromVector4Destructive(this.Configuration, (Span<Vector4>)s, destPixels, PixelConversionModifiers.Scale);
});
}
@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
TestOperation(
source,
expected,
(s, d) => Operations.FromVector4(
(s, d) => Operations.FromVector4Destructive(
this.Configuration,
s,
d.GetSpan(),
@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
TestOperation(
source,
expected,
(s, d) => Operations.FromVector4(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)
(s, d) => Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)
);
}
@ -217,7 +217,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
TestOperation(
source,
expected,
(s, d) => Operations.FromVector4(
(s, d) => Operations.FromVector4Destructive(
this.Configuration,
s,
d.GetSpan(),
@ -255,7 +255,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
TestOperation(
source,
expected,
(s, d) => Operations.FromVector4(
(s, d) => Operations.FromVector4Destructive(
this.Configuration,
s,
d.GetSpan(),

2
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests
v.W = 1F;
}
PixelOperations<TPixel>.Instance.FromVector4(configuration, tempSpan, pixelSpan, PixelConversionModifiers.Scale);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, tempSpan, pixelSpan, PixelConversionModifiers.Scale);
}
}
});

Loading…
Cancel
Save