Пример #1
0
        //Decompress BitStream into integer array
        public static int[] Decompress(ref BitStreamFIFO source)
        {
            //Read necessary info for decompression
            int compressionType  = source.ReadInt(2);                //The compression technique used
            int lengthSaveLength = source.ReadInt(6) * 8;            //The amount of bits needed to save the total length in bits of the compressed data
            int arrayDataLength  = source.ReadInt(lengthSaveLength); //The total length in bits of the compressed data

            //Create a new BitStream of correct length from the incoming BitStream
            BitStreamFIFO arrayData = new BitStreamFIFO(source.ReadBoolArray(arrayDataLength));

            //Decompress using the correct compression type
            int[] intArray = new int[0];
            switch (compressionType)
            {
            //Huffmann
            case 0:
                intArray = HuffmanIntArrayCompressor.DeCompress(arrayData);
                break;

            //Variable int length
            case 1:
                intArray = VaryingIntLengthIntArrayCompressor.Decompress(arrayData);
                break;

                //To add a compression technique, add a new case like the existing ones and increase the length of new byte[??][]
            }

            //Return the decompressed array of integers
            return(intArray);
        }