internal static AniHeaderChunkContent Parse(BinaryReader reader) { var result = new AniHeaderChunkContent { HeaderSize = reader.ReadUInt32(), NumFrames = reader.ReadUInt32(), NumSteps = reader.ReadUInt32(), FrameWidth = reader.ReadUInt32(), FrameHeight = reader.ReadUInt32(), BitCount = reader.ReadUInt32(), NumPlanes = reader.ReadUInt32(), DefaultFrameDisplayRate = reader.ReadUInt32(), }; var attributes = reader.ReadUInt32(); result.FrameType = (attributes & 0x1) == 1 ? AniFrameType.IconOrCursorData : AniFrameType.RawData; result.FileContainsSequenceData = ((attributes >> 1) & 0x1) == 1; if (result.FrameType == AniFrameType.RawData) { throw new NotSupportedException(); } return(result); }
internal static RiffChunk Parse(BinaryReader reader) { var chunkType = reader.ReadFourCc(); var chunkSize = reader.ReadUInt32(); var endPosition = reader.BaseStream.Position + chunkSize; // If this is the RIFF chunk, the chunk size includes the chunk type and chunk size values. if (chunkType == "RIFF") { endPosition -= 8; } RiffChunkContent content; switch (chunkType) { case "RIFF": case "LIST": content = RiffChunkList.Parse(reader, endPosition); break; case "INAM": case "IART": content = InfoChunkContent.Parse(reader); break; case "anih": content = AniHeaderChunkContent.Parse(reader); break; case "rate": content = RateChunkContent.Parse(reader, endPosition); break; case "seq ": content = SequenceChunkContent.Parse(reader, endPosition); break; case "icon": content = IconChunkContent.Parse(reader, endPosition); break; default: throw new InvalidDataException($"Chunk type not supported: {chunkType}"); } if (reader.BaseStream.Position != endPosition) { throw new InvalidDataException(); } if (chunkSize % 2 != 0) { // Pad byte. reader.ReadByte(); } return(new RiffChunk { ChunkType = chunkType, Size = chunkSize, Content = content }); }