Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdfJsHuffmanTable"/> struct.
        /// </summary>
        /// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
        /// <param name="lengths">The code lengths</param>
        /// <param name="values">The huffman values</param>
        public PdfJsHuffmanTable(MemoryManager memoryManager, byte[] lengths, byte[] values)
        {
            // TODO: Replace FakeBuffer<T> usages with standard or array orfixed-sized arrays
            this.lookahead = memoryManager.AllocateFake <short>(256);
            this.valOffset = memoryManager.AllocateFake <short>(18);
            this.maxcode   = memoryManager.AllocateFake <long>(18);

            using (IBuffer <short> huffsize = memoryManager.Allocate <short>(257))
                using (IBuffer <short> huffcode = memoryManager.Allocate <short>(257))
                {
                    GenerateSizeTable(lengths, huffsize.Span);
                    GenerateCodeTable(huffsize.Span, huffcode.Span);
                    GenerateDecoderTables(lengths, huffcode.Span, this.valOffset.Span, this.maxcode.Span);
                    GenerateLookaheadTables(lengths, values, this.lookahead.Span);
                }

            this.huffval = memoryManager.AllocateManagedByteBuffer(values.Length, true);
            Buffer.BlockCopy(values, 0, this.huffval.Array, 0, values.Length);

            this.MaxCode   = this.maxcode.Array;
            this.ValOffset = this.valOffset.Array;
            this.HuffVal   = this.huffval.Array;
            this.Lookahead = this.lookahead.Array;
        }