public void RenderArr() { if ((Arrangement == null) || (Tileset == null)) { bmpArr = null; } else { bmpArr = new Bitmap(arrWidth << 3, arrHeight << 3, PixelFormat.Format8bppIndexed); bmpArr.CopyPalette(Palette, false); lock (bmpArr) { BitmapData bd = bmpArr.LockBits(ImageLockMode.WriteOnly); GfxProvider.RenderArrangement(bd, Arrangement, arrWidth, arrHeight, Tileset, 0, false, false); bmpArr.UnlockBits(bd); } } }
public void RenderTile() { if ((Tileset == null) || (Palette == null)) { bmpTile = null; } else { if (bmpTile == null) { bmpTile = new Bitmap(8, 8, PixelFormat.Format8bppIndexed); } lock (bmpTile) { bmpTile.CopyPalette(Palette, false); BitmapData bd = bmpTile.LockBits(ImageLockMode.WriteOnly); byte[,] pixels = Tileset.Read4BppTile(currentTile << 5); GfxProvider.RenderToBitmap(bd, pixels, 0, 0, chkFlipH.Checked, chkFlipV.Checked, palSelector.PalIndex, false); bmpTile.UnlockBits(bd); } } }
public void RenderTileset() { if (Tileset == null) { bmpTileset = null; } else { int tilecount = Tileset.Length >> 5; int w = 32; int h = (tilecount >> 2) << 3; if ((h == 0) || ((tilecount & 3) != 0)) { h += 8; } if ((bmpTileset == null) || (bmpTileset.Width != w)) { bmpTileset = new Bitmap(w, h, PixelFormat.Format8bppIndexed); } lock (bmpTileset) { bmpTileset.CopyPalette(Palette, false); BitmapData bd = bmpTileset.LockBits(ImageLockMode.WriteOnly); for (int i = 0; i < tilecount; i++) { byte[,] pixels = Tileset.Read4BppTile(i << 5); GfxProvider.RenderToBitmap(bd, pixels, (i & 3) << 3, (i >> 2) << 3, false, false, palSelector.PalIndex, false); } bmpTileset.UnlockBits(bd); } } }
private void btnImport_Click(object sender, EventArgs e) { if (dlgImport.ShowDialog() == DialogResult.OK) { Bitmap bmp = new Bitmap(dlgImport.FileName); if ((bmp.Width != (arrWidth << 3)) || (bmp.Height != (arrHeight << 3))) { MessageBox.Show("The image is the wrong size. It's " + bmp.Width + "x" + bmp.Height + ", but it should be " + (arrWidth << 3) + "x" + (arrHeight << 3) + ".", "Wrong size"); return; } // Prompt for options var f = new frmGfxImportDialog(); DialogResult res = f.ShowDialog(); if (res != DialogResult.OK) { return; } GfxImportSettings g = M3Settings.MainSettings.GfxImportSettings; try { object[] o = GfxProvider.SetArrangement(bmp, Tileset, 0, (EditLimit == -1) ? TileCount : EditLimit, g.UseTileset, g.UseFlips, g.UsePalette ? Palette.Entries[CurrentPalette] : null, g.UsePalette ? CurrentPalette : 0, g.TransparentColor, g.UseTransparency ); // Success! Arrangement = (ArrEntry[])o[0]; Palette.Entries[CurrentPalette] = (Color[])o[1]; int colorsDropped = (int)o[2]; if (colorsDropped > 0) { MessageBox.Show("There were too many colors in the image, so only the 15 most common ones were preserved." + Environment.NewLine + colorsDropped + " color(s) were dropped.", "Too many colors"); } SetPalette(Palette); RenderTileset(); RenderTile(); RenderArr(); RefreshTileset(); RefreshTile(); RefreshArr(); } catch (TileCountException ee) { MessageBox.Show("This image needs " + ee.Tilecount + " tiles, but we only have room for " + ee.Tilelimit + " tiles.", "Too many tiles"); } catch (TileMismatchException ee) { MessageBox.Show("This image contains tiles not in the current tileset." + Environment.NewLine + "The problematic tile is at (" + (ee.TileX << 3) + ", " + (ee.TileY << 3) + ").", "No tile match"); } f.Dispose(); bmp.Dispose(); } }