Browse Source

Use using declarations to reduce nesting

af/octree-no-pixelmap
Brian Popow 7 years ago
parent
commit
c4e5796158
  1. 9
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

9
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

@ -5,7 +5,6 @@ using System;
using System.Buffers; using System.Buffers;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Advanced.ParallelUtils; using SixLabors.ImageSharp.Advanced.ParallelUtils;
@ -58,8 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
Configuration configuration = this.Configuration; Configuration configuration = this.Configuration;
using (Buffer2D<TPixel> targetPixels = this.Configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size())) using Buffer2D<TPixel> targetPixels = this.Configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size());
{
source.CopyTo(targetPixels); source.CopyTo(targetPixels);
var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY); var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY);
@ -69,8 +67,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
(rows) => (rows) =>
{ {
// Rent the shared buffer only once per parallel item. // Rent the shared buffer only once per parallel item.
using (IMemoryOwner<float> bins = configuration.MemoryAllocator.Allocate<float>(levels * 4)) using IMemoryOwner<float> bins = configuration.MemoryAllocator.Allocate<float>(levels * 4);
{
ref float binsRef = ref bins.GetReference(); ref float binsRef = ref bins.GetReference();
ref int intensityBinRef = ref Unsafe.As<float, int>(ref binsRef); ref int intensityBinRef = ref Unsafe.As<float, int>(ref binsRef);
ref float redBinRef = ref Unsafe.Add(ref binsRef, levels); ref float redBinRef = ref Unsafe.Add(ref binsRef, levels);
@ -135,11 +132,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
} }
} }
} }
}
}); });
Buffer2D<TPixel>.SwapOrCopyContent(source.PixelBuffer, targetPixels); Buffer2D<TPixel>.SwapOrCopyContent(source.PixelBuffer, targetPixels);
} }
} }
} }
}

Loading…
Cancel
Save