public void LoadTileImages() { Dictionary <uint, uint> ImageIndexMap = new Dictionary <uint, uint>(); for (uint i = 0; i < Constants.MAX_TILES_1_23; i++) { if (ImageIndexMap.ContainsKey(TilesetInfo_1_23.ImageAddress[i])) { TilesetInfo_1_23.ImageAddress[i] = ImageIndexMap[TilesetInfo_1_23.ImageAddress[i]]; } else { J2T_TileImage image = new J2T_TileImage(); image.ImageData = Utils.getBytesNonRef(Data2, (int)TilesetInfo_1_23.ImageAddress[i], 1024); // memcpy(image.ImageData, &Data2[TilesetInfo_1_23->ImageAddress[i]], 1024); uint newIndex = (uint)TileImages.Count; ImageIndexMap[TilesetInfo_1_23.ImageAddress[i]] = newIndex; TilesetInfo_1_23.ImageAddress[i] = newIndex; TileImages.Add(image); } } }
public uint[] GetTile(uint index, bool flipped) { byte[] bitmap = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; uint CHANNEL_ALPHA, CHANNEL_RED, CHANNEL_GREEN, CHANNEL_BLUE; if (System.BitConverter.IsLittleEndian) { CHANNEL_RED = (uint)0x000000FF; CHANNEL_GREEN = (uint)0x0000FF00; CHANNEL_BLUE = (uint)0x00FF0000; CHANNEL_ALPHA = (uint)0xFF000000; } else { CHANNEL_RED = (uint)0xFF000000; CHANNEL_GREEN = (uint)0x00FF0000; CHANNEL_BLUE = (uint)0x0000FF00; CHANNEL_ALPHA = (uint)0x000000FF; } if (index >= NumTiles()) { return(null); } int ImageIndex = 0; int TransparencyIndex = 0; ImageIndex = (int)TilesetInfo_1_23.ImageAddress[index]; TransparencyIndex = (int)TilesetInfo_1_23.TMaskAddress[index]; J2T_TileImage image = TileImages[ImageIndex]; J2T_TileTransparency transparency = TileTransparencyMasks[TransparencyIndex]; uint[] Pixels = new uint[1024]; for (int i = 0; i < 1024; i++) { Pixels[i] = TilesetInfo_1_23.PaletteColor[image.ImageData[i]]; } for (int i = 0; i < 1024; i++) { Pixels[i] |= ((transparency.TransparencyMask[i / 8] & bitmap[i % 8]) != 0) ? CHANNEL_ALPHA : (uint)0x00000000; //Pixels[i] |= CHANNEL_RED; //Pixels[i] |= CHANNEL_GREEN; //Pixels[i] |= CHANNEL_BLUE; } if (flipped) { for (int i = 0; i < 32; i++) { for (int j = 0; j < 16; j++) { uint temp = Pixels[32 * i + j]; Pixels[32 * i + j] = Pixels[32 * i + (31 - j)]; Pixels[32 * i + (31 - j)] = temp; } } } return(Pixels); }