11// Copyright (c) Six Labors.
22// Licensed under the Six Labors Split License.
33
4+ using System . Buffers ;
45using System . Buffers . Binary ;
56using System . Diagnostics . CodeAnalysis ;
67using System . Runtime . CompilerServices ;
@@ -24,11 +25,6 @@ internal class QoiDecoderCore : IImageDecoderInternals
2425 /// </summary>
2526 private readonly MemoryAllocator memoryAllocator ;
2627
27- /// <summary>
28- /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded.
29- /// </summary>
30- private readonly bool skipMetadata ;
31-
3228 /// <summary>
3329 /// The QOI header.
3430 /// </summary>
@@ -38,7 +34,6 @@ public QoiDecoderCore(DecoderOptions options)
3834 {
3935 this . Options = options ;
4036 this . configuration = options . Configuration ;
41- this . skipMetadata = options . SkipMetadata ;
4237 this . memoryAllocator = this . configuration . MemoryAllocator ;
4338 }
4439
@@ -149,7 +144,9 @@ private static void ThrowInvalidImageContentException()
149144 private void ProcessPixels < TPixel > ( BufferedReadStream stream , Buffer2D < TPixel > pixels )
150145 where TPixel : unmanaged, IPixel < TPixel >
151146 {
152- Rgba32 [ ] previouslySeenPixels = new Rgba32 [ 64 ] ;
147+ using IMemoryOwner < Rgba32 > previouslySeenPixelsBuffer = this . memoryAllocator . Allocate < Rgba32 > ( 64 , AllocationOptions . Clean ) ;
148+ Span < Rgba32 > previouslySeenPixels = previouslySeenPixelsBuffer . GetSpan ( ) ;
149+ //Rgba32[] previouslySeenPixels = new Rgba32[64];
153150 Rgba32 previousPixel = new ( 0 , 0 , 0 , 255 ) ;
154151
155152 // We save the pixel to avoid loosing the fully opaque black pixel
@@ -163,9 +160,9 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
163160
164161 for ( int i = 0 ; i < this . header . Height ; i ++ )
165162 {
166- for ( int j = 0 ; j < this . header . Width ; j ++ )
163+ Span < TPixel > row = pixels . DangerousGetRowSpan ( i ) ;
164+ for ( int j = 0 ; j < row . Length ; j ++ )
167165 {
168- Span < TPixel > row = pixels . DangerousGetRowSpan ( i ) ;
169166 operationByte = ( byte ) stream . ReadByte ( ) ;
170167 switch ( ( QoiChunk ) operationByte )
171168 {
@@ -247,7 +244,7 @@ private void ProcessPixels<TPixel>(BufferedReadStream stream, Buffer2D<TPixel> p
247244 pixel . FromRgba32 ( readPixel ) ;
248245 for ( int k = - 1 ; k < repetitions ; k ++ , j ++ )
249246 {
250- if ( j == this . header . Width )
247+ if ( j == row . Length )
251248 {
252249 j = 0 ;
253250 i ++ ;
0 commit comments