public PicCommand(PicOpCode opcode) { OpCode = opcode; if (SCIPicture.LOG) { Console.WriteLine($"Code {opcode}"); } }
public SCIPicture(byte[] data) { commands = new List <PicCommand>(); using (var stream = new MemoryStream(data.Length)) { stream.Write(data, 0, data.Length); stream.Seek(0, SeekOrigin.Begin); PicOpCode opcode = 0; while (true) { var b = stream.Peek(); if (b >= 0xf0) { opcode = (PicOpCode)b; stream.Seek(1, SeekOrigin.Current); } switch (opcode) { case PicOpCode.DISABLE_VISUAL: case PicOpCode.DISABLE_PRIORITY: case PicOpCode.DISABLE_CONTROL: commands.Add(new PicCommand(opcode)); break; case PicOpCode.SET_COLOR: case PicOpCode.SET_CONTROL: case PicOpCode.SET_PRIORITY: case PicOpCode.SET_PATTERN: commands.Add(new PicCommand(opcode, stream.ReadBytes(1))); break; case PicOpCode.RELATIVE_MEDIUM_LINES: ReadRelativeMediumLines(stream); break; case PicOpCode.RELATIVE_LONG_LINES: ReadRelativeLongLines(stream); break; case PicOpCode.RELATIVE_SHORT_LINES: ReadRelativeShortLines(stream); break; case PicOpCode.FILL: commands.Add(new PicCommand(opcode, stream.ReadBytes(3))); break; case PicOpCode.OPX: ReadExt(stream); break; case PicOpCode.END: commands.Add(new PicCommand(opcode)); return; default: #if DEBUG Debugger.Break(); #endif throw new FormatException($"Unsupported opcode {opcode}"); } } } }
public PicCommand(PicOpCode opcode, byte[] args) { OpCode = opcode; Args = args; if (SCIPicture.LOG) { Console.WriteLine($"Code {opcode} len: {Args.Length}"); } }
public byte[] GetBytes() { PicOpCode prev = 0; ByteBuilder bb = new ByteBuilder(); foreach (var cmd in commands) { if (cmd.OpCode != prev || cmd.OpCode == PicOpCode.OPX) { bb.AddByte((byte)cmd.OpCode); } cmd.Write(bb); prev = cmd.OpCode; } return(bb.GetArray()); }