Browse Source

Revert ref extensions.

af/merge-core
James Jackson-South 8 years ago
parent
commit
448efb17fa
  1. 18
      src/ImageSharp/Common/Extensions/Vector4Extensions.cs
  2. 6
      src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs
  3. 3
      src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs
  4. 6
      src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs
  5. 5
      src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs

18
src/ImageSharp/Common/Extensions/Vector4Extensions.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp
/// <param name="source">The <see cref="Vector4"/> to premultiply</param>
/// <returns>The <see cref="Vector4"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 Premultiply(this ref Vector4 source)
public static Vector4 Premultiply(this Vector4 source)
{
float w = source.W;
Vector4 premultiplied = source * w;
@ -29,12 +29,12 @@ namespace SixLabors.ImageSharp
}
/// <summary>
/// Reverses the result of premultiplying a vector via <see cref="Premultiply(ref Vector4)"/>.
/// Reverses the result of premultiplying a vector via <see cref="Premultiply(Vector4)"/>.
/// </summary>
/// <param name="source">The <see cref="Vector4"/> to premultiply</param>
/// <returns>The <see cref="Vector4"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 UnPremultiply(this ref Vector4 source)
public static Vector4 UnPremultiply(this Vector4 source)
{
float w = source.W;
Vector4 unpremultiplied = source / w;
@ -50,10 +50,10 @@ namespace SixLabors.ImageSharp
/// <param name="linear">The <see cref="Vector4"/> whose signal to compress.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 Compress(this ref Vector4 linear)
public static Vector4 Compress(this Vector4 linear)
{
// TODO: Is there a faster way to do this?
return new Vector4(Compress(ref linear.X), Compress(ref linear.Y), Compress(ref linear.Z), linear.W);
return new Vector4(Compress(linear.X), Compress(linear.Y), Compress(linear.Z), linear.W);
}
/// <summary>
@ -64,10 +64,10 @@ namespace SixLabors.ImageSharp
/// <param name="gamma">The <see cref="Rgba32"/> whose signal to expand.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 Expand(this ref Vector4 gamma)
public static Vector4 Expand(this Vector4 gamma)
{
// TODO: Is there a faster way to do this?
return new Vector4(Expand(ref gamma.X), Expand(ref gamma.Y), Expand(ref gamma.Z), gamma.W);
return new Vector4(Expand(gamma.X), Expand(gamma.Y), Expand(gamma.Z), gamma.W);
}
/// <summary>
@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp
/// The <see cref="float"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float Compress(ref float signal)
private static float Compress(float signal)
{
if (signal <= 0.0031308F)
{
@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp
/// The <see cref="float"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float Expand(ref float signal)
private static float Expand(float signal)
{
if (signal <= 0.04045F)
{

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

@ -95,8 +95,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
int offsetX = x + fxr;
offsetX = offsetX.Clamp(0, maxX);
var currentColor = sourceOffsetRow[offsetX].ToVector4();
currentColor = currentColor.Premultiply();
Vector4 currentColor = sourceOffsetRow[offsetX].ToVector4().Premultiply();
if (fy < kernelXHeight)
{
@ -121,8 +120,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
float blue = MathF.Sqrt((bX * bX) + (bY * bY));
ref TPixel pixel = ref targetRow[x];
var result = new Vector4(red, green, blue, sourceRow[x].ToVector4().W);
pixel.PackFromVector4(result.UnPremultiply());
pixel.PackFromVector4(new Vector4(red, green, blue, sourceRow[x].ToVector4().W).UnPremultiply());
}
});

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

@ -110,8 +110,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
offsetX = offsetX.Clamp(0, maxX);
var currentColor = row[offsetX].ToVector4();
currentColor = currentColor.Premultiply();
Vector4 currentColor = row[offsetX].ToVector4().Premultiply();
destination += kernel[fy, fx] * currentColor;
}
}

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

@ -82,8 +82,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
offsetX = offsetX.Clamp(0, maxX);
var currentColor = sourceOffsetRow[offsetX].ToVector4();
currentColor = currentColor.Premultiply();
Vector4 currentColor = sourceOffsetRow[offsetX].ToVector4().Premultiply();
currentColor *= this.KernelXY[fy, fx];
red += currentColor.X;
@ -93,8 +92,7 @@ namespace SixLabors.ImageSharp.Processing.Convolution.Processors
}
ref TPixel pixel = ref targetRow[x];
var result = new Vector4(red, green, blue, sourceRow[x].ToVector4().W);
pixel.PackFromVector4(result.UnPremultiply());
pixel.PackFromVector4(new Vector4(red, green, blue, sourceRow[x].ToVector4().W).UnPremultiply());
}
});

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

@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <summary>
/// Computes the sum of vectors in 'rowSpan' weighted by weight values, pointed by this <see cref="WeightsWindow"/> instance.
/// Applies <see cref="Vector4Extensions.Expand(ref float)"/> to all input vectors.
/// Applies <see cref="Vector4Extensions.Expand(float)"/> to all input vectors.
/// </summary>
/// <param name="rowSpan">The input span of vectors</param>
/// <param name="sourceX">The source row position.</param>
@ -115,8 +115,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
float weight = Unsafe.Add(ref horizontalValues, i);
Vector4 v = Unsafe.Add(ref vecPtr, i);
v = v.Premultiply();
result += v.Expand() * weight;
result += v.Premultiply().Expand() * weight;
}
return result.UnPremultiply();

Loading…
Cancel
Save