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:
| Bytes | What |
|---|---|
| 0–3 | MAGIC, 1BIT |
| 4 | VERSION |
| 5 | flags: bit 0 set if there is a mask; the others clear |
| 6 | the number of styles, at least 1 |
| 7 | 0 |
| 8–9, 10–11 | width and height in pixels, each at least 1 |
| 12–13, 14–15 | the 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 playdatemakes 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). - OneBit
File - A one-bit picture file read whole as a
OneBitPicture(one-bit). LikeOneBitInfo, 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). - OneBit
Info - A one-bit picture in a PNG’s place, read for the size of the PNG it
was made from (
one-bit), whichImageInfo::checkedmust allow. It claims no extension: it is found by its magic bytes at a PNG’s path, so a.1bitfile beside a PNG (a touched-up picture a build reads) is not an image of its own. - OneBit
Picture - A one-bit picture file, whole and checked (
Bitmap::parse): what a one-bit target’s pictures are baked as (ADR-0008 §4).OneBitFilereads one from a one-bit picture file, and with thepngfeaturedither::Ditheredmakes 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, orNoneif it doesn’t parse (Bitmap::parse). - encode
- The file of a
width×heightpicture made from a PNG ofsourcesize:styles(eachBitmap::plane_byteslong) and themaskthey share, or what is wrong with them.