private static void DecodeTile8(ref byte[] bytes, int index, ref TilesetEntry tile) { for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { tile[x, y] = bytes[index + x + y * 8]; } } }
private static void EncodeTile4(ref TilesetEntry tile, ref byte[] bytes, int index) { for (int y = 0; y < 8; y++) { for (int x = 0; x < 4; x++) { bytes[index + x + y * 4] = (byte)((tile[x * 2, y] & 0xF) | ((tile[x * 2 + 1, y] & 0xF) << 4)); } } }
private static void EncodeTile8(ref TilesetEntry tile, ref byte[] bytes, int index) { for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { bytes[index + x + y * 8] = (byte)tile[x, y]; } } }
private static void DecodeTile4(ref byte[] bytes, int index, ref TilesetEntry tile) { for (int y = 0; y < 8; y++) { for (int x = 0; x < 4; x++) { tile[x * 2, y] = (bytes[index + x + y * 4] & 0xF); tile[x * 2 + 1, y] = (bytes[index + x + y * 4] >> 4 & 0xF); } } }
public static TilesetEntry[] Decode8(byte[] bytes) { var tiles = new TilesetEntry[bytes.Length >> 6]; // / (8 * 8) for (int i = 0; i < tiles.Length; i++) { DecodeTile8(ref bytes, i << 6, ref tiles[i]); // * (8 * 8) } return(tiles); }