private static SMXLayerHeader ReadSMXLayerHeader(BinaryReader reader) { var width = reader.ReadUInt16(); var height = reader.ReadUInt16(); var anchorX = reader.ReadInt16(); var anchorY = reader.ReadInt16(); var layerLength = reader.ReadUInt32(); var _ = reader.ReadUInt32(); var smxLayerHeader = new SMXLayerHeader { Width = width, Height = height, AnchorX = anchorX, AnchorY = anchorY, LayerLength = layerLength }; if (IsVerbose) { Console.WriteLine("\tLayer Header"); Console.WriteLine("\t{0}", new string('-', Repeat)); Console.WriteLine("\tSize : {0} x {1} ({2}, {3})", smxLayerHeader.Width, smxLayerHeader.Height, smxLayerHeader.AnchorX, smxLayerHeader.AnchorY); Console.WriteLine("\tLayer Length : {0}", smxLayerHeader.LayerLength); Console.WriteLine("\tUnknown : {0}", _); Console.WriteLine("\t{0}", new string('-', Repeat)); } return(smxLayerHeader); }
private static IList <SMXLayerRowEdge> ReadSMXLayerRowEdgeArray(SMXLayerHeader header, BinaryReader reader) { var result = new List <SMXLayerRowEdge>(); for (int i = 0; i < header.Height; i++) { result.Add(ReadSMXLayerRowEdge(reader, header.Width)); } return(result); }
private static SMXGraphics ReadOutline(SMXLayerHeader header, IList <SMXLayerRowEdge> rowEdges, BinaryReader reader) { var unifiedArrayLength = reader.ReadUInt32(); var unifiedArray = reader.ReadBytes((int)unifiedArrayLength); if (IsVerbose) { Console.WriteLine("\t\tOutline Layer"); Console.WriteLine("\t\t{0}", new string('-', Repeat)); Console.WriteLine("\t\tUnified Array Length : {0}", unifiedArrayLength); Console.WriteLine("\t\t{0}", new string('-', Repeat)); } var x = rowEdges[0].LeftSpacing; var y = 0; using (var br = new BinaryReader(new MemoryStream(unifiedArray))) { var result = new Bitmap(header.Width, header.Height); for (int i = 0; i < unifiedArray.Length; i++) { if (rowEdges[y].IsEmpty()) { // Todo: Draw Transparent Line! x = rowEdges[++y].LeftSpacing; continue; } if (x == 0 && (rowEdges[y].LeftSpacing != 0 || rowEdges[y].RightSpacing != 0)) { // Todo: Draw Transparent 'Spacing'! } var command = br.ReadByte(); var opCode = (SMXCommandOpCode)(command & 0b00000011); var payload = (command >> 2) + 1; switch (opCode) { case SMXCommandOpCode.Draw: { if (IsVerbose) { Console.WriteLine("\t\t\t[{0,3}] : Draw ({1,3} -> {2,3})", command, x, x + payload); } for (int k = 0; k < payload; k++) { result.SetPixel(x, y, Color.Blue); x += 1; } break; } case SMXCommandOpCode.Skip: { if (IsVerbose) { Console.WriteLine("\t\t\t[{0,3}] : Skip ({1,3} -> {2,3})", command, x, x + payload); } for (int k = 0; k < payload; k++) { result.SetPixel(x, y, Color.Transparent); x += 1; } break; } case SMXCommandOpCode.End: { if (IsVerbose) { Console.WriteLine("\t\t\t[{0,3}] : End", command); } if (i + 1 < unifiedArray.Length) { x = rowEdges[++y].LeftSpacing; } break; } default: { throw new InvalidDataException(); } } } if (IsVerbose) { Console.WriteLine("\t\t\t{0}", new string('-', Repeat)); } return(new SMXGraphics { CommandData = null, PixelData = unifiedArray, Image = result, }); } }
private static SMXGraphics ReadGraphics(SMXLayerHeader header, int paletteIndex, SMXFrameCompression compression, IList <SMXLayerRowEdge> rowEdges, BinaryReader reader) { var commandLength = reader.ReadUInt32(); var pixelsLength = reader.ReadUInt32(); var commands = reader.ReadBytes((int)commandLength); var pixels = reader.ReadBytes((int)pixelsLength); var decoder = new SMXPixelDecoder(pixels, paletteIndex, compression); if (IsVerbose) { Console.WriteLine("\t\tGraphics Layer"); Console.WriteLine("\t\t{0}", new string('-', Repeat)); Console.WriteLine("\t\tCommand Length : {0}", commandLength); Console.WriteLine("\t\tPixels Length : {0}", pixelsLength); Console.WriteLine("\t\t\tCommand Array"); Console.WriteLine("\t\t\t{0}", new string('-', Repeat)); } var x = rowEdges[0].LeftSpacing; var y = 0; using (var brc = new BinaryReader(new MemoryStream(commands))) using (var brp = new BinaryReader(new MemoryStream(pixels))) { var result = new Bitmap(header.Width, header.Height); for (int i = 0; i < commands.Length; i++) { if (rowEdges[y].IsEmpty()) { // Todo: Draw Transparent Line! x = rowEdges[++y].LeftSpacing; continue; } if (rowEdges[y].LeftSpacing != 0 || rowEdges[y].RightSpacing != 0) { // Todo: Draw Transparent 'Spacing'! } var command = brc.ReadByte(); var opCode = (SMXCommandOpCode)(command & 0b00000011); var payload = (command >> 2) + 1; switch (opCode) { case SMXCommandOpCode.Draw: { if (IsVerbose) { Console.WriteLine("\t\t\t[{0,3}] : Draw ({1,3} -> {2,3})", command, x, x + payload); } for (int k = 0; k < payload; k++) { result.SetPixel(x, y, decoder.Next()); x += 1; } break; } case SMXCommandOpCode.Player: { if (IsVerbose) { Console.WriteLine("\t\t\t[{0,3}] : Player ({1,3} -> {2,3})", command, x, x + payload); } for (int k = 0; k < payload; k++) { decoder.Next(); result.SetPixel(x, y, Color.Blue); x += 1; } break; } case SMXCommandOpCode.Skip: { if (IsVerbose) { Console.WriteLine("\t\t\t[{0,3}] : Skip ({1,3} -> {2,3})", command, x, x + payload); } for (int k = 0; k < payload; k++) { result.SetPixel(x, y, Color.Transparent); x += 1; } break; } case SMXCommandOpCode.End: { if (IsVerbose) { Console.WriteLine("\t\t\t[{0,3}] : End", command); } if (i + 1 < commands.Length) { x = rowEdges[++y].LeftSpacing; } break; } default: { throw new InvalidDataException(); } } } if (IsVerbose) { Console.WriteLine("\t\t\t{0}", new string('-', Repeat)); } return(new SMXGraphics { CommandData = commands, PixelData = pixels, Image = result, }); } }