ws-apifix: API.md / STYLE.md / README: music as audio, video as animated image, F.save extra files, variant(r), caps.extraFiles, F.music builder, bitrate in bit/s; type baseline 92

This commit is contained in:
4DBug committed 2026-10-31 14:14:11 -05:00
1 parent 6274eedd12
commit 5bbb4227c2
5 files changed
+21 -7

No files matched your search

+1 -1
View File
@@ -73,7 +73,7 @@ local tune = F.music.load(modBytes) -- MOD / S3M / XM / IT / MIDI
`F.load`, `F.open`, `F.save`, `F.saveString`, `F.convert`, `F.detect`, `F.formats`, `F.format(name)`; the category
facades `F.image`, `F.audio`, `F.video`, `F.model`, `F.cad`, `F.font`, `F.archive`, `F.data`, `F.vector`,
`F.layered`, `F.subtitle`, `F.music`, `F.playlist`; editing in `F.ops.image`, `F.ops.mesh`, `F.ops.layers`,
`F.ops.audio`, `F.ops.vector.rasterize`; `F.host`, `F.plugins`, `F.Err`, `F.Types`. Options and the hooks the api
`F.ops.audio`, `F.ops.music` (also `F.music.new` / `addPattern` / `setCell` / ...), `F.ops.vector.rasterize`; `F.host`, `F.plugins`, `F.Err`, `F.Types`. Options and the hooks the api
hands to formats (decodeImage / encodeImage / openAudio / plugins): [docs/API.md](docs/API.md).
## Host notes
+13 -2
View File
@@ -12,6 +12,8 @@ string is a path only when `opts.path = true` or when it does not look like file
`opts.data = true` to force bytes. Roblox and the luau CLI have no file system: pass buffers or strings.
`F.save(value, dest?, opts?)` returns a `buffer`, or writes the file `dest` (extension = format) and returns `true`.
Formats that write extra files (`caps.extraFiles`: BMFont pages) put them next to `dest`; without a destination they
come back as a third value `{ [file name] = buffer }` (or in the caller's `opts.files` table).
## Loading and saving
@@ -19,16 +21,22 @@ string is a path only when `opts.path = true` or when it does not look like file
|---|---|
| `F.load(src, opts?)` | the category's standard value (`Image`, `Audio`, `Scene`, `Font`, `Archive`, `Vector`, `Layered`, `Subtitles`, `Module` / `Midi`, `Playlist`, data values, a `VideoDecoder`) |
| `F.open(src, opts?)` | a streaming decoder: audio `Decoder`, `VideoDecoder`, or a container `Demuxer` |
| `F.save(value, dest?, opts?)` | `buffer` / `true` |
| `F.save(value, dest?, opts?)` | `buffer` / `true` (+ the extra files, see above) |
| `F.saveString(value, opts?)` | the encoded bytes as a string |
| `F.convert(src, format, opts?)` | load + save (`opts` go to both; `opts.out = path` writes a file) |
| `F.detect(src, opts?)` | the format name (content sniffing first, then the extension) |
| `F.detect(src, opts?)` | the format name (content sniffing first, then the extension); a format's optional `variant(r)` can name the flavour (`"webm"` for a WebM file read by mkv) |
| `F.formats(category?)` | `{ { name, category, extensions, mime, caps } }` without loading any format (also [FORMATS.md](FORMATS.md)) |
| `F.format(name)` | the format module itself (`sniff` / `decode` / `encode` / `open` and extras such as `png.info`) |
Common options: `format` (a name or extension: what to decode as / encode to; without it, saving uses the source
format), `category`, `name` (a file name hint for detection), `path` / `data`, size limits (`maxPixels`, `maxBytes`,
`maxFrames`, ...), and each format's own options (documented in its `init.luau`: `level`, `quality`, `bitrate`, ...).
`bitrate` is in bits per second for every encoder (values below 1000 are read as kbit/s).
Across categories: a Module or Midi saved to an audio format is rendered first (render options in `opts`:
`F.convert(modBytes, "wav", { sampleRate = 22050 })`), and `F.audio.open` / `F.audio.load` render music bytes; a
VideoDecoder saved to an image format (`gif`, `apng`, `webp`) becomes an animated Image of its frames (`frames`,
`fps`, `maxFrames` = 300, `maxPixels` = 2^25); an Image saves to a video format as a frames-backed video.
## Category facades
@@ -43,6 +51,8 @@ one category. Extras:
- `F.cad.toBodies`, `F.cad.fromBodies`, `F.cad.tessellate`: STEP B-rep calls through the injected kernel
(`F.plugins.brep`).
- `F.data.null`: the JSON / YAML / TOML / msgpack / CBOR null.
- `F.music.new`, `addPattern`, `setCell`, `getCell`, `addSample`, `addInstrument`, `note`: build and edit tracker
modules (`ops/MusicOps`, also `F.ops.music`): `F.music.new({ format = "mod", channels = 4 })`.
## Editing: `F.ops`
@@ -54,6 +64,7 @@ arguments.
| `F.ops.image` | `ops/ImageOps` | `convert` (pixel formats), `crop`, `resize` (nearest / bilinear / Lanczos-3), `flip`, `rotate90`, `rotate`, `blit`, `composite`, `premultiply` / `unpremultiply`, `getPixel` / `setPixel` / `fill`, `new` / `copy`, animations: `coalesce` (frames on full canvases), `fromFrames`, `frameCount`, `durations` |
| `F.ops.mesh` | `ops/MeshOps` | `triangulate`, `transform`, `computeNormals`, `computeTangents`, `weld` / `unweld`, `bounds`, `merge`, `scale` / `setUnit` / `setUp`, `voxelsToPrimitive`, `meshVoxels` |
| `F.ops.layers` | `ops/LayerOps` | `flatten(layered, { frame })`, `flattenFrames`, `leaves` |
| `F.ops.music` | `ops/MusicOps` | `new`, `addPattern`, `setCell` / `getCell`, `addSample` (from an Audio), `addInstrument`, `note` (`"C-4"` -> 49) |
| `F.ops.audio` | `ops/AudioOps` | `toAudio` (an Audio from an Audio or a Decoder), `gain`, `gainDb`, `normalize`, `peak`, `rms`, `mix`, `remix` / `downmix` / `upmix` (WAVE-layout matrices), `resample` (`codecs/audio/Resample`), `trim`, `concat`, `fade` |
| `F.ops.vector` | `vector/svg` | `rasterize(vector, w?, h?, opts?)`: any `Vector` to an rgba8 `Image` |
+5 -2
View File
@@ -20,7 +20,7 @@ The reference implementation to copy is **PNG**:
src/Formats/
init.luau Registry.luau (generated) api (layer 6)
ops/ ops (layer 5.5) editing on the standard types (F.ops.image /
mesh / layers / audio; ImageOps, MeshOps, ...)
mesh / layers / audio / music; ImageOps, ...)
<category>/<fmt>/ formats (layer 5) image audio video model cad font archive data
vector layered subtitle music playlist
containers/ containers (layer 4) Chunks, Riff, IsoBmff, Ebml, Ogg, Zip, Tar, ...
@@ -126,7 +126,10 @@ Rules:
- `open(r, opts)` (audio / video) returns the streaming Decoder / VideoDecoder / Demuxer from `Types.luau`. If a format
has `open` but no `decode`, `F.load` decodes the whole stream through it.
- Options are a typed table with defaults documented on each field (`level: number?, -- 0..9, default 6`).
- Extra format-specific functions (`Png.info(r)`) are fine; `F.format("png")` returns the module.
- Extra format-specific functions (`Png.info(r)`) are fine; `F.format("png")` returns the module. Two optional ones the
api calls: `variant(r) -> string?` (a more precise name for `F.detect`: video/mkv gives `"webm"`), and encoders
that write extra files into `opts.files` declare `caps.extraFiles = true` (the api then returns them from
`F.save` without a destination).
- No globals, no state between calls, no host access (no files, no `game`).
### Conventions shared by every format
+1 -1
View File
@@ -12,7 +12,7 @@
-- local s = F.saveString(img, { format = "png" })
-- local buf = F.convert(src, "png", opts?) -- load + save
-- F.formats() -- the capability list (also docs/FORMATS.md)
-- F.ops.image.resize(img, 64, 64) -- editing: F.ops.image / mesh / layers / audio / vector.rasterize
-- F.ops.image.resize(img, 64, 64) -- editing: F.ops.image / mesh / layers / audio / music / vector
--
-- Never throws on bad data or bad arguments: every function returns nil, Err (Err.code, Err.message, tostring(err)).
local Err = require("@formats/core/Err")
+1 -1
View File
@@ -1 +1 @@
93
92