/// <summary> /// Comparison function for sorting bitmaps by size. /// </summary> static int CompareBitmapSizes(ArrangedBitmap a, ArrangedBitmap b) { int aSize = a.Height * 1024 + a.Width; int bSize = b.Height * 1024 + b.Width; return bSize.CompareTo(aSize); }
public static UnsafeBitmap PackBitmaps(Vex.VexObject vo, Dictionary<uint, Rectangle> outputBitmaps) { Gdi.GdiRenderer renderer = new Gdi.GdiRenderer(); Dictionary<uint, Bitmap> sourceBitmaps = renderer.GenerateMappedBitmaps(vo, true); if (sourceBitmaps.Count == 0) { throw new Exception("There are no symbols to arrange"); } List<ArrangedBitmap> bitmaps = new List<ArrangedBitmap>(); foreach (uint key in sourceBitmaps.Keys) { Vex.IDefinition def = vo.Definitions[key]; Bitmap sbmp = sourceBitmaps[key]; ArrangedBitmap bitmap = new ArrangedBitmap(); bitmap.Width = sbmp.Width + 2; bitmap.Height = sbmp.Height + 2; bitmap.Id = def.Id; bitmaps.Add(bitmap); } Size bmpSize = ProcessRectangles(bitmaps); return CopyBitmapsToOutput(bitmaps, sourceBitmaps, outputBitmaps, bmpSize.Width, bmpSize.Height); }
/// <summary> /// Comparison function for sorting bitmaps by size. /// </summary> static int CompareBitmapSizes(ArrangedBitmap a, ArrangedBitmap b) { int aSize = a.Height * 1024 + a.Width; int bSize = b.Height * 1024 + b.Width; return(bSize.CompareTo(aSize)); }
public static UnsafeBitmap PackBitmaps(Vex.VexObject vo, Dictionary <uint, Rectangle> outputBitmaps) { Gdi.GdiRenderer renderer = new Gdi.GdiRenderer(); Dictionary <uint, Bitmap> sourceBitmaps = renderer.GenerateMappedBitmaps(vo, true); if (sourceBitmaps.Count == 0) { throw new Exception("There are no symbols to arrange"); } List <ArrangedBitmap> bitmaps = new List <ArrangedBitmap>(); foreach (uint key in sourceBitmaps.Keys) { Vex.IDefinition def = vo.Definitions[key]; Bitmap sbmp = sourceBitmaps[key]; ArrangedBitmap bitmap = new ArrangedBitmap(); bitmap.Width = sbmp.Width + 2; bitmap.Height = sbmp.Height + 2; bitmap.Id = def.Id; bitmaps.Add(bitmap); } Size bmpSize = ProcessRectangles(bitmaps); return(CopyBitmapsToOutput(bitmaps, sourceBitmaps, outputBitmaps, bmpSize.Width, bmpSize.Height)); }
public static UnsafeBitmap PackBitmaps(Dictionary<uint, string> sourceBitmapPaths, Dictionary<uint, Rectangle> outputBitmaps) { if (sourceBitmapPaths.Count == 0) { throw new Exception("There are no bitmaps to arrange"); } List<Bitmap> sourceBitmaps = new List<Bitmap>(sourceBitmapPaths.Count); List<ArrangedBitmap> bitmaps = new List<ArrangedBitmap>(); //for (int i = 0; i < sourceBitmapPaths.Count; i++) int index = 0; foreach(KeyValuePair<uint, string> pair in sourceBitmapPaths) { ArrangedBitmap bitmap = new ArrangedBitmap(); sourceBitmaps.Add(new Bitmap(pair.Value)); bitmap.Width = sourceBitmaps[index].Width + 2; bitmap.Height = sourceBitmaps[index].Height + 2; bitmap.Index = index; bitmap.Id = pair.Key; bitmaps.Add(bitmap); index++; } // Sort so the largest bitmaps get arranged first. bitmaps.Sort(CompareBitmapSizes); // Work out how big the output bitmap should be. int outputWidth = GuessOutputWidth(bitmaps); int outputHeight = 0; int totalBitmapSize = 0; // Choose positions for each bitmap, one at a time. for (int i = 0; i < bitmaps.Count; i++) { PositionBitmap(bitmaps, i, outputWidth); outputHeight = Math.Max(outputHeight, bitmaps[i].Y + bitmaps[i].Height); totalBitmapSize += bitmaps[i].Width * bitmaps[i].Height; } // Sort the bitmaps back into index order. bitmaps.Sort(CompareBitmapIndices); Console.WriteLine("Packed {0} bitmaps into a {1}x{2} sheet, {3}% efficiency", bitmaps.Count, outputWidth, outputHeight, totalBitmapSize * 100 / outputWidth / outputHeight); return CopyBitmapsToOutput(bitmaps, sourceBitmaps, outputBitmaps, outputWidth, outputHeight); }
public static UnsafeBitmap PackBitmaps(Dictionary<uint, string> sourceBitmapPaths, Dictionary<uint, Rectangle> outputBitmaps) { if (sourceBitmapPaths.Count == 0) { throw new Exception("There are no bitmaps to arrange"); } Dictionary<uint, Bitmap> sourceBitmaps = new Dictionary<uint, Bitmap>(); List<ArrangedBitmap> bitmaps = new List<ArrangedBitmap>(); foreach (KeyValuePair<uint, string> pair in sourceBitmapPaths) { ArrangedBitmap bitmap = new ArrangedBitmap(); uint id = pair.Key; sourceBitmaps.Add(id, new Bitmap(pair.Value)); bitmap.Width = sourceBitmaps[id].Width + 2; bitmap.Height = sourceBitmaps[id].Height + 2; bitmap.Id = id; bitmaps.Add(bitmap); } Size bmpSize = ProcessRectangles(bitmaps); return CopyBitmapsToOutput(bitmaps, sourceBitmaps, outputBitmaps, bmpSize.Width, bmpSize.Height); }
public static UnsafeBitmap PackBitmaps(Dictionary <uint, string> sourceBitmapPaths, Dictionary <uint, Rectangle> outputBitmaps) { if (sourceBitmapPaths.Count == 0) { throw new Exception("There are no bitmaps to arrange"); } Dictionary <uint, Bitmap> sourceBitmaps = new Dictionary <uint, Bitmap>(); List <ArrangedBitmap> bitmaps = new List <ArrangedBitmap>(); foreach (KeyValuePair <uint, string> pair in sourceBitmapPaths) { ArrangedBitmap bitmap = new ArrangedBitmap(); uint id = pair.Key; sourceBitmaps.Add(id, new Bitmap(pair.Value)); bitmap.Width = sourceBitmaps[id].Width + 2; bitmap.Height = sourceBitmaps[id].Height + 2; bitmap.Id = id; bitmaps.Add(bitmap); } Size bmpSize = ProcessRectangles(bitmaps); return(CopyBitmapsToOutput(bitmaps, sourceBitmaps, outputBitmaps, bmpSize.Width, bmpSize.Height)); }
/// <summary> /// Comparison function for sorting bitmaps by their original indices. /// </summary> static int CompareBitmapIndices(ArrangedBitmap a, ArrangedBitmap b) { return a.Index.CompareTo(b.Index); }