diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs index 728da8d02e..e46994c32d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs @@ -4,7 +4,6 @@ // namespace ImageSharp.Formats.Jpg { - using System.Buffers; using System.Runtime.CompilerServices; /// @@ -15,20 +14,20 @@ namespace ImageSharp.Formats.Jpg /// /// Initializes a new instance of the struct from existing data. /// - /// The pixel array - /// The stride + /// The pixel buffer + /// The stride /// The offset - public JpegPixelArea(byte[] pixels, int striede, int offset) + public JpegPixelArea(Buffer2D pixels, int stride, int offset) { - this.Stride = striede; + this.Stride = stride; this.Pixels = pixels; this.Offset = offset; } /// - /// Gets the pixels. + /// Gets the pixels buffer. /// - public byte[] Pixels { get; private set; } + public Buffer2D Pixels { get; private set; } /// /// Gets a value indicating whether the instance has been initalized. (Is not default(JpegPixelArea)) @@ -36,21 +35,19 @@ namespace ImageSharp.Formats.Jpg public bool IsInitialized => this.Pixels != null; /// - /// Gets or the stride. + /// Gets the stride. /// public int Stride { get; } /// - /// Gets or the offset. + /// Gets the offset. /// public int Offset { get; } /// /// Gets a of bytes to the pixel area /// - public MutableSpan Span => new MutableSpan(this.Pixels, this.Offset); - - private static ArrayPool BytePool => ArrayPool.Shared; + public MutableSpan Span => new MutableSpan(this.Pixels.Array, this.Offset); /// /// Returns the pixel at (x, y) @@ -69,21 +66,16 @@ namespace ImageSharp.Formats.Jpg /// /// Creates a new instance of the struct. - /// Pixel array will be taken from a pool, this instance will be the owner of it's pixel data, therefore - /// should be called when the instance is no longer needed. + /// Pixel array will be handled by , but + /// can be called when the instance is no longer needed. /// /// The width. /// The height. /// A with pooled data - public static JpegPixelArea CreatePooled(int width, int height) - { - int size = width * height; - byte[] pixels = BytePool.Rent(size); - return new JpegPixelArea(pixels, width, 0); - } + public static JpegPixelArea CreatePooled(int width, int height) => new JpegPixelArea(Buffer2D.CreateClean(width, height), width, 0); /// - /// Returns to the pool + /// Dispose . /// public void ReturnPooled() { @@ -92,7 +84,7 @@ namespace ImageSharp.Formats.Jpg return; } - BytePool.Return(this.Pixels); + this.Pixels.Dispose(); this.Pixels = null; } @@ -129,7 +121,7 @@ namespace ImageSharp.Formats.Jpg public unsafe void LoadColorsFrom(Block8x8F* block, Block8x8F* temp) { // Level shift by +128, clip to [0, 255], and write to dst. - block->CopyColorsTo(new MutableSpan(this.Pixels, this.Offset), this.Stride, temp); + block->CopyColorsTo(new MutableSpan(this.Pixels.Array, this.Offset), this.Stride, temp); } } } \ No newline at end of file