Skip to content

Commit

Permalink
Convert 8-bit image PNGs (CASTLE/MENU/THEEND/TITUS) on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
tvasenin committed Nov 28, 2017
1 parent 84182ca commit ef02996
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions Pre2/AssetConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit ef02996

Please sign in to comment.