예제 #1
0
        /// <summary>
        /// Reads a 2-byte unsigned integer.
        /// </summary>
        /// <returns>The 2-byte unsigned integer.</returns>
        /// <exception cref="EndOfStreamException">The end of the stream has been reached.</exception>
        /// <exception cref="ObjectDisposedException">The object has been disposed.</exception>
        public ushort ReadUInt16()
        {
            VerifyNotDisposed();

            EnsureBuffer(sizeof(ushort));

            ushort val;

            switch (endianess)
            {
            case Endianess.Big:
                val = (ushort)((buffer[readOffset] << 8) | buffer[readOffset + 1]);
                break;

            case Endianess.Little:
                val = (ushort)(buffer[readOffset] | (buffer[readOffset + 1] << 8));
                break;

            default:
                throw new InvalidOperationException("Unsupported byte order: " + endianess.ToString());
            }

            readOffset += sizeof(ushort);

            return(val);
        }
예제 #2
0
 public void WriteXml(StringBuilder sb, int indent)
 {
     if (Endianess != Endianess.BigEndian)
     {
         HmapXml.StringTag(sb, indent, "Endianess", Endianess.ToString());
     }
     HmapXml.ValueTag(sb, indent, "Width", Width.ToString());
     HmapXml.ValueTag(sb, indent, "Height", Height.ToString());
     HmapXml.SelfClosingTag(sb, indent, "BBMin " + FloatUtil.GetVector3XmlString(BBMin));
     HmapXml.SelfClosingTag(sb, indent, "BBMax " + FloatUtil.GetVector3XmlString(BBMax));
     HmapXml.WriteRawArray(sb, InvertImage(MaxHeights, Width, Height), indent, "MaxHeights", "", HmapXml.FormatHexByte, Width);
     HmapXml.WriteRawArray(sb, InvertImage(MinHeights, Width, Height), indent, "MinHeights", "", HmapXml.FormatHexByte, Width);
 }