ReadBits() public method

public ReadBits ( int bitCount ) : int
bitCount int
return int
コード例 #1
0
        private static LinkedNode Decode(BitStream input, LinkedNode head)
        {
            LinkedNode node = head;

            while (node.Child0 != null)
            {
                int bit = input.ReadBits(1);
                if (bit == -1)
                {
                    throw new Exception("Unexpected end of file");
                }

                node = bit == 0 ? node.Child0 : node.Child1;
            }
            return(node);
        }
コード例 #2
0
        public static MemoryStream Decompress(Stream data)
        {
            int comptype = data.ReadByte();

            if (comptype == 0)
            {
                throw new NotImplementedException("Compression type 0 is not currently supported");
            }

            LinkedNode tail = BuildList(sPrime[comptype]);
            LinkedNode head = BuildTree(tail);

            MemoryStream outputstream = new MemoryStream();
            BitStream    bitstream    = new BitStream(data);
            int          decoded;

            do
            {
                LinkedNode node = Decode(bitstream, head);
                decoded = node.DecompressedValue;
                switch (decoded)
                {
                case 256:
                    break;

                case 257:
                    int newvalue = bitstream.ReadBits(8);
                    outputstream.WriteByte((byte)newvalue);
                    tail = InsertNode(tail, newvalue);
                    break;

                default:
                    outputstream.WriteByte((byte)decoded);
                    break;
                }
            } while (decoded != 256);

            outputstream.Seek(0, SeekOrigin.Begin);
            return(outputstream);
        }
コード例 #3
0
ファイル: Huffman.cs プロジェクト: Nihlus/libwarcraft
        private static LinkedNode Decode(BitStream input, LinkedNode head)
        {
            LinkedNode node = head;

            while (node.Child0 != null)
            {
                int bit = input.ReadBits(1);
                if (bit == -1)
                {
                    throw new Exception("Unexpected end of file");
                }

                node = bit == 0 ? node.Child0 : node.Child1;
            }
            return node;
        }
コード例 #4
0
ファイル: Huffman.cs プロジェクト: Nihlus/libwarcraft
        public static MemoryStream Decompress(Stream data)
        {
            int comptype = data.ReadByte();

            if (comptype == 0)
            {
                throw new NotImplementedException("Compression type 0 is not currently supported");
            }

            LinkedNode tail = BuildList(sPrime[comptype]);
            LinkedNode head = BuildTree(tail);

            MemoryStream outputstream = new MemoryStream();
            BitStream bitstream = new BitStream(data);
            int decoded;
            do
            {
                LinkedNode node = Decode(bitstream, head);
                decoded = node.DecompressedValue;
                switch (decoded)
                {
                    case 256:
                        break;
                    case 257:
                        int newvalue = bitstream.ReadBits(8);
                        outputstream.WriteByte((byte)newvalue);
                        tail = InsertNode(tail, newvalue);
                        break;
                    default:
                        outputstream.WriteByte((byte)decoded);
                        break;
                }
            } while (decoded != 256);

            outputstream.Seek(0, SeekOrigin.Begin);
            return outputstream;
        }