本文整理汇总了C#中Stream.ReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadUInt16方法的具体用法?C# Stream.ReadUInt16怎么用?C# Stream.ReadUInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.ReadUInt16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseFrames
TmpTDFrame[] ParseFrames(Stream s)
{
var start = s.Position;
var width = s.ReadUInt16();
var height = s.ReadUInt16();
var size = new Size(width, height);
s.Position += 8;
var imgStart = s.ReadUInt32();
s.Position += 8;
var indexEnd = s.ReadInt32();
var indexStart = s.ReadInt32();
s.Position = indexStart;
var count = indexEnd - indexStart;
var tiles = new TmpTDFrame[count];
var tilesIndex = 0;
foreach (var b in s.ReadBytes(count))
{
if (b != 255)
{
s.Position = imgStart + b * width * height;
tiles[tilesIndex++] = new TmpTDFrame(s.ReadBytes(width * height), size);
}
else
tiles[tilesIndex++] = new TmpTDFrame(null, size);
}
s.Position = start;
return tiles;
}
示例2: ShpReader
public ShpReader(Stream stream)
{
imageCount = stream.ReadUInt16();
stream.Position += 4;
var width = stream.ReadUInt16();
var height = stream.ReadUInt16();
Size = new Size(width, height);
stream.Position += 4;
var headers = new ImageHeader[imageCount];
Frames = headers.AsReadOnly();
for (var i = 0; i < headers.Length; i++)
headers[i] = new ImageHeader(stream, this);
// Skip eof and zero headers
stream.Position += 16;
var offsets = headers.ToDictionary(h => h.FileOffset, h => h);
for (var i = 0; i < imageCount; i++)
{
var h = headers[i];
if (h.Format == Format.Format20)
h.RefImage = headers[i - 1];
else if (h.Format == Format.Format40 && !offsets.TryGetValue(h.RefOffset, out h.RefImage))
throw new InvalidDataException("Reference doesnt point to image data {0}->{1}".F(h.FileOffset, h.RefOffset));
}
shpBytesFileOffset = stream.Position;
shpBytes = stream.ReadBytes((int)(stream.Length - stream.Position));
foreach (var h in headers)
Decompress(h);
}
示例3: ShpReader
public ShpReader(Stream stream)
{
imageCount = stream.ReadUInt16();
stream.Position += 4;
var width = stream.ReadUInt16();
var height = stream.ReadUInt16();
Size = new Size(width, height);
stream.Position += 4;
for (var i = 0; i < imageCount; i++)
headers.Add(new ImageHeader(stream, this));
// Skip eof and zero headers
stream.Position += 16;
var offsets = headers.ToDictionary(h => h.FileOffset, h => h);
for (var i = 0; i < imageCount; i++)
{
var h = headers[i];
if (h.Format == Format.Format20)
h.RefImage = headers[i - 1];
else if (h.Format == Format.Format40 && !offsets.TryGetValue(h.RefOffset, out h.RefImage))
throw new InvalidDataException("Reference doesnt point to image data {0}->{1}".F(h.FileOffset, h.RefOffset));
}
foreach (var h in headers)
Decompress(stream, h);
spriteFrames = Exts.Lazy(() => headers.Cast<ISpriteFrame>());
}
示例4: MSCabCompression
public MSCabCompression(Stream stream)
{
this.stream = stream;
var signature = stream.ReadASCII(4);
if (signature != "MSCF")
throw new InvalidDataException("Not a Microsoft CAB package!");
stream.Position += 12;
var filesOffset = stream.ReadUInt32();
stream.Position += 6;
var folderCount = stream.ReadUInt16();
var fileCount = stream.ReadUInt16();
if (stream.ReadUInt16() != 0)
throw new InvalidDataException("Only plain packages (without reserved header space or prev/next archives) are supported!");
stream.Position += 4;
folders = new CabFolder[folderCount];
for (var i = 0; i < folderCount; i++)
{
folders[i] = new CabFolder(stream);
if (folders[i].CompressionType != 1)
throw new InvalidDataException("Compression type is not supported");
}
files = new CabFile[fileCount];
stream.Seek(filesOffset, SeekOrigin.Begin);
for (var i = 0; i < fileCount; i++)
files[i] = new CabFile(stream);
}
示例5: IsWsaD2
bool IsWsaD2(Stream s)
{
if (s.Length < 10)
return false;
var start = s.Position;
numTiles = s.ReadUInt16();
tileWidth = s.ReadUInt16();
tileHeight = s.ReadUInt16();
Delta = s.ReadUInt32();
offsets = new uint[numTiles + 1];
for (var i = 0; i <= numTiles; i++)
offsets[i] = s.ReadUInt32();
s.Position = start;
//if (offsets[numTiles] < s.Length)
// return false;
if (offsets[0] == 0)
{
numTiles -= 1;
for (var i = 1; i <= numTiles; i++)
offsets[i - 1] = offsets[i];
}
return true;
}
示例6: MixFile
public MixFile(FileSystem context, string filename)
{
Name = filename;
this.context = context;
s = context.Open(filename);
try
{
// Detect format type
var isCncMix = s.ReadUInt16() != 0;
// The C&C mix format doesn't contain any flags or encryption
var isEncrypted = false;
if (!isCncMix)
isEncrypted = (s.ReadUInt16() & 0x2) != 0;
List<PackageEntry> entries;
if (isEncrypted)
{
long unused;
entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out unused);
}
else
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
index = ParseIndex(entries.ToDictionaryWithConflictLog(x => x.Hash,
"{0} ({1} format, Encrypted: {2}, DataStart: {3})".F(filename, isCncMix ? "C&C" : "RA/TS/RA2", isEncrypted, dataStart),
null, x => "(offs={0}, len={1})".F(x.Offset, x.Length)));
}
catch (Exception)
{
Dispose();
throw;
}
}
示例7: Container
public Container(Stream stream)
{
UInt16 stringLength = stream.ReadUInt16();
Name = stream.ReadAsciiString(stringLength);
ContainerType = stream.ReadUInt8();
Flags = (ContainerFlags)stream.ReadUInt16();
PrimitiveCount = stream.ReadUInt16();
PackfileBaseOffset = stream.ReadUInt32();
CompressionType = stream.ReadUInt8();
stringLength = stream.ReadUInt16();
StubContainerParentName = stream.ReadAsciiString(stringLength);
Int32 auxDataSize = stream.ReadInt32();
AuxData = new byte[auxDataSize];
stream.Read(AuxData, 0, auxDataSize);
TotalCompressedPackfileReadSize = stream.ReadInt32();
Primitives = new List<Primitive>();
PrimitiveSizes = new List<WriteTimeSizes>();
for (UInt16 i = 0; i < PrimitiveCount; i++)
{
var sizes = stream.ReadStruct<WriteTimeSizes>();
PrimitiveSizes.Add(sizes);
}
for (UInt16 i = 0; i < PrimitiveCount; i++)
{
Primitive primitive = new Primitive(stream);
Primitives.Add(primitive);
}
}
示例8: MixFile
public MixFile(string filename, PackageHashType type, int priority)
{
this.filename = filename;
this.priority = priority;
this.type = type;
s = GlobalFileSystem.Open(filename);
// Detect format type
s.Seek(0, SeekOrigin.Begin);
var isCncMix = s.ReadUInt16() != 0;
// The C&C mix format doesn't contain any flags or encryption
var isEncrypted = false;
if (!isCncMix)
isEncrypted = (s.ReadUInt16() & 0x2) != 0;
List<PackageEntry> entries;
if (isEncrypted)
{
long unused;
entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out unused);
}
else
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
index = entries.ToDictionaryWithConflictLog(x => x.Hash,
"{0} ({1} format, Encrypted: {2}, DataStart: {3})".F(filename, (isCncMix ? "C&C" : "RA/TS/RA2"), isEncrypted, dataStart),
null, x => "(offs={0}, len={1})".F(x.Offset, x.Length)
);
}
示例9: Read
public static Chunk Read(Stream s)
{
Chunk c;
c.CompressedSize = s.ReadUInt16();
c.OutputSize = s.ReadUInt16();
if (0xdeaf != s.ReadUInt32())
throw new InvalidDataException("Chunk header is bogus");
return c;
}
示例10: ImageHeader
public ImageHeader(Stream stream, ShpReader reader)
{
this.reader = reader;
var data = stream.ReadUInt32();
FileOffset = data & 0xffffff;
Format = (Format)(data >> 24);
RefOffset = stream.ReadUInt16();
RefFormat = (Format)stream.ReadUInt16();
}
示例11: InstallShieldPackage
public InstallShieldPackage(FileSystem context, string filename)
{
Name = filename;
s = context.Open(filename);
try
{
// Parse package header
var signature = s.ReadUInt32();
if (signature != 0x8C655D13)
throw new InvalidDataException("Not an Installshield package");
s.Position += 8;
/*var FileCount = */s.ReadUInt16();
s.Position += 4;
/*var ArchiveSize = */s.ReadUInt32();
s.Position += 19;
var tocAddress = s.ReadInt32();
s.Position += 4;
var dirCount = s.ReadUInt16();
// Parse the directory list
s.Position = tocAddress;
// Parse directories
var directories = new Dictionary<string, uint>();
for (var i = 0; i < dirCount; i++)
{
// Parse directory header
var fileCount = s.ReadUInt16();
var chunkSize = s.ReadUInt16();
var nameLength = s.ReadUInt16();
var dirName = s.ReadASCII(nameLength);
// Skip to the end of the chunk
s.ReadBytes(chunkSize - nameLength - 6);
directories.Add(dirName, fileCount);
}
// Parse files
foreach (var dir in directories)
for (var i = 0; i < dir.Value; i++)
ParseFile(s, dir.Key);
}
catch
{
Dispose();
throw;
}
}
示例12: ShpD2Frame
public ShpD2Frame(Stream s)
{
var flags = (FormatFlags)s.ReadUInt16();
s.Position += 1;
var width = s.ReadUInt16();
var height = s.ReadUInt8();
Size = new Size(width, height);
// Subtract header size
var dataLeft = s.ReadUInt16() - 10;
var dataSize = s.ReadUInt16();
byte[] table;
if ((flags & FormatFlags.PaletteTable) != 0)
{
var n = (flags & FormatFlags.VariableLengthTable) != 0 ? s.ReadUInt8() : (byte)16;
table = new byte[n];
for (var i = 0; i < n; i++)
table[i] = s.ReadUInt8();
dataLeft -= n;
}
else
{
table = new byte[256];
for (var i = 0; i < 256; i++)
table[i] = (byte)i;
table[1] = 0x7f;
table[2] = 0x7e;
table[3] = 0x7d;
table[4] = 0x7c;
}
Data = new byte[width * height];
// Decode image data
var compressed = s.ReadBytes(dataLeft);
if ((flags & FormatFlags.SkipFormat80) == 0)
{
var temp = new byte[dataSize];
Format80.DecodeInto(compressed, temp);
compressed = temp;
}
Format2.DecodeInto(compressed, Data, 0);
// Lookup values in lookup table
for (var j = 0; j < Data.Length; j++)
Data[j] = table[Data[j]];
}
示例13: ReadStringFromPositionAndReset
private string ReadStringFromPositionAndReset( Stream s, uint stringPosition )
{
long pos = s.Position;
s.Position = stringPosition;
StringBuilder sb = new StringBuilder();
byte[] buffer = new byte[2];
int b = s.ReadByte();
while ( b != 0 && b != -1 ) {
if ( b == 0x01 ) {
sb.Append( '\n' );
} else if ( b == 0x02 ) {
if ( s.ReadByte() != 0x00 ) { throw new Exception( "control code 0x02 not followed by a null byte!" ); }
sb.AppendFormat( "<Voice: {0:x4}>", s.ReadUInt16() );
} else if ( b == 0x03 ) {
throw new Exception( "unknown control code 0x03" );
} else if ( b == 0x04 ) {
throw new Exception( "unknown control code 0x04" );
} else if ( ( b > 0x04 && b <= 0x80 ) || ( b >= 0xA0 && b <= 0xDF ) ) {
// is a single byte
buffer[0] = (byte)b;
sb.Append( Util.ShiftJISEncoding.GetString( buffer, 0, 1 ) );
} else {
// is two bytes
buffer[0] = (byte)b;
buffer[1] = (byte)s.ReadByte();
sb.Append( Util.ShiftJISEncoding.GetString( buffer ) );
}
b = s.ReadByte();
}
s.Position = pos;
return sb.ToString();
}
示例14: 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;
}
示例15: ParseFrames
ShpTSFrame[] ParseFrames(Stream s)
{
var start = s.Position;
s.ReadUInt16();
var width = s.ReadUInt16();
var height = s.ReadUInt16();
var size = new Size(width, height);
var frameCount = s.ReadUInt16();
var frames = new ShpTSFrame[frameCount];
for (var i = 0; i < frames.Length; i++)
frames[i] = new ShpTSFrame(s, size);
s.Position = start;
return frames;
}