/// <summary> /// Use the meadow graphics library to draw the expressive pixels - P Frame /// </summary> private void Display(PFrameDef pfd, ushort xPos, ushort yPos, ushort zoom) { int x = xPos; int y = yPos; foreach (var p in pfd.Pix) { if (zoom == 1) { x = xPos + p.X; y = yPos + p.Y; graphics.DrawPixel(x, y, Pallette[p.Pal]); } else if (zoom == 2 || zoom == 3) { x = xPos + p.X * zoom; y = yPos + p.Y * zoom; graphics.Stroke = zoom; graphics.DrawLine(x, y, x + zoom - 1, y, Pallette[p.Pal]); } else { x = xPos + p.X * zoom; y = yPos + p.Y * zoom; graphics.DrawRectangle(x, y, zoom, zoom, Pallette[p.Pal], true); } } }
/// <summary> /// The P Frame addresses specific pixels - but encodes the position in a single byte - or in 2 bytes /// for 8bit - Row is in the high nybble, column is in the low nybble /// </summary> /// <param name="f">P Framedef</param> /// <returns>Parsed PFrame</returns> private PFrameDef GetPFrame(FrameDef f) { PFrameDef result = new PFrameDef() { Pix = new List <PFrameItem>() }; bool b8 = (f.Count * 4 == f.Data.Length); if (b8) { Console.WriteLine($" PFrame 8 bit position"); } else { Console.WriteLine($" PFrame 16 bit position"); } if (f.Type != FrameType.P) { return(result); } for (int i = 0; i < f.Count; i++) { PFrameItem item = new PFrameItem(); if (b8) { item.Y = byte.Parse(f.Data.Substring(i * 4, 1), NumberStyles.AllowHexSpecifier); item.X = byte.Parse(f.Data.Substring(i * 4 + 1, 1), NumberStyles.AllowHexSpecifier); item.Pal = byte.Parse(f.Data.Substring(i * 4 + 2, 2), NumberStyles.AllowHexSpecifier); //Console.WriteLine($"{item.X},{item.Y} = {item.Pal}"); } else // long 256 bits per line ? { var y = byte.Parse(f.Data.Substring(i * 6, 2), NumberStyles.AllowHexSpecifier); var x = byte.Parse(f.Data.Substring(i * 6 + 2, 2), NumberStyles.AllowHexSpecifier); // we know the width/height if we had an Iframe - or assume 18x18 ? item.Y = (byte)((x + y * 256) / Width); item.X = (byte)((x + y * 256) % Width); item.Pal = byte.Parse(f.Data.Substring(i * 6 + 4, 2), NumberStyles.AllowHexSpecifier); //Console.WriteLine($"{item.X},{item.Y} = {item.Pal} {f.Data.Substring(i * 6 + 2, 2)},{f.Data.Substring(i * 6, 2)}={f.Data.Substring(i * 6 + 4, 2)}"); } result.Pix.Add(item); } return(result); }