Trezor Optimized Image Format (TOIF)

All multibyte integer values are little endian!

offsetlengthnamedescription
0x00003magicTOI
0x00031fmtdata format: f or g (see below)
0x00042widthwidth of the image
0x00062heightheight of the image
0x00084datasizelength of the compressed data
0x000A?datacompressed data (see below)

Format

TOI currently supports 4 variants:

  • f: full-color big endian
  • F: full-color little endian
  • g: gray-scale odd high
  • G: gray-scale even high

Full-color

For each pixel a 16-bit value is used. First 5 bits are used for red component, next 6 bits are green, final 5 bits are blue:

1514131211109876543210
RRRRRGGGGGGBBBBB

The data is stored according to endianness.

Gray-scale

Each pixel is encoded using a 4-bit value. Each byte contains color of two pixels:

Odd high:

76543210
PoPoPoPoPePePePe

Even high:

76543210
PePePePePoPoPoPo

Where Po is odd pixel and Pe is even pixel.

Compression

Pixel data is compressed using DEFLATE algorithm with 10-bit sliding window and no header. This can be achieved with ZLIB library by using the following:

import zlib
z = zlib.compressobj(level=9, wbits=-10)
zdata = z.compress(pixeldata) + z.flush()

TOIF tool

Tool for converting PNGs into TOI format and back, see the following links for more: