static void ProcessPacked(GifPacket packet, GsProcessor processor) { DataReader reader = new DataReader(packet.Data); if (!packet.IgnorePrimField) { throw new NotSupportedException("Unsupported PRIM field"); } for (int i = 0; i < packet.Loops; i++) { foreach (var register in packet.Registers) { switch (register) { case GifRegisters.APlusD: ulong data = reader.ReadUInt64(); byte regAddress = (byte)(reader.ReadUInt64() & 0xFF); processor.AddOperation(regAddress, data); break; default: throw new NotSupportedException("Unsupported register"); } } } }
public GifPacketList Convert(BinaryFormat source) { GifPacketList packets = new GifPacketList(); DataReader reader = new DataReader(source.Stream); while (!source.Stream.EndOfStream) { GifPacket packet = new GifPacket(); ushort flags1 = reader.ReadUInt16(); packet.Loops = (short)(flags1 & 0x7FFF); packet.FinalPacket = (flags1 >> 15) == 1; reader.ReadUInt16(); // Reserved uint flags2 = reader.ReadUInt32(); packet.IgnorePrimField = ((flags2 >> 15) & 1) == 0; packet.Prim = (short)((flags2 >> 16) & 0x3FF); packet.Kind = (GifPacketKind)((flags2 >> 26) & 0x3); int numRegisters = (int)((flags2 >> 28) & 0xF); if (numRegisters == 0) { numRegisters = 16; } packet.Registers = new GifRegisters[numRegisters]; ulong registers = reader.ReadUInt64(); for (int i = 0; i < numRegisters; i++) { packet.Registers[i] = (GifRegisters)((registers >> (i * 4)) & 0xF); } int dataSize = 0; switch (packet.Kind) { case GifPacketKind.Packed: dataSize = numRegisters * packet.Loops * 16; break; case GifPacketKind.RegList: dataSize = numRegisters * packet.Loops * 8; break; case GifPacketKind.Image: dataSize = packet.Loops * 16; break; } packet.Data = new DataStream(source.Stream, source.Stream.Position, dataSize); source.Stream.Seek(dataSize, SeekMode.Current); packets.AddPacket(packet); } return(packets); }
static void ProcessImage(GifPacket packet, GsProcessor processor) { DataReader reader = new DataReader(packet.Data); for (int i = 0; i < packet.Loops; i++) { processor.AddOperation(0x54, reader.ReadUInt64()); processor.AddOperation(0x54, reader.ReadUInt64()); } }
public void AddPacket(GifPacket packet) { packets.Add(packet); }