Browse Source

Optimize ColorMatrixProcessors

pull/221/head
James Jackson-South 9 years ago
parent
commit
05cbc60244
  1. 33
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs

33
src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs

@ -7,7 +7,6 @@ namespace ImageSharp.Processing.Processors
{ {
using System; using System;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.PixelFormats; using ImageSharp.PixelFormats;
@ -61,29 +60,12 @@ namespace ImageSharp.Processing.Processors
this.ParallelOptions, this.ParallelOptions,
y => y =>
{ {
int offsetY = y - startY; Span<TPixel> row = source.GetRowSpan(y - startY);
for (int x = minX; x < maxX; x++)
{
int offsetX = x - startX;
sourcePixels[offsetX, offsetY] = this.ApplyMatrix(sourcePixels[offsetX, offsetY], matrix, compand);
}
});
}
}
/// <summary> for (int x = minX; x < maxX; x++)
/// Applies the color matrix against the given color.
/// </summary>
/// <param name="color">The source color.</param>
/// <param name="matrix">The matrix.</param>
/// <param name="compand">Whether to compand the color during processing.</param>
/// <returns>
/// The <see cref="Rgba32"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private TPixel ApplyMatrix(TPixel color, Matrix4x4 matrix, bool compand)
{ {
Vector4 vector = color.ToVector4(); ref TPixel pixel = ref row[x - startX];
var vector = pixel.ToVector4();
if (compand) if (compand)
{ {
@ -91,9 +73,10 @@ namespace ImageSharp.Processing.Processors
} }
vector = Vector4.Transform(vector, matrix); vector = Vector4.Transform(vector, matrix);
TPixel packed = default(TPixel); pixel.PackFromVector4(compand ? vector.Compress() : vector);
packed.PackFromVector4(compand ? vector.Compress() : vector); }
return packed; });
}
} }
} }
} }
Loading…
Cancel
Save