Sheeter is a high-performance .NET library for converting retro game graphics formats to and from indexed pixel data. Sheeter is available from nuget.org as the package Spannerisms.Sheeter.
The Sheeter library contains various structure types to represent tile data, for example Snes4bppTile. Before using this library, make sure you are familiar with Span types and ref variables
Important
The tile structs are large, unmanaged types. It is generally best to only use them in arrays or spans. If tiles need to be handled individually, prefer doing so with the ref keyword. Most of this library is built on passing tiles by reference; however, you should keep these concerns in mind when writing your own routines.
- Create a
SheeterBitmapinstance usingnew SheeterBitmap(file)to load an image from a file. Note: This type is disposable. - Create a
PaletteSetand populate it to map colors to indices. - Use
SheeterImage.CreateIndexedTilesto create a collection of indexed-color 8x8 tiles from the image. - Use
GraphicsTile.ConvertAllTiles<TFormat>to convert to the desired tile format.
Example:
using Sheeter;
using Sheeter.Snes;
private static readonly PaletteSet CommonPalette = ...;
public byte[] CreateSpriteSheet(string path) {
using SheeterBitmap image = new(path);
TiledBitmapViewport sheetView = new(image, x: 0, y: 0, tilesWidth: 16, tilesHeight: 4);
GraphicsTile[] indexedTiles = sheetView.CreateGraphicsTiles(CommonPalette);
Snes3bppTile[] convertedTiles = indexedTiles.ConvertAllTo<Snes3bppTile>();
return convertedTiles.AsBytes();
}- Use one of the
FromBytesextension methods available to the tile format types. - Pass the span to
GraphicsTile.ConvertAllTilesToIndexed.
Example:
using Sheeter;
using Sheeter.Snes;
public static GraphicsTile[] Read4bpp(byte[] rom, int offset, int tileCount) {
ReadOnlySpan<Snes4bppTile> tiles = Snes4bppTile.CreateSpanFromBytes(rom, offset, tileCount);
return GraphicsTile.ConvertAllTiles<Snes4bppTile>(tiles);
}Packed1bppTileimplicitly works for NES, SNES, and several other interleaved formats.- Gameboy and Gameboy Color use
Snes2bppTile. - PC Engine uses
Snes4bppTile.