Пример #1
0
        public static Table3D TryParseValid(System.IO.Stream stream)
        {
            s_tableInfo3D.Reset();
            s_tableInfo3D.location = (int)stream.Position;

            s_tableInfo3D.countX     = stream.ReadInt16BigEndian();
            s_tableInfo3D.countY     = stream.ReadInt16BigEndian();
            s_tableInfo3D.rangeX.Pos = stream.ReadInt32BigEndian();
            s_tableInfo3D.rangeY.Pos = stream.ReadInt32BigEndian();
            s_tableInfo3D.rangeZ.Pos = stream.ReadInt32BigEndian();
            // first byte matters, rest probably just alignment (zeroes), read all four in one go by little endian
            s_tableInfo3D.tableType = (TableType)(stream.ReadInt32LittleEndian());

            // Float type never has MAC floats so far, makes sense.
            // Shortcut, does not hurt (valid) results though.
            //if (TableType != TableType.Float)
            {
                // most but not all non-float tables have MAC floats:
                s_tableInfo3D.multiplier = stream.ReadSingleBigEndian();
                s_tableInfo3D.offset     = stream.ReadSingleBigEndian();

                if (s_tableInfo3D.IsRecordValid())
                {
                    if (!s_tableInfo3D.hasMAC)
                    {
                        // must back off to adjust stream position for next possible struct
                        stream.Seek(-2 * FloatSize, System.IO.SeekOrigin.Current);
                    }

                    long afterInfoPos = stream.Position;

                    bool valuesOk = s_tableInfo3D.ReadValidateValues(stream);
                    if (!valuesOk)
                    {
                        //Console.Error.WriteLine ("Error in values");
                    }


                    stream.Seek(afterInfoPos, System.IO.SeekOrigin.Begin);

                    return(valuesOk ? s_tableInfo3D.Copy() : null);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #2
0
        public static Table2D TryParseValid(System.IO.Stream stream)
        {
            s_tableInfo2D.Reset();

            s_tableInfo2D.location = (int)stream.Position;

            s_tableInfo2D.countX = stream.ReadInt16BigEndian();

            // First byte matters, residual byte probably just zero for alignment.
            // By reading as little endian word we read and verify all two bytes in one go.
            s_tableInfo2D.tableType = (TableType)stream.ReadInt16LittleEndian();

            s_tableInfo2D.rangeX.Pos = stream.ReadInt32BigEndian();
            s_tableInfo2D.rangeY.Pos = stream.ReadInt32BigEndian();

            // most but not all non-float tables have MAC floats:
            s_tableInfo2D.multiplier = stream.ReadSingleBigEndian();
            s_tableInfo2D.offset     = stream.ReadSingleBigEndian();

            long afterRecord = stream.Position;

            if (s_tableInfo2D.IsRecordValid())
            {
                if (!s_tableInfo2D.hasMAC)
                {
                    // must back off stream position for next possible struct
                    afterRecord -= 2 * FloatSize;
                }

                bool valuesOk = s_tableInfo2D.ReadValidateValues(stream);
//				if (!valuesOk) {
//					Console.Error.WriteLine ("2D: Error in values");
//				}

                stream.Position = afterRecord;

                return(valuesOk ? s_tableInfo2D.Copy() : null);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        public static uint[] ReadValuesUInt32(System.IO.Stream stream, Range range)
        {
            stream.Seek(range.Pos, System.IO.SeekOrigin.Begin);
            int count = range.Size / 4;

            uint[] array = new uint[count];

            for (int i = 0; i < array.Length; i++)
            {
                array [i] = (uint)stream.ReadInt32BigEndian();
            }
            return(array);
        }