Browse Source

[WIP] outer scope memory propagation

pull/1926/head
Dmitry Pentin 4 years ago
parent
commit
e7ee0fdac4
  1. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  2. 9
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs
  3. 3
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs

@ -728,10 +728,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <param name="codeLengths">Code lengths.</param> /// <param name="codeLengths">Code lengths.</param>
/// <param name="values">Code values.</param> /// <param name="values">Code values.</param>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void BuildHuffmanTable(int type, int index, ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values) public void BuildHuffmanTable(int type, int index, ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values, Span<uint> workspace)
{ {
HuffmanTable[] tables = type == 0 ? this.dcHuffmanTables : this.acHuffmanTables; HuffmanTable[] tables = type == 0 ? this.dcHuffmanTables : this.acHuffmanTables;
tables[index] = new HuffmanTable(codeLengths, values); tables[index] = new HuffmanTable(codeLengths, values, workspace);
} }
} }
} }

9
src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanTable.cs

@ -51,13 +51,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HuffmanTable"/> struct. /// Initializes a new instance of the <see cref="HuffmanTable"/> struct.
/// </summary> /// </summary>
/// <param name="codeLengths">The code lengths</param> /// <param name="codeLengths">The code lengths.</param>
/// <param name="values">The huffman values</param> /// <param name="values">The huffman values.</param>
public HuffmanTable(ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values) /// <param name="workspace">The spare workspace memory, must be provided by the caller.</param>
public HuffmanTable(ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values, Span<uint> workspace)
{ {
Unsafe.CopyBlockUnaligned(ref this.Values[0], ref MemoryMarshal.GetReference(values), (uint)values.Length); Unsafe.CopyBlockUnaligned(ref this.Values[0], ref MemoryMarshal.GetReference(values), (uint)values.Length);
Span<uint> huffCode = stackalloc uint[257]; Span<uint> huffCode = workspace;
// Generate codes // Generate codes
uint code = 0; uint code = 0;

3
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -1150,7 +1150,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
tableType, tableType,
tableIndex, tableIndex,
codeLengthsSpan, codeLengthsSpan,
huffmanValuesSpan); huffmanValuesSpan,
stackalloc uint[257]);
} }
} }
} }

Loading…
Cancel
Save