Skip to main content

Module offscreen

Module offscreen 

Source
Expand description

Raster pixels: the Offscreen table and its block data.

An offscreen is a grid of 256×256 blocks. Offscreen.Attribute says how big it is and how a block’s bytes are laid out; Offscreen.BlockData is the id of an external chunk holding the zlib-compressed blocks (spec: docs/spec/04-raster.md).

Attribute (big endian): u32 16, u32 len(Parameter), u32 len(InitColor), u32 len(BlockSize), then three sections, each a UTF-16 name followed by u32 values. The values of Parameter and InitColor are, in order, the columns of the unused VOffscreen table in ParamScheme (BlockDataChannelOrder, BlockDataPixelBytes, … InitColorDataAlphaValue).

A decompressed block is an alpha plane followed by an image plane:

channel_orderkindblock bytesplanes
0x21 (33)colour327 680alpha 256×256, then BGRA 256×256×4 (the 4th byte unused)
0x11 (17), 2 bytes/pixelgray131 072alpha, then gray
0x11 (17), 1-bitmonochrome16 384alpha 1 bit/pixel, then 1 bit/pixel
0x01 (1)mask / alpha only65 536one plane

The external payload (big endian): u64 length of the rest, one record per block (u32 record length, name "BlockDataBeginChunk", u32 index, u32 decompressed size, u32 256, u32 256, u32 has data, [u32 4 + n, u32le n, n bytes of zlib], name "BlockDataEndChunk"), then the tail sections BlockStatus and BlockCheckSum (name, u32 12, u32 count, u32 4, count × u32). The checksum is the Adler-32 of u32le n + the zlib bytes, 0 for an empty block. CSP compresses with zlib level 1.

Structs§

Attribute
Offscreen.Attribute, kept value for value so it can be written back.
Block
One block record of the payload.
BlockData
The external payload of an offscreen.
InitColor
InitColor: how blocks that are not stored start out.
Offscreen
A decoded offscreen.
Parameter
The fields of the Parameter section, named after VOffscreen.
Section
One named section of the attribute: its u32 values.
Table
A tail table (BlockStatus, BlockCheckSum).

Enums§

PixelKind
Pixel layout of an offscreen.

Constants§

BLOCK_PIXELS
Pixels per block.
BLOCK_SIZE
Width and height of a block in pixels.
EMPTY_RECORD_SIZE
Size of a block record without data (the BlockSize entry of empty blocks).
RECORD_OVERHEAD
What a stored block adds to its zlib length in its record.

Functions§

compress
zlib with CSP’s settings: the bundled C zlib at level 1, window bits 15, memory level 9 (gives CSP’s bytes exactly).
encode
Encode an image into blocks for parameter (colour, gray or alpha). Blocks whose pixels are all transparent are not stored, as CSP does.