Ejemplo n.º 1
0
        private void WriteBitAndUnderflowBits(uint value)
        {
            value &= 0x00000001;
            Writer.WriteNBits(value, 1);

            uint negatedValue = (~value & 0x00000001);

            while (UnderflowBits > 0)
            {
                Writer.WriteNBits(negatedValue, 1);
                UnderflowBits--;
            }
        }
Ejemplo n.º 2
0
        public static void CompressFile(string inputFile, string outputFile)
        {
            // Read uncompressed file variables
            BitReader reader    = new BitReader(inputFile);
            var       inputSize = NR_BITS_TO_READ * new FileInfo(inputFile).Length;

            // Write compressed file variables
            BitWriter writer = new BitWriter(outputFile);
            Coder     coder  = new Coder(writer);

            for (var i = inputSize - 1; i >= 0; i -= 8)
            {
                uint symbol = Convert.ToUInt32(reader.ReadNBits(NR_BITS_TO_READ));

                // For each symbol and update the model statistics
                coder.EncodeSymbol(symbol);
                coder.arithmeticModel.UpdateModel(symbol);
            }

            reader.Dispose();

            coder.EncodeSymbol(EOF);
            coder.FlushEncoder();
            writer.WriteNBits(1, 7);
            writer.Dispose();
        }
Ejemplo n.º 3
0
        public static void DecompressFile(string inputFile, string outputFile)
        {
            BitReader reader  = new BitReader(inputFile);
            BitWriter writer  = new BitWriter(outputFile);
            Decoder   decoder = new Decoder(reader);


            // reading loop...
            for (; ;)
            {
                uint symbol = decoder.DecodeSymbol();
                if (symbol == EOF)
                {
                    break;
                }
                writer.WriteNBits(symbol, 8);
                decoder.arithmeticModel.UpdateModel(symbol);
            }

            reader.Dispose();
            writer.WriteNBits(1, 7);
            writer.Dispose();
        }