diff --git a/src/ImageSharp46/Formats/Jpg/Components/Block.cs b/src/ImageSharp46/Formats/Jpg/Components/Block.cs index e0be19206..ca9d15883 100644 --- a/src/ImageSharp46/Formats/Jpg/Components/Block.cs +++ b/src/ImageSharp46/Formats/Jpg/Components/Block.cs @@ -13,7 +13,7 @@ namespace ImageSharp.Formats /// internal struct Block : IDisposable { - private static ArrayPool IntArrayPool => ArrayPool.Shared; /*= ArrayPool.Create(BlockSize, 50);*/ + private static ArrayPool IntArrayPool = ArrayPool.Create(BlockSize, 50); /// /// Gets the size of the block. @@ -88,5 +88,15 @@ namespace ImageSharp.Formats blocks[i].Dispose(); } } + + + public void Clear() + { + for (int i = 0; i < Data.Length; i++) + { + Data[i] = 0; + } + } + } } diff --git a/src/ImageSharp46/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp46/Formats/Jpg/JpegDecoderCore.cs index 181211f4d..e5191069a 100644 --- a/src/ImageSharp46/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp46/Formats/Jpg/JpegDecoderCore.cs @@ -1469,6 +1469,8 @@ namespace ImageSharp.Formats } } + private Block scanWorkerBlock = Block.Create(); + /// /// Processes the SOS (Start of scan marker). /// @@ -1668,13 +1670,14 @@ namespace ImageSharp.Formats } else { - var b = Block.Create(); + //var b = Block.Create(); + scanWorkerBlock.Clear(); - ProcessBlockImpl(ah, ref b, scan, i, zigStart, zigEnd, al, dc, compIndex, @by, mxx, hi, + ProcessBlockImpl(ah, ref scanWorkerBlock, scan, i, zigStart, zigEnd, al, dc, compIndex, @by, mxx, hi, bx, ref this.quantizationTables[qtIndex] ); - b.Dispose(); + //b.Dispose(); } } @@ -1792,6 +1795,9 @@ namespace ImageSharp.Formats if (zigEnd != Block.BlockSize - 1 || al != 0) { // We haven't completely decoded this 8x8 block. Save the coefficients. + + // TODO: This should be broken when isProgressive == true + this.progCoeffs[compIndex][((@by*mxx)*hi) + bx] = b; // At this point, we could execute the rest of the loop body to dequantize and @@ -2257,6 +2263,7 @@ namespace ImageSharp.Formats public void Dispose() { + scanWorkerBlock.Dispose(); Block.DisposeAll(this.quantizationTables); foreach (Block[] blocks in progCoeffs)