当前位置: 首页>>代码示例>>C#>>正文


C# Stream.ReadUInt8方法代码示例

本文整理汇总了C#中System.IO.Stream.ReadUInt8方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadUInt8方法的具体用法?C# Stream.ReadUInt8怎么用?C# Stream.ReadUInt8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Stream的用法示例。


在下文中一共展示了Stream.ReadUInt8方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: R8Image

        public R8Image(Stream s)
        {
            // Scan forward until we find some data
            var type = s.ReadUInt8();
            while (type == 0)
                type = s.ReadUInt8();

            var width = s.ReadInt32();
            var height = s.ReadInt32();
            var x = s.ReadInt32();
            var y = s.ReadInt32();

            Size = new Size(width, height);
            Offset = new int2(width/2 - x, height/2 - y);

            /*var imageOffset = */s.ReadInt32();
            var paletteOffset = s.ReadInt32();
            var bpp = s.ReadUInt8();
            if (bpp != 8)
                throw new InvalidDataException("Error: {0} bits per pixel are not supported.".F(bpp));

            var frameHeight = s.ReadUInt8();
            var frameWidth = s.ReadUInt8();
            FrameSize = new Size(frameWidth, frameHeight);

            // Skip alignment byte
            s.ReadUInt8();

            Data = s.ReadBytes(width*height);

            // Ignore palette
            if (type == 1 && paletteOffset != 0)
                s.Seek(520, SeekOrigin.Current);
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:34,代码来源:R8Reader.cs

示例2: ShpTSFrame

			public ShpTSFrame(Stream s, Size frameSize)
			{
				var x = s.ReadUInt16();
				var y = s.ReadUInt16();
				var width = s.ReadUInt16();
				var height = s.ReadUInt16();

				// Pad the dimensions to an even number to avoid issues with half-integer offsets
				var dataWidth = width;
				var dataHeight = height;
				if (dataWidth % 2 == 1)
					dataWidth += 1;

				if (dataHeight % 2 == 1)
					dataHeight += 1;

				Offset = new int2(x + (dataWidth - frameSize.Width) / 2, y + (dataHeight - frameSize.Height) / 2);
				Size = new Size(dataWidth, dataHeight);
				FrameSize = frameSize;

				Format = s.ReadUInt8();
				s.Position += 11;
				FileOffset = s.ReadUInt32();

				if (FileOffset == 0)
					return;

				// Parse the frame data as we go (but remember to jump back to the header before returning!)
				var start = s.Position;
				s.Position = FileOffset;

				Data = new byte[dataWidth * dataHeight];

				if (Format == 3)
				{
					// Format 3 provides RLE-zero compressed scanlines
					for (var j = 0; j < height; j++)
					{
						var length = s.ReadUInt16() - 2;
						Format2.DecodeInto(s.ReadBytes(length), Data, dataWidth * j);
					}
				}
				else
				{
					// Format 2 provides uncompressed length-prefixed scanlines
					// Formats 1 and 0 provide an uncompressed full-width row
					var length = Format == 2 ? s.ReadUInt16() - 2 : width;
					for (var j = 0; j < height; j++)
						s.ReadBytes(Data, dataWidth * j, length);
				}

				s.Position = start;
			}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:53,代码来源:ShpTSLoader.cs

示例3: XccGlobalDatabase

        public XccGlobalDatabase(Stream s)
        {
            var entries = new List<string>();
            while (s.Peek() > -1)
            {
                var count = s.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var chars = new List<char>();
                    byte c;

                    // Read filename
                    while ((c = s.ReadUInt8()) != 0)
                        chars.Add((char)c);
                    entries.Add(new string(chars.ToArray()));

                    // Skip comment
                    while ((c = s.ReadUInt8()) != 0) { }
                }
            }

            Entries = entries.ToArray();
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:23,代码来源:XccGlobalDatabase.cs

示例4: FrameHeader

			public FrameHeader(Stream stream, Size frameSize)
			{
				var x = stream.ReadUInt16();
				var y = stream.ReadUInt16();
				var width = stream.ReadUInt16();
				var height = stream.ReadUInt16();

				// Note: the mixed Integer / fp division is intentional, and required for calculating the correct offset.
				Offset = new float2(x + width / 2 - 0.5f * frameSize.Width, y + height / 2 - 0.5f * frameSize.Height);
				Size = new Size(width, height);
				FrameSize = frameSize;

				Format = stream.ReadUInt8();
				stream.Position += 11;
				FileOffset = stream.ReadUInt32();
			}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:16,代码来源:ShpTSReader.cs

示例5: TmpTSTile

		public TmpTSTile(Stream s, Size size)
		{
			Size = size;

			// Ignore tile header for now
			s.Position += 52;

			Data = new byte[size.Width * size.Height];

			// Unpack tile data
			var width = 4;
			for (var i = 0; i < size.Height; i++)
			{
				var start = i * size.Width + (size.Width - width) / 2;
				for (var j = 0; j < width; j++)
					Data[start + j] = s.ReadUInt8();

				width += (i < size.Height / 2 - 1 ? 1 : -1) * 4;
			}

			// Ignore Z-data for now
			// Ignore extra data for now
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:23,代码来源:TmpTSReader.cs

示例6: IsShpTS

        static bool IsShpTS(Stream s)
        {
            var start = s.Position;

            // First word is zero
            if (s.ReadUInt16() != 0)
            {
                s.Position = start;
                return false;
            }

            // Sanity Check the image count
            s.Position += 4;
            var imageCount = s.ReadUInt16();
            if (s.Position + 24 * imageCount > s.Length)
            {
                s.Position = start;
                return false;
            }

            // Check the size and format flag
            // Some files define bogus frames, so loop until we find a valid one
            s.Position += 4;
            ushort w, h, f = 0;
            byte type;
            do
            {
                w = s.ReadUInt16();
                h = s.ReadUInt16();
                type = s.ReadUInt8();
            }
            while (w == 0 && h == 0 && f++ < imageCount);

            s.Position = start;
            return type < 4;
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:36,代码来源:SpriteSource.cs

示例7: IsShpTD

        static bool IsShpTD(Stream s)
        {
            var start = s.Position;

            // First word is the image count
            var imageCount = s.ReadUInt16();
            if (imageCount == 0)
            {
                s.Position = start;
                return false;
            }

            // Last offset should point to the end of file
            var finalOffset = start + 14 + 8 * imageCount;
            if (finalOffset > s.Length)
            {
                s.Position = start;
                return false;
            }

            s.Position = finalOffset;
            var eof = s.ReadUInt32();
            if (eof != s.Length)
            {
                s.Position = start;
                return false;
            }

            // Check the format flag on the first frame
            s.Position = start + 17;
            var b = s.ReadUInt8();

            s.Position = start;
            return b == 0x20 || b == 0x40 || b == 0x80;
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:35,代码来源:SpriteSource.cs

示例8: IsR8

        static bool IsR8(Stream s)
        {
            var start = s.Position;

            // First byte is nonzero
            if (s.ReadUInt8() == 0)
            {
                s.Position = start;
                return false;
            }

            // Check the format of the first frame
            s.Position = start + 25;
            var d = s.ReadUInt8();

            s.Position = start;
            return d == 8;
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:18,代码来源:SpriteSource.cs

示例9: ReadVoxelData

        void ReadVoxelData(Stream s, VxlLimb l)
        {
            var baseSize = l.Size[0]*l.Size[1];
            var colStart = new int[baseSize];
            for (var i = 0; i < baseSize; i++)
                colStart[i] = s.ReadInt32();
            s.Seek(4*baseSize, SeekOrigin.Current);
            var dataStart = s.Position;

            // Count the voxels in this limb
            l.VoxelCount = 0;
            for (var i = 0; i < baseSize; i++)
            {
                // Empty column
                if (colStart[i] == -1)
                    continue;

                s.Seek(dataStart + colStart[i], SeekOrigin.Begin);
                var z = 0;
                do
                {
                    z += s.ReadUInt8();
                    var count = s.ReadUInt8();
                    z += count;
                    l.VoxelCount += count;
                    s.Seek(2*count + 1, SeekOrigin.Current);
                } while (z < l.Size[2]);
            }

            // Read the data
            l.VoxelMap = new Dictionary<byte, VxlElement>[l.Size[0],l.Size[1]];
            for (var i = 0; i < baseSize; i++)
            {
                // Empty column
                if (colStart[i] == -1)
                    continue;

                s.Seek(dataStart + colStart[i], SeekOrigin.Begin);

                byte x = (byte)(i % l.Size[0]);
                byte y = (byte)(i / l.Size[0]);
                byte z = 0;
                l.VoxelMap[x,y] = new Dictionary<byte, VxlElement>();
                do
                {
                    z += s.ReadUInt8();
                    var count = s.ReadUInt8();
                    for (var j = 0; j < count; j++)
                    {
                        var v = new VxlElement();
                        v.Color = s.ReadUInt8();
                        v.Normal = s.ReadUInt8();

                        l.VoxelMap[x,y].Add(z, v);
                        z++;
                    }
                    // Skip duplicate count
                    s.ReadUInt8();
                } while (z < l.Size[2]);
            }
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:61,代码来源:VxlReader.cs

示例10: FrameHeader

        public FrameHeader(Stream stream, Size frameSize)
        {
            var x = stream.ReadUInt16();
            var y = stream.ReadUInt16();
            var width = stream.ReadUInt16();
            var height = stream.ReadUInt16();

            Offset = new float2(x + 0.5f * (width - frameSize.Width), y + 0.5f * (height - frameSize.Height));
            Size = new Size(width, height);
            FrameSize = frameSize;

            Format = stream.ReadUInt8();
            stream.Position += 11;
            FileOffset = stream.ReadUInt32();
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:15,代码来源:ShpTSReader.cs


注:本文中的System.IO.Stream.ReadUInt8方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。