Luau Bindings — image

The require("image") script API — a small image codec: encode/decode PNG and the Atari Degas formats (PI1, PC1), and convert between pixel representations. Every function is [antos]. Design & native core: antos_image.

local image = require("image")
local pixels, w, h = image.decode_pi1(io.open("B:/art/logo.pi1","rb"):read("a"))
image.save_png("D:/logo.png", pixels, w, h)

Pixels cross the C/Lua boundary two ways:

  • as a raw RGB888 byte string (w*h*3 bytes) — the compact form the encoders/decoders speak, matching data's string-in/string-out style;
  • as a flat array of packed 0xRRGGBB integers, one per pixel, 1-based and row-major (arr[y*w + x + 1]) — for pixel-level work in Lua.

image.to_array / image.from_array convert between them.

Encode / decode

Function Behaviour
image.encode_png(pixels, w, h) RGB888 string → PNG bytes.
image.decode_pi1(bytes) · image.encode_pi1(pixels, w, h) Atari Degas PI1 (low-res).
image.decode_pc1(bytes) · image.encode_pc1(pixels, w, h) Atari Degas PC1 (compressed).

Load / save (file convenience)

Function Behaviour
image.save_png(path, pixels, w, h) Encode + write a PNG.
image.load_pi1(path) · image.save_pi1(path, …) PI1 file I/O.
image.load_pc1(path) · image.save_pc1(path, …) PC1 file I/O.

Pixel conversion

Function Behaviour
image.to_array(bytes, w, h) RGB888 string → array of 0xRRGGBB ints.
image.from_array(arr, w, h) Array of ints → RGB888 string.

(RGB only today; a future 0xAARRGGBB form can slot in behind the same two functions.)

Screen capture

The framebuffer → PNG path lives here (a screenshot is just "encode the screen"). Async: screenshot() snapshots the framebuffer and hands off to a worker that encodes and writes, so it returns at once.

Function Behaviour
image.screenshot() Trigger a capture → true if one started, false if already busy.
image.capturing() Is a capture in progress?
image.screenshot_dir([path]) Get / set the save folder — the screenshot.dir setting (shared with Settings and the Ctrl+S hotkey).
if image.screenshot() then print("capturing to " .. image.screenshot_dir()) end

Related

Important: The Ant64 family of home computers are at early design/prototype stage, everything you see here is subject to change.