BitMiracle.LibJpeg.Classic.Internal.huff_entropy_encoder.emit_bits_e C# (CSharp) Méthode

emit_bits_e() private méthode

Outputting bits to the file Only the right 24 bits of put_buffer are used; the valid bits are left-justified in this part. At most 16 bits can be passed to emit_bits in one call, and we never retain more than 7 bits in put_buffer between calls, so 24 bits are sufficient.
private emit_bits_e ( int code, int size ) : void
code int
size int
Résultat void
        private void emit_bits_e(int code, int size)
        {
            /* This routine is heavily used, so it's worth coding tightly. */

            /* if size is 0, caller used an invalid Huffman table entry */
            if (size == 0)
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_HUFF_MISSING_CODE);

            if (m_gather_statistics)
            {
                /* do nothing if we're only getting stats */
                return;
            }

            int local_put_buffer = code & ((1 << size) - 1); /* mask off any extra bits in code */

            int put_bits = size + m_saved.put_bits;       /* new number of bits in buffer */

            local_put_buffer <<= 24 - put_bits; /* align incoming bits */

            local_put_buffer |= m_saved.put_buffer; /* and merge with old buffer contents */

            while (put_bits >= 8)
            {
                int c = (local_put_buffer >> 16) & 0xFF;

                emit_byte_e(c);
                if (c == 0xFF)
                {
                    /* need to stuff a zero byte? */
                    emit_byte_e(0);
                }
                local_put_buffer <<= 8;
                put_bits -= 8;
            }

            m_saved.put_buffer = local_put_buffer; /* update variables */
            m_saved.put_bits = put_bits;
        }