当前位置: 首页>>代码示例>>C#>>正文


C# BitStream.GetBit方法代码示例

本文整理汇总了C#中BitStream.GetBit方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.GetBit方法的具体用法?C# BitStream.GetBit怎么用?C# BitStream.GetBit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitStream的用法示例。


在下文中一共展示了BitStream.GetBit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SmallHuffmanTree

        public SmallHuffmanTree(BitStream bs)
        {
            _bs = bs;
            uint bit = _bs.GetBit();
            Debug.Assert(bit != 0);

            for (ushort i = 0; i < 256; ++i)
                _prefixtree[i] = _prefixlength[i] = 0;

            DecodeTree(0, 0);

            bit = _bs.GetBit();
            Debug.Assert(bit == 0);
        }
开发者ID:scemino,项目名称:nscumm,代码行数:14,代码来源:SmallHuffmanTree.cs

示例2: BigHuffmanTree

        public BigHuffmanTree(BitStream bs, int allocSize)
        {
            _bs = bs;
            uint bit = _bs.GetBit();
            if (bit == 0)
            {
                _tree = new uint[1];
                _tree[0] = 0;
                _last[0] = _last[1] = _last[2] = 0;
                return;
            }

            for (uint i = 0; i < 256; ++i)
                _prefixtree[i] = _prefixlength[i] = 0;

            _loBytes = new SmallHuffmanTree(_bs);
            _hiBytes = new SmallHuffmanTree(_bs);

            _markers[0] = _bs.GetBits(16);
            _markers[1] = _bs.GetBits(16);
            _markers[2] = _bs.GetBits(16);

            _last[0] = _last[1] = _last[2] = 0xffffffff;

            _treeSize = 0;
            _tree = new uint[allocSize / 4];
            DecodeTree(0, 0);
            bit = _bs.GetBit();
            Debug.Assert(bit == 0);

            for (uint i = 0; i < 3; ++i)
            {
                if (_last[i] == 0xffffffff)
                {
                    _last[i] = _treeSize;
                    _tree[_treeSize++] = 0;
                }
            }
        }
开发者ID:scemino,项目名称:nscumm,代码行数:39,代码来源:BigHuffmanTree.cs

示例3: GetCode

        public ushort GetCode(BitStream bs)
        {
            byte peek = (byte)bs.PeekBits(Math.Min(bs.Size - bs.Position, 8));
            int p = _prefixtree[peek];
            bs.Skip(_prefixlength[peek]);

            while ((_tree[p] & SMK_NODE) != 0)
            {
                if (bs.GetBit() != 0)
                    p += (_tree[p] & ~SMK_NODE);
                p++;
            }

            return _tree[p];
        }
开发者ID:scemino,项目名称:nscumm,代码行数:15,代码来源:SmallHuffmanTree.cs

示例4: DecodeFrame

        public void DecodeFrame(BitStream bs)
        {
            _mMapTree.Reset();
            _mClrTree.Reset();
            _fullTree.Reset();
            _typeTree.Reset();

            // Height needs to be doubled if we have flags (Y-interlaced or Y-doubled)
            uint doubleY = (uint)(_flags != 0 ? 2 : 1);

            uint bw = (uint)(Width / 4);
            uint bh = Height / doubleY / 4;
            int stride = Width;
            uint block = 0, blocks = bw * bh;

            uint type, run, j, mode;
            uint p1, p2, clr, map;
            byte hi, lo;
            uint i;
            int bOut;
            byte[] pixels = _surface.Pixels;
            while (block < blocks)
            {
                type = _typeTree.GetCode(bs);
                run = GetBlockRun((int) ((type >> 2) & 0x3f));

                switch (type & 3)
                {
                    case SmkBlockMono:
                        while (run-- != 0 && block < blocks)
                        {
                            clr = _mClrTree.GetCode(bs);
                            map = _mMapTree.GetCode(bs);

                            bOut = (int)((block / bw) * (stride * 4 * doubleY) + (block % bw) * 4);
                            hi = (byte)(clr >> 8);
                            lo = (byte)(clr & 0xff);
                            for (i = 0; i < 4; i++)
                            {
                                for (j = 0; j < doubleY; j++)
                                {
                                    pixels[bOut] = (map & 1) != 0 ? hi : lo;
                                    pixels[bOut + 1] = (map & 2) != 0 ? hi : lo;
                                    pixels[bOut + 2] = (map & 4) != 0 ? hi : lo;
                                    pixels[bOut + 3] = (map & 8) != 0 ? hi : lo;
                                    bOut += stride;
                                }
                                map >>= 4;
                            }
                            ++block;
                        }
                        break;
                    case SmkBlockFull:
                        // Smacker v2 has one mode, Smacker v4 has three
                        if (_signature == ScummHelper.MakeTag('S', 'M', 'K', '2'))
                        {
                            mode = 0;
                        }
                        else
                        {
                            // 00 - mode 0
                            // 10 - mode 1
                            // 01 - mode 2
                            mode = 0;
                            if (bs.GetBit() != 0)
                            {
                                mode = 1;
                            }
                            else if (bs.GetBit() != 0)
                            {
                                mode = 2;
                            }
                        }

                        while (run-- != 0 && block < blocks)
                        {
                            bOut = (int)((block / bw) * (stride * 4 * doubleY) + (block % bw) * 4);
                            switch (mode)
                            {
                                case 0:
                                    for (i = 0; i < 4; ++i)
                                    {
                                        p1 = _fullTree.GetCode(bs);
                                        p2 = _fullTree.GetCode(bs);
                                        for (j = 0; j < doubleY; ++j)
                                        {
                                            pixels[bOut + 2] = (byte)(p1 & 0xff);
                                            pixels[bOut + 3] = (byte)(p1 >> 8);
                                            pixels[bOut + 0] = (byte)(p2 & 0xff);
                                            pixels[bOut + 1] = (byte)(p2 >> 8);
                                            bOut += stride;
                                        }
                                    }
                                    break;
                                case 1:
                                    p1 = _fullTree.GetCode(bs);
                                    pixels[bOut + 0] = pixels[bOut + 1] = (byte)(p1 & 0xFF);
                                    pixels[bOut + 2] = pixels[bOut + 3] = (byte)(p1 >> 8);
                                    bOut += stride;
                                    pixels[bOut + 0] = pixels[bOut + 1] = (byte)(p1 & 0xFF);
//.........这里部分代码省略.........
开发者ID:scemino,项目名称:nscumm,代码行数:101,代码来源:SmackerVideoTrack.cs

示例5: GetCode

        public uint GetCode(BitStream bs)
        {
            byte peek = (byte)bs.PeekBits(Math.Min(bs.Size - bs.Position, 8));
            var p = _prefixtree[peek];
            bs.Skip(_prefixlength[peek]);

            while ((_tree[p] & SMK_NODE) != 0)
            {
                if (bs.GetBit() != 0)
                    p += _tree[p] & ~SMK_NODE;
                p++;
            }

            uint v = _tree[p];
            if (v != _tree[_last[0]])
            {
                _tree[_last[2]] = _tree[_last[1]];
                _tree[_last[1]] = _tree[_last[0]];
                _tree[_last[0]] = v;
            }

            return v;
        }
开发者ID:scemino,项目名称:nscumm,代码行数:23,代码来源:BigHuffmanTree.cs

示例6: ReadDC

            private int ReadDC(BitStream bits, ushort version, PlaneType plane)
            {
                // Version 2 just has its coefficient as 10-bits
                if (version == 2)
                    return ReadSignedCoefficient(bits);

                // Version 3 has it stored as huffman codes as a difference from the previous DC value

                var huffman = (plane == PlaneType.Y) ? _dcHuffmanLuma : _dcHuffmanChroma;

                uint symbol = huffman.GetSymbol(bits);
                int dc = 0;

                if (GET_DC_BITS(symbol) != 0)
                {
                    bool negative = (bits.GetBit() == 0);
                    dc = (int)bits.GetBits(GET_DC_BITS(symbol) - 1);

                    if (negative)
                        dc -= GET_DC_NEG(symbol);
                    else
                        dc += GET_DC_POS(symbol);
                }

                _lastDC[(int)plane] += dc * 4; // convert from 8-bit to 10-bit
                return _lastDC[(int)plane];
            }
开发者ID:scemino,项目名称:nscumm,代码行数:27,代码来源:PsxStreamDecoder.Video.cs

示例7: ReadAC

            private void ReadAC(BitStream bits, int[] block, int offset)
            {
                // Clear the block first
                for (int i = 0; i < 63; i++)
                    block[offset + i] = 0;

                int count = 0;
                int b = offset;
                while (!bits.IsEndOfStream)
                {
                    uint symbol = _acHuffman.GetSymbol(bits);

                    if (symbol == ESCAPE_CODE)
                    {
                        // The escape code!
                        int zeroes = (int)bits.GetBits(6);
                        count += zeroes + 1;
                        BLOCK_OVERFLOW_CHECK(count);
                        b += zeroes;
                        block[b++] = ReadSignedCoefficient(bits);
                    }
                    else if (symbol == END_OF_BLOCK)
                    {
                        // We're done
                        break;
                    }
                    else {
                        // Normal huffman code
                        int zeroes = GET_AC_ZERO_RUN(symbol);
                        count += zeroes + 1;
                        BLOCK_OVERFLOW_CHECK(count);
                        b += zeroes;

                        if (bits.GetBit() != 0)
                            block[b++] = -GET_AC_COEFFICIENT(symbol);
                        else
                            block[b++] = GET_AC_COEFFICIENT(symbol);
                    }
                }
            }
开发者ID:scemino,项目名称:nscumm,代码行数:40,代码来源:PsxStreamDecoder.Video.cs


注:本文中的BitStream.GetBit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。