private static JpegHuffmanCanonicalCode[] BuildCanonicalCode(ReadOnlySpan <byte> bits, ReadOnlySpan <Symbol> symbols)
        {
            int codeCount = symbols.Length;
            var codes     = new JpegHuffmanCanonicalCode[codeCount];

            int      currentCodeLength = 1;
            ref byte codeLengthsRef    = ref MemoryMarshal.GetReference(bits);
示例#2
0
        public void GetCode(int symbol, out ushort code, out int codeLength)
        {
            Debug.Assert((uint)symbol < 256);
            JpegHuffmanCanonicalCode c = _codes[_symbolMap[symbol]];

            code       = c.Code;
            codeLength = c.CodeLength;
        }
示例#3
0
        private static JpegHuffmanCanonicalCode[] BuildCanonicalCode(ReadOnlySpan <byte> codeLengths, ReadOnlySpan <byte> codeValues)
        {
            int codeCount = codeValues.Length;
            var codes     = new JpegHuffmanCanonicalCode[codeCount];

            Span <byte> codeLengthsBuffer = stackalloc byte[16];

            codeLengths.CopyTo(codeLengthsBuffer);

            int      currentCodeLength = 1;
            ref byte codeLengthsRef    = ref MemoryMarshal.GetReference(codeLengthsBuffer);
示例#4
0
        public JpegHuffmanEncodingTable(JpegHuffmanCanonicalCode[] codes)
        {
            _codes = codes ?? throw new ArgumentNullException(nameof(codes));

            int codeCount = 0;

            _symbolMap = new byte[256];
            for (int i = 0; i < codes.Length; i++)
            {
                JpegHuffmanCanonicalCode code = codes[i];
                if (code.CodeLength != 0)
                {
                    _symbolMap[code.Symbol] = (byte)i;
                    codeCount++;
                }
            }
            _codeCount = codeCount;
        }