Browse Source

Inlining temporary compatibility methods (FromScaledVector4, ToScaledVector4)

af/merge-core
Anton Firszov 7 years ago
parent
commit
fd3d76e78e
  1. 36
      src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs
  2. 15
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  3. 8
      src/ImageSharp/PixelFormats/Utils/Vector4Converters.RgbaCompatible.cs
  4. 2
      src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs
  5. 2
      src/ImageSharp/Processing/Processors/Quantization/FrameQuantizerBase{TPixel}.cs
  6. 14
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
  7. 4
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

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

@ -112,21 +112,15 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
PixelOperations<TPixel>.Instance.ToScaledVector4( ReadOnlySpan<TPixel> sourcePixels = background.Slice(0, background.Length);
configuration, PixelOperations<TPixel>.Instance.ToVector4(configuration, sourcePixels, backgroundSpan, PixelConversionModifiers.Scale);
background.Slice(0, background.Length), ReadOnlySpan<TPixelSrc> sourcePixels1 = source.Slice(0, background.Length);
backgroundSpan); PixelOperations<TPixelSrc>.Instance.ToVector4(configuration, sourcePixels1, sourceSpan, PixelConversionModifiers.Scale);
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(
configuration,
source.Slice(0, background.Length),
sourceSpan);
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount); this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount);
PixelOperations<TPixel>.Instance.FromScaledVector4( Span<Vector4> sourceVectors = destinationSpan.Slice(0, background.Length);
configuration, PixelOperations<TPixel>.Instance.FromVector4(configuration, sourceVectors, destination, PixelConversionModifiers.Scale);
destinationSpan.Slice(0, background.Length),
destination);
} }
} }
@ -161,21 +155,15 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length); Span<Vector4> backgroundSpan = buffer.Slice(destination.Length, destination.Length);
Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); Span<Vector4> sourceSpan = buffer.Slice(destination.Length * 2, destination.Length);
PixelOperations<TPixel>.Instance.ToScaledVector4( ReadOnlySpan<TPixel> sourcePixels = background.Slice(0, background.Length);
configuration, PixelOperations<TPixel>.Instance.ToVector4(configuration, sourcePixels, backgroundSpan, PixelConversionModifiers.Scale);
background.Slice(0, background.Length), ReadOnlySpan<TPixelSrc> sourcePixels1 = source.Slice(0, background.Length);
backgroundSpan); PixelOperations<TPixelSrc>.Instance.ToVector4(configuration, sourcePixels1, sourceSpan, PixelConversionModifiers.Scale);
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(
configuration,
source.Slice(0, background.Length),
sourceSpan);
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount); this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount);
PixelOperations<TPixel>.Instance.FromScaledVector4( Span<Vector4> sourceVectors = destinationSpan.Slice(0, background.Length);
configuration, PixelOperations<TPixel>.Instance.FromVector4(configuration, sourceVectors, destination, PixelConversionModifiers.Scale);
destinationSpan.Slice(0, background.Length),
destination);
} }
} }
} }

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

@ -41,15 +41,6 @@ namespace SixLabors.ImageSharp.PixelFormats
Utils.Vector4Converters.Default.FromVector4(sourceVectors, destPixels, modifiers); Utils.Vector4Converters.Default.FromVector4(sourceVectors, destPixels, modifiers);
} }
/// <summary>
/// TODO: For compatibility, should be inlined!
/// </summary>
internal void FromScaledVector4(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<TPixel> destPixels) =>
this.FromVector4(configuration, sourceVectors, destPixels, PixelConversionModifiers.Scale);
/// <summary> /// <summary>
/// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'. /// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.
/// TODO: Rename to DestructiveFromVector4() + add explain behavior /// TODO: Rename to DestructiveFromVector4() + add explain behavior
@ -90,12 +81,6 @@ namespace SixLabors.ImageSharp.PixelFormats
Span<Vector4> destVectors) => Span<Vector4> destVectors) =>
this.ToVector4(configuration, sourcePixels, destVectors, PixelConversionModifiers.None); this.ToVector4(configuration, sourcePixels, destVectors, PixelConversionModifiers.None);
/// <summary>
/// TODO: For compatibility, should be inlined!
/// </summary>
internal void ToScaledVector4(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Vector4> destVectors) =>
this.ToVector4(configuration, sourcePixels, destVectors, PixelConversionModifiers.Scale);
/// <summary> /// <summary>
/// Converts 'sourceColors.Length' pixels from 'sourceColors' into 'destinationColors'. /// Converts 'sourceColors.Length' pixels from 'sourceColors' into 'destinationColors'.
/// </summary> /// </summary>

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

@ -32,10 +32,7 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
/// <summary> /// <summary>
/// Provides an efficient default implementation for <see cref="PixelOperations{TPixel}.ToVector4(SixLabors.ImageSharp.Configuration,System.ReadOnlySpan{TPixel},System.Span{System.Numerics.Vector4},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/> /// Provides an efficient default implementation for <see cref="PixelOperations{TPixel}.ToVector4(SixLabors.ImageSharp.Configuration,System.ReadOnlySpan{TPixel},System.Span{System.Numerics.Vector4},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
/// and <see cref="PixelOperations{TPixel}.ToScaledVector4"/> /// The method works by internally converting to a <see cref="Rgba32"/> therefore it's not applicable for that type!
/// which is applicable for <see cref="Rgba32"/>-compatible pixel types where <see cref="IPixel.ToVector4"/>
/// returns the same scaled result as <see cref="IPixel.ToScaledVector4"/>.
/// The method is works by internally converting to a <see cref="Rgba32"/> therefore it's not applicable for that type!
/// </summary> /// </summary>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
internal static void ToVector4<TPixel>( internal static void ToVector4<TPixel>(
@ -79,9 +76,6 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
/// <summary> /// <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}.FromVector4(SixLabors.ImageSharp.Configuration,System.Span{System.Numerics.Vector4},System.Span{TPixel},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
/// and <see cref="PixelOperations{TPixel}.FromScaledVector4"/>
/// which is applicable for <see cref="Rgba32"/>-compatible pixel types where <see cref="IPixel.ToVector4"/>
/// returns the same scaled result as <see cref="IPixel.ToScaledVector4"/>.
/// The method is works by internally converting to a <see cref="Rgba32"/> therefore it's not applicable for that type! /// The method is works by internally converting to a <see cref="Rgba32"/> therefore it's not applicable for that type!
/// </summary> /// </summary>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

2
src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs

@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
if (this.paletteVector is null) if (this.paletteVector is null)
{ {
this.paletteVector = new Vector4[this.Palette.Length]; this.paletteVector = new Vector4[this.Palette.Length];
PixelOperations<TPixel>.Instance.ToScaledVector4(configuration, this.Palette, this.paletteVector); PixelOperations<TPixel>.Instance.ToVector4(configuration, (ReadOnlySpan<TPixel>)this.Palette, (Span<Vector4>)this.paletteVector, PixelConversionModifiers.Scale);
} }
} }
} }

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

@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
// Collect the palette. Required before the second pass runs. // Collect the palette. Required before the second pass runs.
TPixel[] palette = this.GetPalette(); TPixel[] palette = this.GetPalette();
this.paletteVector = new Vector4[palette.Length]; this.paletteVector = new Vector4[palette.Length];
PixelOperations<TPixel>.Instance.ToScaledVector4(image.Configuration, palette, this.paletteVector); PixelOperations<TPixel>.Instance.ToVector4(image.Configuration, (ReadOnlySpan<TPixel>)palette, (Span<Vector4>)this.paletteVector, PixelConversionModifiers.Scale);
var quantizedFrame = new QuantizedFrame<TPixel>(image.MemoryAllocator, width, height, palette); var quantizedFrame = new QuantizedFrame<TPixel>(image.MemoryAllocator, width, height, palette);
if (this.Dither) if (this.Dither)

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

@ -124,8 +124,11 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.FromScaledVector4(this.Configuration, s, d.GetSpan()) (s, d) =>
); {
Span<TPixel> destPixels = d.GetSpan();
Operations.FromVector4(this.Configuration, (Span<Vector4>)s, destPixels, PixelConversionModifiers.Scale);
});
} }
[Theory] [Theory]
@ -262,8 +265,11 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToScaledVector4(this.Configuration, s, d.GetSpan()) (s, d) =>
); {
Span<Vector4> destVectors = d.GetSpan();
Operations.ToVector4(this.Configuration, (ReadOnlySpan<TPixel>)s, destVectors, PixelConversionModifiers.Scale);
});
} }
[Theory] [Theory]

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

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
Span<TPixel> pixelSpan = frame.GetPixelSpan(); Span<TPixel> pixelSpan = frame.GetPixelSpan();
PixelOperations<TPixel>.Instance.ToScaledVector4(configuration, pixelSpan, tempSpan); PixelOperations<TPixel>.Instance.ToVector4(configuration, pixelSpan, tempSpan, PixelConversionModifiers.Scale);
for (int i = 0; i < tempSpan.Length; i++) for (int i = 0; i < tempSpan.Length; i++)
{ {
@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests
v.W = 1F; v.W = 1F;
} }
PixelOperations<TPixel>.Instance.FromScaledVector4(configuration, tempSpan, pixelSpan); PixelOperations<TPixel>.Instance.FromVector4(configuration, tempSpan, pixelSpan, PixelConversionModifiers.Scale);
} }
} }
}); });

Loading…
Cancel
Save