Beispiel #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);
                }
            }
        }