Biksel File Formats — Quick Reference

Basic formats

// Primitive formats:
//
//   Byte     (8-bit unsigned integer)
//   Int32    (32-bit signed integer)
//   Int64    (64-bit signed integer)
//   Float64  (64-bit floating point number)
//
// All primitive formats use little-endian byte order, are
// naturally aligned relative to the beginning of the file, and
// are preceded by zero-valued padding bytes as necessary for
// alignment.
//
// Signed integers are encoded in two's complement
// representation. Floating point numbers are encoded in IEEE 754
// binary representation.
format Bool = "False" | "True"
// Optional value
format Maybe a
   = "Nothing"
   | "Just" >> a
// Sequence of zero or more values
format ArrayOf a
   = ()
   | a >> ArrayOf a
// Self-delimiting list of zero or more values
format ListOf a
   = "Nil"
   | "Cons" >> a >> ListOf a

// Note that 'ListOf a' is usually written '[a]'.

Format identifier

format FormatName
   = Byte          // 0: this initial null byte indicates
                   //   immediately to anyone inspecting the file
                   //   that it is not a UTF-8 plain text file

  >> ArrayOf Byte  // format name: sequence of ASCII lowercase
                   //   letters, digits, and hyphens

  >> Byte          // 0: this null byte terminates the format
                   //   name
format FormatId
   = FormatName
  >> Int32       // format major version: non-negative
  >> Int32       // format minor version: non-negative

Sprite file

format Color
     // transparent
   = Byte >> Byte >> Byte >> Byte  // 0, 0, 0, 1
     // rgb
   | Byte >> Byte >> Byte >> Byte  // blue, green, red, 0
format Pixmap
   = Int32          // width: non-negative
  >> Int32          // height: non-negative
  >> ArrayOf Color  // pixel values:
                    //   no. elements = width * height

// The order of the pixel values in the above format is as
// follows: start from the bottom-left corner and proceed in
// horizontal scanlines; the pixels within each scanline are
// ordered from left to right; the scanlines themselves are
// ordered from bottom to top.
format Sprite
   = Pixmap
  >> Int32 >> Int32  // (x, y) offset of bottom-left corner of
                     //   pixmap relative to sprite origin
// Recommended file extension: .sprite
format SpriteFile
   = FormatId  // "biksel-sprite" 1.0
  >> Sprite