Skip to main content

Module bitmap

Module bitmap 

Source
Expand description

One-bit pictures (game ADR-0085): the file a one-bit screen draws in place of a PNG, made ahead of time by convert so the device never decodes a PNG. Pixels are packed one bit a pixel in rows, the Playdate’s own bitmap layout: each row stride bytes, a byte’s highest bit its left pixel, a set bit white.

A file holds one picture in one or more styles (the same picture converted different ways, all the same size) and at most one mask they share: a set bit where the picture is drawn, a clear one where it is see-through.

A picture is usually bigger than the PNG it was made from: it is enlarged to the size it is shown at before it is dithered, so each dot is one screen pixel. The file keeps the PNG’s own size too (the source size), so a game keeps naming parts of the picture in the PNG’s pixels and a renderer scales them to the picture’s.

The layout, all numbers little-endian:

BytesWhat
0–3MAGIC, 1BIT
4VERSION
5flags: bit 0 set if there is a mask; the others clear
6the number of styles, at least 1
70
8–9, 10–11width and height in pixels, each at least 1
12–13, 14–15the source size, each at least 1
16…each style’s rows, in order, then the mask’s rows if any

As formats (ADR-0007), a one-bit picture in a PNG’s place is read for the size of that PNG (OneBitInfo), and whole as a OneBitPicture (OneBitFile). A one-bit target’s pack holds its pictures so: shuyi bake --target playdate makes each PNG one in integers (dither), and the device draws it with no copying.

Modules§

convert
Making a one-bit picture from a colour one, ahead of time (game ADR-0085). A tool runs it (a build script, a command); never the device.
dither
Making a colour picture one-bit at bake time, in integers (ADR-0008 §4): shuyi bake --target playdate makes every picture a one-bit picture file once, so the device never dithers. The same picture and settings give the same file on every platform, so the baked file is tested equal to dithering its source again (ADR-0007 §4).

Structs§

Bitmap
A one-bit picture file, read without copying (Bitmap::parse).
OneBitFile
A one-bit picture file read whole as a OneBitPicture (one-bit). Like OneBitInfo, it claims no extension and is found by its magic bytes, at a PNG’s path in a one-bit target’s pack or in place of a PNG in a target’s layer. It writes the file back as it was (Encode), which is how a bake keeps a picture in its pack (Bake::under_as).
OneBitInfo
A one-bit picture in a PNG’s place, read for the size of the PNG it was made from (one-bit), which ImageInfo::checked must allow. It claims no extension: it is found by its magic bytes at a PNG’s path, so a .1bit file beside a PNG (a touched-up picture a build reads) is not an image of its own.
OneBitPicture
A one-bit picture file, whole and checked (Bitmap::parse): what a one-bit target’s pictures are baked as (ADR-0008 §4). OneBitFile reads one from a one-bit picture file, and with the png feature dither::Dithered makes one from a PNG.

Constants§

EXTENSION
The extension of a one-bit picture file on disk (.1bit).
HEADER_BYTES
Bytes before the first style’s rows.
MAGIC
The first four bytes of a one-bit picture file.
MAX_BYTES
The most bytes a one-bit picture file may have: 16 MiB, far more than a one-bit screen’s pictures need (the Playdate’s whole screen is 12 KB a style).
VERSION
The layout’s version: the fifth byte.

Functions§

bitmap_sizes
The size, in pixels, of one-bit picture file bytes, and its source size, or None if it doesn’t parse (Bitmap::parse).
encode
The file of a width × height picture made from a PNG of source size: styles (each Bitmap::plane_bytes long) and the mask they share, or what is wrong with them.