Browse Source

review cleanup

pull/475/head
Anton Firszov 8 years ago
parent
commit
c07cbeaa6f
  1. 28
      src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
  2. 6
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  3. 4
      src/ImageSharp/Formats/Jpeg/Common/Block8x8F.CopyTo.cs
  4. 2
      src/ImageSharp/Memory/BufferArea{T}.cs

28
src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs

@ -89,28 +89,20 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <inheritdoc /> /// <inheritdoc />
internal override void Apply(Span<float> scanline, int x, int y) internal override void Apply(Span<float> scanline, int x, int y)
{ {
try Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
{
Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
MemoryManager memoryManager = this.Target.MemoryManager;
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length)) MemoryManager memoryManager = this.Target.MemoryManager;
{
Span<float> amountSpan = amountBuffer.Span;
for (int i = 0; i < scanline.Length; i++) using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
{ {
amountSpan[i] = scanline[i] * this.Options.BlendPercentage; Span<float> amountSpan = amountBuffer.Span;
}
this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan); for (int i = 0; i < scanline.Length; i++)
{
amountSpan[i] = scanline[i] * this.Options.BlendPercentage;
} }
}
catch (Exception) this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan);
{
// TODO: Why are we catching exceptions here silently ???
throw;
} }
} }
} }

6
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -224,7 +224,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
var color = default(TPixel); var color = default(TPixel);
var rgba = new Rgba32(0, 0, 0, 255); var rgba = new Rgba32(0, 0, 0, 255);
using (var buffer = this.configuration.MemoryManager.Allocate2D<byte>(width, height, true)) using (var buffer = this.memoryManager.AllocateClean2D<byte>(width, height))
{ {
this.UncompressRle8(width, buffer.Span); this.UncompressRle8(width, buffer.Span);
@ -346,7 +346,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
padding = 4 - padding; padding = 4 - padding;
} }
using (IManagedByteBuffer row = this.configuration.MemoryManager.AllocateManagedByteBuffer(arrayWidth + padding, true)) using (IManagedByteBuffer row = this.memoryManager.AllocateCleanManagedByteBuffer(arrayWidth + padding))
{ {
var color = default(TPixel); var color = default(TPixel);
var rgba = new Rgba32(0, 0, 0, 255); var rgba = new Rgba32(0, 0, 0, 255);
@ -398,7 +398,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
var color = default(TPixel); var color = default(TPixel);
var rgba = new Rgba32(0, 0, 0, 255); var rgba = new Rgba32(0, 0, 0, 255);
using (var buffer = this.configuration.MemoryManager.AllocateManagedByteBuffer(stride)) using (var buffer = this.memoryManager.AllocateManagedByteBuffer(stride))
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {

4
src/ImageSharp/Formats/Jpeg/Common/Block8x8F.CopyTo.cs

@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
public void CopyTo(BufferArea<float> area) public void CopyTo(BufferArea<float> area)
{ {
ref byte selfBase = ref Unsafe.As<Block8x8F, byte>(ref this); ref byte selfBase = ref Unsafe.As<Block8x8F, byte>(ref this);
ref byte destBase = ref Unsafe.As<float, byte>(ref area.GetReferenceToOrigo()); ref byte destBase = ref Unsafe.As<float, byte>(ref area.GetReferenceToOrigin());
int destStride = area.Stride * sizeof(float); int destStride = area.Stride * sizeof(float);
CopyRowImpl(ref selfBase, ref destBase, destStride, 0); CopyRowImpl(ref selfBase, ref destBase, destStride, 0);
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
private void CopyTo2x2(BufferArea<float> area) private void CopyTo2x2(BufferArea<float> area)
{ {
ref float destBase = ref area.GetReferenceToOrigo(); ref float destBase = ref area.GetReferenceToOrigin();
int destStride = area.Stride; int destStride = area.Stride;
this.WidenCopyImpl2x2(ref destBase, 0, destStride); this.WidenCopyImpl2x2(ref destBase, 0, destStride);

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

@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Memory
/// </summary> /// </summary>
/// <returns>The reference to the [0,0] element</returns> /// <returns>The reference to the [0,0] element</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T GetReferenceToOrigo() => public ref T GetReferenceToOrigin() =>
ref this.DestinationBuffer.Span[(this.Rectangle.Y * this.DestinationBuffer.Width) + this.Rectangle.X]; ref this.DestinationBuffer.Span[(this.Rectangle.Y * this.DestinationBuffer.Width) + this.Rectangle.X];
/// <summary> /// <summary>

Loading…
Cancel
Save