docs: rosetta naming in README, docs, guide, licenses
This commit is contained in:
1 parent
22ddcd78fa
commit
753ae98d4a
20 files changed
+123
-123
No files matched your search
+5
-5
@@ -1,7 +1,7 @@
|
||||
# formats-luau API
|
||||
# rosetta API
|
||||
|
||||
`local F = require(Formats)` (Roblox: the ModuleScript; LuaJIT / LÖVE: `require("formats")`; luau CLI:
|
||||
`require("@formats")`). Everything below is `src/Formats/init.luau` unless noted. Nothing throws on bad data or bad
|
||||
`local F = require(Rosetta)` (Roblox: the ModuleScript; LuaJIT / LÖVE: `require("rosetta")`; luau CLI:
|
||||
`require("@rosetta")`). Everything below is `src/Rosetta/init.luau` unless noted. Nothing throws on bad data or bad
|
||||
arguments: a failing call returns `nil, err` where `err` is a `core/Err` value (`err.code`, `err.message`,
|
||||
`err.offset`, `err.format`; `tostring(err)` prints `png: CORRUPT at 0x21: bad filter type 7`).
|
||||
|
||||
@@ -97,7 +97,7 @@ A format never requires another format, so the api passes these to decoders / en
|
||||
|
||||
## Host
|
||||
|
||||
`F.host` (`src/Formats/host`): `name` (`"roblox"`, `"love"`, `"luajit"`, `"luau"`), `hasFiles`, `readFile`,
|
||||
`F.host` (`src/Rosetta/host`): `name` (`"roblox"`, `"love"`, `"luajit"`, `"luau"`), `hasFiles`, `readFile`,
|
||||
`writeFile`, `exists`; Roblox `toEditableImage(img)`, `meshPages(prim, opts?)`, `pageData(prim, page, opts?)`,
|
||||
`toEditableMesh(prim, page?, opts?)` (a triangle primitive in pages of at most 20k triangles / 60k vertices, each an
|
||||
EditableMesh; see the Hosts section of the guide); LÖVE `toImageData(img)`, `fromImageData(imageData)`,
|
||||
@@ -105,7 +105,7 @@ EditableMesh; see the Hosts section of the guide); LÖVE `toImageData(img)`, `fr
|
||||
|
||||
On LuaJIT the host raises the trace limits at load (`jit.opt.start("maxtrace=8000", "maxmcode=65536")`): the big
|
||||
decoders (CELT, VP8, H.264, MPEG-1) outgrow the defaults and fall back to the interpreter. Set
|
||||
`_G.FORMATS_NO_JIT_TUNE = true` before requiring the library to leave the JIT settings alone.
|
||||
`_G.ROSETTA_NO_JIT_TUNE = true` before requiring the library to leave the JIT settings alone.
|
||||
|
||||
## Also exported
|
||||
|
||||
|
||||
+2
-2
@@ -185,7 +185,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- **audio**
|
||||
- codecs/audio/Aac: AAC-LC decoder (ISO/IEC 14496-3 subpart 4, ISO/IEC 13818-7): the AudioSpecificConfig (with a program
|
||||
- codecs/audio/Ac3: AC-3 (Dolby Digital, ATSC A/52) syncframes: the syncinfo / BSI header, the CRC check, and the
|
||||
- codecs/audio/Adpcm: the 4-bit ADPCM family, decode (and encode where it is cheap). New in formats-luau; the IMA and
|
||||
- codecs/audio/Adpcm: the 4-bit ADPCM family, decode (and encode where it is cheap). New in rosetta; the IMA and
|
||||
- codecs/audio/Alac: Apple Lossless (ALAC) decoder and encoder, the codec inside m4a / mov / caf. A codec (layer 1).
|
||||
- codecs/audio/Ape: the Monkey's Audio codec (.ape). A codec (layer 3). Ported from the Monkey's Audio SDK 13.28
|
||||
- codecs/audio/ApeTag: APEv1 / APEv2 tags (the tag block of Monkey's Audio, WavPack, Musepack, TTA, OptimFROG and
|
||||
@@ -268,4 +268,4 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- codecs/video/Mpeg1: the MPEG-1 video decoder (ISO/IEC 11172-2), which is codecs/video/Mpeg2 (an MPEG-2 decoder
|
||||
- codecs/video/Mpeg2: an MPEG-1 / MPEG-2 video decoder (ISO/IEC 11172-2, ISO/IEC 13818-2 Main profile).
|
||||
- codecs/video/Theora: a Theora video decoder (the Theora I specification, Xiph.Org), for Ogg (video/ogv) and Matroska
|
||||
- codecs/video/Video: the video codec registry and the generic VideoDecoder. New in formats-luau.
|
||||
- codecs/video/Video: the video codec registry and the generic VideoDecoder. New in rosetta.
|
||||
+21
-21
@@ -1,4 +1,4 @@
|
||||
# formats-luau style guide
|
||||
# rosetta style guide
|
||||
|
||||
Every format looks the same: one folder, one contract, one test, one fixture generator, and the folder holds only what
|
||||
is specific to the format (section 2a). `bash tools/lint.sh` enforces most of what follows (the rule names in
|
||||
@@ -8,16 +8,16 @@ The reference implementation to copy is **PNG**:
|
||||
|
||||
| What | Copy from |
|
||||
|---|---|
|
||||
| Format contract (`init.luau`) | `src/Formats/image/png/init.luau` |
|
||||
| Private hot submodules (`--!native`) | `src/Formats/image/png/Decode.luau`, `src/Formats/image/png/Encode.luau` |
|
||||
| Format contract (`init.luau`) | `src/Rosetta/image/png/init.luau` |
|
||||
| Private hot submodules (`--!native`) | `src/Rosetta/image/png/Decode.luau`, `src/Rosetta/image/png/Encode.luau` |
|
||||
| Test | `tests/image/png.luau` |
|
||||
| Fixture generator | `tools/fixtures/png.py` (a reference tool through nix: `tools/fixtures/_png_reference.py`) |
|
||||
| A codec (layer 3) | `src/Formats/codecs/compress/Deflate/` + `tests/codecs/deflate.luau` + `tools/fixtures/deflate.py` |
|
||||
| A codec (layer 3) | `src/Rosetta/codecs/compress/Deflate/` + `tests/codecs/deflate.luau` + `tools/fixtures/deflate.py` |
|
||||
|
||||
## 1. Layout and layers
|
||||
|
||||
```
|
||||
src/Formats/
|
||||
src/Rosetta/
|
||||
init.luau Registry.luau (generated) api (layer 6)
|
||||
ops/ ops (layer 5.5) editing on the standard types (F.ops.image /
|
||||
mesh / layers / audio / music; ImageOps, ...)
|
||||
@@ -49,9 +49,9 @@ Nothing but the api requires `host/`: formats are pure functions of bytes. A cod
|
||||
(`codecs/<compress|entropy|image|audio|video|text|font|model>/<Name>`); `containers/` and `core/` are flat. Moving a
|
||||
module: `python3 -I tools/move.py old/Path=new/Path` rewrites every reference (requires, deps, headers, docs).
|
||||
|
||||
REQUIRE: every require is a string literal `require("@formats/<path>")` (tests and tools may also use
|
||||
REQUIRE: every require is a string literal `require("@rosetta/<path>")` (tests and tools may also use
|
||||
`require("@tests/<path>")`). No `script.X`, no `@self`, no relative paths, no computed requires: `tools/build.py` turns
|
||||
these literals into Roblox instance paths and `require("formats.x.y")` for LuaJIT. `@formats/image/png` is the folder's
|
||||
these literals into Roblox instance paths and `require("rosetta.x.y")` for LuaJIT. `@rosetta/image/png` is the folder's
|
||||
`init.luau`.
|
||||
|
||||
DEPS: a format's `deps = { ... }` lists exactly the modules outside its folder that the folder requires.
|
||||
@@ -60,8 +60,8 @@ DEPS: a format's `deps = { ... }` lists exactly the modules outside its folder t
|
||||
|
||||
### Files
|
||||
```
|
||||
src/Formats/<category>/<fmt>/init.luau the contract (interpreted: never --!native)
|
||||
src/Formats/<category>/<fmt>/<Private>.luau hot code, --!native allowed (Decode, Encode, Huffman tables, ...)
|
||||
src/Rosetta/<category>/<fmt>/init.luau the contract (interpreted: never --!native)
|
||||
src/Rosetta/<category>/<fmt>/<Private>.luau hot code, --!native allowed (Decode, Encode, Huffman tables, ...)
|
||||
tests/<category>/<fmt>.luau the test (both runtimes)
|
||||
tools/fixtures/<fmt>.py fixture generator (reference tools via nix) -> tests/gen/<fmt>_*.luau
|
||||
```
|
||||
@@ -73,7 +73,7 @@ tools/fixtures/<fmt>.py fixture generator (reference tools v
|
||||
--!optimize 2 -- optional
|
||||
-- image/png/Decode: <what it is>. <Spec / port origin>. <Supports / not supported>.
|
||||
```
|
||||
The first comment line starts with the module path (`core/Bytes:`, `image/png:`, `image/png/Decode:`; `Formats:` for
|
||||
The first comment line starts with the module path (`core/Bytes:`, `image/png:`, `image/png/Decode:`; `Rosetta:` for
|
||||
the root). A format's `init.luau` header says what is supported and what is not, and where it came from (spec, port,
|
||||
absorbed repo).
|
||||
|
||||
@@ -86,10 +86,10 @@ contract are mandatory, the rest as needed):
|
||||
### The contract
|
||||
```luau
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Types = require("@formats/Types")
|
||||
local Decode = require("@formats/image/qoi/Decode")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Decode = require("@rosetta/image/qoi/Decode")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Qoi = {
|
||||
@@ -236,9 +236,9 @@ copying.
|
||||
```luau
|
||||
-- image/qoi tests: <what is covered>. Fixtures: tools/fixtures/qoi.py.
|
||||
local T = require("@tests/T")
|
||||
local Qoi = require("@formats/image/qoi")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Qoi = require("@rosetta/image/qoi")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Fx = require("@tests/gen/qoi") -- written by tools/fixtures/qoi.py
|
||||
|
||||
local t = T.suite("qoi")
|
||||
@@ -272,13 +272,13 @@ t:done()
|
||||
|
||||
## 4. Adding a format
|
||||
|
||||
1. `src/Formats/<category>/<fmt>/init.luau` from the template above (copy `image/png/init.luau`), private submodules
|
||||
1. `src/Rosetta/<category>/<fmt>/init.luau` from the template above (copy `image/png/init.luau`), private submodules
|
||||
next to it. Use `core/Bytes` for parsing, `core/Bits` / `codecs/entropy/Huffman` for entropy coding, the shared
|
||||
modules of section 2a for everything generic, `Types` constructors for the result.
|
||||
2. Shared code (a codec two formats need, a container) goes to `codecs/<domain>/` or `containers/` instead, with its
|
||||
own test in `tests/codecs/` / `tests/containers/`.
|
||||
3. `deps = { ... }` = the requires outside the folder.
|
||||
4. `python3 -I tools/gen_registry.py` (regenerates `src/Formats/Registry.luau` and `docs/FORMATS.md`; never edit those
|
||||
4. `python3 -I tools/gen_registry.py` (regenerates `src/Rosetta/Registry.luau` and `docs/FORMATS.md`; never edit those
|
||||
by hand; after a merge, just rerun it).
|
||||
5. `tools/fixtures/<fmt>.py` + `tests/<category>/<fmt>.luau`.
|
||||
6. `bash tools/test.sh <fmt>` while working (both runtimes), then `bash tools/test.sh` (everything + lint).
|
||||
@@ -296,7 +296,7 @@ making them (a missing `Bytes` method, a new `Types` field, a `Err` code).
|
||||
2. Provenance: the module header says `Absorbed from <repo> <version> (<author / licence>)` and what changed.
|
||||
3. Licence: copy the repo's licence / NOTICE into `licenses/` (`licenses/<repo>-LICENSE.txt`) and add a line to
|
||||
`licenses/NOTICE.md`. Third-party ports keep their upstream licence text there too.
|
||||
4. Requires: `if script then require(script.X) else require("@self/X")` becomes `require("@formats/<cat>/<fmt>/X")`;
|
||||
4. Requires: `if script then require(script.X) else require("@self/X")` becomes `require("@rosetta/<cat>/<fmt>/X")`;
|
||||
injected dependencies (`require(Png)(Deflate)`) become direct requires of the codec.
|
||||
5. Checksums / bit readers / Huffman tables the repo carries are replaced by `core/` ones when equivalent.
|
||||
6. Wrap the public API in the contract: `sniff`, `decode(r: Reader, opts)` (reading from `r.buf` between `r.base` and
|
||||
@@ -317,7 +317,7 @@ cover what it cannot:
|
||||
`elseif` to `else if` before darklua.
|
||||
- **If-expression tables**: darklua lowers `if c then x else y` to `(c and {x} or {y})[1]` unless `x` is a literal.
|
||||
build.py turns it back into `(c and (x) or (y))` when `x` is provably not nil/false (numbers, strings, arithmetic).
|
||||
- **Requires** become `require("formats.a.b")`; **stdlib names** come from `formats._compat` through locals injected on
|
||||
- **Requires** become `require("rosetta.a.b")`; **stdlib names** come from `rosetta._compat` through locals injected on
|
||||
the first line of each module (only the ones used: LuaJIT allows 60 upvalues per function).
|
||||
- `string.format("%s", x)` with interpolation and `tostring` of floats print differently on LuaJIT (14 significant
|
||||
digits); never compare formatted floats in tests.
|
||||
+16
-16
@@ -1,6 +1,6 @@
|
||||
# formats-luau guide
|
||||
# rosetta guide
|
||||
|
||||
formats-luau reads, writes and converts file formats in pure Luau. One source tree runs on Roblox, on LuaJIT / LÖVE
|
||||
rosetta reads, writes and converts file formats in pure Luau. One source tree runs on Roblox, on LuaJIT / LÖVE
|
||||
and in the luau CLI. Each format maps onto the standard type of its category, so a PNG and a WebP both load as the
|
||||
same `Image`, and every audio format opens as the same streaming `Decoder`.
|
||||
|
||||
@@ -44,15 +44,15 @@ as `F`, and its input files as variables such as `pngBytes` (a buffer) or `srtTe
|
||||
**Roblox (Rojo).** Build the Roblox tree, then let Rojo turn it into a model or sync it into Studio:
|
||||
|
||||
```sh
|
||||
python3 -I tools/build.py roblox # writes build/roblox/Formats (requires become instance paths)
|
||||
rojo build -o Formats.rbxm # default.project.json mounts build/roblox/Formats; or: rojo serve
|
||||
python3 -I tools/build.py roblox # writes build/roblox/Rosetta (requires become instance paths)
|
||||
rojo build -o Rosetta.rbxm # default.project.json mounts build/roblox/Rosetta; or: rojo serve
|
||||
```
|
||||
|
||||
Put the `Formats` ModuleScript somewhere both client and server can see it, for example ReplicatedStorage:
|
||||
Put the `Rosetta` ModuleScript somewhere both client and server can see it, for example ReplicatedStorage:
|
||||
|
||||
<!-- doc:display needs Roblox -->
|
||||
```luau
|
||||
local F = require(game:GetService("ReplicatedStorage").Formats)
|
||||
local F = require(game:GetService("ReplicatedStorage").Rosetta)
|
||||
```
|
||||
|
||||
Roblox has no file system: pass buffers or strings, for example from `HttpService:GetAsync` or a `buffer` you built.
|
||||
@@ -60,27 +60,27 @@ Roblox has no file system: pass buffers or strings, for example from `HttpServic
|
||||
**LuaJIT and LÖVE.** Build the Lua 5.1 tree:
|
||||
|
||||
```sh
|
||||
python3 -I tools/build.py luajit # writes build/luajit/formats/ (plain Lua 5.1 + the LuaJIT FFI)
|
||||
python3 -I tools/build.py luajit # writes build/luajit/rosetta/ (plain Lua 5.1 + the LuaJIT FFI)
|
||||
```
|
||||
|
||||
Then either copy `build/luajit/formats` into your game, or put the build on `package.path`:
|
||||
Then either copy `build/luajit/rosetta` into your game, or put the build on `package.path`:
|
||||
|
||||
<!-- doc:display plain LuaJIT code -->
|
||||
```lua
|
||||
package.path = "build/luajit/?.lua;build/luajit/?/init.lua;" .. package.path
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
```
|
||||
|
||||
The library carries its own copy of the Luau standard library pieces it uses (`buffer`, `bit32`, `utf8`, ...).
|
||||
Your own code gets them as globals with `require("formats._compat").install()`, which is useful when you read the
|
||||
Your own code gets them as globals with `require("rosetta._compat").install()`, which is useful when you read the
|
||||
pixel buffers yourself. [examples/love](../../examples/love/main.lua) is a runnable LÖVE example.
|
||||
|
||||
**luau CLI.** The repository's `.luaurc` defines the alias `@formats` for `src/Formats`, so a script run from the
|
||||
**luau CLI.** The repository's `.luaurc` defines the alias `@rosetta` for `src/Rosetta`, so a script run from the
|
||||
repository root can require the sources directly. The CLI has no file system.
|
||||
|
||||
<!-- doc:display a top-level require -->
|
||||
```luau
|
||||
local F = require("@formats")
|
||||
local F = require("@rosetta")
|
||||
```
|
||||
|
||||
The runnable programs in [examples/](../../examples) work this way: `luau examples/image.luau`.
|
||||
@@ -336,7 +336,7 @@ and `toSoundData` turns an `Audio` or a `Decoder` (read to its end) into 16-bit
|
||||
|
||||
<!-- doc:display needs LÖVE -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local img = assert(F.load("sprite.png")) -- love.filesystem path
|
||||
local texture = love.graphics.newImage(F.host.toImageData(img))
|
||||
local music = love.audio.newSource(F.host.toSoundData(F.audio.open("music.ogg")), "static")
|
||||
@@ -347,13 +347,13 @@ F.save(shot, "shot.png") -- to the save directory
|
||||
|
||||
**LuaJIT trace limits.** When the library loads on LuaJIT it raises the JIT's trace limits
|
||||
(`jit.opt.start("maxtrace=8000", "maxmcode=65536")`). The big decoders (Opus CELT, VP8, H.264, MPEG-1) outgrow the
|
||||
defaults and fall back to the interpreter, which is 2x or more slower. Set `FORMATS_NO_JIT_TUNE` before the first
|
||||
defaults and fall back to the interpreter, which is 2x or more slower. Set `ROSETTA_NO_JIT_TUNE` before the first
|
||||
`require` to leave the JIT settings alone:
|
||||
|
||||
<!-- doc:display plain LuaJIT code -->
|
||||
```lua
|
||||
FORMATS_NO_JIT_TUNE = true -- a global, read once when the library loads
|
||||
local F = require("formats")
|
||||
ROSETTA_NO_JIT_TUNE = true -- a global, read once when the library loads
|
||||
local F = require("rosetta")
|
||||
```
|
||||
|
||||
## Conventions
|
||||
|
||||
@@ -150,10 +150,10 @@ local zip = F.format("zip").create()
|
||||
zip:add("assets/", nil) -- a directory
|
||||
zip:add("assets/hello.txt", "hello", { level = 9, mtime = 1767225600 })
|
||||
zip:add("assets/raw.bin", buffer.create(1024), { method = "store" })
|
||||
local bytes = assert(F.save(zip, nil, { format = "zip", comment = "made by formats-luau" }))
|
||||
local bytes = assert(F.save(zip, nil, { format = "zip", comment = "made by rosetta" }))
|
||||
|
||||
local back = assert(F.archive.load(bytes))
|
||||
assert(#back:list() == 3 and back.meta.comment == "made by formats-luau")
|
||||
assert(#back:list() == 3 and back.meta.comment == "made by rosetta")
|
||||
assert(back:list()[3].method == "store")
|
||||
assert(back:remove("assets/raw.bin") and #back:list() == 2)
|
||||
|
||||
@@ -350,7 +350,7 @@ stored data); ARJ and Zoo are read only.
|
||||
```luau
|
||||
local lzh = assert(F.archive.load(lzhBytes))
|
||||
assert(lzh.format == "lha" and lzh:list()[1].method == "lh0") -- small files are stored
|
||||
assert(buffer.tostring(assert(lzh:read("readme.txt"))) == "formats-luau retro archives\n")
|
||||
assert(buffer.tostring(assert(lzh:read("readme.txt"))) == "rosetta retro archives\n")
|
||||
local arj = assert(F.archive.load(arjBytes))
|
||||
assert(arj:read("src/main.c"))
|
||||
local zoo = assert(F.archive.load(zooBytes))
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ used the same way.
|
||||
```luau
|
||||
local song = assert(F.audio.load(flacBytes)) -- Audio: the whole file decoded
|
||||
print(song.sampleRate, song.channels, song.frames) -- 44100 2 44100
|
||||
print(song.tags.title, song.tags.artist) -- Docs Tone formats-luau
|
||||
print(song.tags.title, song.tags.artist) -- Docs Tone rosetta
|
||||
local quieter = F.ops.audio.gainDb(song, -6)
|
||||
local mp3 = assert(F.save(quieter, nil, { format = "mp3", bitrate = 192000 })) -- a buffer
|
||||
assert(F.detect(mp3) == "mp3")
|
||||
@@ -225,7 +225,7 @@ source can be fed block by block:
|
||||
|
||||
<!-- doc:display needs LÖVE -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local sd = F.host.toSoundData(F.audio.load("music.flac")) -- whole file
|
||||
love.audio.newSource(sd):play()
|
||||
|
||||
@@ -313,7 +313,7 @@ assert(wv.bitsPerSample == 16 and wv.lossless and wv.tags.title == "Docs Tone")
|
||||
local exact, n = wv:readInt(1024) -- i32 samples, as wvunpack writes them
|
||||
assert(n == 1024 and buffer.readi32(exact, 0) == 0)
|
||||
local ape = assert(F.audio.load(apeBytes)) -- any level, fast .. insane
|
||||
assert(ape.meta.source.format == "ape" and ape.tags.artist == "formats-luau")
|
||||
assert(ape.meta.source.format == "ape" and ape.tags.artist == "rosetta")
|
||||
local tta = assert(F.audio.open(ttaBytes))
|
||||
tta:seek(0.5)
|
||||
assert(math.abs(tta:position() - 0.5) < 1e-6)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ STEP files (ISO 10303-21, "Part 21": AP203, AP214, AP242 and any other schema) l
|
||||
its *entity graph*, every `#id = TYPE(...)` instance with its arguments, exactly as written. Reading and writing the
|
||||
graph is built in and lossless (parse, write, parse gives the same entities).
|
||||
|
||||
Turning the graph into solid geometry needs a B-rep kernel, which formats-luau does not include: B-rep bodies and
|
||||
Turning the graph into solid geometry needs a B-rep kernel, which rosetta does not include: B-rep bodies and
|
||||
tessellated meshes come from a plug-in you inject as `F.plugins.brep` (for example
|
||||
brep-luau's modules). Without it, `F.cad.toBodies` / `fromBodies` / `tessellate` return
|
||||
`UNSUPPORTED` and everything else on this page still works.
|
||||
|
||||
+2
-2
@@ -277,7 +277,7 @@ An animated image also opens as a video (`F.video.open(gifBytes)`), and saves to
|
||||
|
||||
<!-- doc:display Roblox only -->
|
||||
```luau
|
||||
local F = require(game.ReplicatedStorage.Formats)
|
||||
local F = require(game.ReplicatedStorage.Rosetta)
|
||||
local img = assert(F.image.load(pngBuffer)) -- e.g. from HttpService:GetAsync(...)
|
||||
local editable = assert(F.host.toEditableImage(img)) -- needs rgba8: F.ops.image.convert first otherwise
|
||||
local label = Instance.new("ImageLabel")
|
||||
@@ -286,7 +286,7 @@ label.ImageContent = Content.fromObject(editable)
|
||||
|
||||
<!-- doc:display LÖVE only -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local img = assert(F.load("photo.png")) -- love.filesystem path
|
||||
local image = love.graphics.newImage(F.host.toImageData(img))
|
||||
local back = F.host.fromImageData(love.image.newImageData("other.png")) -- ImageData -> rgba8 Image
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ Its only use is as `opts.soundfont` when rendering MIDI.
|
||||
|
||||
```luau
|
||||
local bank = assert(F.music.load(sf2Bytes))
|
||||
assert(bank.kind == "soundfont" and bank.info.name == "formats-luau test bank")
|
||||
assert(bank.kind == "soundfont" and bank.info.name == "rosetta test bank")
|
||||
for _, p in bank.presets do
|
||||
print(p.bank, p.preset, p.name) -- 0 0 Sine, ...
|
||||
end
|
||||
|
||||
@@ -77,7 +77,7 @@ end
|
||||
|
||||
<!-- doc:display needs Roblox -->
|
||||
```luau
|
||||
local F = require(game:GetService("ReplicatedStorage").Formats)
|
||||
local F = require(game:GetService("ReplicatedStorage").Rosetta)
|
||||
local bytes = game:GetService("HttpService"):GetAsync("https://example.com/cat.webp")
|
||||
local img = assert(F.image.load(bytes))
|
||||
if img.format ~= "rgba8" then
|
||||
@@ -94,7 +94,7 @@ label.Parent = game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("Sc
|
||||
|
||||
<!-- doc:display needs LÖVE -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local image
|
||||
function love.load()
|
||||
local img = assert(F.load("cat.webp")) -- a love.filesystem path
|
||||
@@ -141,7 +141,7 @@ container calls them.
|
||||
```luau
|
||||
for _, bytes in { flacBytes, mp3Bytes, oggBytes } do
|
||||
local dec = assert(F.audio.open(bytes)) -- open reads the headers only
|
||||
assert(dec.tags.title == "Docs Tone" and dec.tags.artist == "formats-luau")
|
||||
assert(dec.tags.title == "Docs Tone" and dec.tags.artist == "rosetta")
|
||||
print(string.format("%s - %s (%.1f s, %d Hz)", dec.tags.artist, dec.tags.title, dec.duration, dec.sampleRate))
|
||||
end
|
||||
```
|
||||
|
||||
@@ -36,7 +36,7 @@ assert(F.detect(xml) == "rbxlx" and F.detect(placeBytes) == "rbxl")
|
||||
Property values keep the file's type, because a number alone could be an `Int32`, a `Float32` or an `Enum`. Arrays
|
||||
follow the argument order of the Roblox constructors, so `Vector3.new(table.unpack(v.value))` and
|
||||
`CFrame.new(table.unpack(v.value))` rebuild them in a game. The full list is in the header of
|
||||
`src/Formats/codecs/model/Rbx/init.luau`:
|
||||
`src/Rosetta/codecs/model/Rbx/init.luau`:
|
||||
|
||||
- **Text and numbers:** `String`, `BinaryString`, `ProtectedString`, `ContentId`, `SharedString` are strings.
|
||||
`Bool`, `Int32`, `Int64`, `Float32`, `Float64`, `Enum`, `BrickColor`, `Faces` and `Axes` are numbers and booleans.
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ assert(not string.find(buffer.tostring(plain), "KHR_draco", 1, true))
|
||||
```
|
||||
|
||||
Raw `.drc` files (and Draco data inside other formats) go through the codec itself:
|
||||
`require(Formats.codecs.model.Draco).decode(bytes)` returns `{ kind, numPoints, numFaces, indices, attributes }` with
|
||||
`require(Rosetta.codecs.model.Draco).decode(bytes)` returns `{ kind, numPoints, numFaces, indices, attributes }` with
|
||||
each attribute's values per point (`name`, `uniqueId`, `components`, `type`, `normalized`, `data`).
|
||||
|
||||
## Editing: `F.ops.mesh`
|
||||
|
||||
+2
-2
@@ -39,13 +39,13 @@ another format): `F.video.open` / `F.load` set it; calling a video format's `ope
|
||||
|
||||
## Adding a codec (H.264, ...)
|
||||
|
||||
The registry is static (Roblox has no dynamic require): add an entry to `BUILTIN` in `src/Formats/codecs/video/Video/init.luau`
|
||||
The registry is static (Roblox has no dynamic require): add an entry to `BUILTIN` in `src/Rosetta/codecs/video/Video/init.luau`
|
||||
with a `new` constructor that requires the codec lazily, or call `Video.register(entry)` at run time
|
||||
(`F.video.codecs.register`).
|
||||
|
||||
```luau
|
||||
{ id = "h264", name = "H.264 / AVC", fourcc = { "avc1", "avc3", "H264", ... }, matroska = { "V_MPEG4/ISO/AVC" },
|
||||
new = function(track, opts) return require("@formats/codecs/video/H264").newVideoDecoder(track, opts) end }
|
||||
new = function(track, opts) return require("@rosetta/codecs/video/H264").newVideoDecoder(track, opts) end }
|
||||
```
|
||||
|
||||
`new(track, opts)` returns a `Types.VideoCodecDecoder`:
|
||||
|
||||
Reference in new issue
Block a user