/// <summary> /// Gets the graphics. /// </summary> /// <param name="z">The z.</param> /// <returns>An array of uint.</returns> public BitmapBuffer GetGraphics(Zoom z) { if (Width == 0 || Height == 0) { return(null); } if (RequireRefresh) { RequireRefresh = false; _ = Parallel.ForEach(bitmaps, b => { b.Value.SetDirty(true); }); } int lenght = Width * Height * z * z; if (!bitmaps.ContainsKey(z)) { bitmaps.TryAdd(z, new DirtyBitmap(BitmapBuffer.CreateInstance(Width * z, Height * z, BytesPerColor))); } DirtyBitmap d = bitmaps[z]; if (d.IsDirty) { if (d.Bitmap.Length < lenght) { d.Bitmap = BitmapBuffer.CreateInstance(Width * z, Height * z, BytesPerColor); } foreach (TileMask t in tiles) { d.Bitmap.DrawBitmapBuffer(t.GetGraphics(z), (t.X - Left) * z, (t.Y - Top) * z); } d.SetDirty(false); } return(bitmaps[z].Bitmap); }
public unsafe override void Load(string path, int offset) { Bitmap bp = new Bitmap(path); Int32[,] Bits = PaletteProcessor.BitmapToIntArray(bp); PaletteProcessor.RoundColor5BitsPerChannel(Bits); ColorReductor.ReduceColorsFromBitmap <UnityColorPalette, UnityColorPaletteIndex>(15, Bits); var ts = TileProcessor.GetUniqueTilesPositions(Bits, tileSize.Width, tileSize.Height); UnityColorPalette[] pals = PaletteProcessor.ExtractPalettesFromBitmap <UnityColorPalette, UnityColorPaletteIndex>(Bits, ts.Item1, tileSize.Width, tileSize.Height, 15); var tiles = TileProcessor.GetTiles <UnityColorPalette, IndexedBitmapBufferDisguise>(pals, ts.Item1, ts.Item2, Bits, tileSize.Width, tileSize.Height); int w = bp.Width; int h = bp.Height; foreach (var kvp in tiles) { BitmapBuffer bf = BitmapBuffer.CreateInstance(w, h, pals[0].RealObject.BytesPerColor); Int32[] retbp = new Int32[w * h]; GCHandle BitsHandle = GCHandle.Alloc(retbp, GCHandleType.Pinned); Bitmap finishedBP = new Bitmap(w, h, w * 4, PixelFormat.Format32bppArgb, BitsHandle.AddrOfPinnedObject()); byte[] ret = new byte[retbp.Length * 4]; foreach (var t in kvp.Value) { BitmapBuffer bpb = t.Item4.RealObject.CreateBitmapBuffer(Flip.GetFlip(t.Item2, t.Item3), pals[kvp.Key].RealObject); bf.DrawBitmapBuffer(bpb, t.Item1.X * tileSize.Width, t.Item1.Y * tileSize.Height); } unsafe { fixed(byte *bs = ret) { bf.CopyTo(bs, 0, w - 1, 0, h - 1, 0, 0, 0, 0); } } Buffer.BlockCopy(ret, 0, retbp, 0, ret.Length); finishedBP.Save(Path.GetFileNameWithoutExtension(path) + kvp.Key.Value + ".png", ImageFormat.Png); } }