diff --git a/Domain/ImageCreators/ImageCreator.cs b/Domain/ImageCreators/ImageCreator.cs index d634c4d..7858389 100644 --- a/Domain/ImageCreators/ImageCreator.cs +++ b/Domain/ImageCreators/ImageCreator.cs @@ -1,4 +1,3 @@ -using System.Buffers; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; using StitchATon2.Infra; @@ -7,7 +6,7 @@ using StitchATon2.Infra.Encoders; namespace StitchATon2.Domain.ImageCreators; -public class ImageCreator +public class ImageCreator : IDisposable { private readonly GridSection _section; @@ -29,12 +28,12 @@ public class ImageCreator private TileManager TileManager => _section.TileManager; - private readonly Int32Pixel[] _mmfReadBuffer; + private readonly ArrayOwner _mmfReadBuffer; public ImageCreator(GridSection section) { _section = section; - _mmfReadBuffer = ArrayPool.Shared.Rent(TileWidth); + _mmfReadBuffer = MemoryAllocator.AllocateArray(TileWidth); } public async Task WriteToStream(Stream writableStream, float scale) @@ -109,7 +108,7 @@ public class ImageCreator var written = 0; while (true) { - currentTile.Integral.Acquire(yOffset, _mmfReadBuffer); + currentTile.Integral.Acquire(yOffset, _mmfReadBuffer.Array); int localX; while (written < sourceMap.Length && (localX = sourceMap[written] - xOffset) < TileWidth) { @@ -135,7 +134,7 @@ public class ImageCreator var written = 0; while (true) { - currentTile.Integral.Acquire(yOffset, _mmfReadBuffer); + currentTile.Integral.Acquire(yOffset, _mmfReadBuffer.Array); int localX; while (written < sourceMap.Length && (localX = sourceMap[written] - xOffset) < TileWidth) { @@ -152,4 +151,10 @@ public class ImageCreator currentTile = TileManager.GetAdjacent(currentTile, 1, 0); } } + + public void Dispose() + { + _mmfReadBuffer.Dispose(); + GC.SuppressFinalize(this); + } } \ No newline at end of file