Browse Source

BufferArea optimizations

pull/1143/head
Anton Firszov 6 years ago
parent
commit
1f2894af80
  1. 18
      src/ImageSharp/Memory/BufferArea{T}.cs

18
src/ImageSharp/Memory/BufferArea{T}.cs

@ -79,8 +79,12 @@ namespace SixLabors.ImageSharp.Memory
/// </summary>
/// <returns>The reference to the [0,0] element</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T GetReferenceToOrigin() =>
ref this.GetRowSpan(0)[0];
public ref T GetReferenceToOrigin()
{
int y = this.Rectangle.Y;
int x = this.Rectangle.X;
return ref this.DestinationBuffer.GetRowSpan(y)[x];
}
/// <summary>
/// Gets a span to row 'y' inside this area.
@ -90,11 +94,11 @@ namespace SixLabors.ImageSharp.Memory
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> GetRowSpan(int y)
{
int yy = this.GetRowIndex(y);
int yy = this.Rectangle.Y + y;
int xx = this.Rectangle.X;
int width = this.Rectangle.Width;
return this.DestinationBuffer.FastMemoryGroup.GetBoundedSlice(yy + xx, width).Span;
return this.DestinationBuffer.GetRowSpan(yy).Slice(xx, width);
}
/// <summary>
@ -129,12 +133,6 @@ namespace SixLabors.ImageSharp.Memory
return new BufferArea<T>(this.DestinationBuffer, rectangle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal int GetRowIndex(int y)
{
return (y + this.Rectangle.Y) * this.DestinationBuffer.Width;
}
public void Clear()
{
// Optimization for when the size of the area is the same as the buffer size.

Loading…
Cancel
Save