public static void Initialize() { RAM = new RAMSegmentStruct[16]; byte[] TextureBuffer = new byte[32 * 32 * 4]; TextureBuffer.Fill(new byte[] { 0xFF, 0x00, 0xFF, 0xFF }); InvalidTextureID = TexUtil.CreateRGBATexture(32, 32, TextureBuffer); }
public void Generate_Blank_Tile_Texture() { byte[] singleTileImage = new byte[32 * 32 * 4]; var pixel = new byte[4] { Tile0Color.R, Tile0Color.G, Tile0Color.B, 255 }; for (ushort i = 0; i < singleTileImage.Length; i++) { singleTileImage[i] = pixel[i % 4]; } ImageAtlas = TexUtil.CreateRGBATexture(32, 32, singleTileImage); AtlasLength = 1; AtlasFraction = 1; }
public void Generate_Textures(TransparencySource source = TransparencySource.JJ2_Style, bool includeMasks = false, Palette palette = null) { Color usedColor = Tile0Color; var transformation = TileTypeColorTransformations[VersionType]; if (palette == null) { palette = Palette; } byte[][] workingAtlases = new byte[2][]; for (byte i = 0; i < 5; i++) { if (TileCount < 16 << (i * 2)) { AtlasLength = 128 << i; workingAtlases[0] = new byte[AtlasLength * AtlasLength * 4]; if (includeMasks) { workingAtlases[1] = new byte[AtlasLength * AtlasLength * 4]; } AtlasLength /= 32; AtlasFraction = 1.0d / AtlasLength; break; } } for (ushort tileInLevelID = 0; tileInLevelID < TileCount; tileInLevelID++) { J2TFile J2T; uint tileInTilesetID = getTileInTilesetID(tileInLevelID, out J2T); bool customTileImage; byte[] tileTrans; byte[] tile = PlusPropertyList.TileImages[tileInLevelID]; if (!(customTileImage = (tile != null))) { tile = J2T.Images[J2T.ImageAddress[tileInTilesetID]]; tileTrans = ((source == TransparencySource.JJ2_Style) ? J2T.TransparencyMaskJJ2_Style : J2T.TransparencyMaskJCS_Style)[Array.BinarySearch(J2T.TransparencyMaskOffset, 0, (int)J2T.data3Counter, J2T.TransparencyMaskAddress[tileInTilesetID])]; } else { tileTrans = tile; } var colorRemapping = (J2T.ColorRemapping == null || customTileImage) ? J2TFile.DefaultColorRemapping : J2T.ColorRemapping; var mask = PlusPropertyList.TileMasks[tileInLevelID] ?? J2T.Masks[J2T.MaskAddress[tileInTilesetID]]; for (short j = 0; j < 32 * 32 * 4; j += 4) { bool transparentPixel = tileTrans[j / 4] == 0; var color = Palette.Convert(!transparentPixel ? transformation(palette[colorRemapping[tile[j / 4]]], TileTypes[tileInLevelID]) : usedColor, true); if (transparentPixel) { color[3] = 0; } for (byte k = 0; k < 4; k++) { int atlasDrawingLocation = tileInLevelID % AtlasLength * 128 + tileInLevelID / AtlasLength * AtlasLength * 4096 + j % 128 + j / 128 * AtlasLength * 128 + k; workingAtlases[0][atlasDrawingLocation] = color[k]; if (includeMasks) { workingAtlases[1][atlasDrawingLocation] = (k == 3) ? (mask[j / 4] == 1) ? (byte)196 : (byte)0 : (mask[j / 4] == 1) ? (byte)0 : GetLevelFromColor(usedColor, k); } } } if (tileInLevelID == 0) { usedColor = TranspColor; } } ImageAtlas = TexUtil.CreateRGBATexture(AtlasLength * 32, AtlasLength * 32, workingAtlases[0]); if (includeMasks) { MaskAtlas = TexUtil.CreateRGBATexture(AtlasLength * 32, AtlasLength * 32, workingAtlases[1]); } }