public void EnsureDimensions(SxzPoint boundingBox) { foreach (Frame frame in Frames) { frame.EnsureDimensions(boundingBox); } }
public static void DrawContainer(string filename, Container container) { SxzPoint boundingBox = new SxzPoint(); container.EnsureDimensions(boundingBox); DrawContainer(filename, container, boundingBox); }
public double Length(SxzPoint point) { double dx = point.X - X; double dy = point.Y - Y; return Math.Sqrt(dx * dx + dy * dy); }
public void EnsureDimensions(SxzPoint boundingBox) { foreach (Chunk chunk in Chunks) { chunk.EnsureDimensions(boundingBox); } }
public void EnsureDimensions(SxzPoint boundingBox) { if (Origin.X + Width > boundingBox.X) { boundingBox.X = Origin.X + Width; } if (Origin.Y + Height > boundingBox.Y) { boundingBox.Y = Origin.Y + Height; } }
public void Add(SxzPoint point) { if (UpperLeft.X == -1) { UpperLeft.X = point.X; } if (LowerRight.X == -1) { LowerRight.X = point.X; } if (UpperLeft.Y == -1) { UpperLeft.Y = point.Y; } if (LowerRight.Y == -1) { LowerRight.Y = point.Y; } if (point.X < UpperLeft.X) { UpperLeft.X = point.X; } if (point.X > LowerRight.X) { LowerRight.X = point.X; } if (point.Y < UpperLeft.Y) { UpperLeft.Y = point.Y; } if (point.Y > LowerRight.Y) { LowerRight.Y = point.Y; } }
public BackgroundChunk() { Origin = new SxzPoint(); }
public Chunk GetSelected(int x, int y) { for (int i = this.Frames.Count - 1; i >= 0; i--) { Frame frame = this.Frames[i]; var boundingBox = new SxzPoint(0, 0); frame.EnsureDimensions(boundingBox); Chunk chunk = frame.GetSelected(x, y); if (chunk != null) { return chunk; } } return null; }
public Location(int x, int y) { Point = new SxzPoint(x, y); }
public BoundingBox(BoundingBox input) { UpperLeft = new SxzPoint(input.UpperLeft.X, input.UpperLeft.Y); LowerRight = new SxzPoint(input.LowerRight.X, input.LowerRight.Y); }
public BoundingBox() { UpperLeft = new SxzPoint(-1, -1); LowerRight = new SxzPoint(-1, -1); }
private static BoundingBox GrowOnes(SxzPoint upperLeft, BoundingBox boundingBox, bool[,] boolArray) { SxzPoint lowerRight = new SxzPoint(upperLeft.X, upperLeft.Y); BoundingBox best = new BoundingBox(); best.UpperLeft = upperLeft; best.LowerRight = upperLeft; int maxX = boundingBox.LowerRight.X; int y = upperLeft.Y - 1; while ((y + 1) < (boundingBox.LowerRight.Y + 1) && boolArray[upperLeft.X, y + 1]) { y++; int x = upperLeft.X; while ((x + 1) <= maxX && boolArray[x + 1, y]) { x++; } maxX = x; BoundingBox candidate = new BoundingBox(); candidate.UpperLeft = upperLeft; candidate.LowerRight.X = x; candidate.LowerRight.Y = y; if (candidate.Area() > best.Area()) { best = candidate; } } return best; }
public static void DrawContainer(string filename, Container container, SxzPoint boundingBox) { bool[,] drawable = new bool[boundingBox.X, boundingBox.Y]; Color transparent = Color.Transparent; using (Bitmap drawableSurface = new Bitmap(boundingBox.X, boundingBox.Y, PixelFormat.Format32bppArgb)) { drawableSurface.MakeTransparent(transparent); using (Graphics graphics = Graphics.FromImage(drawableSurface)) { graphics.Clear(transparent); //debug color of green for now SolidBrush brush = new SolidBrush(Color.Green); //graphics.FillRectangle(brush, 0, 0, boundingBox.X, boundingBox.Y); foreach (Frame frame in container.Frames) { foreach (Chunk chunk in frame.Chunks) { if (chunk.IsPalette()) { continue; } if (chunk.IsBackground()) { brush.Color = GetColor(chunk.GetColor(0, 0)); graphics.FillRectangle(brush, 0, 0, boundingBox.X, boundingBox.Y); continue; } SxzPoint dimensions = chunk.GetDimensions(); SxzPoint origin = chunk.Origin; for (int y = origin.Y; y < origin.Y + dimensions.Y; y++) { for (int x = origin.X; x < origin.X + dimensions.X; x++) { SxzColor sxzColor = chunk.GetColor(x, y); if (sxzColor == null) { //For chunks with bitplanes, this means don't drawn on this pixel even though it is within //the region of the chunk continue; } if (chunk.IsTransparent()) { drawableSurface.SetPixel(x, y, transparent); continue; } Color color = GetColor(sxzColor); if (color == null) { continue; } drawable[x, y] = true; brush.Color = color; graphics.FillRectangle(brush, x, y, 1, 1); } } } } Image outputImage = (Image)drawableSurface; outputImage.Save(filename, ImageFormat.Png); } } }
public void EnsureDimensions(SxzPoint boundingBox) { }
public Location() { Point = new SxzPoint(); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Usage: SxzAppend <sxzfilepath1> <sxzfilepath2>"); return; } string filename1 = args[0]; if (!File.Exists(filename1)) { Console.WriteLine("Failed to find file " + filename1); return; } byte[] byteData = Helper.ReadBytesFromFile(filename1); Console.WriteLine("Read in size for file1 is " + byteData.Length); Container container = new Container(); container.SetData(byteData); SxzPoint dimensions = new SxzPoint(); container.EnsureDimensions(dimensions); dimensions.X = (int)(dimensions.X / 2); dimensions.Y = (int)(dimensions.Y / 2); string filename2 = args[1]; if (!File.Exists(filename2)) { Console.WriteLine("Failed to find file " + filename2); return; } byteData = Helper.ReadBytesFromFile(filename2); Console.WriteLine("Read in size for file2 is " + byteData.Length); Container container2 = new Container(); container2.SetData(byteData); SxzPoint dimensions2 = new SxzPoint(); container2.EnsureDimensions(dimensions2); dimensions.X = dimensions.X - (int)(dimensions2.X / 2); dimensions.Y = dimensions.Y - (int)(dimensions2.Y / 2); foreach (Frame frame in container2.Frames) { foreach (Chunk chunk in frame.Chunks) { if (chunk.Origin == null) { continue; } chunk.Origin.X = chunk.Origin.X + dimensions.X; chunk.Origin.Y = chunk.Origin.Y + dimensions.Y; } } container.Frames.AddRange(container2.Frames); byte[] output = container.GetData(); Console.WriteLine("Output byte total is " + output.Length); Helper.WriteBytesToFile("appendoutput.sxz", output); File.WriteAllText("appendoutput.sxz.txt", Print.GetString(container)); Helper.DrawContainer("appendoutput.png", container); }
public Chunk GetSelected(int x, int y) { for (int i = this.Chunks.Count - 1; i >= 0; i--) { Chunk chunk = this.Chunks[i]; if (chunk.IsPalette()) { continue; } if (chunk.IsBackground()) { continue; } SxzPoint boundingBox = new SxzPoint(0, 0); SxzPoint origin = chunk.Origin; chunk.EnsureDimensions(boundingBox); if (x >= origin.X && y >= origin.Y && x < (boundingBox.X) && y < (boundingBox.Y)) { if (chunk.GetColor(x, y) != null) { return chunk; } } } return null; }