private static int DecodeHuffmanCode(ref JpegBitReader reader, JpegHuffmanDecodingTable table)
        {
            int bits = reader.PeekBits(16, out int bitsRead);

            JpegHuffmanDecodingTable.Entry entry = table.Lookup(bits);
            bitsRead = Math.Min(entry.CodeSize, bitsRead);
            _        = reader.TryAdvanceBits(bitsRead, out _);
            return(entry.SymbolValue);
        }
 private void ProcessDefineHuffmanTable(ReadOnlySequence <byte> segment, int currentOffset)
 {
     while (!segment.IsEmpty)
     {
         if (!JpegHuffmanDecodingTable.TryParse(segment, out JpegHuffmanDecodingTable? huffmanTable, out int bytesConsumed))
         {
             ThrowInvalidDataException(currentOffset, "Failed to parse Huffman table.");
             return;
         }
         segment        = segment.Slice(bytesConsumed);
         currentOffset += bytesConsumed;
         SetHuffmanTable(huffmanTable);
     }
 }
        private void SetHuffmanTable(JpegHuffmanDecodingTable table)
        {
            List <JpegHuffmanDecodingTable>?list = _huffmanTables;

            if (list is null)
            {
                list = _huffmanTables = new List <JpegHuffmanDecodingTable>(4);
            }
            for (int i = 0; i < list.Count; i++)
            {
                JpegHuffmanDecodingTable item = list[i];
                if (item.TableClass == table.TableClass && item.Identifier == table.Identifier)
                {
                    list[i] = table;
                    return;
                }
            }
            list.Add(table);
        }