private void Flip(FlipType flipType) { if (DraggedTiles != null) { Defloat(DraggedTiles); } if (overlay.SelectTS.Empty) { return; } int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; CopyBuffer buffer = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] copiedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { copiedTiles[y * (overlay.SelectTS.Width / 16) + x] = Tileset.Tilesets_tiles[Layer][(y + y_) * 16 + x + x_].Copy(); } } if (flipType == FlipType.Horizontal) { Do.FlipHorizontal(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } else if (flipType == FlipType.Vertical) { Do.FlipVertical(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } buffer.Tiles = copiedTiles; Defloat(buffer); }
private void ImportTilemap(byte[] array, int layer, int offset) { if (!checkBox4.Checked || tilemap.Tilemaps_tiles[layer] == null) { return; } int counter = 0; int extratiles = 256; bool mirror, invert; for (int i = 0; i < tilemap.Tilemaps_tiles[layer].Length; i++) { int tile = Bits.GetShort(array, offset) & 0x1FF; mirror = Bits.GetBit(array, offset + 1, 6); invert = Bits.GetBit(array, offset + 1, 7); tilemap.Tilemaps_tiles[layer][i] = tileset.Tilesets_tiles[layer][tile]; if (layer != 2) { Bits.SetShort(tilemap.Tilemaps_bytes[layer], counter, tile); counter += 2; offset += 2; } else { tilemap.Tilemaps_bytes[layer][counter] = (byte)tile; counter++; offset += 2; } if (tileset.Tilesets_tiles[layer] == null || tileset.Tilesets_tiles[layer].Length != 512) { continue; } if (mirror || invert) { Tile copy = tileset.Tilesets_tiles[layer][tile].Copy(); if (mirror) { Do.FlipHorizontal(copy); } if (invert) { Do.FlipVertical(copy); } Tile contains = Do.Contains(tileset.Tilesets_tiles[layer], copy); if (contains == null) { tileset.Tilesets_tiles[layer][extratiles] = copy; tileset.Tilesets_tiles[layer][extratiles].Index = extratiles; tilemap.Tilemaps_tiles[layer][i] = tileset.Tilesets_tiles[layer][extratiles]; Bits.SetShort(tilemap.Tilemaps_bytes[layer], counter - 2, extratiles); extratiles++; } else { tilemap.Tilemaps_tiles[layer][i] = tileset.Tilesets_tiles[layer][contains.Index]; Bits.SetShort(tilemap.Tilemaps_bytes[layer], counter - 2, contains.Index); } } } }
private void buttonInvertTile_Click(object sender, EventArgs e) { Do.FlipVertical(tile); LoadSubtileProperties(); SetTileImage(); SetSubtileImage(); if (autoUpdate.Checked) { updater.UpdateTile(); } }
/// <summary> /// Creates a new instance of a generic 8x8 subtile. /// </summary> /// <param name="index">The index of the subtile in the BPP graphics.</param> /// <param name="graphics">The source BPP graphics to read from.</param> /// <param name="offset">The offset of the BPP graphics to start reading from.</param> /// <param name="palette">The RGB palette to use.</param> /// <param name="mirror">The subtile will be flipped horizontally.</param> /// <param name="invert">The subtile will be flipped vertically.</param> /// <param name="priority1">The subtile will have priority 1 status in a map's layers.</param> /// <param name="twoBPP">The source graphics are in 2bpp format.</param> public Subtile(int index, byte[] graphics, int offset, int[] palette, bool mirror, bool invert, bool priority1, bool twoBPP) { this.Mirror = mirror; this.Invert = invert; this.Priority1 = priority1; this.Index = index; this.TwoBPP = twoBPP; // Initialize RGB arrays this.Pixels = new int[64]; this.Colors = new int[64]; // Convert SNES 4bpp to pixel array if (twoBPP == false) { // Read all 8 rows of color indexes for (int r = 0; r < 8; r++) { // Get 8 color indexes in a row byte[] row = new byte[8]; for (int i = 7, b = 1; i >= 0; i--, b *= 2) { if ((graphics[offset + r * 2 + 0x11] & b) == b) { row[i] += 8; } } for (int i = 7, b = 1; i >= 0; i--, b *= 2) { if ((graphics[offset + r * 2 + 0x10] & b) == b) { row[i] += 4; } } for (int i = 7, b = 1; i >= 0; i--, b *= 2) { if ((graphics[offset + r * 2 + 1] & b) == b) { row[i] += 2; } } for (int i = 7, b = 1; i >= 0; i--, b *= 2) { if ((graphics[offset + r * 2] & b) == b) { row[i]++; } } // Paint pixels using RGB palette and color indexes for (int c = 0; c < 8; c++) { Colors[r * 8 + c] = row[c]; // Set RGB pixel value to RGB color in palette if (row[c] != 0) { Pixels[r * 8 + c] = palette[row[c]]; // Color index in palette } } } } // Convert SNES 2bpp to pixel array else { byte b1, b2, t1, t2, col = 0; // Convert to 4-color palette int[] pal = new int[4]; for (int i = 0; i < 4; i++) { pal[i] = palette[i]; } // Read all 8 rows of color indexes for (byte i = 0; i < 8; i++) { b1 = graphics[offset]; b2 = graphics[offset + 1]; // Get 8 color indexes in a row for (byte z = 7; col < 8; z--) { t1 = (byte)((b1 >> z) & 1); t2 = (byte)((b2 >> z) & 1); Colors[(i * 8) + col] = (t2 * 2) + t1; if ((t2 * 2) + t1 != 0) { Pixels[(i * 8) + col] = pal[(t2 * 2) + t1]; } col++; } col = 0; offset += 2; } } // Flip subtile pixels if necessary if (mirror) { Do.FlipHorizontal(Pixels, 8, 8); } if (invert) { Do.FlipVertical(Pixels, 8, 8); } }