trick

    Dark Mode
Search:
Group by:

Trick is a library for GBA image conversion and more.

import trick                       # import everything
import trick/[common, gfxconvert]  # import individual modules

See below for an API overview of each module.

common

This module contains some general utilitites for working with data.

Go to full docs ⇒

Types

NameTypeSummary
View[T]objectAllows you to treat arbitrary memory like an array of some type, without copying.

Procedures

NameParametersReturnsSummary
viewSeqseq[T]View[T]Interpret a sequence as a view
viewSeqAsseq[A]View[B]Interpret a sequence as a view of a different type
viewBytesAsstringView[T]Interpret a string of binary data as a view of some type
toSeqView[T]seq[T]Convert a view to a sequence
toBytesView[T]stringConvert a view to binary data
toBytesseq[T]stringConvert a sequence to binary data
makeCStringstringstringConvert a string of binary data to an escaped C string literal
toCamelCasename, firstUpper=falsestringConvert a string from snake_case to camelCase
fileToVarNamename, firstUpper=falsestringConvert a filename to a variable name

gfxconvert

Types and procedures to convert between PNG and raw binary image/palette data.

For reading and writing PNGs, Trick uses the nimPNG library by jangko.

Go to full docs ⇒

Types

NameTypeSummary
GfxInfoobjectConfiguration object to encode/decode an image
GfxColoruint1615-bit BGR color
GfxPaletteseq[GfxColor]List of colors
GfxBppenumBits per pixel specifier
GfxLayoutenumWhether the image is arranged into 8x8 tiles

Constants

NameTypeSummary
clrEmptyGfxColorSpecial 'transparent' color

Procedures

NameParametersReturnsSummary
binToPngdata, confPNGConvert raw GBA/NDS image data to a PNG object
writeFilefilename, pngWrite a PNG object to a file
pngToBinfilename, conf, buildPalstringLoad a PNG and convert to GBA/NDS image data
readPalfilenameGfxPaletteRead a palette from a binary file
writePalfilename, palWrite a palette to a binary file
rgb5r, g, bGfxColorCreate a color using 5-bit components
rgb8r, g, bGfxColorCreate a color using 8-bit components
rgb8hexGfxColorCreate a color using an 0xRRGGBB value
swap4bppabbaSwap the low and high nybbles within a byte
swap2bppabcddcbaSwap the four pairs of bits within a byte

Iterators

NameParametersReturnsSummary
tileEncodewidth, height, bpp=8(srcIndex, destIndex)Unravel a tiled space into a bitmap space or vice versa

bgconvert

Procedures for working with tiled backgrounds.

Go to full docs ⇒

Types

NameTypeSummary
Tile4array[32, uint8]8x8 pixels at 4bpp (paletted)
Tile8array[64, uint8]8x8 pixels at 8bpp (paletted)
Tile16array[32, GfxColor]8x8 pixels at 15bpp
SomeTileTile4 | Tile8 | Tile16Typeclass for any kind of tile
ScrEntrydistinct uint16Tile index with palette and flipping flags (via getters/setters)
Screenblockarray[1024, ScrEntry]A block of 32x32 screen entries
Bg4object4bpp tiled background with a list of palettes
Bg16object16bpp high-color tiled background (used for processing/conversion)

Procedures

NameParametersReturnsSummary
loadBg4filenameBg4Load a PNG as a 4bpp tiled background
loadBg8filenameBg8Load a PNG as a 8bpp tiled background
loadBg16filenameBg16Load a PNG as a 15bpp (direct color) tiled background
toBg4Bg8Bg4Convert a 8bpp background to 4bpp with strict rules
toBg4Bg16Bg4Convert a 15bpp (direct color) background to 4bpp (paletted)
reducetiles(tiles, map)Remove duplicates from a list of tiles, and build a tile map
getPalettesFromTilestiles16seq[IntSet]Get a list of palettes from a list of 15bpp tiles
toScreenBlocksmap, wseq[Screenblock]Arrange a map into screenblocks (chunks of 32x32 tiles)
flipXtiletileFlip a tile horizontally
flipYtiletileFlip a tile vertically
cleartileErase all pixels in a tile

palbuilder

This module implements a palette reduction algorithm: Given a list of palettes (of which many are duplicates or at least have colors in common), it attempts to merge them down into a reduced list of palettes.

This also produces a list of indexes, mapping palettes from the old list to the new list.

Note: Throughout this module, IntSet is used in place of GfxPalette, for performance reasons.

Go to full docs ⇒

Procedures

NameParametersReturnsSummary
reducePalettesseq[IntSet](seq[GfxPalette], seq[int])Try to produce a minimal list of 16-color palettes
toPaletteIntSetGfxPaletteConvert an IntSet to a list of colors
toIntSetGfxPaletteIntSetConvert a list of colors to an IntSet
joinPalettesseq[GfxPalette]GfxPaletteConcatenate several palettes into one (with padding)

mmutil

Note: This module is on the chopping block, best not to use.

Uses the Maxmod utility program (mmutil) to produce a soundbank, which is then converted to C. The soundbank header is converted to Nim, for use in your game.

Go to full docs ⇒

Procedures

NameParametersReturnsSummary
makeSoundbank

nimOutputPath, cOutputPath,
inputFiles, nds=false

Create a soundbank from a list of audio files

Variables

NameTypeSummary
mmutilPathstringLocation of the mmutil executable. You shouldn't need to change this.