Exemplo n.º 1
0
        public static void TransformFloat(float val, byte[] buffer, int index)
        {
            var floatBytes         = EndianAwareBitConverter.GetBytes(val, Endianness.Big);
            var intForm            = (uint)EndianAwareBitConverter.ToInt32(floatBytes, Endianness.Big);
            var transformedIntForm = (intForm << 1) | (intForm >> 31); // Rotate left 1 bit
            var transformedBytes   = EndianAwareBitConverter.GetBytes((int)transformedIntForm, Endianness.Big);

            Array.Copy(transformedBytes, 0, buffer, index, sizeof(float));
        }
Exemplo n.º 2
0
        public static float ReverseTransformFloat(byte[] buffer, int index)
        {
            var bytes = new byte[sizeof(float)];

            Array.Copy(buffer, index, bytes, 0, sizeof(float));
            var intForm            = (uint)EndianAwareBitConverter.ToInt32(bytes, Endianness.Big);
            var transformedIntForm = (intForm >> 1) | (intForm << 31); // Rotate right 1 bit
            var transformedBytes   = EndianAwareBitConverter.GetBytes((int)transformedIntForm, Endianness.Big);

            return(EndianAwareBitConverter.ToSingle(transformedBytes, Endianness.Big));
        }
Exemplo n.º 3
0
        public static int[] ReadReferentArray(EndianAwareBinaryReader reader, int count)
        {
            var values        = new int[count];
            var bytes         = reader.ReadBytes(count * sizeof(int));
            var deinterleaved = DeinterleaveBytes(bytes, sizeof(int));

            var last   = 0;
            var buffer = new byte[sizeof(int)];

            for (var i = 0; i < count; i++)
            {
                Array.Copy(deinterleaved, i * sizeof(int), buffer, 0, sizeof(int));
                var value = EndianAwareBitConverter.ToInt32(buffer, Endianness.Big);
                value     = ReverseTransformInt32(value);
                value    += last;
                values[i] = value;
                last      = value;
            }

            return(values);
        }
Exemplo n.º 4
0
        public static int[] ReverseTransformInt32Array(byte[] data)
        {
            if (data.Length % sizeof(int) != 0)
            {
                throw new ArgumentException("Invalid interleaved data. Data length must be a multiple of 4 bytes.");
            }

            var valueCount = data.Length / sizeof(int);
            var values     = new int[valueCount];
            var buffer     = new byte[sizeof(int)];

            var deinterleavedData = DeinterleaveBytes(data, sizeof(int));

            for (var i = 0; i < valueCount; i++)
            {
                Array.Copy(deinterleavedData, i * sizeof(int), buffer, 0, sizeof(int));
                var transformedValue = EndianAwareBitConverter.ToInt32(buffer, Endianness.Big);
                values[i] = ReverseTransformInt32(transformedValue);
            }

            return(values);
        }
Exemplo n.º 5
0
 public static int[] ReadEnumerationArray(EndianAwareBinaryReader reader, int count)
 {
     return(ReadInterleavedPropertyDataArrayHelper(reader, count, sizeof(int), bytes => EndianAwareBitConverter.ToInt32(bytes, Endianness.Big)));
 }
Exemplo n.º 6
0
 public static BrickColor[] ReadBrickColorArray(EndianAwareBinaryReader reader, int count)
 {
     return(ReadInterleavedPropertyDataArrayHelper(reader, count, sizeof(int), bytes => (BrickColor)EndianAwareBitConverter.ToInt32(bytes, Endianness.Big)));
 }