public override int Read(IOfcNumberWriter writer, Block block, StreamBitReader reader)
        {
            // ReSharper disable once AssignmentInConditionalExpression
            if (block.OverrideGlobalNb = reader.ReadByte(1) > 0)
            {
                block.NeededBits = reader.ReadByte(Metadata.MaxNeededBitsNeededBitsNumber);
            }

            // ReSharper disable once AssignmentInConditionalExpression
            if (!Metadata.IsAbsolute)
            {
                if (block.AbsoluteSign = reader.ReadByte(1) > 0)
                {
                    block.IsSignNegative = reader.ReadByte(1) > 0;
                }
            }

            var hasAbsoluteSign = block.AbsoluteSign || Metadata.IsAbsolute;
            var isNegative      = block.AbsoluteSign && block.IsSignNegative || Metadata.IsAbsolute && Metadata.IsNegative;

            for (var i = 0; i < block.Length; i++)
            {
                var num = new OfcNumber();

                if (!hasAbsoluteSign)
                {
                    isNegative = reader.ReadByte(1) > 0;
                }

                num.Number = ((long)reader.Read(Metadata.MaxNeededBitsNumber)) * (isNegative ? -1 : 1);
                writer.Write(num);
            }

            return(block.Length);
        }
        public override int Read(IOfcNumberWriter writer, Block block, StreamBitReader reader)
        {
            var val1 = ReadSingleValueWithoutControlBit(reader, Metadata);
            var val2 = ReadSingleValueWithoutControlBit(reader, Metadata);

            writer.Write(val1);
            writer.Write(val2);

            var difference = val2.SubtractEach(val1);

            for (var i = 1; i < block.Length - 1; i++)
            {
                writer.Write(difference.LinearMultiplyEach(i).AddEach(val2));
            }

            return(block.Length);
        }
Exemple #3
0
        public override int Read(IOfcNumberWriter writer, Block block, StreamBitReader reader)
        {
            var value = ReadSingleValueWithoutControlBit(reader, Metadata);

            for (var i = 0; i < block.Length; i++)
            {
                writer.Write(value);
            }

            return(block.Length);
        }
Exemple #4
0
        public override int Read(IOfcNumberWriter writer, Block block, StreamBitReader reader)
        {
            var val1 = ReadSingleValueWithoutControlBit(reader, Metadata);
            var val2 = ReadSingleValueWithoutControlBit(reader, Metadata);

            var ppLength = reader.ReadByte(8);
            var total    = ppLength * block.Length;

            for (var i = 0; i < total; i++)
            {
                writer.Write(i % (ppLength * 2) >= ppLength ? val2 : val1);
            }

            return(total);
        }
Exemple #5
0
        public void Decompress()
        {
            var valueCount = 0;

            while (valueCount < Metadata.ValueCount)
            {
                if (_bitReader.ReadByte(1) > 0) // isBlock
                {
                    var block  = DecompressionMethod.ReadDefaultBlockHeader(_bitReader, Metadata);
                    var method = GetMethodForBlock(block); // Get decompressor class for block type
                    valueCount += method.Read(_numberWriter, block, _bitReader);
                }
                else
                {
                    _numberWriter.Write(DecompressionMethod.ReadSingleValueWithoutControlBit(_bitReader, Metadata));
                    valueCount++;
                }
            }
            _writer?.Flush();
        }