From ef02996489747c8335b6c3d944813a024484f416 Mon Sep 17 00:00:00 2001 From: Timofey Vasenin Date: Tue, 28 Nov 2017 09:06:45 +0700 Subject: [PATCH] Convert 8-bit image PNGs (CASTLE/MENU/THEEND/TITUS) on the fly --- Pre2/AssetConverter.cs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/Pre2/AssetConverter.cs b/Pre2/AssetConverter.cs index dfb8103..d4384dd 100644 --- a/Pre2/AssetConverter.cs +++ b/Pre2/AssetConverter.cs @@ -105,11 +105,6 @@ public static void PrepareAllAssets() Directory.CreateDirectory(CacheDir); ConvertAllFonts(); - ConvertIndex8WithPalette("CASTLE"); - ConvertIndex8WithPalette("MENU"); - ConvertIndex8WithPalette("THEEND"); - ConvertIndex8WithPalette("TITUS"); - // Palette for MENU2 is concatenated at the end of the image (using a copy for convenience)! ConvertIndex4("GAMEOVER", File.ReadAllBytes(Path.Combine(ResDir, "gameover.pal")), BackgroundInfo); ConvertIndex4("MAP", File.ReadAllBytes(Path.Combine(ResDir, "map.pal")), MapInfo); @@ -172,6 +167,26 @@ public static Tilemap GetLevelTilemap(int levelIdx) return GenerateLevelTilemap(levelIdx); } + public static Bitmap GetCastleBitmap() + { + return GetIndex8WithPaletteBackground("CASTLE"); + } + + public static Bitmap GetMenuBitmap() + { + return GetIndex8WithPaletteBackground("MENU"); + } + + public static Bitmap GetTheEndBitmap() + { + return GetIndex8WithPaletteBackground("THEEND"); + } + + public static Bitmap GetTitusBitmap() + { + return GetIndex8WithPaletteBackground("TITUS"); + } + public static Bitmap GetYearBitmap() { int width = BackgroundInfo.W; @@ -314,15 +329,19 @@ private static byte[][] ReadSprites(byte[] rawSprites, SpriteData[] entries) return sprites; } - private static void ConvertIndex8WithPalette(string resource) + private static Bitmap GetIndex8WithPaletteBackground(string resource) { - string destFilename = Path.Combine(CacheDir, resource + ".png"); byte[] data = UnpackSqz(resource); using (BinaryReader br = new BinaryReader(new MemoryStream(data, false))) { byte[] pal = br.ReadBytes(256 * 3); byte[] indexBytes = br.ReadBytes(BackgroundInfo.W * BackgroundInfo.H); // 8 bpp - WritePng8(destFilename, indexBytes, pal, BackgroundInfo); + Bitmap bitmap = new Bitmap(BackgroundInfo.W, BackgroundInfo.H, 8) + { + PixelData = indexBytes, + Palette = GetPalette(pal) + }; + return bitmap; } }