Browse Source

single Block for the non-progressive branch

pull/34/head
Anton Firszov 9 years ago
parent
commit
7626c67480
  1. 12
      src/ImageSharp46/Formats/Jpg/Components/Block.cs
  2. 13
      src/ImageSharp46/Formats/Jpg/JpegDecoderCore.cs

12
src/ImageSharp46/Formats/Jpg/Components/Block.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
internal struct Block : IDisposable internal struct Block : IDisposable
{ {
private static ArrayPool<int> IntArrayPool => ArrayPool<int>.Shared; /*= ArrayPool<int>.Create(BlockSize, 50);*/ private static ArrayPool<int> IntArrayPool = ArrayPool<int>.Create(BlockSize, 50);
/// <summary> /// <summary>
/// Gets the size of the block. /// Gets the size of the block.
@ -88,5 +88,15 @@ namespace ImageSharp.Formats
blocks[i].Dispose(); blocks[i].Dispose();
} }
} }
public void Clear()
{
for (int i = 0; i < Data.Length; i++)
{
Data[i] = 0;
}
}
} }
} }

13
src/ImageSharp46/Formats/Jpg/JpegDecoderCore.cs

@ -1469,6 +1469,8 @@ namespace ImageSharp.Formats
} }
} }
private Block scanWorkerBlock = Block.Create();
/// <summary> /// <summary>
/// Processes the SOS (Start of scan marker). /// Processes the SOS (Start of scan marker).
/// </summary> /// </summary>
@ -1668,13 +1670,14 @@ namespace ImageSharp.Formats
} }
else 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] bx, ref this.quantizationTables[qtIndex]
); );
b.Dispose(); //b.Dispose();
} }
} }
@ -1792,6 +1795,9 @@ namespace ImageSharp.Formats
if (zigEnd != Block.BlockSize - 1 || al != 0) if (zigEnd != Block.BlockSize - 1 || al != 0)
{ {
// We haven't completely decoded this 8x8 block. Save the coefficients. // 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; this.progCoeffs[compIndex][((@by*mxx)*hi) + bx] = b;
// At this point, we could execute the rest of the loop body to dequantize and // 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() public void Dispose()
{ {
scanWorkerBlock.Dispose();
Block.DisposeAll(this.quantizationTables); Block.DisposeAll(this.quantizationTables);
foreach (Block[] blocks in progCoeffs) foreach (Block[] blocks in progCoeffs)

Loading…
Cancel
Save