merge ws/polish
This commit is contained in:
commit
551fd937b9
20 files changed
+369
-94
No files matched your search
@@ -5,10 +5,11 @@ generation) and on **LuaJIT / LÖVE** (through `tools/build.py`). Every format o
|
||||
(`src/Formats/Types.luau`): a PNG and a WebP both load as an `Image`, every audio format opens as the same streaming
|
||||
`Decoder`, every model format loads as a `Scene`.
|
||||
|
||||
About 76 formats across images, audio, video, 3D models, CAD, fonts, archives, data, vector graphics, layered images,
|
||||
subtitles, music and playlists: see [docs/FORMATS.md](docs/FORMATS.md) (generated from the code) for the list and each
|
||||
format's capabilities, [docs/API.md](docs/API.md) for the whole API, and the guide
|
||||
([docs/guide/README.md](docs/guide/README.md)) for walkthroughs.
|
||||
174 formats: images (25), audio (21), video (11), 3D models (32), CAD (1), fonts (11), archives (31), data (11),
|
||||
vector graphics and tile maps (2), layered images (3), subtitles (3), music (20) and playlists (3). See
|
||||
[docs/FORMATS.md](docs/FORMATS.md) (generated from the code) for the list and each format's capabilities,
|
||||
[docs/API.md](docs/API.md) for the whole API, and the guide ([docs/guide/README.md](docs/guide/README.md)) for
|
||||
walkthroughs. `tools/lint.sh` checks these counts against the registry.
|
||||
|
||||
```luau
|
||||
local F = require(Formats) -- LuaJIT: require("formats"); luau CLI: require("@formats")
|
||||
@@ -41,33 +42,38 @@ standard library pieces come from `formats/_compat.lua`). Copy the `formats` fol
|
||||
## Quick start
|
||||
|
||||
```luau
|
||||
-- images: PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO, PNM, HDR -> Image (rgba8 pixels in a buffer)
|
||||
-- images: PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO, PNM, HDR, EXR, DDS, KTX, PCX, ... -> Image
|
||||
local img = F.image.load(pngBytes)
|
||||
print(img.width, img.height, #(img.frames or {}), img.loops) -- animations: frames; loops = play count, 0 forever
|
||||
local jpg = F.save(img, nil, { format = "jpeg", quality = 85 })
|
||||
|
||||
-- audio: WAV, FLAC, MP3 / MP2, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC -> streaming Decoder or Audio
|
||||
-- audio: WAV, FLAC, MP3 / MP2, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC, WavPack, APE, TTA, Musepack, AC-3,
|
||||
-- QOA, ADPCM (ADX, VAG, BRSTM, ...) -> streaming Decoder or Audio
|
||||
local dec = F.audio.open(flacBytes) -- dec:read(n) -> interleaved f32 buffer, frames; dec:seek(s)
|
||||
local song = F.audio.load(mp3Bytes) -- Audio { sampleRate, channels, frames, samples, tags }
|
||||
local mono = F.ops.audio.downmix(song, 1) -- channels are in WAVE order; tags keys are lower case
|
||||
local opus = F.save(F.ops.audio.resample(mono, 48000), nil, { format = "opus", bitrate = 64000 })
|
||||
|
||||
-- video: MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Y4M (+ animated images) -> VideoDecoder
|
||||
-- video: MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Ogg Theora, FLV, FLI, Smacker, Y4M (+ animated images)
|
||||
-- -> VideoDecoder
|
||||
local v = F.video.open(mp4Bytes) -- v:nextFrame() -> frame (image yuv420p or rgba8, pts)
|
||||
|
||||
-- models: glTF / GLB (+ Draco), OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX, 3DS, MS3D, LWO, .x, IQM, B3D,
|
||||
-- PMX / PMD, VRML, X3D, LDraw -> Scene
|
||||
-- PMX / PMD, VRML, X3D, LDraw, MD2 / MD3 / MDL / MD5, BSP, SMD, Roblox (rbxm / rbxmx / .mesh),
|
||||
-- Minecraft (.schem, .mca), Qubicle -> Scene
|
||||
local scene = F.model.load(glbBytes)
|
||||
local prim = F.ops.mesh.merge(scene) -- one triangle primitive in world space
|
||||
|
||||
-- fonts, archives, data, vector, layered, subtitles, music, playlists
|
||||
local font = F.font.load(ttfBytes) -- outlines, metrics, kerning
|
||||
local zip = F.archive.load(zipBytes) -- entries; F.archive.save writes zip / tar / gzip
|
||||
local t = F.data.load('{"a": [1, 2]}', { format = "json" }) -- JSON, XML, YAML, TOML, CSV, INI, plist, msgpack, CBOR
|
||||
local icon = F.ops.vector.rasterize(F.vector.load(svgText), 64, 64)
|
||||
local flat = F.ops.layers.flatten(F.layered.load(psdBytes))
|
||||
local subs = F.subtitle.load(srtText)
|
||||
local tune = F.music.load(modBytes) -- MOD / S3M / XM / IT / MIDI, rendered to audio on request
|
||||
-- CAD, fonts, archives, data, vector, tile maps, layered, subtitles, music, playlists
|
||||
local font = F.font.load(ttfBytes) -- TTF / OTF, WOFF / WOFF2, BMFont, bitmap fonts: outlines, kerning
|
||||
local zip = F.archive.load(zipBytes) -- zip, tar, 7z, gzip, cab, iso, ...; saves zip / tar / gzip
|
||||
local t = F.data.load('{"a": [1, 2]}', { format = "json" }) -- JSON, XML, YAML, TOML, CSV, INI, plist, CBOR, NBT, ...
|
||||
local icon = F.ops.vector.rasterize(F.vector.load(svgText), 64, 64) -- SVG; Tiled maps load as a TileMap
|
||||
local flat = F.ops.layers.flatten(F.layered.load(psdBytes)) -- PSD, Aseprite, OpenRaster
|
||||
local subs = F.subtitle.load(srtText) -- SRT, WebVTT, ASS / SSA
|
||||
local tune = F.music.load(modBytes) -- MOD / S3M / XM / IT / AHX / MIDI, ...: rendered to audio
|
||||
local step = F.cad.load(stepText) -- STEP entity graph (B-rep through a plug-in)
|
||||
local list = F.playlist.load(m3uText) -- M3U / M3U8, PLS, XSPF
|
||||
```
|
||||
|
||||
## The API in short
|
||||
@@ -100,20 +106,25 @@ hands to formats (decodeImage / encodeImage / openAudio / plugins): [docs/API.md
|
||||
```
|
||||
src/Formats/
|
||||
init.luau Registry.luau (generated) api: F.*
|
||||
ops/ editing on the standard types (ImageOps, MeshOps, LayerOps, AudioOps)
|
||||
ops/ editing on the standard types (ImageOps, MeshOps, LayerOps, AudioOps, ...)
|
||||
<category>/<fmt>/ formats: only what is specific to the format (parsing, mapping, writing)
|
||||
containers/ Chunks, Riff, IsoBmff, Ebml, Ogg, Zip, Tar, Avi, MpegTs, MpegPs, ...
|
||||
codecs/compress/ Deflate, Lzma, Zstd, Brotli, Bzip2, Lzw
|
||||
codecs/entropy/ Huffman, RangeCoder
|
||||
codecs/image/ Jpeg, Dct, Vp8, Vp8L, Pixels, Yuv, Quantize, Raster, Blend
|
||||
codecs/audio/ Opus, Vorbis, Flac, Mpa (MP1-3), Aac, Alac, Mdct, Pcm, Stream, Resample,
|
||||
VorbisComment, Tracker, SoundFont
|
||||
codecs/video/ H264, Mpeg1, Video (the codec registry)
|
||||
codecs/text/ codecs/font/ codecs/model/ Json, Xml, Text, Url / TrueType, Cff / Mat4, MeshFlatten, Draco,
|
||||
Sampler, Vrml, Rig
|
||||
containers/ Archive AudioWrap Avi Chunks Cpio Demux Ebml Fat Iso9660 IsoBmff MacFile
|
||||
MpegEs MpegPs MpegTs Ogg Riff Tar Zip
|
||||
codecs/compress/ Brotli Bzip2 Deflate Explode Lz4 Lzh Lzma Lzw Lzx PackBits Quantum
|
||||
UnixCompress Xxh32 Zstd
|
||||
codecs/entropy/ Huffman RangeCoder
|
||||
codecs/image/ Bcn Blend Dct Etc Half Jpeg Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
|
||||
codecs/audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa (MP1-3)
|
||||
Musepack Opus Pcm Qoa Resample SoundFont Stream Tracker Tta Vorbis
|
||||
VorbisComment WavPack
|
||||
codecs/video/ Dsp H263 H264 Legacy (FLI, Cinepak, MSV1, QT RLE, SMC, Smacker) Mpeg1 Mpeg2
|
||||
Theora Video (the codec registry)
|
||||
codecs/text/ Json Nbt Text Url Xml
|
||||
codecs/font/ Bitmap Cff GlyphNames TrueType
|
||||
codecs/model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml
|
||||
host/ runtime adapters (only the api uses them)
|
||||
Types.luau the standard types + constructors
|
||||
core/ Bytes, Bits, Err, Crc32, Adler32, Base64, Md5, Input, Sniff
|
||||
core/ Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input Md5 Sniff
|
||||
compat/luajit.lua tools/ tests/ (T.luau, <category>/<fmt>.luau, codecs/, containers/, gen/) docs/ licenses/
|
||||
examples/love/
|
||||
```
|
||||
@@ -125,7 +136,7 @@ How the layers fit, the format contract, and what belongs in a format folder: [d
|
||||
```sh
|
||||
bash tools/test.sh # fixtures, registry, build, every test under luau --codegen -O2 and LuaJIT, lint
|
||||
bash tools/test.sh png # one test (both runtimes), no lint
|
||||
bash tools/lint.sh # globals, type baseline, headers, requires, native-throw, layers, deps, contract, DUP
|
||||
bash tools/lint.sh # globals, types, headers, requires, native-throw, layers, deps, contract, DUP, docs
|
||||
bash tools/bench.sh # throughput on both runtimes (pin it: taskset -c 2 bash tools/bench.sh)
|
||||
python3 -I tools/build.py # build/roblox + build/luajit
|
||||
python3 -I tools/gen_registry.py # src/Formats/Registry.luau + docs/FORMATS.md from the format folders
|
||||
|
||||
+25
-8
@@ -23,17 +23,23 @@ src/Formats/
|
||||
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, ...
|
||||
containers/ containers (layer 4) Archive AudioWrap Avi Chunks Cpio Demux Ebml
|
||||
Fat Iso9660 IsoBmff MacFile MpegEs MpegPs
|
||||
MpegTs Ogg Riff Tar Zip
|
||||
codecs/<domain>/<Name> codecs (layer 3) generic algorithms, by domain:
|
||||
compress/ Deflate Lzma Zstd Brotli Bzip2 Lzw Lz4 entropy/ Huffman RangeCoder
|
||||
image/ Jpeg Dct Vp8 Vp8L Pixels Yuv Quantize Raster Blend
|
||||
audio/ Opus Vorbis Flac Mpa Aac Alac Mdct Pcm Stream Resample VorbisComment Tracker SoundFont
|
||||
video/ H264 Mpeg1 Video (the video codec registry) text/ Json Xml Text Url
|
||||
font/ TrueType Cff model/ Mat4 MeshFlatten Rbx
|
||||
compress/ Brotli Bzip2 Deflate Explode Lz4 Lzh Lzma Lzw Lzx PackBits Quantum UnixCompress Xxh32 Zstd
|
||||
entropy/ Huffman RangeCoder
|
||||
image/ Bcn Blend Dct Etc Half Jpeg Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
|
||||
audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa Musepack Opus Pcm Qoa Resample
|
||||
SoundFont Stream Tracker Tta Vorbis VorbisComment WavPack
|
||||
video/ Dsp H263 H264 Legacy Mpeg1 Mpeg2 Theora Video (the video codec registry)
|
||||
text/ Json Nbt Text Url Xml
|
||||
font/ Bitmap Cff GlyphNames TrueType
|
||||
model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml
|
||||
host/ host (layer 2) runtime adapters; only the api uses them
|
||||
Types.luau types (layer 1) standard types + constructors
|
||||
core/ core (layer 0) Bytes, Bits, Err, Crc32, Adler32, Base64, Md5,
|
||||
Input, Sniff (runtime-neutral primitives)
|
||||
core/ core (layer 0) Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input
|
||||
Md5 Sniff (runtime-neutral primitives)
|
||||
```
|
||||
|
||||
LAYERS: a module requires only what is below it. core requires core; Types requires core; codecs require core, Types
|
||||
@@ -207,6 +213,17 @@ them. Anything generic goes down a layer and is called:
|
||||
| sniffing text (BOM) / magic | `core/Sniff` |
|
||||
| private-submodule errors -> Err | `core/Err.from` |
|
||||
| UTF-8 code points, text decoding | `codecs/text/Text` |
|
||||
| ADPCM (IMA, MS, ADX, PS-ADPCM, DSP, Flash, ModPlug) | `codecs/audio/Adpcm` |
|
||||
| APE tags | `codecs/audio/ApeTag` |
|
||||
| GPU texture pixels (BCn, ETC / EAC, uncompressed texel layouts, half floats) | `codecs/image/Texture` (`Bcn`, `Etc`, `Texel`, `Half`) |
|
||||
| animation channels sampled at a time; game-model frames, joints and skins -> Scene | `codecs/model/Sampler`, `codecs/model/Rig` |
|
||||
| polygons with holes -> triangles | `codecs/model/Polygon` |
|
||||
| NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` |
|
||||
| Roblox instance trees and property values | `codecs/model/Rbx` |
|
||||
| bitmap fonts as a Font; PostScript glyph names | `codecs/font/Bitmap`, `codecs/font/GlyphNames` |
|
||||
| CRC-16 (XMODEM / ARC), xxHash32 | `core/Crc16`, `codecs/compress/Xxh32` |
|
||||
| Mac files (data + resource forks), FAT / ISO 9660 file systems, cpio | `containers/MacFile`, `containers/Fat`, `containers/Iso9660`, `containers/Cpio` |
|
||||
| 8x8 IDCT and half-pel motion compensation of MPEG-style video | `codecs/video/Dsp` |
|
||||
|
||||
DUP enforces the direction: a function body of 12 or more code lines repeated token for token in another module
|
||||
fails the lint. When two formats need the same code, move it down (to `codecs/<domain>/` or `containers/`) instead of
|
||||
|
||||
@@ -9,20 +9,20 @@ and the host notes. Each standard type has its own page:
|
||||
|
||||
| Page | Type(s) | Formats |
|
||||
|---|---|---|
|
||||
| [Images](image.md) | `Image`, `Frame` (animation) | PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO, PNM, HDR |
|
||||
| [Audio](audio.md) | `Audio`, `Decoder` | WAV, FLAC, MP3, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC |
|
||||
| [Music](music.md) | `Module`, `Midi` | MOD, S3M, XM, IT, MIDI, SoundFont 2 |
|
||||
| [Video](video.md) | `VideoDecoder`, `Demuxer`, `Track`, `Packet` | MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Y4M, H.264 |
|
||||
| [3D scenes](scene.md) | `Scene`, `Voxels` | glTF / GLB, OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX |
|
||||
| [Images](image.md) | `Image`, `Frame` (animation) | PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO / CUR, PNM, HDR, OpenEXR, DDS, KTX, VTF, BLP, TIM, PCX, SGI, Sun Raster, ILBM, XPM, XBM, ICNS, ANI |
|
||||
| [Audio](audio.md) | `Audio`, `Decoder` | WAV, FLAC, MP3, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC, WavPack, APE, TTA, Musepack, AC-3, QOA, ADPCM, ADX, VAG, BRSTM |
|
||||
| [Music](music.md) | `Module`, `Midi` | MOD, S3M, XM, IT, MTM, 669, STM, ULT, OKT, MED, PTM, FAR, UMX, AHX / HVL, MIDI, MUS, XMI, HMP, SoundFont 2 |
|
||||
| [Video](video.md) | `VideoDecoder`, `Demuxer`, `Track`, `Packet` | MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Ogg Theora, FLV, FLI / FLC, Smacker, Y4M, H.264 |
|
||||
| [3D scenes](scene.md) | `Scene`, `Voxels` | glTF / GLB, OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX, 3DS, MS3D, B3D, LDraw, LWO, .x, IQM, PMX / PMD, VRML, X3D, MD2, MD3, MDL, MD5, BSP, SMD |
|
||||
| [Roblox](roblox.md) | `RbxTree` (`F.Rbx`), `Scene` | rbxm / rbxl, rbxmx / rbxlx, Roblox .mesh |
|
||||
| [CAD](cad.md) | `Cad` (STEP) | STEP (B-rep through a plug-in) |
|
||||
| [Fonts](font.md) | `Font` | TTF / OTF, WOFF, WOFF2, BMFont |
|
||||
| [Archives](archive.md) | `Archive` | zip, tar, gzip, 7z, xz, zstd, Brotli, bzip2 |
|
||||
| [Fonts](font.md) | `Font` | TTF / OTF, WOFF, WOFF2, BMFont, BDF, PCF, PSF, FON, Type 1, EOT, Hershey |
|
||||
| [Archives](archive.md) | `Archive` | zip, tar, gzip, 7z, xz, zstd, Brotli, bzip2, PAK, WAD, GRP, VPK, MPQ, cpio, ar / deb, rpm, .Z, LZ4, ISO 9660, LHA, ARJ, Zoo, uu / yEnc / BinHex / MacBinary / AppleSingle, D64, ADF, FAT, CAB |
|
||||
| [Data](data.md) | plain values, `XmlNode`, `Date` | JSON, XML, YAML, TOML, CSV, INI, MessagePack, CBOR, plist |
|
||||
| [Minecraft and voxels](voxel.md) | typed values, `Scene` + `Voxels` | NBT, SNBT, `.schem` / `.schematic` / `.litematic`, Anvil `.mca`, Qubicle `.qb` |
|
||||
| [Vector](vector.md) | `Vector` | SVG |
|
||||
| [Layered images](layered.md) | `Layered` | PSD, Aseprite |
|
||||
| [Tile maps](tilemap.md) | `TileMap` | Tiled TMX / TMJ |
|
||||
| [Layered images](layered.md) | `Layered` | PSD, Aseprite, OpenRaster |
|
||||
| [Tile maps](tilemap.md) | `TileMap` | Tiled TMX / TMJ (+ TSX / TSJ tilesets) |
|
||||
| [Subtitles](subtitles.md) | `Subtitles`, `Cue` | SRT, WebVTT, ASS / SSA |
|
||||
| [Playlists](playlist.md) | `Playlist` | M3U / M3U8 (HLS), PLS, XSPF |
|
||||
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
Every archive format loads as one `Archive` value: a list of named entries whose bytes you `read` on demand. Zip,
|
||||
tar and 7z hold many entries; gzip, xz, zstd, bzip2 and Brotli files are *single-stream* archives with one entry
|
||||
(the decompressed data). A `.tar.gz` (`.tgz`, `.tar.xz`, `.tar.zst`, `.tar.bz2`, `.tar.br`) loads straight as the tar
|
||||
inside. Zip, tar and gzip are writable; any Archive can be written as any of them.
|
||||
inside. Zip, tar and gzip are writable; any Archive can be written as any of them. The same value holds the
|
||||
[game archives](#game-archives) (PAK, WAD, GRP, VPK, MPQ), the [Unix, package and disc archives](#unix-package-and-disc-archives)
|
||||
(cpio, ar / .deb, rpm, .Z, .lz4, ISO 9660), [LHA, ARJ and Zoo](#lha-arj-and-zoo), the [text and Mac
|
||||
encodings](#encodings) (uuencode, yEnc, BinHex, MacBinary, AppleSingle), [disk images](#disk-images) (D64, ADF, FAT)
|
||||
and [Microsoft Cabinet](#microsoft-cabinet) files: [Formats](#formats) lists them all.
|
||||
|
||||
```luau
|
||||
local zip = assert(F.archive.load(zipBytes))
|
||||
|
||||
@@ -340,6 +340,7 @@ is an error there), CSV needs rows, INI needs sections of scalars, JSON has no b
|
||||
| msgpack (`.msgpack`, `.mpk`) | yes | yes | values, buffers, Dates |
|
||||
| cbor (`.cbor`) | yes | yes | values, buffers, Dates, tagged values |
|
||||
| plist (`.plist`) | XML + binary | XML | values, buffers, Dates |
|
||||
| nbt (`.nbt`, `.dat`, `.mcstructure`), snbt (`.snbt`) | yes | yes | typed values: see [Minecraft and voxels](voxel.md) |
|
||||
|
||||
Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
|
||||
+3
-1
@@ -2,7 +2,9 @@
|
||||
|
||||
Every font format loads as one `Font`: metrics, a character map, advances, kerning and glyph images. Outline fonts
|
||||
(TrueType / OpenType `.ttf` / `.otf` / `.ttc`, WOFF, WOFF2) also give glyph outlines and rasterize at any size.
|
||||
Bitmap fonts (AngelCode BMFont `.fnt`) crop their glyphs from page images. Fonts are read-only except BMFont, which is
|
||||
Bitmap fonts (AngelCode BMFont `.fnt`) crop their glyphs from page images; the [pixel fonts](#bitmap-fonts) (BDF,
|
||||
PCF, PSF, Windows FON) carry their glyph bitmaps, and [Type 1, EOT and Hershey](#type-1-eot-and-hershey) fonts load
|
||||
too. Fonts are read-only except BMFont, which is
|
||||
also how an outline font is *baked* into a texture atlas for a game.
|
||||
|
||||
```luau
|
||||
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
# Images
|
||||
|
||||
Every image format (PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO / CUR, PNM / PAM / PFM, Radiance HDR) loads
|
||||
as one `Image`: a width, a height, a pixel format and one tightly packed `buffer`. Animations (GIF, APNG, animated
|
||||
Every image format (PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO / CUR, PNM / PAM / PFM, Radiance HDR,
|
||||
OpenEXR, the [game textures](#game-textures) DDS / KTX / VTF / BLP / TIM, and the [older formats](#formats) PCX, SGI,
|
||||
Sun Raster, ILBM, XPM, XBM, ICNS, ANI) loads as one `Image`: a width, a height, a pixel format and one tightly packed `buffer`. Animations (GIF, APNG, animated
|
||||
WebP) and multi-image files (TIFF pages, ICO entries) add a list of `Frame`s. Editing goes through `F.ops.image`.
|
||||
|
||||
```luau
|
||||
|
||||
+3
-2
@@ -2,8 +2,9 @@
|
||||
|
||||
Music files hold notes and instruments, not a recording. Tracker modules (MOD, S3M, XM, IT, and the
|
||||
[other trackers](#more-tracker-formats): MTM, 669, STM, ULT, OKT, MED, PTM, FAR, UMX) load as a **Module**:
|
||||
the patterns, the order list, the samples and the instruments. Standard MIDI files load as a **Midi**: tracks of
|
||||
timed events. Both render to the standard audio [Decoder](audio.md#decoder), so every music file can also be
|
||||
the patterns, the order list, the samples and the instruments; AHX / HivelyTracker songs are Modules with their own
|
||||
synth. Standard MIDI files (and Doom MUS, Miles XMI and HMP: see [AHX / HVL and MIDI
|
||||
variants](#ahx--hvl-and-midi-variants)) load as a **Midi**: tracks of timed events. Both render to the standard audio [Decoder](audio.md#decoder), so every music file can also be
|
||||
played, analysed or saved as audio. MIDI renders through a SoundFont 2 bank, or through a small built-in set of
|
||||
waveforms when you don't give one.
|
||||
|
||||
|
||||
+4
-1
@@ -1,7 +1,8 @@
|
||||
# Scene (3D models) and Voxels
|
||||
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D, B3D, LDraw, LightWave
|
||||
LWO, DirectX .x, IQM, PMX / PMD, VRML, X3D) loads as one `Scene`, a structure shaped like glTF 2.0: a node tree, meshes
|
||||
LWO, DirectX .x, IQM, PMX / PMD, VRML, X3D, the [game models](#game-models) MD2 / MD3 / MDL / MD5 / BSP / SMD,
|
||||
[Roblox meshes](roblox.md) and the [Minecraft and Qubicle voxel files](voxel.md)) loads as one `Scene`, a structure shaped like glTF 2.0: a node tree, meshes
|
||||
made of primitives, flat attribute buffers (accessors), PBR materials, textures, cameras, lights, skins and animations.
|
||||
Mesh-only formats (STL, PLY, OFF) give a one-node scene. MagicaVoxel files also carry voxel grids (`scene.voxels`).
|
||||
Editing goes through `F.ops.mesh`.
|
||||
@@ -745,6 +746,8 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
|
||||
| STEP | via the CAD plug-in | | see [cad.md](cad.md) |
|
||||
| MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above |
|
||||
| SMD | yes | yes | Valve studiomdl data |
|
||||
| Roblox `.mesh` (robloxmesh) | yes | yes | see [roblox.md](roblox.md) |
|
||||
| Roblox `.rbxm` / `.rbxl`, `.rbxmx` / `.rbxlx` | as an `RbxTree` | yes | instance trees with typed properties: see [roblox.md](roblox.md) |
|
||||
|
||||
Capabilities per format: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
|
||||
+5
-7
@@ -318,8 +318,9 @@ assert(F.video.open(mkv).codec == "theora")
|
||||
FLV (Flash Video) opens like any other container. Its onMetaData script tag is `v.meta.metadata` (duration, width,
|
||||
height, framerate, codec ids, encoder, ...). Sorenson Spark (FLV1) and H.263 (in 3GP / MP4 `s263`, AVI `H263`)
|
||||
decode bit-exactly as ffmpeg decodes them; H.264 tracks carry their avcC in `track.config` and their B-frame
|
||||
composition times in the pts. VP6, screen video, Flash ADPCM, Nellymoser and Speex tracks are known (and remuxable)
|
||||
but not decoded: `nextFrame` / `v.audioError` say UNSUPPORTED. Writing FLV copies H.264 + AAC / MP3 from MP4,
|
||||
composition times in the pts. Flash ADPCM audio decodes (bit-exact with ffmpeg's `adpcm_swf`) next to MP3, AAC and
|
||||
PCM. VP6, screen video, Nellymoser and Speex tracks are known (and remuxable) but not decoded: `nextFrame` /
|
||||
`v.audioError` say UNSUPPORTED. Writing FLV copies H.264 + AAC / MP3 from MP4,
|
||||
Matroska or FLV sources (FLV has no codec here that encodes).
|
||||
|
||||
```luau
|
||||
@@ -394,18 +395,15 @@ editable:WritePixelsBuffer(Vector2.zero, editable.Size, v:toRGBA(frame).pixels)
|
||||
| mpegts, mpegps | yes | - | MPEG-1, MPEG-2, H.264 |
|
||||
| y4m | yes | yes | raw |
|
||||
| h264 (Annex B) | yes | yes (copy) | H.264 |
|
||||
| fli / flc / flx | yes | - | FLIC (8-bit palettised, 15 / 16 / 24-bit): see [Legacy video](#legacy-video) |
|
||||
| smk | yes | - | Smacker video (SMK2 / SMK4) + Smacker audio / PCM: see [Legacy video](#legacy-video) |
|
||||
| gif, png (APNG), webp | as video | as video via the image writers | frames |
|
||||
|
||||
See [FORMATS.md](../FORMATS.md). Subtitle tracks of Matroska files are read as cues by `F.format("mkv").subtitles`.
|
||||
|
||||
<!-- ws-video2-legacy: formats table addition -->
|
||||
| fli / flc / flx | yes | - | FLIC (8-bit palettised, 15 / 16 / 24-bit) |
|
||||
| smk | yes | - | Smacker video (SMK2 / SMK4) + Smacker audio / PCM |
|
||||
|
||||
AVI, MOV / MP4 and MKV (V_MS/VFW/FOURCC, V_QUICKTIME) also decode the legacy codecs: Cinepak, Microsoft Video 1,
|
||||
QuickTime Animation (RLE) and QuickTime Graphics (SMC). See [Legacy video](#legacy-video).
|
||||
|
||||
<!-- ws-video2-legacy: section -->
|
||||
## Legacy video
|
||||
|
||||
The 1990s formats and codecs decode to **rgba8** frames (they are palettised or RGB, not YUV), each frame painted
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
-- Adpcm.psx(src, p, pstride, nframes, st, so, dst, d, ds) -- Sony PS-ADPCM (VAG): 16-byte frames, 28 samples
|
||||
-- Adpcm.dsp(src, p, count, coefs, co, st, so, dst, d, ds) -- Nintendo DSP: 8-byte frames, 14 samples
|
||||
-- Adpcm.modplug(src, p, count, dst, d) -- ModPlug ADPCM (XM / MOD samples)
|
||||
-- Adpcm.swfFrames(src, p, n, ch) -> frames -- Flash (SWF / FLV) ADPCM: one packet's length
|
||||
-- Adpcm.swf(src, p, n, ch, dst, d) -> frames -- Flash ADPCM: one packet of n bytes
|
||||
-- encoders: imaEncode, imaWavEncode, msEncode, adxEncode, psxEncode, dspEncode (see each)
|
||||
--
|
||||
-- Every function reads only the bytes its arguments describe: the caller checks the ranges (byte counts per call are
|
||||
@@ -704,4 +706,113 @@ function Adpcm.modplug(src: buffer, p: number, count: number, dst: buffer, d: nu
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ Flash ADPCM
|
||||
-- The SWF / FLV ADPCM (SoundFormat 1, Adobe's SWF specification, "ADPCM compression"): an MSB-first bit stream of
|
||||
-- 2 bits (code size - 2), then blocks of 4096 frames: per channel a signed 16-bit first sample and a 6-bit step
|
||||
-- index, then 4095 frames of `bits`-bit codes, channels interleaved. A code is IMA generalised to 2..5 bits: sign in
|
||||
-- the top bit, the magnitude bits adding step, step/2, ... and the final step/2^(bits-1) (as ffmpeg's adpcm_swf and
|
||||
-- the spec's reference decoder do); the step index moves by SWF_INDEX[bits]. The last block may be short.
|
||||
local SWF_INDEX: { { number } } = {
|
||||
{ -1, 2 },
|
||||
{ -1, -1, 2, 4 },
|
||||
{ -1, -1, -1, -1, 2, 4, 6, 8 },
|
||||
{ -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 },
|
||||
}
|
||||
|
||||
-- swfFrames: the frame count of one Flash ADPCM packet (n bytes at p, n >= 1)
|
||||
function Adpcm.swfFrames(src: buffer, p: number, n: number, ch: number): number
|
||||
if n < 1 or ch < 1 then
|
||||
return 0
|
||||
end
|
||||
local bits = rshift(readu8(src, p), 6) + 2
|
||||
local total = n * 8 - 2
|
||||
local hdr = 22 * ch
|
||||
local block = hdr + bits * ch * 4095
|
||||
local blocks = total // block
|
||||
local left = total - blocks * block
|
||||
local frames = blocks * 4096
|
||||
if left >= hdr then
|
||||
frames += 1 + (left - hdr) // (bits * ch)
|
||||
end
|
||||
return frames
|
||||
end
|
||||
|
||||
-- the k-bit (k <= 16) MSB-first value at bit position pos of src[p ..]; bytes at or past e read as 0
|
||||
local function msb(src: buffer, p: number, e: number, pos: number, k: number): number
|
||||
local q = p + rshift(pos, 3)
|
||||
local v = readu8(src, q) * 65536
|
||||
if q + 1 < e then
|
||||
v += readu8(src, q + 1) * 256
|
||||
end
|
||||
if q + 2 < e then
|
||||
v += readu8(src, q + 2)
|
||||
end
|
||||
return band(rshift(v, 24 - band(pos, 7) - k), lshift(1, k) - 1)
|
||||
end
|
||||
|
||||
-- swf: one Flash ADPCM packet (n bytes at p, ch channels) -> interleaved f32 frames to dst from float index d; returns
|
||||
-- the frame count (Adpcm.swfFrames). Reads p .. p + n - 1 only.
|
||||
function Adpcm.swf(src: buffer, p: number, n: number, ch: number, dst: buffer, d: number): number
|
||||
local frames = Adpcm.swfFrames(src, p, n, ch)
|
||||
if frames == 0 then
|
||||
return 0
|
||||
end
|
||||
local e = p + n
|
||||
local bits = rshift(readu8(src, p), 6) + 2
|
||||
local tab = SWF_INDEX[bits - 1]
|
||||
local k0 = lshift(1, bits - 2)
|
||||
local sign = lshift(1, bits - 1)
|
||||
local mask = sign - 1
|
||||
local pred = table.create(ch, 0)
|
||||
local index = table.create(ch, 0)
|
||||
local pos = 2
|
||||
local o = d * 4
|
||||
local done = 0
|
||||
while done < frames do
|
||||
for c = 1, ch do
|
||||
local v = msb(src, p, e, pos, 16)
|
||||
if v >= 32768 then
|
||||
v -= 65536
|
||||
end
|
||||
pred[c] = v
|
||||
index[c] = msb(src, p, e, pos + 16, 6)
|
||||
pos += 22
|
||||
writef32(dst, o, v / 32768)
|
||||
o += 4
|
||||
end
|
||||
done += 1
|
||||
local m = math.min(4095, frames - done)
|
||||
for _ = 1, m do
|
||||
for c = 1, ch do
|
||||
local code = msb(src, p, e, pos, bits)
|
||||
pos += bits
|
||||
local step = IMA_STEP[math.clamp(index[c], 0, 88) + 1]
|
||||
local diff = 0
|
||||
local k = k0
|
||||
while k > 0 do
|
||||
if band(code, k) ~= 0 then
|
||||
diff += step
|
||||
end
|
||||
step = rshift(step, 1)
|
||||
k = rshift(k, 1)
|
||||
end
|
||||
diff += step
|
||||
local v = pred[c]
|
||||
if band(code, sign) ~= 0 then
|
||||
v -= diff
|
||||
else
|
||||
v += diff
|
||||
end
|
||||
v = math.clamp(v, -32768, 32767)
|
||||
pred[c] = v
|
||||
index[c] = math.clamp(index[c] + tab[band(code, mask) + 1], 0, 88)
|
||||
writef32(dst, o, v / 32768)
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
done += m
|
||||
end
|
||||
return frames
|
||||
end
|
||||
|
||||
return Adpcm
|
||||
@@ -4,6 +4,7 @@
|
||||
-- format). New in formats-luau.
|
||||
-- PCM (pcm_u8 / s16 / s24 / s32 le and be, f32 / f64, alaw, mulaw) -> WAV (big-endian samples byte-swapped);
|
||||
-- an AVI audio track with its WAVEFORMATEX (track.waveFormat: IMA / MS ADPCM, ...) -> WAV with that fmt chunk;
|
||||
-- adpcm_swf (Flash ADPCM, FLV SoundFormat 1) -> decoded through codecs/audio/Adpcm into a float WAV;
|
||||
-- mp3 / mp2 / mp1 -> the frames back to back (format "mp3");
|
||||
-- flac -> "fLaC" + the metadata blocks (CodecPrivate / dfLa) + the frames;
|
||||
-- opus -> Ogg Opus (OpusHead from the config or made up, OpusTags, packets with granules from their TOC durations);
|
||||
@@ -16,6 +17,7 @@ local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Types = require("@formats/Types")
|
||||
local Mux = require("@formats/containers/Ogg/Mux")
|
||||
local Adpcm = require("@formats/codecs/audio/Adpcm")
|
||||
|
||||
local AudioWrap = {}
|
||||
|
||||
@@ -131,6 +133,32 @@ local function pcmWav(track: Types.Track, packets: { Types.Packet }): (buffer?,
|
||||
return wav(f:finish(), data), nil
|
||||
end
|
||||
|
||||
-- Flash ADPCM packets decode on their own (each starts with its code size and block headers): f32 samples in a WAV
|
||||
local function swfWav(track: Types.Track, packets: { Types.Packet }): (buffer?, Err.Err?)
|
||||
local ch = track.channels or 1
|
||||
local rate = math.floor((track.sampleRate or 0) + 0.5)
|
||||
if ch < 1 or ch > 2 or rate <= 0 then
|
||||
return nil, Err.new(Err.CORRUPT, "Flash ADPCM track without channels / sample rate")
|
||||
end
|
||||
local frames = 0
|
||||
for _, pk in packets do
|
||||
frames += Adpcm.swfFrames(pk.data, 0, buffer.len(pk.data), ch)
|
||||
end
|
||||
local data = buffer.create(frames * ch * 4)
|
||||
local d = 0
|
||||
for _, pk in packets do
|
||||
d += Adpcm.swf(pk.data, 0, buffer.len(pk.data), ch, data, d) * ch
|
||||
end
|
||||
local f = Bytes.writer(16)
|
||||
f:u16le(3)
|
||||
f:u16le(ch)
|
||||
f:u32le(rate)
|
||||
f:u32le(rate * ch * 4)
|
||||
f:u16le(ch * 4)
|
||||
f:u16le(32)
|
||||
return wav(f:finish(), data), nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ Ogg
|
||||
-- the number of 48 kHz samples in an Opus packet (RFC 6716 section 3.1)
|
||||
local function opusSamples(b: buffer): number
|
||||
@@ -401,6 +429,10 @@ function AudioWrap.wrap(dmx: any, track: Types.Track): (buffer?, string?, Err.Er
|
||||
if track.waveFormat and string.sub(codec, 1, 6) == "adpcm_" then
|
||||
return wav(track.waveFormat, concat(packets)), "wav", nil
|
||||
end
|
||||
if codec == "adpcm_swf" then
|
||||
local b, err = swfWav(track, packets)
|
||||
return b, if b then "wav" else nil, err
|
||||
end
|
||||
if PCM[codec] then
|
||||
local b, err = pcmWav(track, packets)
|
||||
return b, if b then "wav" else nil, err
|
||||
|
||||
@@ -44,7 +44,6 @@ export type DecodeOptions = {
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local ENCODINGS = { ["txt "] = "text", ["bin "] = "binary", tzip = "text", bzip = "binary" }
|
||||
local WINDOW = 32768
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function X.sniff(r: Bytes.Reader): number
|
||||
@@ -55,9 +54,9 @@ function X.sniff(r: Bytes.Reader): number
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
-- MSZIP: a u32 total size (with the header), then blocks (u16 uncompressed size, u16 compressed size, "CK", deflate data); each block
|
||||
-- may refer back into the previous block's output. That history is handed to the inflater as a stored block in
|
||||
-- front of the compressed one (both start on a byte boundary), and cut off the output again.
|
||||
-- MSZIP: a u32 total size (with the 16-byte file header), then blocks (u16 uncompressed size, u16 compressed size,
|
||||
-- "CK" + deflate data). The blocks are walked here; codecs/compress/Deflate.mszip inflates the chain (each block may
|
||||
-- refer back into the previous block's output).
|
||||
local function mszip(b: buffer, p: number, limit: number, maxBytes: number): (buffer?, Err.Err?)
|
||||
if p + 4 > limit then
|
||||
return nil, Err.new(Err.TRUNCATED, "no MSZIP header", p)
|
||||
@@ -67,36 +66,27 @@ local function mszip(b: buffer, p: number, limit: number, maxBytes: number): (bu
|
||||
return nil, Err.new(Err.LIMIT, "inflates to " .. total .. " bytes", p)
|
||||
end
|
||||
p += 4
|
||||
local out = buffer.create(total)
|
||||
local spans: { { offset: number, length: number, size: number } } = {}
|
||||
local o = 0
|
||||
while p + 6 <= limit and o < total do
|
||||
local usize, csize = buffer.readu16(b, p), buffer.readu16(b, p + 2)
|
||||
if buffer.readstring(b, p + 4, 2) ~= "CK" or csize < 2 then
|
||||
return nil, Err.new(Err.CORRUPT, "bad MSZIP block", p)
|
||||
end
|
||||
local data, dlen = p + 6, math.min(csize - 2, limit - p - 6)
|
||||
local hist = math.min(o, WINDOW)
|
||||
local src = buffer.create(5 + hist + dlen)
|
||||
buffer.writeu8(src, 0, 0) -- BFINAL 0, stored
|
||||
buffer.writeu16(src, 1, hist)
|
||||
buffer.writeu16(src, 3, bit32.bxor(hist, 0xFFFF))
|
||||
buffer.copy(src, 5, out, o - hist, hist)
|
||||
buffer.copy(src, 5 + hist, b, data, dlen)
|
||||
local inflated, err = Deflate.inflate(src)
|
||||
if not inflated then
|
||||
return nil, Err.new(err.code, "MSZIP block: " .. err.message, p)
|
||||
end
|
||||
local got = buffer.len(inflated) - hist
|
||||
if got ~= usize or o + got > total then
|
||||
if o + usize > total then
|
||||
return nil, Err.new(Err.CORRUPT, "MSZIP block size mismatch", p)
|
||||
end
|
||||
buffer.copy(out, o, inflated, hist, got)
|
||||
o += got
|
||||
p = data + csize - 2
|
||||
table.insert(spans, { offset = p + 4, length = math.min(csize, limit - p - 4), size = usize })
|
||||
o += usize
|
||||
p += 4 + csize
|
||||
end
|
||||
if o < total then
|
||||
return nil, Err.new(Err.TRUNCATED, "MSZIP data ends early", p)
|
||||
end
|
||||
local out, err = Deflate.mszip(b, spans)
|
||||
if not out then
|
||||
return nil, Err.new((err :: Err.Err).code, "MSZIP: " .. (err :: Err.Err).message, (err :: Err.Err).offset)
|
||||
end
|
||||
return out, nil
|
||||
end
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
-- and H.264 decode; VP6 / VP6 alpha, screen video 1 / 2 and enhanced FourCC codecs (HEVC, AV1, VP9) are known tracks
|
||||
-- whose decoding is UNSUPPORTED); H.264's AVCDecoderConfigurationRecord in track.config, composition time offsets
|
||||
-- in the pts. Audio through the api's opts.openAudio hook: MP3 (also 8 kHz), AAC (AudioSpecificConfig in track.config),
|
||||
-- linear PCM (platform-endian read as little-endian), A-law / mu-law; Flash ADPCM, Nellymoser and Speex are known
|
||||
-- tracks without an audio decoder (UNSUPPORTED). Flv.demux(r) gives the Demuxer.
|
||||
-- linear PCM (platform-endian read as little-endian), A-law / mu-law, Flash ADPCM (codecs/audio/Adpcm.swf, through
|
||||
-- containers/AudioWrap); Nellymoser and Speex are known tracks without an audio decoder (UNSUPPORTED). Flv.demux(r) gives the Demuxer.
|
||||
-- Write: H.264 / Sorenson Spark / VP6 / screen video copied from the source (FLV has no codec we encode), AAC / MP3 /
|
||||
-- PCM / A-law / mu-law / ADPCM / Nellymoser / Speex audio copied (AAC from ADTS sources re-framed), else PCM s16 at
|
||||
-- the FLV sample rates (5512 / 11025 / 22050 / 44100 Hz), with onMetaData (duration, sizes, frame rate, data
|
||||
|
||||
+24
-1
@@ -2,7 +2,8 @@
|
||||
-- (tools/fixtures/adpcm.py: ADX from ffmpeg and PS-ADPCM / DSP from our Python encoders decoded by vgmstream, Apple
|
||||
-- ima4 from ffmpeg, IMA nibble streams decoded by ffmpeg); ADX coefficients; the encoders (IMA nibbles, IMA WAV
|
||||
-- blocks, MS blocks) decoded back with a signal-to-noise floor; the Decoder layouts (seeking matches a straight
|
||||
-- read); a fuzz pass of random bytes through every kernel (ranges valid, contents random) and the layouts.
|
||||
-- read); Flash ADPCM by hand; a fuzz pass of random bytes through every kernel (ranges valid, contents random) and
|
||||
-- the layouts.
|
||||
local T = require("@tests/T")
|
||||
local Adpcm = require("@formats/codecs/audio/Adpcm")
|
||||
local Decoder = require("@formats/codecs/audio/Adpcm/Decoder")
|
||||
@@ -88,6 +89,25 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- Flash ADPCM (bit-exact with ffmpeg's adpcm_swf in tests/video/flv.luau): a hand-made 2-bit packet of 4 bytes:
|
||||
-- code size 0 (2-bit codes), first sample 100, step index 0, then the codes 01 11 00 00
|
||||
do
|
||||
local bits = "00" .. "0000000001100100" .. "000000" .. "01110000"
|
||||
local src = buffer.create(4)
|
||||
for i = 0, 3 do
|
||||
buffer.writeu8(src, i, tonumber(string.sub(bits, i * 8 + 1, i * 8 + 8), 2) :: number)
|
||||
end
|
||||
t:eq(Adpcm.swfFrames(src, 0, 4, 1), 5, "swf: frames in a 4-byte packet")
|
||||
local out = buffer.create(20)
|
||||
t:eq(Adpcm.swf(src, 0, 4, 1, out, 0), 5, "swf: frames decoded")
|
||||
-- 01: +7 + 7/2 = 110 (index 0 + 2: step 9); 11: -(9 + 4) = 97 (index 4: step 11); 00: +5 = 102 (index 3: step
|
||||
-- 10); 00: +5 = 107
|
||||
local want = { 100, 110, 97, 102, 107 }
|
||||
for i, v in want do
|
||||
t:eq(buffer.readf32(out, (i - 1) * 4) * 32768, v, "swf sample " .. i)
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encoders
|
||||
local function snr(x: buffer, y: buffer, count: number): number
|
||||
local sig, err = 0, 0
|
||||
@@ -235,6 +255,9 @@ t:fuzz("kernels", function(b: buffer)
|
||||
if n >= 17 then
|
||||
Adpcm.modplug(b, 0, math.min((n - 16) * 2, 1000), out, 0)
|
||||
end
|
||||
if n >= 1 then
|
||||
Adpcm.swf(b, 0, math.min(n, 600), 1 + n % 2, buffer.create(Adpcm.swfFrames(b, 0, math.min(n, 600), 1 + n % 2) * 8 + 8), 0)
|
||||
end
|
||||
Adpcm.imaWav(b, 0, n, 2, 1017, buffer.create(1017 * 2 * 4), 0)
|
||||
Adpcm.msBlock(b, 0, n, 2, 1012, buffer.create(1012 * 2 * 4), 0, coefs, 8, buffer.create(40))
|
||||
local dec = Decoder.interleaved({ sampleRate = 8000, channels = 2, tags = {} }, { kind = "adx", buf = b, offset = 0, size = n, interleave = 18, c1 = 7334, c2 = -3283 })
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
-- video/flv tests: FLV files from ffmpeg (Sorenson Spark + MP3 / PCM s16 / PCM u8 / ADPCM / Nellymoser / Speex /
|
||||
-- A-law, H.264 with B-frames + AAC, Flash screen video, audio only): tracks and every packet against ffprobe
|
||||
-- (composition times in the pts, keyframes), onMetaData, frames against ffmpeg (Sorenson bit-exact, H.264 PSNR), audio
|
||||
-- through the api hook (PCM exact; ADPCM / Nellymoser / Speex known but UNSUPPORTED), seeking; crafted VP6 /
|
||||
-- enhanced FourCC / encrypted / truncated files; our writer (FLV, MP4, Matroska sources) read back by ffprobe and
|
||||
-- ffmpeg (tools/fixtures/flv.py) and by our demuxer with the source's packets; fuzz. Fixtures: tools/fixtures/flv.py.
|
||||
-- through the api hook (PCM and Flash ADPCM mono / stereo exact against ffmpeg's adpcm_swf; Nellymoser / Speex known
|
||||
-- but UNSUPPORTED), seeking; crafted VP6 / enhanced FourCC / encrypted / truncated files; our writer (FLV, MP4,
|
||||
-- Matroska sources) read back by ffprobe and ffmpeg (tools/fixtures/flv.py) and by our demuxer with the source's
|
||||
-- packets; fuzz. Fixtures: tools/fixtures/flv.py.
|
||||
local T = require("@tests/T")
|
||||
local C = require("@tests/video/_common")
|
||||
local F = require("@formats")
|
||||
@@ -19,8 +20,8 @@ local t = T.suite("flv")
|
||||
t:eq(Flv.name, "flv", "name")
|
||||
t:eq(Flv.category, "video", "category")
|
||||
|
||||
local EXACT_AUDIO = { pcm_s16le = true, pcm_u8 = true, pcm_alaw = true }
|
||||
local NO_AUDIO_FORMAT = { adpcm_swf = true, nellymoser = true, speex = true }
|
||||
local EXACT_AUDIO = { pcm_s16le = true, pcm_u8 = true, pcm_alaw = true, adpcm_swf = true }
|
||||
local NO_AUDIO_FORMAT = { nellymoser = true, speex = true }
|
||||
local byName = {}
|
||||
for _, c in Fx do
|
||||
byName[c.name] = c
|
||||
|
||||
+13
-1
@@ -1748,7 +1748,7 @@ do
|
||||
end
|
||||
-- ws-audio2: adpcm / qoa
|
||||
do
|
||||
-- codecs/audio/Adpcm (IMA nibble stream, Nintendo DSP frames) and QOA decode / encode, over generated signals; MB/s
|
||||
-- codecs/audio/Adpcm (IMA nibble stream, Nintendo DSP frames, Flash ADPCM) and QOA decode / encode, over generated signals; MB/s
|
||||
-- of f32 output (MB/s of input for the encoder)
|
||||
local Adpcm = require("@formats/codecs/audio/Adpcm")
|
||||
local QoaCodec = require("@formats/codecs/audio/Qoa")
|
||||
@@ -1784,6 +1784,18 @@ do
|
||||
bench("adpcm dsp decode", 5, frames * 14 * 4, function()
|
||||
Adpcm.dsp(dsp, 0, frames * 14, coefs, 0, buffer.create(8), 0, out, 0, 1)
|
||||
end)
|
||||
-- Flash ADPCM: one mono packet of random 4-bit codes (the bit stream reader per code)
|
||||
local swf = buffer.create(n // 2)
|
||||
for i = 0, n // 2 - 1 do
|
||||
seed = (seed * 1103515245 + 12345) % 2147483648
|
||||
buffer.writeu8(swf, i, seed // 65536 % 256)
|
||||
end
|
||||
buffer.writeu8(swf, 0, 0x80 + buffer.readu8(swf, 0) % 64) -- code size 2 + 2 = 4 bits
|
||||
local swfFrames = Adpcm.swfFrames(swf, 0, n // 2, 1)
|
||||
local swfOut = buffer.create(swfFrames * 4)
|
||||
bench("adpcm swf decode", 5, swfFrames * 4, function()
|
||||
Adpcm.swf(swf, 0, n // 2, 1, swfOut, 0)
|
||||
end)
|
||||
-- QOA (stereo 44.1 kHz)
|
||||
local file = assert(Qoa.encode(sig))
|
||||
bench("qoa encode", 2, n * 2 * 4, function()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# FLV fixtures (tools/fixtures.py): files made by ffmpeg (Sorenson Spark + MP3 / PCM s16 / PCM u8 / Flash ADPCM /
|
||||
# FLV fixtures (tools/fixtures.py): files made by ffmpeg (Sorenson Spark + MP3 / PCM s16 / PCM u8 / Flash ADPCM mono + stereo /
|
||||
# Nellymoser / Speex / A-law, H.264 with B-frames + AAC, Flash screen video), with ffprobe's streams and packets,
|
||||
# ffmpeg's frames (CRC-32 of `-flags +bitexact -idct int` decoding; the first two raw) and audio (f32); then our FLV
|
||||
# writer (tools/fixtures/_flv_encode.luau) remuxes FLV, MP4, Matroska and MPEG-TS sources and each output is probed,
|
||||
@@ -49,13 +49,14 @@ def generate(ctx):
|
||||
ff(*SRC, *aud(22050, 2), "-t", "1", "-c:v", "flv", "-g", "12", "-c:a", "pcm_s16le", "sorenson_pcm.flv")
|
||||
ff(*SRC, *aud(11025), "-t", "1", "-c:v", "flv", "-g", "12", "-c:a", "pcm_u8", "sorenson_pcm8.flv")
|
||||
ff(*SRC, *aud(22050), "-t", "0.5", "-c:v", "flv", "-c:a", "adpcm_swf", "sorenson_adpcm.flv")
|
||||
ff(*SRC, *aud(44100, 2), "-t", "0.5", "-c:v", "flv", "-c:a", "adpcm_swf", "sorenson_adpcm2.flv")
|
||||
ff(*SRC, *aud(22050), "-t", "0.5", "-c:v", "flv", "-c:a", "nellymoser", "sorenson_nelly.flv")
|
||||
ff(*SRC, *aud(16000), "-t", "0.5", "-c:v", "flv", "-c:a", "libspeex", "sorenson_speex.flv")
|
||||
ff(*SRC, *aud(8000), "-t", "0.5", "-c:v", "flv", "-c:a", "pcm_alaw", "sorenson_alaw.flv")
|
||||
ff("-f", "lavfi", "-i", "testsrc2=size=64x48:rate=10", "-t", "0.5", "-c:v", "flashsv", "screen.flv")
|
||||
ff(*aud(44100, 2), "-t", "0.5", "-c:a", "libmp3lame", "audio_only.flv")
|
||||
names = ["sorenson_mp3.flv", "h264_aac.flv", "sorenson_pcm.flv", "sorenson_pcm8.flv", "sorenson_adpcm.flv",
|
||||
"sorenson_nelly.flv", "sorenson_speex.flv", "sorenson_alaw.flv", "screen.flv", "audio_only.flv"]
|
||||
"sorenson_adpcm2.flv", "sorenson_nelly.flv", "sorenson_speex.flv", "sorenson_alaw.flv", "screen.flv", "audio_only.flv"]
|
||||
cases = [case(tmp, n) for n in names]
|
||||
ctx.emit("flv_cases", cases)
|
||||
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
# TYPES: the other type diagnostics are counted (unique lines: the analyzer reports a required module once per
|
||||
# path spelling) and printed with LINT_TYPES=1. The count may not rise above tools/lint_types_baseline.txt; when
|
||||
# it drops, lower the baseline (LINT_TYPES_UPDATE=1 writes the current count), so it only goes down.
|
||||
# 2. HEADER, REQUIRE, NATIVE (native code never throws: it crashes Roblox Studio), LAYERS, DEPS, CONTRACT:
|
||||
# 2. HEADER, REQUIRE, NATIVE (native code never throws: it crashes Roblox Studio), LAYERS, DEPS, CONTRACT, DUP, DOCS:
|
||||
# tools/lint_rules.py (its header lists the rules; docs/STYLE.md explains them).
|
||||
# 3. The generated registry / docs/FORMATS.md are up to date (tools/gen_registry.py --check), and tools/build.py's
|
||||
# token passes pass their self-test.
|
||||
@@ -39,6 +39,6 @@ python3 -I tools/lint_rules.py || { echo "lint: structure rules failed (see tool
|
||||
python3 -I tools/gen_registry.py --check > /dev/null || { python3 -I tools/gen_registry.py --check; fail=1; }
|
||||
python3 -I tools/build.py --test > /dev/null || { echo "lint: tools/build.py --test failed"; fail=1; }
|
||||
if [ $fail -eq 0 ]; then
|
||||
echo "lint passed (globals, header, require, native, layers, deps, contract, registry; $ntype type diagnostics, baseline $baseline: LINT_TYPES=1 shows them)"
|
||||
echo "lint passed (globals, header, require, native, layers, deps, contract, dup, docs, registry; $ntype type diagnostics, baseline $baseline: LINT_TYPES=1 shows them)"
|
||||
fi
|
||||
exit $fail
|
||||
@@ -20,6 +20,9 @@
|
||||
# DUP no copy-pasted code: a function body of DUP_LINES (12) or more code lines whose tokens (comments and
|
||||
# whitespace dropped, identifiers kept) equal another module's function body fails; move it down to a
|
||||
# shared module (core / codecs / containers) and call it from both.
|
||||
# DOCS the module lists in README.md's Layout block and docs/STYLE.md's layer block name every codec
|
||||
# (codecs/<domain>/<Name>), container and core module in the tree; README.md's format counts
|
||||
# ("images (25)", ...) match the registry (docs/FORMATS.md); docs/guide/README.md links every guide page.
|
||||
import os, re, sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -314,5 +317,69 @@ for key, where in bodies.items():
|
||||
if f != first[0]:
|
||||
bad(f, ln, "DUP: `%s` repeats %s:%d (move it to a shared module)" % (head[:60], os.path.relpath(first[0], ROOT), first[1]))
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------- DOCS
|
||||
def module_names(rel):
|
||||
"""the module names directly under src/Formats/<rel>: Foo.luau and Foo/ (a folder module)"""
|
||||
d = os.path.join(SRC, rel)
|
||||
names = set()
|
||||
for n in os.listdir(d):
|
||||
if n.endswith(".luau"):
|
||||
names.add(n[:-5])
|
||||
elif os.path.isdir(os.path.join(d, n)):
|
||||
names.add(n)
|
||||
return names
|
||||
|
||||
|
||||
def layout_block(path):
|
||||
"""(first line, text) of the first fenced block of a markdown file that starts with src/Formats/"""
|
||||
lines = open(path, encoding="utf-8").read().split("\n")
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith("```") and i + 1 < len(lines) and lines[i + 1].startswith("src/Formats/"):
|
||||
j = i + 1
|
||||
while j < len(lines) and not lines[j].startswith("```"):
|
||||
j += 1
|
||||
return i + 1, "\n".join(lines[i + 1:j])
|
||||
return 1, ""
|
||||
|
||||
|
||||
modules = []
|
||||
for dom in sorted(os.listdir(os.path.join(SRC, "codecs"))):
|
||||
modules += ["codecs/%s/%s" % (dom, n) for n in sorted(module_names("codecs/" + dom))]
|
||||
modules += ["containers/" + n for n in sorted(module_names("containers"))]
|
||||
modules += ["core/" + n for n in sorted(module_names("core"))]
|
||||
for doc in ("README.md", os.path.join("docs", "STYLE.md")):
|
||||
path = os.path.join(ROOT, doc)
|
||||
ln, block = layout_block(path)
|
||||
if not block:
|
||||
bad(path, 1, "DOCS: no layout block (a ``` block starting with src/Formats/)")
|
||||
continue
|
||||
for m in modules:
|
||||
if not re.search(r"(?<![\w/])" + re.escape(m.rsplit("/", 1)[1]) + r"\b", block):
|
||||
bad(path, ln, "DOCS: the layout block does not list %s" % m)
|
||||
|
||||
LABELS = {"image": "images", "audio": "audio", "video": "video", "model": "3D models", "cad": "CAD", "font": "fonts",
|
||||
"archive": "archives", "data": "data", "vector": "vector graphics and tile maps", "layered": "layered images",
|
||||
"subtitle": "subtitles", "music": "music", "playlist": "playlists"}
|
||||
counts = {}
|
||||
for line in open(os.path.join(ROOT, "docs", "FORMATS.md"), encoding="utf-8"):
|
||||
cells = [c.strip() for c in line.split("|")]
|
||||
if len(cells) > 3 and cells[1] in LABELS:
|
||||
counts[cells[1]] = counts.get(cells[1], 0) + 1
|
||||
readme = os.path.join(ROOT, "README.md")
|
||||
rtext = open(readme, encoding="utf-8").read()
|
||||
m = re.search(r"(\d+) formats:", rtext)
|
||||
if not m or int(m.group(1)) != sum(counts.values()):
|
||||
bad(readme, 1, "DOCS: README.md should say \"%d formats:\" (docs/FORMATS.md)" % sum(counts.values()))
|
||||
for cat, label in LABELS.items():
|
||||
m = re.search(r"\s+".join(map(re.escape, label.split())) + r"\s+\((\d+)\)", rtext)
|
||||
if not m or int(m.group(1)) != counts.get(cat, 0):
|
||||
bad(readme, 1, "DOCS: README.md should say \"%s (%d)\" (docs/FORMATS.md)" % (label, counts.get(cat, 0)))
|
||||
|
||||
guide = os.path.join(ROOT, "docs", "guide")
|
||||
gindex = open(os.path.join(guide, "README.md"), encoding="utf-8").read()
|
||||
for n in sorted(os.listdir(guide)):
|
||||
if n.endswith(".md") and n != "README.md" and "](%s" % n not in gindex:
|
||||
bad(os.path.join(guide, "README.md"), 1, "DOCS: the guide index does not link %s" % n)
|
||||
|
||||
print("\n".join(out))
|
||||
sys.exit(1 if out else 0)
|
||||
Reference in new issue
Block a user