Browse Source

Docs, faster span slice method

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

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

@ -13,6 +13,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct HuffmanTable
{
/// <summary>
/// Memory workspace buffer size used in <see cref="HuffmanTable"/> ctor.
/// </summary>
public const int WorkspaceByteSize = 256 * sizeof(uint);
/// <summary>
/// Derived from the DHT marker. Contains the symbols, in order of incremental code length.
/// </summary>

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

@ -1097,16 +1097,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
const int codeLengthsByteSize = 17;
const int codeValuesMaxByteSize = 256;
const int tableWorkspaceByteSize = 256 * sizeof(uint);
const int totalBufferSize = codeLengthsByteSize + codeValuesMaxByteSize + tableWorkspaceByteSize;
const int totalBufferSize = codeLengthsByteSize + codeValuesMaxByteSize + HuffmanTable.WorkspaceByteSize;
int length = remaining;
using (IMemoryOwner<byte> buffer = this.Configuration.MemoryAllocator.Allocate<byte>(totalBufferSize))
{
Span<byte> bufferSpan = buffer.GetSpan();
Span<byte> huffmanLegthsSpan = buffer.Slice(0, codeLengthsByteSize);
Span<byte> huffmanValuesSpan = buffer.Slice(codeLengthsByteSize, codeValuesMaxByteSize);
Span<uint> tableWorkspace = MemoryMarshal.Cast<byte, uint>(buffer.Slice(codeLengthsByteSize + codeValuesMaxByteSize));
Span<byte> huffmanLegthsSpan = bufferSpan.Slice(0, codeLengthsByteSize);
Span<byte> huffmanValuesSpan = bufferSpan.Slice(codeLengthsByteSize, codeValuesMaxByteSize);
Span<uint> tableWorkspace = MemoryMarshal.Cast<byte, uint>(bufferSpan.Slice(codeLengthsByteSize + codeValuesMaxByteSize));
for (int i = 2; i < remaining;)
{

Loading…
Cancel
Save