public override void Map(Pixel[] image, int[] palettes) { List <Pixel[]> tiles = new List <Pixel[]>(); List <MapInfo> infos = new List <MapInfo>(); int tileLength = this.TileSize.Width * this.TileSize.Height; for (int i = 0; i < image.Length; i += tileLength) { // Get tile Pixel[] tile = new Pixel[tileLength]; Array.Copy(image, i, tile, 0, tileLength); bool flipX; bool flipY; int index = CompressMapping.Search(tile, tiles, this.TileSize, out flipX, out flipY); // Otherwise add if (index == -1) { tiles.Add(tile); index = tiles.Count - 1; flipX = false; flipY = false; } // Finally create map info infos.Add(new MapInfo(index, palettes[i / tileLength], flipX, flipY)); } // Get an array of pixels instead of tiles Pixel[] linPixels = new Pixel[tiles.Count * tileLength]; for (int i = 0; i < tiles.Count; i++) { tiles[i].CopyTo(linPixels, i * tileLength); } // Set data this.mappedImage = linPixels; this.mapInfo = infos.ToArray(); }
public override void Map(Pixel[] image) { List <Pixel[]> tiles = new List <Pixel[]>(); List <MapInfo> infos = new List <MapInfo>(); int tileLength = this.TileSize.Width * this.TileSize.Height; // Get tiles for (int i = 0; i < mappedImage.Length; i += tileLength) { Pixel[] tile = new Pixel[tileLength]; Array.Copy(mappedImage, i, tile, 0, tileLength); tiles.Add(tile); } // Perfom search for (int i = 0; i < image.Length; i += tileLength) { // Get tile Pixel[] tile = new Pixel[tileLength]; Array.Copy(image, i, tile, 0, tileLength); bool flipX; bool flipY; int index = CompressMapping.Search(tile, tiles, this.TileSize, out flipX, out flipY); if (index == -1) { throw new Exception("Tile not found."); } // Finally create map info infos.Add(new MapInfo(index, 0, flipX, flipY)); } this.mapInfo = infos.ToArray(); }