root: Video, AudioWrap, Rbx, ImageOps required on first use (F.Rbx, F.video.codecs through __index); chunked build: one chunk per unit (format folder, codec, container), small family neighbours packed to 32 KB; Sniffs copies typed as in their module

This commit is contained in:
4DBug committed 2026-11-03 01:24:44 -06:00
1 parent 3468bfb49a
commit 5b2605f514
10 files changed
+7577 -5774

No files matched your search

+50 -21
View File
@@ -19,7 +19,7 @@ end
local P_audio_mp3_Tags: any = {}
do -- audio/mp3/Tags: id3v2Size
local Tags = P_audio_mp3_Tags
local Tags = {}
local band, bor, lshift = bit32.band, bit32.bor, bit32.lshift
local ru8 = buffer.readu8
local function syncsafe(b: buffer, o: number): number
@@ -43,11 +43,12 @@ function Tags.id3v2Size(b: buffer, o: number, len: number): number
end
return size
end
P_audio_mp3_Tags.id3v2Size = Tags.id3v2Size
end
local P_codecs_audio_Aac: any = {}
do -- codecs/audio/Aac: adts
local Aac = P_codecs_audio_Aac
local Aac = {}
local Bits = require("@rosetta/core/Bits")
Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 }
local function objectType(br: Bits.BitReader): number
@@ -96,11 +97,12 @@ function Aac.adts(b: buffer, o: number, limit: number): Adts?
protected = protected,
}
end
P_codecs_audio_Aac.adts = Aac.adts
end
local P_codecs_audio_Ac3_Tables: any = {}
do -- codecs/audio/Ac3/Tables: BITRATES, RATES, frameWords
local T = P_codecs_audio_Ac3_Tables
local T = {}
T.BITRATES = { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 512, 576, 640 }
T.RATES = { 48000, 44100, 32000 }
function T.frameWords(fscod: number, frmsizecod: number): number
@@ -115,11 +117,14 @@ function T.frameWords(fscod: number, frmsizecod: number): number
end
return kbps * 1536000 // 705600 + frmsizecod % 2
end
P_codecs_audio_Ac3_Tables.BITRATES = T.BITRATES
P_codecs_audio_Ac3_Tables.RATES = T.RATES
P_codecs_audio_Ac3_Tables.frameWords = T.frameWords
end
local P_codecs_audio_Ac3: any = {}
do -- codecs/audio/Ac3: header
local Ac3 = P_codecs_audio_Ac3
local Ac3 = {}
local T = P_codecs_audio_Ac3_Tables
local readu8 = buffer.readu8
local NFCHANS = { [0] = 2, 1, 2, 3, 3, 4, 4, 5 }
@@ -188,22 +193,24 @@ function Ac3.header(b: buffer, o: number, limit: number): Header?
bsid = bsid,
}
end
P_codecs_audio_Ac3.header = Ac3.header
end
local P_codecs_audio_Mpa_Tables: any = {}
do -- codecs/audio/Mpa/Tables: halfrate
local T = P_codecs_audio_Mpa_Tables
local T = {}
T.halfrate = { [0] = 0,
4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 56, 64, 72, 80, 0, 4, 8, 12, 16, 20, 24, 28, 32, 40,
48, 56, 64, 72, 80, 0, 16, 24, 28, 32, 40, 48, 56, 64, 72, 80, 88, 96, 112, 128, 0, 16, 20, 24,
28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 0, 16, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128,
160, 192, 0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224,
}
P_codecs_audio_Mpa_Tables.halfrate = T.halfrate
end
local P_codecs_audio_Mpa_Header: any = {}
do -- codecs/audio/Mpa/Header: compare, frameBytes, padding, valid
local H = P_codecs_audio_Mpa_Header
local H = {}
local T = P_codecs_audio_Mpa_Tables
local band, bxor, rshift = bit32.band, bit32.bxor, bit32.rshift
local ru8 = buffer.readu8
@@ -271,11 +278,15 @@ function H.padding(b: buffer, o: number): number
end
return if band(ru8(b, o + 1), 6) == 6 then 4 else 1
end
P_codecs_audio_Mpa_Header.compare = H.compare
P_codecs_audio_Mpa_Header.frameBytes = H.frameBytes
P_codecs_audio_Mpa_Header.padding = H.padding
P_codecs_audio_Mpa_Header.valid = H.valid
end
local P_codecs_audio_Musepack: any = {}
do -- codecs/audio/Musepack: magic
local Musepack = P_codecs_audio_Musepack
local Musepack = {}
function Musepack.magic(buf: buffer, p: number, limit: number): number
if p + 4 > limit then
return 0
@@ -289,15 +300,17 @@ function Musepack.magic(buf: buffer, p: number, limit: number): number
end
return 0
end
P_codecs_audio_Musepack.magic = Musepack.magic
end
local P_codecs_audio_SoundFont: any = {}
do -- codecs/audio/SoundFont: sniff
local SoundFont = P_codecs_audio_SoundFont
local SoundFont = {}
local Bytes = require("@rosetta/core/Bytes")
function SoundFont.sniff(r: Bytes.Reader): boolean
return r:peek(4) == "RIFF" and r:peek(4, 8) == "sfbk"
end
P_codecs_audio_SoundFont.sniff = SoundFont.sniff
end
local P_codecs_compress_Brotli = lazy(function()
@@ -310,7 +323,7 @@ end)
local P_codecs_compress_Deflate: any = {}
do -- codecs/compress/Deflate: peek
local Deflate = P_codecs_compress_Deflate
local Deflate = {}
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Inflate = P_codecs_compress_Deflate_Inflate
@@ -383,6 +396,7 @@ function Deflate.peek(buf: buffer | string, offset: number?, length: number?, n:
end
return shrink(out, k), nil
end
P_codecs_compress_Deflate.peek = Deflate.peek
end
local P_codecs_compress_Zstd_Decode = lazy(function()
@@ -391,7 +405,7 @@ end)
local P_codecs_compress_Zstd: any = {}
do -- codecs/compress/Zstd: MAGIC, decompress
local Zstd = P_codecs_compress_Zstd
local Zstd = {}
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Decode = P_codecs_compress_Zstd_Decode
@@ -421,11 +435,13 @@ function Zstd.decompress(buf: buffer | string, offset: number?, length: number?,
end
return out, consumed
end
P_codecs_compress_Zstd.MAGIC = Zstd.MAGIC
P_codecs_compress_Zstd.decompress = Zstd.decompress
end
local P_codecs_text_KeyValues_Binary: any = {}
do -- codecs/text/KeyValues/Binary: sniff
local Binary = P_codecs_text_KeyValues_Binary
local Binary = {}
local readu8, readu32, readi32, readf32 = buffer.readu8, buffer.readu32, buffer.readi32, buffer.readf32
function Binary.sniff(b: buffer, o: number, n: number): boolean
if n < 3 then
@@ -445,18 +461,20 @@ function Binary.sniff(b: buffer, o: number, n: number): boolean
end
return false
end
P_codecs_text_KeyValues_Binary.sniff = Binary.sniff
end
local P_codecs_text_KeyValues: any = {}
do -- codecs/text/KeyValues: isBinary
local KeyValues = P_codecs_text_KeyValues
local KeyValues = {}
local Binary = P_codecs_text_KeyValues_Binary
KeyValues.isBinary = Binary.sniff
P_codecs_text_KeyValues.isBinary = KeyValues.isBinary
end
local P_codecs_text_Nbt_Value: any = {}
do -- codecs/text/Nbt/Value: NAMES
local Value = P_codecs_text_Nbt_Value
local Value = {}
Value.NAMES = {
[0] = "end",
"byte",
@@ -476,11 +494,12 @@ Value.IDS = {} :: { [string]: number }
for id = 0, 12 do
Value.IDS[Value.NAMES[id]] = id
end
P_codecs_text_Nbt_Value.NAMES = Value.NAMES
end
local P_codecs_text_Nbt: any = {}
do -- codecs/text/Nbt: peek
local Nbt = P_codecs_text_Nbt
local Nbt = {}
local Deflate = P_codecs_compress_Deflate
local Value = P_codecs_text_Nbt_Value
type Peek = {
@@ -568,11 +587,12 @@ function Nbt.peek(buf: buffer, offset: number?, length: number?): Peek?
end
return at(0, "big", false) or at(0, "little", false)
end
P_codecs_text_Nbt.peek = Nbt.peek
end
local P_codecs_text_Text: any = {}
do -- codecs/text/Text: toUtf8, trim, utf16
local Text = P_codecs_text_Text
local Text = {}
function Text.utf8char(c: number): string
local char = string.char
if c < 0x80 then
@@ -640,11 +660,14 @@ function Text.toUtf8(text: string, warnings: { string }?): string
end
return table.concat(out)
end
P_codecs_text_Text.toUtf8 = Text.toUtf8
P_codecs_text_Text.trim = Text.trim
P_codecs_text_Text.utf16 = Text.utf16
end
local P_containers_Fat: any = {}
do -- containers/Fat: open
local Fat = P_containers_Fat
local Fat = {}
local readu8, readu16, readu32 = buffer.readu8, buffer.readu16, buffer.readu32
type Volume = {
b: buffer,
@@ -766,11 +789,12 @@ function Fat.open(b: buffer, off: number, len: number, opts: OpenOptions?): (Vol
end
return nil, if o.partition then "no partition " .. o.partition else "no FAT partition"
end
P_containers_Fat.open = Fat.open
end
local P_containers_IsoBmff: any = {}
do -- containers/IsoBmff: sniff
local IsoBmff = P_containers_IsoBmff
local IsoBmff = {}
local Bytes = require("@rosetta/core/Bytes")
local TOP: { [string]: boolean } = {
ftyp = true, moov = true, mdat = true, free = true, skip = true, wide = true, pnot = true, moof = true,
@@ -793,11 +817,12 @@ function IsoBmff.sniff(r: Bytes.Reader): string?
end
return nil
end
P_containers_IsoBmff.sniff = IsoBmff.sniff
end
local P_containers_Riff: any = {}
do -- containers/Riff: sniff
local Riff = P_containers_Riff
local Riff = {}
function Riff.sniff(r: any): string?
local magic = r:peek(4)
if magic ~= "RIFF" and magic ~= "RIFX" and magic ~= "RF64" and magic ~= "BW64" then
@@ -806,11 +831,12 @@ function Riff.sniff(r: any): string?
local form = r:peek(4, 8)
return if #form == 4 then form else nil
end
P_containers_Riff.sniff = Riff.sniff
end
local P_containers_Tar: any = {}
do -- containers/Tar: valid
local Tar = P_containers_Tar
local Tar = {}
local BLOCK = 512
local function zeros(b: buffer, o: number): boolean
for i = 0, BLOCK - 1, 4 do
@@ -853,19 +879,22 @@ function Tar.valid(b: buffer, o: number): boolean
local u, s = checksum(b, o)
return want == u or want == s
end
P_containers_Tar.valid = Tar.valid
end
local P_model_fbx_Binary: any = {}
do -- model/fbx/Binary: MAGIC
local Binary = P_model_fbx_Binary
local Binary = {}
local MAGIC = "Kaydara FBX Binary \0"
Binary.MAGIC = MAGIC
P_model_fbx_Binary.MAGIC = Binary.MAGIC
end
local P_model_ms3d_Read: any = {}
do -- model/ms3d/Read: MAGIC
local Read = P_model_ms3d_Read
local Read = {}
Read.MAGIC = "MS3D000000"
P_model_ms3d_Read.MAGIC = Read.MAGIC
end
do -- image/ani
@@ -888,13 +888,12 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb
end
local ws = w
if wl > 0 then
if dict == nil then
dict = S.dictionary()
if dict == nil then
return nil, NO_DICTIONARY
end
local d = dict or S.dictionary()
if d == nil then
return nil, NO_DICTIONARY
end
bcopy(WORD, w, dict, wo, wl)
dict = d
bcopy(WORD, w, d, wo, wl)
w += wl
end
if ttype == 10 then
+30 -14
View File
@@ -7,10 +7,6 @@ local Bytes = require("@rosetta/core/Bytes")
local Input = require("@rosetta/core/Input")
local Types = require("@rosetta/Types")
local Registry = require("@rosetta/Registry")
local Video = require("@rosetta/codecs/video/Video")
local AudioWrap = require("@rosetta/containers/AudioWrap")
local Rbx = require("@rosetta/codecs/model/Rbx")
local ImageOps = require("@rosetta/ops/ImageOps")
local host = require("@rosetta/host")
local F = {}
@@ -19,7 +15,6 @@ F.version = "0.1.0"
F.Err = Err
F.Types = Types
F.Bytes = Bytes
F.Rbx = Rbx
F.null = Types.null
F.host = host
F.plugins = {} :: { [string]: any } -- injected optional dependencies (plugins.brep for cad/step)
@@ -338,7 +333,7 @@ end
-- api hooks (a format never requires another format): opts.decodeImage / encodeImage, opts.plugins, opts.decodeModule,
-- opts.openAudio (containers/AudioWrap: PCM -> WAV, Opus / Vorbis -> Ogg, AAC -> ADTS, MP3 / FLAC / AC-3 as they are)
local function openAudio(demuxer: any, track: any, sbr: boolean?): (any, Err.Err?)
local buf, fmt, err = AudioWrap.wrap(demuxer, track)
local buf, fmt, err = require("@rosetta/containers/AudioWrap").wrap(demuxer, track)
if not buf then
return nil, err
end
@@ -350,7 +345,7 @@ local function openAudio(demuxer: any, track: any, sbr: boolean?): (any, Err.Err
local skip = if type(track.codecDelay) == "number" and track.codecDelay > 0 then math.floor(track.codecDelay * dec.sampleRate + 0.5) else 0
local length = if type(track.playDuration) == "number" and track.playDuration > 0 then math.floor(track.playDuration * dec.sampleRate + 0.5) else nil
if skip > 0 or length then
dec = AudioWrap.trim(dec, skip, length)
dec = require("@rosetta/containers/AudioWrap").trim(dec, skip, length)
end
end
return dec, oerr
@@ -530,7 +525,7 @@ local function videoToImage(v: any, o: Options): (any, Err.Err?)
if #images == 0 then
return nil, Err.new(Err.ARG, "save: the video has no frames")
end
local img, ierr = ImageOps.fromFrames(images, delays)
local img, ierr = require("@rosetta/ops/ImageOps").fromFrames(images, delays)
if not img then
return nil, ierr
end
@@ -816,7 +811,7 @@ F.video.fromImage = function(img: any, opts: Options?): (any, Err.Err?)
end
local frames, delays = { img }, { 0.1 }
if type(img.frames) == "table" and #img.frames > 0 then
local list, cerr = ImageOps.coalesce(img)
local list, cerr = require("@rosetta/ops/ImageOps").coalesce(img)
if not list then
return nil, cerr
end
@@ -826,19 +821,18 @@ F.video.fromImage = function(img: any, opts: Options?): (any, Err.Err?)
delays[i] = if type(f.delay) == "number" and f.delay > 0 then f.delay else 0.1
end
elseif img.format ~= "rgba8" and img.format ~= "yuv420p" then
local c, cerr = ImageOps.convert(img, "rgba8")
local c, cerr = require("@rosetta/ops/ImageOps").convert(img, "rgba8")
if not c then
return nil, cerr
end
frames = { c }
end
local src = type(img.meta) == "table" and img.meta.source
return Video.fromFrames(frames, delays, { format = type(src) == "table" and src.format or "image", loops = img.loops, meta = img.meta })
return require("@rosetta/codecs/video/Video").fromFrames(frames, delays, { format = type(src) == "table" and src.format or "image", loops = img.loops, meta = img.meta })
end
F.video.fromFrames = function(images: any, delays: any?, opts: Options?): (any, Err.Err?)
return Video.fromFrames(images, delays, opts)
return require("@rosetta/codecs/video/Video").fromFrames(images, delays, opts)
end
F.video.codecs = Video
F.model.loadTextures = function(scene: any, opts: Options?): (any, { [number]: Err.Err })
local errs: { [number]: Err.Err } = {}
@@ -867,7 +861,7 @@ end
local OPS: { [string]: () -> any } = {
image = function()
return ImageOps
return require("@rosetta/ops/ImageOps")
end,
mesh = function()
return require("@rosetta/ops/MeshOps")
@@ -912,4 +906,26 @@ F.ops = setmetatable({}, {
end,
}) :: any
-- F.Rbx (codecs/model/Rbx), F.video.codecs (codecs/video/Video): required on first use
setmetatable(F, {
__index = function(t: any, k: string): any
if k == "Rbx" then
local m = require("@rosetta/codecs/model/Rbx")
rawset(t, k, m)
return m
end
return nil
end,
})
setmetatable(F.video, {
__index = function(t: any, k: string): any
if k == "codecs" then
local m = require("@rosetta/codecs/video/Video")
rawset(t, k, m)
return m
end
return nil
end,
})
return F