Skip to content

Commit

Permalink
Merge pull request #1465 from SixLabors/js/convolution-experiments
Browse files Browse the repository at this point in the history
Optimize Convolution
  • Loading branch information
JimBobSquarePants authored Dec 10, 2020
2 parents 3d3537e + 6ab7be3 commit 943830f
Show file tree
Hide file tree
Showing 15 changed files with 804 additions and 504 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@
*.pvr binary
*.snk binary
*.tga binary
*.tif binary
*.tiff binary
*.ttc binary
*.ttf binary
*.wbmp binary
*.webp binary
*.woff binary
*.woff2 binary
Expand Down
279 changes: 0 additions & 279 deletions src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ public override Span<T> GetSpan()
{
ThrowObjectDisposedException();
}

#if SUPPORTS_CREATESPAN
ref byte r0 = ref MemoryMarshal.GetReference<byte>(this.Data);
return MemoryMarshal.CreateSpan(ref Unsafe.As<byte, T>(ref r0), this.length);
#else
return MemoryMarshal.Cast<byte, T>(this.Data.AsSpan()).Slice(0, this.length);
#endif

}

/// <inheritdoc />
Expand Down
16 changes: 8 additions & 8 deletions src/ImageSharp/Primitives/DenseMatrix{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public DenseMatrix(T[,] data)
/// <returns>The <see typeparam="T"/> at the specified position.</returns>
public ref T this[int row, int column]
{
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
this.CheckCoordinates(row, column);
Expand All @@ -124,7 +124,7 @@ public DenseMatrix(T[,] data)
/// <returns>
/// The <see cref="DenseMatrix{T}"/> representation on the source data.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator DenseMatrix<T>(T[,] data) => new DenseMatrix<T>(data);

/// <summary>
Expand All @@ -134,7 +134,7 @@ public DenseMatrix(T[,] data)
/// <returns>
/// The <see cref="T:T[,]"/> representation on the source data.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#pragma warning disable SA1008 // Opening parenthesis should be spaced correctly
public static implicit operator T[,](in DenseMatrix<T> data)
#pragma warning restore SA1008 // Opening parenthesis should be spaced correctly
Expand Down Expand Up @@ -175,7 +175,7 @@ public DenseMatrix(T[,] data)
/// Transposes the rows and columns of the dense matrix.
/// </summary>
/// <returns>The <see cref="DenseMatrix{T}"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DenseMatrix<T> Transpose()
{
var result = new DenseMatrix<T>(this.Rows, this.Columns);
Expand All @@ -196,13 +196,13 @@ public DenseMatrix<T> Transpose()
/// Fills the matrix with the given value
/// </summary>
/// <param name="value">The value to fill each item with</param>
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Fill(T value) => this.Span.Fill(value);

/// <summary>
/// Clears the matrix setting each value to the default value for the element type
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear() => this.Span.Clear();

/// <summary>
Expand Down Expand Up @@ -232,14 +232,14 @@ public override bool Equals(object obj)
=> obj is DenseMatrix<T> other && this.Equals(other);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(DenseMatrix<T> other) =>
this.Columns == other.Columns
&& this.Rows == other.Rows
&& this.Span.SequenceEqual(other.Span);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
HashCode code = default;
Expand Down
Loading

0 comments on commit 943830f

Please sign in to comment.