Bounded PNG alpha masks, grid-cell projection and Tiled TMX/TMJ occupied-tile decoding. Package tilemask, module github.com/Rethunk-Tech/go-tilemask.
Answers one question: which cells of an image, or which tiles of a map, are used. A cell is a square of a size the caller picks. A PNG becomes a one-bit-per-pixel mask (alpha not zero) that projects onto any grid, and a Tiled map becomes the occupied tiles of each top-level layer. Both decoders bound what their input claims (pixels, tiles, inflation) before allocating, so a few hostile bytes cannot ask for gigabytes. The caller bounds the input's byte size. Stdlib only.
go get github.com/Rethunk-Tech/go-tilemaskA worked example and the contracts: HUMANS.md.
- A pixel is set when its alpha is not zero, at any bit depth;
Mask.AtandMask.Cellsread it. Cellsprojects any region onto any cell size with floor division, so negative offsets land in negative cells.cell = 1costs one byte per pixel while it runs.- 8-bit, non-interlaced PNGs take a fast path that skips what a mask does not need; everything else goes through
image/png. DecodeMapreads TMX and TMJ under one tile cap for the whole map, declared and decoded, and refuses a layer or chunk that holds more values than it declared.WriteToandReadMaskstore a mask as a gzip file whose reader holds the header to the pixel cap.- Errors say why:
ErrTooLarge,ErrUnsupported(zstd, unknown encodings) orErrMalformed.
| Doc | Audience |
|---|---|
| HUMANS.md | Running and using the package |
| AGENTS.md | Internals, invariants, and why |
| CONTRIBUTING.md | Process — commits, tests, docs |
| SECURITY.md | Vulnerability disclosure |
| CHANGELOG.md | Release notes |
MIT — see LICENSE. © 2026 Rethunk.Tech, LLC.