Exemplo n.º 1
0
    /// <summary>
    /// Expands compressed patch data into the given array of int values
    ///
    /// If the value starts with bits   0: The value is zero
    /// If the value starts with bits  00: The rest of the patch is zeroes
    /// If the value starts with bits 000: The value is a positive integer of wordBits bits
    /// If the value starts with bits 001: The value is a negative integer of wordBits bits
    ///
    /// </summary>
    /// <param name="bitPack">The bitPack to read data from</param>
    /// <param name="patchSize">The number of values in the patch is patchSize * patchSize</param>
    /// <param name="wordBits">The number of bits in each value</param>
    /// <param name="patchData">Array to place the decoded values in</param>
    public static void Decode(BitPack bitPack, int patchSize, int wordBits, int[] patchData)
    {
        //Logger.LogDebug($"Patch.Decode: patchSize={patchSize}, wordBits={wordBits}");

        // TODO: Different for Big Endian?
        int i;
        int j;

        for (i = 0; i < patchSize * patchSize; i++)
        {
            if (bitPack.GetBool() == false)
            {
                patchData[i] = 0;
                continue;
            }

            if (bitPack.GetBool() == false)
            {
                for (j = i; j < patchSize * patchSize; j++)
                {
                    patchData[j] = 0;
                }

                return;
            }

            bool isNegative = bitPack.GetBool();
            patchData[i] = (int)bitPack.GetUInt32_Le(wordBits) * (isNegative ? -1 : 1);
        }
    }
Exemplo n.º 2
0
        public void GetBool()
        {
            byte[] buffer =
            {
                0x50
            };
            BitPack bitPack = new BitPack(buffer);

            Assert.AreEqual(false, bitPack.GetBool());
            Assert.AreEqual(true, bitPack.GetBool());
            Assert.AreEqual(false, bitPack.GetBool());
            Assert.AreEqual(true, bitPack.GetBool());
            Assert.AreEqual(false, bitPack.GetBool());
            Assert.AreEqual(false, bitPack.GetBool());
            Assert.AreEqual(false, bitPack.GetBool());
            Assert.AreEqual(false, bitPack.GetBool());
        }