diff --git a/build/Rosetta.luau b/build/Rosetta.luau index 1b09a19..cd56fba 100644 --- a/build/Rosetta.luau +++ b/build/Rosetta.luau @@ -35,10 +35,6 @@ local Bytes = __include("core/Bytes") local Input = __include("core/Input") local Types = __include("Types") local Registry = __include("Registry") -local Video = __include("codecs/video/Video") -local AudioWrap = __include("containers/AudioWrap") -local Rbx = __include("codecs/model/Rbx") -local ImageOps = __include("ops/ImageOps") local host = __include("host") local F = {} @@ -47,7 +43,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) @@ -366,7 +361,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 = __include("containers/AudioWrap").wrap(demuxer, track) if not buf then return nil, err end @@ -378,7 +373,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 = __include("containers/AudioWrap").trim(dec, skip, length) end end return dec, oerr @@ -558,7 +553,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 = __include("ops/ImageOps").fromFrames(images, delays) if not img then return nil, ierr end @@ -844,7 +839,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 = __include("ops/ImageOps").coalesce(img) if not list then return nil, cerr end @@ -854,19 +849,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 = __include("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 __include("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 __include("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 } = {} @@ -895,7 +889,7 @@ end local OPS: { [string]: () -> any } = { image = function() - return ImageOps + return __include("ops/ImageOps") end, mesh = function() return __include("ops/MeshOps") @@ -940,6 +934,28 @@ 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 = __include("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 = __include("codecs/video/Video") + rawset(t, k, m) + return m + end + return nil + end, +}) + return F end __FILES["Registry"] = function() @@ -1335,7 +1351,7 @@ local list: { Entry } = { mime = { "audio/aac", "audio/aacp", "audio/x-aac" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Aac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = false, codecs = { "aac" }, streaming = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/aac") end, @@ -1348,7 +1364,7 @@ local list: { Entry } = { mime = { "audio/ac3", "audio/x-ac3" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/Ac3" }, caps = { decode = true, encode = false, codecs = { "ac3" }, channels = 6, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/ac3") end, @@ -1466,7 +1482,7 @@ local list: { Entry } = { mime = { "audio/mp4", "audio/x-m4a", "audio/m4a" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "codecs/audio/Aac", "codecs/audio/Alac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = true, codecs = { "aac", "alac" }, encodeCodecs = { "alac" }, tags = true, streaming = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/m4a") end, @@ -1479,7 +1495,7 @@ local list: { Entry } = { mime = { "audio/mpeg", "audio/mp3", "audio/mpa" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Resample", "codecs/audio/Mpa/Header", "codecs/audio/Mpa/Core", "codecs/audio/Mpa/Encode3", "codecs/audio/Mpa/Encode2" }, caps = { decode = true, encode = true, streaming = true, seek = true, layers = { 1, 2, 3 }, encodeLayers = { 2, 3 }, channels = 2 }, - sniff = 1, + sniff = 0, load = function() return __include("audio/mp3") end, @@ -1492,7 +1508,7 @@ local list: { Entry } = { mime = { "audio/x-musepack", "audio/musepack" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/ApeTag", "codecs/audio/Musepack" }, caps = { decode = true, encode = false, codecs = { "musepack" }, versions = { 7, 8 }, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/mpc") end, @@ -1583,7 +1599,7 @@ local list: { Entry } = { mime = { "audio/wav", "audio/x-wav", "audio/wave", "audio/vnd.wave" }, deps = { "core/Err", "core/Bytes", "Types", "containers/Riff", "codecs/audio/Pcm", "codecs/audio/Adpcm" }, caps = { decode = true, encode = true, streaming = true, depths = { 8, 16, 24, 32 }, float = true, rf64 = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/wav") end, @@ -1675,7 +1691,7 @@ local list: { Entry } = { mime = { "video/mp4", "video/quicktime", "video/3gpp" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "containers/Demux", "codecs/video/Video", "codecs/video/Video/Source" }, caps = { decode = true, encode = true, streaming = true, remux = true, video = { "mjpeg", "mpeg1", "mpeg2", "h264" }, audio = true, fragments = true }, - sniff = 1, + sniff = 0, load = function() return __include("video/mp4") end, @@ -1779,7 +1795,7 @@ local list: { Entry } = { mime = { "model/x-ase", "text/plain" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, - sniff = 1, + sniff = 0, load = function() return __include("model/ase") end, @@ -1870,7 +1886,7 @@ local list: { Entry } = { mime = { "application/vnd.autodesk.fbx", "model/fbx" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/compress/Deflate", "core/Base64", "codecs/model/Mat4" }, caps = { decode = true, encode = true, binary = true, ascii = true, materials = true, animation = true, skins = true, morphTargets = true, cameras = true, lights = true, polygons = true }, - sniff = 2, + sniff = 0, load = function() return __include("model/fbx") end, @@ -2026,7 +2042,7 @@ local list: { Entry } = { mime = { "application/x-ms3d" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten" }, caps = { decode = true, encode = true, materials = true, skins = true, animation = true }, - sniff = 1, + sniff = 0, load = function() return __include("model/ms3d") end, @@ -2627,7 +2643,7 @@ local list: { Entry } = { mime = { "application/x-fat-image" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Fat" }, caps = { decode = true, encode = true, variants = { "fat12", "fat16", "fat32" } }, - sniff = 1, + sniff = 0, load = function() return __include("archive/fat") end, @@ -2757,7 +2773,7 @@ local list: { Entry } = { mime = { "application/x-tar" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Tar" }, caps = { decode = true, encode = true, variants = { "ustar", "pax", "gnu" } }, - sniff = 1, + sniff = 0, load = function() return __include("archive/tar") end, @@ -3082,7 +3098,7 @@ local list: { Entry } = { mime = { "text/x-vdf" }, deps = { "core/Err", "core/Bytes", "core/Sniff", "codecs/text/KeyValues" }, caps = { decode = true, encode = true, ordered = true, binary = true }, - sniff = 1, + sniff = 0, load = function() return __include("data/vdf") end, @@ -3446,7 +3462,7 @@ local list: { Entry } = { mime = { "audio/x-soundfont" }, deps = { "core/Err", "core/Bytes", "codecs/audio/SoundFont" }, caps = { decode = true, encode = false, sm24 = true, sf3 = false }, - sniff = 1, + sniff = 0, load = function() return __include("music/sf2") end, @@ -3537,7 +3553,7 @@ local list: { Entry } = { mime = { "audio/x-scpls", "audio/scpls" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Url", "codecs/text/Text", "core/Sniff" }, caps = { decode = true, encode = true }, - sniff = 1, + sniff = 0, load = function() return __include("playlist/pls") end, @@ -3579,6 +3595,878 @@ local function lazy(load: () -> any): any }) end +local P_audio_mp3_Tags: any = {} +do -- audio/mp3/Tags: id3v2Size +local Tags = {} +local band, bor, lshift = bit32.band, bit32.bor, bit32.lshift +local ru8 = buffer.readu8 +local function syncsafe(b: buffer, o: number): number + return bor(lshift(band(ru8(b, o), 0x7F), 21), lshift(band(ru8(b, o + 1), 0x7F), 14), lshift(band(ru8(b, o + 2), 0x7F), 7), band(ru8(b, o + 3), 0x7F)) +end +function Tags.id3v2Size(b: buffer, o: number, len: number): number + if len - o < 10 or buffer.readstring(b, o, 3) ~= "ID3" then + return 0 + end + if band(ru8(b, o + 5), 15) ~= 0 then + return 0 + end + for k = 6, 9 do + if band(ru8(b, o + k), 0x80) ~= 0 then + return 0 + end + end + local size = syncsafe(b, o + 6) + 10 + if band(ru8(b, o + 5), 16) ~= 0 then + size += 10 + 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 = {} +Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 } +type Adts = { + headerSize: number, -- 7, or 9 with a CRC + frameSize: number, + objectType: number, + sfIndex: number, + sampleRate: number, + channelConfig: number, + blocks: number, -- raw_data_blocks in the frame (1 .. 4) + protected: boolean, +} +function Aac.adts(b: buffer, o: number, limit: number): Adts? + if o < 0 or o + 7 > limit or o + 7 > buffer.len(b) then + return nil + end + local b0, b1, b2, b3, b4, b5, b6 = buffer.readu8(b, o), buffer.readu8(b, o + 1), buffer.readu8(b, o + 2), buffer.readu8(b, o + 3), buffer.readu8(b, o + 4), buffer.readu8(b, o + 5), buffer.readu8(b, o + 6) + if b0 ~= 0xFF or bit32.band(b1, 0xF6) ~= 0xF0 then -- sync, layer 0 + return nil + end + local protected = bit32.band(b1, 1) == 0 + local profile = bit32.rshift(b2, 6) + local sfi = bit32.band(bit32.rshift(b2, 2), 15) + local ch = bit32.band(b2, 1) * 4 + bit32.rshift(b3, 6) + local size = bit32.band(b3, 3) * 2048 + b4 * 8 + bit32.rshift(b5, 5) + local blocks = bit32.band(b6, 3) + 1 + local hs = if protected then 9 else 7 + if sfi > 12 or size < hs then + return nil + end + return { + headerSize = hs, + frameSize = size, + objectType = profile + 1, + sfIndex = sfi, + sampleRate = Aac.RATES[sfi + 1], + channelConfig = ch, + blocks = blocks, + 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 = {} +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 + local kbps = T.BITRATES[frmsizecod // 2 + 1] + if not kbps or fscod > 2 then + return 0 + end + if fscod == 0 then + return 2 * kbps + elseif fscod == 2 then + return 3 * kbps + 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 = {} +local T = P_codecs_audio_Ac3_Tables +local readu8 = buffer.readu8 +local NFCHANS = { [0] = 2, 1, 2, 3, 3, 4, 4, 5 } +type Header = { + sampleRate: number, + frameSize: number, + bitrate: number, + channels: number, + acmod: number, + lfeon: boolean, + bsid: number, +} +function Ac3.header(b: buffer, o: number, limit: number): Header? + if o < 0 or o + 8 > limit or o + 8 > buffer.len(b) then + return nil + end + if readu8(b, o) ~= 0x0B or readu8(b, o + 1) ~= 0x77 then + return nil + end + local bsid = bit32.rshift(readu8(b, o + 5), 3) + if bsid > 10 then + if bsid > 16 then + return nil + end + -- E-AC-3: strmtyp(2) substreamid(3) frmsiz(11) fscod(2) ... + local words = bit32.band(readu8(b, o + 2), 7) * 256 + readu8(b, o + 3) + 1 + local fs = bit32.rshift(readu8(b, o + 4), 6) + return { + sampleRate = if fs < 3 then T.RATES[fs + 1] else 0, + frameSize = words * 2, + bitrate = 0, + channels = 0, + acmod = bit32.band(bit32.rshift(readu8(b, o + 4), 1), 7), + lfeon = false, + bsid = bsid, + } + end + local b4 = readu8(b, o + 4) + local fscod, frmsizecod = bit32.rshift(b4, 6), bit32.band(b4, 63) + local words = T.frameWords(fscod, frmsizecod) + if words == 0 then + return nil + end + local acmod = bit32.rshift(readu8(b, o + 6), 5) + -- lfeon: after acmod and the optional cmixlev / surmixlev / dsurmod fields + local skip = 0 + if bit32.band(acmod, 1) == 1 and acmod ~= 1 then + skip += 2 + end + if bit32.band(acmod, 4) ~= 0 then + skip += 2 + end + if acmod == 2 then + skip += 2 + end + local w = readu8(b, o + 6) * 256 + readu8(b, o + 7) + local lfeon = bit32.extract(w, 12 - skip, 1) == 1 + local shift = if bsid > 8 then bsid - 8 else 0 + return { + sampleRate = T.RATES[fscod + 1] // 2 ^ shift, + frameSize = words * 2, + bitrate = T.BITRATES[frmsizecod // 2 + 1] * 1000 // 2 ^ shift, + channels = NFCHANS[acmod] + (if lfeon then 1 else 0), + acmod = acmod, + lfeon = lfeon, + 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 = {} +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 = {} +local T = P_codecs_audio_Mpa_Tables +local band, bxor, rshift = bit32.band, bit32.bxor, bit32.rshift +local ru8 = buffer.readu8 +local HALFRATE = T.halfrate +local HZ = { [0] = 44100, 48000, 32000 } +function H.valid(b: buffer, o: number): boolean + if ru8(b, o) ~= 0xFF then + return false + end + local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + return (band(h1, 0xF0) == 0xF0 or band(h1, 0xFE) == 0xE2) + and band(rshift(h1, 1), 3) ~= 0 + and rshift(h2, 4) ~= 15 + and band(rshift(h2, 2), 3) ~= 3 +end +local valid = H.valid +function H.compare(b: buffer, o1: number, o2: number): boolean + if not valid(b, o2) then + return false + end + local a1, a2 = ru8(b, o1 + 1), ru8(b, o1 + 2) + local c1, c2 = ru8(b, o2 + 1), ru8(b, o2 + 2) + return band(bxor(a1, c1), 0xFE) == 0 + and band(bxor(a2, c2), 0x0C) == 0 + and (band(a2, 0xF0) == 0) == (band(c2, 0xF0) == 0) +end +function H.bitrateKbps(h1: number, h2: number): number + local mpeg1 = if band(h1, 8) ~= 0 then 1 else 0 + local layer = band(rshift(h1, 1), 3) + return 2 * HALFRATE[mpeg1 * 45 + (layer - 1) * 15 + rshift(h2, 4)] +end +local bitrateKbps = H.bitrateKbps +function H.sampleRate(h1: number, h2: number): number + local hz = HZ[band(rshift(h2, 2), 3)] + if band(h1, 8) == 0 then + hz //= 2 + end + if band(h1, 0x10) == 0 then + hz //= 2 + end + return hz +end +local sampleRate = H.sampleRate +function H.frameSamples(h1: number): number + if band(h1, 6) == 6 then + return 384 + elseif band(h1, 14) == 2 then + return 576 + end + return 1152 +end +local frameSamples = H.frameSamples +function H.frameBytes(b: buffer, o: number, freeSize: number): number + local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + local hz = sampleRate(h1, h2) + local fb = frameSamples(h1) * bitrateKbps(h1, h2) * 125 // hz + if band(h1, 6) == 6 then + fb = band(fb, 0xFFFFFFFC) + end + return if fb ~= 0 then fb else freeSize +end +function H.padding(b: buffer, o: number): number + if band(ru8(b, o + 2), 2) == 0 then + return 0 + 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 = {} +function Musepack.magic(buf: buffer, p: number, limit: number): number + if p + 4 > limit then + return 0 + end + local m = buffer.readstring(buf, p, 4) + if m == "MPCK" then + return 8 + end + if string.sub(m, 1, 3) == "MP+" then + return 7 + 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 = {} +local Bytes = __include("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() + return __include("codecs/compress/Brotli") +end) + +local P_codecs_compress_Deflate_Inflate = lazy(function() + return __include("codecs/compress/Deflate/Inflate") +end) + +local P_codecs_compress_Deflate: any = {} +do -- codecs/compress/Deflate: peek +local Deflate = {} +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Inflate = P_codecs_compress_Deflate_Inflate +local args = Bytes.span +local function shrink(out: buffer, n: number): buffer + if buffer.len(out) == n then + return out + end + local b = buffer.create(n) + buffer.copy(b, 0, out, 0, n) + return b +end +local function inflateErr(msg: string, at: number?): Err.Err + local code = if string.find(msg, "truncated", 1, true) then Err.TRUNCATED else Err.CORRUPT + return Err.new(code, "inflate: " .. msg, at) +end +local function gzipBody(b: buffer, p: number, e: number): (number?, Err.Err?) + local flg = buffer.readu8(b, p + 3) + if flg >= 0x20 then + return nil, Err.new(Err.CORRUPT, "gzip: reserved flags set", p + 3) + end + local q = p + 10 + if bit32.band(flg, 4) ~= 0 then -- FEXTRA + if q + 2 > e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + q += 2 + buffer.readu16(b, q) + end + for _, bit in { 8, 16 } do -- FNAME, FCOMMENT: zero-terminated + if bit32.band(flg, bit) ~= 0 then + while q < e and buffer.readu8(b, q) ~= 0 do + q += 1 + end + q += 1 + end + end + if bit32.band(flg, 2) ~= 0 then -- FHCRC + q += 2 + end + if q >= e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + return q, nil +end +function Deflate.peek(buf: buffer | string, offset: number?, length: number?, n: number): (buffer?, Err.Err?) + local b, o, l, aerr = args("Deflate.peek", buf, offset, length) + if not b then + return nil, aerr + end + if type(n) ~= "number" or n < 1 then + return nil, Err.new(Err.ARG, "Deflate.peek: bad size " .. tostring(n)) + end + local e = o + l + local q = o + if l >= 18 and buffer.readu8(b, o) == 0x1f and buffer.readu8(b, o + 1) == 0x8b and buffer.readu8(b, o + 2) == 8 then + local herr + q, herr = gzipBody(b, o, e) + if not q then + return nil, herr + end + elseif l >= 6 then + local cmf, flg = buffer.readu8(b, o), buffer.readu8(b, o + 1) + if cmf % 16 == 8 and cmf // 16 <= 7 and (cmf * 256 + flg) % 31 == 0 and bit32.band(flg, 0x20) == 0 then + q = o + 2 + end + end + local out, k = Inflate.raw(b, q :: number, e, n, true, true) + if not out then + return nil, inflateErr(tostring(k), q) + end + return shrink(out, k), nil +end +P_codecs_compress_Deflate.peek = Deflate.peek +end + +local P_codecs_compress_Zstd_Decode = lazy(function() + return __include("codecs/compress/Zstd/Decode") +end) + +local P_codecs_compress_Zstd: any = {} +do -- codecs/compress/Zstd: MAGIC, decompress +local Zstd = {} +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Decode = P_codecs_compress_Zstd_Decode +type Options = { + maxBytes: number?, + verify: boolean?, +} +Zstd.MAGIC = "\40\181\47\253" +function Zstd.decompress(buf: buffer | string, offset: number?, length: number?, opts: Options?): (buffer?, any) + local b, o, l, aerr = Bytes.span("Zstd.decompress", buf, offset, length) + if not b then + return nil, aerr + end + local maxBytes = if opts and opts.maxBytes ~= nil then opts.maxBytes else 2 ^ 30 + if type(maxBytes) ~= "number" or maxBytes < 0 then + return nil, Err.new(Err.ARG, "Zstd.decompress: bad maxBytes " .. tostring(maxBytes)) + end + local verify = not (opts and opts.verify == false) + local out, len, consumed, at = Decode.decompress(b, o, o + l, maxBytes, verify) + if not out then + return nil, Err.from(consumed, at, len) + end + if buffer.len(out) ~= len then + local r = buffer.create(len) + buffer.copy(r, 0, out, 0, len) + out = r + 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 = {} +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 + return false + end + local t = readu8(b, o) + if t ~= 0 and t ~= 1 and t ~= 2 then + return false + end + for i = 1, math.min(n - 1, 64) do + local c = readu8(b, o + i) + if c == 0 then + return i > 1 + elseif c < 32 then + return false + end + 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 = {} +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 = {} +Value.NAMES = { + [0] = "end", + "byte", + "short", + "int", + "long", + "float", + "double", + "byteArray", + "string", + "list", + "compound", + "intArray", + "longArray", +} :: { [number]: string } +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 = {} +local Deflate = P_codecs_compress_Deflate +local Value = P_codecs_text_Nbt_Value +type Peek = { + compression: string, + endian: "big" | "little", + header: boolean, + rootType: string, + name: string, + firstType: string?, + firstName: string?, + head: buffer, +} +local function plausibleName(b: buffer, p: number, n: number): string? + if p + n > buffer.len(b) or n > 256 then + return nil + end + local s = buffer.readstring(b, p, n) + if string.find(s, "[%z\1-\31\127]") then + return nil + end + return s +end +function Nbt.peek(buf: buffer, offset: number?, length: number?): Peek? + local o = offset or 0 + local l = length or (buffer.len(buf) - o) + if l < 3 then + return nil + end + local c0, c1 = buffer.readu8(buf, o), buffer.readu8(buf, o + 1) + local head: buffer + local comp = "none" + if c0 == 0x1f and c1 == 0x8b or (c0 % 16 == 8 and c0 < 0x80 and (c0 * 256 + c1) % 31 == 0) then + local h = Deflate.peek(buf, o, l, 1024) + if not h then + return nil + end + head, comp = h, if c0 == 0x1f then "gzip" else "zlib" + else + local n = math.min(l, 1024) + head = buffer.create(n) + buffer.copy(head, 0, buf, o, n) + end + local hn = buffer.len(head) + local function at(p: number, endian: string, header: boolean): Peek? + if p + 3 > hn then + return nil + end + local t = buffer.readu8(head, p) + if t ~= 10 and t ~= 9 then + return nil + end + local function u16(q: number): number + local a, b = buffer.readu8(head, q), buffer.readu8(head, q + 1) + return if endian == "big" then a * 256 + b else b * 256 + a + end + local nl = u16(p + 1) + local name = plausibleName(head, p + 3, nl) + if not name then + return nil + end + local res: Peek = { compression = comp, endian = endian :: any, header = header, rootType = Value.NAMES[t], name = name, head = head } + local q = p + 3 + nl + if t == 10 and q < hn then + local ft = buffer.readu8(head, q) + if ft > 12 then + return nil + end + if ft == 0 then + res.firstType = "end" + elseif q + 3 <= hn then + local fname = plausibleName(head, q + 3, u16(q + 1)) + if fname == nil and q + 3 + u16(q + 1) <= hn then + return nil + end + res.firstType, res.firstName = Value.NAMES[ft], fname + end + end + return res + end + if hn >= 12 and buffer.readu32(head, 4) == (if comp == "none" then l else -1) - 8 then + local r = at(8, "little", true) + if r then + return r + end + 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 = {} +function Text.utf8char(c: number): string + local char = string.char + if c < 0x80 then + return char(c) + elseif c < 0x800 then + return char(0xC0 + c // 64, 0x80 + c % 64) + elseif c < 0x10000 then + return char(0xE0 + c // 4096, 0x80 + (c // 64) % 64, 0x80 + c % 64) + end + return char(0xF0 + c // 262144, 0x80 + (c // 4096) % 64, 0x80 + (c // 64) % 64, 0x80 + c % 64) +end +Text.CP1252 = { + [0x80] = 0x20AC, [0x82] = 0x201A, [0x83] = 0x0192, [0x84] = 0x201E, [0x85] = 0x2026, [0x86] = 0x2020, + [0x87] = 0x2021, [0x88] = 0x02C6, [0x89] = 0x2030, [0x8A] = 0x0160, [0x8B] = 0x2039, [0x8C] = 0x0152, + [0x8E] = 0x017D, [0x91] = 0x2018, [0x92] = 0x2019, [0x93] = 0x201C, [0x94] = 0x201D, [0x95] = 0x2022, + [0x96] = 0x2013, [0x97] = 0x2014, [0x98] = 0x02DC, [0x99] = 0x2122, [0x9A] = 0x0161, [0x9B] = 0x203A, + [0x9C] = 0x0153, [0x9E] = 0x017E, [0x9F] = 0x0178, +} +function Text.trim(s: string): string + return (string.match(s, "^%s*(.-)%s*$") :: string) +end +function Text.utf16(b: buffer, o: number, n: number, bigEndian: boolean?): string + local out = {} + local k = 0 + local readu16 = buffer.readu16 + local function unit(at: number): number + local v = readu16(b, at) + return if bigEndian then (v % 256) * 256 + v // 256 else v + end + while k + 1 < n do + local c = unit(o + k) + k += 2 + if c >= 0xD800 and c < 0xDC00 and k + 1 < n then + local lo = unit(o + k) + if lo >= 0xDC00 and lo < 0xE000 then + c = 0x10000 + (c - 0xD800) * 1024 + (lo - 0xDC00) + k += 2 + end + end + if c >= 0xD800 and c < 0xE000 then + c = 0xFFFD + end + table.insert(out, Text.utf8char(c)) + end + return table.concat(out) +end +function Text.toUtf8(text: string, warnings: { string }?): string + if string.sub(text, 1, 3) == "\239\187\191" then + text = string.sub(text, 4) + end + if utf8.len(text) then + return text + end + if warnings then + table.insert(warnings, "text is not UTF-8: read as Windows-1252") + end + local out = table.create(#text) + for i = 1, #text do + local b = string.byte(text, i) + if b < 0x80 then + out[i] = string.char(b) + else + out[i] = utf8.char(if b < 0xA0 then Text.CP1252[b] or 0xFFFD else b) + end + 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 = {} +local readu8, readu16, readu32 = buffer.readu8, buffer.readu16, buffer.readu32 +type Volume = { + b: buffer, + base: number, -- byte offset of the volume (partition) in b + limit: number, + bps: number, -- bytes per sector + spc: number, -- sectors per cluster + fatOffset: number, -- byte offset of the first FAT (relative to base) + fatSize: number, -- bytes per FAT + rootOffset: number, -- FAT12 / 16: the fixed root directory + rootEntries: number, + rootCluster: number, -- FAT32 + dataOffset: number, -- byte offset of cluster 2 + clusters: number, -- data clusters + bits: number, -- 12 / 16 / 32 + label: string?, + oem: string, + media: number, + partition: number?, +} +local function bpbAt(b: buffer, o: number, len: number): (Volume?, string?) + if len < 512 then + return nil, "truncated: smaller than a boot sector" + end + local jump = readu8(b, o) + local bps = readu16(b, o + 11) + local spc = readu8(b, o + 13) + if (jump ~= 0xEB and jump ~= 0xE9 and jump ~= 0xE8) or (bps ~= 512 and bps ~= 1024 and bps ~= 2048 and bps ~= 4096) then + return nil, "no FAT boot sector" + end + if spc == 0 or bit32.band(spc, spc - 1) ~= 0 then + return nil, "bad sectors per cluster" + end + local reserved, nfats, rootEntries = readu16(b, o + 14), readu8(b, o + 16), readu16(b, o + 17) + local total = readu16(b, o + 19) + if total == 0 then + total = readu32(b, o + 32) + end + local fatSectors = readu16(b, o + 22) + local fat32 = fatSectors == 0 + if fat32 then + fatSectors = readu32(b, o + 36) + end + if reserved == 0 or nfats == 0 or fatSectors == 0 or total == 0 then + return nil, "bad BPB" + end + local rootSectors = math.ceil(rootEntries * 32 / bps) + local dataSector = reserved + nfats * fatSectors + rootSectors + if dataSector >= total then + return nil, "bad BPB: no data area" + end + local clusters = (total - dataSector) // spc + local bits = if clusters < 4085 then 12 elseif clusters < 65525 then 16 else 32 + if fat32 and bits ~= 32 then + bits = 32 -- some small FAT32 volumes (mkfs.fat -F 32 on tiny images) are FAT32 regardless of the count + end + if total * bps > len then + -- images cut short at the last used sector are common: allow, reads past the end fail + total = len // bps + end + local labelAt = if bits == 32 then 71 else 43 + local sig = readu8(b, o + (if bits == 32 then 66 else 38)) + local label: string? = if sig == 0x29 then (string.gsub(buffer.readstring(b, o + labelAt, 11), " +$", "")) else nil + if label == "NO NAME" or label == "" then + label = nil + end + return { + b = b, + base = o, + limit = o + len, + bps = bps, + spc = spc, + fatOffset = reserved * bps, + fatSize = fatSectors * bps, + rootOffset = (reserved + nfats * fatSectors) * bps, + rootEntries = rootEntries, + rootCluster = if bits == 32 then readu32(b, o + 44) else 0, + dataOffset = dataSector * bps, + clusters = clusters, + bits = bits, + label = label, + oem = buffer.readstring(b, o + 3, 8), + media = readu8(b, o + 21), + }, nil +end +type OpenOptions = { partition: number? } -- 1..4: the MBR partition (default: the first FAT one) +local FAT_TYPES = { [0x01] = true, [0x04] = true, [0x06] = true, [0x0B] = true, [0x0C] = true, [0x0E] = true, [0x11] = true, [0x14] = true, [0x16] = true, [0x1B] = true, [0x1C] = true, [0x1E] = true } +function Fat.open(b: buffer, off: number, len: number, opts: OpenOptions?): (Volume?, string?) + local o: OpenOptions = opts or {} + off = math.max(0, off) + len = math.min(len, buffer.len(b) - off) + if len < 512 then + return nil, "truncated: smaller than a boot sector" + end + if not o.partition then + local v = bpbAt(b, off, len) + if v then + return v, nil + end + end + -- an MBR: 0x55AA and four partition entries + if readu8(b, off + 510) ~= 0x55 or readu8(b, off + 511) ~= 0xAA then + return nil, "no FAT boot sector and no partition table" + end + for i = 1, 4 do + local e = off + 446 + (i - 1) * 16 + local ptype = readu8(b, e + 4) + local lba, count = readu32(b, e + 8), readu32(b, e + 12) + if (o.partition == i or (not o.partition and FAT_TYPES[ptype])) and ptype ~= 0 then + if lba * 512 >= len then + return nil, "truncated: partition " .. i .. " starts past the end" + end + local v, err = bpbAt(b, off + lba * 512, math.min(count * 512, len - lba * 512)) + if v then + v.partition = i + end + return v, err + end + 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 = {} +local Bytes = __include("core/Bytes") +local TOP: { [string]: boolean } = { + ftyp = true, moov = true, mdat = true, free = true, skip = true, wide = true, pnot = true, moof = true, + styp = true, sidx = true, meta = true, uuid = true, PICT = true, +} +function IsoBmff.sniff(r: Bytes.Reader): string? + local head = r:peek(12) + if #head < 8 then + return nil + end + local typ = string.sub(head, 5, 8) + if typ == "ftyp" then + return if #head >= 12 then string.sub(head, 9, 12) else "" + end + if TOP[typ] then + local size = string.byte(head, 1) * 16777216 + string.byte(head, 2) * 65536 + string.byte(head, 3) * 256 + string.byte(head, 4) + if size == 1 or size == 0 or size >= 8 then + return "" + end + end + return nil +end +P_containers_IsoBmff.sniff = IsoBmff.sniff +end + +local P_containers_Riff: any = {} +do -- containers/Riff: sniff +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 + return nil + end + 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 = {} +local BLOCK = 512 +local function zeros(b: buffer, o: number): boolean + for i = 0, BLOCK - 1, 4 do + if buffer.readu32(b, o + i) ~= 0 then + return false + end + end + return true +end +local function number(b: buffer, o: number, n: number): number? + local first = buffer.readu8(b, o) + if first >= 0x80 then + local v = first - (if first >= 0xC0 then 0x100 else 0x80) -- 0xFF.. = negative + for i = 1, n - 1 do + v = v * 256 + buffer.readu8(b, o + i) + end + return v + end + local s = buffer.readstring(b, o, n) + s = string.match(s, "^[ %z]*([0-7]*)") or "" + if s == "" then + return 0 + end + return tonumber(s, 8) +end +local function checksum(b: buffer, o: number): (number, number) + local u, s = 0, 0 + for i = 0, BLOCK - 1 do + local v = if i >= 148 and i < 156 then 32 else buffer.readu8(b, o + i) + u += v + s += if v >= 128 then v - 256 else v + end + return u, s +end +function Tar.valid(b: buffer, o: number): boolean + if o + BLOCK > buffer.len(b) or zeros(b, o) then + return false + end + local want = number(b, o + 148, 8) + 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 = {} +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 = {} +Read.MAGIC = "MS3D000000" +P_model_ms3d_Read.MAGIC = Read.MAGIC +end + do -- image/ani local Bytes = __include("core/Bytes") S["image/ani"] = function(r: Bytes.Reader): number @@ -4008,9 +4896,7 @@ end do -- audio/aac local Bytes = __include("core/Bytes") -local Aac = lazy(function() - return __include("codecs/audio/Aac") -end) +local Aac = P_codecs_audio_Aac local readu8 = buffer.readu8 local function id3Size(b: buffer, p: number, limit: number): number if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then @@ -4040,9 +4926,7 @@ end do -- audio/ac3 local Bytes = __include("core/Bytes") -local Ac3 = lazy(function() - return __include("codecs/audio/Ac3") -end) +local Ac3 = P_codecs_audio_Ac3 S["audio/ac3"] = function(r: Bytes.Reader): number local b, p, limit = r.buf, r.pos, r.limit local h = Ac3.header(b, p, limit) @@ -4174,9 +5058,7 @@ end do -- audio/m4a local Bytes = __include("core/Bytes") -local IsoBmff = lazy(function() - return __include("containers/IsoBmff") -end) +local IsoBmff = P_containers_IsoBmff local AUDIO_BRANDS: { [string]: number } = { ["M4A "] = 1, ["M4B "] = 1, ["M4P "] = 1, ["M4V "] = 0.3 } S["audio/m4a"] = function(r: Bytes.Reader): number local brand = IsoBmff.sniff(r) @@ -4195,12 +5077,8 @@ end do -- audio/mp3 local Bytes = __include("core/Bytes") -local Header = lazy(function() - return __include("codecs/audio/Mpa/Header") -end) -local Tags = lazy(function() - return __include("audio/mp3/Tags") -end) +local Header = P_codecs_audio_Mpa_Header +local Tags = P_audio_mp3_Tags S["audio/mp3"] = function(r: Bytes.Reader): number local b, p, lim = r.buf, r.pos, r.limit local id3 = false @@ -4231,9 +5109,7 @@ end do -- audio/mpc local Bytes = __include("core/Bytes") -local Musepack = lazy(function() - return __include("codecs/audio/Musepack") -end) +local Musepack = P_codecs_audio_Musepack local function id3v2(b: buffer, p: number, limit: number): number if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then return 0 @@ -4332,9 +5208,7 @@ end do -- audio/wav local Bytes = __include("core/Bytes") -local Riff = lazy(function() - return __include("containers/Riff") -end) +local Riff = P_containers_Riff S["audio/wav"] = function(r: Bytes.Reader): number return if Riff.sniff(r) == "WAVE" then 1 else 0 end @@ -4438,9 +5312,7 @@ end do -- video/mp4 local Bytes = __include("core/Bytes") -local IsoBmff = lazy(function() - return __include("containers/IsoBmff") -end) +local IsoBmff = P_containers_IsoBmff local IMAGE_BRANDS = { avif = true, avis = true, heic = true, heix = true, mif1 = true, msf1 = true, ["crx "] = true } local AUDIO_BRANDS = { ["M4A "] = true, ["M4B "] = true, ["M4P "] = true } S["video/mp4"] = function(r: Bytes.Reader): number @@ -4603,9 +5475,7 @@ end do -- model/ase local Bytes = __include("core/Bytes") -local Text = lazy(function() - return __include("codecs/text/Text") -end) +local Text = P_codecs_text_Text local MAGIC = "*3DSMAX_ASCIIEXPORT" local function utf16(r: Bytes.Reader): (boolean?, boolean) local h = r:peek(2) @@ -4653,12 +5523,8 @@ end do -- model/blend local Bytes = __include("core/Bytes") -local Deflate = lazy(function() - return __include("codecs/compress/Deflate") -end) -local Zstd = lazy(function() - return __include("codecs/compress/Zstd") -end) +local Deflate = P_codecs_compress_Deflate +local Zstd = P_codecs_compress_Zstd S["model/blend"] = function(r: Bytes.Reader): number local head = r:peek(7) if head == "BLENDER" then @@ -4787,6 +5653,25 @@ S["model/dae"] = function(r: Bytes.Reader): number end end +do -- model/fbx +local Bytes = __include("core/Bytes") +local Binary = P_model_fbx_Binary +local MAGIC = Binary.MAGIC +S["model/fbx"] = function(r: Bytes.Reader): number + if r:peek(21) == MAGIC then + return 1 + end + local head = r:peek(2048) + if string.find(head, "FBXHeaderExtension:", 1, true) then + return 0.95 + end + if string.find(head, "^; FBX %d") then + return 0.8 + end + return 0 +end +end + do -- model/gltf local Sniff = __include("core/Sniff") local Bytes = __include("core/Bytes") @@ -4966,9 +5851,7 @@ end do -- model/ms3d local Bytes = __include("core/Bytes") -local Read = lazy(function() - return __include("model/ms3d/Read") -end) +local Read = P_model_ms3d_Read S["model/ms3d"] = function(r: Bytes.Reader): number local h = r:peek(14) if string.sub(h, 1, 10) ~= Read.MAGIC then @@ -5098,9 +5981,7 @@ end do -- model/schematic local Bytes = __include("core/Bytes") -local Nbt = lazy(function() - return __include("codecs/text/Nbt") -end) +local Nbt = P_codecs_text_Nbt local LITEMATIC_HINTS = { "Regions", "EnclosingSize", "RegionCount", "TotalVolume", "MinecraftDataVersion" } local SPONGE_HINTS = { "BlockData", "PaletteMax" } -- v1 / v2 fields (some writers leave the root unnamed) local function hinted(head: string, hints: { string }): boolean @@ -5563,9 +6444,7 @@ end do -- archive/br local Err = __include("core/Err") local Bytes = __include("core/Bytes") -local Brotli = lazy(function() - return __include("codecs/compress/Brotli") -end) +local Brotli = P_codecs_compress_Brotli local SNIFF_WHOLE = 262144 -- streams up to this size are decoded whole by sniff local SNIFF_PREFIX = 65536 S["archive/br"] = function(r: Bytes.Reader): number @@ -5678,9 +6557,7 @@ end do -- archive/fat local Bytes = __include("core/Bytes") -local Fat = lazy(function() - return __include("containers/Fat") -end) +local Fat = P_containers_Fat S["archive/fat"] = function(r: Bytes.Reader): number if r:remaining() < 512 then return 0 @@ -5852,9 +6729,7 @@ end do -- archive/tar local Bytes = __include("core/Bytes") -local Tar = lazy(function() - return __include("containers/Tar") -end) +local Tar = P_containers_Tar S["archive/tar"] = function(r: Bytes.Reader): number if r:remaining() < 512 then return 0 @@ -5868,12 +6743,8 @@ end do -- archive/unitypackage local Bytes = __include("core/Bytes") -local Deflate = lazy(function() - return __include("codecs/compress/Deflate") -end) -local Tar = lazy(function() - return __include("containers/Tar") -end) +local Deflate = P_codecs_compress_Deflate +local Tar = P_containers_Tar local function guidOf(name: string): (string?, string?) local n = string.gsub(name, "^%./", "") local guid, rest = string.match(n, "^(%x+)/?(.*)$") @@ -6077,9 +6948,7 @@ end do -- archive/zst local Bytes = __include("core/Bytes") -local Zstd = lazy(function() - return __include("codecs/compress/Zstd") -end) +local Zstd = P_codecs_compress_Zstd S["archive/zst"] = function(r: Bytes.Reader): number local m = r:peek(4) if m == Zstd.MAGIC then @@ -6172,9 +7041,7 @@ end do -- data/nbt local Bytes = __include("core/Bytes") -local Nbt = lazy(function() - return __include("codecs/text/Nbt") -end) +local Nbt = P_codecs_text_Nbt S["data/nbt"] = function(r: Bytes.Reader): number local p = Nbt.peek(r.buf, r.base, r.limit - r.base) if not p or p.rootType ~= "compound" then @@ -6302,9 +7169,7 @@ end do -- data/vdf local Bytes = __include("core/Bytes") local Sniff = __include("core/Sniff") -local KeyValues = lazy(function() - return __include("codecs/text/KeyValues") -end) +local KeyValues = P_codecs_text_KeyValues S["data/vdf"] = function(r: Bytes.Reader): number local n = r:remaining() if KeyValues.isBinary(r.buf, r.pos, n) then @@ -6770,9 +7635,7 @@ end do -- music/sf2 local Bytes = __include("core/Bytes") -local SoundFont = lazy(function() - return __include("codecs/audio/SoundFont") -end) +local SoundFont = P_codecs_audio_SoundFont S["music/sf2"] = function(r: Bytes.Reader): number return if SoundFont.sniff(r) then 1 else 0 end @@ -6920,9 +7783,7 @@ end do -- playlist/pls local Sniff = __include("core/Sniff") local Bytes = __include("core/Bytes") -local Text = lazy(function() - return __include("codecs/text/Text") -end) +local Text = P_codecs_text_Text S["playlist/pls"] = function(r: Bytes.Reader): number local s = Sniff.text(r, 64) local first = string.match(s, "^%s*([^\r\n]*)") @@ -61807,7 +62668,6 @@ local Err = __include("core/Err") local Bytes = __include("core/Bytes") local Crc32 = __include("core/Crc32") local Base64 = __include("core/Base64") -local Deflate = __include("codecs/compress/Deflate") local Decode = __include("codecs/compress/Brotli/Decode") local StaticData = __include("codecs/compress/Brotli/Static") @@ -61824,32 +62684,46 @@ local function unbase64(s: string): buffer end local static: Decode.Static? = nil +local dictionary: buffer? = nil +local dictionaryErr: Err.Err? = nil -local function tables(): (Decode.Static?, Err.Err?) - if static then - return static, nil +-- inflated on the first dictionary reference (RFC 7932 section 8) +local function loadDictionary(): buffer? + if dictionary or dictionaryErr then + return dictionary end + local Deflate = __include("codecs/compress/Deflate") local z = unbase64(table.concat(StaticData.dictionary)) local dict, err = Deflate.zlib(z, 0, nil, StaticData.dictionarySize) if not dict then - return nil, err + dictionaryErr = err + return nil end if Crc32.of(dict) ~= StaticData.dictionaryCrc then - return nil, Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + dictionaryErr = Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + return nil end - static = { - dictionary = dict, + dictionary = dict + return dict +end + +local function tables(): Decode.Static + if static then + return static + end + local s: Decode.Static = { + dictionary = loadDictionary, context = unbase64(table.concat(StaticData.context)), prefixSuffix = unbase64(StaticData.prefixSuffix), prefixSuffixMap = StaticData.prefixSuffixMap, transforms = StaticData.transforms, } - return static, nil + static = s + return s end function Brotli.dictionary(): buffer? - local s = tables() - return if s then s.dictionary else nil + return loadDictionary() end function Brotli.decompress(buf: buffer | string, offset: number?, length: number?, opts: Options?): (buffer?, any) @@ -61865,12 +62739,11 @@ function Brotli.decompress(buf: buffer | string, offset: number?, length: number if l == 0 then return nil, Err.new(Err.TRUNCATED, "brotli: empty input", o) end - local S, serr = tables() - if not S then - return nil, serr - end - local out, size, consumed = Decode.decompress(b, o, l, maxBytes, S, large) + local out, size, consumed = Decode.decompress(b, o, l, maxBytes, tables(), large) if not out then + if size == Decode.NO_DICTIONARY and dictionaryErr then + return nil, dictionaryErr + end local e = Err.from(size, o) e.message = "brotli: " .. e.message return nil, e @@ -61898,8 +62771,11 @@ local bcreate, bcopy, blen, bfill = buffer.create, buffer.copy, buffer.len, buff local Decode = {} +local NO_DICTIONARY = "static dictionary unavailable" +Decode.NO_DICTIONARY = NO_DICTIONARY + type Static = { - dictionary: buffer, -- 122784 bytes + dictionary: () -> buffer?, -- 122784 bytes, on first use (nil: Decode.NO_DICTIONARY) context: buffer, -- 2048 bytes: 4 modes x (256 for p1, 256 for p2) prefixSuffix: buffer, -- length-prefixed strings prefixSuffixMap: { number }, @@ -62404,7 +63280,7 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb end local maxBackward = 2 ^ wbits - 16 - local dict = S.dictionary + local dict: buffer? = nil local LUT = S.context local PS = S.prefixSuffix local PSMAP = S.prefixSuffixMap @@ -62773,7 +63649,12 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb end local ws = w if wl > 0 then - bcopy(WORD, w, dict, wo, wl) + local d = dict or S.dictionary() + if d == nil then + return nil, NO_DICTIONARY + end + dict = d + bcopy(WORD, w, d, wo, wl) w += wl end if ttype == 10 then diff --git a/build/Rosetta.luau.linemap.json b/build/Rosetta.luau.linemap.json index 6cef22d..cfb7414 100644 --- a/build/Rosetta.luau.linemap.json +++ b/build/Rosetta.luau.linemap.json @@ -1,623 +1,623 @@ [ [29, "src/Rosetta/init.luau"], -[946, "src/Rosetta/Registry.luau"], -[3563, "src/Rosetta/Sniffs.luau"], -[6949, "src/Rosetta/Types.luau"], -[8066, "src/Rosetta/archive/7z/init.luau"], -[8451, "src/Rosetta/archive/7z/Header.luau"], -[8978, "src/Rosetta/archive/adf/init.luau"], -[9260, "src/Rosetta/archive/applesingle/init.luau"], -[9446, "src/Rosetta/archive/ar/init.luau"], -[9849, "src/Rosetta/archive/arj/init.luau"], -[10059, "src/Rosetta/archive/binhex/init.luau"], -[10308, "src/Rosetta/archive/br/init.luau"], -[10383, "src/Rosetta/archive/bz2/init.luau"], -[10447, "src/Rosetta/archive/cab/init.luau"], -[10860, "src/Rosetta/archive/cab/Sum.luau"], -[10901, "src/Rosetta/archive/cpio/init.luau"], -[11069, "src/Rosetta/archive/d64/init.luau"], -[11483, "src/Rosetta/archive/fat/init.luau"], -[11605, "src/Rosetta/archive/grp/init.luau"], -[11719, "src/Rosetta/archive/gzip/init.luau"], -[11904, "src/Rosetta/archive/iso/init.luau"], -[11976, "src/Rosetta/archive/lha/init.luau"], -[12401, "src/Rosetta/archive/lz4/init.luau"], -[12745, "src/Rosetta/archive/macbinary/init.luau"], -[12943, "src/Rosetta/archive/mpq/init.luau"], -[13349, "src/Rosetta/archive/mpq/Crypt.luau"], -[13414, "src/Rosetta/archive/pak/init.luau"], -[13548, "src/Rosetta/archive/rpm/init.luau"], -[13872, "src/Rosetta/archive/tar/init.luau"], -[13990, "src/Rosetta/archive/unitypackage/init.luau"], -[14226, "src/Rosetta/archive/uu/init.luau"], -[14496, "src/Rosetta/archive/vpk/init.luau"], -[14807, "src/Rosetta/archive/vswap/init.luau"], -[15077, "src/Rosetta/archive/wad/init.luau"], -[15531, "src/Rosetta/archive/wad/Picture.luau"], -[15633, "src/Rosetta/archive/wad2/init.luau"], -[15915, "src/Rosetta/archive/xz/init.luau"], -[16015, "src/Rosetta/archive/yenc/init.luau"], -[16287, "src/Rosetta/archive/z/init.luau"], -[16383, "src/Rosetta/archive/zip/init.luau"], -[16602, "src/Rosetta/archive/zoo/init.luau"], -[16798, "src/Rosetta/archive/zst/init.luau"], -[16862, "src/Rosetta/audio/aac/init.luau"], -[17075, "src/Rosetta/audio/ac3/init.luau"], -[17222, "src/Rosetta/audio/adpcm/init.luau"], -[17368, "src/Rosetta/audio/adx/init.luau"], -[17600, "src/Rosetta/audio/aiff/init.luau"], -[17992, "src/Rosetta/audio/ape/init.luau"], -[18121, "src/Rosetta/audio/au/init.luau"], -[18283, "src/Rosetta/audio/brstm/init.luau"], -[18575, "src/Rosetta/audio/caf/init.luau"], -[19242, "src/Rosetta/audio/flac/init.luau"], -[19391, "src/Rosetta/audio/flac/Meta.luau"], -[19613, "src/Rosetta/audio/flac/Stream.luau"], -[19983, "src/Rosetta/audio/m4a/init.luau"], -[20326, "src/Rosetta/audio/mp3/init.luau"], -[20587, "src/Rosetta/audio/mp3/Index.luau"], -[20778, "src/Rosetta/audio/mp3/Stream.luau"], -[21005, "src/Rosetta/audio/mp3/Tags.luau"], -[21317, "src/Rosetta/audio/mpc/init.luau"], -[21412, "src/Rosetta/audio/opus/init.luau"], -[21791, "src/Rosetta/audio/opus/Encode.luau"], -[21903, "src/Rosetta/audio/qoa/init.luau"], -[22084, "src/Rosetta/audio/tta/init.luau"], -[22203, "src/Rosetta/audio/vag/init.luau"], -[22427, "src/Rosetta/audio/voc/init.luau"], -[22703, "src/Rosetta/audio/vorbis/init.luau"], -[23158, "src/Rosetta/audio/vorbis/Encode.luau"], -[23971, "src/Rosetta/audio/wav/init.luau"], -[24592, "src/Rosetta/audio/wav/Codecs.luau"], -[24771, "src/Rosetta/audio/wavpack/init.luau"], -[24979, "src/Rosetta/cad/step/init.luau"], -[25361, "src/Rosetta/cad/step/Brep.luau"], -[25596, "src/Rosetta/cad/step/Parse.luau"], -[26153, "src/Rosetta/cad/step/Write.luau"], -[26401, "src/Rosetta/codecs/audio/Aac/init.luau"], -[26809, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[27785, "src/Rosetta/codecs/audio/Aac/Ps.luau"], -[28375, "src/Rosetta/codecs/audio/Aac/Sbr.luau"], -[29442, "src/Rosetta/codecs/audio/Aac/SbrBits.luau"], -[29561, "src/Rosetta/codecs/audio/Aac/SbrDct.luau"], -[30803, "src/Rosetta/codecs/audio/Aac/SbrHf.luau"], -[31295, "src/Rosetta/codecs/audio/Aac/SbrQmf.luau"], -[31412, "src/Rosetta/codecs/audio/Aac/SbrTables.luau"], -[31825, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[32161, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[32321, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[33206, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[33308, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[34062, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[34365, "src/Rosetta/codecs/audio/Alac/init.luau"], -[34600, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[35019, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[35431, "src/Rosetta/codecs/audio/Ape/init.luau"], -[35647, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[36408, "src/Rosetta/codecs/audio/ApeTag.luau"], -[36506, "src/Rosetta/codecs/audio/Flac/init.luau"], -[36518, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[37467, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[38087, "src/Rosetta/codecs/audio/Hively/init.luau"], -[38284, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[38534, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[39493, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[39713, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[39933, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[40187, "src/Rosetta/codecs/audio/MidiRender.luau"], -[40534, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[40549, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[40608, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[42266, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[42559, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[42944, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[43585, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[43726, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[43953, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[44299, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[45193, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[45572, "src/Rosetta/codecs/audio/Opus/init.luau"], -[45587, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[47459, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[48524, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[48585, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[49049, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[49400, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[49633, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[51675, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[52049, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[52313, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[52610, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[52892, "src/Rosetta/codecs/audio/Resample/init.luau"], -[53287, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[53342, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[53486, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[54000, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[54799, "src/Rosetta/codecs/audio/Stream.luau"], -[54961, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[55444, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[55723, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[55970, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[56099, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[58088, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[58205, "src/Rosetta/codecs/audio/Tta/init.luau"], -[58323, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[58575, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[58589, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[58973, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[59546, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[59968, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[60008, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[60061, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[60284, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[61739, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[61802, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[61889, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[62865, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[63733, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[63777, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[64290, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[64703, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[65185, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[65706, "src/Rosetta/codecs/compress/Explode.luau"], -[65902, "src/Rosetta/codecs/compress/Lz4.luau"], -[66171, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[66775, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[67315, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[67382, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[67855, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[68031, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[68299, "src/Rosetta/codecs/compress/Lzx.luau"], -[68733, "src/Rosetta/codecs/compress/PackBits.luau"], -[68823, "src/Rosetta/codecs/compress/Quantum.luau"], -[69060, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[69364, "src/Rosetta/codecs/compress/Xxh32.luau"], -[69433, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[69490, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[70474, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[70626, "src/Rosetta/codecs/entropy/Huffman.luau"], -[70913, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[70924, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[71145, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[71389, "src/Rosetta/codecs/font/Bitmap.luau"], -[71590, "src/Rosetta/codecs/font/Cff/init.luau"], -[72231, "src/Rosetta/codecs/font/GlyphNames.luau"], -[72381, "src/Rosetta/codecs/font/TrueType/init.luau"], -[72695, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[73087, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[73589, "src/Rosetta/codecs/image/Bcn/init.luau"], -[73696, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[74180, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[74609, "src/Rosetta/codecs/image/Blend.luau"], -[74988, "src/Rosetta/codecs/image/Dct/init.luau"], -[75483, "src/Rosetta/codecs/image/Etc.luau"], -[75781, "src/Rosetta/codecs/image/Half.luau"], -[75850, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[76204, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[76612, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[76977, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[77742, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[78623, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[79100, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[79178, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[79245, "src/Rosetta/codecs/image/Miptex.luau"], -[79545, "src/Rosetta/codecs/image/Pixels.luau"], -[79865, "src/Rosetta/codecs/image/Quantize/init.luau"], -[80326, "src/Rosetta/codecs/image/Raster.luau"], -[81023, "src/Rosetta/codecs/image/Texel.luau"], -[81396, "src/Rosetta/codecs/image/Texture.luau"], -[81541, "src/Rosetta/codecs/image/Vp8/init.luau"], -[81683, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[83663, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[83926, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[84176, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[84318, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[84422, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[85362, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[86314, "src/Rosetta/codecs/image/Yuv.luau"], -[86635, "src/Rosetta/codecs/model/Brush.luau"], -[87275, "src/Rosetta/codecs/model/Displacement.luau"], -[87424, "src/Rosetta/codecs/model/DoomMap/init.luau"], -[87869, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], -[88119, "src/Rosetta/codecs/model/Draco/init.luau"], -[88451, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[88920, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[90109, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[90258, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[90617, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[91579, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[92053, "src/Rosetta/codecs/model/Mat4.luau"], -[92312, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[92840, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[93392, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[93471, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[93578, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[93784, "src/Rosetta/codecs/model/Patch.luau"], -[93908, "src/Rosetta/codecs/model/Polygon.luau"], -[94142, "src/Rosetta/codecs/model/Rbx/init.luau"], -[94379, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[95133, "src/Rosetta/codecs/model/Rig.luau"], -[95376, "src/Rosetta/codecs/model/Sampler.luau"], -[95536, "src/Rosetta/codecs/model/SourceAnim.luau"], -[95757, "src/Rosetta/codecs/model/Vrml/init.luau"], -[95905, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[96479, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[96642, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[97391, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[97913, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[98640, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[98872, "src/Rosetta/codecs/text/GodotVariant.luau"], -[99531, "src/Rosetta/codecs/text/Json/init.luau"], -[99800, "src/Rosetta/codecs/text/Json/Decode.luau"], -[100235, "src/Rosetta/codecs/text/Json/Encode.luau"], -[100580, "src/Rosetta/codecs/text/KeyValues/init.luau"], -[101150, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], -[101456, "src/Rosetta/codecs/text/Lexer/init.luau"], -[101588, "src/Rosetta/codecs/text/Nbt/init.luau"], -[101941, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[102633, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[103273, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[103511, "src/Rosetta/codecs/text/Text/init.luau"], -[103602, "src/Rosetta/codecs/text/Url/init.luau"], -[103807, "src/Rosetta/codecs/text/Xml/init.luau"], -[104257, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[105061, "src/Rosetta/codecs/video/Dsp.luau"], -[105899, "src/Rosetta/codecs/video/H263/init.luau"], -[106056, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[106914, "src/Rosetta/codecs/video/H263/Tables.luau"], -[107118, "src/Rosetta/codecs/video/H264/init.luau"], -[107508, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[107783, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[108914, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[109682, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[109944, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[111010, "src/Rosetta/codecs/video/H264/Inter.luau"], -[111336, "src/Rosetta/codecs/video/H264/Intra.luau"], -[111743, "src/Rosetta/codecs/video/H264/Mb.luau"], -[112697, "src/Rosetta/codecs/video/H264/Params.luau"], -[113145, "src/Rosetta/codecs/video/H264/Slice.luau"], -[113397, "src/Rosetta/codecs/video/H264/Tables.luau"], -[113439, "src/Rosetta/codecs/video/H264/Transform.luau"], -[113604, "src/Rosetta/codecs/video/Legacy/init.luau"], -[113803, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[114100, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[114467, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[114585, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[114693, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[114966, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[115361, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[115538, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[115551, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[115925, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[117452, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[117592, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[117731, "src/Rosetta/codecs/video/Theora/init.luau"], -[117995, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[119259, "src/Rosetta/codecs/video/Theora/Header.luau"], -[119623, "src/Rosetta/codecs/video/Video/init.luau"], -[120238, "src/Rosetta/codecs/video/Video/Disposable.luau"], -[120449, "src/Rosetta/codecs/video/Video/Pool.luau"], -[120501, "src/Rosetta/codecs/video/Video/Source.luau"], -[120787, "src/Rosetta/containers/Archive.luau"], -[121054, "src/Rosetta/containers/AudioWrap.luau"], -[121564, "src/Rosetta/containers/Avi/init.luau"], -[122117, "src/Rosetta/containers/Blend.luau"], -[122856, "src/Rosetta/containers/Chunks.luau"], -[122991, "src/Rosetta/containers/Cpio.luau"], -[123419, "src/Rosetta/containers/Demux.luau"], -[123705, "src/Rosetta/containers/Ebml/init.luau"], -[124019, "src/Rosetta/containers/Fat.luau"], -[124707, "src/Rosetta/containers/Iso9660.luau"], -[125212, "src/Rosetta/containers/IsoBmff/init.luau"], -[125383, "src/Rosetta/containers/IsoBmff/Box.luau"], -[125572, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[126418, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[126940, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[127457, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[127575, "src/Rosetta/containers/MacFile.luau"], -[127724, "src/Rosetta/containers/MpegEs.luau"], -[127891, "src/Rosetta/containers/MpegPs/init.luau"], -[128112, "src/Rosetta/containers/MpegTs/init.luau"], -[128905, "src/Rosetta/containers/Ogg/init.luau"], -[129330, "src/Rosetta/containers/Ogg/Mux.luau"], -[129519, "src/Rosetta/containers/Ogg/Page.luau"], -[129685, "src/Rosetta/containers/Riff/init.luau"], -[130002, "src/Rosetta/containers/Tar.luau"], -[130416, "src/Rosetta/containers/Zip/init.luau"], -[131048, "src/Rosetta/core/Adler32.luau"], -[131108, "src/Rosetta/core/Base64.luau"], -[131336, "src/Rosetta/core/Bits.luau"], -[131629, "src/Rosetta/core/Bytes.luau"], -[132156, "src/Rosetta/core/Crc16.luau"], -[132208, "src/Rosetta/core/Crc32.luau"], -[132359, "src/Rosetta/core/Err.luau"], -[132441, "src/Rosetta/core/Input.luau"], -[132517, "src/Rosetta/core/Md5.luau"], -[132675, "src/Rosetta/core/Sniff.luau"], -[132704, "src/Rosetta/data/cbor/init.luau"], -[132803, "src/Rosetta/data/cbor/Codec.luau"], -[133372, "src/Rosetta/data/csv/init.luau"], -[133684, "src/Rosetta/data/ini/init.luau"], -[133930, "src/Rosetta/data/json/init.luau"], -[134022, "src/Rosetta/data/msgpack/init.luau"], -[134111, "src/Rosetta/data/msgpack/Codec.luau"], -[134553, "src/Rosetta/data/nbt/init.luau"], -[134612, "src/Rosetta/data/plist/init.luau"], -[134918, "src/Rosetta/data/plist/Binary.luau"], -[135185, "src/Rosetta/data/q3shader/init.luau"], -[135424, "src/Rosetta/data/q3skin/init.luau"], -[135520, "src/Rosetta/data/snbt/init.luau"], -[135583, "src/Rosetta/data/toml/init.luau"], -[135650, "src/Rosetta/data/toml/Decode.luau"], -[136278, "src/Rosetta/data/toml/Encode.luau"], -[136487, "src/Rosetta/data/tres/init.luau"], -[136632, "src/Rosetta/data/vdf/init.luau"], -[136733, "src/Rosetta/data/xml/init.luau"], -[136789, "src/Rosetta/data/yaml/init.luau"], -[136862, "src/Rosetta/data/yaml/Emit.luau"], -[137152, "src/Rosetta/data/yaml/Parse.luau"], -[138445, "src/Rosetta/font/bdf/init.luau"], -[138734, "src/Rosetta/font/bmfont/init.luau"], -[139161, "src/Rosetta/font/bmfont/Parse.luau"], -[139614, "src/Rosetta/font/eot/init.luau"], -[139846, "src/Rosetta/font/fon/init.luau"], -[140129, "src/Rosetta/font/hershey/init.luau"], -[140324, "src/Rosetta/font/pcf/init.luau"], -[140604, "src/Rosetta/font/psf/init.luau"], -[140924, "src/Rosetta/font/ttf/init.luau"], -[140975, "src/Rosetta/font/type1/init.luau"], -[141334, "src/Rosetta/font/type1/Charstring.luau"], -[141612, "src/Rosetta/font/woff/init.luau"], -[141744, "src/Rosetta/font/woff2/init.luau"], -[141801, "src/Rosetta/font/woff2/Rebuild.luau"], -[142341, "src/Rosetta/host/init.luau"], -[142386, "src/Rosetta/host/Love.luau"], -[142529, "src/Rosetta/host/LuaJIT.luau"], -[142579, "src/Rosetta/host/Luau.luau"], -[142602, "src/Rosetta/host/Roblox.luau"], -[142961, "src/Rosetta/image/ani/init.luau"], -[143141, "src/Rosetta/image/art/init.luau"], -[143629, "src/Rosetta/image/blp/init.luau"], -[143887, "src/Rosetta/image/bmp/init.luau"], -[144302, "src/Rosetta/image/dds/init.luau"], -[144785, "src/Rosetta/image/exr/init.luau"], -[145545, "src/Rosetta/image/exr/Codec.luau"], -[145656, "src/Rosetta/image/exr/Piz.luau"], -[146013, "src/Rosetta/image/gif/init.luau"], -[146529, "src/Rosetta/image/gif/Decode.luau"], -[146605, "src/Rosetta/image/hdr/init.luau"], -[146834, "src/Rosetta/image/hdr/Codec.luau"], -[147045, "src/Rosetta/image/icns/init.luau"], -[147376, "src/Rosetta/image/ico/init.luau"], -[147653, "src/Rosetta/image/ico/Dib.luau"], -[147748, "src/Rosetta/image/ilbm/init.luau"], -[148067, "src/Rosetta/image/jpeg/init.luau"], -[148226, "src/Rosetta/image/ktx/init.luau"], -[148886, "src/Rosetta/image/lmp/init.luau"], -[149019, "src/Rosetta/image/pcx/init.luau"], -[149283, "src/Rosetta/image/png/init.luau"], -[149918, "src/Rosetta/image/png/Apng.luau"], -[149998, "src/Rosetta/image/png/Decode.luau"], -[150543, "src/Rosetta/image/png/Encode.luau"], -[150746, "src/Rosetta/image/pnm/init.luau"], -[151124, "src/Rosetta/image/pnm/Codec.luau"], -[151401, "src/Rosetta/image/qoi/init.luau"], -[151523, "src/Rosetta/image/qoi/Codec.luau"], -[151680, "src/Rosetta/image/sgi/init.luau"], -[151965, "src/Rosetta/image/spr/init.luau"], -[152278, "src/Rosetta/image/sunras/init.luau"], -[152524, "src/Rosetta/image/tga/init.luau"], -[152794, "src/Rosetta/image/tga/Codec.luau"], -[152994, "src/Rosetta/image/tiff/init.luau"], -[153821, "src/Rosetta/image/tiff/Pixels.luau"], -[154211, "src/Rosetta/image/tim/init.luau"], -[154453, "src/Rosetta/image/vtf/init.luau"], -[154688, "src/Rosetta/image/webp/init.luau"], -[155298, "src/Rosetta/image/webp/Alpha.luau"], -[155374, "src/Rosetta/image/webp/Anim.luau"], -[155529, "src/Rosetta/image/xbm/init.luau"], -[155690, "src/Rosetta/image/xpm/init.luau"], -[155958, "src/Rosetta/image/xpm/Names.luau"], -[156014, "src/Rosetta/layered/aseprite/init.luau"], -[156752, "src/Rosetta/layered/ora/init.luau"], -[157039, "src/Rosetta/layered/psd/init.luau"], -[157774, "src/Rosetta/layered/psd/Channels.luau"], -[158126, "src/Rosetta/model/3ds/init.luau"], -[158209, "src/Rosetta/model/3ds/Build.luau"], -[158856, "src/Rosetta/model/3ds/Read.luau"], -[159352, "src/Rosetta/model/3ds/Write.luau"], -[160157, "src/Rosetta/model/3mf/init.luau"], -[160239, "src/Rosetta/model/3mf/Read.luau"], -[160827, "src/Rosetta/model/3mf/Write.luau"], -[161232, "src/Rosetta/model/ase/init.luau"], -[161355, "src/Rosetta/model/ase/Build.luau"], -[161929, "src/Rosetta/model/ase/Parse.luau"], -[161998, "src/Rosetta/model/ase/Write.luau"], -[162461, "src/Rosetta/model/b3d/init.luau"], -[162516, "src/Rosetta/model/b3d/Read.luau"], -[163087, "src/Rosetta/model/blend/init.luau"], -[163187, "src/Rosetta/model/blend/Anim.luau"], -[163717, "src/Rosetta/model/blend/Armature.luau"], -[164253, "src/Rosetta/model/blend/Driver.luau"], -[164428, "src/Rosetta/model/blend/Material.luau"], -[164780, "src/Rosetta/model/blend/Mesh.luau"], -[165468, "src/Rosetta/model/blend/Normals.luau"], -[165629, "src/Rosetta/model/blend/Prim.luau"], -[166136, "src/Rosetta/model/blend/Read.luau"], -[167224, "src/Rosetta/model/bsp/init.luau"], -[167415, "src/Rosetta/model/bsp/Lightmap.luau"], -[167481, "src/Rosetta/model/bsp/Quake.luau"], -[167870, "src/Rosetta/model/bsp/Quake3.luau"], -[168099, "src/Rosetta/model/bsp/Tree.luau"], -[168487, "src/Rosetta/model/buildmap/init.luau"], -[168759, "src/Rosetta/model/buildmap/Geometry.luau"], -[169162, "src/Rosetta/model/d3map/init.luau"], -[169444, "src/Rosetta/model/d3map/Parse.luau"], -[169642, "src/Rosetta/model/dae/init.luau"], -[169831, "src/Rosetta/model/dae/Math.luau"], -[169878, "src/Rosetta/model/dae/Read.luau"], -[171728, "src/Rosetta/model/dae/Write.luau"], -[172097, "src/Rosetta/model/fbx/init.luau"], -[172245, "src/Rosetta/model/fbx/Ascii.luau"], -[172515, "src/Rosetta/model/fbx/Binary.luau"], -[172970, "src/Rosetta/model/fbx/Read.luau"], -[174332, "src/Rosetta/model/fbx/Write.luau"], -[175317, "src/Rosetta/model/fbx/Xform.luau"], -[175358, "src/Rosetta/model/gltf/init.luau"], -[175595, "src/Rosetta/model/gltf/Pack.luau"], -[175664, "src/Rosetta/model/gltf/Read.luau"], -[176405, "src/Rosetta/model/gltf/Write.luau"], -[177091, "src/Rosetta/model/godot/init.luau"], -[177182, "src/Rosetta/model/godot/Build.luau"], -[177724, "src/Rosetta/model/godot/Primitives.luau"], -[177999, "src/Rosetta/model/godot/Surface.luau"], -[178484, "src/Rosetta/model/godot/Write.luau"], -[178813, "src/Rosetta/model/iqm/init.luau"], -[178889, "src/Rosetta/model/iqm/Read.luau"], -[179244, "src/Rosetta/model/iqm/Write.luau"], -[179931, "src/Rosetta/model/ldraw/init.luau"], -[180009, "src/Rosetta/model/ldraw/Colors.luau"], -[180327, "src/Rosetta/model/ldraw/Read.luau"], -[180904, "src/Rosetta/model/lwo/init.luau"], -[180980, "src/Rosetta/model/lwo/Build.luau"], -[181442, "src/Rosetta/model/lwo/Parse.luau"], -[181985, "src/Rosetta/model/map/init.luau"], -[182302, "src/Rosetta/model/map/Build.luau"], -[182546, "src/Rosetta/model/map/Parse.luau"], -[182931, "src/Rosetta/model/map/Write.luau"], -[183077, "src/Rosetta/model/mca/init.luau"], -[183419, "src/Rosetta/model/mca/Chunk.luau"], -[183552, "src/Rosetta/model/mca/Lz4Block.luau"], -[183622, "src/Rosetta/model/md2/init.luau"], -[183821, "src/Rosetta/model/md3/init.luau"], -[184049, "src/Rosetta/model/md5/init.luau"], -[184130, "src/Rosetta/model/md5/Read.luau"], -[184563, "src/Rosetta/model/mdl/init.luau"], -[184645, "src/Rosetta/model/mdl/HalfLife.luau"], -[184949, "src/Rosetta/model/mdl/Quake.luau"], -[185167, "src/Rosetta/model/ms3d/init.luau"], -[185239, "src/Rosetta/model/ms3d/Read.luau"], -[185685, "src/Rosetta/model/ms3d/Write.luau"], -[186154, "src/Rosetta/model/obj/init.luau"], -[186972, "src/Rosetta/model/obj/Mtl.luau"], -[187260, "src/Rosetta/model/off/init.luau"], -[187722, "src/Rosetta/model/ply/init.luau"], -[188827, "src/Rosetta/model/ply/Binary.luau"], -[189028, "src/Rosetta/model/pmx/init.luau"], -[189097, "src/Rosetta/model/pmx/Build.luau"], -[189393, "src/Rosetta/model/pmx/Pmd.luau"], -[189728, "src/Rosetta/model/pmx/Read.luau"], -[190132, "src/Rosetta/model/proc/init.luau"], -[190514, "src/Rosetta/model/qb/init.luau"], -[190907, "src/Rosetta/model/rbxm/init.luau"], -[191500, "src/Rosetta/model/rbxmx/init.luau"], -[192176, "src/Rosetta/model/robloxmesh/init.luau"], -[192835, "src/Rosetta/model/robloxmesh/Parse.luau"], -[193292, "src/Rosetta/model/robloxmesh/Write.luau"], -[193401, "src/Rosetta/model/schematic/init.luau"], -[193722, "src/Rosetta/model/schematic/Common.luau"], -[193842, "src/Rosetta/model/schematic/Litematic.luau"], -[194053, "src/Rosetta/model/schematic/Mcedit.luau"], -[194297, "src/Rosetta/model/schematic/Sponge.luau"], -[194426, "src/Rosetta/model/smd/init.luau"], -[194493, "src/Rosetta/model/smd/Read.luau"], -[194762, "src/Rosetta/model/smd/Write.luau"], -[195005, "src/Rosetta/model/sourcemdl/init.luau"], -[195176, "src/Rosetta/model/sourcemdl/Build.luau"], -[195606, "src/Rosetta/model/sourcemdl/Material.luau"], -[195767, "src/Rosetta/model/sourcemdl/Mdl.luau"], -[196294, "src/Rosetta/model/sourcemdl/Phy.luau"], -[196417, "src/Rosetta/model/sourcemdl/Vtx.luau"], -[196599, "src/Rosetta/model/sourcemdl/Vvd.luau"], -[196693, "src/Rosetta/model/stl/init.luau"], -[197143, "src/Rosetta/model/stl/Decode.luau"], -[197217, "src/Rosetta/model/t3d/init.luau"], -[197311, "src/Rosetta/model/t3d/Build.luau"], -[197716, "src/Rosetta/model/t3d/Parse.luau"], -[197884, "src/Rosetta/model/udmf/init.luau"], -[197967, "src/Rosetta/model/usda/init.luau"], -[198176, "src/Rosetta/model/usda/Build.luau"], -[199454, "src/Rosetta/model/usda/Parse.luau"], -[200252, "src/Rosetta/model/usda/Write.luau"], -[201069, "src/Rosetta/model/vbsp/init.luau"], -[201515, "src/Rosetta/model/vbsp/Faces.luau"], -[201739, "src/Rosetta/model/vbsp/Props.luau"], -[201831, "src/Rosetta/model/vmf/init.luau"], -[202156, "src/Rosetta/model/vmf/Build.luau"], -[202580, "src/Rosetta/model/vox/init.luau"], -[203466, "src/Rosetta/model/vox/Grid.luau"], -[203523, "src/Rosetta/model/vrml/init.luau"], -[203589, "src/Rosetta/model/x/init.luau"], -[203719, "src/Rosetta/model/x/Build.luau"], -[204282, "src/Rosetta/model/x/Parse.luau"], -[204579, "src/Rosetta/model/x3d/init.luau"], -[204657, "src/Rosetta/music/669/init.luau"], -[204864, "src/Rosetta/music/ahx/init.luau"], -[204916, "src/Rosetta/music/far/init.luau"], -[205146, "src/Rosetta/music/hmp/init.luau"], -[205411, "src/Rosetta/music/hvl/init.luau"], -[205463, "src/Rosetta/music/it/init.luau"], -[205882, "src/Rosetta/music/it/Itsex.luau"], -[205999, "src/Rosetta/music/med/init.luau"], -[206647, "src/Rosetta/music/midi/init.luau"], -[206791, "src/Rosetta/music/midi/Smf.luau"], -[207203, "src/Rosetta/music/mod/init.luau"], -[207557, "src/Rosetta/music/mtm/init.luau"], -[207780, "src/Rosetta/music/mus/init.luau"], -[207938, "src/Rosetta/music/okt/init.luau"], -[208220, "src/Rosetta/music/ptm/init.luau"], -[208443, "src/Rosetta/music/s3m/init.luau"], -[208680, "src/Rosetta/music/sf2/init.luau"], -[208724, "src/Rosetta/music/stm/init.luau"], -[208956, "src/Rosetta/music/ult/init.luau"], -[209261, "src/Rosetta/music/umx/init.luau"], -[209478, "src/Rosetta/music/xm/init.luau"], -[210040, "src/Rosetta/music/xmi/init.luau"], -[210249, "src/Rosetta/ops/AudioOps.luau"], -[210728, "src/Rosetta/ops/ImageOps/init.luau"], -[211376, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[212016, "src/Rosetta/ops/LayerOps.luau"], -[212109, "src/Rosetta/ops/MeshOps/init.luau"], -[213249, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[213416, "src/Rosetta/ops/MusicOps.luau"], -[213765, "src/Rosetta/playlist/m3u/init.luau"], -[214118, "src/Rosetta/playlist/pls/init.luau"], -[214296, "src/Rosetta/playlist/xspf/init.luau"], -[214499, "src/Rosetta/subtitle/ass/init.luau"], -[214943, "src/Rosetta/subtitle/srt/init.luau"], -[215116, "src/Rosetta/subtitle/vtt/init.luau"], -[215319, "src/Rosetta/vector/gamemaps/init.luau"], -[215506, "src/Rosetta/vector/gamemaps/Expand.luau"], -[215603, "src/Rosetta/vector/ldtk/init.luau"], -[215695, "src/Rosetta/vector/ldtk/Read.luau"], -[216031, "src/Rosetta/vector/ldtk/Write.luau"], -[216679, "src/Rosetta/vector/ogmo/init.luau"], -[216798, "src/Rosetta/vector/ogmo/Read.luau"], -[217203, "src/Rosetta/vector/ogmo/Write.luau"], -[217557, "src/Rosetta/vector/svg/init.luau"], -[217643, "src/Rosetta/vector/svg/Parse.luau"], -[218389, "src/Rosetta/vector/svg/PathData.luau"], -[218757, "src/Rosetta/vector/svg/Render.luau"], -[219174, "src/Rosetta/vector/svg/Style.luau"], -[219546, "src/Rosetta/vector/svg/Write.luau"], -[219746, "src/Rosetta/vector/tiled/init.luau"], -[219926, "src/Rosetta/vector/tiled/Data.luau"], -[220077, "src/Rosetta/vector/tiled/Tmj.luau"], -[220708, "src/Rosetta/vector/tiled/Tmx.luau"], -[221320, "src/Rosetta/video/avi/init.luau"], -[221614, "src/Rosetta/video/fli/init.luau"], -[221765, "src/Rosetta/video/flv/init.luau"], -[222149, "src/Rosetta/video/flv/Amf.luau"], -[222307, "src/Rosetta/video/flv/Mux.luau"], -[222588, "src/Rosetta/video/h264/init.luau"], -[222727, "src/Rosetta/video/mkv/init.luau"], -[222883, "src/Rosetta/video/mkv/Mux.luau"], -[223162, "src/Rosetta/video/mkv/Parse.luau"], -[223883, "src/Rosetta/video/mp4/init.luau"], -[224211, "src/Rosetta/video/mpegps/init.luau"], -[224398, "src/Rosetta/video/mpegts/init.luau"], -[224644, "src/Rosetta/video/ogv/init.luau"], -[225039, "src/Rosetta/video/smk/init.luau"], -[225348, "src/Rosetta/video/smk/Audio.luau"], -[225468, "src/Rosetta/video/y4m/init.luau"] +[962, "src/Rosetta/Registry.luau"], +[3579, "src/Rosetta/Sniffs.luau"], +[7810, "src/Rosetta/Types.luau"], +[8927, "src/Rosetta/archive/7z/init.luau"], +[9312, "src/Rosetta/archive/7z/Header.luau"], +[9839, "src/Rosetta/archive/adf/init.luau"], +[10121, "src/Rosetta/archive/applesingle/init.luau"], +[10307, "src/Rosetta/archive/ar/init.luau"], +[10710, "src/Rosetta/archive/arj/init.luau"], +[10920, "src/Rosetta/archive/binhex/init.luau"], +[11169, "src/Rosetta/archive/br/init.luau"], +[11244, "src/Rosetta/archive/bz2/init.luau"], +[11308, "src/Rosetta/archive/cab/init.luau"], +[11721, "src/Rosetta/archive/cab/Sum.luau"], +[11762, "src/Rosetta/archive/cpio/init.luau"], +[11930, "src/Rosetta/archive/d64/init.luau"], +[12344, "src/Rosetta/archive/fat/init.luau"], +[12466, "src/Rosetta/archive/grp/init.luau"], +[12580, "src/Rosetta/archive/gzip/init.luau"], +[12765, "src/Rosetta/archive/iso/init.luau"], +[12837, "src/Rosetta/archive/lha/init.luau"], +[13262, "src/Rosetta/archive/lz4/init.luau"], +[13606, "src/Rosetta/archive/macbinary/init.luau"], +[13804, "src/Rosetta/archive/mpq/init.luau"], +[14210, "src/Rosetta/archive/mpq/Crypt.luau"], +[14275, "src/Rosetta/archive/pak/init.luau"], +[14409, "src/Rosetta/archive/rpm/init.luau"], +[14733, "src/Rosetta/archive/tar/init.luau"], +[14851, "src/Rosetta/archive/unitypackage/init.luau"], +[15087, "src/Rosetta/archive/uu/init.luau"], +[15357, "src/Rosetta/archive/vpk/init.luau"], +[15668, "src/Rosetta/archive/vswap/init.luau"], +[15938, "src/Rosetta/archive/wad/init.luau"], +[16392, "src/Rosetta/archive/wad/Picture.luau"], +[16494, "src/Rosetta/archive/wad2/init.luau"], +[16776, "src/Rosetta/archive/xz/init.luau"], +[16876, "src/Rosetta/archive/yenc/init.luau"], +[17148, "src/Rosetta/archive/z/init.luau"], +[17244, "src/Rosetta/archive/zip/init.luau"], +[17463, "src/Rosetta/archive/zoo/init.luau"], +[17659, "src/Rosetta/archive/zst/init.luau"], +[17723, "src/Rosetta/audio/aac/init.luau"], +[17936, "src/Rosetta/audio/ac3/init.luau"], +[18083, "src/Rosetta/audio/adpcm/init.luau"], +[18229, "src/Rosetta/audio/adx/init.luau"], +[18461, "src/Rosetta/audio/aiff/init.luau"], +[18853, "src/Rosetta/audio/ape/init.luau"], +[18982, "src/Rosetta/audio/au/init.luau"], +[19144, "src/Rosetta/audio/brstm/init.luau"], +[19436, "src/Rosetta/audio/caf/init.luau"], +[20103, "src/Rosetta/audio/flac/init.luau"], +[20252, "src/Rosetta/audio/flac/Meta.luau"], +[20474, "src/Rosetta/audio/flac/Stream.luau"], +[20844, "src/Rosetta/audio/m4a/init.luau"], +[21187, "src/Rosetta/audio/mp3/init.luau"], +[21448, "src/Rosetta/audio/mp3/Index.luau"], +[21639, "src/Rosetta/audio/mp3/Stream.luau"], +[21866, "src/Rosetta/audio/mp3/Tags.luau"], +[22178, "src/Rosetta/audio/mpc/init.luau"], +[22273, "src/Rosetta/audio/opus/init.luau"], +[22652, "src/Rosetta/audio/opus/Encode.luau"], +[22764, "src/Rosetta/audio/qoa/init.luau"], +[22945, "src/Rosetta/audio/tta/init.luau"], +[23064, "src/Rosetta/audio/vag/init.luau"], +[23288, "src/Rosetta/audio/voc/init.luau"], +[23564, "src/Rosetta/audio/vorbis/init.luau"], +[24019, "src/Rosetta/audio/vorbis/Encode.luau"], +[24832, "src/Rosetta/audio/wav/init.luau"], +[25453, "src/Rosetta/audio/wav/Codecs.luau"], +[25632, "src/Rosetta/audio/wavpack/init.luau"], +[25840, "src/Rosetta/cad/step/init.luau"], +[26222, "src/Rosetta/cad/step/Brep.luau"], +[26457, "src/Rosetta/cad/step/Parse.luau"], +[27014, "src/Rosetta/cad/step/Write.luau"], +[27262, "src/Rosetta/codecs/audio/Aac/init.luau"], +[27670, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[28646, "src/Rosetta/codecs/audio/Aac/Ps.luau"], +[29236, "src/Rosetta/codecs/audio/Aac/Sbr.luau"], +[30303, "src/Rosetta/codecs/audio/Aac/SbrBits.luau"], +[30422, "src/Rosetta/codecs/audio/Aac/SbrDct.luau"], +[31664, "src/Rosetta/codecs/audio/Aac/SbrHf.luau"], +[32156, "src/Rosetta/codecs/audio/Aac/SbrQmf.luau"], +[32273, "src/Rosetta/codecs/audio/Aac/SbrTables.luau"], +[32686, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[33022, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[33182, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[34067, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[34169, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[34923, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[35226, "src/Rosetta/codecs/audio/Alac/init.luau"], +[35461, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[35880, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[36292, "src/Rosetta/codecs/audio/Ape/init.luau"], +[36508, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[37269, "src/Rosetta/codecs/audio/ApeTag.luau"], +[37367, "src/Rosetta/codecs/audio/Flac/init.luau"], +[37379, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[38328, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[38948, "src/Rosetta/codecs/audio/Hively/init.luau"], +[39145, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[39395, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[40354, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[40574, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[40794, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[41048, "src/Rosetta/codecs/audio/MidiRender.luau"], +[41395, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[41410, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[41469, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[43127, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[43420, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[43805, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[44446, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[44587, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[44814, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[45160, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[46054, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[46433, "src/Rosetta/codecs/audio/Opus/init.luau"], +[46448, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[48320, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[49385, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[49446, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[49910, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[50261, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[50494, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[52536, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[52910, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[53174, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[53471, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[53753, "src/Rosetta/codecs/audio/Resample/init.luau"], +[54148, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[54203, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[54347, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[54861, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[55660, "src/Rosetta/codecs/audio/Stream.luau"], +[55822, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[56305, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[56584, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[56831, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[56960, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[58949, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[59066, "src/Rosetta/codecs/audio/Tta/init.luau"], +[59184, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[59436, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[59450, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[59834, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[60407, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[60829, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[60869, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[60922, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[61145, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[62600, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[62663, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[62762, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[63746, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[64614, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[64658, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[65171, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[65584, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[66066, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[66587, "src/Rosetta/codecs/compress/Explode.luau"], +[66783, "src/Rosetta/codecs/compress/Lz4.luau"], +[67052, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[67656, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[68196, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[68263, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[68736, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[68912, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[69180, "src/Rosetta/codecs/compress/Lzx.luau"], +[69614, "src/Rosetta/codecs/compress/PackBits.luau"], +[69704, "src/Rosetta/codecs/compress/Quantum.luau"], +[69941, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[70245, "src/Rosetta/codecs/compress/Xxh32.luau"], +[70314, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[70371, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[71355, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[71507, "src/Rosetta/codecs/entropy/Huffman.luau"], +[71794, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[71805, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[72026, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[72270, "src/Rosetta/codecs/font/Bitmap.luau"], +[72471, "src/Rosetta/codecs/font/Cff/init.luau"], +[73112, "src/Rosetta/codecs/font/GlyphNames.luau"], +[73262, "src/Rosetta/codecs/font/TrueType/init.luau"], +[73576, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[73968, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[74470, "src/Rosetta/codecs/image/Bcn/init.luau"], +[74577, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[75061, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[75490, "src/Rosetta/codecs/image/Blend.luau"], +[75869, "src/Rosetta/codecs/image/Dct/init.luau"], +[76364, "src/Rosetta/codecs/image/Etc.luau"], +[76662, "src/Rosetta/codecs/image/Half.luau"], +[76731, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[77085, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[77493, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[77858, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[78623, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[79504, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[79981, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[80059, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[80126, "src/Rosetta/codecs/image/Miptex.luau"], +[80426, "src/Rosetta/codecs/image/Pixels.luau"], +[80746, "src/Rosetta/codecs/image/Quantize/init.luau"], +[81207, "src/Rosetta/codecs/image/Raster.luau"], +[81904, "src/Rosetta/codecs/image/Texel.luau"], +[82277, "src/Rosetta/codecs/image/Texture.luau"], +[82422, "src/Rosetta/codecs/image/Vp8/init.luau"], +[82564, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[84544, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[84807, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[85057, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[85199, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[85303, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[86243, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[87195, "src/Rosetta/codecs/image/Yuv.luau"], +[87516, "src/Rosetta/codecs/model/Brush.luau"], +[88156, "src/Rosetta/codecs/model/Displacement.luau"], +[88305, "src/Rosetta/codecs/model/DoomMap/init.luau"], +[88750, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], +[89000, "src/Rosetta/codecs/model/Draco/init.luau"], +[89332, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[89801, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[90990, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[91139, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[91498, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[92460, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[92934, "src/Rosetta/codecs/model/Mat4.luau"], +[93193, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[93721, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[94273, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[94352, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[94459, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[94665, "src/Rosetta/codecs/model/Patch.luau"], +[94789, "src/Rosetta/codecs/model/Polygon.luau"], +[95023, "src/Rosetta/codecs/model/Rbx/init.luau"], +[95260, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[96014, "src/Rosetta/codecs/model/Rig.luau"], +[96257, "src/Rosetta/codecs/model/Sampler.luau"], +[96417, "src/Rosetta/codecs/model/SourceAnim.luau"], +[96638, "src/Rosetta/codecs/model/Vrml/init.luau"], +[96786, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[97360, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[97523, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[98272, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[98794, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[99521, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[99753, "src/Rosetta/codecs/text/GodotVariant.luau"], +[100412, "src/Rosetta/codecs/text/Json/init.luau"], +[100681, "src/Rosetta/codecs/text/Json/Decode.luau"], +[101116, "src/Rosetta/codecs/text/Json/Encode.luau"], +[101461, "src/Rosetta/codecs/text/KeyValues/init.luau"], +[102031, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], +[102337, "src/Rosetta/codecs/text/Lexer/init.luau"], +[102469, "src/Rosetta/codecs/text/Nbt/init.luau"], +[102822, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[103514, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[104154, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[104392, "src/Rosetta/codecs/text/Text/init.luau"], +[104483, "src/Rosetta/codecs/text/Url/init.luau"], +[104688, "src/Rosetta/codecs/text/Xml/init.luau"], +[105138, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[105942, "src/Rosetta/codecs/video/Dsp.luau"], +[106780, "src/Rosetta/codecs/video/H263/init.luau"], +[106937, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[107795, "src/Rosetta/codecs/video/H263/Tables.luau"], +[107999, "src/Rosetta/codecs/video/H264/init.luau"], +[108389, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[108664, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[109795, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[110563, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[110825, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[111891, "src/Rosetta/codecs/video/H264/Inter.luau"], +[112217, "src/Rosetta/codecs/video/H264/Intra.luau"], +[112624, "src/Rosetta/codecs/video/H264/Mb.luau"], +[113578, "src/Rosetta/codecs/video/H264/Params.luau"], +[114026, "src/Rosetta/codecs/video/H264/Slice.luau"], +[114278, "src/Rosetta/codecs/video/H264/Tables.luau"], +[114320, "src/Rosetta/codecs/video/H264/Transform.luau"], +[114485, "src/Rosetta/codecs/video/Legacy/init.luau"], +[114684, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[114981, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[115348, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[115466, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[115574, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[115847, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[116242, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[116419, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[116432, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[116806, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[118333, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[118473, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[118612, "src/Rosetta/codecs/video/Theora/init.luau"], +[118876, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[120140, "src/Rosetta/codecs/video/Theora/Header.luau"], +[120504, "src/Rosetta/codecs/video/Video/init.luau"], +[121119, "src/Rosetta/codecs/video/Video/Disposable.luau"], +[121330, "src/Rosetta/codecs/video/Video/Pool.luau"], +[121382, "src/Rosetta/codecs/video/Video/Source.luau"], +[121668, "src/Rosetta/containers/Archive.luau"], +[121935, "src/Rosetta/containers/AudioWrap.luau"], +[122445, "src/Rosetta/containers/Avi/init.luau"], +[122998, "src/Rosetta/containers/Blend.luau"], +[123737, "src/Rosetta/containers/Chunks.luau"], +[123872, "src/Rosetta/containers/Cpio.luau"], +[124300, "src/Rosetta/containers/Demux.luau"], +[124586, "src/Rosetta/containers/Ebml/init.luau"], +[124900, "src/Rosetta/containers/Fat.luau"], +[125588, "src/Rosetta/containers/Iso9660.luau"], +[126093, "src/Rosetta/containers/IsoBmff/init.luau"], +[126264, "src/Rosetta/containers/IsoBmff/Box.luau"], +[126453, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[127299, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[127821, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[128338, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[128456, "src/Rosetta/containers/MacFile.luau"], +[128605, "src/Rosetta/containers/MpegEs.luau"], +[128772, "src/Rosetta/containers/MpegPs/init.luau"], +[128993, "src/Rosetta/containers/MpegTs/init.luau"], +[129786, "src/Rosetta/containers/Ogg/init.luau"], +[130211, "src/Rosetta/containers/Ogg/Mux.luau"], +[130400, "src/Rosetta/containers/Ogg/Page.luau"], +[130566, "src/Rosetta/containers/Riff/init.luau"], +[130883, "src/Rosetta/containers/Tar.luau"], +[131297, "src/Rosetta/containers/Zip/init.luau"], +[131929, "src/Rosetta/core/Adler32.luau"], +[131989, "src/Rosetta/core/Base64.luau"], +[132217, "src/Rosetta/core/Bits.luau"], +[132510, "src/Rosetta/core/Bytes.luau"], +[133037, "src/Rosetta/core/Crc16.luau"], +[133089, "src/Rosetta/core/Crc32.luau"], +[133240, "src/Rosetta/core/Err.luau"], +[133322, "src/Rosetta/core/Input.luau"], +[133398, "src/Rosetta/core/Md5.luau"], +[133556, "src/Rosetta/core/Sniff.luau"], +[133585, "src/Rosetta/data/cbor/init.luau"], +[133684, "src/Rosetta/data/cbor/Codec.luau"], +[134253, "src/Rosetta/data/csv/init.luau"], +[134565, "src/Rosetta/data/ini/init.luau"], +[134811, "src/Rosetta/data/json/init.luau"], +[134903, "src/Rosetta/data/msgpack/init.luau"], +[134992, "src/Rosetta/data/msgpack/Codec.luau"], +[135434, "src/Rosetta/data/nbt/init.luau"], +[135493, "src/Rosetta/data/plist/init.luau"], +[135799, "src/Rosetta/data/plist/Binary.luau"], +[136066, "src/Rosetta/data/q3shader/init.luau"], +[136305, "src/Rosetta/data/q3skin/init.luau"], +[136401, "src/Rosetta/data/snbt/init.luau"], +[136464, "src/Rosetta/data/toml/init.luau"], +[136531, "src/Rosetta/data/toml/Decode.luau"], +[137159, "src/Rosetta/data/toml/Encode.luau"], +[137368, "src/Rosetta/data/tres/init.luau"], +[137513, "src/Rosetta/data/vdf/init.luau"], +[137614, "src/Rosetta/data/xml/init.luau"], +[137670, "src/Rosetta/data/yaml/init.luau"], +[137743, "src/Rosetta/data/yaml/Emit.luau"], +[138033, "src/Rosetta/data/yaml/Parse.luau"], +[139326, "src/Rosetta/font/bdf/init.luau"], +[139615, "src/Rosetta/font/bmfont/init.luau"], +[140042, "src/Rosetta/font/bmfont/Parse.luau"], +[140495, "src/Rosetta/font/eot/init.luau"], +[140727, "src/Rosetta/font/fon/init.luau"], +[141010, "src/Rosetta/font/hershey/init.luau"], +[141205, "src/Rosetta/font/pcf/init.luau"], +[141485, "src/Rosetta/font/psf/init.luau"], +[141805, "src/Rosetta/font/ttf/init.luau"], +[141856, "src/Rosetta/font/type1/init.luau"], +[142215, "src/Rosetta/font/type1/Charstring.luau"], +[142493, "src/Rosetta/font/woff/init.luau"], +[142625, "src/Rosetta/font/woff2/init.luau"], +[142682, "src/Rosetta/font/woff2/Rebuild.luau"], +[143222, "src/Rosetta/host/init.luau"], +[143267, "src/Rosetta/host/Love.luau"], +[143410, "src/Rosetta/host/LuaJIT.luau"], +[143460, "src/Rosetta/host/Luau.luau"], +[143483, "src/Rosetta/host/Roblox.luau"], +[143842, "src/Rosetta/image/ani/init.luau"], +[144022, "src/Rosetta/image/art/init.luau"], +[144510, "src/Rosetta/image/blp/init.luau"], +[144768, "src/Rosetta/image/bmp/init.luau"], +[145183, "src/Rosetta/image/dds/init.luau"], +[145666, "src/Rosetta/image/exr/init.luau"], +[146426, "src/Rosetta/image/exr/Codec.luau"], +[146537, "src/Rosetta/image/exr/Piz.luau"], +[146894, "src/Rosetta/image/gif/init.luau"], +[147410, "src/Rosetta/image/gif/Decode.luau"], +[147486, "src/Rosetta/image/hdr/init.luau"], +[147715, "src/Rosetta/image/hdr/Codec.luau"], +[147926, "src/Rosetta/image/icns/init.luau"], +[148257, "src/Rosetta/image/ico/init.luau"], +[148534, "src/Rosetta/image/ico/Dib.luau"], +[148629, "src/Rosetta/image/ilbm/init.luau"], +[148948, "src/Rosetta/image/jpeg/init.luau"], +[149107, "src/Rosetta/image/ktx/init.luau"], +[149767, "src/Rosetta/image/lmp/init.luau"], +[149900, "src/Rosetta/image/pcx/init.luau"], +[150164, "src/Rosetta/image/png/init.luau"], +[150799, "src/Rosetta/image/png/Apng.luau"], +[150879, "src/Rosetta/image/png/Decode.luau"], +[151424, "src/Rosetta/image/png/Encode.luau"], +[151627, "src/Rosetta/image/pnm/init.luau"], +[152005, "src/Rosetta/image/pnm/Codec.luau"], +[152282, "src/Rosetta/image/qoi/init.luau"], +[152404, "src/Rosetta/image/qoi/Codec.luau"], +[152561, "src/Rosetta/image/sgi/init.luau"], +[152846, "src/Rosetta/image/spr/init.luau"], +[153159, "src/Rosetta/image/sunras/init.luau"], +[153405, "src/Rosetta/image/tga/init.luau"], +[153675, "src/Rosetta/image/tga/Codec.luau"], +[153875, "src/Rosetta/image/tiff/init.luau"], +[154702, "src/Rosetta/image/tiff/Pixels.luau"], +[155092, "src/Rosetta/image/tim/init.luau"], +[155334, "src/Rosetta/image/vtf/init.luau"], +[155569, "src/Rosetta/image/webp/init.luau"], +[156179, "src/Rosetta/image/webp/Alpha.luau"], +[156255, "src/Rosetta/image/webp/Anim.luau"], +[156410, "src/Rosetta/image/xbm/init.luau"], +[156571, "src/Rosetta/image/xpm/init.luau"], +[156839, "src/Rosetta/image/xpm/Names.luau"], +[156895, "src/Rosetta/layered/aseprite/init.luau"], +[157633, "src/Rosetta/layered/ora/init.luau"], +[157920, "src/Rosetta/layered/psd/init.luau"], +[158655, "src/Rosetta/layered/psd/Channels.luau"], +[159007, "src/Rosetta/model/3ds/init.luau"], +[159090, "src/Rosetta/model/3ds/Build.luau"], +[159737, "src/Rosetta/model/3ds/Read.luau"], +[160233, "src/Rosetta/model/3ds/Write.luau"], +[161038, "src/Rosetta/model/3mf/init.luau"], +[161120, "src/Rosetta/model/3mf/Read.luau"], +[161708, "src/Rosetta/model/3mf/Write.luau"], +[162113, "src/Rosetta/model/ase/init.luau"], +[162236, "src/Rosetta/model/ase/Build.luau"], +[162810, "src/Rosetta/model/ase/Parse.luau"], +[162879, "src/Rosetta/model/ase/Write.luau"], +[163342, "src/Rosetta/model/b3d/init.luau"], +[163397, "src/Rosetta/model/b3d/Read.luau"], +[163968, "src/Rosetta/model/blend/init.luau"], +[164068, "src/Rosetta/model/blend/Anim.luau"], +[164598, "src/Rosetta/model/blend/Armature.luau"], +[165134, "src/Rosetta/model/blend/Driver.luau"], +[165309, "src/Rosetta/model/blend/Material.luau"], +[165661, "src/Rosetta/model/blend/Mesh.luau"], +[166349, "src/Rosetta/model/blend/Normals.luau"], +[166510, "src/Rosetta/model/blend/Prim.luau"], +[167017, "src/Rosetta/model/blend/Read.luau"], +[168105, "src/Rosetta/model/bsp/init.luau"], +[168296, "src/Rosetta/model/bsp/Lightmap.luau"], +[168362, "src/Rosetta/model/bsp/Quake.luau"], +[168751, "src/Rosetta/model/bsp/Quake3.luau"], +[168980, "src/Rosetta/model/bsp/Tree.luau"], +[169368, "src/Rosetta/model/buildmap/init.luau"], +[169640, "src/Rosetta/model/buildmap/Geometry.luau"], +[170043, "src/Rosetta/model/d3map/init.luau"], +[170325, "src/Rosetta/model/d3map/Parse.luau"], +[170523, "src/Rosetta/model/dae/init.luau"], +[170712, "src/Rosetta/model/dae/Math.luau"], +[170759, "src/Rosetta/model/dae/Read.luau"], +[172609, "src/Rosetta/model/dae/Write.luau"], +[172978, "src/Rosetta/model/fbx/init.luau"], +[173126, "src/Rosetta/model/fbx/Ascii.luau"], +[173396, "src/Rosetta/model/fbx/Binary.luau"], +[173851, "src/Rosetta/model/fbx/Read.luau"], +[175213, "src/Rosetta/model/fbx/Write.luau"], +[176198, "src/Rosetta/model/fbx/Xform.luau"], +[176239, "src/Rosetta/model/gltf/init.luau"], +[176476, "src/Rosetta/model/gltf/Pack.luau"], +[176545, "src/Rosetta/model/gltf/Read.luau"], +[177286, "src/Rosetta/model/gltf/Write.luau"], +[177972, "src/Rosetta/model/godot/init.luau"], +[178063, "src/Rosetta/model/godot/Build.luau"], +[178605, "src/Rosetta/model/godot/Primitives.luau"], +[178880, "src/Rosetta/model/godot/Surface.luau"], +[179365, "src/Rosetta/model/godot/Write.luau"], +[179694, "src/Rosetta/model/iqm/init.luau"], +[179770, "src/Rosetta/model/iqm/Read.luau"], +[180125, "src/Rosetta/model/iqm/Write.luau"], +[180812, "src/Rosetta/model/ldraw/init.luau"], +[180890, "src/Rosetta/model/ldraw/Colors.luau"], +[181208, "src/Rosetta/model/ldraw/Read.luau"], +[181785, "src/Rosetta/model/lwo/init.luau"], +[181861, "src/Rosetta/model/lwo/Build.luau"], +[182323, "src/Rosetta/model/lwo/Parse.luau"], +[182866, "src/Rosetta/model/map/init.luau"], +[183183, "src/Rosetta/model/map/Build.luau"], +[183427, "src/Rosetta/model/map/Parse.luau"], +[183812, "src/Rosetta/model/map/Write.luau"], +[183958, "src/Rosetta/model/mca/init.luau"], +[184300, "src/Rosetta/model/mca/Chunk.luau"], +[184433, "src/Rosetta/model/mca/Lz4Block.luau"], +[184503, "src/Rosetta/model/md2/init.luau"], +[184702, "src/Rosetta/model/md3/init.luau"], +[184930, "src/Rosetta/model/md5/init.luau"], +[185011, "src/Rosetta/model/md5/Read.luau"], +[185444, "src/Rosetta/model/mdl/init.luau"], +[185526, "src/Rosetta/model/mdl/HalfLife.luau"], +[185830, "src/Rosetta/model/mdl/Quake.luau"], +[186048, "src/Rosetta/model/ms3d/init.luau"], +[186120, "src/Rosetta/model/ms3d/Read.luau"], +[186566, "src/Rosetta/model/ms3d/Write.luau"], +[187035, "src/Rosetta/model/obj/init.luau"], +[187853, "src/Rosetta/model/obj/Mtl.luau"], +[188141, "src/Rosetta/model/off/init.luau"], +[188603, "src/Rosetta/model/ply/init.luau"], +[189708, "src/Rosetta/model/ply/Binary.luau"], +[189909, "src/Rosetta/model/pmx/init.luau"], +[189978, "src/Rosetta/model/pmx/Build.luau"], +[190274, "src/Rosetta/model/pmx/Pmd.luau"], +[190609, "src/Rosetta/model/pmx/Read.luau"], +[191013, "src/Rosetta/model/proc/init.luau"], +[191395, "src/Rosetta/model/qb/init.luau"], +[191788, "src/Rosetta/model/rbxm/init.luau"], +[192381, "src/Rosetta/model/rbxmx/init.luau"], +[193057, "src/Rosetta/model/robloxmesh/init.luau"], +[193716, "src/Rosetta/model/robloxmesh/Parse.luau"], +[194173, "src/Rosetta/model/robloxmesh/Write.luau"], +[194282, "src/Rosetta/model/schematic/init.luau"], +[194603, "src/Rosetta/model/schematic/Common.luau"], +[194723, "src/Rosetta/model/schematic/Litematic.luau"], +[194934, "src/Rosetta/model/schematic/Mcedit.luau"], +[195178, "src/Rosetta/model/schematic/Sponge.luau"], +[195307, "src/Rosetta/model/smd/init.luau"], +[195374, "src/Rosetta/model/smd/Read.luau"], +[195643, "src/Rosetta/model/smd/Write.luau"], +[195886, "src/Rosetta/model/sourcemdl/init.luau"], +[196057, "src/Rosetta/model/sourcemdl/Build.luau"], +[196487, "src/Rosetta/model/sourcemdl/Material.luau"], +[196648, "src/Rosetta/model/sourcemdl/Mdl.luau"], +[197175, "src/Rosetta/model/sourcemdl/Phy.luau"], +[197298, "src/Rosetta/model/sourcemdl/Vtx.luau"], +[197480, "src/Rosetta/model/sourcemdl/Vvd.luau"], +[197574, "src/Rosetta/model/stl/init.luau"], +[198024, "src/Rosetta/model/stl/Decode.luau"], +[198098, "src/Rosetta/model/t3d/init.luau"], +[198192, "src/Rosetta/model/t3d/Build.luau"], +[198597, "src/Rosetta/model/t3d/Parse.luau"], +[198765, "src/Rosetta/model/udmf/init.luau"], +[198848, "src/Rosetta/model/usda/init.luau"], +[199057, "src/Rosetta/model/usda/Build.luau"], +[200335, "src/Rosetta/model/usda/Parse.luau"], +[201133, "src/Rosetta/model/usda/Write.luau"], +[201950, "src/Rosetta/model/vbsp/init.luau"], +[202396, "src/Rosetta/model/vbsp/Faces.luau"], +[202620, "src/Rosetta/model/vbsp/Props.luau"], +[202712, "src/Rosetta/model/vmf/init.luau"], +[203037, "src/Rosetta/model/vmf/Build.luau"], +[203461, "src/Rosetta/model/vox/init.luau"], +[204347, "src/Rosetta/model/vox/Grid.luau"], +[204404, "src/Rosetta/model/vrml/init.luau"], +[204470, "src/Rosetta/model/x/init.luau"], +[204600, "src/Rosetta/model/x/Build.luau"], +[205163, "src/Rosetta/model/x/Parse.luau"], +[205460, "src/Rosetta/model/x3d/init.luau"], +[205538, "src/Rosetta/music/669/init.luau"], +[205745, "src/Rosetta/music/ahx/init.luau"], +[205797, "src/Rosetta/music/far/init.luau"], +[206027, "src/Rosetta/music/hmp/init.luau"], +[206292, "src/Rosetta/music/hvl/init.luau"], +[206344, "src/Rosetta/music/it/init.luau"], +[206763, "src/Rosetta/music/it/Itsex.luau"], +[206880, "src/Rosetta/music/med/init.luau"], +[207528, "src/Rosetta/music/midi/init.luau"], +[207672, "src/Rosetta/music/midi/Smf.luau"], +[208084, "src/Rosetta/music/mod/init.luau"], +[208438, "src/Rosetta/music/mtm/init.luau"], +[208661, "src/Rosetta/music/mus/init.luau"], +[208819, "src/Rosetta/music/okt/init.luau"], +[209101, "src/Rosetta/music/ptm/init.luau"], +[209324, "src/Rosetta/music/s3m/init.luau"], +[209561, "src/Rosetta/music/sf2/init.luau"], +[209605, "src/Rosetta/music/stm/init.luau"], +[209837, "src/Rosetta/music/ult/init.luau"], +[210142, "src/Rosetta/music/umx/init.luau"], +[210359, "src/Rosetta/music/xm/init.luau"], +[210921, "src/Rosetta/music/xmi/init.luau"], +[211130, "src/Rosetta/ops/AudioOps.luau"], +[211609, "src/Rosetta/ops/ImageOps/init.luau"], +[212257, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[212897, "src/Rosetta/ops/LayerOps.luau"], +[212990, "src/Rosetta/ops/MeshOps/init.luau"], +[214130, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[214297, "src/Rosetta/ops/MusicOps.luau"], +[214646, "src/Rosetta/playlist/m3u/init.luau"], +[214999, "src/Rosetta/playlist/pls/init.luau"], +[215177, "src/Rosetta/playlist/xspf/init.luau"], +[215380, "src/Rosetta/subtitle/ass/init.luau"], +[215824, "src/Rosetta/subtitle/srt/init.luau"], +[215997, "src/Rosetta/subtitle/vtt/init.luau"], +[216200, "src/Rosetta/vector/gamemaps/init.luau"], +[216387, "src/Rosetta/vector/gamemaps/Expand.luau"], +[216484, "src/Rosetta/vector/ldtk/init.luau"], +[216576, "src/Rosetta/vector/ldtk/Read.luau"], +[216912, "src/Rosetta/vector/ldtk/Write.luau"], +[217560, "src/Rosetta/vector/ogmo/init.luau"], +[217679, "src/Rosetta/vector/ogmo/Read.luau"], +[218084, "src/Rosetta/vector/ogmo/Write.luau"], +[218438, "src/Rosetta/vector/svg/init.luau"], +[218524, "src/Rosetta/vector/svg/Parse.luau"], +[219270, "src/Rosetta/vector/svg/PathData.luau"], +[219638, "src/Rosetta/vector/svg/Render.luau"], +[220055, "src/Rosetta/vector/svg/Style.luau"], +[220427, "src/Rosetta/vector/svg/Write.luau"], +[220627, "src/Rosetta/vector/tiled/init.luau"], +[220807, "src/Rosetta/vector/tiled/Data.luau"], +[220958, "src/Rosetta/vector/tiled/Tmj.luau"], +[221589, "src/Rosetta/vector/tiled/Tmx.luau"], +[222201, "src/Rosetta/video/avi/init.luau"], +[222495, "src/Rosetta/video/fli/init.luau"], +[222646, "src/Rosetta/video/flv/init.luau"], +[223030, "src/Rosetta/video/flv/Amf.luau"], +[223188, "src/Rosetta/video/flv/Mux.luau"], +[223469, "src/Rosetta/video/h264/init.luau"], +[223608, "src/Rosetta/video/mkv/init.luau"], +[223764, "src/Rosetta/video/mkv/Mux.luau"], +[224043, "src/Rosetta/video/mkv/Parse.luau"], +[224764, "src/Rosetta/video/mp4/init.luau"], +[225092, "src/Rosetta/video/mpegps/init.luau"], +[225279, "src/Rosetta/video/mpegts/init.luau"], +[225525, "src/Rosetta/video/ogv/init.luau"], +[225920, "src/Rosetta/video/smk/init.luau"], +[226229, "src/Rosetta/video/smk/Audio.luau"], +[226349, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/build/Rosetta.rbxm b/build/Rosetta.rbxm index 4e5a456..846b647 100644 Binary files a/build/Rosetta.rbxm and b/build/Rosetta.rbxm differ diff --git a/build/Rosetta.rbxm.linemap.json b/build/Rosetta.rbxm.linemap.json index b911480..c2fbb3a 100644 --- a/build/Rosetta.rbxm.linemap.json +++ b/build/Rosetta.rbxm.linemap.json @@ -1,6 +1,6 @@ { -"Core_1": [[8, "src/Rosetta/init.luau"], [925, "src/Rosetta/Registry.luau"], [3542, "src/Rosetta/Types.luau"], [4659, "src/Rosetta/codecs/audio/Adpcm/init.luau"], [5413, "src/Rosetta/codecs/image/Yuv.luau"], [5734, "src/Rosetta/codecs/model/Rbx/init.luau"], [5971, "src/Rosetta/codecs/video/Video/init.luau"], [6586, "src/Rosetta/codecs/video/Video/Disposable.luau"], [6797, "src/Rosetta/codecs/video/Video/Pool.luau"], [6849, "src/Rosetta/containers/AudioWrap.luau"], [7359, "src/Rosetta/containers/Ogg/Mux.luau"]], -"Core_2": [[8, "src/Rosetta/core/Bytes.luau"], [535, "src/Rosetta/core/Crc32.luau"], [686, "src/Rosetta/core/Err.luau"], [768, "src/Rosetta/core/Input.luau"], [844, "src/Rosetta/host/init.luau"], [889, "src/Rosetta/ops/ImageOps/init.luau"], [1537, "src/Rosetta/ops/ImageOps/Kernels.luau"]], +"Core": [[8, "src/Rosetta/init.luau"], [941, "src/Rosetta/Registry.luau"], [3558, "src/Rosetta/Types.luau"], [4675, "src/Rosetta/core/Bytes.luau"], [5202, "src/Rosetta/core/Err.luau"], [5284, "src/Rosetta/core/Input.luau"], [5360, "src/Rosetta/host/init.luau"]], +"Detect": [[8, "src/Rosetta/Sniffs.luau"], [4239, "src/Rosetta/core/Crc16.luau"], [4291, "src/Rosetta/core/Sniff.luau"]], "Mpeg2": [[8, "src/Rosetta/codecs/video/Dsp.luau"], [846, "src/Rosetta/codecs/video/Mpeg1/init.luau"], [859, "src/Rosetta/codecs/video/Mpeg2/init.luau"], [1233, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], [2760, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], [2900, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"]], "H263": [[8, "src/Rosetta/codecs/video/H263/init.luau"], [165, "src/Rosetta/codecs/video/H263/Decoder.luau"], [1023, "src/Rosetta/codecs/video/H263/Tables.luau"]], "H264": [[8, "src/Rosetta/codecs/video/H264/init.luau"], [398, "src/Rosetta/codecs/video/H264/Bitstream.luau"], [673, "src/Rosetta/codecs/video/H264/Cabac.luau"], [1804, "src/Rosetta/codecs/video/H264/Cavlc.luau"], [2572, "src/Rosetta/codecs/video/H264/Deblock.luau"], [2834, "src/Rosetta/codecs/video/H264/Decoder.luau"], [3900, "src/Rosetta/codecs/video/H264/Inter.luau"], [4226, "src/Rosetta/codecs/video/H264/Intra.luau"], [4633, "src/Rosetta/codecs/video/H264/Mb.luau"], [5587, "src/Rosetta/codecs/video/H264/Params.luau"], [6035, "src/Rosetta/codecs/video/H264/Slice.luau"], [6287, "src/Rosetta/codecs/video/H264/Tables.luau"], [6329, "src/Rosetta/codecs/video/H264/Transform.luau"]], @@ -13,7 +13,7 @@ "Bcn": [[8, "src/Rosetta/codecs/image/Bcn/init.luau"], [115, "src/Rosetta/codecs/image/Bcn/Decode.luau"], [599, "src/Rosetta/codecs/image/Bcn/Encode.luau"]], "Png": [[8, "src/Rosetta/image/png/init.luau"], [643, "src/Rosetta/image/png/Apng.luau"], [723, "src/Rosetta/image/png/Decode.luau"], [1268, "src/Rosetta/image/png/Encode.luau"]], "Deflate": [[8, "src/Rosetta/codecs/compress/Deflate/init.luau"], [421, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], [903, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"]], -"Brotli": [[8, "src/Rosetta/codecs/compress/Brotli/init.luau"], [95, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], [1071, "src/Rosetta/codecs/compress/Brotli/Static.luau"]], +"Brotli": [[8, "src/Rosetta/codecs/compress/Brotli/init.luau"], [107, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], [1091, "src/Rosetta/codecs/compress/Brotli/Static.luau"]], "Lzma": [[8, "src/Rosetta/codecs/compress/Lzma/init.luau"], [548, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], [615, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], [1088, "src/Rosetta/codecs/compress/Lzma/Filters.luau"]], "Zstd": [[8, "src/Rosetta/codecs/compress/Zstd/init.luau"], [65, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], [1049, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"]], "Mpa": [[8, "src/Rosetta/codecs/audio/Mpa/init.luau"], [23, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], [82, "src/Rosetta/codecs/audio/Mpa/Core.luau"], [1740, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], [2033, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], [2418, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], [3059, "src/Rosetta/codecs/audio/Mpa/Header.luau"], [3200, "src/Rosetta/codecs/audio/Mpa/Tables.luau"]], @@ -27,38 +27,160 @@ "Hively": [[8, "src/Rosetta/codecs/audio/Hively/init.luau"], [205, "src/Rosetta/codecs/audio/Hively/Load.luau"], [455, "src/Rosetta/codecs/audio/Hively/Player.luau"], [1414, "src/Rosetta/codecs/audio/Hively/Tables.luau"]], "SoundFont": [[8, "src/Rosetta/codecs/audio/SoundFont/init.luau"], [63, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], [207, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], [721, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"]], "Draco": [[8, "src/Rosetta/codecs/model/Draco/init.luau"], [340, "src/Rosetta/codecs/model/Draco/Attributes.luau"], [809, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], [1998, "src/Rosetta/codecs/model/Draco/Int64.luau"], [2147, "src/Rosetta/codecs/model/Draco/KdTree.luau"], [2506, "src/Rosetta/codecs/model/Draco/Predict.luau"], [3468, "src/Rosetta/codecs/model/Draco/Reader.luau"]], -"Root": [[8, "src/Rosetta/Sniffs.luau"]], -"archive_1": [[8, "src/Rosetta/archive/7z/init.luau"], [393, "src/Rosetta/archive/7z/Header.luau"], [920, "src/Rosetta/archive/adf/init.luau"], [1202, "src/Rosetta/archive/applesingle/init.luau"], [1388, "src/Rosetta/archive/ar/init.luau"], [1791, "src/Rosetta/archive/arj/init.luau"], [2001, "src/Rosetta/archive/binhex/init.luau"], [2250, "src/Rosetta/archive/br/init.luau"], [2325, "src/Rosetta/archive/bz2/init.luau"], [2389, "src/Rosetta/archive/cab/init.luau"], [2802, "src/Rosetta/archive/cab/Sum.luau"], [2843, "src/Rosetta/archive/cpio/init.luau"], [3011, "src/Rosetta/archive/d64/init.luau"], [3425, "src/Rosetta/archive/fat/init.luau"], [3547, "src/Rosetta/archive/grp/init.luau"], [3661, "src/Rosetta/archive/gzip/init.luau"], [3846, "src/Rosetta/archive/iso/init.luau"], [3918, "src/Rosetta/archive/lha/init.luau"], [4343, "src/Rosetta/archive/lz4/init.luau"], [4687, "src/Rosetta/archive/macbinary/init.luau"], [4885, "src/Rosetta/archive/mpq/init.luau"], [5291, "src/Rosetta/archive/mpq/Crypt.luau"], [5356, "src/Rosetta/archive/pak/init.luau"], [5490, "src/Rosetta/archive/rpm/init.luau"], [5814, "src/Rosetta/archive/tar/init.luau"], [5932, "src/Rosetta/archive/unitypackage/init.luau"], [6168, "src/Rosetta/archive/uu/init.luau"], [6438, "src/Rosetta/archive/vpk/init.luau"], [6749, "src/Rosetta/archive/vswap/init.luau"], [7019, "src/Rosetta/archive/wad/init.luau"], [7473, "src/Rosetta/archive/wad/Picture.luau"], [7575, "src/Rosetta/archive/wad2/init.luau"], [7857, "src/Rosetta/archive/xz/init.luau"]], -"archive_2": [[8, "src/Rosetta/archive/yenc/init.luau"], [280, "src/Rosetta/archive/z/init.luau"], [376, "src/Rosetta/archive/zip/init.luau"], [595, "src/Rosetta/archive/zoo/init.luau"], [791, "src/Rosetta/archive/zst/init.luau"]], -"audio": [[8, "src/Rosetta/audio/aac/init.luau"], [221, "src/Rosetta/audio/ac3/init.luau"], [368, "src/Rosetta/audio/adpcm/init.luau"], [514, "src/Rosetta/audio/adx/init.luau"], [746, "src/Rosetta/audio/aiff/init.luau"], [1138, "src/Rosetta/audio/ape/init.luau"], [1267, "src/Rosetta/audio/au/init.luau"], [1429, "src/Rosetta/audio/brstm/init.luau"], [1721, "src/Rosetta/audio/caf/init.luau"], [2388, "src/Rosetta/audio/flac/init.luau"], [2537, "src/Rosetta/audio/flac/Meta.luau"], [2759, "src/Rosetta/audio/flac/Stream.luau"], [3129, "src/Rosetta/audio/m4a/init.luau"], [3472, "src/Rosetta/audio/mp3/init.luau"], [3733, "src/Rosetta/audio/mp3/Index.luau"], [3924, "src/Rosetta/audio/mp3/Stream.luau"], [4151, "src/Rosetta/audio/mp3/Tags.luau"], [4463, "src/Rosetta/audio/mpc/init.luau"], [4558, "src/Rosetta/audio/opus/init.luau"], [4937, "src/Rosetta/audio/opus/Encode.luau"], [5049, "src/Rosetta/audio/qoa/init.luau"], [5230, "src/Rosetta/audio/tta/init.luau"], [5349, "src/Rosetta/audio/vag/init.luau"], [5573, "src/Rosetta/audio/voc/init.luau"], [5849, "src/Rosetta/audio/vorbis/init.luau"], [6304, "src/Rosetta/audio/vorbis/Encode.luau"], [7117, "src/Rosetta/audio/wav/init.luau"], [7738, "src/Rosetta/audio/wav/Codecs.luau"], [7917, "src/Rosetta/audio/wavpack/init.luau"]], -"cad": [[8, "src/Rosetta/cad/step/init.luau"], [390, "src/Rosetta/cad/step/Brep.luau"], [625, "src/Rosetta/cad/step/Parse.luau"], [1182, "src/Rosetta/cad/step/Write.luau"]], -"codecs_audio": [[8, "src/Rosetta/codecs/audio/Ac3/init.luau"], [168, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], [1053, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], [1155, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], [1458, "src/Rosetta/codecs/audio/Alac/init.luau"], [1693, "src/Rosetta/codecs/audio/Alac/Decode.luau"], [2112, "src/Rosetta/codecs/audio/Alac/Encode.luau"], [2524, "src/Rosetta/codecs/audio/Ape/init.luau"], [2740, "src/Rosetta/codecs/audio/Ape/Decode.luau"], [3501, "src/Rosetta/codecs/audio/ApeTag.luau"], [3599, "src/Rosetta/codecs/audio/Mdct/init.luau"], [3819, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], [4073, "src/Rosetta/codecs/audio/MidiRender.luau"], [4420, "src/Rosetta/codecs/audio/Pcm/init.luau"], [4684, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], [4981, "src/Rosetta/codecs/audio/Qoa/init.luau"], [5263, "src/Rosetta/codecs/audio/Resample/init.luau"], [5658, "src/Rosetta/codecs/audio/Stream.luau"], [5820, "src/Rosetta/codecs/audio/Tta/init.luau"], [5938, "src/Rosetta/codecs/audio/Tta/Decode.luau"], [6190, "src/Rosetta/codecs/audio/VorbisComment.luau"]], -"codecs_compress": [[8, "src/Rosetta/codecs/compress/Bzip2/init.luau"], [52, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], [565, "src/Rosetta/codecs/compress/Explode.luau"], [761, "src/Rosetta/codecs/compress/Lz4.luau"], [1030, "src/Rosetta/codecs/compress/Lzh/init.luau"], [1634, "src/Rosetta/codecs/compress/Lzw/init.luau"], [1902, "src/Rosetta/codecs/compress/Lzx.luau"], [2336, "src/Rosetta/codecs/compress/PackBits.luau"], [2426, "src/Rosetta/codecs/compress/Quantum.luau"], [2663, "src/Rosetta/codecs/compress/UnixCompress.luau"], [2967, "src/Rosetta/codecs/compress/Xxh32.luau"]], -"codecs_entropy": [[8, "src/Rosetta/codecs/entropy/Huffman.luau"], [295, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], [306, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], [527, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"]], -"codecs_font": [[8, "src/Rosetta/codecs/font/Bitmap.luau"], [209, "src/Rosetta/codecs/font/Cff/init.luau"], [850, "src/Rosetta/codecs/font/GlyphNames.luau"], [1000, "src/Rosetta/codecs/font/TrueType/init.luau"], [1314, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], [1706, "src/Rosetta/codecs/font/TrueType/Tables.luau"]], -"codecs_image": [[8, "src/Rosetta/codecs/image/Blend.luau"], [387, "src/Rosetta/codecs/image/Etc.luau"], [685, "src/Rosetta/codecs/image/Half.luau"], [754, "src/Rosetta/codecs/image/Miptex.luau"], [1054, "src/Rosetta/codecs/image/Pixels.luau"], [1374, "src/Rosetta/codecs/image/Quantize/init.luau"], [1835, "src/Rosetta/codecs/image/Raster.luau"], [2532, "src/Rosetta/codecs/image/Texel.luau"], [2905, "src/Rosetta/codecs/image/Texture.luau"]], -"codecs_model": [[8, "src/Rosetta/codecs/model/Brush.luau"], [648, "src/Rosetta/codecs/model/Displacement.luau"], [797, "src/Rosetta/codecs/model/DoomMap/init.luau"], [1242, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], [1492, "src/Rosetta/codecs/model/Mat4.luau"], [1751, "src/Rosetta/codecs/model/MeshFlatten.luau"], [2279, "src/Rosetta/codecs/model/Minecraft/init.luau"], [2831, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], [2910, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], [3017, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], [3223, "src/Rosetta/codecs/model/Patch.luau"], [3347, "src/Rosetta/codecs/model/Polygon.luau"], [3581, "src/Rosetta/codecs/model/Rbx/Binary.luau"], [4335, "src/Rosetta/codecs/model/Rig.luau"], [4578, "src/Rosetta/codecs/model/Sampler.luau"], [4738, "src/Rosetta/codecs/model/SourceAnim.luau"], [4959, "src/Rosetta/codecs/model/Vrml/init.luau"], [5107, "src/Rosetta/codecs/model/Vrml/Build.luau"], [5681, "src/Rosetta/codecs/model/Vrml/Fields.luau"], [5844, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], [6593, "src/Rosetta/codecs/model/Vrml/Parse.luau"], [7115, "src/Rosetta/codecs/model/Vrml/Write.luau"], [7842, "src/Rosetta/codecs/model/Vrml/Xml.luau"]], -"codecs_text": [[8, "src/Rosetta/codecs/text/GodotVariant.luau"], [667, "src/Rosetta/codecs/text/Json/init.luau"], [936, "src/Rosetta/codecs/text/Json/Decode.luau"], [1371, "src/Rosetta/codecs/text/Json/Encode.luau"], [1716, "src/Rosetta/codecs/text/KeyValues/init.luau"], [2286, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], [2592, "src/Rosetta/codecs/text/Lexer/init.luau"], [2724, "src/Rosetta/codecs/text/Nbt/init.luau"], [3077, "src/Rosetta/codecs/text/Nbt/Binary.luau"], [3769, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], [4409, "src/Rosetta/codecs/text/Nbt/Value.luau"], [4647, "src/Rosetta/codecs/text/Text/init.luau"], [4738, "src/Rosetta/codecs/text/Url/init.luau"], [4943, "src/Rosetta/codecs/text/Xml/init.luau"], [5393, "src/Rosetta/codecs/text/Xml/Parse.luau"]], -"codecs_video": [[8, "src/Rosetta/codecs/video/Video/Source.luau"]], -"containers": [[8, "src/Rosetta/containers/Archive.luau"], [275, "src/Rosetta/containers/Avi/init.luau"], [828, "src/Rosetta/containers/Blend.luau"], [1567, "src/Rosetta/containers/Chunks.luau"], [1702, "src/Rosetta/containers/Cpio.luau"], [2130, "src/Rosetta/containers/Demux.luau"], [2416, "src/Rosetta/containers/Ebml/init.luau"], [2730, "src/Rosetta/containers/Fat.luau"], [3418, "src/Rosetta/containers/Iso9660.luau"], [3923, "src/Rosetta/containers/IsoBmff/init.luau"], [4094, "src/Rosetta/containers/IsoBmff/Box.luau"], [4283, "src/Rosetta/containers/IsoBmff/Demux.luau"], [5129, "src/Rosetta/containers/IsoBmff/Meta.luau"], [5651, "src/Rosetta/containers/IsoBmff/Mux.luau"], [6168, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], [6286, "src/Rosetta/containers/MacFile.luau"], [6435, "src/Rosetta/containers/Ogg/init.luau"], [6860, "src/Rosetta/containers/Ogg/Page.luau"], [7026, "src/Rosetta/containers/Riff/init.luau"], [7343, "src/Rosetta/containers/Tar.luau"], [7757, "src/Rosetta/containers/Zip/init.luau"]], -"core": [[8, "src/Rosetta/core/Adler32.luau"], [68, "src/Rosetta/core/Base64.luau"], [296, "src/Rosetta/core/Bits.luau"], [589, "src/Rosetta/core/Crc16.luau"], [641, "src/Rosetta/core/Md5.luau"], [799, "src/Rosetta/core/Sniff.luau"]], -"data": [[8, "src/Rosetta/data/cbor/init.luau"], [107, "src/Rosetta/data/cbor/Codec.luau"], [676, "src/Rosetta/data/csv/init.luau"], [988, "src/Rosetta/data/ini/init.luau"], [1234, "src/Rosetta/data/json/init.luau"], [1326, "src/Rosetta/data/msgpack/init.luau"], [1415, "src/Rosetta/data/msgpack/Codec.luau"], [1857, "src/Rosetta/data/nbt/init.luau"], [1916, "src/Rosetta/data/plist/init.luau"], [2222, "src/Rosetta/data/plist/Binary.luau"], [2489, "src/Rosetta/data/q3shader/init.luau"], [2728, "src/Rosetta/data/q3skin/init.luau"], [2824, "src/Rosetta/data/snbt/init.luau"], [2887, "src/Rosetta/data/toml/init.luau"], [2954, "src/Rosetta/data/toml/Decode.luau"], [3582, "src/Rosetta/data/toml/Encode.luau"], [3791, "src/Rosetta/data/tres/init.luau"], [3936, "src/Rosetta/data/vdf/init.luau"], [4037, "src/Rosetta/data/xml/init.luau"], [4093, "src/Rosetta/data/yaml/init.luau"], [4166, "src/Rosetta/data/yaml/Emit.luau"], [4456, "src/Rosetta/data/yaml/Parse.luau"]], -"font": [[8, "src/Rosetta/font/bdf/init.luau"], [297, "src/Rosetta/font/bmfont/init.luau"], [724, "src/Rosetta/font/bmfont/Parse.luau"], [1177, "src/Rosetta/font/eot/init.luau"], [1409, "src/Rosetta/font/fon/init.luau"], [1692, "src/Rosetta/font/hershey/init.luau"], [1887, "src/Rosetta/font/pcf/init.luau"], [2167, "src/Rosetta/font/psf/init.luau"], [2487, "src/Rosetta/font/ttf/init.luau"], [2538, "src/Rosetta/font/type1/init.luau"], [2897, "src/Rosetta/font/type1/Charstring.luau"], [3175, "src/Rosetta/font/woff/init.luau"], [3307, "src/Rosetta/font/woff2/init.luau"], [3364, "src/Rosetta/font/woff2/Rebuild.luau"]], -"host": [[8, "src/Rosetta/host/Love.luau"], [151, "src/Rosetta/host/LuaJIT.luau"], [201, "src/Rosetta/host/Luau.luau"], [224, "src/Rosetta/host/Roblox.luau"]], -"image_1": [[8, "src/Rosetta/image/ani/init.luau"], [188, "src/Rosetta/image/art/init.luau"], [676, "src/Rosetta/image/blp/init.luau"], [934, "src/Rosetta/image/bmp/init.luau"], [1349, "src/Rosetta/image/dds/init.luau"], [1832, "src/Rosetta/image/exr/init.luau"], [2592, "src/Rosetta/image/exr/Codec.luau"], [2703, "src/Rosetta/image/exr/Piz.luau"], [3060, "src/Rosetta/image/gif/init.luau"], [3576, "src/Rosetta/image/gif/Decode.luau"], [3652, "src/Rosetta/image/hdr/init.luau"], [3881, "src/Rosetta/image/hdr/Codec.luau"], [4092, "src/Rosetta/image/icns/init.luau"], [4423, "src/Rosetta/image/ico/init.luau"], [4700, "src/Rosetta/image/ico/Dib.luau"], [4795, "src/Rosetta/image/ilbm/init.luau"], [5114, "src/Rosetta/image/jpeg/init.luau"], [5273, "src/Rosetta/image/ktx/init.luau"], [5933, "src/Rosetta/image/lmp/init.luau"], [6066, "src/Rosetta/image/pcx/init.luau"], [6330, "src/Rosetta/image/pnm/init.luau"], [6708, "src/Rosetta/image/pnm/Codec.luau"], [6985, "src/Rosetta/image/qoi/init.luau"], [7107, "src/Rosetta/image/qoi/Codec.luau"], [7264, "src/Rosetta/image/sgi/init.luau"]], -"image_2": [[8, "src/Rosetta/image/spr/init.luau"], [321, "src/Rosetta/image/sunras/init.luau"], [567, "src/Rosetta/image/tga/init.luau"], [837, "src/Rosetta/image/tga/Codec.luau"], [1037, "src/Rosetta/image/tiff/init.luau"], [1864, "src/Rosetta/image/tiff/Pixels.luau"], [2254, "src/Rosetta/image/tim/init.luau"], [2496, "src/Rosetta/image/vtf/init.luau"], [2731, "src/Rosetta/image/webp/init.luau"], [3341, "src/Rosetta/image/webp/Alpha.luau"], [3417, "src/Rosetta/image/webp/Anim.luau"], [3572, "src/Rosetta/image/xbm/init.luau"], [3733, "src/Rosetta/image/xpm/init.luau"], [4001, "src/Rosetta/image/xpm/Names.luau"]], -"layered": [[8, "src/Rosetta/layered/aseprite/init.luau"], [746, "src/Rosetta/layered/ora/init.luau"], [1033, "src/Rosetta/layered/psd/init.luau"], [1768, "src/Rosetta/layered/psd/Channels.luau"]], -"model_1": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"], [2039, "src/Rosetta/model/3mf/init.luau"], [2121, "src/Rosetta/model/3mf/Read.luau"], [2709, "src/Rosetta/model/3mf/Write.luau"], [3114, "src/Rosetta/model/ase/init.luau"], [3237, "src/Rosetta/model/ase/Build.luau"], [3811, "src/Rosetta/model/ase/Parse.luau"], [3880, "src/Rosetta/model/ase/Write.luau"], [4343, "src/Rosetta/model/b3d/init.luau"], [4398, "src/Rosetta/model/b3d/Read.luau"], [4969, "src/Rosetta/model/blend/init.luau"], [5069, "src/Rosetta/model/blend/Anim.luau"], [5599, "src/Rosetta/model/blend/Armature.luau"], [6135, "src/Rosetta/model/blend/Driver.luau"], [6310, "src/Rosetta/model/blend/Material.luau"], [6662, "src/Rosetta/model/blend/Mesh.luau"]], -"model_2": [[8, "src/Rosetta/model/blend/Normals.luau"], [169, "src/Rosetta/model/blend/Prim.luau"], [676, "src/Rosetta/model/blend/Read.luau"], [1764, "src/Rosetta/model/bsp/init.luau"], [1955, "src/Rosetta/model/bsp/Lightmap.luau"], [2021, "src/Rosetta/model/bsp/Quake.luau"], [2410, "src/Rosetta/model/bsp/Quake3.luau"], [2639, "src/Rosetta/model/bsp/Tree.luau"], [3027, "src/Rosetta/model/buildmap/init.luau"], [3299, "src/Rosetta/model/buildmap/Geometry.luau"], [3702, "src/Rosetta/model/d3map/init.luau"], [3984, "src/Rosetta/model/d3map/Parse.luau"], [4182, "src/Rosetta/model/dae/init.luau"], [4371, "src/Rosetta/model/dae/Math.luau"], [4418, "src/Rosetta/model/dae/Read.luau"], [6268, "src/Rosetta/model/dae/Write.luau"], [6637, "src/Rosetta/model/fbx/init.luau"], [6785, "src/Rosetta/model/fbx/Ascii.luau"], [7055, "src/Rosetta/model/fbx/Binary.luau"]], -"model_3": [[8, "src/Rosetta/model/fbx/Read.luau"], [1370, "src/Rosetta/model/fbx/Write.luau"], [2355, "src/Rosetta/model/fbx/Xform.luau"], [2396, "src/Rosetta/model/gltf/init.luau"], [2633, "src/Rosetta/model/gltf/Pack.luau"], [2702, "src/Rosetta/model/gltf/Read.luau"], [3443, "src/Rosetta/model/gltf/Write.luau"], [4129, "src/Rosetta/model/godot/init.luau"], [4220, "src/Rosetta/model/godot/Build.luau"], [4762, "src/Rosetta/model/godot/Primitives.luau"], [5037, "src/Rosetta/model/godot/Surface.luau"], [5522, "src/Rosetta/model/godot/Write.luau"], [5851, "src/Rosetta/model/iqm/init.luau"], [5927, "src/Rosetta/model/iqm/Read.luau"], [6282, "src/Rosetta/model/iqm/Write.luau"], [6969, "src/Rosetta/model/ldraw/init.luau"], [7047, "src/Rosetta/model/ldraw/Colors.luau"]], -"model_4": [[8, "src/Rosetta/model/ldraw/Read.luau"], [585, "src/Rosetta/model/lwo/init.luau"], [661, "src/Rosetta/model/lwo/Build.luau"], [1123, "src/Rosetta/model/lwo/Parse.luau"], [1666, "src/Rosetta/model/map/init.luau"], [1983, "src/Rosetta/model/map/Build.luau"], [2227, "src/Rosetta/model/map/Parse.luau"], [2612, "src/Rosetta/model/map/Write.luau"], [2758, "src/Rosetta/model/mca/init.luau"], [3100, "src/Rosetta/model/mca/Chunk.luau"], [3233, "src/Rosetta/model/mca/Lz4Block.luau"], [3303, "src/Rosetta/model/md2/init.luau"], [3502, "src/Rosetta/model/md3/init.luau"], [3730, "src/Rosetta/model/md5/init.luau"], [3811, "src/Rosetta/model/md5/Read.luau"], [4244, "src/Rosetta/model/mdl/init.luau"], [4326, "src/Rosetta/model/mdl/HalfLife.luau"], [4630, "src/Rosetta/model/mdl/Quake.luau"], [4848, "src/Rosetta/model/ms3d/init.luau"], [4920, "src/Rosetta/model/ms3d/Read.luau"], [5366, "src/Rosetta/model/ms3d/Write.luau"], [5835, "src/Rosetta/model/obj/init.luau"], [6653, "src/Rosetta/model/obj/Mtl.luau"], [6941, "src/Rosetta/model/off/init.luau"]], -"model_5": [[8, "src/Rosetta/model/ply/init.luau"], [1113, "src/Rosetta/model/ply/Binary.luau"], [1314, "src/Rosetta/model/pmx/init.luau"], [1383, "src/Rosetta/model/pmx/Build.luau"], [1679, "src/Rosetta/model/pmx/Pmd.luau"], [2014, "src/Rosetta/model/pmx/Read.luau"], [2418, "src/Rosetta/model/proc/init.luau"], [2800, "src/Rosetta/model/qb/init.luau"], [3193, "src/Rosetta/model/rbxm/init.luau"], [3786, "src/Rosetta/model/rbxmx/init.luau"], [4462, "src/Rosetta/model/robloxmesh/init.luau"], [5121, "src/Rosetta/model/robloxmesh/Parse.luau"], [5578, "src/Rosetta/model/robloxmesh/Write.luau"], [5687, "src/Rosetta/model/schematic/init.luau"], [6008, "src/Rosetta/model/schematic/Common.luau"], [6128, "src/Rosetta/model/schematic/Litematic.luau"], [6339, "src/Rosetta/model/schematic/Mcedit.luau"], [6583, "src/Rosetta/model/schematic/Sponge.luau"], [6712, "src/Rosetta/model/smd/init.luau"], [6779, "src/Rosetta/model/smd/Read.luau"], [7048, "src/Rosetta/model/smd/Write.luau"], [7291, "src/Rosetta/model/sourcemdl/init.luau"], [7462, "src/Rosetta/model/sourcemdl/Build.luau"], [7892, "src/Rosetta/model/sourcemdl/Material.luau"]], -"model_6": [[8, "src/Rosetta/model/sourcemdl/Mdl.luau"], [535, "src/Rosetta/model/sourcemdl/Phy.luau"], [658, "src/Rosetta/model/sourcemdl/Vtx.luau"], [840, "src/Rosetta/model/sourcemdl/Vvd.luau"], [934, "src/Rosetta/model/stl/init.luau"], [1384, "src/Rosetta/model/stl/Decode.luau"], [1458, "src/Rosetta/model/t3d/init.luau"], [1552, "src/Rosetta/model/t3d/Build.luau"], [1957, "src/Rosetta/model/t3d/Parse.luau"], [2125, "src/Rosetta/model/udmf/init.luau"], [2208, "src/Rosetta/model/usda/init.luau"], [2417, "src/Rosetta/model/usda/Build.luau"], [3695, "src/Rosetta/model/usda/Parse.luau"], [4493, "src/Rosetta/model/usda/Write.luau"], [5310, "src/Rosetta/model/vbsp/init.luau"], [5756, "src/Rosetta/model/vbsp/Faces.luau"], [5980, "src/Rosetta/model/vbsp/Props.luau"], [6072, "src/Rosetta/model/vmf/init.luau"], [6397, "src/Rosetta/model/vmf/Build.luau"], [6821, "src/Rosetta/model/vox/init.luau"], [7707, "src/Rosetta/model/vox/Grid.luau"], [7764, "src/Rosetta/model/vrml/init.luau"], [7830, "src/Rosetta/model/x/init.luau"]], -"model_7": [[8, "src/Rosetta/model/x/Build.luau"], [571, "src/Rosetta/model/x/Parse.luau"], [868, "src/Rosetta/model/x3d/init.luau"]], -"music": [[8, "src/Rosetta/music/669/init.luau"], [215, "src/Rosetta/music/ahx/init.luau"], [267, "src/Rosetta/music/far/init.luau"], [497, "src/Rosetta/music/hmp/init.luau"], [762, "src/Rosetta/music/hvl/init.luau"], [814, "src/Rosetta/music/it/init.luau"], [1233, "src/Rosetta/music/it/Itsex.luau"], [1350, "src/Rosetta/music/med/init.luau"], [1998, "src/Rosetta/music/midi/init.luau"], [2142, "src/Rosetta/music/midi/Smf.luau"], [2554, "src/Rosetta/music/mod/init.luau"], [2908, "src/Rosetta/music/mtm/init.luau"], [3131, "src/Rosetta/music/mus/init.luau"], [3289, "src/Rosetta/music/okt/init.luau"], [3571, "src/Rosetta/music/ptm/init.luau"], [3794, "src/Rosetta/music/s3m/init.luau"], [4031, "src/Rosetta/music/sf2/init.luau"], [4075, "src/Rosetta/music/stm/init.luau"], [4307, "src/Rosetta/music/ult/init.luau"], [4612, "src/Rosetta/music/umx/init.luau"], [4829, "src/Rosetta/music/xm/init.luau"], [5391, "src/Rosetta/music/xmi/init.luau"]], -"ops": [[8, "src/Rosetta/ops/AudioOps.luau"], [487, "src/Rosetta/ops/LayerOps.luau"], [580, "src/Rosetta/ops/MeshOps/init.luau"], [1720, "src/Rosetta/ops/MeshOps/Greedy.luau"], [1887, "src/Rosetta/ops/MusicOps.luau"]], -"playlist": [[8, "src/Rosetta/playlist/m3u/init.luau"], [361, "src/Rosetta/playlist/pls/init.luau"], [539, "src/Rosetta/playlist/xspf/init.luau"]], -"subtitle": [[8, "src/Rosetta/subtitle/ass/init.luau"], [452, "src/Rosetta/subtitle/srt/init.luau"], [625, "src/Rosetta/subtitle/vtt/init.luau"]], -"vector": [[8, "src/Rosetta/vector/gamemaps/init.luau"], [195, "src/Rosetta/vector/gamemaps/Expand.luau"], [292, "src/Rosetta/vector/ldtk/init.luau"], [384, "src/Rosetta/vector/ldtk/Read.luau"], [720, "src/Rosetta/vector/ldtk/Write.luau"], [1368, "src/Rosetta/vector/ogmo/init.luau"], [1487, "src/Rosetta/vector/ogmo/Read.luau"], [1892, "src/Rosetta/vector/ogmo/Write.luau"], [2246, "src/Rosetta/vector/svg/init.luau"], [2332, "src/Rosetta/vector/svg/Parse.luau"], [3078, "src/Rosetta/vector/svg/PathData.luau"], [3446, "src/Rosetta/vector/svg/Render.luau"], [3863, "src/Rosetta/vector/svg/Style.luau"], [4235, "src/Rosetta/vector/svg/Write.luau"], [4435, "src/Rosetta/vector/tiled/init.luau"], [4615, "src/Rosetta/vector/tiled/Data.luau"], [4766, "src/Rosetta/vector/tiled/Tmj.luau"], [5397, "src/Rosetta/vector/tiled/Tmx.luau"]], -"video": [[8, "src/Rosetta/video/avi/init.luau"], [302, "src/Rosetta/video/fli/init.luau"], [453, "src/Rosetta/video/flv/init.luau"], [837, "src/Rosetta/video/flv/Amf.luau"], [995, "src/Rosetta/video/flv/Mux.luau"], [1276, "src/Rosetta/video/h264/init.luau"], [1415, "src/Rosetta/video/mkv/init.luau"], [1571, "src/Rosetta/video/mkv/Mux.luau"], [1850, "src/Rosetta/video/mkv/Parse.luau"], [2571, "src/Rosetta/video/mp4/init.luau"], [2899, "src/Rosetta/video/mpegps/init.luau"], [3086, "src/Rosetta/video/mpegts/init.luau"], [3332, "src/Rosetta/video/ogv/init.luau"], [3727, "src/Rosetta/video/smk/init.luau"], [4036, "src/Rosetta/video/smk/Audio.luau"], [4156, "src/Rosetta/video/y4m/init.luau"]] +"archive_7z": [[8, "src/Rosetta/archive/7z/init.luau"], [393, "src/Rosetta/archive/7z/Header.luau"], [920, "src/Rosetta/archive/adf/init.luau"]], +"archive_applesingle": [[8, "src/Rosetta/archive/applesingle/init.luau"], [194, "src/Rosetta/archive/ar/init.luau"], [597, "src/Rosetta/archive/arj/init.luau"]], +"archive_binhex": [[8, "src/Rosetta/archive/binhex/init.luau"], [257, "src/Rosetta/archive/br/init.luau"], [332, "src/Rosetta/archive/bz2/init.luau"], [396, "src/Rosetta/archive/cab/init.luau"], [809, "src/Rosetta/archive/cab/Sum.luau"], [850, "src/Rosetta/archive/cpio/init.luau"]], +"archive_d64": [[8, "src/Rosetta/archive/d64/init.luau"], [422, "src/Rosetta/archive/fat/init.luau"], [544, "src/Rosetta/archive/grp/init.luau"], [658, "src/Rosetta/archive/gzip/init.luau"], [843, "src/Rosetta/archive/iso/init.luau"]], +"archive_lha": [[8, "src/Rosetta/archive/lha/init.luau"], [433, "src/Rosetta/archive/lz4/init.luau"], [777, "src/Rosetta/archive/macbinary/init.luau"]], +"archive_mpq": [[8, "src/Rosetta/archive/mpq/init.luau"], [414, "src/Rosetta/archive/mpq/Crypt.luau"], [479, "src/Rosetta/archive/pak/init.luau"], [613, "src/Rosetta/archive/rpm/init.luau"]], +"archive_tar": [[8, "src/Rosetta/archive/tar/init.luau"], [126, "src/Rosetta/archive/unitypackage/init.luau"], [362, "src/Rosetta/archive/uu/init.luau"], [632, "src/Rosetta/archive/vpk/init.luau"]], +"archive_vswap": [[8, "src/Rosetta/archive/vswap/init.luau"], [278, "src/Rosetta/archive/wad/init.luau"], [732, "src/Rosetta/archive/wad/Picture.luau"]], +"archive_wad2": [[8, "src/Rosetta/archive/wad2/init.luau"], [290, "src/Rosetta/archive/xz/init.luau"], [390, "src/Rosetta/archive/yenc/init.luau"], [662, "src/Rosetta/archive/z/init.luau"], [758, "src/Rosetta/archive/zip/init.luau"]], +"archive_zoo": [[8, "src/Rosetta/archive/zoo/init.luau"], [204, "src/Rosetta/archive/zst/init.luau"]], +"audio_aac": [[8, "src/Rosetta/audio/aac/init.luau"], [221, "src/Rosetta/audio/ac3/init.luau"], [368, "src/Rosetta/audio/adpcm/init.luau"], [514, "src/Rosetta/audio/adx/init.luau"]], +"audio_aiff": [[8, "src/Rosetta/audio/aiff/init.luau"], [400, "src/Rosetta/audio/ape/init.luau"], [529, "src/Rosetta/audio/au/init.luau"], [691, "src/Rosetta/audio/brstm/init.luau"]], +"audio_caf": [[8, "src/Rosetta/audio/caf/init.luau"]], +"audio_flac": [[8, "src/Rosetta/audio/flac/init.luau"], [157, "src/Rosetta/audio/flac/Meta.luau"], [379, "src/Rosetta/audio/flac/Stream.luau"], [749, "src/Rosetta/audio/m4a/init.luau"]], +"audio_mp3": [[8, "src/Rosetta/audio/mp3/init.luau"], [269, "src/Rosetta/audio/mp3/Index.luau"], [460, "src/Rosetta/audio/mp3/Stream.luau"], [687, "src/Rosetta/audio/mp3/Tags.luau"]], +"audio_mpc": [[8, "src/Rosetta/audio/mpc/init.luau"], [103, "src/Rosetta/audio/opus/init.luau"], [482, "src/Rosetta/audio/opus/Encode.luau"], [594, "src/Rosetta/audio/qoa/init.luau"], [775, "src/Rosetta/audio/tta/init.luau"]], +"audio_vag": [[8, "src/Rosetta/audio/vag/init.luau"], [232, "src/Rosetta/audio/voc/init.luau"]], +"audio_vorbis": [[8, "src/Rosetta/audio/vorbis/init.luau"], [463, "src/Rosetta/audio/vorbis/Encode.luau"]], +"audio_wav": [[8, "src/Rosetta/audio/wav/init.luau"], [629, "src/Rosetta/audio/wav/Codecs.luau"], [808, "src/Rosetta/audio/wavpack/init.luau"]], +"cad_step": [[8, "src/Rosetta/cad/step/init.luau"], [390, "src/Rosetta/cad/step/Brep.luau"], [625, "src/Rosetta/cad/step/Parse.luau"], [1182, "src/Rosetta/cad/step/Write.luau"]], +"codecs_audio_Ac3": [[8, "src/Rosetta/codecs/audio/Ac3/init.luau"], [168, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], [1053, "src/Rosetta/codecs/audio/Ac3/Tables.luau"]], +"codecs_audio_Adpcm": [[8, "src/Rosetta/codecs/audio/Adpcm/init.luau"], [762, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"]], +"codecs_audio_Alac": [[8, "src/Rosetta/codecs/audio/Alac/init.luau"], [243, "src/Rosetta/codecs/audio/Alac/Decode.luau"], [662, "src/Rosetta/codecs/audio/Alac/Encode.luau"]], +"codecs_audio_Ape": [[8, "src/Rosetta/codecs/audio/Ape/init.luau"], [224, "src/Rosetta/codecs/audio/Ape/Decode.luau"], [985, "src/Rosetta/codecs/audio/ApeTag.luau"]], +"codecs_audio_Mdct": [[8, "src/Rosetta/codecs/audio/Mdct/init.luau"], [228, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], [482, "src/Rosetta/codecs/audio/MidiRender.luau"]], +"codecs_audio_Pcm": [[8, "src/Rosetta/codecs/audio/Pcm/init.luau"], [272, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], [569, "src/Rosetta/codecs/audio/Qoa/init.luau"]], +"codecs_audio_Resample": [[8, "src/Rosetta/codecs/audio/Resample/init.luau"], [403, "src/Rosetta/codecs/audio/Stream.luau"], [565, "src/Rosetta/codecs/audio/Tta/init.luau"], [683, "src/Rosetta/codecs/audio/Tta/Decode.luau"], [935, "src/Rosetta/codecs/audio/VorbisComment.luau"]], +"codecs_compress_Bzip2": [[8, "src/Rosetta/codecs/compress/Bzip2/init.luau"], [52, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], [565, "src/Rosetta/codecs/compress/Explode.luau"], [761, "src/Rosetta/codecs/compress/Lz4.luau"]], +"codecs_compress_Lzh": [[8, "src/Rosetta/codecs/compress/Lzh/init.luau"], [612, "src/Rosetta/codecs/compress/Lzw/init.luau"], [880, "src/Rosetta/codecs/compress/Lzx.luau"]], +"codecs_compress_PackBits": [[8, "src/Rosetta/codecs/compress/PackBits.luau"], [98, "src/Rosetta/codecs/compress/Quantum.luau"], [335, "src/Rosetta/codecs/compress/UnixCompress.luau"], [639, "src/Rosetta/codecs/compress/Xxh32.luau"]], +"codecs_entropy_Huffman": [[8, "src/Rosetta/codecs/entropy/Huffman.luau"], [295, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], [306, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], [527, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"]], +"codecs_font_Bitmap": [[8, "src/Rosetta/codecs/font/Bitmap.luau"], [209, "src/Rosetta/codecs/font/Cff/init.luau"], [850, "src/Rosetta/codecs/font/GlyphNames.luau"]], +"codecs_font_TrueType": [[8, "src/Rosetta/codecs/font/TrueType/init.luau"], [322, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], [714, "src/Rosetta/codecs/font/TrueType/Tables.luau"]], +"codecs_image_Blend": [[8, "src/Rosetta/codecs/image/Blend.luau"], [387, "src/Rosetta/codecs/image/Etc.luau"], [685, "src/Rosetta/codecs/image/Half.luau"]], +"codecs_image_Miptex": [[8, "src/Rosetta/codecs/image/Miptex.luau"], [308, "src/Rosetta/codecs/image/Pixels.luau"]], +"codecs_image_Quantize": [[8, "src/Rosetta/codecs/image/Quantize/init.luau"]], +"codecs_image_Raster": [[8, "src/Rosetta/codecs/image/Raster.luau"]], +"codecs_image_Texel": [[8, "src/Rosetta/codecs/image/Texel.luau"], [381, "src/Rosetta/codecs/image/Texture.luau"], [526, "src/Rosetta/codecs/image/Yuv.luau"]], +"codecs_model_Brush": [[8, "src/Rosetta/codecs/model/Brush.luau"], [648, "src/Rosetta/codecs/model/Displacement.luau"]], +"codecs_model_DoomMap": [[8, "src/Rosetta/codecs/model/DoomMap/init.luau"], [453, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], [703, "src/Rosetta/codecs/model/Mat4.luau"]], +"codecs_model_MeshFlatten": [[8, "src/Rosetta/codecs/model/MeshFlatten.luau"]], +"codecs_model_Minecraft": [[8, "src/Rosetta/codecs/model/Minecraft/init.luau"], [560, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], [639, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], [746, "src/Rosetta/codecs/model/Minecraft/Packed.luau"]], +"codecs_model_Patch": [[8, "src/Rosetta/codecs/model/Patch.luau"], [132, "src/Rosetta/codecs/model/Polygon.luau"]], +"codecs_model_Rbx": [[8, "src/Rosetta/codecs/model/Rbx/init.luau"], [245, "src/Rosetta/codecs/model/Rbx/Binary.luau"]], +"codecs_model_Rig": [[8, "src/Rosetta/codecs/model/Rig.luau"], [251, "src/Rosetta/codecs/model/Sampler.luau"], [411, "src/Rosetta/codecs/model/SourceAnim.luau"]], +"codecs_model_Vrml": [[8, "src/Rosetta/codecs/model/Vrml/init.luau"], [156, "src/Rosetta/codecs/model/Vrml/Build.luau"], [730, "src/Rosetta/codecs/model/Vrml/Fields.luau"], [893, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], [1642, "src/Rosetta/codecs/model/Vrml/Parse.luau"], [2164, "src/Rosetta/codecs/model/Vrml/Write.luau"], [2891, "src/Rosetta/codecs/model/Vrml/Xml.luau"]], +"codecs_text_GodotVariant": [[8, "src/Rosetta/codecs/text/GodotVariant.luau"]], +"codecs_text_Json": [[8, "src/Rosetta/codecs/text/Json/init.luau"], [277, "src/Rosetta/codecs/text/Json/Decode.luau"], [712, "src/Rosetta/codecs/text/Json/Encode.luau"]], +"codecs_text_KeyValues": [[8, "src/Rosetta/codecs/text/KeyValues/init.luau"], [578, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], [884, "src/Rosetta/codecs/text/Lexer/init.luau"]], +"codecs_text_Nbt": [[8, "src/Rosetta/codecs/text/Nbt/init.luau"], [361, "src/Rosetta/codecs/text/Nbt/Binary.luau"], [1053, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], [1693, "src/Rosetta/codecs/text/Nbt/Value.luau"]], +"codecs_text_Text": [[8, "src/Rosetta/codecs/text/Text/init.luau"], [99, "src/Rosetta/codecs/text/Url/init.luau"]], +"codecs_text_Xml": [[8, "src/Rosetta/codecs/text/Xml/init.luau"], [458, "src/Rosetta/codecs/text/Xml/Parse.luau"]], +"codecs_video_Video": [[8, "src/Rosetta/codecs/video/Video/init.luau"], [623, "src/Rosetta/codecs/video/Video/Disposable.luau"], [834, "src/Rosetta/codecs/video/Video/Pool.luau"], [886, "src/Rosetta/codecs/video/Video/Source.luau"]], +"containers_Archive": [[8, "src/Rosetta/containers/Archive.luau"], [275, "src/Rosetta/containers/AudioWrap.luau"]], +"containers_Avi": [[8, "src/Rosetta/containers/Avi/init.luau"]], +"containers_Blend": [[8, "src/Rosetta/containers/Blend.luau"], [747, "src/Rosetta/containers/Chunks.luau"]], +"containers_Cpio": [[8, "src/Rosetta/containers/Cpio.luau"], [436, "src/Rosetta/containers/Demux.luau"], [722, "src/Rosetta/containers/Ebml/init.luau"]], +"containers_Fat": [[8, "src/Rosetta/containers/Fat.luau"]], +"containers_Iso9660": [[8, "src/Rosetta/containers/Iso9660.luau"]], +"containers_IsoBmff": [[8, "src/Rosetta/containers/IsoBmff/init.luau"], [179, "src/Rosetta/containers/IsoBmff/Box.luau"], [368, "src/Rosetta/containers/IsoBmff/Demux.luau"], [1214, "src/Rosetta/containers/IsoBmff/Meta.luau"], [1736, "src/Rosetta/containers/IsoBmff/Mux.luau"], [2253, "src/Rosetta/containers/IsoBmff/QtPalette.luau"]], +"containers_MacFile": [[8, "src/Rosetta/containers/MacFile.luau"], [157, "src/Rosetta/containers/Ogg/init.luau"], [582, "src/Rosetta/containers/Ogg/Mux.luau"], [771, "src/Rosetta/containers/Ogg/Page.luau"]], +"containers_Riff": [[8, "src/Rosetta/containers/Riff/init.luau"], [325, "src/Rosetta/containers/Tar.luau"]], +"containers_Zip": [[8, "src/Rosetta/containers/Zip/init.luau"]], +"core_Adler32": [[8, "src/Rosetta/core/Adler32.luau"], [68, "src/Rosetta/core/Base64.luau"], [296, "src/Rosetta/core/Bits.luau"], [589, "src/Rosetta/core/Crc32.luau"], [740, "src/Rosetta/core/Md5.luau"]], +"data_cbor": [[8, "src/Rosetta/data/cbor/init.luau"], [107, "src/Rosetta/data/cbor/Codec.luau"], [676, "src/Rosetta/data/csv/init.luau"]], +"data_ini": [[8, "src/Rosetta/data/ini/init.luau"], [254, "src/Rosetta/data/json/init.luau"], [346, "src/Rosetta/data/msgpack/init.luau"], [435, "src/Rosetta/data/msgpack/Codec.luau"], [877, "src/Rosetta/data/nbt/init.luau"]], +"data_plist": [[8, "src/Rosetta/data/plist/init.luau"], [314, "src/Rosetta/data/plist/Binary.luau"], [581, "src/Rosetta/data/q3shader/init.luau"], [820, "src/Rosetta/data/q3skin/init.luau"], [916, "src/Rosetta/data/snbt/init.luau"]], +"data_toml": [[8, "src/Rosetta/data/toml/init.luau"], [75, "src/Rosetta/data/toml/Decode.luau"], [703, "src/Rosetta/data/toml/Encode.luau"], [912, "src/Rosetta/data/tres/init.luau"], [1057, "src/Rosetta/data/vdf/init.luau"]], +"data_xml": [[8, "src/Rosetta/data/xml/init.luau"]], +"data_yaml": [[8, "src/Rosetta/data/yaml/init.luau"], [81, "src/Rosetta/data/yaml/Emit.luau"], [371, "src/Rosetta/data/yaml/Parse.luau"]], +"font_bdf": [[8, "src/Rosetta/font/bdf/init.luau"]], +"font_bmfont": [[8, "src/Rosetta/font/bmfont/init.luau"], [435, "src/Rosetta/font/bmfont/Parse.luau"], [888, "src/Rosetta/font/eot/init.luau"]], +"font_fon": [[8, "src/Rosetta/font/fon/init.luau"], [291, "src/Rosetta/font/hershey/init.luau"], [486, "src/Rosetta/font/pcf/init.luau"]], +"font_psf": [[8, "src/Rosetta/font/psf/init.luau"], [328, "src/Rosetta/font/ttf/init.luau"], [379, "src/Rosetta/font/type1/init.luau"], [738, "src/Rosetta/font/type1/Charstring.luau"]], +"font_woff": [[8, "src/Rosetta/font/woff/init.luau"], [140, "src/Rosetta/font/woff2/init.luau"], [197, "src/Rosetta/font/woff2/Rebuild.luau"]], +"host_Love": [[8, "src/Rosetta/host/Love.luau"], [151, "src/Rosetta/host/LuaJIT.luau"], [201, "src/Rosetta/host/Luau.luau"], [224, "src/Rosetta/host/Roblox.luau"]], +"image_ani": [[8, "src/Rosetta/image/ani/init.luau"], [188, "src/Rosetta/image/art/init.luau"], [676, "src/Rosetta/image/blp/init.luau"]], +"image_bmp": [[8, "src/Rosetta/image/bmp/init.luau"], [423, "src/Rosetta/image/dds/init.luau"]], +"image_exr": [[8, "src/Rosetta/image/exr/init.luau"], [768, "src/Rosetta/image/exr/Codec.luau"], [879, "src/Rosetta/image/exr/Piz.luau"]], +"image_gif": [[8, "src/Rosetta/image/gif/init.luau"], [524, "src/Rosetta/image/gif/Decode.luau"], [600, "src/Rosetta/image/hdr/init.luau"], [829, "src/Rosetta/image/hdr/Codec.luau"]], +"image_icns": [[8, "src/Rosetta/image/icns/init.luau"], [339, "src/Rosetta/image/ico/init.luau"], [616, "src/Rosetta/image/ico/Dib.luau"]], +"image_ilbm": [[8, "src/Rosetta/image/ilbm/init.luau"], [327, "src/Rosetta/image/jpeg/init.luau"]], +"image_ktx": [[8, "src/Rosetta/image/ktx/init.luau"], [668, "src/Rosetta/image/lmp/init.luau"]], +"image_pcx": [[8, "src/Rosetta/image/pcx/init.luau"], [272, "src/Rosetta/image/pnm/init.luau"], [650, "src/Rosetta/image/pnm/Codec.luau"]], +"image_qoi": [[8, "src/Rosetta/image/qoi/init.luau"], [130, "src/Rosetta/image/qoi/Codec.luau"], [287, "src/Rosetta/image/sgi/init.luau"], [572, "src/Rosetta/image/spr/init.luau"]], +"image_sunras": [[8, "src/Rosetta/image/sunras/init.luau"], [254, "src/Rosetta/image/tga/init.luau"], [524, "src/Rosetta/image/tga/Codec.luau"]], +"image_tiff": [[8, "src/Rosetta/image/tiff/init.luau"], [835, "src/Rosetta/image/tiff/Pixels.luau"]], +"image_tim": [[8, "src/Rosetta/image/tim/init.luau"], [250, "src/Rosetta/image/vtf/init.luau"]], +"image_webp": [[8, "src/Rosetta/image/webp/init.luau"], [618, "src/Rosetta/image/webp/Alpha.luau"], [694, "src/Rosetta/image/webp/Anim.luau"], [849, "src/Rosetta/image/xbm/init.luau"]], +"image_xpm": [[8, "src/Rosetta/image/xpm/init.luau"], [276, "src/Rosetta/image/xpm/Names.luau"]], +"layered_aseprite": [[8, "src/Rosetta/layered/aseprite/init.luau"]], +"layered_ora": [[8, "src/Rosetta/layered/ora/init.luau"]], +"layered_psd": [[8, "src/Rosetta/layered/psd/init.luau"], [743, "src/Rosetta/layered/psd/Channels.luau"]], +"model_3ds": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"]], +"model_3mf": [[8, "src/Rosetta/model/3mf/init.luau"], [90, "src/Rosetta/model/3mf/Read.luau"], [678, "src/Rosetta/model/3mf/Write.luau"]], +"model_ase": [[8, "src/Rosetta/model/ase/init.luau"], [131, "src/Rosetta/model/ase/Build.luau"], [705, "src/Rosetta/model/ase/Parse.luau"], [774, "src/Rosetta/model/ase/Write.luau"]], +"model_b3d": [[8, "src/Rosetta/model/b3d/init.luau"], [63, "src/Rosetta/model/b3d/Read.luau"]], +"model_blend": [[8, "src/Rosetta/model/blend/init.luau"], [108, "src/Rosetta/model/blend/Anim.luau"], [638, "src/Rosetta/model/blend/Armature.luau"], [1174, "src/Rosetta/model/blend/Driver.luau"], [1349, "src/Rosetta/model/blend/Material.luau"], [1701, "src/Rosetta/model/blend/Mesh.luau"], [2389, "src/Rosetta/model/blend/Normals.luau"], [2550, "src/Rosetta/model/blend/Prim.luau"], [3057, "src/Rosetta/model/blend/Read.luau"]], +"model_bsp": [[8, "src/Rosetta/model/bsp/init.luau"], [199, "src/Rosetta/model/bsp/Lightmap.luau"], [265, "src/Rosetta/model/bsp/Quake.luau"], [654, "src/Rosetta/model/bsp/Quake3.luau"], [883, "src/Rosetta/model/bsp/Tree.luau"]], +"model_buildmap": [[8, "src/Rosetta/model/buildmap/init.luau"], [280, "src/Rosetta/model/buildmap/Geometry.luau"]], +"model_d3map": [[8, "src/Rosetta/model/d3map/init.luau"], [290, "src/Rosetta/model/d3map/Parse.luau"]], +"model_dae": [[8, "src/Rosetta/model/dae/init.luau"], [197, "src/Rosetta/model/dae/Math.luau"], [244, "src/Rosetta/model/dae/Read.luau"], [2094, "src/Rosetta/model/dae/Write.luau"]], +"model_fbx": [[8, "src/Rosetta/model/fbx/init.luau"], [156, "src/Rosetta/model/fbx/Ascii.luau"], [426, "src/Rosetta/model/fbx/Binary.luau"], [881, "src/Rosetta/model/fbx/Read.luau"], [2243, "src/Rosetta/model/fbx/Write.luau"], [3228, "src/Rosetta/model/fbx/Xform.luau"]], +"model_gltf": [[8, "src/Rosetta/model/gltf/init.luau"], [245, "src/Rosetta/model/gltf/Pack.luau"], [314, "src/Rosetta/model/gltf/Read.luau"], [1055, "src/Rosetta/model/gltf/Write.luau"]], +"model_godot": [[8, "src/Rosetta/model/godot/init.luau"], [99, "src/Rosetta/model/godot/Build.luau"], [641, "src/Rosetta/model/godot/Primitives.luau"], [916, "src/Rosetta/model/godot/Surface.luau"], [1401, "src/Rosetta/model/godot/Write.luau"]], +"model_iqm": [[8, "src/Rosetta/model/iqm/init.luau"], [84, "src/Rosetta/model/iqm/Read.luau"], [439, "src/Rosetta/model/iqm/Write.luau"]], +"model_ldraw": [[8, "src/Rosetta/model/ldraw/init.luau"], [86, "src/Rosetta/model/ldraw/Colors.luau"], [404, "src/Rosetta/model/ldraw/Read.luau"]], +"model_lwo": [[8, "src/Rosetta/model/lwo/init.luau"], [84, "src/Rosetta/model/lwo/Build.luau"], [546, "src/Rosetta/model/lwo/Parse.luau"]], +"model_map": [[8, "src/Rosetta/model/map/init.luau"], [325, "src/Rosetta/model/map/Build.luau"], [569, "src/Rosetta/model/map/Parse.luau"], [954, "src/Rosetta/model/map/Write.luau"]], +"model_mca": [[8, "src/Rosetta/model/mca/init.luau"], [350, "src/Rosetta/model/mca/Chunk.luau"], [483, "src/Rosetta/model/mca/Lz4Block.luau"], [553, "src/Rosetta/model/md2/init.luau"]], +"model_md3": [[8, "src/Rosetta/model/md3/init.luau"], [236, "src/Rosetta/model/md5/init.luau"], [317, "src/Rosetta/model/md5/Read.luau"]], +"model_mdl": [[8, "src/Rosetta/model/mdl/init.luau"], [90, "src/Rosetta/model/mdl/HalfLife.luau"], [394, "src/Rosetta/model/mdl/Quake.luau"]], +"model_ms3d": [[8, "src/Rosetta/model/ms3d/init.luau"], [80, "src/Rosetta/model/ms3d/Read.luau"], [526, "src/Rosetta/model/ms3d/Write.luau"]], +"model_obj": [[8, "src/Rosetta/model/obj/init.luau"], [826, "src/Rosetta/model/obj/Mtl.luau"]], +"model_off": [[8, "src/Rosetta/model/off/init.luau"]], +"model_ply": [[8, "src/Rosetta/model/ply/init.luau"], [1113, "src/Rosetta/model/ply/Binary.luau"]], +"model_pmx": [[8, "src/Rosetta/model/pmx/init.luau"], [77, "src/Rosetta/model/pmx/Build.luau"], [373, "src/Rosetta/model/pmx/Pmd.luau"], [708, "src/Rosetta/model/pmx/Read.luau"]], +"model_proc": [[8, "src/Rosetta/model/proc/init.luau"], [390, "src/Rosetta/model/qb/init.luau"]], +"model_rbxm": [[8, "src/Rosetta/model/rbxm/init.luau"]], +"model_rbxmx": [[8, "src/Rosetta/model/rbxmx/init.luau"]], +"model_robloxmesh": [[8, "src/Rosetta/model/robloxmesh/init.luau"], [667, "src/Rosetta/model/robloxmesh/Parse.luau"], [1124, "src/Rosetta/model/robloxmesh/Write.luau"]], +"model_schematic": [[8, "src/Rosetta/model/schematic/init.luau"], [329, "src/Rosetta/model/schematic/Common.luau"], [449, "src/Rosetta/model/schematic/Litematic.luau"], [660, "src/Rosetta/model/schematic/Mcedit.luau"], [904, "src/Rosetta/model/schematic/Sponge.luau"]], +"model_smd": [[8, "src/Rosetta/model/smd/init.luau"], [75, "src/Rosetta/model/smd/Read.luau"], [344, "src/Rosetta/model/smd/Write.luau"]], +"model_sourcemdl": [[8, "src/Rosetta/model/sourcemdl/init.luau"], [179, "src/Rosetta/model/sourcemdl/Build.luau"], [609, "src/Rosetta/model/sourcemdl/Material.luau"], [770, "src/Rosetta/model/sourcemdl/Mdl.luau"], [1297, "src/Rosetta/model/sourcemdl/Phy.luau"], [1420, "src/Rosetta/model/sourcemdl/Vtx.luau"], [1602, "src/Rosetta/model/sourcemdl/Vvd.luau"]], +"model_stl": [[8, "src/Rosetta/model/stl/init.luau"], [458, "src/Rosetta/model/stl/Decode.luau"]], +"model_t3d": [[8, "src/Rosetta/model/t3d/init.luau"], [102, "src/Rosetta/model/t3d/Build.luau"], [507, "src/Rosetta/model/t3d/Parse.luau"], [675, "src/Rosetta/model/udmf/init.luau"]], +"model_usda": [[8, "src/Rosetta/model/usda/init.luau"], [217, "src/Rosetta/model/usda/Build.luau"], [1495, "src/Rosetta/model/usda/Parse.luau"], [2293, "src/Rosetta/model/usda/Write.luau"]], +"model_vbsp": [[8, "src/Rosetta/model/vbsp/init.luau"], [454, "src/Rosetta/model/vbsp/Faces.luau"], [678, "src/Rosetta/model/vbsp/Props.luau"]], +"model_vmf": [[8, "src/Rosetta/model/vmf/init.luau"], [333, "src/Rosetta/model/vmf/Build.luau"]], +"model_vox": [[8, "src/Rosetta/model/vox/init.luau"], [894, "src/Rosetta/model/vox/Grid.luau"], [951, "src/Rosetta/model/vrml/init.luau"]], +"model_x": [[8, "src/Rosetta/model/x/init.luau"], [138, "src/Rosetta/model/x/Build.luau"], [701, "src/Rosetta/model/x/Parse.luau"]], +"model_x3d": [[8, "src/Rosetta/model/x3d/init.luau"]], +"music_669": [[8, "src/Rosetta/music/669/init.luau"], [215, "src/Rosetta/music/ahx/init.luau"], [267, "src/Rosetta/music/far/init.luau"], [497, "src/Rosetta/music/hmp/init.luau"], [762, "src/Rosetta/music/hvl/init.luau"]], +"music_it": [[8, "src/Rosetta/music/it/init.luau"], [427, "src/Rosetta/music/it/Itsex.luau"]], +"music_med": [[8, "src/Rosetta/music/med/init.luau"]], +"music_midi": [[8, "src/Rosetta/music/midi/init.luau"], [152, "src/Rosetta/music/midi/Smf.luau"], [564, "src/Rosetta/music/mod/init.luau"]], +"music_mtm": [[8, "src/Rosetta/music/mtm/init.luau"], [231, "src/Rosetta/music/mus/init.luau"], [389, "src/Rosetta/music/okt/init.luau"], [671, "src/Rosetta/music/ptm/init.luau"]], +"music_s3m": [[8, "src/Rosetta/music/s3m/init.luau"], [245, "src/Rosetta/music/sf2/init.luau"], [289, "src/Rosetta/music/stm/init.luau"], [521, "src/Rosetta/music/ult/init.luau"], [826, "src/Rosetta/music/umx/init.luau"]], +"music_xm": [[8, "src/Rosetta/music/xm/init.luau"], [570, "src/Rosetta/music/xmi/init.luau"]], +"ops_AudioOps": [[8, "src/Rosetta/ops/AudioOps.luau"]], +"ops_ImageOps": [[8, "src/Rosetta/ops/ImageOps/init.luau"], [656, "src/Rosetta/ops/ImageOps/Kernels.luau"]], +"ops_LayerOps": [[8, "src/Rosetta/ops/LayerOps.luau"]], +"ops_MeshOps": [[8, "src/Rosetta/ops/MeshOps/init.luau"], [1148, "src/Rosetta/ops/MeshOps/Greedy.luau"]], +"ops_MusicOps": [[8, "src/Rosetta/ops/MusicOps.luau"]], +"playlist_m3u": [[8, "src/Rosetta/playlist/m3u/init.luau"], [361, "src/Rosetta/playlist/pls/init.luau"], [539, "src/Rosetta/playlist/xspf/init.luau"]], +"subtitle_ass": [[8, "src/Rosetta/subtitle/ass/init.luau"], [452, "src/Rosetta/subtitle/srt/init.luau"], [625, "src/Rosetta/subtitle/vtt/init.luau"]], +"vector_gamemaps": [[8, "src/Rosetta/vector/gamemaps/init.luau"], [195, "src/Rosetta/vector/gamemaps/Expand.luau"]], +"vector_ldtk": [[8, "src/Rosetta/vector/ldtk/init.luau"], [100, "src/Rosetta/vector/ldtk/Read.luau"], [436, "src/Rosetta/vector/ldtk/Write.luau"]], +"vector_ogmo": [[8, "src/Rosetta/vector/ogmo/init.luau"], [127, "src/Rosetta/vector/ogmo/Read.luau"], [532, "src/Rosetta/vector/ogmo/Write.luau"]], +"vector_svg": [[8, "src/Rosetta/vector/svg/init.luau"], [94, "src/Rosetta/vector/svg/Parse.luau"], [840, "src/Rosetta/vector/svg/PathData.luau"], [1208, "src/Rosetta/vector/svg/Render.luau"], [1625, "src/Rosetta/vector/svg/Style.luau"], [1997, "src/Rosetta/vector/svg/Write.luau"]], +"vector_tiled": [[8, "src/Rosetta/vector/tiled/init.luau"], [188, "src/Rosetta/vector/tiled/Data.luau"], [339, "src/Rosetta/vector/tiled/Tmj.luau"], [970, "src/Rosetta/vector/tiled/Tmx.luau"]], +"video_avi": [[8, "src/Rosetta/video/avi/init.luau"], [302, "src/Rosetta/video/fli/init.luau"]], +"video_flv": [[8, "src/Rosetta/video/flv/init.luau"], [392, "src/Rosetta/video/flv/Amf.luau"], [550, "src/Rosetta/video/flv/Mux.luau"], [831, "src/Rosetta/video/h264/init.luau"]], +"video_mkv": [[8, "src/Rosetta/video/mkv/init.luau"], [164, "src/Rosetta/video/mkv/Mux.luau"], [443, "src/Rosetta/video/mkv/Parse.luau"]], +"video_mp4": [[8, "src/Rosetta/video/mp4/init.luau"], [336, "src/Rosetta/video/mpegps/init.luau"], [523, "src/Rosetta/video/mpegts/init.luau"]], +"video_ogv": [[8, "src/Rosetta/video/ogv/init.luau"], [403, "src/Rosetta/video/smk/init.luau"], [712, "src/Rosetta/video/smk/Audio.luau"], [832, "src/Rosetta/video/y4m/init.luau"]] } diff --git a/build/Rosetta.rbxmx b/build/Rosetta.rbxmx index 953ec14..51d9b33 100644 --- a/build/Rosetta.rbxmx +++ b/build/Rosetta.rbxmx @@ -9,24 +9,16 @@ -- required on the first include of one of them. require(this) -> the API (docs/API.md); -- Rosetta._internal("codecs/video/Mpeg1") -> an internal module. local __CHUNK = { - [""] = "Core_1", - ["Registry"] = "Core_1", - ["Types"] = "Core_1", - ["codecs/audio/Adpcm"] = "Core_1", - ["codecs/image/Yuv"] = "Core_1", - ["codecs/model/Rbx"] = "Core_1", - ["codecs/video/Video"] = "Core_1", - ["codecs/video/Video/Disposable"] = "Core_1", - ["codecs/video/Video/Pool"] = "Core_1", - ["containers/AudioWrap"] = "Core_1", - ["containers/Ogg/Mux"] = "Core_1", - ["core/Bytes"] = "Core_2", - ["core/Crc32"] = "Core_2", - ["core/Err"] = "Core_2", - ["core/Input"] = "Core_2", - ["host"] = "Core_2", - ["ops/ImageOps"] = "Core_2", - ["ops/ImageOps/Kernels"] = "Core_2", + [""] = "Core", + ["Registry"] = "Core", + ["Types"] = "Core", + ["core/Bytes"] = "Core", + ["core/Err"] = "Core", + ["core/Input"] = "Core", + ["host"] = "Core", + ["Sniffs"] = "Detect", + ["core/Crc16"] = "Detect", + ["core/Sniff"] = "Detect", ["codecs/video/Dsp"] = "Mpeg2", ["codecs/video/Mpeg1"] = "Mpeg2", ["codecs/video/Mpeg2"] = "Mpeg2", @@ -162,474 +154,482 @@ local __CHUNK = { ["codecs/model/Draco/KdTree"] = "Draco", ["codecs/model/Draco/Predict"] = "Draco", ["codecs/model/Draco/Reader"] = "Draco", - ["Sniffs"] = "Root", - ["archive/7z"] = "archive_1", - ["archive/7z/Header"] = "archive_1", - ["archive/adf"] = "archive_1", - ["archive/applesingle"] = "archive_1", - ["archive/ar"] = "archive_1", - ["archive/arj"] = "archive_1", - ["archive/binhex"] = "archive_1", - ["archive/br"] = "archive_1", - ["archive/bz2"] = "archive_1", - ["archive/cab"] = "archive_1", - ["archive/cab/Sum"] = "archive_1", - ["archive/cpio"] = "archive_1", - ["archive/d64"] = "archive_1", - ["archive/fat"] = "archive_1", - ["archive/grp"] = "archive_1", - ["archive/gzip"] = "archive_1", - ["archive/iso"] = "archive_1", - ["archive/lha"] = "archive_1", - ["archive/lz4"] = "archive_1", - ["archive/macbinary"] = "archive_1", - ["archive/mpq"] = "archive_1", - ["archive/mpq/Crypt"] = "archive_1", - ["archive/pak"] = "archive_1", - ["archive/rpm"] = "archive_1", - ["archive/tar"] = "archive_1", - ["archive/unitypackage"] = "archive_1", - ["archive/uu"] = "archive_1", - ["archive/vpk"] = "archive_1", - ["archive/vswap"] = "archive_1", - ["archive/wad"] = "archive_1", - ["archive/wad/Picture"] = "archive_1", - ["archive/wad2"] = "archive_1", - ["archive/xz"] = "archive_1", - ["archive/yenc"] = "archive_2", - ["archive/z"] = "archive_2", - ["archive/zip"] = "archive_2", - ["archive/zoo"] = "archive_2", - ["archive/zst"] = "archive_2", - ["audio/aac"] = "audio", - ["audio/ac3"] = "audio", - ["audio/adpcm"] = "audio", - ["audio/adx"] = "audio", - ["audio/aiff"] = "audio", - ["audio/ape"] = "audio", - ["audio/au"] = "audio", - ["audio/brstm"] = "audio", - ["audio/caf"] = "audio", - ["audio/flac"] = "audio", - ["audio/flac/Meta"] = "audio", - ["audio/flac/Stream"] = "audio", - ["audio/m4a"] = "audio", - ["audio/mp3"] = "audio", - ["audio/mp3/Index"] = "audio", - ["audio/mp3/Stream"] = "audio", - ["audio/mp3/Tags"] = "audio", - ["audio/mpc"] = "audio", - ["audio/opus"] = "audio", - ["audio/opus/Encode"] = "audio", - ["audio/qoa"] = "audio", - ["audio/tta"] = "audio", - ["audio/vag"] = "audio", - ["audio/voc"] = "audio", - ["audio/vorbis"] = "audio", - ["audio/vorbis/Encode"] = "audio", - ["audio/wav"] = "audio", - ["audio/wav/Codecs"] = "audio", - ["audio/wavpack"] = "audio", - ["cad/step"] = "cad", - ["cad/step/Brep"] = "cad", - ["cad/step/Parse"] = "cad", - ["cad/step/Write"] = "cad", - ["codecs/audio/Ac3"] = "codecs_audio", - ["codecs/audio/Ac3/Decode"] = "codecs_audio", - ["codecs/audio/Ac3/Tables"] = "codecs_audio", - ["codecs/audio/Adpcm/Decoder"] = "codecs_audio", - ["codecs/audio/Alac"] = "codecs_audio", - ["codecs/audio/Alac/Decode"] = "codecs_audio", - ["codecs/audio/Alac/Encode"] = "codecs_audio", - ["codecs/audio/Ape"] = "codecs_audio", - ["codecs/audio/Ape/Decode"] = "codecs_audio", - ["codecs/audio/ApeTag"] = "codecs_audio", - ["codecs/audio/Mdct"] = "codecs_audio", - ["codecs/audio/Mdct/Fft"] = "codecs_audio", - ["codecs/audio/MidiRender"] = "codecs_audio", - ["codecs/audio/Pcm"] = "codecs_audio", - ["codecs/audio/Pcm/Convert"] = "codecs_audio", - ["codecs/audio/Qoa"] = "codecs_audio", - ["codecs/audio/Resample"] = "codecs_audio", - ["codecs/audio/Stream"] = "codecs_audio", - ["codecs/audio/Tta"] = "codecs_audio", - ["codecs/audio/Tta/Decode"] = "codecs_audio", - ["codecs/audio/VorbisComment"] = "codecs_audio", - ["codecs/compress/Bzip2"] = "codecs_compress", - ["codecs/compress/Bzip2/Decode"] = "codecs_compress", - ["codecs/compress/Explode"] = "codecs_compress", - ["codecs/compress/Lz4"] = "codecs_compress", - ["codecs/compress/Lzh"] = "codecs_compress", - ["codecs/compress/Lzw"] = "codecs_compress", - ["codecs/compress/Lzx"] = "codecs_compress", - ["codecs/compress/PackBits"] = "codecs_compress", - ["codecs/compress/Quantum"] = "codecs_compress", - ["codecs/compress/UnixCompress"] = "codecs_compress", - ["codecs/compress/Xxh32"] = "codecs_compress", - ["codecs/entropy/Huffman"] = "codecs_entropy", - ["codecs/entropy/RangeCoder"] = "codecs_entropy", - ["codecs/entropy/RangeCoder/Decoder"] = "codecs_entropy", - ["codecs/entropy/RangeCoder/Encoder"] = "codecs_entropy", - ["codecs/font/Bitmap"] = "codecs_font", - ["codecs/font/Cff"] = "codecs_font", - ["codecs/font/GlyphNames"] = "codecs_font", - ["codecs/font/TrueType"] = "codecs_font", - ["codecs/font/TrueType/Glyf"] = "codecs_font", - ["codecs/font/TrueType/Tables"] = "codecs_font", - ["codecs/image/Blend"] = "codecs_image", - ["codecs/image/Etc"] = "codecs_image", - ["codecs/image/Half"] = "codecs_image", - ["codecs/image/Miptex"] = "codecs_image", - ["codecs/image/Pixels"] = "codecs_image", - ["codecs/image/Quantize"] = "codecs_image", - ["codecs/image/Raster"] = "codecs_image", - ["codecs/image/Texel"] = "codecs_image", - ["codecs/image/Texture"] = "codecs_image", - ["codecs/model/Brush"] = "codecs_model", - ["codecs/model/Displacement"] = "codecs_model", - ["codecs/model/DoomMap"] = "codecs_model", - ["codecs/model/DoomMap/Udmf"] = "codecs_model", - ["codecs/model/Mat4"] = "codecs_model", - ["codecs/model/MeshFlatten"] = "codecs_model", - ["codecs/model/Minecraft"] = "codecs_model", - ["codecs/model/Minecraft/Colors"] = "codecs_model", - ["codecs/model/Minecraft/Legacy"] = "codecs_model", - ["codecs/model/Minecraft/Packed"] = "codecs_model", - ["codecs/model/Patch"] = "codecs_model", - ["codecs/model/Polygon"] = "codecs_model", - ["codecs/model/Rbx/Binary"] = "codecs_model", - ["codecs/model/Rig"] = "codecs_model", - ["codecs/model/Sampler"] = "codecs_model", - ["codecs/model/SourceAnim"] = "codecs_model", - ["codecs/model/Vrml"] = "codecs_model", - ["codecs/model/Vrml/Build"] = "codecs_model", - ["codecs/model/Vrml/Fields"] = "codecs_model", - ["codecs/model/Vrml/Geometry"] = "codecs_model", - ["codecs/model/Vrml/Parse"] = "codecs_model", - ["codecs/model/Vrml/Write"] = "codecs_model", - ["codecs/model/Vrml/Xml"] = "codecs_model", - ["codecs/text/GodotVariant"] = "codecs_text", - ["codecs/text/Json"] = "codecs_text", - ["codecs/text/Json/Decode"] = "codecs_text", - ["codecs/text/Json/Encode"] = "codecs_text", - ["codecs/text/KeyValues"] = "codecs_text", - ["codecs/text/KeyValues/Binary"] = "codecs_text", - ["codecs/text/Lexer"] = "codecs_text", - ["codecs/text/Nbt"] = "codecs_text", - ["codecs/text/Nbt/Binary"] = "codecs_text", - ["codecs/text/Nbt/Snbt"] = "codecs_text", - ["codecs/text/Nbt/Value"] = "codecs_text", - ["codecs/text/Text"] = "codecs_text", - ["codecs/text/Url"] = "codecs_text", - ["codecs/text/Xml"] = "codecs_text", - ["codecs/text/Xml/Parse"] = "codecs_text", - ["codecs/video/Video/Source"] = "codecs_video", - ["containers/Archive"] = "containers", - ["containers/Avi"] = "containers", - ["containers/Blend"] = "containers", - ["containers/Chunks"] = "containers", - ["containers/Cpio"] = "containers", - ["containers/Demux"] = "containers", - ["containers/Ebml"] = "containers", - ["containers/Fat"] = "containers", - ["containers/Iso9660"] = "containers", - ["containers/IsoBmff"] = "containers", - ["containers/IsoBmff/Box"] = "containers", - ["containers/IsoBmff/Demux"] = "containers", - ["containers/IsoBmff/Meta"] = "containers", - ["containers/IsoBmff/Mux"] = "containers", - ["containers/IsoBmff/QtPalette"] = "containers", - ["containers/MacFile"] = "containers", - ["containers/Ogg"] = "containers", - ["containers/Ogg/Page"] = "containers", - ["containers/Riff"] = "containers", - ["containers/Tar"] = "containers", - ["containers/Zip"] = "containers", - ["core/Adler32"] = "core", - ["core/Base64"] = "core", - ["core/Bits"] = "core", - ["core/Crc16"] = "core", - ["core/Md5"] = "core", - ["core/Sniff"] = "core", - ["data/cbor"] = "data", - ["data/cbor/Codec"] = "data", - ["data/csv"] = "data", - ["data/ini"] = "data", - ["data/json"] = "data", - ["data/msgpack"] = "data", - ["data/msgpack/Codec"] = "data", - ["data/nbt"] = "data", - ["data/plist"] = "data", - ["data/plist/Binary"] = "data", - ["data/q3shader"] = "data", - ["data/q3skin"] = "data", - ["data/snbt"] = "data", - ["data/toml"] = "data", - ["data/toml/Decode"] = "data", - ["data/toml/Encode"] = "data", - ["data/tres"] = "data", - ["data/vdf"] = "data", - ["data/xml"] = "data", - ["data/yaml"] = "data", - ["data/yaml/Emit"] = "data", - ["data/yaml/Parse"] = "data", - ["font/bdf"] = "font", - ["font/bmfont"] = "font", - ["font/bmfont/Parse"] = "font", - ["font/eot"] = "font", - ["font/fon"] = "font", - ["font/hershey"] = "font", - ["font/pcf"] = "font", - ["font/psf"] = "font", - ["font/ttf"] = "font", - ["font/type1"] = "font", - ["font/type1/Charstring"] = "font", - ["font/woff"] = "font", - ["font/woff2"] = "font", - ["font/woff2/Rebuild"] = "font", - ["host/Love"] = "host", - ["host/LuaJIT"] = "host", - ["host/Luau"] = "host", - ["host/Roblox"] = "host", - ["image/ani"] = "image_1", - ["image/art"] = "image_1", - ["image/blp"] = "image_1", - ["image/bmp"] = "image_1", - ["image/dds"] = "image_1", - ["image/exr"] = "image_1", - ["image/exr/Codec"] = "image_1", - ["image/exr/Piz"] = "image_1", - ["image/gif"] = "image_1", - ["image/gif/Decode"] = "image_1", - ["image/hdr"] = "image_1", - ["image/hdr/Codec"] = "image_1", - ["image/icns"] = "image_1", - ["image/ico"] = "image_1", - ["image/ico/Dib"] = "image_1", - ["image/ilbm"] = "image_1", - ["image/jpeg"] = "image_1", - ["image/ktx"] = "image_1", - ["image/lmp"] = "image_1", - ["image/pcx"] = "image_1", - ["image/pnm"] = "image_1", - ["image/pnm/Codec"] = "image_1", - ["image/qoi"] = "image_1", - ["image/qoi/Codec"] = "image_1", - ["image/sgi"] = "image_1", - ["image/spr"] = "image_2", - ["image/sunras"] = "image_2", - ["image/tga"] = "image_2", - ["image/tga/Codec"] = "image_2", - ["image/tiff"] = "image_2", - ["image/tiff/Pixels"] = "image_2", - ["image/tim"] = "image_2", - ["image/vtf"] = "image_2", - ["image/webp"] = "image_2", - ["image/webp/Alpha"] = "image_2", - ["image/webp/Anim"] = "image_2", - ["image/xbm"] = "image_2", - ["image/xpm"] = "image_2", - ["image/xpm/Names"] = "image_2", - ["layered/aseprite"] = "layered", - ["layered/ora"] = "layered", - ["layered/psd"] = "layered", - ["layered/psd/Channels"] = "layered", - ["model/3ds"] = "model_1", - ["model/3ds/Build"] = "model_1", - ["model/3ds/Read"] = "model_1", - ["model/3ds/Write"] = "model_1", - ["model/3mf"] = "model_1", - ["model/3mf/Read"] = "model_1", - ["model/3mf/Write"] = "model_1", - ["model/ase"] = "model_1", - ["model/ase/Build"] = "model_1", - ["model/ase/Parse"] = "model_1", - ["model/ase/Write"] = "model_1", - ["model/b3d"] = "model_1", - ["model/b3d/Read"] = "model_1", - ["model/blend"] = "model_1", - ["model/blend/Anim"] = "model_1", - ["model/blend/Armature"] = "model_1", - ["model/blend/Driver"] = "model_1", - ["model/blend/Material"] = "model_1", - ["model/blend/Mesh"] = "model_1", - ["model/blend/Normals"] = "model_2", - ["model/blend/Prim"] = "model_2", - ["model/blend/Read"] = "model_2", - ["model/bsp"] = "model_2", - ["model/bsp/Lightmap"] = "model_2", - ["model/bsp/Quake"] = "model_2", - ["model/bsp/Quake3"] = "model_2", - ["model/bsp/Tree"] = "model_2", - ["model/buildmap"] = "model_2", - ["model/buildmap/Geometry"] = "model_2", - ["model/d3map"] = "model_2", - ["model/d3map/Parse"] = "model_2", - ["model/dae"] = "model_2", - ["model/dae/Math"] = "model_2", - ["model/dae/Read"] = "model_2", - ["model/dae/Write"] = "model_2", - ["model/fbx"] = "model_2", - ["model/fbx/Ascii"] = "model_2", - ["model/fbx/Binary"] = "model_2", - ["model/fbx/Read"] = "model_3", - ["model/fbx/Write"] = "model_3", - ["model/fbx/Xform"] = "model_3", - ["model/gltf"] = "model_3", - ["model/gltf/Pack"] = "model_3", - ["model/gltf/Read"] = "model_3", - ["model/gltf/Write"] = "model_3", - ["model/godot"] = "model_3", - ["model/godot/Build"] = "model_3", - ["model/godot/Primitives"] = "model_3", - ["model/godot/Surface"] = "model_3", - ["model/godot/Write"] = "model_3", - ["model/iqm"] = "model_3", - ["model/iqm/Read"] = "model_3", - ["model/iqm/Write"] = "model_3", - ["model/ldraw"] = "model_3", - ["model/ldraw/Colors"] = "model_3", - ["model/ldraw/Read"] = "model_4", - ["model/lwo"] = "model_4", - ["model/lwo/Build"] = "model_4", - ["model/lwo/Parse"] = "model_4", - ["model/map"] = "model_4", - ["model/map/Build"] = "model_4", - ["model/map/Parse"] = "model_4", - ["model/map/Write"] = "model_4", - ["model/mca"] = "model_4", - ["model/mca/Chunk"] = "model_4", - ["model/mca/Lz4Block"] = "model_4", - ["model/md2"] = "model_4", - ["model/md3"] = "model_4", - ["model/md5"] = "model_4", - ["model/md5/Read"] = "model_4", - ["model/mdl"] = "model_4", - ["model/mdl/HalfLife"] = "model_4", - ["model/mdl/Quake"] = "model_4", - ["model/ms3d"] = "model_4", - ["model/ms3d/Read"] = "model_4", - ["model/ms3d/Write"] = "model_4", - ["model/obj"] = "model_4", - ["model/obj/Mtl"] = "model_4", - ["model/off"] = "model_4", - ["model/ply"] = "model_5", - ["model/ply/Binary"] = "model_5", - ["model/pmx"] = "model_5", - ["model/pmx/Build"] = "model_5", - ["model/pmx/Pmd"] = "model_5", - ["model/pmx/Read"] = "model_5", - ["model/proc"] = "model_5", - ["model/qb"] = "model_5", - ["model/rbxm"] = "model_5", - ["model/rbxmx"] = "model_5", - ["model/robloxmesh"] = "model_5", - ["model/robloxmesh/Parse"] = "model_5", - ["model/robloxmesh/Write"] = "model_5", - ["model/schematic"] = "model_5", - ["model/schematic/Common"] = "model_5", - ["model/schematic/Litematic"] = "model_5", - ["model/schematic/Mcedit"] = "model_5", - ["model/schematic/Sponge"] = "model_5", - ["model/smd"] = "model_5", - ["model/smd/Read"] = "model_5", - ["model/smd/Write"] = "model_5", - ["model/sourcemdl"] = "model_5", - ["model/sourcemdl/Build"] = "model_5", - ["model/sourcemdl/Material"] = "model_5", - ["model/sourcemdl/Mdl"] = "model_6", - ["model/sourcemdl/Phy"] = "model_6", - ["model/sourcemdl/Vtx"] = "model_6", - ["model/sourcemdl/Vvd"] = "model_6", - ["model/stl"] = "model_6", - ["model/stl/Decode"] = "model_6", - ["model/t3d"] = "model_6", - ["model/t3d/Build"] = "model_6", - ["model/t3d/Parse"] = "model_6", - ["model/udmf"] = "model_6", - ["model/usda"] = "model_6", - ["model/usda/Build"] = "model_6", - ["model/usda/Parse"] = "model_6", - ["model/usda/Write"] = "model_6", - ["model/vbsp"] = "model_6", - ["model/vbsp/Faces"] = "model_6", - ["model/vbsp/Props"] = "model_6", - ["model/vmf"] = "model_6", - ["model/vmf/Build"] = "model_6", - ["model/vox"] = "model_6", - ["model/vox/Grid"] = "model_6", - ["model/vrml"] = "model_6", - ["model/x"] = "model_6", - ["model/x/Build"] = "model_7", - ["model/x/Parse"] = "model_7", - ["model/x3d"] = "model_7", - ["music/669"] = "music", - ["music/ahx"] = "music", - ["music/far"] = "music", - ["music/hmp"] = "music", - ["music/hvl"] = "music", - ["music/it"] = "music", - ["music/it/Itsex"] = "music", - ["music/med"] = "music", - ["music/midi"] = "music", - ["music/midi/Smf"] = "music", - ["music/mod"] = "music", - ["music/mtm"] = "music", - ["music/mus"] = "music", - ["music/okt"] = "music", - ["music/ptm"] = "music", - ["music/s3m"] = "music", - ["music/sf2"] = "music", - ["music/stm"] = "music", - ["music/ult"] = "music", - ["music/umx"] = "music", - ["music/xm"] = "music", - ["music/xmi"] = "music", - ["ops/AudioOps"] = "ops", - ["ops/LayerOps"] = "ops", - ["ops/MeshOps"] = "ops", - ["ops/MeshOps/Greedy"] = "ops", - ["ops/MusicOps"] = "ops", - ["playlist/m3u"] = "playlist", - ["playlist/pls"] = "playlist", - ["playlist/xspf"] = "playlist", - ["subtitle/ass"] = "subtitle", - ["subtitle/srt"] = "subtitle", - ["subtitle/vtt"] = "subtitle", - ["vector/gamemaps"] = "vector", - ["vector/gamemaps/Expand"] = "vector", - ["vector/ldtk"] = "vector", - ["vector/ldtk/Read"] = "vector", - ["vector/ldtk/Write"] = "vector", - ["vector/ogmo"] = "vector", - ["vector/ogmo/Read"] = "vector", - ["vector/ogmo/Write"] = "vector", - ["vector/svg"] = "vector", - ["vector/svg/Parse"] = "vector", - ["vector/svg/PathData"] = "vector", - ["vector/svg/Render"] = "vector", - ["vector/svg/Style"] = "vector", - ["vector/svg/Write"] = "vector", - ["vector/tiled"] = "vector", - ["vector/tiled/Data"] = "vector", - ["vector/tiled/Tmj"] = "vector", - ["vector/tiled/Tmx"] = "vector", - ["video/avi"] = "video", - ["video/fli"] = "video", - ["video/flv"] = "video", - ["video/flv/Amf"] = "video", - ["video/flv/Mux"] = "video", - ["video/h264"] = "video", - ["video/mkv"] = "video", - ["video/mkv/Mux"] = "video", - ["video/mkv/Parse"] = "video", - ["video/mp4"] = "video", - ["video/mpegps"] = "video", - ["video/mpegts"] = "video", - ["video/ogv"] = "video", - ["video/smk"] = "video", - ["video/smk/Audio"] = "video", - ["video/y4m"] = "video", + ["archive/7z"] = "archive_7z", + ["archive/7z/Header"] = "archive_7z", + ["archive/adf"] = "archive_7z", + ["archive/applesingle"] = "archive_applesingle", + ["archive/ar"] = "archive_applesingle", + ["archive/arj"] = "archive_applesingle", + ["archive/binhex"] = "archive_binhex", + ["archive/br"] = "archive_binhex", + ["archive/bz2"] = "archive_binhex", + ["archive/cab"] = "archive_binhex", + ["archive/cab/Sum"] = "archive_binhex", + ["archive/cpio"] = "archive_binhex", + ["archive/d64"] = "archive_d64", + ["archive/fat"] = "archive_d64", + ["archive/grp"] = "archive_d64", + ["archive/gzip"] = "archive_d64", + ["archive/iso"] = "archive_d64", + ["archive/lha"] = "archive_lha", + ["archive/lz4"] = "archive_lha", + ["archive/macbinary"] = "archive_lha", + ["archive/mpq"] = "archive_mpq", + ["archive/mpq/Crypt"] = "archive_mpq", + ["archive/pak"] = "archive_mpq", + ["archive/rpm"] = "archive_mpq", + ["archive/tar"] = "archive_tar", + ["archive/unitypackage"] = "archive_tar", + ["archive/uu"] = "archive_tar", + ["archive/vpk"] = "archive_tar", + ["archive/vswap"] = "archive_vswap", + ["archive/wad"] = "archive_vswap", + ["archive/wad/Picture"] = "archive_vswap", + ["archive/wad2"] = "archive_wad2", + ["archive/xz"] = "archive_wad2", + ["archive/yenc"] = "archive_wad2", + ["archive/z"] = "archive_wad2", + ["archive/zip"] = "archive_wad2", + ["archive/zoo"] = "archive_zoo", + ["archive/zst"] = "archive_zoo", + ["audio/aac"] = "audio_aac", + ["audio/ac3"] = "audio_aac", + ["audio/adpcm"] = "audio_aac", + ["audio/adx"] = "audio_aac", + ["audio/aiff"] = "audio_aiff", + ["audio/ape"] = "audio_aiff", + ["audio/au"] = "audio_aiff", + ["audio/brstm"] = "audio_aiff", + ["audio/caf"] = "audio_caf", + ["audio/flac"] = "audio_flac", + ["audio/flac/Meta"] = "audio_flac", + ["audio/flac/Stream"] = "audio_flac", + ["audio/m4a"] = "audio_flac", + ["audio/mp3"] = "audio_mp3", + ["audio/mp3/Index"] = "audio_mp3", + ["audio/mp3/Stream"] = "audio_mp3", + ["audio/mp3/Tags"] = "audio_mp3", + ["audio/mpc"] = "audio_mpc", + ["audio/opus"] = "audio_mpc", + ["audio/opus/Encode"] = "audio_mpc", + ["audio/qoa"] = "audio_mpc", + ["audio/tta"] = "audio_mpc", + ["audio/vag"] = "audio_vag", + ["audio/voc"] = "audio_vag", + ["audio/vorbis"] = "audio_vorbis", + ["audio/vorbis/Encode"] = "audio_vorbis", + ["audio/wav"] = "audio_wav", + ["audio/wav/Codecs"] = "audio_wav", + ["audio/wavpack"] = "audio_wav", + ["cad/step"] = "cad_step", + ["cad/step/Brep"] = "cad_step", + ["cad/step/Parse"] = "cad_step", + ["cad/step/Write"] = "cad_step", + ["codecs/audio/Ac3"] = "codecs_audio_Ac3", + ["codecs/audio/Ac3/Decode"] = "codecs_audio_Ac3", + ["codecs/audio/Ac3/Tables"] = "codecs_audio_Ac3", + ["codecs/audio/Adpcm"] = "codecs_audio_Adpcm", + ["codecs/audio/Adpcm/Decoder"] = "codecs_audio_Adpcm", + ["codecs/audio/Alac"] = "codecs_audio_Alac", + ["codecs/audio/Alac/Decode"] = "codecs_audio_Alac", + ["codecs/audio/Alac/Encode"] = "codecs_audio_Alac", + ["codecs/audio/Ape"] = "codecs_audio_Ape", + ["codecs/audio/Ape/Decode"] = "codecs_audio_Ape", + ["codecs/audio/ApeTag"] = "codecs_audio_Ape", + ["codecs/audio/Mdct"] = "codecs_audio_Mdct", + ["codecs/audio/Mdct/Fft"] = "codecs_audio_Mdct", + ["codecs/audio/MidiRender"] = "codecs_audio_Mdct", + ["codecs/audio/Pcm"] = "codecs_audio_Pcm", + ["codecs/audio/Pcm/Convert"] = "codecs_audio_Pcm", + ["codecs/audio/Qoa"] = "codecs_audio_Pcm", + ["codecs/audio/Resample"] = "codecs_audio_Resample", + ["codecs/audio/Stream"] = "codecs_audio_Resample", + ["codecs/audio/Tta"] = "codecs_audio_Resample", + ["codecs/audio/Tta/Decode"] = "codecs_audio_Resample", + ["codecs/audio/VorbisComment"] = "codecs_audio_Resample", + ["codecs/compress/Bzip2"] = "codecs_compress_Bzip2", + ["codecs/compress/Bzip2/Decode"] = "codecs_compress_Bzip2", + ["codecs/compress/Explode"] = "codecs_compress_Bzip2", + ["codecs/compress/Lz4"] = "codecs_compress_Bzip2", + ["codecs/compress/Lzh"] = "codecs_compress_Lzh", + ["codecs/compress/Lzw"] = "codecs_compress_Lzh", + ["codecs/compress/Lzx"] = "codecs_compress_Lzh", + ["codecs/compress/PackBits"] = "codecs_compress_PackBits", + ["codecs/compress/Quantum"] = "codecs_compress_PackBits", + ["codecs/compress/UnixCompress"] = "codecs_compress_PackBits", + ["codecs/compress/Xxh32"] = "codecs_compress_PackBits", + ["codecs/entropy/Huffman"] = "codecs_entropy_Huffman", + ["codecs/entropy/RangeCoder"] = "codecs_entropy_Huffman", + ["codecs/entropy/RangeCoder/Decoder"] = "codecs_entropy_Huffman", + ["codecs/entropy/RangeCoder/Encoder"] = "codecs_entropy_Huffman", + ["codecs/font/Bitmap"] = "codecs_font_Bitmap", + ["codecs/font/Cff"] = "codecs_font_Bitmap", + ["codecs/font/GlyphNames"] = "codecs_font_Bitmap", + ["codecs/font/TrueType"] = "codecs_font_TrueType", + ["codecs/font/TrueType/Glyf"] = "codecs_font_TrueType", + ["codecs/font/TrueType/Tables"] = "codecs_font_TrueType", + ["codecs/image/Blend"] = "codecs_image_Blend", + ["codecs/image/Etc"] = "codecs_image_Blend", + ["codecs/image/Half"] = "codecs_image_Blend", + ["codecs/image/Miptex"] = "codecs_image_Miptex", + ["codecs/image/Pixels"] = "codecs_image_Miptex", + ["codecs/image/Quantize"] = "codecs_image_Quantize", + ["codecs/image/Raster"] = "codecs_image_Raster", + ["codecs/image/Texel"] = "codecs_image_Texel", + ["codecs/image/Texture"] = "codecs_image_Texel", + ["codecs/image/Yuv"] = "codecs_image_Texel", + ["codecs/model/Brush"] = "codecs_model_Brush", + ["codecs/model/Displacement"] = "codecs_model_Brush", + ["codecs/model/DoomMap"] = "codecs_model_DoomMap", + ["codecs/model/DoomMap/Udmf"] = "codecs_model_DoomMap", + ["codecs/model/Mat4"] = "codecs_model_DoomMap", + ["codecs/model/MeshFlatten"] = "codecs_model_MeshFlatten", + ["codecs/model/Minecraft"] = "codecs_model_Minecraft", + ["codecs/model/Minecraft/Colors"] = "codecs_model_Minecraft", + ["codecs/model/Minecraft/Legacy"] = "codecs_model_Minecraft", + ["codecs/model/Minecraft/Packed"] = "codecs_model_Minecraft", + ["codecs/model/Patch"] = "codecs_model_Patch", + ["codecs/model/Polygon"] = "codecs_model_Patch", + ["codecs/model/Rbx"] = "codecs_model_Rbx", + ["codecs/model/Rbx/Binary"] = "codecs_model_Rbx", + ["codecs/model/Rig"] = "codecs_model_Rig", + ["codecs/model/Sampler"] = "codecs_model_Rig", + ["codecs/model/SourceAnim"] = "codecs_model_Rig", + ["codecs/model/Vrml"] = "codecs_model_Vrml", + ["codecs/model/Vrml/Build"] = "codecs_model_Vrml", + ["codecs/model/Vrml/Fields"] = "codecs_model_Vrml", + ["codecs/model/Vrml/Geometry"] = "codecs_model_Vrml", + ["codecs/model/Vrml/Parse"] = "codecs_model_Vrml", + ["codecs/model/Vrml/Write"] = "codecs_model_Vrml", + ["codecs/model/Vrml/Xml"] = "codecs_model_Vrml", + ["codecs/text/GodotVariant"] = "codecs_text_GodotVariant", + ["codecs/text/Json"] = "codecs_text_Json", + ["codecs/text/Json/Decode"] = "codecs_text_Json", + ["codecs/text/Json/Encode"] = "codecs_text_Json", + ["codecs/text/KeyValues"] = "codecs_text_KeyValues", + ["codecs/text/KeyValues/Binary"] = "codecs_text_KeyValues", + ["codecs/text/Lexer"] = "codecs_text_KeyValues", + ["codecs/text/Nbt"] = "codecs_text_Nbt", + ["codecs/text/Nbt/Binary"] = "codecs_text_Nbt", + ["codecs/text/Nbt/Snbt"] = "codecs_text_Nbt", + ["codecs/text/Nbt/Value"] = "codecs_text_Nbt", + ["codecs/text/Text"] = "codecs_text_Text", + ["codecs/text/Url"] = "codecs_text_Text", + ["codecs/text/Xml"] = "codecs_text_Xml", + ["codecs/text/Xml/Parse"] = "codecs_text_Xml", + ["codecs/video/Video"] = "codecs_video_Video", + ["codecs/video/Video/Disposable"] = "codecs_video_Video", + ["codecs/video/Video/Pool"] = "codecs_video_Video", + ["codecs/video/Video/Source"] = "codecs_video_Video", + ["containers/Archive"] = "containers_Archive", + ["containers/AudioWrap"] = "containers_Archive", + ["containers/Avi"] = "containers_Avi", + ["containers/Blend"] = "containers_Blend", + ["containers/Chunks"] = "containers_Blend", + ["containers/Cpio"] = "containers_Cpio", + ["containers/Demux"] = "containers_Cpio", + ["containers/Ebml"] = "containers_Cpio", + ["containers/Fat"] = "containers_Fat", + ["containers/Iso9660"] = "containers_Iso9660", + ["containers/IsoBmff"] = "containers_IsoBmff", + ["containers/IsoBmff/Box"] = "containers_IsoBmff", + ["containers/IsoBmff/Demux"] = "containers_IsoBmff", + ["containers/IsoBmff/Meta"] = "containers_IsoBmff", + ["containers/IsoBmff/Mux"] = "containers_IsoBmff", + ["containers/IsoBmff/QtPalette"] = "containers_IsoBmff", + ["containers/MacFile"] = "containers_MacFile", + ["containers/Ogg"] = "containers_MacFile", + ["containers/Ogg/Mux"] = "containers_MacFile", + ["containers/Ogg/Page"] = "containers_MacFile", + ["containers/Riff"] = "containers_Riff", + ["containers/Tar"] = "containers_Riff", + ["containers/Zip"] = "containers_Zip", + ["core/Adler32"] = "core_Adler32", + ["core/Base64"] = "core_Adler32", + ["core/Bits"] = "core_Adler32", + ["core/Crc32"] = "core_Adler32", + ["core/Md5"] = "core_Adler32", + ["data/cbor"] = "data_cbor", + ["data/cbor/Codec"] = "data_cbor", + ["data/csv"] = "data_cbor", + ["data/ini"] = "data_ini", + ["data/json"] = "data_ini", + ["data/msgpack"] = "data_ini", + ["data/msgpack/Codec"] = "data_ini", + ["data/nbt"] = "data_ini", + ["data/plist"] = "data_plist", + ["data/plist/Binary"] = "data_plist", + ["data/q3shader"] = "data_plist", + ["data/q3skin"] = "data_plist", + ["data/snbt"] = "data_plist", + ["data/toml"] = "data_toml", + ["data/toml/Decode"] = "data_toml", + ["data/toml/Encode"] = "data_toml", + ["data/tres"] = "data_toml", + ["data/vdf"] = "data_toml", + ["data/xml"] = "data_xml", + ["data/yaml"] = "data_yaml", + ["data/yaml/Emit"] = "data_yaml", + ["data/yaml/Parse"] = "data_yaml", + ["font/bdf"] = "font_bdf", + ["font/bmfont"] = "font_bmfont", + ["font/bmfont/Parse"] = "font_bmfont", + ["font/eot"] = "font_bmfont", + ["font/fon"] = "font_fon", + ["font/hershey"] = "font_fon", + ["font/pcf"] = "font_fon", + ["font/psf"] = "font_psf", + ["font/ttf"] = "font_psf", + ["font/type1"] = "font_psf", + ["font/type1/Charstring"] = "font_psf", + ["font/woff"] = "font_woff", + ["font/woff2"] = "font_woff", + ["font/woff2/Rebuild"] = "font_woff", + ["host/Love"] = "host_Love", + ["host/LuaJIT"] = "host_Love", + ["host/Luau"] = "host_Love", + ["host/Roblox"] = "host_Love", + ["image/ani"] = "image_ani", + ["image/art"] = "image_ani", + ["image/blp"] = "image_ani", + ["image/bmp"] = "image_bmp", + ["image/dds"] = "image_bmp", + ["image/exr"] = "image_exr", + ["image/exr/Codec"] = "image_exr", + ["image/exr/Piz"] = "image_exr", + ["image/gif"] = "image_gif", + ["image/gif/Decode"] = "image_gif", + ["image/hdr"] = "image_gif", + ["image/hdr/Codec"] = "image_gif", + ["image/icns"] = "image_icns", + ["image/ico"] = "image_icns", + ["image/ico/Dib"] = "image_icns", + ["image/ilbm"] = "image_ilbm", + ["image/jpeg"] = "image_ilbm", + ["image/ktx"] = "image_ktx", + ["image/lmp"] = "image_ktx", + ["image/pcx"] = "image_pcx", + ["image/pnm"] = "image_pcx", + ["image/pnm/Codec"] = "image_pcx", + ["image/qoi"] = "image_qoi", + ["image/qoi/Codec"] = "image_qoi", + ["image/sgi"] = "image_qoi", + ["image/spr"] = "image_qoi", + ["image/sunras"] = "image_sunras", + ["image/tga"] = "image_sunras", + ["image/tga/Codec"] = "image_sunras", + ["image/tiff"] = "image_tiff", + ["image/tiff/Pixels"] = "image_tiff", + ["image/tim"] = "image_tim", + ["image/vtf"] = "image_tim", + ["image/webp"] = "image_webp", + ["image/webp/Alpha"] = "image_webp", + ["image/webp/Anim"] = "image_webp", + ["image/xbm"] = "image_webp", + ["image/xpm"] = "image_xpm", + ["image/xpm/Names"] = "image_xpm", + ["layered/aseprite"] = "layered_aseprite", + ["layered/ora"] = "layered_ora", + ["layered/psd"] = "layered_psd", + ["layered/psd/Channels"] = "layered_psd", + ["model/3ds"] = "model_3ds", + ["model/3ds/Build"] = "model_3ds", + ["model/3ds/Read"] = "model_3ds", + ["model/3ds/Write"] = "model_3ds", + ["model/3mf"] = "model_3mf", + ["model/3mf/Read"] = "model_3mf", + ["model/3mf/Write"] = "model_3mf", + ["model/ase"] = "model_ase", + ["model/ase/Build"] = "model_ase", + ["model/ase/Parse"] = "model_ase", + ["model/ase/Write"] = "model_ase", + ["model/b3d"] = "model_b3d", + ["model/b3d/Read"] = "model_b3d", + ["model/blend"] = "model_blend", + ["model/blend/Anim"] = "model_blend", + ["model/blend/Armature"] = "model_blend", + ["model/blend/Driver"] = "model_blend", + ["model/blend/Material"] = "model_blend", + ["model/blend/Mesh"] = "model_blend", + ["model/blend/Normals"] = "model_blend", + ["model/blend/Prim"] = "model_blend", + ["model/blend/Read"] = "model_blend", + ["model/bsp"] = "model_bsp", + ["model/bsp/Lightmap"] = "model_bsp", + ["model/bsp/Quake"] = "model_bsp", + ["model/bsp/Quake3"] = "model_bsp", + ["model/bsp/Tree"] = "model_bsp", + ["model/buildmap"] = "model_buildmap", + ["model/buildmap/Geometry"] = "model_buildmap", + ["model/d3map"] = "model_d3map", + ["model/d3map/Parse"] = "model_d3map", + ["model/dae"] = "model_dae", + ["model/dae/Math"] = "model_dae", + ["model/dae/Read"] = "model_dae", + ["model/dae/Write"] = "model_dae", + ["model/fbx"] = "model_fbx", + ["model/fbx/Ascii"] = "model_fbx", + ["model/fbx/Binary"] = "model_fbx", + ["model/fbx/Read"] = "model_fbx", + ["model/fbx/Write"] = "model_fbx", + ["model/fbx/Xform"] = "model_fbx", + ["model/gltf"] = "model_gltf", + ["model/gltf/Pack"] = "model_gltf", + ["model/gltf/Read"] = "model_gltf", + ["model/gltf/Write"] = "model_gltf", + ["model/godot"] = "model_godot", + ["model/godot/Build"] = "model_godot", + ["model/godot/Primitives"] = "model_godot", + ["model/godot/Surface"] = "model_godot", + ["model/godot/Write"] = "model_godot", + ["model/iqm"] = "model_iqm", + ["model/iqm/Read"] = "model_iqm", + ["model/iqm/Write"] = "model_iqm", + ["model/ldraw"] = "model_ldraw", + ["model/ldraw/Colors"] = "model_ldraw", + ["model/ldraw/Read"] = "model_ldraw", + ["model/lwo"] = "model_lwo", + ["model/lwo/Build"] = "model_lwo", + ["model/lwo/Parse"] = "model_lwo", + ["model/map"] = "model_map", + ["model/map/Build"] = "model_map", + ["model/map/Parse"] = "model_map", + ["model/map/Write"] = "model_map", + ["model/mca"] = "model_mca", + ["model/mca/Chunk"] = "model_mca", + ["model/mca/Lz4Block"] = "model_mca", + ["model/md2"] = "model_mca", + ["model/md3"] = "model_md3", + ["model/md5"] = "model_md3", + ["model/md5/Read"] = "model_md3", + ["model/mdl"] = "model_mdl", + ["model/mdl/HalfLife"] = "model_mdl", + ["model/mdl/Quake"] = "model_mdl", + ["model/ms3d"] = "model_ms3d", + ["model/ms3d/Read"] = "model_ms3d", + ["model/ms3d/Write"] = "model_ms3d", + ["model/obj"] = "model_obj", + ["model/obj/Mtl"] = "model_obj", + ["model/off"] = "model_off", + ["model/ply"] = "model_ply", + ["model/ply/Binary"] = "model_ply", + ["model/pmx"] = "model_pmx", + ["model/pmx/Build"] = "model_pmx", + ["model/pmx/Pmd"] = "model_pmx", + ["model/pmx/Read"] = "model_pmx", + ["model/proc"] = "model_proc", + ["model/qb"] = "model_proc", + ["model/rbxm"] = "model_rbxm", + ["model/rbxmx"] = "model_rbxmx", + ["model/robloxmesh"] = "model_robloxmesh", + ["model/robloxmesh/Parse"] = "model_robloxmesh", + ["model/robloxmesh/Write"] = "model_robloxmesh", + ["model/schematic"] = "model_schematic", + ["model/schematic/Common"] = "model_schematic", + ["model/schematic/Litematic"] = "model_schematic", + ["model/schematic/Mcedit"] = "model_schematic", + ["model/schematic/Sponge"] = "model_schematic", + ["model/smd"] = "model_smd", + ["model/smd/Read"] = "model_smd", + ["model/smd/Write"] = "model_smd", + ["model/sourcemdl"] = "model_sourcemdl", + ["model/sourcemdl/Build"] = "model_sourcemdl", + ["model/sourcemdl/Material"] = "model_sourcemdl", + ["model/sourcemdl/Mdl"] = "model_sourcemdl", + ["model/sourcemdl/Phy"] = "model_sourcemdl", + ["model/sourcemdl/Vtx"] = "model_sourcemdl", + ["model/sourcemdl/Vvd"] = "model_sourcemdl", + ["model/stl"] = "model_stl", + ["model/stl/Decode"] = "model_stl", + ["model/t3d"] = "model_t3d", + ["model/t3d/Build"] = "model_t3d", + ["model/t3d/Parse"] = "model_t3d", + ["model/udmf"] = "model_t3d", + ["model/usda"] = "model_usda", + ["model/usda/Build"] = "model_usda", + ["model/usda/Parse"] = "model_usda", + ["model/usda/Write"] = "model_usda", + ["model/vbsp"] = "model_vbsp", + ["model/vbsp/Faces"] = "model_vbsp", + ["model/vbsp/Props"] = "model_vbsp", + ["model/vmf"] = "model_vmf", + ["model/vmf/Build"] = "model_vmf", + ["model/vox"] = "model_vox", + ["model/vox/Grid"] = "model_vox", + ["model/vrml"] = "model_vox", + ["model/x"] = "model_x", + ["model/x/Build"] = "model_x", + ["model/x/Parse"] = "model_x", + ["model/x3d"] = "model_x3d", + ["music/669"] = "music_669", + ["music/ahx"] = "music_669", + ["music/far"] = "music_669", + ["music/hmp"] = "music_669", + ["music/hvl"] = "music_669", + ["music/it"] = "music_it", + ["music/it/Itsex"] = "music_it", + ["music/med"] = "music_med", + ["music/midi"] = "music_midi", + ["music/midi/Smf"] = "music_midi", + ["music/mod"] = "music_midi", + ["music/mtm"] = "music_mtm", + ["music/mus"] = "music_mtm", + ["music/okt"] = "music_mtm", + ["music/ptm"] = "music_mtm", + ["music/s3m"] = "music_s3m", + ["music/sf2"] = "music_s3m", + ["music/stm"] = "music_s3m", + ["music/ult"] = "music_s3m", + ["music/umx"] = "music_s3m", + ["music/xm"] = "music_xm", + ["music/xmi"] = "music_xm", + ["ops/AudioOps"] = "ops_AudioOps", + ["ops/ImageOps"] = "ops_ImageOps", + ["ops/ImageOps/Kernels"] = "ops_ImageOps", + ["ops/LayerOps"] = "ops_LayerOps", + ["ops/MeshOps"] = "ops_MeshOps", + ["ops/MeshOps/Greedy"] = "ops_MeshOps", + ["ops/MusicOps"] = "ops_MusicOps", + ["playlist/m3u"] = "playlist_m3u", + ["playlist/pls"] = "playlist_m3u", + ["playlist/xspf"] = "playlist_m3u", + ["subtitle/ass"] = "subtitle_ass", + ["subtitle/srt"] = "subtitle_ass", + ["subtitle/vtt"] = "subtitle_ass", + ["vector/gamemaps"] = "vector_gamemaps", + ["vector/gamemaps/Expand"] = "vector_gamemaps", + ["vector/ldtk"] = "vector_ldtk", + ["vector/ldtk/Read"] = "vector_ldtk", + ["vector/ldtk/Write"] = "vector_ldtk", + ["vector/ogmo"] = "vector_ogmo", + ["vector/ogmo/Read"] = "vector_ogmo", + ["vector/ogmo/Write"] = "vector_ogmo", + ["vector/svg"] = "vector_svg", + ["vector/svg/Parse"] = "vector_svg", + ["vector/svg/PathData"] = "vector_svg", + ["vector/svg/Render"] = "vector_svg", + ["vector/svg/Style"] = "vector_svg", + ["vector/svg/Write"] = "vector_svg", + ["vector/tiled"] = "vector_tiled", + ["vector/tiled/Data"] = "vector_tiled", + ["vector/tiled/Tmj"] = "vector_tiled", + ["vector/tiled/Tmx"] = "vector_tiled", + ["video/avi"] = "video_avi", + ["video/fli"] = "video_avi", + ["video/flv"] = "video_flv", + ["video/flv/Amf"] = "video_flv", + ["video/flv/Mux"] = "video_flv", + ["video/h264"] = "video_flv", + ["video/mkv"] = "video_mkv", + ["video/mkv/Mux"] = "video_mkv", + ["video/mkv/Parse"] = "video_mkv", + ["video/mp4"] = "video_mp4", + ["video/mpegps"] = "video_mp4", + ["video/mpegts"] = "video_mp4", + ["video/ogv"] = "video_ogv", + ["video/smk"] = "video_ogv", + ["video/smk/Audio"] = "video_ogv", + ["video/y4m"] = "video_ogv", } local __FILES = {} local __LOADED = {} @@ -681,11 +681,11 @@ return Rosetta - Core_1 + Core --!optimize 2 --!nocheck --- rosetta chunk Core_1 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 11 modules (3 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk Core (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 7 modules (1 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES[""] = function() @@ -698,10 +698,6 @@ local Bytes = __include("core/Bytes") local Input = __include("core/Input") local Types = __include("Types") local Registry = __include("Registry") -local Video = __include("codecs/video/Video") -local AudioWrap = __include("containers/AudioWrap") -local Rbx = __include("codecs/model/Rbx") -local ImageOps = __include("ops/ImageOps") local host = __include("host") local F = {} @@ -710,7 +706,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) @@ -1029,7 +1024,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 = __include("containers/AudioWrap").wrap(demuxer, track) if not buf then return nil, err end @@ -1041,7 +1036,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 = __include("containers/AudioWrap").trim(dec, skip, length) end end return dec, oerr @@ -1221,7 +1216,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 = __include("ops/ImageOps").fromFrames(images, delays) if not img then return nil, ierr end @@ -1507,7 +1502,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 = __include("ops/ImageOps").coalesce(img) if not list then return nil, cerr end @@ -1517,19 +1512,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 = __include("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 __include("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 __include("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 } = {} @@ -1558,7 +1552,7 @@ end local OPS: { [string]: () -> any } = { image = function() - return ImageOps + return __include("ops/ImageOps") end, mesh = function() return __include("ops/MeshOps") @@ -1603,6 +1597,28 @@ 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 = __include("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 = __include("codecs/video/Video") + rawset(t, k, m) + return m + end + return nil + end, +}) + return F end __FILES["Registry"] = function() @@ -1998,7 +2014,7 @@ local list: { Entry } = { mime = { "audio/aac", "audio/aacp", "audio/x-aac" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Aac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = false, codecs = { "aac" }, streaming = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/aac") end, @@ -2011,7 +2027,7 @@ local list: { Entry } = { mime = { "audio/ac3", "audio/x-ac3" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/Ac3" }, caps = { decode = true, encode = false, codecs = { "ac3" }, channels = 6, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/ac3") end, @@ -2129,7 +2145,7 @@ local list: { Entry } = { mime = { "audio/mp4", "audio/x-m4a", "audio/m4a" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "codecs/audio/Aac", "codecs/audio/Alac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = true, codecs = { "aac", "alac" }, encodeCodecs = { "alac" }, tags = true, streaming = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/m4a") end, @@ -2142,7 +2158,7 @@ local list: { Entry } = { mime = { "audio/mpeg", "audio/mp3", "audio/mpa" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Resample", "codecs/audio/Mpa/Header", "codecs/audio/Mpa/Core", "codecs/audio/Mpa/Encode3", "codecs/audio/Mpa/Encode2" }, caps = { decode = true, encode = true, streaming = true, seek = true, layers = { 1, 2, 3 }, encodeLayers = { 2, 3 }, channels = 2 }, - sniff = 1, + sniff = 0, load = function() return __include("audio/mp3") end, @@ -2155,7 +2171,7 @@ local list: { Entry } = { mime = { "audio/x-musepack", "audio/musepack" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/ApeTag", "codecs/audio/Musepack" }, caps = { decode = true, encode = false, codecs = { "musepack" }, versions = { 7, 8 }, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/mpc") end, @@ -2246,7 +2262,7 @@ local list: { Entry } = { mime = { "audio/wav", "audio/x-wav", "audio/wave", "audio/vnd.wave" }, deps = { "core/Err", "core/Bytes", "Types", "containers/Riff", "codecs/audio/Pcm", "codecs/audio/Adpcm" }, caps = { decode = true, encode = true, streaming = true, depths = { 8, 16, 24, 32 }, float = true, rf64 = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/wav") end, @@ -2338,7 +2354,7 @@ local list: { Entry } = { mime = { "video/mp4", "video/quicktime", "video/3gpp" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "containers/Demux", "codecs/video/Video", "codecs/video/Video/Source" }, caps = { decode = true, encode = true, streaming = true, remux = true, video = { "mjpeg", "mpeg1", "mpeg2", "h264" }, audio = true, fragments = true }, - sniff = 1, + sniff = 0, load = function() return __include("video/mp4") end, @@ -2442,7 +2458,7 @@ local list: { Entry } = { mime = { "model/x-ase", "text/plain" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, - sniff = 1, + sniff = 0, load = function() return __include("model/ase") end, @@ -2533,7 +2549,7 @@ local list: { Entry } = { mime = { "application/vnd.autodesk.fbx", "model/fbx" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/compress/Deflate", "core/Base64", "codecs/model/Mat4" }, caps = { decode = true, encode = true, binary = true, ascii = true, materials = true, animation = true, skins = true, morphTargets = true, cameras = true, lights = true, polygons = true }, - sniff = 2, + sniff = 0, load = function() return __include("model/fbx") end, @@ -2689,7 +2705,7 @@ local list: { Entry } = { mime = { "application/x-ms3d" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten" }, caps = { decode = true, encode = true, materials = true, skins = true, animation = true }, - sniff = 1, + sniff = 0, load = function() return __include("model/ms3d") end, @@ -3290,7 +3306,7 @@ local list: { Entry } = { mime = { "application/x-fat-image" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Fat" }, caps = { decode = true, encode = true, variants = { "fat12", "fat16", "fat32" } }, - sniff = 1, + sniff = 0, load = function() return __include("archive/fat") end, @@ -3420,7 +3436,7 @@ local list: { Entry } = { mime = { "application/x-tar" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Tar" }, caps = { decode = true, encode = true, variants = { "ustar", "pax", "gnu" } }, - sniff = 1, + sniff = 0, load = function() return __include("archive/tar") end, @@ -3745,7 +3761,7 @@ local list: { Entry } = { mime = { "text/x-vdf" }, deps = { "core/Err", "core/Bytes", "core/Sniff", "codecs/text/KeyValues" }, caps = { decode = true, encode = true, ordered = true, binary = true }, - sniff = 1, + sniff = 0, load = function() return __include("data/vdf") end, @@ -4109,7 +4125,7 @@ local list: { Entry } = { mime = { "audio/x-soundfont" }, deps = { "core/Err", "core/Bytes", "codecs/audio/SoundFont" }, caps = { decode = true, encode = false, sm24 = true, sf3 = false }, - sniff = 1, + sniff = 0, load = function() return __include("music/sf2") end, @@ -4200,7 +4216,7 @@ local list: { Entry } = { mime = { "audio/x-scpls", "audio/scpls" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Url", "codecs/text/Text", "core/Sniff" }, caps = { decode = true, encode = true }, - sniff = 1, + sniff = 0, load = function() return __include("playlist/pls") end, @@ -5339,2908 +5355,6 @@ Types.CATEGORIES = table.freeze({ return Types end -__FILES["codecs/audio/Adpcm"] = @native function() - - - --- codecs/audio/Adpcm: the 4-bit ADPCM family, decode (and encode where it is cheap). --- ADX, PS-ADPCM and Nintendo DSP decoding follow vgmstream r2117 (ISC, licenses/vgmstream-LICENSE.txt) bit-exactly: the --- ADX scale + 1 and version 3 rounding, PS-ADPCM's float filter (exact in integers below 2^17), DSP's 1024 rounding. -local readu8, readi16, readu16, readi32 = buffer.readu8, buffer.readi16, buffer.readu16, buffer.readi32 -local writef32, readf32, writei32, writeu8, writeu16 = buffer.writef32, buffer.readf32, buffer.writei32, buffer.writeu8, buffer.writeu16 -local band, rshift, bor, lshift = bit32.band, bit32.rshift, bit32.bor, bit32.lshift -local floor = math.floor - -local Adpcm = {} - -local IMA_STEP = { - 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, - 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, - 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, - 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767, -} -local IMA_ADJ = { -1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8 } --- IMA_DIFF[index * 8 + (nibble & 7) + 1]: the shift-and-add difference (step/8 + bits of step/4, step/2, step), as --- the IMA reference computes it (not (2n + 1) * step / 8, which rounds differently) -local IMA_DIFF = table.create(89 * 8, 0) --- IMA_NEXT[index * 16 + nibble + 1]: the next step index -local IMA_NEXT = table.create(89 * 16, 0) -for i = 0, 88 do - local step = IMA_STEP[i + 1] - for n = 0, 7 do - local d = rshift(step, 3) - if band(n, 1) ~= 0 then - d += rshift(step, 2) - end - if band(n, 2) ~= 0 then - d += rshift(step, 1) - end - if band(n, 4) ~= 0 then - d += step - end - IMA_DIFF[i * 8 + n + 1] = d - end - for n = 0, 15 do - IMA_NEXT[i * 16 + n + 1] = math.clamp(i + IMA_ADJ[n + 1], 0, 88) - end -end -Adpcm.IMA_STEP = IMA_STEP - --- IMA nibble q is in byte p + q // 2, the low half first unless hi -@native function Adpcm.ima(src: buffer, p: number, q0: number, qs: number, count: number, hi: boolean, st: buffer, so: number, - dst: buffer, d: number, ds: number) - local pred = readi32(st, so) - local index = math.clamp(readi32(st, so + 4), 0, 88) - local q = q0 - local o = d * 4 - local os = ds * 4 - for _ = 1, count do - local b = readu8(src, p + rshift(q, 1)) - local nib - if (band(q, 1) == 0) == hi then - nib = rshift(b, 4) - else - nib = band(b, 15) - end - local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] - if nib >= 8 then - pred -= diff - if pred < -32768 then - pred = -32768 - end - else - pred += diff - if pred > 32767 then - pred = 32767 - end - end - index = IMA_NEXT[index * 16 + nib + 1] - writef32(dst, o, pred / 32768) - o += os - q += qs - end - writei32(st, so, pred) - writei32(st, so + 4, index) -end - --- Apple ima4: 34 bytes: a big-endian header (the predictor's top 9 bits, 7-bit step index), 64 nibbles low first; --- Apple's decoders keep the full-precision predictor while the header agrees (same step index, within 127) -@native function Adpcm.imaQt(src: buffer, p: number, st: buffer, so: number, dst: buffer, d: number, ds: number) - local h = readu8(src, p) * 256 + readu8(src, p + 1) - local pred = band(h, 0xFF80) - if pred >= 32768 then - pred -= 65536 - end - local index = band(h, 0x7F) - if index ~= readi32(st, so + 4) or math.abs(pred - readi32(st, so)) > 0x7F then - writei32(st, so, pred) - writei32(st, so + 4, index) - end - Adpcm.ima(src, p + 2, 0, 1, 64, false, st, so, dst, d, ds) -end - --- Microsoft IMA block: per channel s16 predictor (= the first sample), u8 step index, pad; then 4-byte groups --- (8 nibbles, low first) per channel in turn -@native function Adpcm.imaWav(src: buffer, off: number, avail: number, ch: number, spb: number, dst: buffer, d: number): number - if avail < 4 * ch then - return 0 - end - local groups = (avail - 4 * ch) // (4 * ch) - local frames = math.min(spb, 1 + groups * 8) - local o = d * 4 - for c = 0, ch - 1 do - local pred = readi16(src, off + c * 4) - local index = math.min(readu8(src, off + c * 4 + 2), 88) - writef32(dst, o + c * 4, pred / 32768) - local f = 1 - local g = 0 - while f < frames do - local p = off + 4 * ch + (g * ch + c) * 4 - local k = 0 - while k < 8 and f < frames do - local b = readu8(src, p + rshift(k, 1)) - local nib = if band(k, 1) == 0 then band(b, 15) else rshift(b, 4) - local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] - if nib >= 8 then - pred -= diff - if pred < -32768 then - pred = -32768 - end - else - pred += diff - if pred > 32767 then - pred = 32767 - end - end - index = IMA_NEXT[index * 16 + nib + 1] - writef32(dst, o + (f * ch + c) * 4, pred / 32768) - f += 1 - k += 1 - end - g += 1 - end - end - return frames -end - -local MS_ADAPT = { 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 } -Adpcm.MS_COEF1 = { 256, 512, 0, 192, 240, 460, 392 } -Adpcm.MS_COEF2 = { 0, -256, 0, 64, 0, -208, -232 } - --- MS ADPCM block: per channel u8 predictor index, s16 delta, s16 sample 1, s16 sample 2 (each field for every channel --- in turn), then nibbles high first, channels interleaved per nibble; coefficients 256 = 1.0 -@native function Adpcm.msBlock(src: buffer, off: number, avail: number, ch: number, spb: number, dst: buffer, d: number, - coefs: buffer, ncoef: number, state: buffer): number - local hdr = 7 * ch - if avail < hdr or ncoef < 1 then - return 0 - end - local frames = math.min(spb, 2 + ((avail - hdr) * 2) // ch) - local o = d * 4 - for c = 0, ch - 1 do - local pi = math.min(readu8(src, off + c), ncoef - 1) - local idelta = readi16(src, off + ch + c * 2) - local s1 = readi16(src, off + 3 * ch + c * 2) - local s2 = readi16(src, off + 5 * ch + c * 2) - local so = c * 20 - writei32(state, so, readi32(coefs, pi * 8)) - writei32(state, so + 4, readi32(coefs, pi * 8 + 4)) - writei32(state, so + 8, idelta) - writei32(state, so + 12, s1) - writei32(state, so + 16, s2) - writef32(dst, o + c * 4, s2 / 32768) - if frames > 1 then - writef32(dst, o + (ch + c) * 4, s1 / 32768) - end - end - local total = (frames - 2) * ch - for k = 0, total - 1 do - local b = readu8(src, off + hdr + rshift(k, 1)) - local nib = if band(k, 1) == 0 then rshift(b, 4) else band(b, 15) - local so = (k % ch) * 20 - local c1, c2 = readi32(state, so), readi32(state, so + 4) - local idelta = readi32(state, so + 8) - local s1, s2 = readi32(state, so + 12), readi32(state, so + 16) - local p = s1 * c1 + s2 * c2 - p = if p >= 0 then p // 256 else -((-p) // 256) - p += (if nib >= 8 then nib - 16 else nib) * idelta - if p > 32767 then - p = 32767 - elseif p < -32768 then - p = -32768 - end - idelta = (MS_ADAPT[nib + 1] * idelta) // 256 - if idelta < 16 then - idelta = 16 - elseif idelta > 2796202 then -- INT_MAX / 768 - idelta = 2796202 - end - writei32(state, so + 8, idelta) - writei32(state, so + 12, p) - writei32(state, so + 16, s1) - writef32(dst, o + (2 * ch + k) * 4, p / 32768) - end - return frames -end - -local F32 = buffer.create(4) -@native local function f32(x: number): number - writef32(F32, 0, x) - return readf32(F32, 0) -end - --- coef1, coef2 (12 fractional bits): the 2-pole high-pass predictor from the header's cutoff, in single precision as --- CRI's decoders (and vgmstream) compute it -@native function Adpcm.adxCoefs(cutoff: number, rate: number): (number, number) - if rate <= 0 then - return 0, 0 - end - local z = f32(math.cos(f32(2 * math.pi * cutoff / rate))) - local a = f32(math.sqrt(2) - z) - local b = f32(math.sqrt(2) - 1) - local c = f32(f32(a - f32(math.sqrt(f32(f32(a + b) * f32(a - b))))) / b) - local c1 = c * 8192 - local c2 = f32(c * c) * -4096 - c1 = if c1 >= 0 then floor(c1) else -floor(-c1) - c2 = if c2 >= 0 then floor(c2) else -floor(-c2) - return c1, c2 -end - --- ADX frame: s16 big-endian scale, 32 nibbles high first. v3 shifts each product on its own; scale 0x8001 (CRI's end --- marker) decodes as silence -@native function Adpcm.adx(src: buffer, p: number, pstride: number, nframes: number, c1: number, c2: number, v3: boolean, - st: buffer, so: number, dst: buffer, d: number, ds: number) - local h1, h2 = readi32(st, so), readi32(st, so + 4) - local o = d * 4 - local os = ds * 4 - for f = 0, nframes - 1 do - local fp = p + f * pstride - local scale = readu8(src, fp) * 256 + readu8(src, fp + 1) - if scale == 0x8001 then - scale = 0 - elseif scale >= 32768 then - scale -= 65535 -- the signed value + 1 - else - scale += 1 - end - for k = 0, 31 do - local b = readu8(src, fp + 2 + rshift(k, 1)) - local n = if band(k, 1) == 0 then rshift(b, 4) else band(b, 15) - if n >= 8 then - n -= 16 - end - local s - if v3 then - s = n * scale + (c1 * h1) // 4096 + (c2 * h2) // 4096 - else - s = n * scale + (c1 * h1 + c2 * h2) // 4096 - end - if s > 32767 then - s = 32767 - elseif s < -32768 then - s = -32768 - end - h2 = h1 - h1 = s - writef32(dst, o, s / 32768) - o += os - end - end - writei32(st, so, h1) - writei32(st, so + 4, h2) -end - -local PSX1 = { 0, 60, 115, 98, 122 } -local PSX2 = { 0, 0, -52, -55, -60 } - --- the filter term (c1 * h1 + c2 * h2) / 64 * 256 truncated, as vgmstream's single-precision float code computes it: --- exact in integers while the products fit a float's 24 bits -@native local function psxPred(f: number, h1: number, h2: number): number - local x = PSX1[f] * h1 + PSX2[f] * h2 - if h1 > -65536 and h1 < 65536 and h2 > -65536 and h2 < 65536 then - return 4 * x - end - local v = f32(f32(f32(PSX1[f] / 64) * h1) + f32(f32(PSX2[f] / 64) * h2)) * 256 - return if v >= 0 then floor(v) else -floor(-v) -end - --- PS-ADPCM frame: filter << 4 | shift, flags, 28 nibbles low first. Filters past 4 decode as 0 and shifts past 12 as 9 --- (as vgmstream); flags 7 is silence; the history keeps the unclipped value -@native function Adpcm.psx(src: buffer, p: number, pstride: number, nframes: number, st: buffer, so: number, dst: buffer, - d: number, ds: number) - local h1, h2 = readi32(st, so), readi32(st, so + 4) - local o = d * 4 - local os = ds * 4 - for f = 0, nframes - 1 do - local fp = p + f * pstride - local head = readu8(src, fp) - local filter = rshift(head, 4) - local shift = band(head, 15) - if filter > 4 then - filter = 0 - end - if shift > 12 then - shift = 9 - end - local mul = 2 ^ (20 - shift) - local fi = filter + 1 - local silent = band(readu8(src, fp + 1), 15) == 7 - for k = 0, 27 do - local s = 0 - if not silent then - local b = readu8(src, fp + 2 + rshift(k, 1)) - local n = if band(k, 1) == 0 then band(b, 15) else rshift(b, 4) - if n >= 8 then - n -= 16 - end - s = (n * mul + psxPred(fi, h1, h2)) // 256 - end - h2 = h1 - h1 = s - if s > 32767 then - s = 32767 - elseif s < -32768 then - s = -32768 - end - writef32(dst, o, s / 32768) - o += os - end - end - writei32(st, so, h1) - writei32(st, so + 4, h2) -end - --- DSP frame: predictor << 4 | scale shift, 14 nibbles high first; coefs 8 pairs, 11 fractional bits; a predictor --- index past 7 uses pair 7 -@native function Adpcm.dsp(src: buffer, p: number, count: number, coefs: buffer, co: number, st: buffer, so: number, - dst: buffer, d: number, ds: number) - local h1, h2 = readi32(st, so), readi32(st, so + 4) - local o = d * 4 - local os = ds * 4 - local done = 0 - local fp = p - while done < count do - local head = readu8(src, fp) - local pi = math.min(rshift(head, 4), 7) - local scale = 2 ^ band(head, 15) * 2048 - local c1, c2 = readi32(coefs, co + pi * 8), readi32(coefs, co + pi * 8 + 4) - local n14 = math.min(14, count - done) - for k = 0, n14 - 1 do - local b = readu8(src, fp + 1 + rshift(k, 1)) - local n = if band(k, 1) == 0 then rshift(b, 4) else band(b, 15) - if n >= 8 then - n -= 16 - end - local s = (n * scale + 1024 + c1 * h1 + c2 * h2) // 2048 - if s > 32767 then - s = 32767 - elseif s < -32768 then - s = -32768 - end - h2 = h1 - h1 = s - writef32(dst, o, s / 32768) - o += os - end - done += n14 - fp += 8 - end - writei32(st, so, h1) - writei32(st, so + 4, h2) -end - -@native local function toS16(x: number): number - local v = floor(x * 32768 + 0.5) - if v ~= v then - return 0 - elseif v > 32767 then - return 32767 - elseif v < -32768 then - return -32768 - end - return v -end -Adpcm.toS16 = toS16 - -@native local function imaNibble(x: number, pred: number, index: number): number - local base = index * 8 + 1 - local best, bestErr = 0, math.huge - for m = 0, 7 do - local diff = IMA_DIFF[base + m] - local up = math.min(pred + diff, 32767) - local e = math.abs(x - up) - if e < bestErr then - best, bestErr = m, e - end - local down = math.max(pred - diff, -32768) - e = math.abs(x - down) - if e < bestErr then - best, bestErr = m + 8, e - end - end - return best -end - -@native function Adpcm.imaEncode(x: buffer, xi: number, xs: number, count: number, st: buffer, so: number, out: buffer, - p: number, q0: number, qs: number, hi: boolean) - local pred = readi32(st, so) - local index = math.clamp(readi32(st, so + 4), 0, 88) - local q = q0 - for i = 0, count - 1 do - local v = toS16(readf32(x, (xi + i * xs) * 4)) - local nib = imaNibble(v, pred, index) - local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] - pred = if nib >= 8 then math.max(pred - diff, -32768) else math.min(pred + diff, 32767) - index = IMA_NEXT[index * 16 + nib + 1] - local bp = p + rshift(q, 1) - local b = readu8(out, bp) - if (band(q, 1) == 0) == hi then - b = bor(band(b, 0x0F), lshift(nib, 4)) - else - b = bor(band(b, 0xF0), nib) - end - writeu8(out, bp, b) - q += qs - end - writei32(st, so, pred) - writei32(st, so + 4, index) -end - --- Microsoft IMA block: spb = 1 + 8k frames, 4 * ch + (spb - 1) / 2 * ch bytes -@native function Adpcm.imaWavEncode(x: buffer, xf: number, n: number, ch: number, spb: number, st: buffer, out: buffer, off: number) - local groups = (spb - 1) // 8 - for c = 0, ch - 1 do - local so = c * 8 - local first = if n > 0 then toS16(readf32(x, (xf * ch + c) * 4)) else 0 - writei32(st, so, first) - local index = math.clamp(readi32(st, so + 4), 0, 88) - writei32(st, so + 4, index) - buffer.writei16(out, off + c * 4, first) - writeu8(out, off + c * 4 + 2, index) - writeu8(out, off + c * 4 + 3, 0) - local pred = first - for g = 0, groups - 1 do - local gp = off + 4 * ch + (g * ch + c) * 4 - for k = 0, 7 do - local f = 1 + g * 8 + k - local v = if f < n then toS16(readf32(x, ((xf + f) * ch + c) * 4)) else pred - local nib = imaNibble(v, pred, index) - local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] - pred = if nib >= 8 then math.max(pred - diff, -32768) else math.min(pred + diff, 32767) - index = IMA_NEXT[index * 16 + nib + 1] - local bp = gp + rshift(k, 1) - if band(k, 1) == 0 then - writeu8(out, bp, nib) - else - writeu8(out, bp, bor(readu8(out, bp), lshift(nib, 4))) - end - end - end - writei32(st, so + 4, index) - end -end - -@native local function msTrial(xs: { number }, n: number, c1: number, c2: number, delta0: number, nibs: { number }?): number - local s1, s2 = xs[2], xs[1] - local idelta = delta0 - local err = 0 - for i = 3, n do - local p = s1 * c1 + s2 * c2 - p = if p >= 0 then p // 256 else -((-p) // 256) - local e = xs[i] - p - local nib = if e >= 0 then (e + idelta // 2) // idelta else -((-e + idelta // 2) // idelta) - nib = math.clamp(nib, -8, 7) - local v = math.clamp(p + nib * idelta, -32768, 32767) - err += (xs[i] - v) * (xs[i] - v) - if nibs then - nibs[i] = band(nib, 15) - end - idelta = math.clamp((MS_ADAPT[band(nib, 15) + 1] * idelta) // 256, 16, 2796202) - s2 = s1 - s1 = v - end - return err -end - --- MS ADPCM block (standard 7 coefficient pairs): 7 * ch + (spb - 2) * ch / 2 bytes -@native function Adpcm.msEncode(x: buffer, xf: number, n: number, ch: number, spb: number, out: buffer, off: number) - local C1, C2 = Adpcm.MS_COEF1, Adpcm.MS_COEF2 - local xs = table.create(spb, 0) - local nibs = table.create(spb, 0) - local all = table.create(spb * ch, 0) - for c = 0, ch - 1 do - for i = 1, spb do - xs[i] = if i <= n then toS16(readf32(x, ((xf + i - 1) * ch + c) * 4)) else 0 - end - local sum = 0 - for i = 3, math.min(spb, 10) do - sum += math.abs(xs[i] - xs[i - 1]) - end - local delta0 = math.clamp(sum // 16, 16, 32767) - local best, bestErr = 1, math.huge - for k = 1, 7 do - local e = msTrial(xs, spb, C1[k], C2[k], delta0, nil) - if e < bestErr then - best, bestErr = k, e - end - end - msTrial(xs, spb, C1[best], C2[best], delta0, nibs) - writeu8(out, off + c, best - 1) - writeu16(out, off + ch + c * 2, delta0) - buffer.writei16(out, off + 3 * ch + c * 2, xs[2] or 0) - buffer.writei16(out, off + 5 * ch + c * 2, xs[1]) - for i = 3, spb do - all[(i - 3) * ch + c + 1] = nibs[i] - end - end - local total = (spb - 2) * ch - for k = 0, total - 1, 2 do - writeu8(out, off + 7 * ch + k // 2, all[k + 1] * 16 + (all[k + 2] or 0)) - end -end - -@native local function adxTrial(xs: { number }, scale: number, c1: number, c2: number, h1: number, h2: number, nibs: { number }?): (number, number, number) - local err = 0 - for k = 1, 32 do - local pred = (c1 * h1 + c2 * h2) // 4096 - local e = xs[k] - pred - local n = if e >= 0 then (e + scale // 2) // scale else -((-e + scale // 2) // scale) - n = math.clamp(n, -8, 7) - local s = math.clamp(n * scale + pred, -32768, 32767) - err += (xs[k] - s) * (xs[k] - s) - if nibs then - nibs[k] = band(n, 15) - end - h2 = h1 - h1 = s - end - return err, h1, h2 -end - --- ADX v4 rounding; the scale is stored minus one as CRI's decoders add it back --- (v4 rounding, the scale stored minus one as CRI's decoders add it back) at out[p], pstride bytes apart; the frame -@native function Adpcm.adxEncode(x: buffer, xi: number, xs: number, count: number, c1: number, c2: number, st: buffer, so: number, - out: buffer, p: number, pstride: number) - local h1, h2 = readi32(st, so), readi32(st, so + 4) - local v = table.create(32, 0) - local nibs = table.create(32, 0) - for f = 0, (count + 31) // 32 - 1 do - local peak = 0 - local a, b = h1, h2 - for k = 1, 32 do - local i = f * 32 + k - 1 - local s = if i < count then toS16(readf32(x, (xi + i * xs) * 4)) else 0 - v[k] = s - peak = math.max(peak, math.abs(s - (c1 * a + c2 * b) // 4096)) - b = a - a = s - end - local base = math.max(1, (peak + 6) // 7) - local best, bestErr = base, math.huge - for _, m in { 1, 0.75, 1.25, 0.5, 1.6 } do - local sc = math.clamp(floor(base * m + 0.5), 1, 0x7FFF) - local e = adxTrial(v, sc, c1, c2, h1, h2, nil) - if e < bestErr then - best, bestErr = sc, e - end - end - local _, n1, n2 = adxTrial(v, best, c1, c2, h1, h2, nibs) - h1, h2 = n1, n2 - local fp = p + f * pstride - writeu8(out, fp, rshift(best - 1, 8)) - writeu8(out, fp + 1, band(best - 1, 255)) - for k = 0, 15 do - writeu8(out, fp + 2 + k, nibs[k * 2 + 1] * 16 + nibs[k * 2 + 2]) - end - end - writei32(st, so, h1) - writei32(st, so + 4, h2) -end - -@native function Adpcm.psxEncode(x: buffer, xi: number, xs: number, count: number, st: buffer, so: number, out: buffer, - p: number, pstride: number) - local h1, h2 = readi32(st, so), readi32(st, so + 4) - local v = table.create(28, 0) - local nibs = table.create(28, 0) - for f = 0, (count + 27) // 28 - 1 do - for k = 1, 28 do - local i = f * 28 + k - 1 - v[k] = if i < count then toS16(readf32(x, (xi + i * xs) * 4)) else 0 - end - local bestErr, bestHead = math.huge, 0 - for fi = 1, 5 do - for shift = 0, 12 do - local mul = 2 ^ (20 - shift) - local a, b = h1, h2 - local err = 0 - for k = 1, 28 do - local pred = psxPred(fi, a, b) - local n = floor((v[k] * 256 - pred) / mul + 0.5) - n = if n > 7 then 7 elseif n < -8 then -8 else n - local s = (n * mul + pred) // 256 - local c = if s > 32767 then 32767 elseif s < -32768 then -32768 else s - err += (v[k] - c) * (v[k] - c) - if err >= bestErr then - break - end - b = a - a = s - end - if err < bestErr then - bestErr, bestHead = err, (fi - 1) * 16 + shift - end - end - end - local fi, shift = rshift(bestHead, 4) + 1, band(bestHead, 15) - local mul = 2 ^ (20 - shift) - for k = 1, 28 do - local pred = psxPred(fi, h1, h2) - local n = math.clamp(floor((v[k] * 256 - pred) / mul + 0.5), -8, 7) - nibs[k] = band(n, 15) - h2 = h1 - h1 = (n * mul + pred) // 256 - end - local fp = p + f * pstride - writeu8(out, fp, bestHead) - writeu8(out, fp + 1, 0) - for k = 0, 13 do - writeu8(out, fp + 2 + k, nibs[k * 2 + 1] + nibs[k * 2 + 2] * 16) - end - end - writei32(st, so, h1) - writei32(st, so + 4, h2) -end - --- ModPlug / OpenMPT ADPCM (sample data marked 0xAD): 16 signed byte deltas, then nibbles low first, each adding its --- delta to a wrapping signed byte; value / 128 -@native function Adpcm.modplug(src: buffer, p: number, count: number, dst: buffer, d: number) - local tab = table.create(16, 0) - for k = 0, 15 do - tab[k + 1] = buffer.readi8(src, p + k) - end - local v = 0 - for i = 0, count - 1 do - local b = readu8(src, p + 16 + rshift(i, 1)) - local nib = if band(i, 1) == 0 then band(b, 15) else rshift(b, 4) - v = (v + tab[nib + 1] + 128) % 256 - 128 - writef32(dst, (d + i) * 4, v / 128) - end -end - --- 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 }, -} - -@native 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 - -@native 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 - -@native 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 -end -__FILES["codecs/image/Yuv"] = @native function() - - - --- codecs/image/Yuv: planar 4:2:0 Y'CbCr <-> rgba8, BT.601 / BT.709, limited or full range. --- yuv -> rgb: nearest chroma, swscale's default 16-bit coefficients (within about one level of ffmpeg -pix_fmt rgba); --- rgb -> yuv: each 2x2 block averaged for the chroma. -local Types = __include("Types") - -local readu8, writeu8, writeu32 = buffer.readu8, buffer.writeu8, buffer.writeu32 -local bcreate = buffer.create -local floor = math.floor - -local Yuv = {} - --- coefficients (x 65536): r = y' + crv * v; g = y' - cgu * u - cgv * v; b = y' + cbu * u --- limited: y' = (y - 16) * 255 / 219, chroma scaled by 255 / 224 -local MATRIX: { [string]: { kr: number, kb: number } } = { - bt601 = { kr = 0.299, kb = 0.114 }, - bt709 = { kr = 0.2126, kb = 0.0722 }, -} - -type Coeffs = { ys: number, yo: number, crv: number, cgu: number, cgv: number, cbu: number, cs: number, yt: { number } } - -local cache: { [string]: Coeffs } = {} -@native local function coeffs(range: string?, matrix: string?): Coeffs - local key = (range or "limited") .. (matrix or "bt601") - local c = cache[key] - if c then - return c - end - local m = MATRIX[matrix or "bt601"] or MATRIX.bt601 - local kr, kb = m.kr, m.kb - local kg = 1 - kr - kb - local full = range == "full" - local ys = if full then 1 else 255 / 219 - local cs = if full then 1 else 255 / 224 - c = { - ys = floor(ys * 65536 + 0.5), - yo = if full then 0 else 16, - crv = floor(2 * (1 - kr) * cs * 65536 + 0.5), - cbu = floor(2 * (1 - kb) * cs * 65536 + 0.5), - cgu = floor(2 * (1 - kb) * kb / kg * cs * 65536 + 0.5), - cgv = floor(2 * (1 - kr) * kr / kg * cs * 65536 + 0.5), - cs = cs, - yt = table.create(256, 0), - } - for v = 0, 255 do - c.yt[v + 1] = (c.ys * (v - c.yo) + 32768) // 65536 + 1024 - end - cache[key] = c - return c -end - -local CLIP = bcreate(2304) -for i = 0, 2303 do - writeu8(CLIP, i, math.clamp(i - 1024, 0, 255)) -end --- CLIP's values shifted into their rgba8 byte (CB carries the alpha); indexes stay within 600..1700 -local CR: { number } = table.create(2304, 0) -local CG: { number } = table.create(2304, 0) -local CB: { number } = table.create(2304, 0) -for i = 1, 2304 do - local v = math.clamp(i - 1024, 0, 255) - CR[i] = v - CG[i] = v * 256 - CB[i] = v * 65536 + 0xff000000 -end - --- hook: called (through pcall) every 16 rows, a cooperative yield point -@native function Yuv.toRgba(src: buffer, w: number, h: number, uo: number, vo: number, cw: number, range: string?, matrix: string?, out: buffer?, hook: (() -> ())?): buffer - local dst = out or bcreate(w * h * 4) - local c = coeffs(range, matrix) - local crv, cgu, cgv, cbu = c.crv, c.cgu, c.cgv, c.cbu - local yt, cr, cg, cb = c.yt, CR, CG, CB - local ch = (h + 1) // 2 - if buffer.len(src) < vo + cw * ch or buffer.len(dst) < w * h * 4 or uo + cw * ch > buffer.len(src) then - return dst - end - local w2 = w // 2 - local stride = w * 4 - for y = 0, h - 1, 2 do - if hook and y % 16 == 0 and y > 0 then - pcall(hook) - end - local yrow = y * w - local ci = uo + (y // 2) * cw - local dv = vo - uo - local o = yrow * 4 - local two = y + 1 < h - for _ = 1, w2 do - local u = readu8(src, ci) - 128 - local v = readu8(src, ci + dv) - 128 - ci += 1 - local rv = (crv * v + 32768) // 65536 - local gv = -((cgu * u + cgv * v + 32768) // 65536) - local bu = (cbu * u + 32768) // 65536 - local yy = yt[readu8(src, yrow) + 1] - writeu32(dst, o, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) - yy = yt[readu8(src, yrow + 1) + 1] - writeu32(dst, o + 4, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) - if two then - yy = yt[readu8(src, yrow + w) + 1] - writeu32(dst, o + stride, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) - yy = yt[readu8(src, yrow + w + 1) + 1] - writeu32(dst, o + stride + 4, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) - end - yrow += 2 - o += 8 - end - if w % 2 == 1 then - local u = readu8(src, ci) - 128 - local v = readu8(src, ci + dv) - 128 - local rv = (crv * v + 32768) // 65536 - local gv = -((cgu * u + cgv * v + 32768) // 65536) - local bu = (cbu * u + 32768) // 65536 - local yy = yt[readu8(src, yrow) + 1] - writeu32(dst, o, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) - if two then - yy = yt[readu8(src, yrow + w) + 1] - writeu32(dst, o + stride, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) - end - end - end - return dst -end - -@native function Yuv.fromRgba(src: buffer, w: number, h: number, range: string?, matrix: string?, out: buffer?): buffer - local cw, ch = (w + 1) // 2, (h + 1) // 2 - local uo, vo = w * h, w * h + cw * ch - local dst = out or bcreate(w * h + 2 * cw * ch) - if buffer.len(src) < w * h * 4 or buffer.len(dst) < w * h + 2 * cw * ch then - return dst - end - local m = MATRIX[matrix or "bt601"] or MATRIX.bt601 - local kr, kb = m.kr, m.kb - local kg = 1 - kr - kb - local full = range == "full" - local ysc = if full then 1 else 219 / 255 - local csc = if full then 1 else 224 / 255 - local yof = if full then 0.5 else 16.5 - local yr, yg, yb = floor(kr * ysc * 65536 + 0.5), floor(kg * ysc * 65536 + 0.5), floor(kb * ysc * 65536 + 0.5) - local yoff = floor(yof * 65536) - local ur = floor(-kr / (2 * (1 - kb)) * csc * 65536 + 0.5) - local ug = floor(-kg / (2 * (1 - kb)) * csc * 65536 + 0.5) - local ub = floor(0.5 * csc * 65536 + 0.5) - local vr = ub - local vg = floor(-kg / (2 * (1 - kr)) * csc * 65536 + 0.5) - local vb = floor(-kb / (2 * (1 - kr)) * csc * 65536 + 0.5) - local coff4 = floor(128.5 * 65536) * 4 - for i = 0, w * h - 1 do - local o = i * 4 - local r, g, b = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2) - writeu8(dst, i, readu8(CLIP, (yr * r + yg * g + yb * b + yoff) // 65536 + 1024)) - end - for cy = 0, ch - 1 do - local y0 = cy * 2 - local y1 = if y0 + 1 < h then y0 + 1 else y0 - for cx = 0, cw - 1 do - local x0 = cx * 2 - local x1 = if x0 + 1 < w then x0 + 1 else x0 - local a, b2, c2, d = (y0 * w + x0) * 4, (y0 * w + x1) * 4, (y1 * w + x0) * 4, (y1 * w + x1) * 4 - local r = readu8(src, a) + readu8(src, b2) + readu8(src, c2) + readu8(src, d) - local g = readu8(src, a + 1) + readu8(src, b2 + 1) + readu8(src, c2 + 1) + readu8(src, d + 1) - local b = readu8(src, a + 2) + readu8(src, b2 + 2) + readu8(src, c2 + 2) + readu8(src, d + 2) - local i = cy * cw + cx - writeu8(dst, uo + i, readu8(CLIP, (ur * r + ug * g + ub * b + coff4) // 262144 + 1024)) - writeu8(dst, vo + i, readu8(CLIP, (vr * r + vg * g + vb * b + coff4) // 262144 + 1024)) - end - end - return dst -end - -@native local function info(img: Types.Image): (string, string) - local m = img.meta - local y = m and m.yuv - if type(y) == "table" then - return y.range or "limited", y.matrix or "bt601" - end - local src = m and m.source - if type(src) == "table" and src.range == "full" then - return "full", "bt601" - end - return "limited", "bt601" -end -Yuv.info = info - -@native function Yuv.planes(w: number, h: number): (number, number, number, number) - local cw, ch = (w + 1) // 2, (h + 1) // 2 - return w * h, w * h + cw * ch, cw, ch -end - -local FULL_Y = bcreate(256) -local FULL_C = bcreate(256) -for v = 0, 255 do - writeu8(FULL_Y, v, math.clamp(floor((v - 16) * 255 / 219 + 0.5), 0, 255)) - writeu8(FULL_C, v, math.clamp(floor((v - 128) * 255 / 224 + 128.5), 0, 255)) -end - -@native function Yuv.toFullRange(img: Types.Image): Types.Image - if img.format ~= "yuv420p" or info(img) == "full" then - return img - end - local w, h = img.width, img.height - local out = Types.Image.new(w, h, "yuv420p") - local src, dst = img.pixels, out.pixels - local ny = w * h - local n = math.min(buffer.len(src), buffer.len(dst)) - for i = 0, math.min(ny, n) - 1 do - writeu8(dst, i, readu8(FULL_Y, readu8(src, i))) - end - for i = ny, n - 1 do - writeu8(dst, i, readu8(FULL_C, readu8(src, i))) - end - out.meta.yuv = { range = "full", matrix = select(2, info(img)) } - out.meta.source = img.meta.source - return out -end - --- out: an rgba8 Image of the same size to write into (else a new one) -@native function Yuv.imageToRgba(img: Types.Image, out: Types.Image?, hook: (() -> ())?): Types.Image? - if img.format == "rgba8" then - return img - end - if img.format ~= "yuv420p" then - return nil - end - local w, h = img.width, img.height - local uo, vo, cw = Yuv.planes(w, h) - local range, matrix = info(img) - if not out or out.format ~= "rgba8" or out.width ~= w or out.height ~= h or buffer.len(out.pixels) < w * h * 4 then - out = Types.Image.new(w, h, "rgba8") - end - local o = out :: Types.Image - Yuv.toRgba(img.pixels, w, h, uo, vo, cw, range, matrix, o.pixels, hook) - o.meta.source = img.meta.source - return o -end - -@native function Yuv.imageFromRgba(img: Types.Image, range: string?, matrix: string?): Types.Image? - if img.format == "yuv420p" then - return img - end - if img.format ~= "rgba8" then - return nil - end - local out = Types.Image.new(img.width, img.height, "yuv420p") - Yuv.fromRgba(img.pixels, img.width, img.height, range, matrix, out.pixels) - out.meta.yuv = { range = range or "limited", matrix = matrix or "bt601" } - out.meta.source = img.meta.source - return out -end - -@native local function scalePlane(src: buffer, so: number, sw: number, sh: number, dst: buffer, d0: number, dw: number, dh: number, hook: (() -> ())?) - local fx, fy = sw / dw, sh / dh - for y = 0, dh - 1 do - if hook and y % 16 == 15 then - pcall(hook) - end - local sy = (y + 0.5) * fy - 0.5 - if sy < 0 then - sy = 0 - end - local y0 = floor(sy) - if y0 > sh - 1 then - y0 = sh - 1 - end - local y1 = if y0 < sh - 1 then y0 + 1 else y0 - local wy = floor((sy - y0) * 256) - local r0, r1 = so + y0 * sw, so + y1 * sw - local o = d0 + y * dw - for x = 0, dw - 1 do - local sx = (x + 0.5) * fx - 0.5 - if sx < 0 then - sx = 0 - end - local x0 = floor(sx) - if x0 > sw - 1 then - x0 = sw - 1 - end - local x1 = if x0 < sw - 1 then x0 + 1 else x0 - local wx = floor((sx - x0) * 256) - local a = readu8(src, r0 + x0) * (256 - wx) + readu8(src, r0 + x1) * wx - local b = readu8(src, r1 + x0) * (256 - wx) + readu8(src, r1 + x1) * wx - writeu8(dst, o + x, (a * (256 - wy) + b * wy + 32768) // 65536) - end - end -end - -@native function Yuv.scale(src: buffer, w: number, h: number, width: number, height: number, out: buffer?, hook: (() -> ())?): buffer - local dw: number = math.max(1, floor(width)) - local dh: number = math.max(1, floor(height)) - local cw: number = (w + 1) // 2 - local ch: number = (h + 1) // 2 - local dcw: number = (dw + 1) // 2 - local dch: number = (dh + 1) // 2 - local size = dw * dh + 2 * dcw * dch - local dst = if out and buffer.len(out) >= size then out else bcreate(size) - if w < 1 or h < 1 or buffer.len(src) < w * h + 2 * cw * ch then - return dst - end - scalePlane(src, 0, w, h, dst, 0, dw, dh, hook) - scalePlane(src, w * h, cw, ch, dst, dw * dh, dcw, dch, hook) - scalePlane(src, w * h + cw * ch, cw, ch, dst, dw * dh + dcw * dch, dcw, dch, hook) - return dst -end - --- out: a yuv420p Image of the target size to write into (else a new one) -@native function Yuv.imageScale(img: Types.Image, dw: number, dh: number, out: Types.Image?, hook: (() -> ())?): Types.Image - local tw, th = math.max(1, floor(dw)), math.max(1, floor(dh)) - if not out or out.format ~= "yuv420p" or out.width ~= tw or out.height ~= th then - out = Types.Image.new(tw, th, "yuv420p") - end - local o = out :: Types.Image - Yuv.scale(img.pixels, img.width, img.height, tw, th, o.pixels, hook) - o.meta = table.clone(img.meta or {}) - return o -end - -return Yuv -end -__FILES["codecs/model/Rbx"] = function() - --- codecs/model/Rbx: the Roblox instance tree and property values shared by model/rbxm and model/rbxmx. --- Written from the rbx-dom format notes (docs/binary.md, docs/xml.md); checked against rbx-dom through rojo / lune. --- Faces: bits Right 1, Top 2, Back 4, Left 8, Bottom 16, Front 32 --- Axes: bits X 1, Y 2, Z 4 --- UniqueId: 32 hex digits: random (16), time (8), index (8) - -local Rbx = {} - -type Value = { type: string, value: any } -type Instance = { - className: string, - name: string, - properties: { [string]: Value }, - children: { Instance }, - parent: Instance?, - referent: string?, - service: boolean?, -- a service (binary INST object format 1; rbxl roots) -} -type Tree = { - kind: "rbxtree", - roots: { Instance }, - place: boolean, - metadata: { [string]: string }, -- binary META / XML <Meta> entries (ExplicitAutoJoints, ...) - extra: { any }, - meta: { source: { format: string, [string]: any }?, [string]: any }, -} - -function Rbx.tree(place: boolean?): Tree - return { kind = "rbxtree", roots = {}, place = place == true, metadata = {}, extra = {}, meta = {} } -end - -function Rbx.instance(className: string, name: string?): Instance - return { className = className, name = name or className, properties = {}, children = {} } -end - -function Rbx.add(parent: any, child: Instance): Instance - if parent.kind == "rbxtree" then - child.parent = nil - table.insert(parent.roots, child) - else - child.parent = parent - table.insert(parent.children, child) - end - return child -end - -function Rbx.set(inst: Instance, name: string, typ: string, value: any) - inst.properties[name] = { type = typ, value = value } -end - -function Rbx.get(inst: Instance, name: string): any - local v = inst.properties[name] - return if v then v.value else nil -end - -function Rbx.descendants(root: any): () -> (Instance?, number?) - local stack: { any } = {} - local list = if root.kind == "rbxtree" then root.roots else root.children - for i = #list, 1, -1 do - table.insert(stack, { list[i], 1 }) - end - return function(): (Instance?, number?) - local top = table.remove(stack) - if not top then - return nil, nil - end - local inst, depth = top[1], top[2] - for i = #inst.children, 1, -1 do - table.insert(stack, { inst.children[i], depth + 1 }) - end - return inst, depth - end -end - -function Rbx.list(tree: any): { Instance } - local out = {} - for inst in Rbx.descendants(tree) do - table.insert(out, inst :: Instance) - end - return out -end - -function Rbx.find(root: any, path: string): Instance? - local cur: any = root - for part in string.gmatch(path, "[^/]+") do - local list = if cur.kind == "rbxtree" then cur.roots else cur.children - local found = nil - for _, c in list do - if c.name == part then - found = c - break - end - end - if not found then - return nil - end - cur = found - end - return if cur.kind == "rbxtree" then nil else cur -end - -function Rbx.fullName(inst: Instance): string - local parts = {} - local cur: Instance? = inst - while cur do - table.insert(parts, 1, cur.name) - cur = cur.parent - end - return table.concat(parts, ".") -end - --- The binary format stores axis-aligned rotations as one byte: id = 6 * n(RightVector) + n(UpVector) + 1, where n is --- the NormalId of a unit axis (+X 0, +Y 1, +Z 2, -X 3, -Y 4, -Z 5) and the third column is their cross product. -local AXES = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { -1, 0, 0 }, { 0, -1, 0 }, { 0, 0, -1 } } - -local ROTATIONS: { [number]: { number } } = {} -for a = 0, 5 do - for b = 0, 5 do - if a % 3 ~= b % 3 then - local r, u = AXES[a + 1], AXES[b + 1] - local k = { r[2] * u[3] - r[3] * u[2], r[3] * u[1] - r[1] * u[3], r[1] * u[2] - r[2] * u[1] } - -- columns: right, up, back (= right x up) - ROTATIONS[6 * a + b + 1] = { r[1], u[1], k[1] + 0, r[2], u[2], k[2] + 0, r[3], u[3], k[3] + 0 } - end - end -end -Rbx.ROTATIONS = ROTATIONS - -local function axisIndex(x: number, y: number, z: number): number? - for i, a in AXES do - if a[1] == x and a[2] == y and a[3] == z then - return i - 1 - end - end - return nil -end - -function Rbx.rotationId(cf: { number }): number - local a = axisIndex(cf[4], cf[7], cf[10]) - local b = axisIndex(cf[5], cf[8], cf[11]) - if not a or not b then - return 0 - end - local id = 6 * a + b + 1 - local rot = ROTATIONS[id] - if not rot or rot[3] ~= cf[6] or rot[6] ~= cf[9] or rot[9] ~= cf[12] then - return 0 - end - return id -end - --- binary type ids (rbx-dom docs/binary.md) by type name, and back -Rbx.TYPE_IDS = table.freeze({ - String = 0x01, - BinaryString = 0x01, - ProtectedString = 0x01, - ContentId = 0x01, - Bool = 0x02, - Int32 = 0x03, - Float32 = 0x04, - Float64 = 0x05, - UDim = 0x06, - UDim2 = 0x07, - Ray = 0x08, - Faces = 0x09, - Axes = 0x0A, - BrickColor = 0x0B, - Color3 = 0x0C, - Vector2 = 0x0D, - Vector3 = 0x0E, - Vector2int16 = 0x0F, - CFrame = 0x10, - Enum = 0x12, - Ref = 0x13, - Vector3int16 = 0x14, - NumberSequence = 0x15, - ColorSequence = 0x16, - NumberRange = 0x17, - Rect = 0x18, - PhysicalProperties = 0x19, - Color3uint8 = 0x1A, - Int64 = 0x1B, - SharedString = 0x1C, - Bytecode = 0x1D, - OptionalCFrame = 0x1E, - UniqueId = 0x1F, - Font = 0x20, - SecurityCapabilities = 0x21, - Content = 0x22, -} :: { [string]: number }) -local NAMES: { [number]: string } = {} -for name, id in Rbx.TYPE_IDS do - if NAMES[id] == nil or name == "String" then - NAMES[id] = name - end -end -Rbx.TYPE_NAMES = table.freeze(NAMES) - --- BrickColor 194 (Medium stone grey) is Roblox's default -local IDENTITY_CF = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 } -function Rbx.default(typ: string): any - if typ == "String" or typ == "BinaryString" or typ == "ProtectedString" or typ == "ContentId" or typ == "Bytecode" or typ == "SharedString" then - return "" - elseif typ == "Bool" then - return false - elseif typ == "BrickColor" then - return 194 - elseif typ == "UDim" or typ == "NumberRange" or typ == "Vector2" or typ == "Vector2int16" then - return { 0, 0 } - elseif typ == "UDim2" or typ == "Rect" then - return { 0, 0, 0, 0 } - elseif typ == "Vector3" or typ == "Vector3int16" or typ == "Color3" or typ == "Color3uint8" then - return { 0, 0, 0 } - elseif typ == "Ray" then - return { 0, 0, 0, 0, 0, 0 } - elseif typ == "CFrame" then - return table.clone(IDENTITY_CF) - elseif typ == "NumberSequence" then - return { { 0, 0, 0 }, { 1, 0, 0 } } - elseif typ == "ColorSequence" then - return { { 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0 } } - elseif typ == "UniqueId" then - return string.rep("0", 32) - elseif typ == "Font" then - return { family = "rbxasset://fonts/families/SourceSansPro.json", weight = 400, style = "Normal" } - elseif typ == "PhysicalProperties" or typ == "Ref" or typ == "OptionalCFrame" or typ == "Content" then - return nil - end - return 0 -end - -Rbx.STRINGS = table.freeze({ String = true, BinaryString = true, ProtectedString = true, ContentId = true, Bytecode = true } :: { [string]: boolean }) - -return Rbx -end -__FILES["codecs/video/Video"] = function() - - --- codecs/video/Video: the video codec registry and the generic VideoDecoder. New in rosetta. -local Err = __include("core/Err") -local Types = __include("Types") -local Yuv = __include("codecs/image/Yuv") -local Disposable = __include("codecs/video/Video/Disposable") -local Pool = __include("codecs/video/Video/Pool") - -local Video = {} - -type Entry = { - id: string, - name: string, - fourcc: { string }?, -- AVI biCompression / MOV sample entry FourCCs - matroska: { string }?, -- Matroska / WebM CodecIDs - new: ((track: Types.Track, opts: any?) -> (Types.VideoCodecDecoder?, Err.Err?))?, - [string]: any, -} - --- decodeOne -> nil, nil: a packet with no picture to show (a hidden VP8 altref frame); false: a picture skipped -function Video.simpleDecoder(decodeOne: (data: buffer, packet: Types.Packet) -> (Types.Image? | false, Err.Err?), resetFn: (() -> ())?): Types.VideoCodecDecoder - local queue: { any } = {} - local self = {} - function self.decode(_: any, packet: Types.Packet): Err.Err? - local ok, img, err = pcall(decodeOne, packet.data, packet) - if not ok then - return Err.new(Err.CORRUPT, "decoder threw: " .. tostring(img)) - end - if img ~= nil then - table.insert(queue, { img, packet.pts, packet.keyframe }) - end - return err - end - function self.receive(_: any): (Types.Image? | false, number?, boolean?) - local q = table.remove(queue, 1) - if q then - return q[1], q[2], q[3] - end - return nil, nil, nil - end - function self.flush(_: any) end - function self.reset(_: any) - table.clear(queue) - if resetFn then - resetFn() - end - end - return self :: any -end - --- raw video: yuv420p (I420 / IYUV / y4m), yv12 (V before U), yuv422p / yuv444p / yuva444p / gray (chroma averaged --- down to 4:2:0, alpha dropped), track.bitDepth 9..16 (little-endian 16-bit samples scaled to 8 bits), rgb24 / bgr24 / --- bgra / rgba (AVI DIBs: track.flip = bottom-up rows, track.stride = padded rows) -local function rawPlanar(data: buffer, pf: string, bits: number, w: number, h: number): Types.Image - local img = Types.Image.new(w, h, "yuv420p") - local px = img.pixels - local cw, ch = (w + 1) // 2, (h + 1) // 2 - local bps = if bits > 8 then 2 else 1 - local shift = 2 ^ (bits - 8) - local function sample(o: number): number - if bps == 1 then - return buffer.readu8(data, o) - end - return math.min(255, buffer.readu16(data, o) // shift) - end - for i = 0, w * h - 1 do - buffer.writeu8(px, i, sample(i * bps)) - end - local scw, sch = w, h -- source chroma plane size - if pf == "yuv420p" then - scw, sch = cw, ch - elseif pf == "yuv422p" then - scw, sch = cw, h - end - local uo, vo = w * h * bps, (w * h + scw * sch) * bps - for cy = 0, ch - 1 do - for cx = 0, cw - 1 do - local i = cy * cw + cx - local u, v - if pf == "gray" then - u, v = 128, 128 - elseif pf == "yuv420p" then - u, v = sample(uo + i * bps), sample(vo + i * bps) :: number - elseif pf == "yuv422p" then - local y0, y1 = cy * 2, math.min(cy * 2 + 1, h - 1) - u = (sample(uo + (y0 * scw + cx) * bps) + sample(uo + (y1 * scw + cx) * bps) + 1) // 2 - v = (sample(vo + (y0 * scw + cx) * bps) + sample(vo + (y1 * scw + cx) * bps) + 1) // 2 - else - local x0, x1 = cx * 2, math.min(cx * 2 + 1, w - 1) - local y0, y1 = cy * 2, math.min(cy * 2 + 1, h - 1) - local a, b, c, d = (y0 * w + x0) * bps, (y0 * w + x1) * bps, (y1 * w + x0) * bps, (y1 * w + x1) * bps - u = (sample(uo + a) + sample(uo + b) + sample(uo + c) + sample(uo + d) + 2) // 4 - v = (sample(vo + a) + sample(vo + b) + sample(vo + c) + sample(vo + d) + 2) // 4 - end - buffer.writeu8(px, w * h + i, u) - buffer.writeu8(px, w * h + cw * ch + i, v) - end - end - return img -end - -local PLANAR_SIZE: { [string]: (w: number, h: number, cw: number, ch: number) -> number } = { - yuv420p = function(w, h, cw, ch) - return w * h + 2 * cw * ch - end, - yv12 = function(w, h, cw, ch) - return w * h + 2 * cw * ch - end, - yuv422p = function(w, h, cw, _ch) - return w * h + 2 * cw * h - end, - yuv444p = function(w, h) - return w * h * 3 - end, - yuva444p = function(w, h) - return w * h * 4 - end, - gray = function(w, h) - return w * h - end, -} - -local function rawDecoder(track: Types.Track, _opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local w, h = track.width or 0, track.height or 0 - if w <= 0 or h <= 0 or w * h > 2 ^ 26 then - return nil, Err.new(Err.CORRUPT, "raw video without a valid size") - end - local pf = track.pixelFormat or "yuv420p" - local bits = track.bitDepth or 8 - local cw, ch = (w + 1) // 2, (h + 1) // 2 - local flip = track.flip == true - local planar = PLANAR_SIZE[pf] - return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?) - local n = buffer.len(data) - if planar then - local need = planar(w, h, cw, ch) * (if bits > 8 then 2 else 1) - if n < need then - return nil, Err.new(Err.TRUNCATED, "raw frame: " .. n .. " of " .. need .. " bytes") - end - if pf == "yuv420p" and bits == 8 then - local img = Types.Image.new(w, h, "yuv420p") - buffer.copy(img.pixels, 0, data, 0, need) - return img, nil - elseif pf == "yv12" then - local img = Types.Image.new(w, h, "yuv420p") - buffer.copy(img.pixels, 0, data, 0, w * h) - buffer.copy(img.pixels, w * h, data, w * h + cw * ch, cw * ch) - buffer.copy(img.pixels, w * h + cw * ch, data, w * h, cw * ch) - return img, nil - end - return rawPlanar(data, pf, bits, w, h), nil - end - local bpp = if pf == "bgra" or pf == "rgba" then 4 else 3 - local stride: number = track.stride or w * bpp - if n < stride * (h - 1) + w * bpp then - return nil, Err.new(Err.TRUNCATED, "raw frame too short") - end - local img = Types.Image.new(w, h, "rgba8") - local px = img.pixels - local bgr = pf == "bgr24" or pf == "bgra" - for y = 0, h - 1 do - local s = (if flip then h - 1 - y else y) * stride - local o = y * w * 4 - for x = 0, w - 1 do - local p = s + x * bpp - local a, b, c = buffer.readu8(data, p), buffer.readu8(data, p + 1), buffer.readu8(data, p + 2) - if bgr then - a, c = c, a - end - buffer.writeu32(px, o + x * 4, a + b * 256 + c * 65536 + 0xff000000) - end - end - return img, nil - end), nil -end - -local function vp8Decoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local Vp8 = __include("codecs/image/Vp8") - local dec = Vp8.newDecoder() - local o = { maxPixels = opts and opts.maxPixels, yield = opts and opts.yield, skipDisposable = opts and opts.skipDisposable } - local self: any - self = Video.simpleDecoder(function(data: buffer): (Types.Image? | false, Err.Err?) - local img, err = dec:decodeFrame(data, 0, buffer.len(data), o) - if not img then - if err then - return nil, err - end - self.skipped += 1 - -- show_frame (RFC 6386 9.1): a shown frame keeps its place - return if buffer.readu8(data, 0) // 16 % 2 == 1 then false else nil, nil - end - local src = img.meta.source - if type(src) == "table" and src.show == false then - return nil, nil - end - img.meta.yuv = { range = "limited", matrix = "bt601" } - return img, nil - end, function() - if dec.reset then - dec:reset() - else - dec = Vp8.newDecoder() - end - end) :: any - self.skipped = 0 - function self.release(_: any, image: Types.Image): boolean - return dec:release(image) - end - return self, nil -end - --- Motion JPEG: yuv420p straight from the planes (full range) when the layout allows, else rgba8 -local function mjpegDecoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local Jpeg = __include("codecs/image/Jpeg") - local o: Jpeg.DecodeOptions = { yuv = true, maxPixels = opts and opts.maxPixels } - return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?) - local img, err = Jpeg.decode(data, 0, buffer.len(data), o) - if img and img.format == "yuv420p" then - img.meta.yuv = { range = "full", matrix = "bt601" } - end - return img, err - end), nil -end - --- the MJPEG encoder (writers): JPEG is full-range, so limited-range yuv420p frames are remapped first -local function mjpegEncode(img: Types.Image, opts: any?): (buffer?, Err.Err?) - local Jpeg = __include("codecs/image/Jpeg") - local src = img - if img.format == "yuv420p" then - local range = Yuv.info(img) - if range ~= "full" then - src = Yuv.toFullRange(img) - end - end - return Jpeg.encode(src, { quality = opts and opts.quality or 90 }) -end - -local function mpeg2Decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local Mpeg2 = __include("codecs/video/Mpeg2") - return Mpeg2.newVideoDecoder(track, opts) -end - -local function h264Decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local H264 = __include("codecs/video/H264") - return H264.newVideoDecoder(track, opts) -end - -local function h263Decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local H263 = __include("codecs/video/H263") - local dec = H263.new({ flv = track.codec == "flv1", maxPixels = opts and opts.maxPixels }) - return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?) - return dec:image(data) - end, function() - dec:reset() - end), nil -end - -local function theoraDecoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local Theora = __include("codecs/video/Theora") - return Theora.newVideoDecoder(track, opts) -end - -local function legacyDecoder(id: string): (track: Types.Track, opts: any?) -> (Types.VideoCodecDecoder?, Err.Err?) - return function(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - return __include("codecs/video/Legacy").newDecoder(id, track, opts) - end -end - --- FourCCs compare case-sensitively first, then upper-cased -local BUILTIN: { Entry } = { - { id = "vp8", name = "VP8", fourcc = { "VP80", "vp08" }, matroska = { "V_VP8" }, new = vp8Decoder }, - { id = "mjpeg", name = "Motion JPEG", fourcc = { "MJPG", "mjpa", "mjpb", "jpeg", "AVRn", "AVDJ", "dmb1", "LJPG", "JPGL", "MJLS", "ijpg" }, matroska = { "V_MJPEG" }, new = mjpegDecoder, encode = mjpegEncode }, - { id = "mpeg1", name = "MPEG-1 video", fourcc = { "mpg1", "MPG1", "PIM1", "m1v " }, matroska = { "V_MPEG1" }, new = mpeg2Decoder }, - { id = "rawvideo", name = "raw video", fourcc = { "\0\0\0\0", "I420", "IYUV", "YV12", "raw ", "DIB " }, matroska = { "V_UNCOMPRESSED" }, new = rawDecoder }, - { id = "mpeg2", name = "MPEG-2 video", fourcc = { "mpg2", "MPG2", "MPEG", "mp2v", "hdv1", "hdv2", "hdv3", "hdv5", "hdv6", "hdv7", "hdv8", "hdv9", "hdva", "xdv1", "xdv2", "xdv3", "xdv4", "xdv5", "xdv6", "xdv7", "xdv8", "xdv9", "xdva", "xdvb", "xdvc", "xdvd", "xdve", "xdvf", "xd54", "xd55", "xd59", "xd5a", "xd5b", "xd5c", "xd5d", "xd5e", "xd5f", "xdhd", "xdh2", "AVmp", "mx3n", "mx3p", "mx4n", "mx4p", "mx5n", "mx5p", "mmes", "MMES", "M701", "M702", "M703", "M704", "M705", "mpgv", "m2v1", "M2V1" }, matroska = { "V_MPEG2" }, new = mpeg2Decoder }, - { id = "mpeg4", name = "MPEG-4 part 2", fourcc = { "mp4v", "FMP4", "XVID", "DIVX", "DX50", "MP4V" }, matroska = { "V_MPEG4/ISO/SP", "V_MPEG4/ISO/ASP", "V_MPEG4/ISO/AP" } }, - { id = "h264", name = "H.264 / AVC", fourcc = { "avc1", "avc3", "H264", "h264", "X264", "x264", "AVC1", "DAVC", "VSSH" }, matroska = { "V_MPEG4/ISO/AVC" }, new = h264Decoder }, - { id = "hevc", name = "H.265 / HEVC", fourcc = { "hvc1", "hev1", "HEVC", "H265" }, matroska = { "V_MPEGH/ISO/HEVC" } }, - { id = "vp9", name = "VP9", fourcc = { "VP90", "vp09" }, matroska = { "V_VP9" } }, - { id = "av1", name = "AV1", fourcc = { "AV01", "av01" }, matroska = { "V_AV1" } }, - { id = "theora", name = "Theora", matroska = { "V_THEORA" }, new = theoraDecoder }, - { id = "h263", name = "H.263", fourcc = { "H263", "h263", "s263", "U263" }, new = h263Decoder }, - { id = "flv1", name = "Sorenson Spark (FLV1)", fourcc = { "FLV1" }, new = h263Decoder }, - { id = "vp6f", name = "On2 VP6 (Flash)", fourcc = { "VP6F", "FLV4" } }, - { id = "vp6a", name = "On2 VP6 with alpha (Flash)", fourcc = { "VP6A" } }, - { id = "flashsv", name = "Flash Screen Video", fourcc = { "FSV1" } }, - { id = "flashsv2", name = "Flash Screen Video 2" }, - { id = "png", name = "PNG", fourcc = { "png ", "MPNG" }, matroska = { "V_PNG" } }, - { id = "cinepak", name = "Cinepak", fourcc = { "cvid" }, new = legacyDecoder("cinepak") }, - { id = "msvideo1", name = "Microsoft Video 1", fourcc = { "CRAM", "MSVC", "WHAM" }, new = legacyDecoder("msvideo1") }, - { id = "qtrle", name = "QuickTime Animation (RLE)", fourcc = { "rle " }, new = legacyDecoder("qtrle") }, - { id = "smc", name = "QuickTime Graphics (SMC)", fourcc = { "smc " }, new = legacyDecoder("smc") }, - { id = "flic", name = "Autodesk Animator FLIC", fourcc = { "AFLC" }, new = legacyDecoder("flic") }, - { id = "smackvid", name = "Smacker video", fourcc = { "SMK2", "SMK4" }, new = legacyDecoder("smackvid") }, -} - -local byId: { [string]: Entry } = {} -local byFourcc: { [string]: string } = {} -local byMatroska: { [string]: string } = {} - -function Video.register(entry: Entry): (boolean, Err.Err?) - if type(entry) ~= "table" or type(entry.id) ~= "string" then - return false, Err.new(Err.ARG, "register: needs an entry with an id") - end - local old = byId[entry.id] - if old and entry.new == nil then - entry.new = old.new - end - byId[entry.id] = entry - for _, f in entry.fourcc or {} do - byFourcc[f] = entry.id - end - for _, m in entry.matroska or {} do - byMatroska[m] = entry.id - end - return true, nil -end -for _, e in BUILTIN do - Video.register(e) -end - -Video.codecs = byId - -function Video.fromFourcc(fcc: string): string? - return byFourcc[fcc] or byFourcc[string.upper(fcc)] or byFourcc[string.lower(fcc)] -end - -function Video.fromMatroska(id: string): string? - return byMatroska[id] -end - -function Video.entry(id: string): Entry? - return byId[id] -end - --- disposable: no later frame predicts from the packet's; droppable: it may also be left out unread (VP8 headers can --- carry probability and loop filter updates, so a disposable VP8 frame is droppable only without them) -function Video.isDisposable(track: Types.Track | string, packet: Types.Packet | buffer): (boolean, boolean) - local codec = if type(track) == "table" then track.codec else track - local config = if type(track) == "table" then track.config else nil - local data = if type(packet) == "table" then packet.data else packet - if type(data) ~= "buffer" or type(codec) ~= "string" then - return false, false - end - return Disposable.check(codec, data, config) -end - -function Video.canDecode(id: string): boolean - local e = byId[id] - return e ~= nil and e.new ~= nil -end - -function Video.decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) - local e = byId[track.codec] - if not e or not e.new then - return nil, Err.new(Err.UNSUPPORTED, "no decoder for video codec " .. tostring(track.codec)) - end - local ok, dec, err = pcall(e.new :: any, track, opts) - if not ok then - return nil, Err.new(Err.CORRUPT, "codec " .. track.codec .. " failed to start: " .. tostring(dec)) - end - return dec, err -end - -local function toRGBA(_self: any, f: any): Types.Image - local img = if type(f) == "table" and f.image then f.image else f - local out = Yuv.imageToRgba(img) - return out or img -end - -type OpenOptions = { - rgba: boolean?, - track: number?, - maxPixels: number?, - openAudio: ((demuxer: Types.Demuxer, track: Types.Track) -> (Types.Decoder?, Err.Err?))?, - audio: boolean?, - maxSide: number?, - yield: (() -> ())?, - skipDisposable: boolean?, - reuse: boolean?, -- nextFrame may overwrite the Image of the frame it returned before - [string]: any, -} - -function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDecoder?, Err.Err?) - local o: OpenOptions = opts or {} - local track: Types.Track? = nil - if o.track then - for _, t in demuxer.tracks do - if t.id == o.track then - track = t - end - end - if not track then - return nil, Err.new(Err.ARG, "no track " .. tostring(o.track)) - end - else - track = demuxer:track("video") - end - local codec: Types.VideoCodecDecoder? = nil - local codecErr: Err.Err? = nil - if track then - codec, codecErr = Video.decoder(track, o) - else - codecErr = Err.new(Err.UNSUPPORTED, "no video track") - end - local v: any = { - kind = "video", - format = demuxer.format, - codec = if track then track.codec else "none", - width = if track then track.width or 0 else 0, - height = if track then track.height or 0 else 0, - frameRate = if track then track.frameRate or 0 else 0, - frames = if track then track.frames or 0 else 0, - duration = if track and track.duration and track.duration > 0 then track.duration else demuxer.duration, - track = track, - demuxer = demuxer, - meta = demuxer.meta or {}, - decodeError = codecErr, - toRGBA = toRGBA, - } - if v.frames == 0 and v.frameRate > 0 and v.duration > 0 then - v.frames = math.floor(v.duration * v.frameRate + 0.5) - end - if o.audio ~= false then - local at = demuxer:track("audio") - if at then - if o.openAudio then - local ok, dec, err = pcall(o.openAudio, demuxer, at) - if ok and dec then - v.audio = dec - else - v.audioError = if ok then err else Err.new(Err.CORRUPT, "audio: " .. tostring(dec)) - end - else - v.audioError = Err.new(Err.UNSUPPORTED, "no audio hook (open through the api: F.video.open)") - end - end - end - local index, flushed, skipUntil = 0, false, -math.huge - local tid = if track then track.id else -1 - local scale: number = if track and track.timescale and track.timescale > 0 then track.timescale else 1000 - local start = demuxer.startTime or 0 - v.startTime = start - local defaultDur = if v.frameRate > 0 then 1 / v.frameRate else 0 - local lastPts = nil :: number? - -- rgba8 / scaled Images made here; the codec's own go back through codec:release - local own = Pool.new(2) - local function recycle(img: any) - if img and not own:give(img) and codec and codec.release then - codec:release(img) - end - end - local lastFrame: any = nil - function v.release(self: any, frame: any) - recycle(if type(frame) == "table" and frame.kind == "image" then frame else type(frame) == "table" and frame.image) - end - function v.nextFrame(self: any): (Types.VideoFrame?, Err.Err?) - if not codec then - return nil, codecErr - end - if lastFrame then - recycle(lastFrame.image) - lastFrame = nil - end - local dec = codec :: Types.VideoCodecDecoder - while true do - local img, pts, key = dec:receive() - if img == false then - -- a picture skipped (skipDisposable): it keeps its place in output order - if index >= 0 then - index += 1 - end - elseif img then - local t = (pts or 0) / scale - start - if t + 1e-9 >= skipUntil then - if index < 0 then - -- after a seek: constant-rate index = round(pts * fps), else counted from the seek - index = if v.frameRate > 0 then math.max(0, math.floor(t * v.frameRate + 0.5)) else 0 - end - index += 1 - local d = defaultDur - if lastPts and t > (lastPts :: number) and defaultDur == 0 then - d = t - (lastPts :: number) - end - lastPts = t - local maxSide = o.maxSide - local hook = o.yield - if hook and (o.rgba or maxSide) then - pcall(hook) - end - if maxSide and maxSide >= 1 and img.format == "yuv420p" and math.max(img.width, img.height) > maxSide then - local s = maxSide / math.max(img.width, img.height) - local dw, dh = math.max(1, math.floor(img.width * s + 0.5)), math.max(1, math.floor(img.height * s + 0.5)) - local src = img - img = Yuv.imageScale(src, dw, dh, own:take(dw, dh, "yuv420p"), o.yield) - recycle(src) -- (never seen by the caller) - end - if o.rgba and img.format == "yuv420p" then - local src = img - img = Yuv.imageToRgba(src, own:take(src.width, src.height, "rgba8"), o.yield) or src - recycle(src) - end - local frame = { image = img, pts = t, duration = d, keyframe = key, index = index } - if o.reuse then - lastFrame = frame - end - return frame, nil - end - else - local p = demuxer:read(tid) - if p == nil then - if flushed then - return nil, nil - end - flushed = true - dec:flush() - else - local err = dec:decode(p) - if err then - return nil, err - end - end - end - end - end - function v.seek(self: any, seconds: number) - lastFrame = nil - demuxer:seek(seconds + start) - if codec then - codec:reset() - end - flushed = false - skipUntil = seconds - lastPts = nil - index = -1 -- recomputed from the first frame's time - if self.audio then - pcall(self.audio.seek, self.audio, seconds) - end - end - function v.reset(self: any) - self:seek(0) - skipUntil = -math.huge - index = 0 - end - return v, nil -end - -function Video.fromFrames(images: { Types.Image }, delays: (number | { number })?, opts: any?): (Types.VideoDecoder?, Err.Err?) - if type(images) ~= "table" or #images == 0 or type(images[1]) ~= "table" then - return nil, Err.new(Err.ARG, "fromFrames: needs a list of Images") - end - local w, h = images[1].width, images[1].height - local pts: { number } = {} - local durs: { number } = {} - local t = 0 - for i, img in images do - if type(img) ~= "table" or img.width ~= w or img.height ~= h then - return nil, Err.new(Err.ARG, "fromFrames: frame " .. i .. " is not a " .. w .. "x" .. h .. " Image") - end - local d = if type(delays) == "table" then delays[i] or 0.1 else (delays or 0.1) - if type(d) ~= "number" or d ~= d or d < 0 then - d = 0.1 - end - pts[i] = t - durs[i] = d - t += d - end - local n = #images - local o = opts or {} - local v: any = { - kind = "video", - format = o.format or "frames", - codec = "frames", - width = w, - height = h, - frameRate = if t > 0 then n / t else 10, - frames = n, - duration = t, - loops = o.loops, - meta = o.meta or {}, - toRGBA = toRGBA, - images = images, - } - local i = 0 - function v.nextFrame(self: any): (Types.VideoFrame?, Err.Err?) - i += 1 - if i > n then - i = n - return nil, nil - end - local img = images[i] - if o.rgba then - img = Yuv.imageToRgba(img) or img - end - return { image = img, pts = pts[i], duration = durs[i], keyframe = true, index = i }, nil - end - function v.seek(self: any, seconds: number) - local k = 0 - for j = 1, n do - if pts[j] <= seconds + 1e-9 then - k = j - 1 - end - end - i = k - end - function v.reset(self: any) - i = 0 - end - return v, nil -end - -return Video -end -__FILES["codecs/video/Video/Disposable"] = function() - - --- codecs/video/Video/Disposable: packets whose frame no later frame predicts from (a player may skip decoding them). --- H.264: the first VCL NAL unit has nal_ref_idc 0 (7.4.1: then every slice of the picture has), and no parameter --- set comes before it; one access unit per packet, length-prefixed (avcC lengthSizeMinusOne) or Annex B. --- VP8 (RFC 6386 9.3-9.11, 19.2): an inter frame that refreshes no reference (last / golden / altref, no copies) and --- leaves the segment map; its header may still change decoder state (probabilities, loop filter deltas). -local readu8 = buffer.readu8 - -local Disposable = {} - --- the offset of the first byte after the first start code at or after p, or -1 -local function nextStart(b: buffer, p: number, e: number): number - local i = p - while i + 2 < e do - local b2 = readu8(b, i + 2) - if b2 > 1 then - i += 3 - elseif readu8(b, i + 1) ~= 0 then - i += 2 - elseif b2 == 1 and readu8(b, i) == 0 then - return i + 3 - else - i += 1 - end - end - return -1 -end - --- nal_unit_type 1..5: slices (decided by nal_ref_idc); 7, 8, 13, 15: parameter sets (never dropped) -local function nalVerdict(hdr: number): boolean? - local t = hdr % 32 - if t >= 1 and t <= 5 then - return hdr // 32 % 4 == 0 - elseif t == 7 or t == 8 or t == 13 or t == 15 then - return false - end - return nil -end - -function Disposable.h264(b: buffer, lengthSize: number?): boolean - local n = buffer.len(b) - if lengthSize then - local p = 0 - while p + lengthSize < n do - local len = 0 - for k = 0, lengthSize - 1 do - len = len * 256 + readu8(b, p + k) - end - p += lengthSize - if len > n - p then - return false - end - if len > 0 then - local v = nalVerdict(readu8(b, p)) - if v ~= nil then - return v - end - end - p += len - end - return false - end - if n >= 3 and readu8(b, 0) == 0 and readu8(b, 1) == 0 then - local p = nextStart(b, 0, n) - while p >= 0 and p < n do - local v = nalVerdict(readu8(b, p)) - if v ~= nil then - return v - end - p = nextStart(b, p, n) - end - return false - end - return n > 0 and nalVerdict(readu8(b, 0)) == true -end - --- the boolean decoder of RFC 6386 7.3 (a 2-byte window), enough for the frame header -type Bool = { b: buffer, p: number, e: number, value: number, range: number, count: number } - -local function byteAt(d: Bool): number - local p = d.p - d.p = p + 1 - return if p < d.e then readu8(d.b, p) else 0 -end - -local function boolNew(b: buffer, p: number, e: number): Bool - local d: Bool = { b = b, p = p, e = e, value = 0, range = 255, count = 0 } - d.value = byteAt(d) * 256 + byteAt(d) - return d -end - -local function boolRead(d: Bool, prob: number): number - local split = 1 + (d.range - 1) * prob // 256 - local big = split * 256 - local bit = 0 - if d.value >= big then - bit = 1 - d.range -= split - d.value -= big - else - d.range = split - end - while d.range < 128 do - d.value *= 2 - d.range *= 2 - d.count += 1 - if d.count == 8 then - d.count = 0 - d.value += byteAt(d) - end - end - return bit -end - -local function lit(d: Bool, n: number): number - local v = 0 - for _ = 1, n do - v = v * 2 + boolRead(d, 128) - end - return v -end - --- skips flag ? (n bits + sign) : nothing -local function optSigned(d: Bool, n: number) - if lit(d, 1) == 1 then - lit(d, n + 1) - end -end - --- disposable: no reference refresh or copy and no segment map update; droppable: also no state the decoder keeps --- (refresh_entropy_probs 0, no segment feature or loop filter delta update) -function Disposable.vp8(b: buffer): (boolean, boolean) - local n = buffer.len(b) - if n < 4 then - return false, false - end - local tag = readu8(b, 0) + readu8(b, 1) * 256 + readu8(b, 2) * 65536 - if tag % 2 == 0 then - return false, false -- key frame - end - local first = tag // 32 - if first > n - 3 then - return false, false - end - local d = boolNew(b, 3, 3 + first) - local keep = true - if lit(d, 1) == 1 then -- segmentation_enabled - local updateMap, updateData = lit(d, 1), lit(d, 1) - if updateMap == 1 then - return false, false - end - if updateData == 1 then - keep = false - lit(d, 1) -- segment_feature_mode - for _ = 1, 4 do - optSigned(d, 7) - end - for _ = 1, 4 do - optSigned(d, 6) - end - end - end - lit(d, 1 + 6 + 3) -- filter_type, loop_filter_level, sharpness_level - if lit(d, 1) == 1 and lit(d, 1) == 1 then -- loop_filter_adj_enable, mode_ref_lf_delta_update - keep = false - for _ = 1, 8 do - optSigned(d, 6) - end - end - lit(d, 2 + 7) -- log2_nbr_of_dct_partitions, y_ac_qi - for _ = 1, 5 do - optSigned(d, 4) - end - local refreshGolden, refreshAlt = lit(d, 1), lit(d, 1) - if refreshGolden == 1 or refreshAlt == 1 then - return false, false - end - if lit(d, 2) ~= 0 or lit(d, 2) ~= 0 then -- copy_buffer_to_golden, copy_buffer_to_alternate - return false, false - end - lit(d, 2) -- sign_bias_golden, sign_bias_alternate - local refreshEntropy, refreshLast = lit(d, 1), lit(d, 1) - if refreshLast == 1 or d.p > d.e + 2 then - return false, false - end - return true, keep and refreshEntropy == 0 -end - --- the avcC NAL length size of a track (nil: Annex B or one bare NAL unit per packet) -function Disposable.lengthSize(config: buffer?): number? - if config and buffer.len(config) >= 7 and readu8(config, 0) == 1 then - return readu8(config, 4) % 4 + 1 - end - return nil -end - --- disposable: no later frame predicts from it; droppable: it can also be left out without telling the decoder -function Disposable.check(codec: string?, data: buffer, config: buffer?): (boolean, boolean) - if codec == "h264" then - local v = Disposable.h264(data, Disposable.lengthSize(config)) - return v, v - elseif codec == "vp8" then - return Disposable.vp8(data) - end - return false, false -end - -return Disposable -end -__FILES["codecs/video/Video/Pool"] = function() - - --- codecs/video/Video/Pool: output Images handed back by the caller (decoder:release), reused for later frames. Only --- Images this pool made are taken back; a reused Image gets a fresh meta table. -local Types = __include("Types") - -local Pool = {} -Pool.__index = Pool - -type Pool = typeof(setmetatable({} :: { free: { Types.Image }, made: { [Types.Image]: boolean }, max: number }, Pool)) - -function Pool.new(max: number?): Pool - return setmetatable({ free = {}, made = setmetatable({}, { __mode = "k" }) :: any, max = max or 3 }, Pool) -end - -function Pool.take(self: Pool, w: number, h: number, format: Types.PixelFormat): Types.Image - local free = self.free - for i = #free, 1, -1 do - local img = free[i] - if img.width == w and img.height == h and img.format == format then - table.remove(free, i) - img.meta = {} - return img - end - end - local img = Types.Image.new(w, h, format) - self.made[img] = true - return img -end - --- true when the Image was this pool's (it is kept for reuse, or dropped when the pool is full) -function Pool.give(self: Pool, img: any): boolean - if type(img) ~= "table" or not self.made[img] then - return false - end - local free = self.free - for _, q in free do - if q == img then - return true - end - end - if #free < self.max then - table.insert(free, img) - else - self.made[img] = nil - end - return true -end - -return Pool -end -__FILES["containers/AudioWrap"] = function() - --- containers/AudioWrap: a video container's audio track as a stream an audio format reads (a format never requires --- another). New in rosetta. PCM / WAVEFORMATEX -> WAV, adpcm_swf -> f32 WAV, mp1-3 / ac3 -> frames back to back, --- flac -> fLaC + metadata blocks, opus / vorbis -> Ogg, aac -> ADTS. E-AC-3 is UNSUPPORTED. -local Err = __include("core/Err") -local Bytes = __include("core/Bytes") -local Types = __include("Types") -local Mux = __include("containers/Ogg/Mux") -local Adpcm = __include("codecs/audio/Adpcm") - -local AudioWrap = {} - -type PacketSource = { - count: ((self: any, track: number) -> number)?, - get: ((self: any, track: number, k: number) -> Types.Packet?)?, -} - -local function allPackets(dmx: PacketSource, track: Types.Track): { Types.Packet } - local out: { Types.Packet } = {} - local n = if dmx.count then dmx:count(track.id) else 0 - if n > 0 and dmx.get then - for k = 1, n do - local p = dmx:get(track.id, k) - if p then - table.insert(out, p) - end - end - end - return out -end - -local function concat(packets: { Types.Packet }, prefix: buffer?): buffer - local total = if prefix then buffer.len(prefix) else 0 - for _, p in packets do - total += buffer.len(p.data) - end - local out = buffer.create(total) - local o = 0 - if prefix then - buffer.copy(out, 0, prefix) - o = buffer.len(prefix) - end - for _, p in packets do - buffer.copy(out, o, p.data) - o += buffer.len(p.data) - end - return out -end - -local PCM: { [string]: { number } } = { -- tag, bits, bytes swapped (big-endian source) - pcm_u8 = { 1, 8, 0 }, - pcm_s8 = { 1, 8, 0 }, - pcm_s16le = { 1, 16, 0 }, - pcm_s24le = { 1, 24, 0 }, - pcm_s32le = { 1, 32, 0 }, - pcm_s16be = { 1, 16, 1 }, - pcm_s24be = { 1, 24, 1 }, - pcm_s32be = { 1, 32, 1 }, - pcm_f32le = { 3, 32, 0 }, - pcm_f64le = { 3, 64, 0 }, - pcm_f32be = { 3, 32, 1 }, - pcm_f64be = { 3, 64, 1 }, - pcm_alaw = { 6, 8, 0 }, - pcm_mulaw = { 7, 8, 0 }, -} - -local function wav(fmt: buffer, data: buffer): buffer - local w = Bytes.writer(buffer.len(data) + buffer.len(fmt) + 64) - local fl = buffer.len(fmt) - local dl = buffer.len(data) - w:string("RIFF") - w:u32le(4 + 8 + fl + (fl % 2) + 8 + dl + (dl % 2)) - w:string("WAVE") - w:string("fmt ") - w:u32le(fl) - w:bytes(fmt) - if fl % 2 == 1 then - w:u8(0) - end - w:string("data") - w:u32le(dl) - w:bytes(data) - if dl % 2 == 1 then - w:u8(0) - end - return w:finish() -end - -local function pcmWav(track: Types.Track, packets: { Types.Packet }): (buffer?, Err.Err?) - local spec = PCM[track.codec] - local ch = track.channels or 1 - local rate = math.floor((track.sampleRate or 0) + 0.5) - if ch < 1 or rate <= 0 then - return nil, Err.new(Err.CORRUPT, "PCM track without channels / sample rate") - end - local bits = spec[2] - local data = concat(packets) - if spec[3] == 1 then - local bps = bits // 8 - for i = 0, buffer.len(data) - bps, bps do - for k = 0, bps // 2 - 1 do - local a, b = buffer.readu8(data, i + k), buffer.readu8(data, i + bps - 1 - k) - buffer.writeu8(data, i + k, b) - buffer.writeu8(data, i + bps - 1 - k, a) - end - end - end - if track.codec == "pcm_s8" then - for i = 0, buffer.len(data) - 1 do - buffer.writeu8(data, i, (buffer.readu8(data, i) + 128) % 256) - end - end - local f = Bytes.writer(16) - local align = ch * bits // 8 - f:u16le(spec[1]) - f:u16le(ch) - f:u32le(rate) - f:u32le(rate * align) - f:u16le(align) - f:u16le(bits) - 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 - --- the number of 48 kHz samples in an Opus packet (RFC 6716 section 3.1) -local function opusSamples(b: buffer): number - local n = buffer.len(b) - if n < 1 then - return 0 - end - local toc = buffer.readu8(b, 0) - local config = toc // 8 - local fs: number - if config < 12 then - fs = ({ 480, 960, 1920, 2880 })[config % 4 + 1] - elseif config < 16 then - fs = if config % 2 == 0 then 480 else 960 - else - fs = ({ 120, 240, 480, 960 })[config % 4 + 1] - end - local c = toc % 4 - local frames = if c == 0 then 1 elseif c == 3 then (if n >= 2 then buffer.readu8(b, 1) % 64 else 0) else 2 - return fs * frames -end - -local function opusHead(track: Types.Track): buffer - local c = track.config - if c and buffer.len(c) >= 19 and buffer.readstring(c, 0, 8) == "OpusHead" then - return c - end - local w = Bytes.writer(19) - w:string("OpusHead") - w:u8(1) - w:u8(math.clamp(track.channels or 2, 1, 2)) - w:u16le(math.floor((track.codecDelay or 0) * 48000 + 0.5)) - w:u32le(math.floor(track.sampleRate or 48000)) - w:u16le(0) - w:u8(0) - return w:finish() -end - -local function opusTags(): buffer - local w = Bytes.writer(32) - w:string("OpusTags") - local vendor = "rosetta" - w:u32le(#vendor) - w:string(vendor) - w:u32le(0) - return w:finish() -end - -local function ogg(headers: { buffer }, packets: { Types.Packet }, granuleOf: (p: Types.Packet, i: number) -> number): buffer - local mux = Mux.new({ pageSize = 4096 }) - local s = mux:stream(1) - for i, h in headers do - s:packet(h, 0, { flush = i == 1 or i == #headers }) - end - for i, p in packets do - s:packet(p.data, granuleOf(p, i), { eos = i == #packets }) - end - return mux:finish() -end - --- Matroska's Vorbis CodecPrivate: Xiph-laced headers (count - 1, sizes, data) -local function xiphHeaders(c: buffer): { buffer }? - local n = buffer.len(c) - if n < 3 then - return nil - end - local count = buffer.readu8(c, 0) + 1 - local p = 1 - local sizes = {} - local total = 0 - for k = 1, count - 1 do - local s = 0 - while true do - if p >= n then - return nil - end - local b = buffer.readu8(c, p) - p += 1 - s += b - if b ~= 255 then - break - end - end - sizes[k] = s - total += s - end - sizes[count] = n - p - total - if sizes[count] < 0 then - return nil - end - local out = {} - for k = 1, count do - local b = buffer.create(sizes[k]) - buffer.copy(b, 0, c, p, sizes[k]) - p += sizes[k] - out[k] = b - end - return out -end - --- Vorbis packet sizes: the block sizes from the identification header and each mode's block flag from the end of the --- setup header (read backwards from its framing bit: mode entries are 41 bits whose window / transform types are 0, --- preceded by the 6-bit mode count), so the Ogg granules are exact: a packet yields (previous + current block) / 4 --- samples (the first one as if its previous block had its own size, as ffmpeg times it). -local function bit(b: buffer, k: number): number - return bit32.extract(buffer.readu8(b, k // 8), k % 8, 1) -end -local function bits(b: buffer, k: number, n: number): number - local v = 0 - for i = n - 1, 0, -1 do - v = v * 2 + bit(b, k + i) - end - return v -end - -local function vorbisModes(id: buffer, setup: buffer): ({ number }?, { boolean }?) - if buffer.len(id) < 30 or buffer.len(setup) < 8 then - return nil, nil - end - local bs = buffer.readu8(id, 28) - local sizes = { 2 ^ (bs % 16), 2 ^ (bs // 16) } - -- the framing bit: the highest set bit of the last non-zero byte - local last = buffer.len(setup) - 1 - while last > 0 and buffer.readu8(setup, last) == 0 do - last -= 1 - end - local v = buffer.readu8(setup, last) - local hb = 7 - while hb > 0 and bit32.extract(v, hb, 1) == 0 do - hb -= 1 - end - local f = last * 8 + hb - local flags: { boolean } = {} - local pos = f - while #flags < 64 and pos - 41 >= 7 * 8 do - local s0 = pos - 41 - if bits(setup, s0 + 1, 16) ~= 0 or bits(setup, s0 + 17, 16) ~= 0 then - break - end - table.insert(flags, 1, bit(setup, s0) == 1) - pos = s0 - end - -- the largest count whose 6-bit field matches - for n = #flags, 1, -1 do - local start = f - 41 * n - if start - 6 >= 0 and bits(setup, start - 6, 6) == n - 1 then - local out = {} - for i = #flags - n + 1, #flags do - table.insert(out, flags[i]) - end - return sizes, out - end - end - return nil, nil -end - -local function adts(track: Types.Track, packets: { Types.Packet }): (buffer?, Err.Err?) - local c = track.config - local profile, rateIndex, chanConfig - if c and buffer.len(c) >= 2 then - local b0, b1 = buffer.readu8(c, 0), buffer.readu8(c, 1) - profile = b0 // 8 -- audio object type - rateIndex = (b0 % 8) * 2 + b1 // 128 - chanConfig = (b1 // 8) % 16 - -- HE-AAC (5) / HE-AACv2 (29), 14496-3 1.6.2.1: ADTS carries the AAC-LC core (the decoder finds SBR / PS in it) - if (profile == 5 or profile == 29) and rateIndex ~= 15 and buffer.len(c) >= 4 then - local v = buffer.readu8(c, 1) * 65536 + buffer.readu8(c, 2) * 256 + buffer.readu8(c, 3) - local extIndex = (v // 2 ^ 15) % 16 -- after aot (5), sfi (4), channels (4): bits 13 .. 16 - local core = if extIndex == 15 then -1 else (v // 2 ^ 10) % 32 -- bits 17 .. 21 - profile = if core == 2 then 2 else -1 - end - else - local rates = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 } - profile = 2 - rateIndex = 4 - for i, r in rates do - if r == math.floor((track.sampleRate or 44100) + 0.5) then - rateIndex = i - 1 - end - end - chanConfig = track.channels or 2 - end - if profile < 1 or profile > 4 or rateIndex > 12 then - return nil, Err.new(Err.UNSUPPORTED, "AAC object type " .. tostring(profile) .. " in ADTS") - end - local w = Bytes.writer(64) - for _, p in packets do - local len = buffer.len(p.data) + 7 - w:u8(0xFF) - w:u8(0xF1) - w:u8((profile - 1) * 64 + rateIndex * 4 + chanConfig // 4) - w:u8((chanConfig % 4) * 64 + (len // 2048) % 4) - w:u8((len // 8) % 256) - w:u8((len % 8) * 32 + 0x1F) - w:u8(0xFC) - w:bytes(p.data) - end - return w:finish(), nil -end - --- trim: a container's codec delay (Matroska CodecDelay, an MP4 edit's media time for MP2 / MP3 / AAC, as ffmpeg) --- and end padding -function AudioWrap.trim(dec: any, skip: number, length: number?): any - if skip <= 0 and length == nil then - return dec - end - skip = math.max(0, skip) - local rate = dec.sampleRate - local w: any = setmetatable({}, { __index = dec }) - w.frames = math.max(0, (dec.frames or 0) - skip) - if length then - w.frames = if (dec.frames or 0) > 0 then math.min(w.frames, length) else length - end - w.duration = w.frames / rate - local cap = length or math.huge - local delivered = 0 - local function drop() - local left = skip - while left > 0 do - local _, n = dec:read(math.min(left, 4096)) - if not n or n <= 0 then - break - end - left -= n - end - end - local started = false - function w.read(_: any, n: number, out: buffer?): (buffer, number) - if not started then - started = true - drop() - end - local want = math.min(n, cap - delivered) - if want <= 0 then - return out or buffer.create(0), 0 - end - local b, got = dec:read(want, out) - delivered += got - return b, got - end - function w.seek(_: any, seconds: number) - started = true - if seconds <= 0 then - dec:seek(0) - drop() - delivered = 0 - else - dec:seek(seconds + skip / rate) - delivered = math.floor(seconds * rate + 0.5) - end - end - function w.position(_: any): number - return math.max(0, dec:position() - skip / rate) - end - return w -end - -function AudioWrap.wrap(dmx: any, track: Types.Track): (buffer?, string?, Err.Err?) - if type(track) ~= "table" or track.kind ~= "audio" then - return nil, nil, Err.new(Err.ARG, "not an audio track") - end - if track.unsupported then - return nil, nil, Err.new(Err.UNSUPPORTED, track.unsupported) - end - local codec = track.codec - local packets = allPackets(dmx, track) - if #packets == 0 then - return nil, nil, Err.new(Err.CORRUPT, "audio track without packets") - end - 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 - end - if codec == "mp3" or codec == "mp2" or codec == "mp1" then - return concat(packets), "mp3", nil - end - if codec == "ac3" then - return concat(packets), "ac3", nil - end - if codec == "flac" then - local c = track.config - local prefix: buffer? = nil - if c and buffer.len(c) >= 4 and buffer.readstring(c, 0, 4) == "fLaC" then - prefix = c - elseif c and buffer.len(c) >= 34 then - -- metadata blocks without the marker (MP4 dfLa payload after version / flags) - local start = if buffer.len(c) >= 38 and buffer.readu8(c, 0) == 0 and buffer.readu8(c, 4) % 128 == 0 then 4 else 0 - local b = buffer.create(4 + buffer.len(c) - start) - buffer.writestring(b, 0, "fLaC") - buffer.copy(b, 4, c, start) - prefix = b - else - return nil, nil, Err.new(Err.CORRUPT, "FLAC track without its STREAMINFO") - end - return concat(packets, prefix), "flac", nil - end - if codec == "opus" then - local head = opusHead(track) - local pre = buffer.readu16(head, 10) - local g = pre - local out = ogg({ head, opusTags() }, packets, function(p: Types.Packet): number - g += opusSamples(p.data) - local d = (p :: any).discardPadding - if type(d) == "number" and d > 0 then - return g - math.floor(d * 48000 + 0.5) -- the end trimming (WebM DiscardPadding) - end - return g - end) - return out, "opus", nil - end - if codec == "vorbis" then - local c = track.config - local headers = c and xiphHeaders(c) - if not headers or #headers ~= 3 then - return nil, nil, Err.new(Err.CORRUPT, "Vorbis track without its three headers") - end - local sizes, modes = vorbisModes(headers[1], headers[3]) - local granule, prev = 0, nil :: number? - local rate = track.sampleRate or 44100 - local scale = track.timescale - local out = ogg(headers, packets, function(p: Types.Packet): number - if not sizes or not modes then - return math.floor((p.pts + (p.duration or 0)) / scale * rate + 0.5) -- from the container's times - end - local d = p.data - if buffer.len(d) == 0 or buffer.readu8(d, 0) % 2 ~= 0 then - return granule - end - local mb = 0 - while 2 ^ mb < #(modes :: { boolean }) do - mb += 1 - end - local m = if mb > 0 and buffer.len(d) * 8 > mb then bits(d, 1, mb) else 0 - local cur = sizes[if (modes :: { boolean })[m + 1] then 2 else 1] - if prev then - granule += (prev + cur) // 4 - end - prev = cur - return granule - end) - return out, "vorbis", nil - end - if codec == "aac" then - if track.adts then - return concat(packets), "aac", nil -- already ADTS (MPEG-TS) - end - local b, err = adts(track, packets) - return b, if b then "aac" else nil, err - end - return nil, nil, Err.new(Err.UNSUPPORTED, "no audio format for codec " .. tostring(codec)) -end - -return AudioWrap -end -__FILES["containers/Ogg/Mux"] = @native function() - - - --- containers/Ogg/Mux: the Ogg page writer (RFC 3533), for Ogg Opus / Vorbis / FLAC output. New in rosetta. --- Packets are laced into pages per logical stream; a page is closed when it reaches opts.pageSize bytes of data (or --- 255 lacing values), when a packet asks for flush, and at the end (eos). The page granule is the granule of the last --- packet that finishes on it (-1 when none does). Pages go to the output in the order they close, so the bos pages --- of a multiplexed file come first when every stream's first packet is written (with flush) before any other. --- Never throws: a bad argument returns false, Err. -local Err = __include("core/Err") -local Crc32 = __include("core/Crc32") - -local writeu8, writeu32, writei32 = buffer.writeu8, buffer.writeu32, buffer.writei32 - -local Mux = {} -Mux.__index = Mux -local Stream = {} -Stream.__index = Stream - -type Options = { - pageSize: number?, -- close a page once its data reaches this many bytes (default 4096; at most 255 * 255) -} -type PacketOptions = { - flush: boolean?, -- close the page after this packet (headers; default false) - eos: boolean?, -- this is the stream's last packet (default false: finish() writes an empty eos page if needed) -} - -@native function Mux.new(opts: Options?): any - local size = opts and opts.pageSize or 4096 - if type(size) ~= "number" or size < 1 then - size = 4096 - end - return setmetatable({ - pageSize = math.min(size, 255 * 255), - chunks = {} :: { buffer }, - total = 0, - streams = {} :: { any }, - nextSerial = 1, - }, Mux) -end - -@native function Mux.stream(self: any, serial: number?): any - local sr = serial or self.nextSerial - self.nextSerial = math.max(self.nextSerial, sr + 1) - local s = setmetatable({ - mux = self, - serial = sr % 4294967296, - seq = 0, - lacing = {} :: { number }, - parts = {} :: { any }, -- buffer, offset, length triples of the page data - dataLen = 0, - granule = -1, - continued = false, -- the page being built starts with the tail of a packet - first = true, - ended = false, - lastGranule = -1, - }, Stream) - table.insert(self.streams, s) - return s -end - --- the CRC of a page (the crc field written as zero) -@native local function crc(b: buffer, n: number): number - return Crc32.msb(b, 0, n, 0) -end - -@native function Stream._flush(self: any, eos: boolean) - local nseg = #self.lacing - local n = 27 + nseg + self.dataLen - local b = buffer.create(n) - buffer.writestring(b, 0, "OggS") - local flags = (if self.continued then 1 else 0) + (if self.first then 2 else 0) + (if eos then 4 else 0) - writeu8(b, 5, flags) - local g = self.granule - if g < 0 then - writeu32(b, 6, 0xFFFFFFFF) - writei32(b, 10, -1) - else - writeu32(b, 6, g % 4294967296) - writeu32(b, 10, (g // 4294967296) % 4294967296) - end - writeu32(b, 14, self.serial) - writeu32(b, 18, self.seq % 4294967296) - writeu8(b, 26, nseg) - for i = 1, nseg do - writeu8(b, 26 + i, self.lacing[i]) - end - local o = 27 + nseg - local parts = self.parts - for i = 1, #parts, 3 do - buffer.copy(b, o, parts[i], parts[i + 1], parts[i + 2]) - o += parts[i + 2] - end - writeu32(b, 22, crc(b, n)) - local m = self.mux - table.insert(m.chunks, b) - m.total += n - self.seq += 1 - self.first = false - self.lacing, self.parts, self.dataLen, self.granule = {}, {}, 0, -1 - self.continued = false - if eos then - self.ended = true - end -end - -@native function Stream.packet(self: any, data: any, granule: number, opts: PacketOptions?, offset: number?, length: number?): (boolean, Err.Err?) - if self.ended then - return false, Err.new(Err.ARG, "packet after the end of stream " .. self.serial) - end - local b: buffer - if type(data) == "string" then - b = buffer.fromstring(data) - elseif type(data) == "buffer" then - b = data - else - return false, Err.new(Err.ARG, "packet: data must be a buffer or a string") - end - if type(granule) ~= "number" then - return false, Err.new(Err.ARG, "packet: granule must be a number") - end - local off = offset or 0 - local len = length or (buffer.len(b) - off) - if off < 0 or len < 0 or off + len > buffer.len(b) then - return false, Err.new(Err.ARG, "packet: range outside the buffer") - end - local pageSize = self.mux.pageSize - local left = len - local pos = off - -- lacing: 255-byte segments then one < 255 (0 when the size is a multiple of 255) - while true do - if #self.lacing == 255 or (self.dataLen >= pageSize and #self.lacing > 0) then - self:_flush(false) - self.continued = pos > off -- the next page starts inside this packet - end - local seg = math.min(left, 255) - table.insert(self.lacing, seg) - if seg > 0 then - table.insert(self.parts, b) - table.insert(self.parts, pos) - table.insert(self.parts, seg) - end - self.dataLen += seg - pos += seg - left -= seg - if seg < 255 then - break - end - end - if granule >= 0 then -- -1 (unknown) keeps the granule of an earlier packet finishing on this page - self.granule = granule - self.lastGranule = granule - end - local eos = opts and opts.eos or false - if eos then - self:_flush(true) - elseif (opts and opts.flush) or self.dataLen >= pageSize or #self.lacing == 255 then - self:_flush(false) - end - return true, nil -end - -@native function Stream.flush(self: any) - if not self.ended and #self.lacing > 0 then - self:_flush(false) - end -end - -@native function Mux.finish(self: any): buffer - for _, s in self.streams do - if not s.ended then - if #s.lacing == 0 then - s.granule = s.lastGranule - end - s:_flush(true) - end - end - local out = buffer.create(self.total) - local o = 0 - for _, c in self.chunks do - buffer.copy(out, o, c, 0, buffer.len(c)) - o += buffer.len(c) - end - return out -end - -return Mux -end -end - - - - - - Core_2 - --!optimize 2 ---!nocheck --- rosetta chunk Core_2 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 7 modules (3 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["core/Bytes"] = @native function() @@ -8768,157 +5882,6 @@ end return Bytes end -__FILES["core/Crc32"] = @native function() - - --- core/Crc32: CRC-32 (IEEE 802.3, the zlib / gzip / zip / PNG polynomial 0xEDB88320, reflected), slice-by-8. --- Absorbed from deflate-luau src/Deflate/Checksum.luau (same author; no third-party code). Never throws. -local band, bxor, rshift, lshift, byteswap = bit32.band, bit32.bxor, bit32.rshift, bit32.lshift, bit32.byteswap -local readu8, readu32 = buffer.readu8, buffer.readu32 - -local T0, T1, T2, T3 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0) -local T4, T5, T6, T7 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0) -for n = 0, 255 do - local c = n - for _ = 1, 8 do - if band(c, 1) ~= 0 then - c = bxor(0xEDB88320, rshift(c, 1)) - else - c = rshift(c, 1) - end - end - T0[n + 1] = c -end -for n = 0, 255 do - local c = T0[n + 1] - c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) - T1[n + 1] = c - c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) - T2[n + 1] = c - c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) - T3[n + 1] = c - c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) - T4[n + 1] = c - c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) - T5[n + 1] = c - c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) - T6[n + 1] = c - c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) - T7[n + 1] = c -end - -@native local function crc32(buf: buffer, off: number, len: number, crc: number?): number - local c = bxor(crc or 0, 0xFFFFFFFF) - local i, e = off, off + len - local e8 = e - 8 - while i <= e8 do - c = bxor(c, readu32(buf, i)) - local d = readu32(buf, i + 4) - c = bxor( - T7[band(c, 255) + 1], - T6[band(rshift(c, 8), 255) + 1], - T5[band(rshift(c, 16), 255) + 1], - T4[rshift(c, 24) + 1], - T3[band(d, 255) + 1], - T2[band(rshift(d, 8), 255) + 1], - T1[band(rshift(d, 16), 255) + 1], - T0[rshift(d, 24) + 1] - ) - i += 8 - end - local e4 = e - 4 - while i <= e4 do - c = bxor(c, readu32(buf, i)) - c = bxor(T3[band(c, 255) + 1], T2[band(rshift(c, 8), 255) + 1], T1[band(rshift(c, 16), 255) + 1], T0[rshift(c, 24) + 1]) - i += 4 - end - while i < e do - c = bxor(T0[band(bxor(c, readu8(buf, i)), 255) + 1], rshift(c, 8)) - i += 1 - end - return bxor(c, 0xFFFFFFFF) -end - -@native local function range(buf: buffer, offset: number?, length: number?): (number, number) - local n = buffer.len(buf) - local o = math.clamp(offset or 0, 0, n) - return o, math.clamp(length or (n - o), 0, n - o) -end - -local Crc32 = {} - -@native function Crc32.of(buf: buffer, offset: number?, length: number?, crc: number?): number - local o, l = range(buf, offset, length) - return crc32(buf, o, l, crc) -end - -@native function Crc32.string(s: string, crc: number?): number - return crc32(buffer.fromstring(s), 0, #s, crc) -end - -Crc32.raw = crc32 - --- MSB-first CRC-32 (polynomial 0x04C11DB7, not reflected, raw register, no inversions): Ogg pages (init 0), --- MPEG-2 PSI sections and bzip2 blocks (init 0xFFFFFFFF) -local MSB = table.create(256, 0) -for n = 0, 255 do - local c = lshift(n, 24) - for _ = 1, 8 do - c = if band(c, 0x80000000) ~= 0 then bxor(lshift(c, 1), 0x04C11DB7) else lshift(c, 1) - end - MSB[n + 1] = c -end -Crc32.MSB_TABLE = MSB - --- slice-by-8 for the MSB-first CRC: M[k][n] = the CRC register after byte n and k zero bytes -local M1, M2, M3 = table.create(256, 0), table.create(256, 0), table.create(256, 0) -local M4, M5, M6, M7 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0) -for n = 0, 255 do - local c = MSB[n + 1] - c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) - M1[n + 1] = c - c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) - M2[n + 1] = c - c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) - M3[n + 1] = c - c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) - M4[n + 1] = c - c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) - M5[n + 1] = c - c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) - M6[n + 1] = c - c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) - M7[n + 1] = c -end - -@native function Crc32.msb(buf: buffer, off: number, len: number, init: number?): number - local c = init or 0 - local i, e = off, off + len - local e8 = e - 8 - while i <= e8 do - c = bxor(c, byteswap(readu32(buf, i))) - local d = byteswap(readu32(buf, i + 4)) - c = bxor( - M7[rshift(c, 24) + 1], - M6[band(rshift(c, 16), 255) + 1], - M5[band(rshift(c, 8), 255) + 1], - M4[band(c, 255) + 1], - M3[rshift(d, 24) + 1], - M2[band(rshift(d, 16), 255) + 1], - M1[band(rshift(d, 8), 255) + 1], - MSB[band(d, 255) + 1] - ) - i += 8 - end - while i < e do - c = bxor(lshift(c, 8), MSB[bxor(rshift(c, 24), readu8(buf, i)) + 1]) - i += 1 - end - return c -end - -return Crc32 -end __FILES["core/Err"] = function() -- core/Err: the error values every decoder / encoder returns (`nil, err`; nothing in the library throws on bad data). @@ -9122,1293 +6085,4330 @@ end local _ = Err return host end -__FILES["ops/ImageOps"] = function() +end + + + + + + Detect + --!optimize 2 +--!nocheck +-- rosetta chunk Detect (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) +__FILES["Sniffs"] = function() --- ops/ImageOps: editing on the standard Image: conversion, crop, resize, flips, rotation, compositing, pixel access, --- animation helpers. New code; the resampling and compositing follow Pillow's C sources. --- Conventions: angles are degrees counter-clockwise and rotate90 turns are counter-clockwise quarter turns (as --- Pillow). Resizing and rotating filter premultiplied alpha (as Pillow does for RGBA / LA). Grey is Pillow's --- L = (19595 R + 38470 G + 7471 B + 32768) >> 16. 8 <-> 16 bit is * 257 and --- (v * 255 + 32767) // 65535; float <-> integer clamps to 0..1 and rounds (no gamma). alpha8 converts to white with --- that alpha. yuv420p is JPEG-style BT.601 full range (2x2 box chroma); geometric ops on yuv420p go through rgba8. -local Err = __include("core/Err") -local Types = __include("Types") -local K = __include("ops/ImageOps/Kernels") -local ImageOps = {} +-- Sniffs: GENERATED by tools/gen_registry.py from the format folders - do not edit. +-- Each format's sniff (format path -> sniff(r)), copied from its init.luau with the top-level locals and types it +-- reaches (tools/sniff_extract.py), so detection requires no format module. Requires outside core/ are proxies that +-- require on first use. Formats whose sniff needs their module (Registry sniff = 2) are not here. +local S: { [string]: (any) -> number } = {} -local MAX_PIXELS = 2 ^ 26 - -type Image = Types.Image - -local function arg(msg: string): (nil, Err.Err) - return nil, Err.new(Err.ARG, msg) +local function lazy(load: () -> any): any + local proxy = {} + return setmetatable(proxy, { + __index = function(_, k: any): any + local m = load() + setmetatable(proxy, { __index = m }) + return m[k] + end, + }) end -local function isInt(v: any): boolean - return type(v) == "number" and v == v and v % 1 == 0 and v > -2 ^ 31 and v < 2 ^ 31 +local P_audio_mp3_Tags: any = {} +do -- audio/mp3/Tags: id3v2Size +local Tags = {} +local band, bor, lshift = bit32.band, bit32.bor, bit32.lshift +local ru8 = buffer.readu8 +local function syncsafe(b: buffer, o: number): number + return bor(lshift(band(ru8(b, o), 0x7F), 21), lshift(band(ru8(b, o + 1), 0x7F), 14), lshift(band(ru8(b, o + 2), 0x7F), 7), band(ru8(b, o + 3), 0x7F)) end - -local function bytesOf(fmt: string, w: number, h: number): number? - if fmt == "yuv420p" then - return w * h + 2 * ((w + 1) // 2) * ((h + 1) // 2) +function Tags.id3v2Size(b: buffer, o: number, len: number): number + if len - o < 10 or buffer.readstring(b, o, 3) ~= "ID3" then + return 0 end - local bpp = Types.BPP[fmt] - return if bpp then w * h * bpp else nil -end - -local function check(img: any): (boolean?, Err.Err?) - if type(img) ~= "table" or type(img.pixels) ~= "buffer" then - return arg("expected an Image") + if band(ru8(b, o + 5), 15) ~= 0 then + return 0 end - if not isInt(img.width) or not isInt(img.height) or img.width < 1 or img.height < 1 then - return arg("bad image size") - end - local need = bytesOf(img.format, img.width, img.height) - if not need then - return arg("unknown pixel format " .. tostring(img.format)) - end - if buffer.len(img.pixels) < need then - return arg("pixel buffer too small for " .. img.width .. " x " .. img.height .. " " .. img.format) - end - return true, nil -end -ImageOps.check = check - -local function limit(w: number, h: number, opts: any): (boolean?, Err.Err?) - local max: number = (type(opts) == "table" and opts.maxPixels) or MAX_PIXELS - if w * h > max then - return nil, Err.new(Err.LIMIT, string.format("%d x %d is over the %d pixel limit", w, h, max)) - end - return true, nil -end - -local function like(img: Image, w: number, h: number, fmt: string?): Image - local out = Types.Image.new(w, h, (fmt or img.format) :: any) - for k, v in img.meta do - out.meta[k] = v - end - out.loops = img.loops - return out -end - -function ImageOps.new(w: number, h: number, format: string?): (Image?, Err.Err?) - local fmt = format or "rgba8" - if not isInt(w) or not isInt(h) or w < 1 or h < 1 then - return arg("bad image size") - end - if not bytesOf(fmt, 1, 1) then - return arg("unknown pixel format " .. tostring(fmt)) - end - local ok, e = limit(w, h, nil) - if not ok then - return nil, e - end - return Types.Image.new(w, h, fmt :: any), nil -end - -function ImageOps.copy(img: Image): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - local out = like(img, img.width, img.height) - buffer.copy(out.pixels, 0, img.pixels, 0, buffer.len(out.pixels)) - out.frames = img.frames - return out, nil -end - -function ImageOps.convert(img: Image, format: string): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if not bytesOf(format, 1, 1) then - return arg("unknown pixel format " .. tostring(format)) - end - local w, h = img.width, img.height - if img.format == format then - return ImageOps.copy(img) - end - local src = img - if img.format == "yuv420p" then - local rgba = like(img, w, h, "rgba8") - K.yuvToRgba(img.pixels, w, h, rgba.pixels) - if format == "rgba8" then - return rgba, nil - end - src = rgba - end - local out = like(img, w, h, format) - if format == "yuv420p" then - local rgba = src - if src.format ~= "rgba8" then - rgba = like(img, w, h, "rgba8") - K.convert(src.pixels, K.ID[src.format], rgba.pixels, K.ID.rgba8, w * h) - end - K.rgbaToYuv(rgba.pixels, w, h, out.pixels) - return out, nil - end - K.convert(src.pixels, K.ID[src.format], out.pixels, K.ID[format], w * h) - return out, nil -end - --- ops on yuv420p run on rgba8 and convert back -local function viaRgba(img: Image, f: (Image) -> (Image?, Err.Err?)): (Image?, Err.Err?) - if img.format ~= "yuv420p" then - return f(img) - end - local rgba = ImageOps.convert(img, "rgba8") :: Image - local res, e = f(rgba) - if not res then - return nil, e - end - return ImageOps.convert(res, "yuv420p") -end - -local ALPHA_CH: { [string]: number } = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, graya8 = 2 } - -function ImageOps.crop(img: Image, x: number, y: number, w: number, h: number): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if not (isInt(x) and isInt(y) and isInt(w) and isInt(h)) then - return arg("crop: integer x, y, w, h") - end - local x0, y0 = math.max(0, x), math.max(0, y) - local x1, y1 = math.min(img.width, x + w), math.min(img.height, y + h) - if x1 <= x0 or y1 <= y0 then - return arg("crop: the rectangle is outside the image or empty") - end - return viaRgba(img, function(im: Image): (Image?, Err.Err?) - local bpp = Types.BPP[im.format] :: number - local out = like(im, x1 - x0, y1 - y0) - K.copyRect(out.pixels, out.width, im.pixels, im.width, x0, y0, 0, 0, out.width, out.height, bpp) - return out, nil - end) -end - -function ImageOps.flip(img: Image, axis: string): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if axis ~= "h" and axis ~= "v" then - return arg("flip: axis must be \"h\" or \"v\"") - end - return viaRgba(img, function(im: Image): (Image?, Err.Err?) - local out = like(im, im.width, im.height) - K.flip(im.pixels, out.pixels, im.width, im.height, Types.BPP[im.format] :: number, axis == "h") - return out, nil - end) -end - -function ImageOps.rotate90(img: Image, turns: number): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if not isInt(turns) then - return arg("rotate90: integer turns") - end - local t = turns % 4 - if t == 0 then - return ImageOps.copy(img) - end - return viaRgba(img, function(im: Image): (Image?, Err.Err?) - local swap = t ~= 2 - local out = like(im, if swap then im.height else im.width, if swap then im.width else im.height) - K.rotate90(im.pixels, out.pixels, im.width, im.height, Types.BPP[im.format] :: number, t) - return out, nil - end) -end - -type ResizeFilter = "nearest" | "bilinear" | "lanczos" - -function ImageOps.resize(img: Image, w: number, h: number, filter: string?, opts: any?): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if not isInt(w) or not isInt(h) or w < 1 or h < 1 then - return arg("resize: bad target size") - end - local f = filter or "bilinear" - if f ~= "nearest" and f ~= "bilinear" and f ~= "lanczos" then - return arg("resize: filter must be nearest, bilinear or lanczos") - end - local lok, le = limit(w, h, opts) - if not lok then - return nil, le - end - return viaRgba(img, function(im: Image): (Image?, Err.Err?) - local fmt = im.format - local bpp = Types.BPP[fmt] :: number - local out = like(im, w, h) - if f == "nearest" then - K.nearest(im.pixels, im.width, im.height, bpp, out.pixels, w, h) - return out, nil - end - local kind, ch = K.KIND[fmt], K.CHANNELS[fmt] - local src, sw, sh = im.pixels, im.width, im.height - local alpha = ALPHA_CH[fmt] - local unAlpha = alpha - if alpha == 4 and kind == 1 and K.opaque(src, sw * sh) then - alpha = nil -- premultiplying is the identity; the resampled alpha can still round to 254: unpremultiplied below - end - if alpha then - src = buffer.create(buffer.len(im.pixels)) - buffer.copy(src, 0, im.pixels) - K.premultiply(src, sw * sh, alpha, kind, false) - end - if w ~= sw then - local tmp = buffer.create(w * sh * bpp) - K.resamplePass(src, sw, sh, ch, kind, tmp, w, K.coeffs(sw, w, f), true) - src, sw = tmp, w - end - if h ~= sh then - K.resamplePass(src, sw, sh, ch, kind, out.pixels, h, K.coeffs(sh, h, f), false) - elseif src == im.pixels or (w == im.width and alpha) then - buffer.copy(out.pixels, 0, im.pixels, 0, w * h * bpp) - return out, nil - else - out.pixels = src - end - if unAlpha then - K.premultiply(out.pixels, w * h, unAlpha, kind, true) - end - return out, nil - end) -end - -function ImageOps.rotate(img: Image, degrees: number, opts: { expand: boolean?, maxPixels: number? }?): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if type(degrees) ~= "number" or degrees ~= degrees or degrees == math.huge or degrees == -math.huge then - return arg("rotate: degrees must be a finite number") - end - local expand = not (opts and opts.expand == false) - if degrees % 90 == 0 and (expand or degrees % 180 == 0 or img.width == img.height) then - return ImageOps.rotate90(img, (degrees // 90) % 4) - end - local w, h = img.width, img.height - local ang = -math.rad(degrees) - local function r15(v: number): number - return math.floor(v * 1e15 + 0.5) / 1e15 - end - local m = { r15(math.cos(ang)), r15(math.sin(ang)), 0, r15(-math.sin(ang)), r15(math.cos(ang)), 0 } - local function tr(x: number, y: number): (number, number) - return m[1] * x + m[2] * y + m[3], m[4] * x + m[5] * y + m[6] - end - local cx, cy = w / 2, h / 2 - m[3], m[6] = tr(-cx, -cy) - m[3] += cx - m[6] += cy - local nw, nh = w, h - if expand then - local xs, ys = {}, {} - for _, p in { { 0, 0 }, { w, 0 }, { w, h }, { 0, h } } do - local x, y = tr(p[1], p[2]) - table.insert(xs, x) - table.insert(ys, y) - end - nw = math.ceil(math.max(xs[1], xs[2], xs[3], xs[4])) - math.floor(math.min(xs[1], xs[2], xs[3], xs[4])) - nh = math.ceil(math.max(ys[1], ys[2], ys[3], ys[4])) - math.floor(math.min(ys[1], ys[2], ys[3], ys[4])) - m[3], m[6] = tr(-(nw - w) / 2, -(nh - h) / 2) - end - local lok, le = limit(nw, nh, opts) - if not lok then - return nil, le - end - return viaRgba(img, function(im: Image): (Image?, Err.Err?) - local out = like(im, nw, nh) - local kind = K.KIND[im.format] - local alpha = ALPHA_CH[im.format] - local src = im.pixels - if alpha then - src = buffer.create(buffer.len(im.pixels)) - buffer.copy(src, 0, im.pixels) - K.premultiply(src, w * h, alpha, kind, false) - end - K.affine(src, w, h, K.CHANNELS[im.format], kind, out.pixels, nw, nh, m) - if alpha then - K.premultiply(out.pixels, nw * nh, alpha, kind, true) - end - return out, nil - end) -end - -local RGBA: { [string]: boolean } = { rgba8 = true, rgba16 = true, rgbaf32 = true } - -type BlitOptions = { blend: ("over" | "source")?, opacity: number? } - -function ImageOps.blit(dst: Image, src: Image, x: number, y: number, opts: BlitOptions?): (Image?, Err.Err?) - local ok, e = check(dst) - if not ok then - return nil, e - end - local ok2, e2 = check(src) - if not ok2 then - return nil, e2 - end - if not isInt(x) or not isInt(y) then - return arg("blit: integer x, y") - end - local blend = (opts and opts.blend) or "over" - if blend ~= "over" and blend ~= "source" then - return arg("blit: blend must be \"over\" or \"source\"") - end - local opacity = (opts and opts.opacity) or 1 - if type(opacity) ~= "number" or not (opacity >= 0 and opacity <= 1) then - return arg("blit: opacity must be 0..1") - end - local sx, sy = math.max(0, -x), math.max(0, -y) - local dx, dy = math.max(0, x), math.max(0, y) - local w = math.min(src.width - sx, dst.width - dx) - local h = math.min(src.height - sy, dst.height - dy) - if w <= 0 or h <= 0 then - return dst, nil - end - if dst.format == "yuv420p" or (blend == "over" and not RGBA[dst.format]) then - -- work on an rgba copy of the region, then write it back in dst's format - local region = ImageOps.crop(dst, dx, dy, w, h) :: Image - local work = if region.format == "rgba8" then region else ImageOps.convert(region, "rgba8") :: Image - ImageOps.blit(work, src, x - dx, y - dy, opts) - if dst.format == "yuv420p" then - local full = ImageOps.convert(dst, "rgba8") :: Image - ImageOps.blit(full, work, dx, dy, { blend = "source" }) - local back = ImageOps.convert(full, "yuv420p") :: Image - buffer.copy(dst.pixels, 0, back.pixels, 0, buffer.len(back.pixels)) - else - local back = ImageOps.convert(work, dst.format) :: Image - K.copyRect(dst.pixels, dst.width, back.pixels, back.width, 0, 0, dx, dy, w, h, Types.BPP[dst.format] :: number) - end - return dst, nil - end - local s = src - if src.format ~= dst.format then - s = ImageOps.convert(src, dst.format) :: Image - end - if blend == "source" then - K.copyRect(dst.pixels, dst.width, s.pixels, s.width, sx, sy, dx, dy, w, h, Types.BPP[dst.format] :: number) - elseif dst.format == "rgba8" then - K.overRgba8(dst.pixels, dst.width, s.pixels, s.width, sx, sy, dx, dy, w, h, math.floor(opacity * 255 + 0.5)) - else - K.overFloat(dst.pixels, dst.width, s.pixels, s.width, sx, sy, dx, dy, w, h, opacity, K.KIND[dst.format]) - end - return dst, nil -end - -function ImageOps.composite(dst: Image, src: Image, x: number?, y: number?, opts: BlitOptions?): (Image?, Err.Err?) - local out, e = ImageOps.copy(dst) - if not out then - return nil, e - end - out.frames = nil - return ImageOps.blit(out, src, x or 0, y or 0, opts) -end - -local function premul(img: Image, un: boolean): (Image?, Err.Err?) - local out, e = ImageOps.copy(img) - if not out then - return nil, e - end - out.frames = nil - local ch = ALPHA_CH[img.format] - if ch then - K.premultiply(out.pixels, img.width * img.height, ch, K.KIND[img.format], un) - end - return out, nil -end - -function ImageOps.premultiply(img: Image): (Image?, Err.Err?) - return premul(img, false) -end -function ImageOps.unpremultiply(img: Image): (Image?, Err.Err?) - return premul(img, true) -end - -local MAXV: { [string]: number } = { rgba8 = 255, rgba16 = 65535, rgbaf32 = 1, rgb8 = 255, gray8 = 255, gray16 = 65535, graya8 = 255, alpha8 = 255, yuv420p = 255 } - -function ImageOps.getPixel(img: Image, x: number, y: number): (any, any, number?, number?) - local ok, e = check(img) - if not ok then - return nil, e - end - if not isInt(x) or not isInt(y) or x < 0 or y < 0 or x >= img.width or y >= img.height then - return arg("getPixel: coordinates out of range") - end - local b, f, i = img.pixels, img.format, y * img.width + x - local ru8, ru16, rf = buffer.readu8, buffer.readu16, buffer.readf32 - if f == "rgba8" then - return ru8(b, i * 4), ru8(b, i * 4 + 1), ru8(b, i * 4 + 2), ru8(b, i * 4 + 3) - elseif f == "rgba16" then - return ru16(b, i * 8), ru16(b, i * 8 + 2), ru16(b, i * 8 + 4), ru16(b, i * 8 + 6) - elseif f == "rgbaf32" then - return rf(b, i * 16), rf(b, i * 16 + 4), rf(b, i * 16 + 8), rf(b, i * 16 + 12) - elseif f == "rgb8" then - return ru8(b, i * 3), ru8(b, i * 3 + 1), ru8(b, i * 3 + 2), 255 - elseif f == "gray8" then - local v = ru8(b, i) - return v, v, v, 255 - elseif f == "gray16" then - local v = ru16(b, i * 2) - return v, v, v, 65535 - elseif f == "graya8" then - local v = ru8(b, i * 2) - return v, v, v, ru8(b, i * 2 + 1) - elseif f == "alpha8" then - return 255, 255, 255, ru8(b, i) - end - local one = ImageOps.crop(img, x - x % 2, y - y % 2, 2, 2) :: Image - local rgba = ImageOps.convert(one, "rgba8") :: Image - local j = ((y % 2) * rgba.width + (x % 2)) * 4 - if j + 4 > buffer.len(rgba.pixels) then - j = 0 - end - return ru8(rgba.pixels, j), ru8(rgba.pixels, j + 1), ru8(rgba.pixels, j + 2), 255 -end - -function ImageOps.setPixel(img: Image, x: number, y: number, r: number, g: number, b: number, a: number?): (boolean?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if not isInt(x) or not isInt(y) or x < 0 or y < 0 or x >= img.width or y >= img.height then - return arg("setPixel: coordinates out of range") - end - if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" or (a ~= nil and type(a) ~= "number") then - return arg("setPixel: numeric channels") - end - local f = img.format - if f == "yuv420p" then - return arg("setPixel: not supported on yuv420p (convert to rgba8 first)") - end - local max = MAXV[f] - local al = if a == nil then max else a - local function q(v: number): number - if max == 1 then - return v - end - if v ~= v then + for k = 6, 9 do + if band(ru8(b, o + k), 0x80) ~= 0 then return 0 end - return math.clamp(math.floor(v + 0.5), 0, max) end - local px, i = img.pixels, y * img.width + x - local wu8, wu16, wf = buffer.writeu8, buffer.writeu16, buffer.writef32 - local function grey(): number - if max == 1 then - return (r * 19595 + g * 38470 + b * 7471) / 65536 + local size = syncsafe(b, o + 6) + 10 + if band(ru8(b, o + 5), 16) ~= 0 then + size += 10 + 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 = {} +Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 } +type Adts = { + headerSize: number, -- 7, or 9 with a CRC + frameSize: number, + objectType: number, + sfIndex: number, + sampleRate: number, + channelConfig: number, + blocks: number, -- raw_data_blocks in the frame (1 .. 4) + protected: boolean, +} +function Aac.adts(b: buffer, o: number, limit: number): Adts? + if o < 0 or o + 7 > limit or o + 7 > buffer.len(b) then + return nil + end + local b0, b1, b2, b3, b4, b5, b6 = buffer.readu8(b, o), buffer.readu8(b, o + 1), buffer.readu8(b, o + 2), buffer.readu8(b, o + 3), buffer.readu8(b, o + 4), buffer.readu8(b, o + 5), buffer.readu8(b, o + 6) + if b0 ~= 0xFF or bit32.band(b1, 0xF6) ~= 0xF0 then -- sync, layer 0 + return nil + end + local protected = bit32.band(b1, 1) == 0 + local profile = bit32.rshift(b2, 6) + local sfi = bit32.band(bit32.rshift(b2, 2), 15) + local ch = bit32.band(b2, 1) * 4 + bit32.rshift(b3, 6) + local size = bit32.band(b3, 3) * 2048 + b4 * 8 + bit32.rshift(b5, 5) + local blocks = bit32.band(b6, 3) + 1 + local hs = if protected then 9 else 7 + if sfi > 12 or size < hs then + return nil + end + return { + headerSize = hs, + frameSize = size, + objectType = profile + 1, + sfIndex = sfi, + sampleRate = Aac.RATES[sfi + 1], + channelConfig = ch, + blocks = blocks, + 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 = {} +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 + local kbps = T.BITRATES[frmsizecod // 2 + 1] + if not kbps or fscod > 2 then + return 0 + end + if fscod == 0 then + return 2 * kbps + elseif fscod == 2 then + return 3 * kbps + 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 = {} +local T = P_codecs_audio_Ac3_Tables +local readu8 = buffer.readu8 +local NFCHANS = { [0] = 2, 1, 2, 3, 3, 4, 4, 5 } +type Header = { + sampleRate: number, + frameSize: number, + bitrate: number, + channels: number, + acmod: number, + lfeon: boolean, + bsid: number, +} +function Ac3.header(b: buffer, o: number, limit: number): Header? + if o < 0 or o + 8 > limit or o + 8 > buffer.len(b) then + return nil + end + if readu8(b, o) ~= 0x0B or readu8(b, o + 1) ~= 0x77 then + return nil + end + local bsid = bit32.rshift(readu8(b, o + 5), 3) + if bsid > 10 then + if bsid > 16 then + return nil end - return (q(r) * 19595 + q(g) * 38470 + q(b) * 7471 + 32768) // 65536 + -- E-AC-3: strmtyp(2) substreamid(3) frmsiz(11) fscod(2) ... + local words = bit32.band(readu8(b, o + 2), 7) * 256 + readu8(b, o + 3) + 1 + local fs = bit32.rshift(readu8(b, o + 4), 6) + return { + sampleRate = if fs < 3 then T.RATES[fs + 1] else 0, + frameSize = words * 2, + bitrate = 0, + channels = 0, + acmod = bit32.band(bit32.rshift(readu8(b, o + 4), 1), 7), + lfeon = false, + bsid = bsid, + } end - if f == "rgba8" then - wu8(px, i * 4, q(r)) - wu8(px, i * 4 + 1, q(g)) - wu8(px, i * 4 + 2, q(b)) - wu8(px, i * 4 + 3, q(al)) - elseif f == "rgba16" then - wu16(px, i * 8, q(r)) - wu16(px, i * 8 + 2, q(g)) - wu16(px, i * 8 + 4, q(b)) - wu16(px, i * 8 + 6, q(al)) - elseif f == "rgbaf32" then - wf(px, i * 16, r) - wf(px, i * 16 + 4, g) - wf(px, i * 16 + 8, b) - wf(px, i * 16 + 12, al) - elseif f == "rgb8" then - wu8(px, i * 3, q(r)) - wu8(px, i * 3 + 1, q(g)) - wu8(px, i * 3 + 2, q(b)) - elseif f == "gray8" then - wu8(px, i, grey()) - elseif f == "gray16" then - wu16(px, i * 2, grey()) - elseif f == "graya8" then - wu8(px, i * 2, grey()) - wu8(px, i * 2 + 1, q(al)) - else - wu8(px, i, q(al)) + local b4 = readu8(b, o + 4) + local fscod, frmsizecod = bit32.rshift(b4, 6), bit32.band(b4, 63) + local words = T.frameWords(fscod, frmsizecod) + if words == 0 then + return nil end - return true, nil + local acmod = bit32.rshift(readu8(b, o + 6), 5) + -- lfeon: after acmod and the optional cmixlev / surmixlev / dsurmod fields + local skip = 0 + if bit32.band(acmod, 1) == 1 and acmod ~= 1 then + skip += 2 + end + if bit32.band(acmod, 4) ~= 0 then + skip += 2 + end + if acmod == 2 then + skip += 2 + end + local w = readu8(b, o + 6) * 256 + readu8(b, o + 7) + local lfeon = bit32.extract(w, 12 - skip, 1) == 1 + local shift = if bsid > 8 then bsid - 8 else 0 + return { + sampleRate = T.RATES[fscod + 1] // 2 ^ shift, + frameSize = words * 2, + bitrate = T.BITRATES[frmsizecod // 2 + 1] * 1000 // 2 ^ shift, + channels = NFCHANS[acmod] + (if lfeon then 1 else 0), + acmod = acmod, + lfeon = lfeon, + bsid = bsid, + } +end +P_codecs_audio_Ac3.header = Ac3.header end -function ImageOps.fill(img: Image, r: number, g: number, b: number, a: number?): (Image?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e - end - if img.format == "yuv420p" then - return arg("fill: not supported on yuv420p") - end - local sok, se = ImageOps.setPixel(img, 0, 0, r, g, b, a) - if not sok then - return nil, se - end - local bpp = Types.BPP[img.format] :: number - local n = img.width * img.height * bpp - local filled = bpp - while filled < n do - local c = math.min(filled, n - filled) - buffer.copy(img.pixels, filled, img.pixels, 0, c) - filled += c - end - return img, nil +local P_codecs_audio_Mpa_Tables: any = {} +do -- codecs/audio/Mpa/Tables: halfrate +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 -function ImageOps.frameCount(img: Image): number - if type(img) == "table" and type(img.frames) == "table" and #img.frames > 0 then - return #img.frames +local P_codecs_audio_Mpa_Header: any = {} +do -- codecs/audio/Mpa/Header: compare, frameBytes, padding, valid +local H = {} +local T = P_codecs_audio_Mpa_Tables +local band, bxor, rshift = bit32.band, bit32.bxor, bit32.rshift +local ru8 = buffer.readu8 +local HALFRATE = T.halfrate +local HZ = { [0] = 44100, 48000, 32000 } +function H.valid(b: buffer, o: number): boolean + if ru8(b, o) ~= 0xFF then + return false end - return 1 + local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + return (band(h1, 0xF0) == 0xF0 or band(h1, 0xFE) == 0xE2) + and band(rshift(h1, 1), 3) ~= 0 + and rshift(h2, 4) ~= 15 + and band(rshift(h2, 2), 3) ~= 3 +end +local valid = H.valid +function H.compare(b: buffer, o1: number, o2: number): boolean + if not valid(b, o2) then + return false + end + local a1, a2 = ru8(b, o1 + 1), ru8(b, o1 + 2) + local c1, c2 = ru8(b, o2 + 1), ru8(b, o2 + 2) + return band(bxor(a1, c1), 0xFE) == 0 + and band(bxor(a2, c2), 0x0C) == 0 + and (band(a2, 0xF0) == 0) == (band(c2, 0xF0) == 0) +end +function H.bitrateKbps(h1: number, h2: number): number + local mpeg1 = if band(h1, 8) ~= 0 then 1 else 0 + local layer = band(rshift(h1, 1), 3) + return 2 * HALFRATE[mpeg1 * 45 + (layer - 1) * 15 + rshift(h2, 4)] +end +local bitrateKbps = H.bitrateKbps +function H.sampleRate(h1: number, h2: number): number + local hz = HZ[band(rshift(h2, 2), 3)] + if band(h1, 8) == 0 then + hz //= 2 + end + if band(h1, 0x10) == 0 then + hz //= 2 + end + return hz +end +local sampleRate = H.sampleRate +function H.frameSamples(h1: number): number + if band(h1, 6) == 6 then + return 384 + elseif band(h1, 14) == 2 then + return 576 + end + return 1152 +end +local frameSamples = H.frameSamples +function H.frameBytes(b: buffer, o: number, freeSize: number): number + local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + local hz = sampleRate(h1, h2) + local fb = frameSamples(h1) * bitrateKbps(h1, h2) * 125 // hz + if band(h1, 6) == 6 then + fb = band(fb, 0xFFFFFFFC) + end + return if fb ~= 0 then fb else freeSize +end +function H.padding(b: buffer, o: number): number + if band(ru8(b, o + 2), 2) == 0 then + return 0 + 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 -function ImageOps.durations(img: Image): { number } - local out = {} - if type(img) == "table" and type(img.frames) == "table" and #img.frames > 0 then - for i, f in img.frames do - out[i] = if type(f.delay) == "number" then f.delay else 0 - end +local P_codecs_audio_Musepack: any = {} +do -- codecs/audio/Musepack: magic +local Musepack = {} +function Musepack.magic(buf: buffer, p: number, limit: number): number + if p + 4 > limit then + return 0 + end + local m = buffer.readstring(buf, p, 4) + if m == "MPCK" then + return 8 + end + if string.sub(m, 1, 3) == "MP+" then + return 7 + 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 = {} +local Bytes = __include("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() + return __include("codecs/compress/Brotli") +end) + +local P_codecs_compress_Deflate_Inflate = lazy(function() + return __include("codecs/compress/Deflate/Inflate") +end) + +local P_codecs_compress_Deflate: any = {} +do -- codecs/compress/Deflate: peek +local Deflate = {} +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Inflate = P_codecs_compress_Deflate_Inflate +local args = Bytes.span +local function shrink(out: buffer, n: number): buffer + if buffer.len(out) == n then return out end - return { 0 } + local b = buffer.create(n) + buffer.copy(b, 0, out, 0, n) + return b +end +local function inflateErr(msg: string, at: number?): Err.Err + local code = if string.find(msg, "truncated", 1, true) then Err.TRUNCATED else Err.CORRUPT + return Err.new(code, "inflate: " .. msg, at) +end +local function gzipBody(b: buffer, p: number, e: number): (number?, Err.Err?) + local flg = buffer.readu8(b, p + 3) + if flg >= 0x20 then + return nil, Err.new(Err.CORRUPT, "gzip: reserved flags set", p + 3) + end + local q = p + 10 + if bit32.band(flg, 4) ~= 0 then -- FEXTRA + if q + 2 > e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + q += 2 + buffer.readu16(b, q) + end + for _, bit in { 8, 16 } do -- FNAME, FCOMMENT: zero-terminated + if bit32.band(flg, bit) ~= 0 then + while q < e and buffer.readu8(b, q) ~= 0 do + q += 1 + end + q += 1 + end + end + if bit32.band(flg, 2) ~= 0 then -- FHCRC + q += 2 + end + if q >= e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + return q, nil +end +function Deflate.peek(buf: buffer | string, offset: number?, length: number?, n: number): (buffer?, Err.Err?) + local b, o, l, aerr = args("Deflate.peek", buf, offset, length) + if not b then + return nil, aerr + end + if type(n) ~= "number" or n < 1 then + return nil, Err.new(Err.ARG, "Deflate.peek: bad size " .. tostring(n)) + end + local e = o + l + local q = o + if l >= 18 and buffer.readu8(b, o) == 0x1f and buffer.readu8(b, o + 1) == 0x8b and buffer.readu8(b, o + 2) == 8 then + local herr + q, herr = gzipBody(b, o, e) + if not q then + return nil, herr + end + elseif l >= 6 then + local cmf, flg = buffer.readu8(b, o), buffer.readu8(b, o + 1) + if cmf % 16 == 8 and cmf // 16 <= 7 and (cmf * 256 + flg) % 31 == 0 and bit32.band(flg, 0x20) == 0 then + q = o + 2 + end + end + local out, k = Inflate.raw(b, q :: number, e, n, true, true) + if not out then + return nil, inflateErr(tostring(k), q) + end + return shrink(out, k), nil +end +P_codecs_compress_Deflate.peek = Deflate.peek end --- coalesce: dispose "none" keeps the canvas, "background" clears the frame's rectangle, "previous" restores it -function ImageOps.coalesce(img: Image): ({ Image }?, Err.Err?) - local ok, e = check(img) - if not ok then - return nil, e +local P_codecs_compress_Zstd_Decode = lazy(function() + return __include("codecs/compress/Zstd/Decode") +end) + +local P_codecs_compress_Zstd: any = {} +do -- codecs/compress/Zstd: MAGIC, decompress +local Zstd = {} +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Decode = P_codecs_compress_Zstd_Decode +type Options = { + maxBytes: number?, + verify: boolean?, +} +Zstd.MAGIC = "\40\181\47\253" +function Zstd.decompress(buf: buffer | string, offset: number?, length: number?, opts: Options?): (buffer?, any) + local b, o, l, aerr = Bytes.span("Zstd.decompress", buf, offset, length) + if not b then + return nil, aerr end - local frames = img.frames - if type(frames) ~= "table" or #frames == 0 then - return { img }, nil + local maxBytes = if opts and opts.maxBytes ~= nil then opts.maxBytes else 2 ^ 30 + if type(maxBytes) ~= "number" or maxBytes < 0 then + return nil, Err.new(Err.ARG, "Zstd.decompress: bad maxBytes " .. tostring(maxBytes)) end - local fmt = if RGBA[img.format] then img.format else "rgba8" - local canvas = Types.Image.new(img.width, img.height, fmt :: any) - local bpp = Types.BPP[fmt] :: number + local verify = not (opts and opts.verify == false) + local out, len, consumed, at = Decode.decompress(b, o, o + l, maxBytes, verify) + if not out then + return nil, Err.from(consumed, at, len) + end + if buffer.len(out) ~= len then + local r = buffer.create(len) + buffer.copy(r, 0, out, 0, len) + out = r + 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 = {} +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 + return false + end + local t = readu8(b, o) + if t ~= 0 and t ~= 1 and t ~= 2 then + return false + end + for i = 1, math.min(n - 1, 64) do + local c = readu8(b, o + i) + if c == 0 then + return i > 1 + elseif c < 32 then + return false + end + 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 = {} +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 = {} +Value.NAMES = { + [0] = "end", + "byte", + "short", + "int", + "long", + "float", + "double", + "byteArray", + "string", + "list", + "compound", + "intArray", + "longArray", +} :: { [number]: string } +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 = {} +local Deflate = P_codecs_compress_Deflate +local Value = P_codecs_text_Nbt_Value +type Peek = { + compression: string, + endian: "big" | "little", + header: boolean, + rootType: string, + name: string, + firstType: string?, + firstName: string?, + head: buffer, +} +local function plausibleName(b: buffer, p: number, n: number): string? + if p + n > buffer.len(b) or n > 256 then + return nil + end + local s = buffer.readstring(b, p, n) + if string.find(s, "[%z\1-\31\127]") then + return nil + end + return s +end +function Nbt.peek(buf: buffer, offset: number?, length: number?): Peek? + local o = offset or 0 + local l = length or (buffer.len(buf) - o) + if l < 3 then + return nil + end + local c0, c1 = buffer.readu8(buf, o), buffer.readu8(buf, o + 1) + local head: buffer + local comp = "none" + if c0 == 0x1f and c1 == 0x8b or (c0 % 16 == 8 and c0 < 0x80 and (c0 * 256 + c1) % 31 == 0) then + local h = Deflate.peek(buf, o, l, 1024) + if not h then + return nil + end + head, comp = h, if c0 == 0x1f then "gzip" else "zlib" + else + local n = math.min(l, 1024) + head = buffer.create(n) + buffer.copy(head, 0, buf, o, n) + end + local hn = buffer.len(head) + local function at(p: number, endian: string, header: boolean): Peek? + if p + 3 > hn then + return nil + end + local t = buffer.readu8(head, p) + if t ~= 10 and t ~= 9 then + return nil + end + local function u16(q: number): number + local a, b = buffer.readu8(head, q), buffer.readu8(head, q + 1) + return if endian == "big" then a * 256 + b else b * 256 + a + end + local nl = u16(p + 1) + local name = plausibleName(head, p + 3, nl) + if not name then + return nil + end + local res: Peek = { compression = comp, endian = endian :: any, header = header, rootType = Value.NAMES[t], name = name, head = head } + local q = p + 3 + nl + if t == 10 and q < hn then + local ft = buffer.readu8(head, q) + if ft > 12 then + return nil + end + if ft == 0 then + res.firstType = "end" + elseif q + 3 <= hn then + local fname = plausibleName(head, q + 3, u16(q + 1)) + if fname == nil and q + 3 + u16(q + 1) <= hn then + return nil + end + res.firstType, res.firstName = Value.NAMES[ft], fname + end + end + return res + end + if hn >= 12 and buffer.readu32(head, 4) == (if comp == "none" then l else -1) - 8 then + local r = at(8, "little", true) + if r then + return r + end + 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 = {} +function Text.utf8char(c: number): string + local char = string.char + if c < 0x80 then + return char(c) + elseif c < 0x800 then + return char(0xC0 + c // 64, 0x80 + c % 64) + elseif c < 0x10000 then + return char(0xE0 + c // 4096, 0x80 + (c // 64) % 64, 0x80 + c % 64) + end + return char(0xF0 + c // 262144, 0x80 + (c // 4096) % 64, 0x80 + (c // 64) % 64, 0x80 + c % 64) +end +Text.CP1252 = { + [0x80] = 0x20AC, [0x82] = 0x201A, [0x83] = 0x0192, [0x84] = 0x201E, [0x85] = 0x2026, [0x86] = 0x2020, + [0x87] = 0x2021, [0x88] = 0x02C6, [0x89] = 0x2030, [0x8A] = 0x0160, [0x8B] = 0x2039, [0x8C] = 0x0152, + [0x8E] = 0x017D, [0x91] = 0x2018, [0x92] = 0x2019, [0x93] = 0x201C, [0x94] = 0x201D, [0x95] = 0x2022, + [0x96] = 0x2013, [0x97] = 0x2014, [0x98] = 0x02DC, [0x99] = 0x2122, [0x9A] = 0x0161, [0x9B] = 0x203A, + [0x9C] = 0x0153, [0x9E] = 0x017E, [0x9F] = 0x0178, +} +function Text.trim(s: string): string + return (string.match(s, "^%s*(.-)%s*$") :: string) +end +function Text.utf16(b: buffer, o: number, n: number, bigEndian: boolean?): string local out = {} - for i, f in frames do - if type(f) ~= "table" then - return arg("coalesce: frame " .. i .. " is not a Frame") - end - local fi = f.image - local fok, fe = check(fi) - if not fok then - return nil, Err.new(Err.ARG, "coalesce: frame " .. i .. ": " .. (fe :: Err.Err).message) - end - local fx, fy = if isInt(f.x) then f.x else 0, if isInt(f.y) then f.y else 0 - local saved: buffer? = nil - if f.dispose == "previous" then - local sb = buffer.create(buffer.len(canvas.pixels)) - buffer.copy(sb, 0, canvas.pixels) - saved = sb - end - local bok, be = ImageOps.blit(canvas, fi, fx, fy, { blend = if f.blend == "source" then "source" else "over" }) - if not bok then - return nil, be - end - local snap = Types.Image.new(img.width, img.height, fmt :: any) - buffer.copy(snap.pixels, 0, canvas.pixels) - for k, v in img.meta do - snap.meta[k] = v - end - snap.meta.delay = f.delay - out[i] = snap - if f.dispose == "background" then - local x0, y0 = math.max(0, fx), math.max(0, fy) - local x1, y1 = math.min(img.width, fx + fi.width), math.min(img.height, fy + fi.height) - for y = y0, y1 - 1 do - if x1 > x0 then - buffer.fill(canvas.pixels, (y * img.width + x0) * bpp, 0, (x1 - x0) * bpp) - end - end - elseif saved then - canvas.pixels = saved - end + local k = 0 + local readu16 = buffer.readu16 + local function unit(at: number): number + local v = readu16(b, at) + return if bigEndian then (v % 256) * 256 + v // 256 else v end - return out, nil -end - -function ImageOps.fromFrames(images: { Image }, delays: (number | { number })?): (Image?, Err.Err?) - if type(images) ~= "table" or #images == 0 then - return arg("fromFrames: a non-empty list of Images") - end - local first = images[1] - local ok, e = check(first) - if not ok then - return nil, e - end - local frames = {} - for i, im in images do - local iok, ie = check(im) - if not iok then - return nil, ie - end - if im.width ~= first.width or im.height ~= first.height or im.format ~= first.format then - return arg("fromFrames: frame " .. i .. " differs in size or format from frame 1") - end - local d = 0.1 - if type(delays) == "number" then - d = delays - elseif type(delays) == "table" and type(delays[i]) == "number" then - d = delays[i] - end - frames[i] = { image = im, delay = d, x = 0, y = 0, dispose = "none", blend = "source" } - end - local out = like(first, first.width, first.height) - buffer.copy(out.pixels, 0, first.pixels, 0, buffer.len(out.pixels)) - out.frames = frames :: any - out.loops = 0 - return out, nil -end - -return ImageOps -end -__FILES["ops/ImageOps/Kernels"] = @native function() - - - --- ops/ImageOps/Kernels: the hot loops behind ops/ImageOps; callers validate, so indexes are in range by construction. --- Sample kinds: 1 = u8, 2 = u16, 4 = f32 (little endian). Resampling follows Pillow's Resample.c (separable, 22-bit --- fixed point for 8-bit) and Geometry.c (affine through pixel centres); compositing is Pillow's AlphaComposite.c. -local readu8, writeu8, readu16, writeu16, readf32, writef32 = buffer.readu8, buffer.writeu8, buffer.readu16, buffer.writeu16, buffer.readf32, buffer.writef32 -local readu32, writeu32 = buffer.readu32, buffer.writeu32 -local floor, clamp = math.floor, math.clamp - -local K = {} - --- format ids: rgba8 1, rgba16 2, rgbaf32 3, rgb8 4, gray8 5, gray16 6, graya8 7, alpha8 8 -K.ID = { rgba8 = 1, rgba16 = 2, rgbaf32 = 3, rgb8 = 4, gray8 = 5, gray16 = 6, graya8 = 7, alpha8 = 8 } :: { [string]: number } -K.KIND = { rgba8 = 1, rgba16 = 2, rgbaf32 = 4, rgb8 = 1, gray8 = 1, gray16 = 2, graya8 = 1, alpha8 = 1 } :: { [string]: number } -K.CHANNELS = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, rgb8 = 3, gray8 = 1, gray16 = 1, graya8 = 2, alpha8 = 1 } :: { [string]: number } - -@native local function rd(b: buffer, o: number, kind: number): number - if kind == 1 then - return readu8(b, o) - elseif kind == 2 then - return readu16(b, o) - end - return readf32(b, o) -end - -@native local function wr(b: buffer, o: number, kind: number, v: number) - if kind == 1 then - writeu8(b, o, clamp(floor(v + 0.5), 0, 255)) - elseif kind == 2 then - writeu16(b, o, clamp(floor(v + 0.5), 0, 65535)) - else - writef32(b, o, v) - end -end - --- depth: 8 -> 0..255, 16 -> 0..65535, 0 -> float 0..1 -local DEPTH = { 8, 16, 0, 8, 8, 16, 8, 8 } - -@native local function depthConv(v: number, from: number, to: number): number - if from == to then - return v - end - if from == 8 then - if to == 16 then - return v * 257 - end - return v / 255 - elseif from == 16 then - if to == 8 then - return (v * 255 + 32767) // 65535 - end - return v / 65535 - end - if v ~= v then - v = 0 - end - if to == 8 then - return clamp(floor(v * 255 + 0.5), 0, 255) - end - return clamp(floor(v * 65535 + 0.5), 0, 65535) -end - --- Pillow's L24 luma (19595 R + 38470 G + 7471 B + 0x8000) >> 16, in the source depth -@native local function luma(r: number, g: number, b: number, depth: number): number - if depth == 0 then - return (r * 19595 + g * 38470 + b * 7471) / 65536 - end - return (r * 19595 + g * 38470 + b * 7471 + 32768) // 65536 -end - -@native function K.convert(src: buffer, sf: number, dst: buffer, df: number, n: number) - if sf == 1 and df == 5 then - for i = 0, n - 1 do - local o = i * 4 - writeu8(dst, i, (readu8(src, o) * 19595 + readu8(src, o + 1) * 38470 + readu8(src, o + 2) * 7471 + 32768) // 65536) - end - return - elseif sf == 1 and df == 4 and n > 0 then - -- a u32 per pixel; its fourth byte is overwritten by the next pixel (the last one is written as 2 + 1 bytes) - for i = 0, n - 2 do - writeu32(dst, i * 3, readu32(src, i * 4)) - end - local o, d = (n - 1) * 4, (n - 1) * 3 - writeu16(dst, d, readu16(src, o)) - writeu8(dst, d + 2, readu8(src, o + 2)) - return - elseif df == 1 and (sf == 4 or sf == 5) then - for i = 0, n - 1 do - if sf == 4 then - local o = i * 3 - writeu32(dst, i * 4, readu8(src, o) + readu8(src, o + 1) * 256 + readu8(src, o + 2) * 65536 + 0xFF000000) - else - writeu32(dst, i * 4, readu8(src, i) * 0x10101 + 0xFF000000) + while k + 1 < n do + local c = unit(o + k) + k += 2 + if c >= 0xD800 and c < 0xDC00 and k + 1 < n then + local lo = unit(o + k) + if lo >= 0xDC00 and lo < 0xE000 then + c = 0x10000 + (c - 0xD800) * 1024 + (lo - 0xDC00) + k += 2 end end - return + if c >= 0xD800 and c < 0xE000 then + c = 0xFFFD + end + table.insert(out, Text.utf8char(c)) end - local sd, dd = DEPTH[sf] :: number, DEPTH[df] :: number - local smax = if sd == 8 then 255 elseif sd == 16 then 65535 else 1 - local toGray = df == 5 or df == 6 or df == 7 - for i = 0, n - 1 do - local r: number, g: number, b: number, a: number - if sf == 1 then - local o = i * 4 - r, g, b, a = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2), readu8(src, o + 3) :: number - elseif sf == 2 then - local o = i * 8 - r, g, b, a = readu16(src, o), readu16(src, o + 2), readu16(src, o + 4), readu16(src, o + 6) :: number - elseif sf == 3 then - local o = i * 16 - r, g, b, a = readf32(src, o), readf32(src, o + 4), readf32(src, o + 8), readf32(src, o + 12) :: number - elseif sf == 4 then - local o = i * 3 - r, g, b, a = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2), 255 - elseif sf == 5 then - local v = readu8(src, i) - r, g, b, a = v, v, v, 255 - elseif sf == 6 then - local v = readu16(src, i * 2) - r, g, b, a = v, v, v, 65535 - elseif sf == 7 then - local v = readu8(src, i * 2) - r, g, b, a = v, v, v, readu8(src, i * 2 + 1) :: number + return table.concat(out) +end +function Text.toUtf8(text: string, warnings: { string }?): string + if string.sub(text, 1, 3) == "\239\187\191" then + text = string.sub(text, 4) + end + if utf8.len(text) then + return text + end + if warnings then + table.insert(warnings, "text is not UTF-8: read as Windows-1252") + end + local out = table.create(#text) + for i = 1, #text do + local b = string.byte(text, i) + if b < 0x80 then + out[i] = string.char(b) else - r, g, b, a = 255, 255, 255, readu8(src, i) - end - if toGray then - local isGray = sf == 5 or sf == 6 or sf == 7 - local l = if isGray then r else luma(r, g, b, sd) - l = depthConv(l, sd, dd) - if df == 5 then - writeu8(dst, i, l) - elseif df == 6 then - writeu16(dst, i * 2, l) - else - writeu8(dst, i * 2, l) - writeu8(dst, i * 2 + 1, depthConv(a, sd, dd)) - end - elseif df == 8 then - writeu8(dst, i, depthConv(a, sd, 8)) - else - r, g, b = depthConv(r, sd, dd), depthConv(g, sd, dd), depthConv(b, sd, dd) :: number - if df == 1 then - local o = i * 4 - writeu8(dst, o, r) - writeu8(dst, o + 1, g) - writeu8(dst, o + 2, b) - writeu8(dst, o + 3, depthConv(a, sd, dd)) - elseif df == 2 then - local o = i * 8 - writeu16(dst, o, r) - writeu16(dst, o + 2, g) - writeu16(dst, o + 4, b) - writeu16(dst, o + 6, depthConv(a, sd, dd)) - elseif df == 3 then - local o = i * 16 - writef32(dst, o, r) - writef32(dst, o + 4, g) - writef32(dst, o + 8, b) - writef32(dst, o + 12, if a == smax and sd ~= 0 then 1 else depthConv(a, sd, dd)) - else -- rgb8 - local o = i * 3 - writeu8(dst, o, r) - writeu8(dst, o + 1, g) - writeu8(dst, o + 2, b) - end + out[i] = utf8.char(if b < 0xA0 then Text.CP1252[b] or 0xFFFD else b) end 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 --- JPEG-style BT.601 full range -@native function K.rgbaToYuv(src: buffer, w: number, h: number, dst: buffer) - local cw, ch = (w + 1) // 2, (h + 1) // 2 - local uo, vo = w * h, w * h + cw * ch - for i = 0, w * h - 1 do - local o = i * 4 - local r, g, b = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2) - writeu8(dst, i, clamp(floor(0.299 * r + 0.587 * g + 0.114 * b + 0.5), 0, 255)) +local P_containers_Fat: any = {} +do -- containers/Fat: open +local Fat = {} +local readu8, readu16, readu32 = buffer.readu8, buffer.readu16, buffer.readu32 +type Volume = { + b: buffer, + base: number, -- byte offset of the volume (partition) in b + limit: number, + bps: number, -- bytes per sector + spc: number, -- sectors per cluster + fatOffset: number, -- byte offset of the first FAT (relative to base) + fatSize: number, -- bytes per FAT + rootOffset: number, -- FAT12 / 16: the fixed root directory + rootEntries: number, + rootCluster: number, -- FAT32 + dataOffset: number, -- byte offset of cluster 2 + clusters: number, -- data clusters + bits: number, -- 12 / 16 / 32 + label: string?, + oem: string, + media: number, + partition: number?, +} +local function bpbAt(b: buffer, o: number, len: number): (Volume?, string?) + if len < 512 then + return nil, "truncated: smaller than a boot sector" end - for cy = 0, ch - 1 do - for cx = 0, cw - 1 do - local sr, sg, sb, n = 0, 0, 0, 0 - for dy = 0, 1 do - local y = cy * 2 + dy - if y < h then - for dx = 0, 1 do - local x = cx * 2 + dx - if x < w then - local o = (y * w + x) * 4 - sr += readu8(src, o) - sg += readu8(src, o + 1) - sb += readu8(src, o + 2) - n += 1 - end - end - end - end - sr, sg, sb = sr / n, sg / n, sb / n - local i = cy * cw + cx - writeu8(dst, uo + i, clamp(floor(128 - 0.168736 * sr - 0.331264 * sg + 0.5 * sb + 0.5), 0, 255)) - writeu8(dst, vo + i, clamp(floor(128 + 0.5 * sr - 0.418688 * sg - 0.081312 * sb + 0.5), 0, 255)) + local jump = readu8(b, o) + local bps = readu16(b, o + 11) + local spc = readu8(b, o + 13) + if (jump ~= 0xEB and jump ~= 0xE9 and jump ~= 0xE8) or (bps ~= 512 and bps ~= 1024 and bps ~= 2048 and bps ~= 4096) then + return nil, "no FAT boot sector" + end + if spc == 0 or bit32.band(spc, spc - 1) ~= 0 then + return nil, "bad sectors per cluster" + end + local reserved, nfats, rootEntries = readu16(b, o + 14), readu8(b, o + 16), readu16(b, o + 17) + local total = readu16(b, o + 19) + if total == 0 then + total = readu32(b, o + 32) + end + local fatSectors = readu16(b, o + 22) + local fat32 = fatSectors == 0 + if fat32 then + fatSectors = readu32(b, o + 36) + end + if reserved == 0 or nfats == 0 or fatSectors == 0 or total == 0 then + return nil, "bad BPB" + end + local rootSectors = math.ceil(rootEntries * 32 / bps) + local dataSector = reserved + nfats * fatSectors + rootSectors + if dataSector >= total then + return nil, "bad BPB: no data area" + end + local clusters = (total - dataSector) // spc + local bits = if clusters < 4085 then 12 elseif clusters < 65525 then 16 else 32 + if fat32 and bits ~= 32 then + bits = 32 -- some small FAT32 volumes (mkfs.fat -F 32 on tiny images) are FAT32 regardless of the count + end + if total * bps > len then + -- images cut short at the last used sector are common: allow, reads past the end fail + total = len // bps + end + local labelAt = if bits == 32 then 71 else 43 + local sig = readu8(b, o + (if bits == 32 then 66 else 38)) + local label: string? = if sig == 0x29 then (string.gsub(buffer.readstring(b, o + labelAt, 11), " +$", "")) else nil + if label == "NO NAME" or label == "" then + label = nil + end + return { + b = b, + base = o, + limit = o + len, + bps = bps, + spc = spc, + fatOffset = reserved * bps, + fatSize = fatSectors * bps, + rootOffset = (reserved + nfats * fatSectors) * bps, + rootEntries = rootEntries, + rootCluster = if bits == 32 then readu32(b, o + 44) else 0, + dataOffset = dataSector * bps, + clusters = clusters, + bits = bits, + label = label, + oem = buffer.readstring(b, o + 3, 8), + media = readu8(b, o + 21), + }, nil +end +type OpenOptions = { partition: number? } -- 1..4: the MBR partition (default: the first FAT one) +local FAT_TYPES = { [0x01] = true, [0x04] = true, [0x06] = true, [0x0B] = true, [0x0C] = true, [0x0E] = true, [0x11] = true, [0x14] = true, [0x16] = true, [0x1B] = true, [0x1C] = true, [0x1E] = true } +function Fat.open(b: buffer, off: number, len: number, opts: OpenOptions?): (Volume?, string?) + local o: OpenOptions = opts or {} + off = math.max(0, off) + len = math.min(len, buffer.len(b) - off) + if len < 512 then + return nil, "truncated: smaller than a boot sector" + end + if not o.partition then + local v = bpbAt(b, off, len) + if v then + return v, nil end end + -- an MBR: 0x55AA and four partition entries + if readu8(b, off + 510) ~= 0x55 or readu8(b, off + 511) ~= 0xAA then + return nil, "no FAT boot sector and no partition table" + end + for i = 1, 4 do + local e = off + 446 + (i - 1) * 16 + local ptype = readu8(b, e + 4) + local lba, count = readu32(b, e + 8), readu32(b, e + 12) + if (o.partition == i or (not o.partition and FAT_TYPES[ptype])) and ptype ~= 0 then + if lba * 512 >= len then + return nil, "truncated: partition " .. i .. " starts past the end" + end + local v, err = bpbAt(b, off + lba * 512, math.min(count * 512, len - lba * 512)) + if v then + v.partition = i + end + return v, err + end + end + return nil, if o.partition then "no partition " .. o.partition else "no FAT partition" +end +P_containers_Fat.open = Fat.open end -@native function K.yuvToRgba(src: buffer, w: number, h: number, dst: buffer) - local cw, ch = (w + 1) // 2, (h + 1) // 2 - local uo, vo = w * h, w * h + cw * ch - for y = 0, h - 1 do - local crow = (y // 2) * cw - for x = 0, w - 1 do - local yy = readu8(src, y * w + x) - local ci = crow + x // 2 - local u, v = readu8(src, uo + ci) - 128, readu8(src, vo + ci) - 128 - local o = (y * w + x) * 4 - writeu8(dst, o, clamp(floor(yy + 1.402 * v + 0.5), 0, 255)) - writeu8(dst, o + 1, clamp(floor(yy - 0.344136 * u - 0.714136 * v + 0.5), 0, 255)) - writeu8(dst, o + 2, clamp(floor(yy + 1.772 * u + 0.5), 0, 255)) - writeu8(dst, o + 3, 255) +local P_containers_IsoBmff: any = {} +do -- containers/IsoBmff: sniff +local IsoBmff = {} +local Bytes = __include("core/Bytes") +local TOP: { [string]: boolean } = { + ftyp = true, moov = true, mdat = true, free = true, skip = true, wide = true, pnot = true, moof = true, + styp = true, sidx = true, meta = true, uuid = true, PICT = true, +} +function IsoBmff.sniff(r: Bytes.Reader): string? + local head = r:peek(12) + if #head < 8 then + return nil + end + local typ = string.sub(head, 5, 8) + if typ == "ftyp" then + return if #head >= 12 then string.sub(head, 9, 12) else "" + end + if TOP[typ] then + local size = string.byte(head, 1) * 16777216 + string.byte(head, 2) * 65536 + string.byte(head, 3) * 256 + string.byte(head, 4) + if size == 1 or size == 0 or size >= 8 then + return "" end end - local _ = ch + return nil +end +P_containers_IsoBmff.sniff = IsoBmff.sniff end -@native function K.flip(src: buffer, dst: buffer, w: number, h: number, bpp: number, horizontal: boolean) - local stride = w * bpp - if not horizontal then - for y = 0, h - 1 do - buffer.copy(dst, (h - 1 - y) * stride, src, y * stride, stride) - end - return - end - for y = 0, h - 1 do - local row = y * stride - for x = 0, w - 1 do - buffer.copy(dst, row + (w - 1 - x) * bpp, src, row + x * bpp, bpp) - end +local P_containers_Riff: any = {} +do -- containers/Riff: sniff +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 + return nil end + local form = r:peek(4, 8) + return if #form == 4 then form else nil +end +P_containers_Riff.sniff = Riff.sniff end --- counter-clockwise quarter turns 1..3 -@native function K.rotate90(src: buffer, dst: buffer, w: number, h: number, bpp: number, turns: number) - for y = 0, h - 1 do - for x = 0, w - 1 do - local ox, oy, ow - if turns == 1 then - ox, oy, ow = y, w - 1 - x, h - elseif turns == 2 then - ox, oy, ow = w - 1 - x, h - 1 - y, w - else - ox, oy, ow = h - 1 - y, x, h - end - local so, d = (y * w + x) * bpp, (oy * ow + ox) * bpp - if bpp == 4 then - buffer.writeu32(dst, d, buffer.readu32(src, so)) - else - buffer.copy(dst, d, src, so, bpp) - end - end - end -end - -@native local function bilinearF(x: number): number - if x < 0 then - x = -x - end - if x < 1 then - return 1 - x - end - return 0 -end - -@native local function sinc(x: number): number - if x == 0 then - return 1 - end - x *= math.pi - return math.sin(x) / x -end - -@native local function lanczosF(x: number): number - if x > -3 and x < 3 then - return sinc(x) * sinc(x / 3) - end - return 0 -end - -@native local function trunc(x: number): number - return if x < 0 then math.ceil(x) else floor(x) -end - --- Pillow precompute_coeffs: per output index its first input index, tap count and weights (normalised) -type Coeffs = { start: { number }, count: { number }, weights: { { number } } } - -@native function K.coeffs(inSize: number, outSize: number, filter: string): Coeffs - local support0 = if filter == "lanczos" then 3 else 1 - local f = if filter == "lanczos" then lanczosF else bilinearF - local scale = inSize / outSize - local filterscale = math.max(scale, 1) - local support = support0 * filterscale - local ss = 1 / filterscale - local start, count, weights = table.create(outSize, 0), table.create(outSize, 0), table.create(outSize) :: { { number } } - for xx = 0, outSize - 1 do - local center = (xx + 0.5) * scale - local xmin = math.max(0, trunc(center - support + 0.5)) - local xmax = math.min(inSize, trunc(center + support + 0.5)) - xmin - local w = table.create(math.max(xmax, 0), 0) - local ww = 0 - for x = 0, xmax - 1 do - local v = f((x + xmin - center + 0.5) * ss) - w[x + 1] = v - ww += v - end - if ww ~= 0 then - for x = 1, xmax do - w[x] /= ww - end - end - start[xx + 1], count[xx + 1], weights[xx + 1] = xmin, math.max(xmax, 0), w - end - return { start = start, count = count, weights = weights } -end - --- 8-bit RGBA: the four channels of a tap together, the pixel written as one u32 -@native local function resample4(src: buffer, w: number, h: number, dst: buffer, outN: number, start: { number }, count: { number }, iw: { { number } }, horizontal: boolean) - local o = 0 - if horizontal then - for y = 0, h - 1 do - local row = y * w * 4 - for xx = 1, outN do - local wt = iw[xx] - local p = row + start[xx] * 4 - local a0, a1, a2, a3 = 2097152, 2097152, 2097152, 2097152 - for k = 1, count[xx] do - local wk = wt[k] - a0 += readu8(src, p) * wk - a1 += readu8(src, p + 1) * wk - a2 += readu8(src, p + 2) * wk - a3 += readu8(src, p + 3) * wk - p += 4 - end - writeu32(dst, o, clamp(a0 // 4194304, 0, 255) + clamp(a1 // 4194304, 0, 255) * 256 + clamp(a2 // 4194304, 0, 255) * 65536 + clamp(a3 // 4194304, 0, 255) * 16777216) - o += 4 - end - end - else - local rs = w * 4 - for yy = 1, outN do - local wt, n = iw[yy], count[yy] - local base = start[yy] * rs - for x = 0, rs - 4, 4 do - local p = base + x - local a0, a1, a2, a3 = 2097152, 2097152, 2097152, 2097152 - for k = 1, n do - local wk = wt[k] - a0 += readu8(src, p) * wk - a1 += readu8(src, p + 1) * wk - a2 += readu8(src, p + 2) * wk - a3 += readu8(src, p + 3) * wk - p += rs - end - writeu32(dst, o, clamp(a0 // 4194304, 0, 255) + clamp(a1 // 4194304, 0, 255) * 256 + clamp(a2 // 4194304, 0, 255) * 65536 + clamp(a3 // 4194304, 0, 255) * 16777216) - o += 4 - end - end - end - local _ = h -end - -@native function K.resamplePass(src: buffer, w: number, h: number, ch: number, kind: number, dst: buffer, outN: number, c: Coeffs, horizontal: boolean) - local start, count, weights = c.start, c.count, c.weights - local size = kind - local fixed = kind == 1 - -- 8-bit: Pillow's 22-bit fixed-point coefficients - local iw: { { number } } = weights - if fixed then - iw = table.create(outN) :: { { number } } - for i = 1, outN do - local src0 = weights[i] - local t = table.create(#src0, 0) - for k = 1, #src0 do - local v = src0[k] * 4194304 - t[k] = if v < 0 then math.ceil(v - 0.5) else floor(v + 0.5) - end - iw[i] = t - end - end - if fixed and ch == 4 then - resample4(src, w, h, dst, outN, start, count, iw, horizontal) - return - end - if horizontal then - for y = 0, h - 1 do - local row = y * w - for xx = 0, outN - 1 do - local s0, n, wt = start[xx + 1], count[xx + 1], iw[xx + 1] - local o = ((y * outN) + xx) * ch * size - for cc = 0, ch - 1 do - if fixed then - local acc = 2097152 - for k = 0, n - 1 do - acc += readu8(src, (row + s0 + k) * ch + cc) * wt[k + 1] - end - writeu8(dst, o + cc, clamp(acc // 4194304, 0, 255)) - else - local acc = 0 - for k = 0, n - 1 do - acc += rd(src, ((row + s0 + k) * ch + cc) * size, kind) * wt[k + 1] - end - wr(dst, o + cc * size, kind, acc) - end - end - end - end - else - for yy = 0, outN - 1 do - local s0, n, wt = start[yy + 1], count[yy + 1], iw[yy + 1] - for x = 0, w - 1 do - local o = (yy * w + x) * ch * size - for cc = 0, ch - 1 do - if fixed then - local acc = 2097152 - for k = 0, n - 1 do - acc += readu8(src, ((s0 + k) * w + x) * ch + cc) * wt[k + 1] - end - writeu8(dst, o + cc, clamp(acc // 4194304, 0, 255)) - else - local acc = 0 - for k = 0, n - 1 do - acc += rd(src, (((s0 + k) * w + x) * ch + cc) * size, kind) * wt[k + 1] - end - wr(dst, o + cc * size, kind, acc) - end - end - end - end - end - local _ = h -end - --- nearest: dst pixel (x, y) = src pixel (floor((x + 0.5) * w / ow), ...) -@native function K.nearest(src: buffer, w: number, h: number, bpp: number, dst: buffer, ow: number, oh: number) - local sx, sy = w / ow, h / oh - local xs = table.create(ow, 0) - for x = 0, ow - 1 do - xs[x + 1] = math.min(floor((x + 0.5) * sx), w - 1) * bpp - end - local o = 0 - for y = 0, oh - 1 do - local row = math.min(floor((y + 0.5) * sy), h - 1) * w * bpp - if bpp == 4 then - for x = 1, ow do - writeu32(dst, o, readu32(src, row + xs[x])) - o += 4 - end - else - for x = 1, ow do - buffer.copy(dst, o, src, row + xs[x], bpp) - o += bpp - end - end - end -end - --- affine: dst pixel centres through m = { a, b, c, d, e, f } (xin = a x + b y + c), bilinear with clamped --- neighbours; centres outside the source -> zeros (Pillow) -@native function K.affine(src: buffer, w: number, h: number, ch: number, kind: number, dst: buffer, ow: number, oh: number, m: { number }) - local a, b, c, d, e, f = m[1], m[2], m[3], m[4], m[5], m[6] - local size = kind - for y = 0, oh - 1 do - local py = y + 0.5 - for x = 0, ow - 1 do - local px = x + 0.5 - local xin = a * px + b * py + c - 0.5 - local yin = d * px + e * py + f - 0.5 - local o = (y * ow + x) * ch * size - local x0 = floor(xin) - local y0 = floor(yin) - if xin < -0.5 or xin >= w - 0.5 or yin < -0.5 or yin >= h - 0.5 then - continue -- dst starts zeroed - end - local dx, dy = xin - x0, yin - y0 - local xa, xb = clamp(x0, 0, w - 1), clamp(x0 + 1, 0, w - 1) - local ya, yb = clamp(y0, 0, h - 1), clamp(y0 + 1, 0, h - 1) - for cc = 0, ch - 1 do - local p00 = rd(src, ((ya * w + xa) * ch + cc) * size, kind) - local p01 = rd(src, ((ya * w + xb) * ch + cc) * size, kind) - local p10 = rd(src, ((yb * w + xa) * ch + cc) * size, kind) - local p11 = rd(src, ((yb * w + xb) * ch + cc) * size, kind) - local top = p00 + (p01 - p00) * dx - local bot = p10 + (p11 - p10) * dx - local v = top + (bot - top) * dy - if kind == 1 then - writeu8(dst, o + cc, clamp(floor(v), 0, 255)) -- Pillow truncates - else - wr(dst, o + cc * size, kind, v) - end - end - end - end -end - --- Pillow's alpha_composite of src onto dst, in place -@native function K.overRgba8(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, opacity: number) - for y = 0, h - 1 do - for x = 0, w - 1 do - local so = ((sy + y) * sw + sx + x) * 4 - local doff = ((dy + y) * dw + dx + x) * 4 - local sa = readu8(src, so + 3) - if opacity < 255 then - sa = (sa * opacity + 127) // 255 - end - if sa == 0 then - continue - elseif sa == 255 then - -- coef1 = 255 * 128, coef2 = 0: the source pixel exactly - writeu32(dst, doff, readu32(src, so)) - continue - end - local da = readu8(dst, doff + 3) - local blend = da * (255 - sa) - local outa255 = sa * 255 + blend - local coef1 = (sa * 255 * 255 * 128) // outa255 - local coef2 = 255 * 128 - coef1 - for cc = 0, 2 do - local t = readu8(src, so + cc) * coef1 + readu8(dst, doff + cc) * coef2 + 0x80 * 128 - t = ((t // 256) + t) // 256 - writeu8(dst, doff + cc, t // 128) - end - local t = outa255 + 0x80 - writeu8(dst, doff + 3, ((t // 256) + t) // 256) - end - end -end - --- overFloat: straight-alpha "over" for rgba16 (kind 2) / rgbaf32 (kind 4); max = 65535 or 1 -@native function K.overFloat(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, opacity: number, kind: number) - local max = if kind == 2 then 65535 else 1 - local px = 4 * kind - for y = 0, h - 1 do - for x = 0, w - 1 do - local so = ((sy + y) * sw + sx + x) * px - local doff = ((dy + y) * dw + dx + x) * px - local sa = rd(src, so + 3 * kind, kind) / max * opacity - if sa <= 0 then - continue - end - local da = rd(dst, doff + 3 * kind, kind) / max - local oa = sa + da * (1 - sa) - for cc = 0, 2 do - local s = rd(src, so + cc * kind, kind) - local d = rd(dst, doff + cc * kind, kind) - wr(dst, doff + cc * kind, kind, if oa > 0 then (s * sa + d * da * (1 - sa)) / oa else 0) - end - wr(dst, doff + 3 * kind, kind, oa * max) - end - end -end - -@native function K.copyRect(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, bpp: number) - for y = 0, h - 1 do - buffer.copy(dst, ((dy + y) * dw + dx) * bpp, src, ((sy + y) * sw + sx) * bpp, w * bpp) - end -end - --- a = 255 leaves the colour as it is both ways (MULDIV255(v, 255) = v, v * 255 // 255 = v) -@native local function premultiply4(b: buffer, n: number, un: boolean) - for o = 3, n * 4 - 1, 4 do - local a = readu8(b, o) - if a == 255 then - continue - end - if a == 0 then - writeu16(b, o - 3, 0) - writeu8(b, o - 1, 0) - continue - end - for c = o - 3, o - 1 do - local v = readu8(b, c) - if un then - writeu8(b, c, math.min(255, (v * 255) // a)) -- Pillow's rgbA2rgba - else - local t = v * a + 128 -- Pillow's MULDIV255 - writeu8(b, c, ((t // 256) + t) // 256) - end - end - end -end - -@native function K.opaque(b: buffer, n: number): boolean - for o = 3, n * 4 - 1, 4 do - if readu8(b, o) ~= 255 then +local P_containers_Tar: any = {} +do -- containers/Tar: valid +local Tar = {} +local BLOCK = 512 +local function zeros(b: buffer, o: number): boolean + for i = 0, BLOCK - 1, 4 do + if buffer.readu32(b, o + i) ~= 0 then return false end end return true end - -@native function K.premultiply(b: buffer, n: number, ch: number, kind: number, un: boolean) - if kind == 1 and ch == 4 then - premultiply4(b, n, un) - return - end - local max = if kind == 1 then 255 elseif kind == 2 then 65535 else 1 - local px = ch * kind - for i = 0, n - 1 do - local o = i * px - local a = rd(b, o + (ch - 1) * kind, kind) - for cc = 0, ch - 2 do - local v = rd(b, o + cc * kind, kind) - local r - if un then - if a <= 0 then - r = 0 - elseif kind == 4 then - r = v / a - elseif kind == 1 then - r = math.min(255, (v * 255) // a) -- Pillow's rgbA2rgba - else - r = math.min(max, (v * max + a // 2) // a) - end - else - if kind == 4 then - r = v * a - elseif kind == 1 then - local t = v * a + 128 -- Pillow's MULDIV255 - r = ((t // 256) + t) // 256 - else - r = (v * a + max // 2) // max - end - end - wr(b, o + cc * kind, kind, r) +local function number(b: buffer, o: number, n: number): number? + local first = buffer.readu8(b, o) + if first >= 0x80 then + local v = first - (if first >= 0xC0 then 0x100 else 0x80) -- 0xFF.. = negative + for i = 1, n - 1 do + v = v * 256 + buffer.readu8(b, o + i) end + return v end + local s = buffer.readstring(b, o, n) + s = string.match(s, "^[ %z]*([0-7]*)") or "" + if s == "" then + return 0 + end + return tonumber(s, 8) +end +local function checksum(b: buffer, o: number): (number, number) + local u, s = 0, 0 + for i = 0, BLOCK - 1 do + local v = if i >= 148 and i < 156 then 32 else buffer.readu8(b, o + i) + u += v + s += if v >= 128 then v - 256 else v + end + return u, s +end +function Tar.valid(b: buffer, o: number): boolean + if o + BLOCK > buffer.len(b) or zeros(b, o) then + return false + end + local want = number(b, o + 148, 8) + local u, s = checksum(b, o) + return want == u or want == s +end +P_containers_Tar.valid = Tar.valid end -return K +local P_model_fbx_Binary: any = {} +do -- model/fbx/Binary: MAGIC +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 = {} +Read.MAGIC = "MS3D000000" +P_model_ms3d_Read.MAGIC = Read.MAGIC +end + +do -- image/ani +local Bytes = __include("core/Bytes") +S["image/ani"] = function(r: Bytes.Reader): number + return if r:peek(4) == "RIFF" and r:peek(4, 8) == "ACON" then 1 else 0 +end +end + +do -- image/art +local Bytes = __include("core/Bytes") +local readu8, readu16, readu32, readi16 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.readi16 +local function header(b: buffer, o: number, limit: number): (number?, number?, number?, number?, boolean?) + local p = o + local prefixed = false + if limit - p >= 8 and buffer.readstring(b, p, 8) == "BUILDART" then + p += 8 + prefixed = true + end + if limit - p < 16 or readu32(b, p) ~= 1 then + return nil, nil, nil, nil, nil + end + local first, last = readu32(b, p + 8), readu32(b, p + 12) + if last < first or last - first >= 65536 then + return nil, nil, nil, nil, nil + end + return p + 16, first, last, readu32(b, p + 4), prefixed +end +S["image/art"] = function(r: Bytes.Reader): number + local at, first, last = header(r.buf, r.base, r.limit) + if not at or not first or not last then + return 0 + end + local n = last - first + 1 + local p = at :: number + if r.limit - p < n * 8 then + return 0 + end + local total = 0 + for i = 0, n - 1 do + local w, h = readi16(r.buf, p + i * 2), readi16(r.buf, p + n * 2 + i * 2) + if w < 0 or h < 0 then + return 0 + end + total += w * h + end + local size = p + n * 8 + total - r.base + local have = r.limit - r.base + return if size == have then 0.9 elseif size < have and have - size < 4096 then 0.5 else 0 +end +end + +do -- image/blp +local Bytes = __include("core/Bytes") +S["image/blp"] = function(r: Bytes.Reader): number + local m = r:peek(4) + return if m == "BLP1" or m == "BLP2" then 1 elseif m == "BLP0" then 0.8 else 0 +end +end + +do -- image/bmp +local Bytes = __include("core/Bytes") +S["image/bmp"] = function(r: Bytes.Reader): number + if r:peek(2) ~= "BM" then + return 0 + end + local n = r:peekU8(14) + math.max(r:peekU8(15), 0) * 256 + if r:peekU8(16) == 0 and r:peekU8(17) == 0 and (n == 12 or n == 16 or n == 40 or n == 52 or n == 56 or n == 64 or n == 108 or n == 124) then + return 0.9 + end + return 0.2 +end +end + +do -- image/dds +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local MAGIC = "DDS " +S["image/dds"] = function(r: Bytes.Reader): number + return math.max(Sniff.magic(r, MAGIC .. "\124\0\0\0"), Sniff.magic(r, MAGIC, 0, 0.6)) +end +end + +do -- image/exr +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local MAGIC = "\118\47\49\1" +S["image/exr"] = function(r: Bytes.Reader): number + return Sniff.magic(r, MAGIC) +end +end + +do -- image/gif +local Bytes = __include("core/Bytes") +S["image/gif"] = function(r: Bytes.Reader): number + local s = r:peek(6) + return if s == "GIF89a" or s == "GIF87a" then 1 else 0 +end +end + +do -- image/hdr +local Bytes = __include("core/Bytes") +S["image/hdr"] = function(r: Bytes.Reader): number + local s = r:peek(10) + if s == "#?RADIANCE" then + return 1 + end + if string.sub(s, 1, 6) == "#?RGBE" then + return 1 + end + if string.sub(s, 1, 2) == "#?" and string.match(s, "^#%?%u") then + return 0.5 + end + return 0 +end +end + +do -- image/icns +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["image/icns"] = function(r: Bytes.Reader): number + return Sniff.magic(r, "icns") +end +end + +do -- image/ico +local Bytes = __include("core/Bytes") +local readu8 = buffer.readu8 +S["image/ico"] = function(r: Bytes.Reader): number + if r:remaining() < 22 then + return 0 + end + local b, o = r.buf, r.pos + local typ = buffer.readu16(b, o + 2) + local count = buffer.readu16(b, o + 4) + if buffer.readu16(b, o) ~= 0 or (typ ~= 1 and typ ~= 2) or count == 0 then + return 0 + end + -- the first entry: reserved byte 0, a size and offset inside the file + local size, off = buffer.readu32(b, o + 14), buffer.readu32(b, o + 18) + if readu8(b, o + 9) ~= 0 or size == 0 or off < 6 + count * 16 then + return 0 + end + return 0.8 +end +end + +do -- image/ilbm +local Bytes = __include("core/Bytes") +S["image/ilbm"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "FORM" then + return 0 + end + local t = r:peek(4, 8) + return if t == "ILBM" or t == "PBM " then 1 else 0 +end +end + +do -- image/jpeg +local Bytes = __include("core/Bytes") +S["image/jpeg"] = function(r: Bytes.Reader): number + local s = r:peek(3) + return if s == "\255\216\255" then 1 else 0 +end +end + +do -- image/ktx +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local ID1 = "\171KTX 11\187\r\n\26\n" +local ID2 = "\171KTX 20\187\r\n\26\n" +S["image/ktx"] = function(r: Bytes.Reader): number + return math.max(Sniff.magic(r, ID2), Sniff.magic(r, ID1)) +end +end + +do -- image/lmp +local Bytes = __include("core/Bytes") +local function kindOf(r: Bytes.Reader): string? + local n = r:remaining() + if n == 768 then + return "palette" + elseif n == 16385 or n == 16384 then + return "colormap" + end + if n < 9 then + return nil + end + local w, h = buffer.readu32(r.buf, r.pos), buffer.readu32(r.buf, r.pos + 4) + if w > 0 and h > 0 and w <= 4096 and h <= 4096 and 8 + w * h == n then + return "qpic" + end + return nil +end +S["image/lmp"] = function(r: Bytes.Reader): number + local k = kindOf(r) + return if k == "qpic" then 0.3 elseif k then 0.05 else 0 +end +end + +do -- image/pcx +local Bytes = __include("core/Bytes") +S["image/pcx"] = function(r: Bytes.Reader): number + if r:size() < 128 then + return 0 + end + local m, v, e, bpp = r:peekU8(0), r:peekU8(1), r:peekU8(2), r:peekU8(3) + if m ~= 10 or (v ~= 0 and v ~= 2 and v ~= 3 and v ~= 4 and v ~= 5) or e > 1 then + return 0 + end + return if bpp == 1 or bpp == 2 or bpp == 4 or bpp == 8 then 0.8 else 0 +end +end + +do -- image/png +local Bytes = __include("core/Bytes") +local SIGNATURE = "\137PNG\r\n\26\n" +S["image/png"] = function(r: Bytes.Reader): number + return if r:peek(8) == SIGNATURE then 1 else 0 +end +end + +do -- image/pnm +local Bytes = __include("core/Bytes") +S["image/pnm"] = function(r: Bytes.Reader): number + if r:remaining() < 3 then + return 0 + end + local a, b, c = r:peekU8(0), r:peekU8(1), r:peekU8(2) + if a ~= 80 then -- 'P' + return 0 + end + local ws = c == 32 or (c >= 9 and c <= 13) + if b >= 49 and b <= 55 and ws then -- P1..P7 + return 0.9 + end + if (b == 70 or b == 102) and ws then -- PF / Pf + return 0.9 + end + return 0 +end +end + +do -- image/qoi +local Bytes = __include("core/Bytes") +S["image/qoi"] = function(r: Bytes.Reader): number + return if r:peek(4) == "qoif" then 1 else 0 +end +end + +do -- image/sgi +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["image/sgi"] = function(r: Bytes.Reader): number + if Sniff.magic(r, "\1\218") == 0 or r:size() < 512 then + return 0 + end + local st, bpc = r:peekU8(2), r:peekU8(3) + return if st <= 1 and (bpc == 1 or bpc == 2) then 1 else 0 +end +end + +do -- image/spr +local Bytes = __include("core/Bytes") +S["image/spr"] = function(r: Bytes.Reader): number + if r:remaining() < 36 or r:peek(4) ~= "IDSP" then + return 0 + end + local v = buffer.readi32(r.buf, r.pos + 4) + return if v == 1 or v == 2 or v == 32 then 1 else 0.3 +end +end + +do -- image/sunras +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local MAGIC = "\89\166\106\149" +S["image/sunras"] = function(r: Bytes.Reader): number + return Sniff.magic(r, MAGIC) +end +end + +do -- image/tga +local Bytes = __include("core/Bytes") +local TYPES = { [1] = true, [2] = true, [3] = true, [9] = true, [10] = true, [11] = true } +local FOOTER = "TRUEVISION-XFILE.\0" +local readu8 = buffer.readu8 +type Header = { + idLen: number, + cmapType: number, + imageType: number, + cmapFirst: number, + cmapLen: number, + cmapBits: number, + width: number, + height: number, + depth: number, + desc: number, +} +local function header(r: Bytes.Reader): Header? + if r.limit - r.base < 18 then + return nil + end + local b, o = r.buf, r.base + local function u16(q: number): number + return readu8(b, o + q) + readu8(b, o + q + 1) * 256 + end + local h: Header = { + idLen = readu8(b, o), + cmapType = readu8(b, o + 1), + imageType = readu8(b, o + 2), + cmapFirst = u16(3), + cmapLen = u16(5), + cmapBits = readu8(b, o + 7), + width = u16(12), + height = u16(14), + depth = readu8(b, o + 16), + desc = readu8(b, o + 17), + } + return h +end +local function implausible(h: Header): string? + local t = h.imageType + if not TYPES[t] then + return "image type " .. t + end + if h.cmapType > 1 then + return "colour map type " .. h.cmapType + end + local mapped = t == 1 or t == 9 + if mapped and (h.cmapType ~= 1 or (h.depth ~= 8 and h.depth ~= 16)) then + return "colour-mapped image without a colour map" + end + if h.cmapType == 1 and h.cmapLen > 0 and h.cmapBits ~= 15 and h.cmapBits ~= 16 and h.cmapBits ~= 24 and h.cmapBits ~= 32 then + return "colour map entry size " .. h.cmapBits + end + if (t == 2 or t == 10) and h.depth ~= 15 and h.depth ~= 16 and h.depth ~= 24 and h.depth ~= 32 then + return "pixel depth " .. h.depth + end + if (t == 3 or t == 11) and h.depth ~= 8 and h.depth ~= 16 then + return "grey pixel depth " .. h.depth + end + if h.width == 0 or h.height == 0 then + return "zero size" + end + if h.desc >= 64 then + return "interleaving / reserved descriptor bits" + end + return nil +end +S["image/tga"] = function(r: Bytes.Reader): number + local h = header(r) + if not h or implausible(h) then + return 0 + end + local n = r.limit - r.base + if n >= 44 and buffer.readstring(r.buf, r.limit - 18, 18) == FOOTER then + return 0.9 + end + return 0.2 +end +end + +do -- image/tiff +local Bytes = __include("core/Bytes") +S["image/tiff"] = function(r: Bytes.Reader): number + local s = r:peek(4) + if s == "II*\0" or s == "MM\0*" or s == "II+\0" or s == "MM\0+" then + return 1 + end + return 0 +end +end + +do -- image/tim +local Bytes = __include("core/Bytes") +S["image/tim"] = function(r: Bytes.Reader): number + if r:remaining() < 20 or r:peek(4) ~= "\16\0\0\0" then + return 0 + end + local flags = r:peekU8(4) + if flags > 0x0F or (flags % 8) > 3 or r:peek(3, 5) ~= "\0\0\0" then + return 0 + end + return 0.8 +end +end + +do -- image/vtf +local Bytes = __include("core/Bytes") +S["image/vtf"] = function(r: Bytes.Reader): number + return if r:peek(4) == "VTF\0" and r:peekU8(4) == 7 then 1 else 0 +end +end + +do -- image/webp +local Bytes = __include("core/Bytes") +S["image/webp"] = function(r: Bytes.Reader): number + if r:peek(4) == "RIFF" and r:peek(4, 8) == "WEBP" then + return 1 + end + return 0 +end +end + +do -- image/xbm +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["image/xbm"] = function(r: Bytes.Reader): number + local s = Sniff.text(r, 256, true) + if string.match(s, "^#define%s+[%w_]*_?width%s+%d+") or string.match(s, "^/%*.-%*/%s*#define%s+[%w_]*width%s+%d+") then + return 0.9 + end + return 0 +end +end + +do -- image/xpm +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["image/xpm"] = function(r: Bytes.Reader): number + local s = Sniff.text(r, 64, true) + if string.sub(s, 1, 9) == "/* XPM */" or string.sub(s, 1, 6) == "! XPM2" then + return 1 + end + return 0 +end +end + +do -- audio/aac +local Bytes = __include("core/Bytes") +local Aac = P_codecs_audio_Aac +local readu8 = buffer.readu8 +local function id3Size(b: buffer, p: number, limit: number): number + if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then + return 0 + end + local s = 0 + for i = 6, 9 do + s = s * 128 + bit32.band(readu8(b, p + i), 127) + end + local footer = if bit32.band(readu8(b, p + 5), 0x10) ~= 0 then 10 else 0 + return 10 + s + footer +end +S["audio/aac"] = function(r: Bytes.Reader): number + local b, p, limit = r.buf, r.pos, r.limit + p += id3Size(b, p, limit) + local h = Aac.adts(b, p, limit) + if not h then + return 0 + end + local h2 = Aac.adts(b, p + h.frameSize, limit) + if h2 and h2.sfIndex == h.sfIndex and h2.channelConfig == h.channelConfig then + return 0.9 + end + return if p + h.frameSize >= limit then 0.7 else 0.4 +end +end + +do -- audio/ac3 +local Bytes = __include("core/Bytes") +local Ac3 = P_codecs_audio_Ac3 +S["audio/ac3"] = function(r: Bytes.Reader): number + local b, p, limit = r.buf, r.pos, r.limit + local h = Ac3.header(b, p, limit) + if not h then + return 0 + end + local h2 = Ac3.header(b, p + h.frameSize, limit) + if h2 and h2.sampleRate == h.sampleRate then + return 0.9 + end + return if p + h.frameSize >= limit then 0.6 else 0.3 +end +end + +do -- audio/adpcm +local Bytes = __include("core/Bytes") +S["audio/adpcm"] = function(_r: Bytes.Reader): number + return 0 +end +end + +do -- audio/adx +local Bytes = __include("core/Bytes") +S["audio/adx"] = function(r: Bytes.Reader): number + if r:peekU8(0) ~= 0x80 or r:peekU8(1) ~= 0 then + return 0 + end + local off = r:peekU8(2) * 256 + r:peekU8(3) + return if r:peek(6, off - 2) == "(c)CRI" then 1 else 0 +end +end + +do -- audio/aiff +local Bytes = __include("core/Bytes") +S["audio/aiff"] = function(r: Bytes.Reader): number + if r:remaining() < 12 or r:peek(4) ~= "FORM" then + return 0 + end + local form = buffer.readstring(r.buf, r.pos + 8, 4) + return if form == "AIFF" or form == "AIFC" then 1 else 0 +end +end + +do -- audio/ape +local Bytes = __include("core/Bytes") +S["audio/ape"] = function(r: Bytes.Reader): number + local head = r:peek(4) + if head == "MAC " or head == "MACF" then -- MACF: float samples + return 1 + end + if string.sub(head, 1, 3) == "ID3" then + local sz = 0 + for i = 6, 9 do + local v = r:peekU8(i) + if v < 0 then + return 0 + end + sz = sz * 128 + bit32.band(v, 127) + end + local footer = bit32.band(math.max(r:peekU8(5), 0), 0x10) ~= 0 + local id = r:peek(4, 10 + sz + (if footer then 10 else 0)) + return if id == "MAC " or id == "MACF" then 1 else 0 + end + return 0 +end +end + +do -- audio/au +local Bytes = __include("core/Bytes") +S["audio/au"] = function(r: Bytes.Reader): number + return if r:peek(4) == ".snd" then 1 else 0 +end +end + +do -- audio/brstm +local Bytes = __include("core/Bytes") +S["audio/brstm"] = function(r: Bytes.Reader): number + local m = r:peek(4) + if m ~= "RSTM" and m ~= "CSTM" and m ~= "FSTM" then + return 0 + end + local bom = r:peek(2, 4) + return if bom == "\254\255" or bom == "\255\254" then 1 else 0 +end +end + +do -- audio/caf +local Bytes = __include("core/Bytes") +S["audio/caf"] = function(r: Bytes.Reader): number + local h = r:peek(8) + if #h == 8 and string.sub(h, 1, 4) == "caff" and string.byte(h, 5) == 0 and string.byte(h, 6) == 1 then + return 1 + end + return 0 +end +end + +do -- audio/flac +local Bytes = __include("core/Bytes") +S["audio/flac"] = function(r: Bytes.Reader): number + local head = r:peek(4) + if head == "fLaC" then + return 1 + end + if head == "OggS" then + -- the first page's packet: 0x7F "FLAC" (the Ogg FLAC mapping) + local nseg = r:peekU8(26) + if nseg > 0 and r:peek(5, 27 + nseg) == "\127FLAC" then + return 1 + end + return 0 + end + if string.sub(head, 1, 3) == "ID3" then + -- an ID3v2 tag, then fLaC (mp3 files start with ID3 too) + local sz = 0 + for i = 6, 9 do + local v = r:peekU8(i) + if v < 0 then + return 0 + end + sz = sz * 128 + bit32.band(v, 127) + end + local footer = bit32.band(math.max(r:peekU8(5), 0), 0x10) ~= 0 + return if r:peek(4, 10 + sz + (if footer then 10 else 0)) == "fLaC" then 1 else 0 + end + return 0 +end +end + +do -- audio/m4a +local Bytes = __include("core/Bytes") +local IsoBmff = P_containers_IsoBmff +local AUDIO_BRANDS: { [string]: number } = { ["M4A "] = 1, ["M4B "] = 1, ["M4P "] = 1, ["M4V "] = 0.3 } +S["audio/m4a"] = function(r: Bytes.Reader): number + local brand = IsoBmff.sniff(r) + if brand == nil then + return 0 + end + if AUDIO_BRANDS[brand] then + return AUDIO_BRANDS[brand] + end + if brand == "avif" or brand == "avis" or brand == "heic" or brand == "heix" or brand == "mif1" or brand == "msf1" or brand == "crx " then + return 0 + end + return 0.4 -- an MP4 / MOV that may hold audio; a video format claims it more strongly +end +end + +do -- audio/mp3 +local Bytes = __include("core/Bytes") +local Header = P_codecs_audio_Mpa_Header +local Tags = P_audio_mp3_Tags +S["audio/mp3"] = function(r: Bytes.Reader): number + local b, p, lim = r.buf, r.pos, r.limit + local id3 = false + for _ = 1, 4 do -- (ffmpeg writes a tag even when the input had one: tags can follow each other) + local n = if p + 3 <= lim and buffer.readstring(b, p, 3) == "ID3" then Tags.id3v2Size(b, p, lim) else 0 + if n <= 0 then + break + end + id3 = true + p += n + end + if p + 4 > lim or not Header.valid(b, p) then + return if id3 then 0.5 else 0 + end + local fb = Header.frameBytes(b, p, 0) + if fb > 0 then + fb += Header.padding(b, p) + if p + fb + 4 <= lim and Header.compare(b, p, p + fb) then + return 0.9 + end + if p + fb == lim then + return 0.6 + end + end + return if id3 then 0.7 else 0.25 +end +end + +do -- audio/mpc +local Bytes = __include("core/Bytes") +local Musepack = P_codecs_audio_Musepack +local function id3v2(b: buffer, p: number, limit: number): number + if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then + return 0 + end + local n = 10 + for i = 6, 9 do + n += bit32.band(buffer.readu8(b, p + i), 127) * 128 ^ (9 - i) + end + return n + (if bit32.band(buffer.readu8(b, p + 5), 0x10) ~= 0 then 10 else 0) +end +S["audio/mpc"] = function(r: Bytes.Reader): number + local b, p, limit = r.buf, r.pos, r.limit + p += id3v2(b, p, limit) + local v = Musepack.magic(b, p, limit) + if v == 8 then + return 1 + end + return if v == 7 then 0.9 else 0 +end +end + +do -- audio/opus +local Bytes = __include("core/Bytes") +S["audio/opus"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "OggS" then + return 0 + end + local nseg = r:peekU8(26) + if nseg < 1 then + return 0 + end + return if r:peek(8, 27 + nseg) == "OpusHead" then 1 else 0 +end +end + +do -- audio/qoa +local Bytes = __include("core/Bytes") +S["audio/qoa"] = function(r: Bytes.Reader): number + return if r:peek(4) == "qoaf" then 1 else 0 +end +end + +do -- audio/tta +local Bytes = __include("core/Bytes") +local function id3Size(r: Bytes.Reader): number + if r:peek(3) ~= "ID3" then + return 0 + end + local sz = 0 + for i = 6, 9 do + local v = r:peekU8(i) + if v < 0 then + return 0 + end + sz = sz * 128 + bit32.band(v, 127) + end + local footer = bit32.band(math.max(r:peekU8(5), 0), 0x10) ~= 0 + return 10 + sz + (if footer then 10 else 0) +end +S["audio/tta"] = function(r: Bytes.Reader): number + return if r:peek(4, id3Size(r)) == "TTA1" then 1 else 0 +end +end + +do -- audio/vag +local Bytes = __include("core/Bytes") +S["audio/vag"] = function(r: Bytes.Reader): number + local m = r:peek(4) + return if m == "VAGp" or m == "VAGi" or m == "KVAG" then 1 else 0 +end +end + +do -- audio/voc +local Bytes = __include("core/Bytes") +local MAGIC = "Creative Voice File\26" +S["audio/voc"] = function(r: Bytes.Reader): number + return if r:peek(20) == MAGIC then 1 else 0 +end +end + +do -- audio/vorbis +local Bytes = __include("core/Bytes") +S["audio/vorbis"] = function(r: Bytes.Reader): number + if r:remaining() < 35 or r:peek(4) ~= "OggS" then + return 0 + end + local b, p = r.buf, r.pos + local nseg = buffer.readu8(b, p + 26) + local d = p + 27 + nseg + if d + 7 > r.limit then + return 0 + end + return if buffer.readu8(b, d) == 1 and buffer.readstring(b, d + 1, 6) == "vorbis" then 1 else 0 +end +end + +do -- audio/wav +local Bytes = __include("core/Bytes") +local Riff = P_containers_Riff +S["audio/wav"] = function(r: Bytes.Reader): number + return if Riff.sniff(r) == "WAVE" then 1 else 0 +end +end + +do -- audio/wavpack +local Bytes = __include("core/Bytes") +S["audio/wavpack"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "wvpk" then + return 0 + end + local v = r:peekU8(9) + return if v == 4 then 1 else 0.5 +end +end + +do -- video/avi +local Bytes = __include("core/Bytes") +S["video/avi"] = function(r: Bytes.Reader): number + if r:peek(4) == "RIFF" and r:peek(4, 8) == "AVI " then + return 1 + end + return 0 +end +end + +do -- video/fli +local Bytes = __include("core/Bytes") +local FLI, FLC, DTA = 0xAF11, 0xAF12, 0xAF44 +S["video/fli"] = function(r: Bytes.Reader): number + local s = r:peek(18) + if #s < 18 then + return 0 + end + local magic = string.byte(s, 5) + string.byte(s, 6) * 256 + if magic ~= FLI and magic ~= FLC and magic ~= DTA then + return 0 + end + local w = string.byte(s, 9) + string.byte(s, 10) * 256 + local h = string.byte(s, 11) + string.byte(s, 12) * 256 + if w > 4096 or h > 4096 then + return 0 + end + return 0.9 +end +end + +do -- video/flv +local Bytes = __include("core/Bytes") +S["video/flv"] = function(r: Bytes.Reader): number + if r:remaining() >= 9 and r:peek(3) == "FLV" then + return if r:peekU8(3) == 1 then 1 else 0.6 + end + return 0 +end +end + +do -- video/h264 +local Bytes = __include("core/Bytes") +S["video/h264"] = function(r: Bytes.Reader): number + local s = r:peek(5) + if not s or #s < 4 then + return 0 + end + local hdr + if string.byte(s, 1) == 0 and string.byte(s, 2) == 0 and string.byte(s, 3) == 1 then + hdr = string.byte(s, 4) + elseif #s >= 5 and string.byte(s, 1) == 0 and string.byte(s, 2) == 0 and string.byte(s, 3) == 0 and string.byte(s, 4) == 1 then + hdr = string.byte(s, 5) + else + return 0 + end + if hdr >= 128 then + return 0 + end + local t = hdr % 32 + if t == 7 then + return 0.8 + elseif t == 9 or t == 6 or t == 8 then + return 0.5 + elseif t == 5 then + return 0.4 + end + return 0 +end +end + +do -- video/mkv +local Bytes = __include("core/Bytes") +S["video/mkv"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "\26\69\223\163" then + return 0 + end + local head = r:peek(math.min(64, r:remaining())) + if string.find(head, "webm", 1, true) or string.find(head, "matroska", 1, true) then + return 1 + end + return 0.5 +end +end + +do -- video/mp4 +local Bytes = __include("core/Bytes") +local IsoBmff = P_containers_IsoBmff +local IMAGE_BRANDS = { avif = true, avis = true, heic = true, heix = true, mif1 = true, msf1 = true, ["crx "] = true } +local AUDIO_BRANDS = { ["M4A "] = true, ["M4B "] = true, ["M4P "] = true } +S["video/mp4"] = function(r: Bytes.Reader): number + local brand = IsoBmff.sniff(r) + if brand == nil or IMAGE_BRANDS[brand] then + return 0 + end + if AUDIO_BRANDS[brand] then + return 0.2 + end + if brand == "M4V " then + return 0.9 + end + return if brand == "" then 0.6 else 0.8 +end +end + +do -- video/mpegps +local Bytes = __include("core/Bytes") +S["video/mpegps"] = function(r: Bytes.Reader): number + if r:peek(4) == "\0\0\1\186" then + return 0.9 + end + if r:peek(4) == "\0\0\1\179" then + return 0.5 -- an MPEG-1 / 2 video elementary stream (sequence header) + end + return 0 +end +end + +do -- video/mpegts +local Bytes = __include("core/Bytes") +local SIZES = { 188, 192 } +local function packetSize(r: Bytes.Reader): (number, number) + local n = r:remaining() + local head = r:peek(2048 + 2 * 192) + local lim = math.min(n, 2048) + local start = 0 + while start < lim do + local f = string.find(head, "G", start + 1, true) -- 0x47 + if not f or f > lim then + break + end + start = f - 1 + for _, size in SIZES do + local hits, need = 0, math.min(3, (n - start - 1) // size + 1) + for k = 0, 2 do + local at = start + k * size + if at < n and string.byte(head, at + 1) == 0x47 then + hits += 1 + end + end + if hits >= need and (need >= 2 or start == 0) then + if size == 192 and start >= 4 then + return 192, start - 4 + elseif size == 188 then + return 188, start + end + end + end + start += 1 + end + return 0, 0 +end +S["video/mpegts"] = function(r: Bytes.Reader): number + local s, off = packetSize(r) + if s == 0 then + return 0 + end + if off > 0 then + return 0.6 + end + return if r:remaining() >= 3 * s then 0.9 else 0.5 +end +end + +do -- video/ogv +local Bytes = __include("core/Bytes") +S["video/ogv"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "OggS" then + return 0 + end + local b, p, lim = r.buf, r.pos, r.limit + for _ = 1, 8 do + if p + 27 > lim or buffer.readstring(b, p, 4) ~= "OggS" or buffer.readu8(b, p + 5) % 4 < 2 then + return 0 + end + local nseg = buffer.readu8(b, p + 26) + local d = p + 27 + nseg + if d + 7 <= lim and buffer.readu8(b, d) == 0x80 and buffer.readstring(b, d + 1, 6) == "theora" then + return 1 + end + if d > lim then + return 0 + end + local size = 0 + for i = 0, nseg - 1 do + size += buffer.readu8(b, p + 27 + i) + end + p = d + size + end + return 0 +end +end + +do -- video/smk +local Bytes = __include("core/Bytes") +S["video/smk"] = function(r: Bytes.Reader): number + local s = r:peek(4) + if s ~= "SMK2" and s ~= "SMK4" then + return 0 + end + return 1 +end +end + +do -- video/y4m +local Bytes = __include("core/Bytes") +local MAGIC = "YUV4MPEG2 " +S["video/y4m"] = function(r: Bytes.Reader): number + return if r:peek(10) == MAGIC then 1 else 0 +end +end + +do -- model/3ds +local Bytes = __include("core/Bytes") +S["model/3ds"] = function(r: Bytes.Reader): number + local h = r:peek(8) + if #h < 8 or string.byte(h, 1) ~= 0x4D or string.byte(h, 2) ~= 0x4D then + return 0 + end + local b1, b2, b3, b4, c1, c2 = string.byte(h, 3, 8) + local size = b1 + b2 * 256 + b3 * 65536 + b4 * 16777216 + local child = c1 + c2 * 256 + if size < 16 or not (child == 0x0002 or child == 0x3D3D or child == 0xB000) then + return 0 + end + return if size == r.limit - r.pos then 0.95 else 0.7 +end +end + +do -- model/3mf +local Bytes = __include("core/Bytes") +S["model/3mf"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "PK\3\4" then + return 0 + end + local n = r:size() + local tail = buffer.readstring(r.buf, r.base + math.max(0, n - 65536), math.min(n, 65536)) + if string.find(tail, "3D/[^/]*%.model") or string.find(tail, "3dmodel.model", 1, true) then + return 0.95 + end + local head = r:peek(256) + if string.find(head, "3D/", 1, true) then + return 0.7 + end + return 0 +end +end + +do -- model/ase +local Bytes = __include("core/Bytes") +local Text = P_codecs_text_Text +local MAGIC = "*3DSMAX_ASCIIEXPORT" +local function utf16(r: Bytes.Reader): (boolean?, boolean) + local h = r:peek(2) + if h == "\255\254" then + return true, false + elseif h == "\254\255" then + return true, true + elseif #h == 2 and string.byte(h, 2) == 0 and string.byte(h, 1) == 42 then + return true, false + elseif #h == 2 and string.byte(h, 1) == 0 and string.byte(h, 2) == 42 then + return true, true + end + return nil, false +end +local function text(r: Bytes.Reader, n: number?): string + local wide, be = utf16(r) + local len = r.limit - r.pos + if n then + len = math.min(len, n) + end + if wide then + local skip = if r:peek(2) == "\255\254" or r:peek(2) == "\254\255" then 2 else 0 + return Text.utf16(r.buf, r.pos + skip, len - skip, be) + end + return Text.toUtf8(buffer.readstring(r.buf, r.pos, len)) +end +S["model/ase"] = function(r: Bytes.Reader): number + local h = string.match(text(r, 256), "^%s*(%*[%w_]+)") + if h == MAGIC then + return 1 + end + return 0 +end +end + +do -- model/b3d +local Bytes = __include("core/Bytes") +S["model/b3d"] = function(r: Bytes.Reader): number + if r:peek(4) == "BB3D" then + return if r:peek(4, 8) ~= "" then 1 else 0.8 + end + return 0 +end +end + +do -- model/blend +local Bytes = __include("core/Bytes") +local Deflate = P_codecs_compress_Deflate +local Zstd = P_codecs_compress_Zstd +S["model/blend"] = function(r: Bytes.Reader): number + local head = r:peek(7) + if head == "BLENDER" then + return 1 + end + local n = r.limit - r.base + if string.sub(head, 1, 3) == "\31\139\8" then + local inner = Deflate.peek(r.buf, r.base, n, 7) + return if inner and buffer.tostring(inner) == "BLENDER" then 1 else 0 + end + if string.sub(head, 1, 4) == Zstd.MAGIC then + if n > 4 * 2 ^ 20 then + return 0.5 + end + local out = Zstd.decompress(r.buf, r.base, n, { verify = false }) + return if out and buffer.len(out) >= 7 and buffer.readstring(out, 0, 7) == "BLENDER" then 1 else 0 + end + return 0 +end +end + +do -- model/bsp +local Bytes = __include("core/Bytes") +S["model/bsp"] = function(r: Bytes.Reader): number + if r:remaining() < 64 then + return 0 + end + local m = r:peek(4) + local v = buffer.readi32(r.buf, r.pos + (if m == "IBSP" then 4 else 0)) + if m == "BSP2" or m == "2PSB" then + v = 29 + end + if m == "IBSP" then + return if v == 38 or v == 46 or v == 47 then 1 else 0.3 + end + if v == 29 or v == 30 then + local size = r:remaining() + for i = 0, 14 do + local o, n = buffer.readi32(r.buf, r.pos + 4 + i * 8), buffer.readi32(r.buf, r.pos + 8 + i * 8) + if o < 0 or n < 0 or o + n > size then + return 0 + end + end + return 0.6 + end + return 0 +end +end + +do -- model/buildmap +local Bytes = __include("core/Bytes") +local SECTOR_SIZE, WALL_SIZE, SPRITE_SIZE = 40, 32, 44 +local HEADER = 22 -- version, posx, posy, posz, ang, cursectnum, then u16 numsectors at 20 +local readu16 = buffer.readu16 +local function layout(b: buffer, o: number, limit: number): (number?, number?, number?, number?) + if limit - o < HEADER then + return nil, nil, nil, nil + end + local ns = readu16(b, o + 20) + local p = o + HEADER + ns * SECTOR_SIZE + if p + 2 > limit then + return nil, nil, nil, nil + end + local nw = readu16(b, p) + p += 2 + nw * WALL_SIZE + if p + 2 > limit then + return nil, nil, nil, nil + end + local nsp = readu16(b, p) + p += 2 + nsp * SPRITE_SIZE + return ns, nw, nsp, p +end +S["model/buildmap"] = function(r: Bytes.Reader): number + local b, o, limit = r.buf, r.base, r.limit + if limit - o < HEADER then + return 0 + end + local v = buffer.readu32(b, o) + if v ~= 7 and v ~= 8 and v ~= 9 then + return 0 + end + local ns, _, _, stop = layout(b, o, limit) + if not ns or not stop or stop > limit then + return 0 + end + return if stop == limit then 0.9 else 0.5 +end +end + +do -- model/d3map +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/d3map"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 512, true) + for _ = 1, 16 do + local rest = string.match(head, "^//[^\n]*\n%s*(.*)$") + if not rest then + break + end + head = rest + end + return if string.match(head, "^Version%s+[123]%s") then 1 else 0 +end +end + +do -- model/dae +local Bytes = __include("core/Bytes") +S["model/dae"] = function(r: Bytes.Reader): number + local head = r:peek(2048) + if string.sub(head, 1, 4) == "PK\3\4" then + local nlen = string.byte(head, 27) or 0 + local name = string.lower(string.sub(head, 31, 30 + nlen)) + if string.find(name, "%.dae$") or name == "manifest.xml" then + return 0.95 + end + return 0 + end + -- UTF-16 files: drop the zero bytes + if string.find(string.sub(head, 1, 4), "\0", 1, true) then + head = string.gsub(head, "%z", "") + end + if string.find(head, "<COLLADA", 1, true) then + return 1 + end + return 0 +end +end + +do -- model/fbx +local Bytes = __include("core/Bytes") +local Binary = P_model_fbx_Binary +local MAGIC = Binary.MAGIC +S["model/fbx"] = function(r: Bytes.Reader): number + if r:peek(21) == MAGIC then + return 1 + end + local head = r:peek(2048) + if string.find(head, "FBXHeaderExtension:", 1, true) then + return 0.95 + end + if string.find(head, "^; FBX %d") then + return 0.8 + end + return 0 +end +end + +do -- model/gltf +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["model/gltf"] = function(r: Bytes.Reader): number + if r:peek(4) == "glTF" then + return 1 + end + local head = r:peek(1024) + local s = Sniff.dropBom(head) + if string.find(s, "^%s*{") and string.find(s, "\"asset\"", 1, true) then + return 0.9 + end + if string.find(s, "^%s*{") and (string.find(s, "\"accessors\"", 1, true) or string.find(s, "\"bufferViews\"", 1, true)) then + return 0.6 + end + return 0 +end +end + +do -- model/godot +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/godot"] = function(r: Bytes.Reader): number + local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_scene[%s%]]") then + return 1 + end + return 0 +end +end + +do -- model/iqm +local Bytes = __include("core/Bytes") +local MAGIC = "INTERQUAKEMODEL\0" +S["model/iqm"] = function(r: Bytes.Reader): number + return if r:peek(16) == MAGIC then 1 else 0 +end +end + +do -- model/ldraw +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/ldraw"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 2048, true) + if string.find(head, "^0%s+FILE%s") then + return 0.9 + end + if string.find(head, "\n%s*1%s+%S+" .. string.rep("%s+[-+%deE.]+", 12) .. "%s+[^\n]+%.[dDlL][aAdD][tTrR]%s*\r?\n") then + return 0.8 + end + if string.find(head, "^0[ \t]+%a") and string.find(head, "\n%s*[1-5]%s+%S+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]") then + return 0.4 + end + return 0 +end +end + +do -- model/lwo +local Bytes = __include("core/Bytes") +local VERSIONS = { LWO2 = true, LWOB = true, LXOB = true } +S["model/lwo"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "FORM" then + return 0 + end + local v = r:peek(4, 8) + return if VERSIONS[v] then 1 elseif v == "LWO3" then 0.8 else 0 +end +end + +do -- model/map +local Bytes = __include("core/Bytes") +S["model/map"] = function(r: Bytes.Reader): number + local head = r:peek(math.min(r:remaining(), 4096)) + if #head < 2 or string.find(head, "[%z\1-\8\14-\31]") then + return 0 + end + if string.sub(head, 1, 3) == "\239\187\191" then + head = string.sub(head, 4) + end + local s = head + local game = false + while true do + local c = string.match(s, "^%s*//[^\n]*\n?()") + if not c then + break + end + if string.match(s, "^%s*//%s*Game:") then + game = true + end + s = string.sub(s, c :: number) + end + local body = string.match(s, '^%s*{%s*"[^"\n]*"%s*"') or string.match(s, "^%s*{%s*{%s*[%(bp]") + if not body then + return if game and string.match(s, "^%s*{") then 0.6 else 0 + end + return if game or string.find(head, '"classname"', 1, true) then 0.9 else 0.6 +end +end + +do -- model/mca +local Bytes = __include("core/Bytes") +local COMPRESSION = { [1] = "gzip", [2] = "zlib", [3] = "none", [4] = "lz4", [127] = "custom" } +S["model/mca"] = function(r: Bytes.Reader): number + local n = r.limit - r.base + if n < 8192 then + return 0 + end + local sectors = (n + 4095) // 4096 + local used, b = 0, r.buf + for i = 0, 1023 do + local e = bit32.byteswap(buffer.readu32(b, r.base + i * 4)) + if e ~= 0 then + local off, cnt = e // 256, e % 256 + if off < 2 or cnt == 0 or off + cnt > sectors then + return 0 + end + used += 1 + if used == 1 then + local p = r.base + off * 4096 + if p + 5 > r.limit then + return 0 + end + local c = buffer.readu8(b, p + 4) % 128 + if COMPRESSION[c] == nil then + return 0 + end + end + end + end + return if used > 0 then 0.8 else 0.2 +end +end + +do -- model/md2 +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/md2"] = function(r: Bytes.Reader): number + if r:remaining() < 68 then + return 0 + end + return if Sniff.magic(r, "IDP2") == 1 and r:peekU8(4) == 8 then 1 else 0 +end +end + +do -- model/md3 +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/md3"] = function(r: Bytes.Reader): number + if r:remaining() < 108 then + return 0 + end + return if Sniff.magic(r, "IDP3") == 1 and r:peekU8(4) == 15 then 1 else 0 +end +end + +do -- model/md5 +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/md5"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 512, true) + head = string.gsub(head, "^//[^\n]*\n%s*", "") + return if string.match(head, "^MD5Version%s+%d+") then 1 else 0 +end +end + +do -- model/mdl +local Bytes = __include("core/Bytes") +S["model/mdl"] = function(r: Bytes.Reader): number + local m = r:peek(4) + local v = r:peekU8(4) + if (m == "IDPO" and v == 6) or (m == "IDST" and v == 10) then + return 1 + end + return 0 +end +end + +do -- model/ms3d +local Bytes = __include("core/Bytes") +local Read = P_model_ms3d_Read +S["model/ms3d"] = function(r: Bytes.Reader): number + local h = r:peek(14) + if string.sub(h, 1, 10) ~= Read.MAGIC then + return 0 + end + local v = string.byte(h, 11) + return if v == 3 or v == 4 then 1 else 0.6 +end +end + +do -- model/obj +local Bytes = __include("core/Bytes") +S["model/obj"] = function(r: Bytes.Reader): number + local head = r:peek(512) + if string.find(head, "\0", 1, true) then + return 0 + end + if string.find(head, "^%s*v%s+[%-%d%.]") or string.find(head, "\n%s*v%s+[%-%d%.]") then + return 0.6 + end + if string.find(head, "^#") and (string.find(head, "\nmtllib ") or string.find(head, "\no ") or string.find(head, "\ng ")) then + return 0.4 + end + return 0 +end +end + +do -- model/off +local Bytes = __include("core/Bytes") +S["model/off"] = function(r: Bytes.Reader): number + local head = r:peek(512) + for _ = 1, 16 do + local rest = string.match(head, "^%s*#[^\n]*\n(.*)$") + if not rest then + break + end + head = rest + end + local kw = string.match(head, "^%s*(%w+)") + if kw and string.match(kw, "^S?T?C?N?4?n?OFF$") then + return 0.9 + end + return 0 +end +end + +do -- model/ply +local Bytes = __include("core/Bytes") +S["model/ply"] = function(r: Bytes.Reader): number + local h = r:peek(4) + return if h == "ply\n" or h == "ply\r" then 1 else 0 +end +end + +do -- model/pmx +local Bytes = __include("core/Bytes") +S["model/pmx"] = function(r: Bytes.Reader): number + local head = r:peek(8) + if string.sub(head, 1, 4) == "PMX " then + return 1 + end + if string.sub(head, 1, 7) == "Pmd\0\0\128\63" then + return 1 + end + return 0 +end +end + +do -- model/proc +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/proc"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 64, true) + if string.match(head, "^mapProcFile%d%d%d") then + return 1 + end + if string.match(head, '^"?PROC"?%s+"?%d') then + return 0.9 + end + return 0 +end +end + +do -- model/qb +local Bytes = __include("core/Bytes") +S["model/qb"] = function(r: Bytes.Reader): number + if r:remaining() < 24 or r:peek(4) ~= "\1\1\0\0" then + return 0 + end + local b, p = r.buf, r.pos + local fmt, z, comp, mask = buffer.readu32(b, p + 4), buffer.readu32(b, p + 8), buffer.readu32(b, p + 12), buffer.readu32(b, p + 16) + if fmt > 1 or z > 1 or comp > 1 or mask > 1 then + return 0 + end + return 0.9 +end +end + +do -- model/rbxm +local Bytes = __include("core/Bytes") +local MAGIC = "<roblox!\137\255\13\10\26\10" +S["model/rbxm"] = function(r: Bytes.Reader): number + return if r:peek(14) == MAGIC then 1 else 0 +end +end + +do -- model/rbxmx +local Bytes = __include("core/Bytes") +local find, format, match, gmatch = string.find, string.format, string.match, string.gmatch +S["model/rbxmx"] = function(r: Bytes.Reader): number + local head = r:peek(256) + head = string.gsub(head, "^\239\187\191", "") + head = string.gsub(head, "^%s*<%?xml[^>]*%?>", "") + if match(head, "^%s*<roblox[%s>]") then + return if find(head, "version=", 1, true) then 1 else 0.8 + end + return 0 +end +end + +do -- model/robloxmesh +local Bytes = __include("core/Bytes") +S["model/robloxmesh"] = function(r: Bytes.Reader): number + return if string.match(r:peek(13), "^version [1-7]%.%d%d[\r\n]") then 1 else 0 +end +end + +do -- model/schematic +local Bytes = __include("core/Bytes") +local Nbt = P_codecs_text_Nbt +local LITEMATIC_HINTS = { "Regions", "EnclosingSize", "RegionCount", "TotalVolume", "MinecraftDataVersion" } +local SPONGE_HINTS = { "BlockData", "PaletteMax" } -- v1 / v2 fields (some writers leave the root unnamed) +local function hinted(head: string, hints: { string }): boolean + for _, h in hints do + if string.find(head, string.char(0, #h) .. h, 1, true) then + return true + end + end + return false +end +S["model/schematic"] = function(r: Bytes.Reader): number + local p = Nbt.peek(r.buf, r.base, r.limit - r.base) + if not p or p.rootType ~= "compound" or p.endian ~= "big" then + return 0 + end + if p.name == "Schematic" or (p.firstName == "Schematic" and p.firstType == "compound") then + return 1 + end + local head = buffer.tostring(p.head) + return if hinted(head, LITEMATIC_HINTS) or hinted(head, SPONGE_HINTS) then 1 else 0 +end +end + +do -- model/smd +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/smd"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 256, true) + head = string.gsub(head, "^//[^\n]*\n%s*", "") + if string.match(head, "^version%s+1%s") and string.find(head, "nodes", 1, true) then + return 0.9 + end + return 0 +end +end + +do -- model/sourcemdl +local Bytes = __include("core/Bytes") +S["model/sourcemdl"] = function(r: Bytes.Reader): number + if r.limit - r.base < 8 or r:peek(4) ~= "IDST" then + return 0 + end + local v = buffer.readi32(r.buf, r.base + 4) + return if v >= 44 and v <= 49 then 1 else 0 +end +end + +do -- model/stl +local Bytes = __include("core/Bytes") +local function lower5(s: string): boolean + return string.lower(s) == "solid" +end +S["model/stl"] = function(r: Bytes.Reader): number + local size = r:remaining() + if size >= 84 then + local c = r:peek(4, 80) + local n = string.byte(c, 1) + string.byte(c, 2) * 256 + string.byte(c, 3) * 65536 + string.byte(c, 4) * 16777216 + if 84 + 50 * n == size then + return 0.9 + end + end + local head = r:peek(512) + local s = string.match(head, "^%s*(%a+)") + if s and lower5(s) then + local l = string.lower(head) + return if string.find(l, "facet", 1, true) or string.find(l, "endsolid", 1, true) then 0.9 else 0.5 + end + return 0 +end +end + +do -- model/t3d +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/t3d"] = function(r: Bytes.Reader): number + local h = Sniff.text(r, 512) + local first = string.match(h, "^%s*(Begin%s+%a+)") + if first == nil then + return 0 + end + local kind = string.lower(string.match(first, "%a+$") or "") + if kind == "map" or kind == "actor" or kind == "level" or kind == "brush" or kind == "polylist" then + return 0.9 + end + return 0.3 +end +end + +do -- model/udmf +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/udmf"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 1024, true) + for _ = 1, 32 do + local rest = string.match(head, "^//[^\n]*\n%s*(.*)$") or string.match(head, "^/%*.-%*/%s*(.*)$") + if not rest then + break + end + head = rest + end + if string.match(head, "^[Nn][Aa][Mm][Ee][Ss][Pp][Aa][Cc][Ee]%s*=%s*\"") then + return 0.9 + end + return 0 +end +end + +do -- model/usda +local Bytes = __include("core/Bytes") +local function isUsdz(r: Bytes.Reader): boolean + if r:peek(4) ~= "PK\3\4" then + return false + end + local lo, hi = r:peekU8(26), r:peekU8(27) + if lo < 0 or hi < 0 then + return false + end + local nameLen = lo + hi * 256 + local name = string.lower(r:peek(30 + nameLen)) + name = string.sub(name, 31) + return string.find(name, "%.usd[ac]?$") ~= nil +end +S["model/usda"] = function(r: Bytes.Reader): number + local head = r:peek(8) + if string.sub(head, 1, 5) == "#usda" or string.sub(head, 1, 8) == "\239\187\191#usda" then + return 1 + end + if head == "PXR-USDC" then + return 0.9 -- USDC magic, so the error says it is unsupported + end + if isUsdz(r) then + return 0.95 + end + return 0 +end +end + +do -- model/vbsp +local Bytes = __include("core/Bytes") +local HEADER = 8 + 64 * 16 + 4 +S["model/vbsp"] = function(r: Bytes.Reader): number + if r:remaining() < HEADER or r:peek(4) ~= "VBSP" then + return 0 + end + local v = buffer.readi32(r.buf, r.pos + 4) + return if v >= 19 and v <= 21 then 1 else 0.5 +end +end + +do -- model/vmf +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["model/vmf"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 512, true) + if string.find(head, "%z") then + return 0 + end + if string.match(head, "^versioninfo%s*{") or string.match(head, '^"versioninfo"%s*{') then + return 0.9 + end + if string.match(head, "^world%s*{") or string.match(head, "^visgroups%s*{") then + return 0.6 + end + return 0 +end +end + +do -- model/vox +local Bytes = __include("core/Bytes") +S["model/vox"] = function(r: Bytes.Reader): number + return if r:peek(4) == "VOX " and r:peek(4, 8) == "MAIN" then 1 elseif r:peek(4) == "VOX " then 0.8 else 0 +end +end + +do -- model/vrml +local Bytes = __include("core/Bytes") +S["model/vrml"] = function(r: Bytes.Reader): number + local head = r:peek(16) + if string.sub(head, 1, 3) == "\239\187\191" then + head = string.sub(head, 4) + end + return if string.sub(head, 1, 10) == "#VRML V2.0" then 1 elseif string.sub(head, 1, 6) == "#VRML " then 0.6 else 0 +end +end + +do -- model/x +local Bytes = __include("core/Bytes") +local ENCODINGS = { ["txt "] = "text", ["bin "] = "binary", tzip = "text", bzip = "binary" } +S["model/x"] = function(r: Bytes.Reader): number + if r:peek(4) ~= "xof " then + return 0 + end + return if ENCODINGS[r:peek(4, 8)] then 1 else 0.5 +end +end + +do -- model/x3d +local Bytes = __include("core/Bytes") +S["model/x3d"] = function(r: Bytes.Reader): number + local head = r:peek(1024) + if string.sub(head, 1, 3) == "\239\187\191" then + head = string.sub(head, 4) + end + if string.sub(head, 1, 5) == "#X3D " then + return 1 + end + if string.sub(head, 1, 4) == "\224\0\0\1" and string.find(head, "x3d", 1, true) then + return 0.9 + end + if string.find(head, "<X3D[%s>]") or string.find(head, "<!DOCTYPE X3D", 1, true) then + return 1 + end + return 0 +end +end + +do -- cad/step +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["cad/step"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 256) + head = string.gsub(head, "^%s*/%*.-%*/", "") + if string.find(head, "^%s*ISO%-10303%-21%s*;") then + return 1 + end + return 0 +end +end + +do -- font/bdf +local Bytes = __include("core/Bytes") +S["font/bdf"] = function(r: Bytes.Reader): number + local head = r:peek(32) + return if string.match(head, "^STARTFONT%s+2%.%d") then 1 else 0 +end +end + +do -- font/bmfont +local Bytes = __include("core/Bytes") +S["font/bmfont"] = function(r: Bytes.Reader): number + local head = r:peek(64) + if string.sub(head, 1, 4) == "BMF\3" then + return 1 + end + if string.match(head, "^info%s+face=") or string.match(head, "^info%s+") and string.find(head, "size=", 1, true) then + return 0.9 + end + if string.find(head, "<font>", 1, true) or (string.find(head, "<?xml", 1, true) and string.find(r:peek(512), "<font>", 1, true)) then + return if string.find(r:peek(512), "<info", 1, true) then 0.9 else 0.3 + end + return 0 +end +end + +do -- font/eot +local Bytes = __include("core/Bytes") +local MAGIC = 0x504C +S["font/eot"] = function(r: Bytes.Reader): number + local h = r:peek(36) + if #h < 36 then + return 0 + end + local ver = string.sub(h, 9, 12) + local magic = string.byte(h, 35) + string.byte(h, 36) * 256 + if magic == MAGIC and (ver == "\0\0\1\0" or ver == "\1\0\2\0" or ver == "\2\0\2\0") then + return 1 + end + return 0 +end +end + +do -- font/fon +local Bytes = __include("core/Bytes") +local function isFnt(h: string): boolean + if #h < 4 then + return false + end + local ver = string.byte(h, 1) + string.byte(h, 2) * 256 + return ver == 0x200 or ver == 0x300 +end +S["font/fon"] = function(r: Bytes.Reader): number + local h = r:peek(64) + if string.sub(h, 1, 2) == "MZ" and #h >= 64 then + local lfanew = string.byte(h, 61) + string.byte(h, 62) * 256 + string.byte(h, 63) * 65536 + local sig = r:peek(2, lfanew) + return if sig == "NE" then 0.6 elseif sig == "PE" then 0.2 else 0 + end + if isFnt(h) and #h >= 6 then + local size = string.byte(h, 3) + string.byte(h, 4) * 256 + string.byte(h, 5) * 65536 + string.byte(h, 6) * 16777216 + return if size == r:size() then 0.9 elseif size <= r:size() and size > 118 then 0.3 else 0 + end + return 0 +end +end + +do -- font/hershey +local Bytes = __include("core/Bytes") +local function header(line: string): (number?, number?) + if #line < 10 then + return nil, nil + end + local id = tonumber((string.gsub(string.sub(line, 1, 5), "^%s+", ""))) + local n = tonumber((string.gsub(string.sub(line, 6, 8), "^%s+", ""))) + if not id or not n or n < 1 or string.find(string.sub(line, 1, 8), "[^%d ]") then + return nil, nil + end + return id, n +end +S["font/hershey"] = function(r: Bytes.Reader): number + local head = r:peek(256) + local line = string.match(head, "^([^\r\n]*)") + local id, n = header(line or "") + if not id or not n then + return 0 + end + local body = string.sub(line :: string, 9) + if string.find(body, "[^ -~]") then + return 0 + end + return if #body == math.min(2 * n, 64) or #body == 2 * n then 0.7 else 0.3 +end +end + +do -- font/pcf +local Bytes = __include("core/Bytes") +S["font/pcf"] = function(r: Bytes.Reader): number + return if r:peek(4) == "\1fcp" then 1 else 0 +end +end + +do -- font/psf +local Bytes = __include("core/Bytes") +S["font/psf"] = function(r: Bytes.Reader): number + local h = r:peek(4) + if h == "\114\181\74\134" then + return 1 + end + if string.sub(h, 1, 2) == "\54\4" and #h >= 4 and string.byte(h, 3) <= 7 and string.byte(h, 4) > 0 then + return 0.9 + end + return 0 +end +end + +do -- font/ttf +local Bytes = __include("core/Bytes") +S["font/ttf"] = function(r: Bytes.Reader): number + local m = r:peek(4) + if m == "\0\1\0\0" or m == "OTTO" or m == "ttcf" or m == "true" then + return 0.9 + end + return 0 +end +end + +do -- font/type1 +local Bytes = __include("core/Bytes") +S["font/type1"] = function(r: Bytes.Reader): number + local h = r:peek(64) + if string.sub(h, 1, 2) == "\128\1" then + h = string.sub(h, 7) + end + if string.sub(h, 1, 14) == "%!PS-AdobeFont" or string.sub(h, 1, 10) == "%!FontType" then + return 1 + end + return 0 +end +end + +do -- font/woff +local Bytes = __include("core/Bytes") +S["font/woff"] = function(r: Bytes.Reader): number + return if r:peek(4) == "wOFF" then 1 else 0 +end +end + +do -- font/woff2 +local Bytes = __include("core/Bytes") +S["font/woff2"] = function(r: Bytes.Reader): number + return if r:peek(4) == "wOF2" then 1 else 0 +end +end + +do -- archive/7z +local Bytes = __include("core/Bytes") +local MAGIC = "7z\188\175\39\28" +S["archive/7z"] = function(r: Bytes.Reader): number + return if r:peek(6) == MAGIC then 1 else 0 +end +end + +do -- archive/adf +local Bytes = __include("core/Bytes") +local BS = 512 +S["archive/adf"] = function(r: Bytes.Reader): number + local n = r:size() + if n < 4 * BS or n % BS ~= 0 then + return 0 + end + local h = r:peek(4) + if string.sub(h, 1, 3) ~= "DOS" or string.byte(h, 4) > 5 then + return 0 + end + return if n == 901120 or n == 1802240 then 0.95 else 0.6 +end +end + +do -- archive/applesingle +local Bytes = __include("core/Bytes") +S["archive/applesingle"] = function(r: Bytes.Reader): number + local h = r:peek(8) + if #h < 8 then + return 0 + end + local magic = string.sub(h, 1, 4) + local ver = string.sub(h, 5, 8) + if (magic == "\0\5\22\0" or magic == "\0\5\22\7") and (ver == "\0\1\0\0" or ver == "\0\2\0\0") then + return 1 + end + return 0 +end +end + +do -- archive/ar +local Bytes = __include("core/Bytes") +local MAGIC = "!<arch>\n" +S["archive/ar"] = function(r: Bytes.Reader): number + if r:peek(8) == MAGIC then + return if r:peek(13, 68) == "debian-binary" then 1 else 0.9 + end + return if r:peek(8) == "!<thin>\n" then 0.5 else 0 +end +end + +do -- archive/arj +local Bytes = __include("core/Bytes") +S["archive/arj"] = function(r: Bytes.Reader): number + local h = r:peek(4) + if #h == 4 and string.byte(h, 1) == 0x60 and string.byte(h, 2) == 0xEA then + local size = string.byte(h, 3) + string.byte(h, 4) * 256 + return if size > 0 and size <= 2600 then 0.9 else 0 + end + return 0 +end +end + +do -- archive/binhex +local Bytes = __include("core/Bytes") +local BANNER = "(This file must be converted with BinHex" +S["archive/binhex"] = function(r: Bytes.Reader): number + local head = r:peek(2048) + local at = string.find(head, BANNER, 1, true) + if not at then + return 0 + end + return if at == 1 then 1 else 0.8 +end +end + +do -- archive/br +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Brotli = P_codecs_compress_Brotli +local SNIFF_WHOLE = 262144 -- streams up to this size are decoded whole by sniff +local SNIFF_PREFIX = 65536 +S["archive/br"] = function(r: Bytes.Reader): number + local n = r:remaining() + if n == 0 then + return 0 + end + if n <= SNIFF_WHOLE then + local out, consumed = Brotli.decompress(r.buf, r.pos, n, { maxBytes = 2 ^ 26 }) + if out and consumed == r.limit then + return if buffer.len(out) > 0 then 0.3 else 0.05 + end + return 0 + end + local _, err = Brotli.decompress(r.buf, r.pos, SNIFF_PREFIX, { maxBytes = 2 ^ 22 }) + if err and (err.code == Err.TRUNCATED or err.code == Err.LIMIT) then + return 0.05 + end + return 0 +end +end + +do -- archive/bz2 +local Bytes = __include("core/Bytes") +S["archive/bz2"] = function(r: Bytes.Reader): number + local h = r:peek(10) + if #h < 10 or string.sub(h, 1, 3) ~= "BZh" then + return 0 + end + local lv = string.byte(h, 4) + if lv < 0x31 or lv > 0x39 then + return 0 + end + local magic = string.sub(h, 5, 10) + if magic == "\x31\x41\x59\x26\x53\x59" or magic == "\x17\x72\x45\x38\x50\x90" then + return 1 + end + return 0 +end +end + +do -- archive/cab +local Bytes = __include("core/Bytes") +S["archive/cab"] = function(r: Bytes.Reader): number + if r:peek(8) == "MSCF\0\0\0\0" then + return 1 + end + return 0 +end +end + +do -- archive/cpio +local Bytes = __include("core/Bytes") +S["archive/cpio"] = function(r: Bytes.Reader): number + local m = r:peek(6) + if m == "070701" or m == "070702" or m == "070707" then + return 1 + end + local b2 = r:peek(2) + if (b2 == "\199\113" or b2 == "\113\199") and r:remaining() >= 26 then + return 0.5 + end + return 0 +end +end + +do -- archive/d64 +local Bytes = __include("core/Bytes") +type Geometry = { kind: string, tracks: number, offsets: { number }, spt: { number }, dirTrack: number, total: number } +local function geometry(kind: string, tracks: number): Geometry + local offsets, spt = {}, {} + local o = 0 + for t = 1, tracks do + local n + if kind == "d81" then + n = 40 + else + local s = if kind == "d71" and t > 35 then t - 35 else t + n = if s <= 17 then 21 elseif s <= 24 then 19 elseif s <= 30 then 18 else 17 + end + offsets[t], spt[t] = o, n + o += n * 256 + end + return { kind = kind, tracks = tracks, offsets = offsets, spt = spt, dirTrack = if kind == "d81" then 40 else 18, total = o } +end +local function detect(len: number): Geometry? + for _, g in { { "d64", 35 }, { "d64", 40 }, { "d64", 42 }, { "d71", 70 }, { "d81", 80 } } :: { { any } } do + local geo = geometry(g[1] :: string, g[2] :: number) + local sectors = geo.total // 256 + if len == geo.total or (g[1] ~= "d81" and len == geo.total + sectors) then + return geo + end + end + return nil +end +S["archive/d64"] = function(r: Bytes.Reader): number + local geo = detect(r:size()) + if not geo then + return 0 + end + -- the BAM / header sector: dir track link and DOS version byte + local h = r:sub(geo.offsets[geo.dirTrack], 256) + local t, s, v = h:u8(), h:u8(), h:u8() + if geo.kind == "d81" then + return if t == 40 and s == 3 and v == 0x44 then 0.9 else 0.3 + end + return if t == 18 and s == 1 and (v == 0x41 or v == 0) then 0.9 else 0.3 +end +end + +do -- archive/fat +local Bytes = __include("core/Bytes") +local Fat = P_containers_Fat +S["archive/fat"] = function(r: Bytes.Reader): number + if r:remaining() < 512 then + return 0 + end + local v = Fat.open(r.buf, r.base + r.pos, r.limit - r.base - r.pos) + if not v then + return 0 + end + return if v.partition then 0.6 else 0.8 +end +end + +do -- archive/grp +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local MAGIC = "KenSilverman" +S["archive/grp"] = function(r: Bytes.Reader): number + return Sniff.magic(r, MAGIC) +end +end + +do -- archive/gzip +local Bytes = __include("core/Bytes") +S["archive/gzip"] = function(r: Bytes.Reader): number + return if r:peek(3) == "\31\139\8" then 1 else 0 +end +end + +do -- archive/iso +local Bytes = __include("core/Bytes") +S["archive/iso"] = function(r: Bytes.Reader): number + return if r:peek(5, 16 * 2048 + 1) == "CD001" then 1 else 0 +end +end + +do -- archive/lha +local Bytes = __include("core/Bytes") +local METHODS: { [string]: boolean } = { + ["-lh0-"] = true, ["-lz4-"] = true, ["-lhd-"] = true, ["-lh1-"] = true, ["-lh4-"] = true, ["-lh5-"] = true, + ["-lh6-"] = true, ["-lh7-"] = true, ["-lhx-"] = true, ["-lzs-"] = true, ["-lz5-"] = true, ["-lh2-"] = true, + ["-lh3-"] = true, ["-pm0-"] = true, ["-pm1-"] = true, ["-pm2-"] = true, ["-lk7-"] = true, +} +local function isHeader(s: string): boolean + if #s < 22 then + return false + end + local m = string.sub(s, 3, 7) + local level = string.byte(s, 21) + return METHODS[m] == true and level <= 3 +end +S["archive/lha"] = function(r: Bytes.Reader): number + if isHeader(r:peek(22)) then + return 0.95 + end + return 0 +end +end + +do -- archive/lz4 +local Bytes = __include("core/Bytes") +S["archive/lz4"] = function(r: Bytes.Reader): number + local m = r:peek(4) + if m == "\4\34\77\24" then + return 1 + elseif m == "\2\33\76\24" then + return 0.9 + elseif #m == 4 and string.byte(m, 1) >= 0x50 and string.byte(m, 1) <= 0x5F and string.sub(m, 2) == "\42\77\24" then + -- a skippable frame (zstd shares the magic): an LZ4 frame after it + local h = r:peek(4, 4) + if #h == 4 then + local n = string.byte(h, 1) + string.byte(h, 2) * 256 + string.byte(h, 3) * 65536 + string.byte(h, 4) * 16777216 + if r:peek(4, 8 + n) == "\4\34\77\24" then + return 1 + end + end + end + return 0 +end +end + +do -- archive/macbinary +local Bytes = __include("core/Bytes") +local Crc16 = __include("core/Crc16") +local function version(b: buffer, o: number, len: number): string? + if len < 128 then + return nil + end + local u8 = function(i: number): number + return buffer.readu8(b, o + i) + end + if u8(0) ~= 0 or u8(74) ~= 0 then + return nil + end + local nameLen = u8(1) + if nameLen < 1 or nameLen > 63 then + return nil + end + local function be32(i: number): number + return u8(i) * 16777216 + u8(i + 1) * 65536 + u8(i + 2) * 256 + u8(i + 3) + end + local dlen, rlen = be32(83), be32(87) + if dlen > 0x7FFFFFFF or rlen > 0x7FFFFFFF then + return nil + end + local crc = u8(124) * 256 + u8(125) + if crc == Crc16.ccitt(b, o, 124) and (crc ~= 0 or u8(122) >= 129) then + return if buffer.readstring(b, o + 102, 4) == "mBIN" then "III" else "II" + end + if buffer.readstring(b, o + 102, 4) == "mBIN" then + return nil -- III with a bad CRC + end + -- MacBinary I: byte 82 zero, bytes 99..125 zero, the forks within the file + if u8(82) ~= 0 then + return nil + end + for i = 99, 125 do + if u8(i) ~= 0 then + return nil + end + end + local need = 128 + math.ceil(dlen / 128) * 128 + rlen + return if need <= len + 127 then "I" else nil +end +S["archive/macbinary"] = function(r: Bytes.Reader): number + local n = math.min(r:remaining(), 128) + if n < 128 then + return 0 + end + local v = version(r.buf, r.base + r.pos, r.limit - r.base - r.pos) + return if v == "III" then 0.95 elseif v == "II" then 0.8 elseif v == "I" then 0.3 else 0 +end +end + +do -- archive/mpq +local Bytes = __include("core/Bytes") +S["archive/mpq"] = function(r: Bytes.Reader): number + local m = r:peek(4) + if m == "MPQ\x1A" or m == "MPQ\x1B" then + return 1 + end + -- a prefixed archive (an installer stub): the header on a 512-byte boundary in the first 64 KB + for at = 512, math.min(65536, r:remaining() - 32), 512 do + if r:peek(4, at) == "MPQ\x1A" then + return 0.6 + end + end + return 0 +end +end + +do -- archive/pak +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["archive/pak"] = function(r: Bytes.Reader): number + if r:remaining() < 12 then + return 0 + end + return math.max(Sniff.magic(r, "PACK", 0, 0.9), Sniff.magic(r, "SPAK", 0, 0.9)) +end +end + +do -- archive/rpm +local Bytes = __include("core/Bytes") +local LEAD_MAGIC = "\237\171\238\219" +S["archive/rpm"] = function(r: Bytes.Reader): number + return if r:peek(4) == LEAD_MAGIC then 1 else 0 +end +end + +do -- archive/tar +local Bytes = __include("core/Bytes") +local Tar = P_containers_Tar +S["archive/tar"] = function(r: Bytes.Reader): number + if r:remaining() < 512 then + return 0 + end + if not Tar.valid(r.buf, r.pos) then + return 0 + end + return if r:peek(5, 257) == "ustar" then 0.95 else 0.6 +end +end + +do -- archive/unitypackage +local Bytes = __include("core/Bytes") +local Deflate = P_codecs_compress_Deflate +local Tar = P_containers_Tar +local function guidOf(name: string): (string?, string?) + local n = string.gsub(name, "^%./", "") + local guid, rest = string.match(n, "^(%x+)/?(.*)$") + if guid and #guid == 32 then + return string.lower(guid), rest + end + return nil, nil +end +S["archive/unitypackage"] = function(r: Bytes.Reader): number + if r:peek(3) ~= "\31\139\8" then + return 0 + end + local head = Deflate.peek(r.buf, r.pos, r.limit - r.pos, 512) + if not head or buffer.len(head) < 512 or not Tar.valid(head, 0) then + return 0 + end + local z = 0 + while z < 100 and buffer.readu8(head, z) ~= 0 do + z += 1 + end + return if guidOf(buffer.readstring(head, 0, z)) then 1 else 0 -- ties with archive/gzip go to the extension +end +end + +do -- archive/uu +local Bytes = __include("core/Bytes") +S["archive/uu"] = function(r: Bytes.Reader): number + local head = r:peek(4096) + if string.match(head, "^begin%-base64 [0-7]+ [^\r\n]") or string.match(head, "^begin [0-7]+ [^\r\n]") then + return 0.9 + end + if string.match(head, "\nbegin%-base64 [0-7]+ [^\r\n]") or string.match(head, "\nbegin [0-7][0-7][0-7]+ [^\r\n]") then + return 0.5 + end + return 0 +end +end + +do -- archive/vpk +local Bytes = __include("core/Bytes") +S["archive/vpk"] = function(r: Bytes.Reader): number + if r:remaining() < 12 or r:peek(4) ~= "\x34\x12\xAA\x55" then + return 0 + end + local v = r:peekU8(4) + return if v == 1 or v == 2 then 1 else 0.5 +end +end + +do -- archive/vswap +local Bytes = __include("core/Bytes") +local readu8, readu16, readi16, writeu32 = buffer.readu8, buffer.readu16, buffer.readi16, buffer.writeu32 +local function header(r: Bytes.Reader): (number?, number, number) + if r:remaining() < 6 then + return nil, 0, 0 + end + local n, ss, so = readu16(r.buf, r.base), readu16(r.buf, r.base + 2), readu16(r.buf, r.base + 4) + if n == 0 or ss > so or so > n or 6 + n * 6 > r:remaining() then + return nil, 0, 0 + end + return n, ss, so +end +S["archive/vswap"] = function(r: Bytes.Reader): number + local n = header(r) + if not n then + return 0 + end + local size = r.limit - r.base + local b = r.buf + local last = 6 + n * 6 + local nonzero = 0 + for i = 0, n - 1 do + local o = buffer.readu32(b, r.base + 6 + i * 4) + local l = readu16(b, r.base + 6 + n * 4 + i * 2) + if o ~= 0 then + if o < last or o + l > size then + return 0 + end + last = o + nonzero += 1 + end + end + return if nonzero > 0 then 0.6 else 0 +end +end + +do -- archive/wad +local Bytes = __include("core/Bytes") +S["archive/wad"] = function(r: Bytes.Reader): number + if r:remaining() < 12 then + return 0 + end + local m = r:peek(4) + if m ~= "IWAD" and m ~= "PWAD" then + return 0 + end + return 0.9 +end +end + +do -- archive/wad2 +local Bytes = __include("core/Bytes") +S["archive/wad2"] = function(r: Bytes.Reader): number + if r:remaining() < 12 then + return 0 + end + local m = r:peek(4) + return if m == "WAD2" or m == "WAD3" then 0.9 else 0 +end +end + +do -- archive/xz +local Bytes = __include("core/Bytes") +local XZ_MAGIC = "\253" .. "7zXZ\0" +local function aloneScore(r: Bytes.Reader): number + local h = r:peek(14) + if #h < 14 then + return 0 + end + local d = string.byte(h, 1) + if d >= 225 or string.byte(h, 14) ~= 0 then + return 0 + end + local dict = string.byte(h, 2) + string.byte(h, 3) * 256 + string.byte(h, 4) * 65536 + string.byte(h, 5) * 16777216 + local okDict = false + for n = 12, 31 do + if dict == 2 ^ n or (n < 31 and dict == 2 ^ n + 2 ^ (n - 1)) then + okDict = true + break + end + end + if not okDict then + return 0 + end + local s = string.sub(h, 6, 13) + if s ~= string.rep("\255", 8) and (string.byte(h, 11) ~= 0 or string.byte(h, 12) ~= 0 or string.byte(h, 13) ~= 0) then + return 0 + end + return if d == 0x5D then 0.4 else 0.2 +end +S["archive/xz"] = function(r: Bytes.Reader): number + if r:peek(6) == XZ_MAGIC then + return 1 + end + return aloneScore(r) +end +end + +do -- archive/yenc +local Bytes = __include("core/Bytes") +S["archive/yenc"] = function(r: Bytes.Reader): number + local head = r:peek(4096) + if string.match(head, "^=ybegin ") then + return 0.95 + end + return if string.find(head, "\n=ybegin [^\n]*name=") then 0.6 else 0 +end +end + +do -- archive/z +local Bytes = __include("core/Bytes") +S["archive/z"] = function(r: Bytes.Reader): number + if r:peek(2) ~= "\31\157" then + return 0 + end + local f = r:peekU8(2) + return if f >= 0 and bit32.band(f, 0x60) == 0 and bit32.band(f, 0x1F) >= 9 and bit32.band(f, 0x1F) <= 16 then 1 else 0.3 +end +end + +do -- archive/zip +local Bytes = __include("core/Bytes") +S["archive/zip"] = function(r: Bytes.Reader): number + local s = r:peek(4) + -- ZIP-based formats (docx, jar, 3mf, ...) score higher in their own sniff + if s == "PK\3\4" or s == "PK\5\6" then + return 0.6 + end + if string.sub(s, 1, 2) == "MZ" then + return 0 -- a self-extractor opens with Zip.decode / opts.format = "zip" + end + return 0 +end +end + +do -- archive/zoo +local Bytes = __include("core/Bytes") +local TAG = 0xFDC4A7DC +S["archive/zoo"] = function(r: Bytes.Reader): number + local h = r:peek(24) + if #h < 24 then + return 0 + end + local tag = string.byte(h, 21) + string.byte(h, 22) * 256 + string.byte(h, 23) * 65536 + string.byte(h, 24) * 16777216 + if tag ~= TAG then + return 0 + end + return if string.sub(h, 1, 4) == "ZOO " then 1 else 0.8 +end +end + +do -- archive/zst +local Bytes = __include("core/Bytes") +local Zstd = P_codecs_compress_Zstd +S["archive/zst"] = function(r: Bytes.Reader): number + local m = r:peek(4) + if m == Zstd.MAGIC then + return 1 + end + -- a skippable frame (0x184D2A50 .. 0x184D2A5F) is usually followed by a zstd frame + if #m == 4 and string.sub(m, 2, 4) == "\42\77\24" and bit32.band(string.byte(m, 1), 0xF0) == 0x50 then + return 0.5 + end + return 0 +end +end + +do -- data/cbor +local Bytes = __include("core/Bytes") +S["data/cbor"] = function(r: Bytes.Reader): number + return if r:peek(3) == "\217\217\247" then 1 else 0 +end +end + +do -- data/csv +local Bytes = __include("core/Bytes") +local find, sub, byte, gsub = string.find, string.sub, string.byte, string.gsub +S["data/csv"] = function(r: Bytes.Reader): number + local head = r:peek(1024) + if find(head, "%z") then + return 0 + end + local l1, l2 = string.match(head, "^([^\r\n]*)\r?\n([^\r\n]*)") + if not l1 or l1 == "" then + return 0 + end + for _, d in { ",", "\t", ";" } do + local _, c1 = gsub(l1, d, "") + local _, c2 = gsub(l2 :: string, d, "") + if c1 > 0 and c1 == c2 then + return 0.15 + end + end + return 0 +end +end + +do -- data/ini +local Bytes = __include("core/Bytes") +S["data/ini"] = function(r: Bytes.Reader): number + local head = r:peek(512) + if string.find(head, "%z") then + return 0 + end + local first = string.match(head, "^[%s]*([^\r\n]*)") + while first and string.match(first, "^[;#]") do + head = string.match(head, "^[^\n]*\n(.*)$") or "" + first = string.match(head, "^[%s]*([^\r\n]*)") + end + if first and string.match(first, "^%[[^%]]+%]%s*$") then + return 0.2 + end + return 0 +end +end + +do -- data/json +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["data/json"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 64) + local first = string.match(head, "^[ \t\r\n]*(.)") + if first == "{" then + local nxt = string.match(head, "^[^{]*{[ \t\r\n]*(.)") + return if nxt == nil or nxt == '"' or nxt == "}" then 0.6 else 0.1 + elseif first == "[" then + -- past any nested '[': a JSON value must start (TOML / INI "[section]" and "[[table]]" do not) + local nxt = string.match(head, "^[ \t\r\n]*[%[ \t\r\n]*(.)") + if nxt == nil or string.find('{"-0123456789tfn]', nxt, 1, true) then + return 0.3 + end + return 0 + end + return 0 +end +end + +do -- data/msgpack +local Bytes = __include("core/Bytes") +S["data/msgpack"] = function(_r: Bytes.Reader): number + return 0 -- no magic: by extension or opts.format only +end +end + +do -- data/nbt +local Bytes = __include("core/Bytes") +local Nbt = P_codecs_text_Nbt +S["data/nbt"] = function(r: Bytes.Reader): number + local p = Nbt.peek(r.buf, r.base, r.limit - r.base) + if not p or p.rootType ~= "compound" then + return 0 + end + if p.compression ~= "none" then + return if p.firstType then 1 else 0.5 -- gzip wrapped NBT: ties with archive/gzip go to the extension + end + return if p.firstType and p.firstName then 0.6 else 0.2 +end +end + +do -- data/plist +local Bytes = __include("core/Bytes") +S["data/plist"] = function(r: Bytes.Reader): number + local head = r:peek(256) + if string.sub(head, 1, 6) == "bplist" then + return 1 + end + if string.find(head, "<!DOCTYPE plist", 1, true) or string.find(head, "<plist", 1, true) then + return 0.9 + end + return 0 +end +end + +do -- data/q3shader +local Bytes = __include("core/Bytes") +local KEYWORDS = { "surfaceparm", "map", "clampmap", "animmap", "blendfunc", "rgbgen", "alphagen", "tcgen", "tcmod", + "cull", "deformvertexes", "qer_editorimage", "nopicmip", "nomipmaps", "skyparms", "q3map_", "depthwrite", "alphafunc" } +S["data/q3shader"] = function(r: Bytes.Reader): number + local head = r:peek(math.min(r:remaining(), 2048)) + if #head < 4 or string.find(head, "[%z\1-\8\14-\31]") then + return 0 + end + local s = string.gsub(string.gsub(head, "/%*.-%*/", " "), "//[^\n]*", "") + if not string.match(s, "^%s*[^%s{}\"]+%s*{") then + return 0 + end + local lower = string.lower(s) + for _, k in KEYWORDS do + if string.find(lower, "%f[%w_]" .. k) then + return 0.7 + end + end + return 0.2 +end +end + +do -- data/q3skin +local Bytes = __include("core/Bytes") +S["data/q3skin"] = function(r: Bytes.Reader): number + local head = r:peek(math.min(r:remaining(), 1024)) + if #head < 3 or string.find(head, "[%z\1-\8\14-\31]") then + return 0 + end + local lines, good, paths = 0, 0, 0 + for line in string.gmatch(head, "[^\r\n]+") do + if not string.match(line, "^%s*$") then + lines += 1 + local surface, shader = string.match(line, "^%s*([%w_%-]+)%s*,%s*([^,%s]*)%s*$") + if surface and shader == "" and string.sub(string.lower(surface), 1, 4) == "tag_" then + good += 1 + elseif shader and string.find(shader, "/", 1, true) then + good += 1 + paths += 1 + end + end + end + return if lines > 0 and good == lines and paths > 0 then 0.5 else 0 +end +end + +do -- data/snbt +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["data/snbt"] = function(r: Bytes.Reader): number + -- SNBT has what JSON never has: unquoted keys, typed numbers (1b, 2.5f), [I; arrays, single-quoted strings + local head = Sniff.text(r, 512, true) + local first = string.sub(head, 1, 1) + if first ~= "{" and first ~= "[" then + return 0 + end + if string.find(head, "[{,]%s*[%a_][%w_%-%.%+]*%s*:") or string.find(head, "%d[bBsSlLfFdD]%s*[,}%]]") + or string.find(head, "%[[BIL]%s*;") or string.find(head, "[:,%[]%s*'") + then + return 0.7 + end + return 0 +end +end + +do -- data/toml +local Bytes = __include("core/Bytes") +S["data/toml"] = function(r: Bytes.Reader): number + local head = r:peek(512) + if string.find(head, "%z") then + return 0 + end + for line in string.gmatch(head, "[^\n]+") do + local l = string.match(line, "^[ \t]*(.-)[ \t\r]*$") :: string + if l ~= "" and string.sub(l, 1, 1) ~= "#" then + if string.match(l, "^%[%[?[%w_%-%.\"' ]+%]%]?$") or string.match(l, "^[%w_%-%.\"']+[ \t]*=[ \t]*[\"'%[{%dtf%+%-in]") then + return 0.2 + end + return 0 + end + end + return 0 +end +end + +do -- data/tres +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["data/tres"] = function(r: Bytes.Reader): number + local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_resource[%s%]]") then + return 1 + end + return 0 +end +end + +do -- data/vdf +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local KeyValues = P_codecs_text_KeyValues +S["data/vdf"] = function(r: Bytes.Reader): number + local n = r:remaining() + if KeyValues.isBinary(r.buf, r.pos, n) then + return 0.3 + end + local head = Sniff.text(r, 256, true) + if string.find(head, "%z") then + return 0 + end + head = string.gsub(head, "^//[^\n]*\n%s*", "") + if string.match(head, '^"[^"\n]+"%s*{') or string.match(head, '^"[^"\n]+"%s*%[[^%]\n]*%]%s*{') then + return 0.6 + end + if string.match(head, "^#base%s") or string.match(head, "^#include%s") then + return 0.5 + end + if string.match(head, '^[%w_]+%s*\n%s*{%s*\n%s*"') then + return 0.3 + end + return 0 +end +end + +do -- data/xml +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["data/xml"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 64) + if string.match(head, "^<%?xml[ \t\r\n]") or string.sub(head, 1, 4) == "\255\254<\0" or string.sub(head, 1, 4) == "\254\255\0<" then + return 0.5 + end + if string.match(head, "^[ \t\r\n]*<[%a!]") then + return 0.3 + end + return 0 +end +end + +do -- data/yaml +local Bytes = __include("core/Bytes") +S["data/yaml"] = function(r: Bytes.Reader): number + local head = r:peek(256) + if string.find(head, "%z") then + return 0 + end + if string.match(head, "^%%YAML ") then + return 0.9 + end + if string.match(head, "^%-%-%-[ \r\n]") then + return 0.5 + end + local line = string.match(head, "^[ \t\r\n]*([^\r\n]*)") + if line and (string.match(line, "^[%w_%-\"']+[%w_%- \"']*:[ ]") or string.match(line, "^[%w_%-]+:$") or string.match(line, "^%- ")) then + return 0.2 + end + return 0 +end +end + +do -- vector/gamemaps +local Bytes = __include("core/Bytes") +local MAGIC = "TED5v1.0" +S["vector/gamemaps"] = function(r: Bytes.Reader): number + if r:peek(8) == MAGIC then + return 1 + end + -- MAPHEAD: the RLEW tag 0xABCD, then 100 offsets (0 / -1 when absent) + if r:remaining() >= 402 and r:remaining() <= 1024 and buffer.readu16(r.buf, r.base) == 0xABCD then + local first = buffer.readi32(r.buf, r.base + 2) + if first > 0 then + return 0.7 + end + end + return 0 +end +end + +do -- vector/ldtk +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["vector/ldtk"] = function(r: Bytes.Reader): number + local h = Sniff.text(r, 1024) + if not string.match(h, "^%s*{") then + return 0 + end + if string.find(h, "\"fileType\"%s*:%s*\"LDtk Project JSON\"") then + return 1 + end + if string.find(h, "\"jsonVersion\"", 1, true) and string.find(h, "\"worldLayout\"", 1, true) then + return 0.8 + end + return 0 +end +end + +do -- vector/ogmo +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +S["vector/ogmo"] = function(r: Bytes.Reader): number + local h = Sniff.text(r, 2048) + if not string.match(h, "^%s*{") or not string.find(h, "\"ogmoVersion\"", 1, true) then + return 0 + end + if string.find(h, "\"layerGridDefaultSize\"", 1, true) or string.find(h, "\"levelPaths\"", 1, true) then + return 1 + end + return 0.9 +end +end + +do -- vector/svg +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["vector/svg"] = function(r: Bytes.Reader): number + local h = Sniff.text(r, 4096) + if not string.match(h, "^%s*<") then + return 0 + end + if string.find(h, "<svg[%s>:]") or string.find(h, "<%w+:svg[%s>]") then + return 0.95 + end + return 0 +end +end + +do -- vector/tiled +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +local function head(r: Bytes.Reader): string + local h = Sniff.text(r, 1024) + return h +end +S["vector/tiled"] = function(r: Bytes.Reader): number + local h = head(r) + if string.match(h, "^%s*<") then + if string.find(h, "<map[%s>]") or string.find(h, "<tileset[%s>]") then + return 0.9 + end + return 0 + end + if string.match(h, "^%s*{") then + -- Tiled writes its keys sorted: "type" comes last, so look at the tail too + local n = r:remaining() + local tail = if n > 1024 then r:peek(1024, n - 1024) else "" + for _, part in { h, tail } do + if string.find(part, "\"type\"%s*:%s*\"map\"") or string.find(part, "\"type\"%s*:%s*\"tileset\"") then + return 0.8 + end + end + if string.find(h, "\"tilewidth\"", 1, true) and (string.find(h, "\"orientation\"", 1, true) or string.find(h, "\"tilesets\"", 1, true)) then + return 0.6 + end + end + return 0 +end +end + +do -- layered/aseprite +local Bytes = __include("core/Bytes") +S["layered/aseprite"] = function(r: Bytes.Reader): number + if r:peekU8(4) == 0xE0 and r:peekU8(5) == 0xA5 then + local d = r:peekU8(12) + if (d == 32 or d == 16 or d == 8) and r:peekU8(13) == 0 then + return 1 + end + return 0.5 + end + return 0 +end +end + +do -- layered/ora +local Bytes = __include("core/Bytes") +local MIME = "image/openraster" +S["layered/ora"] = function(r: Bytes.Reader): number + -- a zip whose first (stored) entry is "mimetype" holding image/openraster + if r:peek(4) == "PK\3\4" and r:peek(8, 30) == "mimetype" and r:peek(#MIME, 38) == MIME then + return 1 + end + return 0 +end +end + +do -- layered/psd +local Bytes = __include("core/Bytes") +S["layered/psd"] = function(r: Bytes.Reader): number + local h = r:peek(6) + if string.sub(h, 1, 4) == "8BPS" and (string.sub(h, 5, 6) == "\0\1" or string.sub(h, 5, 6) == "\0\2") then + return 1 + end + return 0 +end +end + +do -- subtitle/ass +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["subtitle/ass"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 64) + if string.match(head, "^%s*%[[Ss]cript [Ii]nfo%]") then + return 1 + end + return 0 +end +end + +do -- subtitle/srt +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +local TIMING = "^%s*(%d+):(%d%d?):(%d%d?)[,.](%d+)%s*%-%->%s*(%d+):(%d%d?):(%d%d?)[,.](%d+)%s*(.-)%s*$" +local function frac(digits: string): number + return (tonumber(digits) :: number) / 10 ^ #digits +end +local function timing(line: string): (number?, number?, string?) + local h1, m1, s1, f1, h2, m2, s2, f2, rest = string.match(line, TIMING) + if not h1 then + return nil, nil, nil + end + local a = tonumber(h1) :: number * 3600 + tonumber(m1) :: number * 60 + tonumber(s1) :: number + frac(f1 :: string) + local b = tonumber(h2) :: number * 3600 + tonumber(m2) :: number * 60 + tonumber(s2) :: number + frac(f2 :: string) + return a, b, rest +end +S["subtitle/srt"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 512) + head = string.gsub(head, "\r", "\n") + local first, second = string.match(head, "^%s*([^\n]*)\n([^\n]*)") + if first and string.match(first, "^%d+%s*$") and second and timing(second) then + return 0.9 + end + if first and timing(first) then + return 0.6 + end + return 0 +end +end + +do -- subtitle/vtt +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["subtitle/vtt"] = function(r: Bytes.Reader): number + local head = Sniff.text(r, 10) + if string.sub(head, 1, 6) == "WEBVTT" then + local c = string.sub(head, 7, 7) + if c == "" or c == " " or c == "\t" or c == "\n" or c == "\r" then + return 1 + end + end + return 0 +end +end + +do -- music/669 +local Bytes = __include("core/Bytes") +local function validHeader(r: Bytes.Reader): boolean + if r:size() < 497 then + return false + end + local magic = r:peek(2) + if magic ~= "if" and magic ~= "JN" then + return false + end + local nsmp, npat, restart = r:peekU8(110), r:peekU8(111), r:peekU8(112) + if nsmp > 64 or restart >= 128 or npat > 128 then + return false + end + local bad = 0 + for i = 2, 109 do + local c = r:peekU8(i) + if c > 0 and c <= 31 then + bad += 1 + if bad > 40 then + return false + end + end + end + for i = 0, 127 do + local o, t, b = r:peekU8(113 + i), r:peekU8(241 + i), r:peekU8(369 + i) + if (o >= 128 and o < 0xFE) or (o < 128 and t == 0) or t > 15 or b >= 64 then + return false + end + end + return true +end +S["music/669"] = function(r: Bytes.Reader): number + return if validHeader(r) then 0.6 else 0 +end +end + +do -- music/ahx +local Bytes = __include("core/Bytes") +S["music/ahx"] = function(r: Bytes.Reader): number + local m = r:peek(4) + return if m and #m == 4 and string.sub(m, 1, 3) == "THX" and string.byte(m, 4) < 3 then 1 else 0 +end +end + +do -- music/far +local Bytes = __include("core/Bytes") +S["music/far"] = function(r: Bytes.Reader): number + if r:size() >= 98 and r:peek(4) == "FAR\xFE" and r:peek(3, 44) == "\r\n\x1A" and r:peekU8(47) + r:peekU8(48) * 256 >= 98 then + return 1 + end + return 0 +end +end + +do -- music/hmp +local Bytes = __include("core/Bytes") +local HMI_MAGIC = "HMI-MIDISONG061595" +S["music/hmp"] = function(r: Bytes.Reader): number + return if r:peek(8) == "HMIMIDIP" or r:peek(18) == HMI_MAGIC then 1 else 0 +end +end + +do -- music/hvl +local Bytes = __include("core/Bytes") +S["music/hvl"] = function(r: Bytes.Reader): number + local m = r:peek(4) + return if m and #m == 4 and string.sub(m, 1, 3) == "HVL" and string.byte(m, 4) <= 1 then 1 else 0 +end +end + +do -- music/it +local Bytes = __include("core/Bytes") +S["music/it"] = function(r: Bytes.Reader): number + return if r:peek(4) == "IMPM" then 1 else 0 +end +end + +do -- music/med +local Bytes = __include("core/Bytes") +local function validHeader(r: Bytes.Reader): boolean + if r:size() < 52 or r:peek(3) ~= "MMD" then + return false + end + local v = r:peekU8(3) + if v < 0x30 or v > 0x33 then + return false + end + local h = r:sub(8, 44) + local songOff = h:u32be() + h:skip(4) + local blockOff = h:u32be() + h:skip(4) + local smpOff = h:u32be() + return songOff >= 52 and songOff + 63 * 8 + 284 <= r:size() and blockOff >= 52 and (smpOff == 0 or smpOff >= 52) +end +S["music/med"] = function(r: Bytes.Reader): number + return if validHeader(r) then 1 else 0 +end +end + +do -- music/midi +local Bytes = __include("core/Bytes") +S["music/midi"] = function(r: Bytes.Reader): number + if r:peek(4) == "MThd" then + return 1 + end + if r:peek(4) == "RIFF" and r:peek(4, 8) == "RMID" then + return 1 + end + return 0 +end +end + +do -- music/mod +local Bytes = __include("core/Bytes") +local FIXED: { [string]: number } = { + ["M.K."] = 4, + ["M!K!"] = 4, + ["M&K!"] = 4, + ["N.T."] = 4, + ["FLT4"] = 4, + ["FLT8"] = 8, + ["CD81"] = 8, + ["OKTA"] = 8, + ["OCTA"] = 8, + ["EXO4"] = 4, + ["EXO8"] = 8, +} +local function signatureChannels(sig: string): number? + local fixed = FIXED[sig] + if fixed then + return fixed + end + local d = string.match(sig, "^(%d)CHN$") + if d then + local n = tonumber(d) :: number + return if n >= 1 then n else nil + end + local dd = string.match(sig, "^(%d%d)C[HN]$") + if dd then + local n = tonumber(dd) :: number + return if n >= 1 and n <= 32 then n else nil + end + local t = string.match(sig, "^TDZ(%d)$") + if t then + local n = tonumber(t) :: number + return if n >= 1 then n else nil + end + return nil +end +S["music/mod"] = function(r: Bytes.Reader): number + if r:size() < 1084 then + return 0 + end + local sig = r:peek(4, 1080) + if signatureChannels(sig) then + return 0.8 + end + return 0 +end +end + +do -- music/mtm +local Bytes = __include("core/Bytes") +S["music/mtm"] = function(r: Bytes.Reader): number + if r:size() >= 66 and r:peek(3) == "MTM" and r:peekU8(3) < 0x20 and r:peekU8(33) >= 1 and r:peekU8(33) <= 32 then + return 1 + end + return 0 +end +end + +do -- music/mus +local Bytes = __include("core/Bytes") +S["music/mus"] = function(r: Bytes.Reader): number + return if r:peek(4) == "MUS\x1a" then 1 else 0 +end +end + +do -- music/okt +local Bytes = __include("core/Bytes") +S["music/okt"] = function(r: Bytes.Reader): number + return if r:peek(8) == "OKTASONG" then 1 else 0 +end +end + +do -- music/ptm +local Bytes = __include("core/Bytes") +local function validHeader(r: Bytes.Reader): boolean + if r:size() < 608 or r:peek(4, 44) ~= "PTMF" or r:peekU8(28) ~= 26 or r:peekU8(30) > 2 then + return false + end + local h = r:sub(32, 10) + local nord, nsmp, npat, nch, flags = h:u16le(), h:u16le(), h:u16le(), h:u16le(), h:u16le() + return flags == 0 and nch >= 1 and nch <= 32 and nord >= 1 and nord <= 256 and nsmp >= 1 and nsmp <= 255 and npat >= 1 and npat <= 128 +end +S["music/ptm"] = function(r: Bytes.Reader): number + return if validHeader(r) then 1 else 0 +end +end + +do -- music/s3m +local Bytes = __include("core/Bytes") +S["music/s3m"] = function(r: Bytes.Reader): number + if r:size() >= 48 and r:peek(4, 44) == "SCRM" then + return 1 + end + return 0 +end +end + +do -- music/sf2 +local Bytes = __include("core/Bytes") +local SoundFont = P_codecs_audio_SoundFont +S["music/sf2"] = function(r: Bytes.Reader): number + return if SoundFont.sniff(r) then 1 else 0 +end +end + +do -- music/stm +local Bytes = __include("core/Bytes") +local function validHeader(r: Bytes.Reader): boolean + if r:size() < 48 then + return false + end + local eof, ftype, major, minor = r:peekU8(28), r:peekU8(29), r:peekU8(30), r:peekU8(31) + local npat, gv = r:peekU8(33), r:peekU8(34) + if ftype ~= 2 or (eof ~= 0x1A and eof ~= 2) or major ~= 2 or (minor ~= 0 and minor ~= 10 and minor ~= 20 and minor ~= 21) then + return false + end + if npat > 64 or (gv > 64 and gv ~= 0x58) then + return false + end + for i = 20, 27 do + local c = r:peekU8(i) + if c < 0x20 or c >= 0x7F then + return false + end + end + return true +end +S["music/stm"] = function(r: Bytes.Reader): number + return if validHeader(r) then 0.7 else 0 +end +end + +do -- music/ult +local Bytes = __include("core/Bytes") +S["music/ult"] = function(r: Bytes.Reader): number + local v = r:peekU8(14) + if r:size() >= 48 and r:peek(14) == "MAS_UTrack_V00" and v >= 0x31 and v <= 0x34 then + return 1 + end + return 0 +end +end + +do -- music/umx +local Bytes = __include("core/Bytes") +local MAGIC = "\xC1\x83\x2A\x9E" +type Header = { version: number, nameCount: number, nameOffset: number, exportCount: number, exportOffset: number, importCount: number, importOffset: number } +local function header(r: Bytes.Reader): Header? + if r:size() < 36 or r:peek(4) ~= MAGIC then + return nil + end + local h = r:sub(4, 32) + local version = h:u16le() + h:skip(6) + local hd: Header = { + version = version, + nameCount = h:u32le(), + nameOffset = h:u32le(), + exportCount = h:u32le(), + exportOffset = h:u32le(), + importCount = h:u32le(), + importOffset = h:u32le(), + } + if h.err or hd.nameOffset < 36 or hd.exportOffset < 36 or hd.importOffset < 36 then + return nil + end + if hd.nameCount == 0 or hd.exportCount == 0 or hd.importCount == 0 or hd.nameCount > 2 ^ 20 or hd.exportCount > 2 ^ 20 or hd.importCount > 2 ^ 20 then + return nil + end + return hd +end +local function index(r: Bytes.Reader): number + local b = r:u8() + local neg = b >= 0x80 + local v = b % 64 + if bit32.band(b, 0x40) ~= 0 then + local shift = 6 + repeat + b = r:u8() + v += (b % 128) * 2 ^ shift + shift += 7 + until b < 0x80 or shift >= 32 + end + return if neg then -v else v +end +local function names(r: Bytes.Reader, h: Header): { string } + local list = {} + local nr = r:sub(h.nameOffset) + for _ = 1, math.min(h.nameCount, 65536) do + if nr:remaining() < 5 then + break + end + if h.version >= 64 then + index(nr) + end + table.insert(list, string.lower(nr:cstring(1024))) + nr:skip(4) + end + return list +end +S["music/umx"] = function(r: Bytes.Reader): number + local h = header(r) + if not h then + return 0 + end + return if table.find(names(r, h), "music") then 1 else 0.3 +end +end + +do -- music/xm +local Bytes = __include("core/Bytes") +local MAGIC = "Extended Module: " +S["music/xm"] = function(r: Bytes.Reader): number + return if r:peek(17) == MAGIC then 1 else 0 +end +end + +do -- music/xmi +local Bytes = __include("core/Bytes") +S["music/xmi"] = function(r: Bytes.Reader): number + local id, kind = r:peek(4), r:peek(4, 8) + if id == "FORM" and (kind == "XDIR" or kind == "XMID") then + return 1 + end + return if id == "CAT " and kind == "XMID" then 0.9 else 0 +end +end + +do -- playlist/m3u +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +S["playlist/m3u"] = function(r: Bytes.Reader): number + local s = Sniff.text(r, 512) + s = (string.match(s, "^%s*(.*)$") :: string) + if string.sub(s, 1, 7) == "#EXTM3U" then + return 0.95 + end + if string.find(s, "^#EXTINF:") or string.find(s, "^#EXT%-X%-") then + return 0.8 + end + return 0 +end +end + +do -- playlist/pls +local Sniff = __include("core/Sniff") +local Bytes = __include("core/Bytes") +local Text = P_codecs_text_Text +S["playlist/pls"] = function(r: Bytes.Reader): number + local s = Sniff.text(r, 64) + local first = string.match(s, "^%s*([^\r\n]*)") + return if first and string.lower(Text.trim(first)) == "[playlist]" then 0.95 else 0 +end +end + +do -- playlist/xspf +local Bytes = __include("core/Bytes") +local NS = "http://xspf.org/ns/0/" +S["playlist/xspf"] = function(r: Bytes.Reader): number + local s = r:peek(1024) + local i = string.find(s, "<%w*:?playlist[%s>]") + if i and string.find(s, NS, 1, true) then + return 0.95 + end + return 0 +end +end + +return S +end +__FILES["core/Crc16"] = @native function() + + +-- core/Crc16: the 16-bit CRCs old archive formats use, table driven. New code. ccitt: CRC-16/XMODEM (0x1021, MSB first, +-- init 0, no final XOR; BinHex 4.0, MacBinary II / III). arc: CRC-16/ARC (0x8005 reflected = 0xA001, init 0; LHA, Zoo, +-- ARC). Never throws: the range is clamped. +local band, bxor, rshift, lshift = bit32.band, bit32.bxor, bit32.rshift, bit32.lshift +local readu8 = buffer.readu8 + +local MSB = table.create(256, 0) +local ARC = table.create(256, 0) +for n = 0, 255 do + local c = lshift(n, 8) + for _ = 1, 8 do + c = if band(c, 0x8000) ~= 0 then bxor(band(lshift(c, 1), 0xFFFF), 0x1021) else band(lshift(c, 1), 0xFFFF) + end + MSB[n + 1] = c + local r = n + for _ = 1, 8 do + r = if band(r, 1) ~= 0 then bxor(rshift(r, 1), 0xA001) else rshift(r, 1) + end + ARC[n + 1] = r +end + +local Crc16 = {} + +@native local function clamp(buf: buffer, off: number, len: number): (number, number) + local n = buffer.len(buf) + local o = math.clamp(math.floor(off), 0, n) + return o, math.clamp(math.floor(len), 0, n - o) +end + +@native function Crc16.ccitt(buf: buffer, off: number, len: number, crc: number?): number + local o, l = clamp(buf, off, len) + local c = crc or 0 + for i = o, o + l - 1 do + c = bxor(band(lshift(c, 8), 0xFFFF), MSB[bxor(rshift(c, 8), readu8(buf, i)) + 1]) + end + return c +end + +@native function Crc16.arc(buf: buffer, off: number, len: number, crc: number?): number + local o, l = clamp(buf, off, len) + local c = crc or 0 + for i = o, o + l - 1 do + c = bxor(rshift(c, 8), ARC[bxor(band(c, 0xFF), readu8(buf, i)) + 1]) + end + return c +end + +return Crc16 +end +__FILES["core/Sniff"] = function() + +-- core/Sniff: helpers for the formats' sniff functions (which return 0..1 from the first bytes, never consuming and +-- never throwing): magic comparison and the start of a text file without its UTF-8 byte order mark. +local Sniff = {} + +type Peeker = { peek: (any, number, number?) -> string } + +function Sniff.magic(r: Peeker, s: string, at: number?, score: number?): number + return if r:peek(#s, at) == s then score or 1 else 0 +end + +function Sniff.dropBom(s: string): string + return if string.sub(s, 1, 3) == "\239\187\191" then string.sub(s, 4) else s +end + +function Sniff.text(r: Peeker, n: number, trim: boolean?): string + local s = r:peek(n) + if string.sub(s, 1, 3) == "\239\187\191" then + s = string.sub(s, 4) + end + if trim then + s = string.match(s, "^%s*(.*)$") :: string + end + return s +end + +return Sniff end end @@ -38893,7 +38893,6 @@ local Err = __include("core/Err") local Bytes = __include("core/Bytes") local Crc32 = __include("core/Crc32") local Base64 = __include("core/Base64") -local Deflate = __include("codecs/compress/Deflate") local Decode = __include("codecs/compress/Brotli/Decode") local StaticData = __include("codecs/compress/Brotli/Static") @@ -38910,32 +38909,46 @@ local function unbase64(s: string): buffer end local static: Decode.Static? = nil +local dictionary: buffer? = nil +local dictionaryErr: Err.Err? = nil -local function tables(): (Decode.Static?, Err.Err?) - if static then - return static, nil +-- inflated on the first dictionary reference (RFC 7932 section 8) +local function loadDictionary(): buffer? + if dictionary or dictionaryErr then + return dictionary end + local Deflate = __include("codecs/compress/Deflate") local z = unbase64(table.concat(StaticData.dictionary)) local dict, err = Deflate.zlib(z, 0, nil, StaticData.dictionarySize) if not dict then - return nil, err + dictionaryErr = err + return nil end if Crc32.of(dict) ~= StaticData.dictionaryCrc then - return nil, Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + dictionaryErr = Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + return nil end - static = { - dictionary = dict, + dictionary = dict + return dict +end + +local function tables(): Decode.Static + if static then + return static + end + local s: Decode.Static = { + dictionary = loadDictionary, context = unbase64(table.concat(StaticData.context)), prefixSuffix = unbase64(StaticData.prefixSuffix), prefixSuffixMap = StaticData.prefixSuffixMap, transforms = StaticData.transforms, } - return static, nil + static = s + return s end function Brotli.dictionary(): buffer? - local s = tables() - return if s then s.dictionary else nil + return loadDictionary() end function Brotli.decompress(buf: buffer | string, offset: number?, length: number?, opts: Options?): (buffer?, any) @@ -38951,12 +38964,11 @@ function Brotli.decompress(buf: buffer | string, offset: number?, length: number if l == 0 then return nil, Err.new(Err.TRUNCATED, "brotli: empty input", o) end - local S, serr = tables() - if not S then - return nil, serr - end - local out, size, consumed = Decode.decompress(b, o, l, maxBytes, S, large) + local out, size, consumed = Decode.decompress(b, o, l, maxBytes, tables(), large) if not out then + if size == Decode.NO_DICTIONARY and dictionaryErr then + return nil, dictionaryErr + end local e = Err.from(size, o) e.message = "brotli: " .. e.message return nil, e @@ -38984,8 +38996,11 @@ local bcreate, bcopy, blen, bfill = buffer.create, buffer.copy, buffer.len, buff local Decode = {} +local NO_DICTIONARY = "static dictionary unavailable" +Decode.NO_DICTIONARY = NO_DICTIONARY + type Static = { - dictionary: buffer, -- 122784 bytes + dictionary: () -> buffer?, -- 122784 bytes, on first use (nil: Decode.NO_DICTIONARY) context: buffer, -- 2048 bytes: 4 modes x (256 for p1, 256 for p2) prefixSuffix: buffer, -- length-prefixed strings prefixSuffixMap: { number }, @@ -39490,7 +39505,7 @@ end end local maxBackward = 2 ^ wbits - 16 - local dict = S.dictionary + local dict: buffer? = nil local LUT = S.context local PS = S.prefixSuffix local PSMAP = S.prefixSuffixMap @@ -39859,7 +39874,12 @@ end end local ws = w if wl > 0 then - bcopy(WORD, w, dict, wo, wl) + local d = dict or S.dictionary() + if d == nil then + return nil, NO_DICTIONARY + end + dict = d + bcopy(WORD, w, d, wo, wl) w += wl end if ttype == 10 then @@ -75785,3410 +75805,11 @@ end - Root + archive_7z --!optimize 2 --!nocheck --- rosetta chunk Root (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) -__FILES["Sniffs"] = function() - - --- Sniffs: GENERATED by tools/gen_registry.py from the format folders - do not edit. --- Each format's sniff (format path -> sniff(r)), copied from its init.luau with the top-level locals and types it --- reaches (tools/sniff_extract.py), so detection requires no format module. Requires outside core/ are proxies that --- require on first use. Formats whose sniff needs their module (Registry sniff = 2) are not here. -local S: { [string]: (any) -> number } = {} - -local function lazy(load: () -> any): any - local proxy = {} - return setmetatable(proxy, { - __index = function(_, k: any): any - local m = load() - setmetatable(proxy, { __index = m }) - return m[k] - end, - }) -end - -do -- image/ani -local Bytes = __include("core/Bytes") -S["image/ani"] = function(r: Bytes.Reader): number - return if r:peek(4) == "RIFF" and r:peek(4, 8) == "ACON" then 1 else 0 -end -end - -do -- image/art -local Bytes = __include("core/Bytes") -local readu8, readu16, readu32, readi16 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.readi16 -local function header(b: buffer, o: number, limit: number): (number?, number?, number?, number?, boolean?) - local p = o - local prefixed = false - if limit - p >= 8 and buffer.readstring(b, p, 8) == "BUILDART" then - p += 8 - prefixed = true - end - if limit - p < 16 or readu32(b, p) ~= 1 then - return nil, nil, nil, nil, nil - end - local first, last = readu32(b, p + 8), readu32(b, p + 12) - if last < first or last - first >= 65536 then - return nil, nil, nil, nil, nil - end - return p + 16, first, last, readu32(b, p + 4), prefixed -end -S["image/art"] = function(r: Bytes.Reader): number - local at, first, last = header(r.buf, r.base, r.limit) - if not at or not first or not last then - return 0 - end - local n = last - first + 1 - local p = at :: number - if r.limit - p < n * 8 then - return 0 - end - local total = 0 - for i = 0, n - 1 do - local w, h = readi16(r.buf, p + i * 2), readi16(r.buf, p + n * 2 + i * 2) - if w < 0 or h < 0 then - return 0 - end - total += w * h - end - local size = p + n * 8 + total - r.base - local have = r.limit - r.base - return if size == have then 0.9 elseif size < have and have - size < 4096 then 0.5 else 0 -end -end - -do -- image/blp -local Bytes = __include("core/Bytes") -S["image/blp"] = function(r: Bytes.Reader): number - local m = r:peek(4) - return if m == "BLP1" or m == "BLP2" then 1 elseif m == "BLP0" then 0.8 else 0 -end -end - -do -- image/bmp -local Bytes = __include("core/Bytes") -S["image/bmp"] = function(r: Bytes.Reader): number - if r:peek(2) ~= "BM" then - return 0 - end - local n = r:peekU8(14) + math.max(r:peekU8(15), 0) * 256 - if r:peekU8(16) == 0 and r:peekU8(17) == 0 and (n == 12 or n == 16 or n == 40 or n == 52 or n == 56 or n == 64 or n == 108 or n == 124) then - return 0.9 - end - return 0.2 -end -end - -do -- image/dds -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -local MAGIC = "DDS " -S["image/dds"] = function(r: Bytes.Reader): number - return math.max(Sniff.magic(r, MAGIC .. "\124\0\0\0"), Sniff.magic(r, MAGIC, 0, 0.6)) -end -end - -do -- image/exr -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -local MAGIC = "\118\47\49\1" -S["image/exr"] = function(r: Bytes.Reader): number - return Sniff.magic(r, MAGIC) -end -end - -do -- image/gif -local Bytes = __include("core/Bytes") -S["image/gif"] = function(r: Bytes.Reader): number - local s = r:peek(6) - return if s == "GIF89a" or s == "GIF87a" then 1 else 0 -end -end - -do -- image/hdr -local Bytes = __include("core/Bytes") -S["image/hdr"] = function(r: Bytes.Reader): number - local s = r:peek(10) - if s == "#?RADIANCE" then - return 1 - end - if string.sub(s, 1, 6) == "#?RGBE" then - return 1 - end - if string.sub(s, 1, 2) == "#?" and string.match(s, "^#%?%u") then - return 0.5 - end - return 0 -end -end - -do -- image/icns -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["image/icns"] = function(r: Bytes.Reader): number - return Sniff.magic(r, "icns") -end -end - -do -- image/ico -local Bytes = __include("core/Bytes") -local readu8 = buffer.readu8 -S["image/ico"] = function(r: Bytes.Reader): number - if r:remaining() < 22 then - return 0 - end - local b, o = r.buf, r.pos - local typ = buffer.readu16(b, o + 2) - local count = buffer.readu16(b, o + 4) - if buffer.readu16(b, o) ~= 0 or (typ ~= 1 and typ ~= 2) or count == 0 then - return 0 - end - -- the first entry: reserved byte 0, a size and offset inside the file - local size, off = buffer.readu32(b, o + 14), buffer.readu32(b, o + 18) - if readu8(b, o + 9) ~= 0 or size == 0 or off < 6 + count * 16 then - return 0 - end - return 0.8 -end -end - -do -- image/ilbm -local Bytes = __include("core/Bytes") -S["image/ilbm"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "FORM" then - return 0 - end - local t = r:peek(4, 8) - return if t == "ILBM" or t == "PBM " then 1 else 0 -end -end - -do -- image/jpeg -local Bytes = __include("core/Bytes") -S["image/jpeg"] = function(r: Bytes.Reader): number - local s = r:peek(3) - return if s == "\255\216\255" then 1 else 0 -end -end - -do -- image/ktx -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -local ID1 = "\171KTX 11\187\r\n\26\n" -local ID2 = "\171KTX 20\187\r\n\26\n" -S["image/ktx"] = function(r: Bytes.Reader): number - return math.max(Sniff.magic(r, ID2), Sniff.magic(r, ID1)) -end -end - -do -- image/lmp -local Bytes = __include("core/Bytes") -local function kindOf(r: Bytes.Reader): string? - local n = r:remaining() - if n == 768 then - return "palette" - elseif n == 16385 or n == 16384 then - return "colormap" - end - if n < 9 then - return nil - end - local w, h = buffer.readu32(r.buf, r.pos), buffer.readu32(r.buf, r.pos + 4) - if w > 0 and h > 0 and w <= 4096 and h <= 4096 and 8 + w * h == n then - return "qpic" - end - return nil -end -S["image/lmp"] = function(r: Bytes.Reader): number - local k = kindOf(r) - return if k == "qpic" then 0.3 elseif k then 0.05 else 0 -end -end - -do -- image/pcx -local Bytes = __include("core/Bytes") -S["image/pcx"] = function(r: Bytes.Reader): number - if r:size() < 128 then - return 0 - end - local m, v, e, bpp = r:peekU8(0), r:peekU8(1), r:peekU8(2), r:peekU8(3) - if m ~= 10 or (v ~= 0 and v ~= 2 and v ~= 3 and v ~= 4 and v ~= 5) or e > 1 then - return 0 - end - return if bpp == 1 or bpp == 2 or bpp == 4 or bpp == 8 then 0.8 else 0 -end -end - -do -- image/png -local Bytes = __include("core/Bytes") -local SIGNATURE = "\137PNG\r\n\26\n" -S["image/png"] = function(r: Bytes.Reader): number - return if r:peek(8) == SIGNATURE then 1 else 0 -end -end - -do -- image/pnm -local Bytes = __include("core/Bytes") -S["image/pnm"] = function(r: Bytes.Reader): number - if r:remaining() < 3 then - return 0 - end - local a, b, c = r:peekU8(0), r:peekU8(1), r:peekU8(2) - if a ~= 80 then -- 'P' - return 0 - end - local ws = c == 32 or (c >= 9 and c <= 13) - if b >= 49 and b <= 55 and ws then -- P1..P7 - return 0.9 - end - if (b == 70 or b == 102) and ws then -- PF / Pf - return 0.9 - end - return 0 -end -end - -do -- image/qoi -local Bytes = __include("core/Bytes") -S["image/qoi"] = function(r: Bytes.Reader): number - return if r:peek(4) == "qoif" then 1 else 0 -end -end - -do -- image/sgi -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["image/sgi"] = function(r: Bytes.Reader): number - if Sniff.magic(r, "\1\218") == 0 or r:size() < 512 then - return 0 - end - local st, bpc = r:peekU8(2), r:peekU8(3) - return if st <= 1 and (bpc == 1 or bpc == 2) then 1 else 0 -end -end - -do -- image/spr -local Bytes = __include("core/Bytes") -S["image/spr"] = function(r: Bytes.Reader): number - if r:remaining() < 36 or r:peek(4) ~= "IDSP" then - return 0 - end - local v = buffer.readi32(r.buf, r.pos + 4) - return if v == 1 or v == 2 or v == 32 then 1 else 0.3 -end -end - -do -- image/sunras -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -local MAGIC = "\89\166\106\149" -S["image/sunras"] = function(r: Bytes.Reader): number - return Sniff.magic(r, MAGIC) -end -end - -do -- image/tga -local Bytes = __include("core/Bytes") -local TYPES = { [1] = true, [2] = true, [3] = true, [9] = true, [10] = true, [11] = true } -local FOOTER = "TRUEVISION-XFILE.\0" -local readu8 = buffer.readu8 -type Header = { - idLen: number, - cmapType: number, - imageType: number, - cmapFirst: number, - cmapLen: number, - cmapBits: number, - width: number, - height: number, - depth: number, - desc: number, -} -local function header(r: Bytes.Reader): Header? - if r.limit - r.base < 18 then - return nil - end - local b, o = r.buf, r.base - local function u16(q: number): number - return readu8(b, o + q) + readu8(b, o + q + 1) * 256 - end - local h: Header = { - idLen = readu8(b, o), - cmapType = readu8(b, o + 1), - imageType = readu8(b, o + 2), - cmapFirst = u16(3), - cmapLen = u16(5), - cmapBits = readu8(b, o + 7), - width = u16(12), - height = u16(14), - depth = readu8(b, o + 16), - desc = readu8(b, o + 17), - } - return h -end -local function implausible(h: Header): string? - local t = h.imageType - if not TYPES[t] then - return "image type " .. t - end - if h.cmapType > 1 then - return "colour map type " .. h.cmapType - end - local mapped = t == 1 or t == 9 - if mapped and (h.cmapType ~= 1 or (h.depth ~= 8 and h.depth ~= 16)) then - return "colour-mapped image without a colour map" - end - if h.cmapType == 1 and h.cmapLen > 0 and h.cmapBits ~= 15 and h.cmapBits ~= 16 and h.cmapBits ~= 24 and h.cmapBits ~= 32 then - return "colour map entry size " .. h.cmapBits - end - if (t == 2 or t == 10) and h.depth ~= 15 and h.depth ~= 16 and h.depth ~= 24 and h.depth ~= 32 then - return "pixel depth " .. h.depth - end - if (t == 3 or t == 11) and h.depth ~= 8 and h.depth ~= 16 then - return "grey pixel depth " .. h.depth - end - if h.width == 0 or h.height == 0 then - return "zero size" - end - if h.desc >= 64 then - return "interleaving / reserved descriptor bits" - end - return nil -end -S["image/tga"] = function(r: Bytes.Reader): number - local h = header(r) - if not h or implausible(h) then - return 0 - end - local n = r.limit - r.base - if n >= 44 and buffer.readstring(r.buf, r.limit - 18, 18) == FOOTER then - return 0.9 - end - return 0.2 -end -end - -do -- image/tiff -local Bytes = __include("core/Bytes") -S["image/tiff"] = function(r: Bytes.Reader): number - local s = r:peek(4) - if s == "II*\0" or s == "MM\0*" or s == "II+\0" or s == "MM\0+" then - return 1 - end - return 0 -end -end - -do -- image/tim -local Bytes = __include("core/Bytes") -S["image/tim"] = function(r: Bytes.Reader): number - if r:remaining() < 20 or r:peek(4) ~= "\16\0\0\0" then - return 0 - end - local flags = r:peekU8(4) - if flags > 0x0F or (flags % 8) > 3 or r:peek(3, 5) ~= "\0\0\0" then - return 0 - end - return 0.8 -end -end - -do -- image/vtf -local Bytes = __include("core/Bytes") -S["image/vtf"] = function(r: Bytes.Reader): number - return if r:peek(4) == "VTF\0" and r:peekU8(4) == 7 then 1 else 0 -end -end - -do -- image/webp -local Bytes = __include("core/Bytes") -S["image/webp"] = function(r: Bytes.Reader): number - if r:peek(4) == "RIFF" and r:peek(4, 8) == "WEBP" then - return 1 - end - return 0 -end -end - -do -- image/xbm -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["image/xbm"] = function(r: Bytes.Reader): number - local s = Sniff.text(r, 256, true) - if string.match(s, "^#define%s+[%w_]*_?width%s+%d+") or string.match(s, "^/%*.-%*/%s*#define%s+[%w_]*width%s+%d+") then - return 0.9 - end - return 0 -end -end - -do -- image/xpm -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["image/xpm"] = function(r: Bytes.Reader): number - local s = Sniff.text(r, 64, true) - if string.sub(s, 1, 9) == "/* XPM */" or string.sub(s, 1, 6) == "! XPM2" then - return 1 - end - return 0 -end -end - -do -- audio/aac -local Bytes = __include("core/Bytes") -local Aac = lazy(function() - return __include("codecs/audio/Aac") -end) -local readu8 = buffer.readu8 -local function id3Size(b: buffer, p: number, limit: number): number - if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then - return 0 - end - local s = 0 - for i = 6, 9 do - s = s * 128 + bit32.band(readu8(b, p + i), 127) - end - local footer = if bit32.band(readu8(b, p + 5), 0x10) ~= 0 then 10 else 0 - return 10 + s + footer -end -S["audio/aac"] = function(r: Bytes.Reader): number - local b, p, limit = r.buf, r.pos, r.limit - p += id3Size(b, p, limit) - local h = Aac.adts(b, p, limit) - if not h then - return 0 - end - local h2 = Aac.adts(b, p + h.frameSize, limit) - if h2 and h2.sfIndex == h.sfIndex and h2.channelConfig == h.channelConfig then - return 0.9 - end - return if p + h.frameSize >= limit then 0.7 else 0.4 -end -end - -do -- audio/ac3 -local Bytes = __include("core/Bytes") -local Ac3 = lazy(function() - return __include("codecs/audio/Ac3") -end) -S["audio/ac3"] = function(r: Bytes.Reader): number - local b, p, limit = r.buf, r.pos, r.limit - local h = Ac3.header(b, p, limit) - if not h then - return 0 - end - local h2 = Ac3.header(b, p + h.frameSize, limit) - if h2 and h2.sampleRate == h.sampleRate then - return 0.9 - end - return if p + h.frameSize >= limit then 0.6 else 0.3 -end -end - -do -- audio/adpcm -local Bytes = __include("core/Bytes") -S["audio/adpcm"] = function(_r: Bytes.Reader): number - return 0 -end -end - -do -- audio/adx -local Bytes = __include("core/Bytes") -S["audio/adx"] = function(r: Bytes.Reader): number - if r:peekU8(0) ~= 0x80 or r:peekU8(1) ~= 0 then - return 0 - end - local off = r:peekU8(2) * 256 + r:peekU8(3) - return if r:peek(6, off - 2) == "(c)CRI" then 1 else 0 -end -end - -do -- audio/aiff -local Bytes = __include("core/Bytes") -S["audio/aiff"] = function(r: Bytes.Reader): number - if r:remaining() < 12 or r:peek(4) ~= "FORM" then - return 0 - end - local form = buffer.readstring(r.buf, r.pos + 8, 4) - return if form == "AIFF" or form == "AIFC" then 1 else 0 -end -end - -do -- audio/ape -local Bytes = __include("core/Bytes") -S["audio/ape"] = function(r: Bytes.Reader): number - local head = r:peek(4) - if head == "MAC " or head == "MACF" then -- MACF: float samples - return 1 - end - if string.sub(head, 1, 3) == "ID3" then - local sz = 0 - for i = 6, 9 do - local v = r:peekU8(i) - if v < 0 then - return 0 - end - sz = sz * 128 + bit32.band(v, 127) - end - local footer = bit32.band(math.max(r:peekU8(5), 0), 0x10) ~= 0 - local id = r:peek(4, 10 + sz + (if footer then 10 else 0)) - return if id == "MAC " or id == "MACF" then 1 else 0 - end - return 0 -end -end - -do -- audio/au -local Bytes = __include("core/Bytes") -S["audio/au"] = function(r: Bytes.Reader): number - return if r:peek(4) == ".snd" then 1 else 0 -end -end - -do -- audio/brstm -local Bytes = __include("core/Bytes") -S["audio/brstm"] = function(r: Bytes.Reader): number - local m = r:peek(4) - if m ~= "RSTM" and m ~= "CSTM" and m ~= "FSTM" then - return 0 - end - local bom = r:peek(2, 4) - return if bom == "\254\255" or bom == "\255\254" then 1 else 0 -end -end - -do -- audio/caf -local Bytes = __include("core/Bytes") -S["audio/caf"] = function(r: Bytes.Reader): number - local h = r:peek(8) - if #h == 8 and string.sub(h, 1, 4) == "caff" and string.byte(h, 5) == 0 and string.byte(h, 6) == 1 then - return 1 - end - return 0 -end -end - -do -- audio/flac -local Bytes = __include("core/Bytes") -S["audio/flac"] = function(r: Bytes.Reader): number - local head = r:peek(4) - if head == "fLaC" then - return 1 - end - if head == "OggS" then - -- the first page's packet: 0x7F "FLAC" (the Ogg FLAC mapping) - local nseg = r:peekU8(26) - if nseg > 0 and r:peek(5, 27 + nseg) == "\127FLAC" then - return 1 - end - return 0 - end - if string.sub(head, 1, 3) == "ID3" then - -- an ID3v2 tag, then fLaC (mp3 files start with ID3 too) - local sz = 0 - for i = 6, 9 do - local v = r:peekU8(i) - if v < 0 then - return 0 - end - sz = sz * 128 + bit32.band(v, 127) - end - local footer = bit32.band(math.max(r:peekU8(5), 0), 0x10) ~= 0 - return if r:peek(4, 10 + sz + (if footer then 10 else 0)) == "fLaC" then 1 else 0 - end - return 0 -end -end - -do -- audio/m4a -local Bytes = __include("core/Bytes") -local IsoBmff = lazy(function() - return __include("containers/IsoBmff") -end) -local AUDIO_BRANDS: { [string]: number } = { ["M4A "] = 1, ["M4B "] = 1, ["M4P "] = 1, ["M4V "] = 0.3 } -S["audio/m4a"] = function(r: Bytes.Reader): number - local brand = IsoBmff.sniff(r) - if brand == nil then - return 0 - end - if AUDIO_BRANDS[brand] then - return AUDIO_BRANDS[brand] - end - if brand == "avif" or brand == "avis" or brand == "heic" or brand == "heix" or brand == "mif1" or brand == "msf1" or brand == "crx " then - return 0 - end - return 0.4 -- an MP4 / MOV that may hold audio; a video format claims it more strongly -end -end - -do -- audio/mp3 -local Bytes = __include("core/Bytes") -local Header = lazy(function() - return __include("codecs/audio/Mpa/Header") -end) -local Tags = lazy(function() - return __include("audio/mp3/Tags") -end) -S["audio/mp3"] = function(r: Bytes.Reader): number - local b, p, lim = r.buf, r.pos, r.limit - local id3 = false - for _ = 1, 4 do -- (ffmpeg writes a tag even when the input had one: tags can follow each other) - local n = if p + 3 <= lim and buffer.readstring(b, p, 3) == "ID3" then Tags.id3v2Size(b, p, lim) else 0 - if n <= 0 then - break - end - id3 = true - p += n - end - if p + 4 > lim or not Header.valid(b, p) then - return if id3 then 0.5 else 0 - end - local fb = Header.frameBytes(b, p, 0) - if fb > 0 then - fb += Header.padding(b, p) - if p + fb + 4 <= lim and Header.compare(b, p, p + fb) then - return 0.9 - end - if p + fb == lim then - return 0.6 - end - end - return if id3 then 0.7 else 0.25 -end -end - -do -- audio/mpc -local Bytes = __include("core/Bytes") -local Musepack = lazy(function() - return __include("codecs/audio/Musepack") -end) -local function id3v2(b: buffer, p: number, limit: number): number - if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then - return 0 - end - local n = 10 - for i = 6, 9 do - n += bit32.band(buffer.readu8(b, p + i), 127) * 128 ^ (9 - i) - end - return n + (if bit32.band(buffer.readu8(b, p + 5), 0x10) ~= 0 then 10 else 0) -end -S["audio/mpc"] = function(r: Bytes.Reader): number - local b, p, limit = r.buf, r.pos, r.limit - p += id3v2(b, p, limit) - local v = Musepack.magic(b, p, limit) - if v == 8 then - return 1 - end - return if v == 7 then 0.9 else 0 -end -end - -do -- audio/opus -local Bytes = __include("core/Bytes") -S["audio/opus"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "OggS" then - return 0 - end - local nseg = r:peekU8(26) - if nseg < 1 then - return 0 - end - return if r:peek(8, 27 + nseg) == "OpusHead" then 1 else 0 -end -end - -do -- audio/qoa -local Bytes = __include("core/Bytes") -S["audio/qoa"] = function(r: Bytes.Reader): number - return if r:peek(4) == "qoaf" then 1 else 0 -end -end - -do -- audio/tta -local Bytes = __include("core/Bytes") -local function id3Size(r: Bytes.Reader): number - if r:peek(3) ~= "ID3" then - return 0 - end - local sz = 0 - for i = 6, 9 do - local v = r:peekU8(i) - if v < 0 then - return 0 - end - sz = sz * 128 + bit32.band(v, 127) - end - local footer = bit32.band(math.max(r:peekU8(5), 0), 0x10) ~= 0 - return 10 + sz + (if footer then 10 else 0) -end -S["audio/tta"] = function(r: Bytes.Reader): number - return if r:peek(4, id3Size(r)) == "TTA1" then 1 else 0 -end -end - -do -- audio/vag -local Bytes = __include("core/Bytes") -S["audio/vag"] = function(r: Bytes.Reader): number - local m = r:peek(4) - return if m == "VAGp" or m == "VAGi" or m == "KVAG" then 1 else 0 -end -end - -do -- audio/voc -local Bytes = __include("core/Bytes") -local MAGIC = "Creative Voice File\26" -S["audio/voc"] = function(r: Bytes.Reader): number - return if r:peek(20) == MAGIC then 1 else 0 -end -end - -do -- audio/vorbis -local Bytes = __include("core/Bytes") -S["audio/vorbis"] = function(r: Bytes.Reader): number - if r:remaining() < 35 or r:peek(4) ~= "OggS" then - return 0 - end - local b, p = r.buf, r.pos - local nseg = buffer.readu8(b, p + 26) - local d = p + 27 + nseg - if d + 7 > r.limit then - return 0 - end - return if buffer.readu8(b, d) == 1 and buffer.readstring(b, d + 1, 6) == "vorbis" then 1 else 0 -end -end - -do -- audio/wav -local Bytes = __include("core/Bytes") -local Riff = lazy(function() - return __include("containers/Riff") -end) -S["audio/wav"] = function(r: Bytes.Reader): number - return if Riff.sniff(r) == "WAVE" then 1 else 0 -end -end - -do -- audio/wavpack -local Bytes = __include("core/Bytes") -S["audio/wavpack"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "wvpk" then - return 0 - end - local v = r:peekU8(9) - return if v == 4 then 1 else 0.5 -end -end - -do -- video/avi -local Bytes = __include("core/Bytes") -S["video/avi"] = function(r: Bytes.Reader): number - if r:peek(4) == "RIFF" and r:peek(4, 8) == "AVI " then - return 1 - end - return 0 -end -end - -do -- video/fli -local Bytes = __include("core/Bytes") -local FLI, FLC, DTA = 0xAF11, 0xAF12, 0xAF44 -S["video/fli"] = function(r: Bytes.Reader): number - local s = r:peek(18) - if #s < 18 then - return 0 - end - local magic = string.byte(s, 5) + string.byte(s, 6) * 256 - if magic ~= FLI and magic ~= FLC and magic ~= DTA then - return 0 - end - local w = string.byte(s, 9) + string.byte(s, 10) * 256 - local h = string.byte(s, 11) + string.byte(s, 12) * 256 - if w > 4096 or h > 4096 then - return 0 - end - return 0.9 -end -end - -do -- video/flv -local Bytes = __include("core/Bytes") -S["video/flv"] = function(r: Bytes.Reader): number - if r:remaining() >= 9 and r:peek(3) == "FLV" then - return if r:peekU8(3) == 1 then 1 else 0.6 - end - return 0 -end -end - -do -- video/h264 -local Bytes = __include("core/Bytes") -S["video/h264"] = function(r: Bytes.Reader): number - local s = r:peek(5) - if not s or #s < 4 then - return 0 - end - local hdr - if string.byte(s, 1) == 0 and string.byte(s, 2) == 0 and string.byte(s, 3) == 1 then - hdr = string.byte(s, 4) - elseif #s >= 5 and string.byte(s, 1) == 0 and string.byte(s, 2) == 0 and string.byte(s, 3) == 0 and string.byte(s, 4) == 1 then - hdr = string.byte(s, 5) - else - return 0 - end - if hdr >= 128 then - return 0 - end - local t = hdr % 32 - if t == 7 then - return 0.8 - elseif t == 9 or t == 6 or t == 8 then - return 0.5 - elseif t == 5 then - return 0.4 - end - return 0 -end -end - -do -- video/mkv -local Bytes = __include("core/Bytes") -S["video/mkv"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "\26\69\223\163" then - return 0 - end - local head = r:peek(math.min(64, r:remaining())) - if string.find(head, "webm", 1, true) or string.find(head, "matroska", 1, true) then - return 1 - end - return 0.5 -end -end - -do -- video/mp4 -local Bytes = __include("core/Bytes") -local IsoBmff = lazy(function() - return __include("containers/IsoBmff") -end) -local IMAGE_BRANDS = { avif = true, avis = true, heic = true, heix = true, mif1 = true, msf1 = true, ["crx "] = true } -local AUDIO_BRANDS = { ["M4A "] = true, ["M4B "] = true, ["M4P "] = true } -S["video/mp4"] = function(r: Bytes.Reader): number - local brand = IsoBmff.sniff(r) - if brand == nil or IMAGE_BRANDS[brand] then - return 0 - end - if AUDIO_BRANDS[brand] then - return 0.2 - end - if brand == "M4V " then - return 0.9 - end - return if brand == "" then 0.6 else 0.8 -end -end - -do -- video/mpegps -local Bytes = __include("core/Bytes") -S["video/mpegps"] = function(r: Bytes.Reader): number - if r:peek(4) == "\0\0\1\186" then - return 0.9 - end - if r:peek(4) == "\0\0\1\179" then - return 0.5 -- an MPEG-1 / 2 video elementary stream (sequence header) - end - return 0 -end -end - -do -- video/mpegts -local Bytes = __include("core/Bytes") -local SIZES = { 188, 192 } -local function packetSize(r: Bytes.Reader): (number, number) - local n = r:remaining() - local head = r:peek(2048 + 2 * 192) - local lim = math.min(n, 2048) - local start = 0 - while start < lim do - local f = string.find(head, "G", start + 1, true) -- 0x47 - if not f or f > lim then - break - end - start = f - 1 - for _, size in SIZES do - local hits, need = 0, math.min(3, (n - start - 1) // size + 1) - for k = 0, 2 do - local at = start + k * size - if at < n and string.byte(head, at + 1) == 0x47 then - hits += 1 - end - end - if hits >= need and (need >= 2 or start == 0) then - if size == 192 and start >= 4 then - return 192, start - 4 - elseif size == 188 then - return 188, start - end - end - end - start += 1 - end - return 0, 0 -end -S["video/mpegts"] = function(r: Bytes.Reader): number - local s, off = packetSize(r) - if s == 0 then - return 0 - end - if off > 0 then - return 0.6 - end - return if r:remaining() >= 3 * s then 0.9 else 0.5 -end -end - -do -- video/ogv -local Bytes = __include("core/Bytes") -S["video/ogv"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "OggS" then - return 0 - end - local b, p, lim = r.buf, r.pos, r.limit - for _ = 1, 8 do - if p + 27 > lim or buffer.readstring(b, p, 4) ~= "OggS" or buffer.readu8(b, p + 5) % 4 < 2 then - return 0 - end - local nseg = buffer.readu8(b, p + 26) - local d = p + 27 + nseg - if d + 7 <= lim and buffer.readu8(b, d) == 0x80 and buffer.readstring(b, d + 1, 6) == "theora" then - return 1 - end - if d > lim then - return 0 - end - local size = 0 - for i = 0, nseg - 1 do - size += buffer.readu8(b, p + 27 + i) - end - p = d + size - end - return 0 -end -end - -do -- video/smk -local Bytes = __include("core/Bytes") -S["video/smk"] = function(r: Bytes.Reader): number - local s = r:peek(4) - if s ~= "SMK2" and s ~= "SMK4" then - return 0 - end - return 1 -end -end - -do -- video/y4m -local Bytes = __include("core/Bytes") -local MAGIC = "YUV4MPEG2 " -S["video/y4m"] = function(r: Bytes.Reader): number - return if r:peek(10) == MAGIC then 1 else 0 -end -end - -do -- model/3ds -local Bytes = __include("core/Bytes") -S["model/3ds"] = function(r: Bytes.Reader): number - local h = r:peek(8) - if #h < 8 or string.byte(h, 1) ~= 0x4D or string.byte(h, 2) ~= 0x4D then - return 0 - end - local b1, b2, b3, b4, c1, c2 = string.byte(h, 3, 8) - local size = b1 + b2 * 256 + b3 * 65536 + b4 * 16777216 - local child = c1 + c2 * 256 - if size < 16 or not (child == 0x0002 or child == 0x3D3D or child == 0xB000) then - return 0 - end - return if size == r.limit - r.pos then 0.95 else 0.7 -end -end - -do -- model/3mf -local Bytes = __include("core/Bytes") -S["model/3mf"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "PK\3\4" then - return 0 - end - local n = r:size() - local tail = buffer.readstring(r.buf, r.base + math.max(0, n - 65536), math.min(n, 65536)) - if string.find(tail, "3D/[^/]*%.model") or string.find(tail, "3dmodel.model", 1, true) then - return 0.95 - end - local head = r:peek(256) - if string.find(head, "3D/", 1, true) then - return 0.7 - end - return 0 -end -end - -do -- model/ase -local Bytes = __include("core/Bytes") -local Text = lazy(function() - return __include("codecs/text/Text") -end) -local MAGIC = "*3DSMAX_ASCIIEXPORT" -local function utf16(r: Bytes.Reader): (boolean?, boolean) - local h = r:peek(2) - if h == "\255\254" then - return true, false - elseif h == "\254\255" then - return true, true - elseif #h == 2 and string.byte(h, 2) == 0 and string.byte(h, 1) == 42 then - return true, false - elseif #h == 2 and string.byte(h, 1) == 0 and string.byte(h, 2) == 42 then - return true, true - end - return nil, false -end -local function text(r: Bytes.Reader, n: number?): string - local wide, be = utf16(r) - local len = r.limit - r.pos - if n then - len = math.min(len, n) - end - if wide then - local skip = if r:peek(2) == "\255\254" or r:peek(2) == "\254\255" then 2 else 0 - return Text.utf16(r.buf, r.pos + skip, len - skip, be) - end - return Text.toUtf8(buffer.readstring(r.buf, r.pos, len)) -end -S["model/ase"] = function(r: Bytes.Reader): number - local h = string.match(text(r, 256), "^%s*(%*[%w_]+)") - if h == MAGIC then - return 1 - end - return 0 -end -end - -do -- model/b3d -local Bytes = __include("core/Bytes") -S["model/b3d"] = function(r: Bytes.Reader): number - if r:peek(4) == "BB3D" then - return if r:peek(4, 8) ~= "" then 1 else 0.8 - end - return 0 -end -end - -do -- model/blend -local Bytes = __include("core/Bytes") -local Deflate = lazy(function() - return __include("codecs/compress/Deflate") -end) -local Zstd = lazy(function() - return __include("codecs/compress/Zstd") -end) -S["model/blend"] = function(r: Bytes.Reader): number - local head = r:peek(7) - if head == "BLENDER" then - return 1 - end - local n = r.limit - r.base - if string.sub(head, 1, 3) == "\31\139\8" then - local inner = Deflate.peek(r.buf, r.base, n, 7) - return if inner and buffer.tostring(inner) == "BLENDER" then 1 else 0 - end - if string.sub(head, 1, 4) == Zstd.MAGIC then - if n > 4 * 2 ^ 20 then - return 0.5 - end - local out = Zstd.decompress(r.buf, r.base, n, { verify = false }) - return if out and buffer.len(out) >= 7 and buffer.readstring(out, 0, 7) == "BLENDER" then 1 else 0 - end - return 0 -end -end - -do -- model/bsp -local Bytes = __include("core/Bytes") -S["model/bsp"] = function(r: Bytes.Reader): number - if r:remaining() < 64 then - return 0 - end - local m = r:peek(4) - local v = buffer.readi32(r.buf, r.pos + (if m == "IBSP" then 4 else 0)) - if m == "BSP2" or m == "2PSB" then - v = 29 - end - if m == "IBSP" then - return if v == 38 or v == 46 or v == 47 then 1 else 0.3 - end - if v == 29 or v == 30 then - local size = r:remaining() - for i = 0, 14 do - local o, n = buffer.readi32(r.buf, r.pos + 4 + i * 8), buffer.readi32(r.buf, r.pos + 8 + i * 8) - if o < 0 or n < 0 or o + n > size then - return 0 - end - end - return 0.6 - end - return 0 -end -end - -do -- model/buildmap -local Bytes = __include("core/Bytes") -local SECTOR_SIZE, WALL_SIZE, SPRITE_SIZE = 40, 32, 44 -local HEADER = 22 -- version, posx, posy, posz, ang, cursectnum, then u16 numsectors at 20 -local readu16 = buffer.readu16 -local function layout(b: buffer, o: number, limit: number): (number?, number?, number?, number?) - if limit - o < HEADER then - return nil, nil, nil, nil - end - local ns = readu16(b, o + 20) - local p = o + HEADER + ns * SECTOR_SIZE - if p + 2 > limit then - return nil, nil, nil, nil - end - local nw = readu16(b, p) - p += 2 + nw * WALL_SIZE - if p + 2 > limit then - return nil, nil, nil, nil - end - local nsp = readu16(b, p) - p += 2 + nsp * SPRITE_SIZE - return ns, nw, nsp, p -end -S["model/buildmap"] = function(r: Bytes.Reader): number - local b, o, limit = r.buf, r.base, r.limit - if limit - o < HEADER then - return 0 - end - local v = buffer.readu32(b, o) - if v ~= 7 and v ~= 8 and v ~= 9 then - return 0 - end - local ns, _, _, stop = layout(b, o, limit) - if not ns or not stop or stop > limit then - return 0 - end - return if stop == limit then 0.9 else 0.5 -end -end - -do -- model/d3map -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/d3map"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 512, true) - for _ = 1, 16 do - local rest = string.match(head, "^//[^\n]*\n%s*(.*)$") - if not rest then - break - end - head = rest - end - return if string.match(head, "^Version%s+[123]%s") then 1 else 0 -end -end - -do -- model/dae -local Bytes = __include("core/Bytes") -S["model/dae"] = function(r: Bytes.Reader): number - local head = r:peek(2048) - if string.sub(head, 1, 4) == "PK\3\4" then - local nlen = string.byte(head, 27) or 0 - local name = string.lower(string.sub(head, 31, 30 + nlen)) - if string.find(name, "%.dae$") or name == "manifest.xml" then - return 0.95 - end - return 0 - end - -- UTF-16 files: drop the zero bytes - if string.find(string.sub(head, 1, 4), "\0", 1, true) then - head = string.gsub(head, "%z", "") - end - if string.find(head, "<COLLADA", 1, true) then - return 1 - end - return 0 -end -end - -do -- model/gltf -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["model/gltf"] = function(r: Bytes.Reader): number - if r:peek(4) == "glTF" then - return 1 - end - local head = r:peek(1024) - local s = Sniff.dropBom(head) - if string.find(s, "^%s*{") and string.find(s, "\"asset\"", 1, true) then - return 0.9 - end - if string.find(s, "^%s*{") and (string.find(s, "\"accessors\"", 1, true) or string.find(s, "\"bufferViews\"", 1, true)) then - return 0.6 - end - return 0 -end -end - -do -- model/godot -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/godot"] = function(r: Bytes.Reader): number - local h = Sniff.text(r, 256) - if string.match(h, "^%s*%[gd_scene[%s%]]") then - return 1 - end - return 0 -end -end - -do -- model/iqm -local Bytes = __include("core/Bytes") -local MAGIC = "INTERQUAKEMODEL\0" -S["model/iqm"] = function(r: Bytes.Reader): number - return if r:peek(16) == MAGIC then 1 else 0 -end -end - -do -- model/ldraw -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/ldraw"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 2048, true) - if string.find(head, "^0%s+FILE%s") then - return 0.9 - end - if string.find(head, "\n%s*1%s+%S+" .. string.rep("%s+[-+%deE.]+", 12) .. "%s+[^\n]+%.[dDlL][aAdD][tTrR]%s*\r?\n") then - return 0.8 - end - if string.find(head, "^0[ \t]+%a") and string.find(head, "\n%s*[1-5]%s+%S+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]+%s+[-+%d.]") then - return 0.4 - end - return 0 -end -end - -do -- model/lwo -local Bytes = __include("core/Bytes") -local VERSIONS = { LWO2 = true, LWOB = true, LXOB = true } -S["model/lwo"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "FORM" then - return 0 - end - local v = r:peek(4, 8) - return if VERSIONS[v] then 1 elseif v == "LWO3" then 0.8 else 0 -end -end - -do -- model/map -local Bytes = __include("core/Bytes") -S["model/map"] = function(r: Bytes.Reader): number - local head = r:peek(math.min(r:remaining(), 4096)) - if #head < 2 or string.find(head, "[%z\1-\8\14-\31]") then - return 0 - end - if string.sub(head, 1, 3) == "\239\187\191" then - head = string.sub(head, 4) - end - local s = head - local game = false - while true do - local c = string.match(s, "^%s*//[^\n]*\n?()") - if not c then - break - end - if string.match(s, "^%s*//%s*Game:") then - game = true - end - s = string.sub(s, c :: number) - end - local body = string.match(s, '^%s*{%s*"[^"\n]*"%s*"') or string.match(s, "^%s*{%s*{%s*[%(bp]") - if not body then - return if game and string.match(s, "^%s*{") then 0.6 else 0 - end - return if game or string.find(head, '"classname"', 1, true) then 0.9 else 0.6 -end -end - -do -- model/mca -local Bytes = __include("core/Bytes") -local COMPRESSION = { [1] = "gzip", [2] = "zlib", [3] = "none", [4] = "lz4", [127] = "custom" } -S["model/mca"] = function(r: Bytes.Reader): number - local n = r.limit - r.base - if n < 8192 then - return 0 - end - local sectors = (n + 4095) // 4096 - local used, b = 0, r.buf - for i = 0, 1023 do - local e = bit32.byteswap(buffer.readu32(b, r.base + i * 4)) - if e ~= 0 then - local off, cnt = e // 256, e % 256 - if off < 2 or cnt == 0 or off + cnt > sectors then - return 0 - end - used += 1 - if used == 1 then - local p = r.base + off * 4096 - if p + 5 > r.limit then - return 0 - end - local c = buffer.readu8(b, p + 4) % 128 - if COMPRESSION[c] == nil then - return 0 - end - end - end - end - return if used > 0 then 0.8 else 0.2 -end -end - -do -- model/md2 -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/md2"] = function(r: Bytes.Reader): number - if r:remaining() < 68 then - return 0 - end - return if Sniff.magic(r, "IDP2") == 1 and r:peekU8(4) == 8 then 1 else 0 -end -end - -do -- model/md3 -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/md3"] = function(r: Bytes.Reader): number - if r:remaining() < 108 then - return 0 - end - return if Sniff.magic(r, "IDP3") == 1 and r:peekU8(4) == 15 then 1 else 0 -end -end - -do -- model/md5 -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/md5"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 512, true) - head = string.gsub(head, "^//[^\n]*\n%s*", "") - return if string.match(head, "^MD5Version%s+%d+") then 1 else 0 -end -end - -do -- model/mdl -local Bytes = __include("core/Bytes") -S["model/mdl"] = function(r: Bytes.Reader): number - local m = r:peek(4) - local v = r:peekU8(4) - if (m == "IDPO" and v == 6) or (m == "IDST" and v == 10) then - return 1 - end - return 0 -end -end - -do -- model/ms3d -local Bytes = __include("core/Bytes") -local Read = lazy(function() - return __include("model/ms3d/Read") -end) -S["model/ms3d"] = function(r: Bytes.Reader): number - local h = r:peek(14) - if string.sub(h, 1, 10) ~= Read.MAGIC then - return 0 - end - local v = string.byte(h, 11) - return if v == 3 or v == 4 then 1 else 0.6 -end -end - -do -- model/obj -local Bytes = __include("core/Bytes") -S["model/obj"] = function(r: Bytes.Reader): number - local head = r:peek(512) - if string.find(head, "\0", 1, true) then - return 0 - end - if string.find(head, "^%s*v%s+[%-%d%.]") or string.find(head, "\n%s*v%s+[%-%d%.]") then - return 0.6 - end - if string.find(head, "^#") and (string.find(head, "\nmtllib ") or string.find(head, "\no ") or string.find(head, "\ng ")) then - return 0.4 - end - return 0 -end -end - -do -- model/off -local Bytes = __include("core/Bytes") -S["model/off"] = function(r: Bytes.Reader): number - local head = r:peek(512) - for _ = 1, 16 do - local rest = string.match(head, "^%s*#[^\n]*\n(.*)$") - if not rest then - break - end - head = rest - end - local kw = string.match(head, "^%s*(%w+)") - if kw and string.match(kw, "^S?T?C?N?4?n?OFF$") then - return 0.9 - end - return 0 -end -end - -do -- model/ply -local Bytes = __include("core/Bytes") -S["model/ply"] = function(r: Bytes.Reader): number - local h = r:peek(4) - return if h == "ply\n" or h == "ply\r" then 1 else 0 -end -end - -do -- model/pmx -local Bytes = __include("core/Bytes") -S["model/pmx"] = function(r: Bytes.Reader): number - local head = r:peek(8) - if string.sub(head, 1, 4) == "PMX " then - return 1 - end - if string.sub(head, 1, 7) == "Pmd\0\0\128\63" then - return 1 - end - return 0 -end -end - -do -- model/proc -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/proc"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 64, true) - if string.match(head, "^mapProcFile%d%d%d") then - return 1 - end - if string.match(head, '^"?PROC"?%s+"?%d') then - return 0.9 - end - return 0 -end -end - -do -- model/qb -local Bytes = __include("core/Bytes") -S["model/qb"] = function(r: Bytes.Reader): number - if r:remaining() < 24 or r:peek(4) ~= "\1\1\0\0" then - return 0 - end - local b, p = r.buf, r.pos - local fmt, z, comp, mask = buffer.readu32(b, p + 4), buffer.readu32(b, p + 8), buffer.readu32(b, p + 12), buffer.readu32(b, p + 16) - if fmt > 1 or z > 1 or comp > 1 or mask > 1 then - return 0 - end - return 0.9 -end -end - -do -- model/rbxm -local Bytes = __include("core/Bytes") -local MAGIC = "<roblox!\137\255\13\10\26\10" -S["model/rbxm"] = function(r: Bytes.Reader): number - return if r:peek(14) == MAGIC then 1 else 0 -end -end - -do -- model/rbxmx -local Bytes = __include("core/Bytes") -local find, format, match, gmatch = string.find, string.format, string.match, string.gmatch -S["model/rbxmx"] = function(r: Bytes.Reader): number - local head = r:peek(256) - head = string.gsub(head, "^\239\187\191", "") - head = string.gsub(head, "^%s*<%?xml[^>]*%?>", "") - if match(head, "^%s*<roblox[%s>]") then - return if find(head, "version=", 1, true) then 1 else 0.8 - end - return 0 -end -end - -do -- model/robloxmesh -local Bytes = __include("core/Bytes") -S["model/robloxmesh"] = function(r: Bytes.Reader): number - return if string.match(r:peek(13), "^version [1-7]%.%d%d[\r\n]") then 1 else 0 -end -end - -do -- model/schematic -local Bytes = __include("core/Bytes") -local Nbt = lazy(function() - return __include("codecs/text/Nbt") -end) -local LITEMATIC_HINTS = { "Regions", "EnclosingSize", "RegionCount", "TotalVolume", "MinecraftDataVersion" } -local SPONGE_HINTS = { "BlockData", "PaletteMax" } -- v1 / v2 fields (some writers leave the root unnamed) -local function hinted(head: string, hints: { string }): boolean - for _, h in hints do - if string.find(head, string.char(0, #h) .. h, 1, true) then - return true - end - end - return false -end -S["model/schematic"] = function(r: Bytes.Reader): number - local p = Nbt.peek(r.buf, r.base, r.limit - r.base) - if not p or p.rootType ~= "compound" or p.endian ~= "big" then - return 0 - end - if p.name == "Schematic" or (p.firstName == "Schematic" and p.firstType == "compound") then - return 1 - end - local head = buffer.tostring(p.head) - return if hinted(head, LITEMATIC_HINTS) or hinted(head, SPONGE_HINTS) then 1 else 0 -end -end - -do -- model/smd -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/smd"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 256, true) - head = string.gsub(head, "^//[^\n]*\n%s*", "") - if string.match(head, "^version%s+1%s") and string.find(head, "nodes", 1, true) then - return 0.9 - end - return 0 -end -end - -do -- model/sourcemdl -local Bytes = __include("core/Bytes") -S["model/sourcemdl"] = function(r: Bytes.Reader): number - if r.limit - r.base < 8 or r:peek(4) ~= "IDST" then - return 0 - end - local v = buffer.readi32(r.buf, r.base + 4) - return if v >= 44 and v <= 49 then 1 else 0 -end -end - -do -- model/stl -local Bytes = __include("core/Bytes") -local function lower5(s: string): boolean - return string.lower(s) == "solid" -end -S["model/stl"] = function(r: Bytes.Reader): number - local size = r:remaining() - if size >= 84 then - local c = r:peek(4, 80) - local n = string.byte(c, 1) + string.byte(c, 2) * 256 + string.byte(c, 3) * 65536 + string.byte(c, 4) * 16777216 - if 84 + 50 * n == size then - return 0.9 - end - end - local head = r:peek(512) - local s = string.match(head, "^%s*(%a+)") - if s and lower5(s) then - local l = string.lower(head) - return if string.find(l, "facet", 1, true) or string.find(l, "endsolid", 1, true) then 0.9 else 0.5 - end - return 0 -end -end - -do -- model/t3d -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/t3d"] = function(r: Bytes.Reader): number - local h = Sniff.text(r, 512) - local first = string.match(h, "^%s*(Begin%s+%a+)") - if first == nil then - return 0 - end - local kind = string.lower(string.match(first, "%a+$") or "") - if kind == "map" or kind == "actor" or kind == "level" or kind == "brush" or kind == "polylist" then - return 0.9 - end - return 0.3 -end -end - -do -- model/udmf -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/udmf"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 1024, true) - for _ = 1, 32 do - local rest = string.match(head, "^//[^\n]*\n%s*(.*)$") or string.match(head, "^/%*.-%*/%s*(.*)$") - if not rest then - break - end - head = rest - end - if string.match(head, "^[Nn][Aa][Mm][Ee][Ss][Pp][Aa][Cc][Ee]%s*=%s*\"") then - return 0.9 - end - return 0 -end -end - -do -- model/usda -local Bytes = __include("core/Bytes") -local function isUsdz(r: Bytes.Reader): boolean - if r:peek(4) ~= "PK\3\4" then - return false - end - local lo, hi = r:peekU8(26), r:peekU8(27) - if lo < 0 or hi < 0 then - return false - end - local nameLen = lo + hi * 256 - local name = string.lower(r:peek(30 + nameLen)) - name = string.sub(name, 31) - return string.find(name, "%.usd[ac]?$") ~= nil -end -S["model/usda"] = function(r: Bytes.Reader): number - local head = r:peek(8) - if string.sub(head, 1, 5) == "#usda" or string.sub(head, 1, 8) == "\239\187\191#usda" then - return 1 - end - if head == "PXR-USDC" then - return 0.9 -- USDC magic, so the error says it is unsupported - end - if isUsdz(r) then - return 0.95 - end - return 0 -end -end - -do -- model/vbsp -local Bytes = __include("core/Bytes") -local HEADER = 8 + 64 * 16 + 4 -S["model/vbsp"] = function(r: Bytes.Reader): number - if r:remaining() < HEADER or r:peek(4) ~= "VBSP" then - return 0 - end - local v = buffer.readi32(r.buf, r.pos + 4) - return if v >= 19 and v <= 21 then 1 else 0.5 -end -end - -do -- model/vmf -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["model/vmf"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 512, true) - if string.find(head, "%z") then - return 0 - end - if string.match(head, "^versioninfo%s*{") or string.match(head, '^"versioninfo"%s*{') then - return 0.9 - end - if string.match(head, "^world%s*{") or string.match(head, "^visgroups%s*{") then - return 0.6 - end - return 0 -end -end - -do -- model/vox -local Bytes = __include("core/Bytes") -S["model/vox"] = function(r: Bytes.Reader): number - return if r:peek(4) == "VOX " and r:peek(4, 8) == "MAIN" then 1 elseif r:peek(4) == "VOX " then 0.8 else 0 -end -end - -do -- model/vrml -local Bytes = __include("core/Bytes") -S["model/vrml"] = function(r: Bytes.Reader): number - local head = r:peek(16) - if string.sub(head, 1, 3) == "\239\187\191" then - head = string.sub(head, 4) - end - return if string.sub(head, 1, 10) == "#VRML V2.0" then 1 elseif string.sub(head, 1, 6) == "#VRML " then 0.6 else 0 -end -end - -do -- model/x -local Bytes = __include("core/Bytes") -local ENCODINGS = { ["txt "] = "text", ["bin "] = "binary", tzip = "text", bzip = "binary" } -S["model/x"] = function(r: Bytes.Reader): number - if r:peek(4) ~= "xof " then - return 0 - end - return if ENCODINGS[r:peek(4, 8)] then 1 else 0.5 -end -end - -do -- model/x3d -local Bytes = __include("core/Bytes") -S["model/x3d"] = function(r: Bytes.Reader): number - local head = r:peek(1024) - if string.sub(head, 1, 3) == "\239\187\191" then - head = string.sub(head, 4) - end - if string.sub(head, 1, 5) == "#X3D " then - return 1 - end - if string.sub(head, 1, 4) == "\224\0\0\1" and string.find(head, "x3d", 1, true) then - return 0.9 - end - if string.find(head, "<X3D[%s>]") or string.find(head, "<!DOCTYPE X3D", 1, true) then - return 1 - end - return 0 -end -end - -do -- cad/step -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["cad/step"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 256) - head = string.gsub(head, "^%s*/%*.-%*/", "") - if string.find(head, "^%s*ISO%-10303%-21%s*;") then - return 1 - end - return 0 -end -end - -do -- font/bdf -local Bytes = __include("core/Bytes") -S["font/bdf"] = function(r: Bytes.Reader): number - local head = r:peek(32) - return if string.match(head, "^STARTFONT%s+2%.%d") then 1 else 0 -end -end - -do -- font/bmfont -local Bytes = __include("core/Bytes") -S["font/bmfont"] = function(r: Bytes.Reader): number - local head = r:peek(64) - if string.sub(head, 1, 4) == "BMF\3" then - return 1 - end - if string.match(head, "^info%s+face=") or string.match(head, "^info%s+") and string.find(head, "size=", 1, true) then - return 0.9 - end - if string.find(head, "<font>", 1, true) or (string.find(head, "<?xml", 1, true) and string.find(r:peek(512), "<font>", 1, true)) then - return if string.find(r:peek(512), "<info", 1, true) then 0.9 else 0.3 - end - return 0 -end -end - -do -- font/eot -local Bytes = __include("core/Bytes") -local MAGIC = 0x504C -S["font/eot"] = function(r: Bytes.Reader): number - local h = r:peek(36) - if #h < 36 then - return 0 - end - local ver = string.sub(h, 9, 12) - local magic = string.byte(h, 35) + string.byte(h, 36) * 256 - if magic == MAGIC and (ver == "\0\0\1\0" or ver == "\1\0\2\0" or ver == "\2\0\2\0") then - return 1 - end - return 0 -end -end - -do -- font/fon -local Bytes = __include("core/Bytes") -local function isFnt(h: string): boolean - if #h < 4 then - return false - end - local ver = string.byte(h, 1) + string.byte(h, 2) * 256 - return ver == 0x200 or ver == 0x300 -end -S["font/fon"] = function(r: Bytes.Reader): number - local h = r:peek(64) - if string.sub(h, 1, 2) == "MZ" and #h >= 64 then - local lfanew = string.byte(h, 61) + string.byte(h, 62) * 256 + string.byte(h, 63) * 65536 - local sig = r:peek(2, lfanew) - return if sig == "NE" then 0.6 elseif sig == "PE" then 0.2 else 0 - end - if isFnt(h) and #h >= 6 then - local size = string.byte(h, 3) + string.byte(h, 4) * 256 + string.byte(h, 5) * 65536 + string.byte(h, 6) * 16777216 - return if size == r:size() then 0.9 elseif size <= r:size() and size > 118 then 0.3 else 0 - end - return 0 -end -end - -do -- font/hershey -local Bytes = __include("core/Bytes") -local function header(line: string): (number?, number?) - if #line < 10 then - return nil, nil - end - local id = tonumber((string.gsub(string.sub(line, 1, 5), "^%s+", ""))) - local n = tonumber((string.gsub(string.sub(line, 6, 8), "^%s+", ""))) - if not id or not n or n < 1 or string.find(string.sub(line, 1, 8), "[^%d ]") then - return nil, nil - end - return id, n -end -S["font/hershey"] = function(r: Bytes.Reader): number - local head = r:peek(256) - local line = string.match(head, "^([^\r\n]*)") - local id, n = header(line or "") - if not id or not n then - return 0 - end - local body = string.sub(line :: string, 9) - if string.find(body, "[^ -~]") then - return 0 - end - return if #body == math.min(2 * n, 64) or #body == 2 * n then 0.7 else 0.3 -end -end - -do -- font/pcf -local Bytes = __include("core/Bytes") -S["font/pcf"] = function(r: Bytes.Reader): number - return if r:peek(4) == "\1fcp" then 1 else 0 -end -end - -do -- font/psf -local Bytes = __include("core/Bytes") -S["font/psf"] = function(r: Bytes.Reader): number - local h = r:peek(4) - if h == "\114\181\74\134" then - return 1 - end - if string.sub(h, 1, 2) == "\54\4" and #h >= 4 and string.byte(h, 3) <= 7 and string.byte(h, 4) > 0 then - return 0.9 - end - return 0 -end -end - -do -- font/ttf -local Bytes = __include("core/Bytes") -S["font/ttf"] = function(r: Bytes.Reader): number - local m = r:peek(4) - if m == "\0\1\0\0" or m == "OTTO" or m == "ttcf" or m == "true" then - return 0.9 - end - return 0 -end -end - -do -- font/type1 -local Bytes = __include("core/Bytes") -S["font/type1"] = function(r: Bytes.Reader): number - local h = r:peek(64) - if string.sub(h, 1, 2) == "\128\1" then - h = string.sub(h, 7) - end - if string.sub(h, 1, 14) == "%!PS-AdobeFont" or string.sub(h, 1, 10) == "%!FontType" then - return 1 - end - return 0 -end -end - -do -- font/woff -local Bytes = __include("core/Bytes") -S["font/woff"] = function(r: Bytes.Reader): number - return if r:peek(4) == "wOFF" then 1 else 0 -end -end - -do -- font/woff2 -local Bytes = __include("core/Bytes") -S["font/woff2"] = function(r: Bytes.Reader): number - return if r:peek(4) == "wOF2" then 1 else 0 -end -end - -do -- archive/7z -local Bytes = __include("core/Bytes") -local MAGIC = "7z\188\175\39\28" -S["archive/7z"] = function(r: Bytes.Reader): number - return if r:peek(6) == MAGIC then 1 else 0 -end -end - -do -- archive/adf -local Bytes = __include("core/Bytes") -local BS = 512 -S["archive/adf"] = function(r: Bytes.Reader): number - local n = r:size() - if n < 4 * BS or n % BS ~= 0 then - return 0 - end - local h = r:peek(4) - if string.sub(h, 1, 3) ~= "DOS" or string.byte(h, 4) > 5 then - return 0 - end - return if n == 901120 or n == 1802240 then 0.95 else 0.6 -end -end - -do -- archive/applesingle -local Bytes = __include("core/Bytes") -S["archive/applesingle"] = function(r: Bytes.Reader): number - local h = r:peek(8) - if #h < 8 then - return 0 - end - local magic = string.sub(h, 1, 4) - local ver = string.sub(h, 5, 8) - if (magic == "\0\5\22\0" or magic == "\0\5\22\7") and (ver == "\0\1\0\0" or ver == "\0\2\0\0") then - return 1 - end - return 0 -end -end - -do -- archive/ar -local Bytes = __include("core/Bytes") -local MAGIC = "!<arch>\n" -S["archive/ar"] = function(r: Bytes.Reader): number - if r:peek(8) == MAGIC then - return if r:peek(13, 68) == "debian-binary" then 1 else 0.9 - end - return if r:peek(8) == "!<thin>\n" then 0.5 else 0 -end -end - -do -- archive/arj -local Bytes = __include("core/Bytes") -S["archive/arj"] = function(r: Bytes.Reader): number - local h = r:peek(4) - if #h == 4 and string.byte(h, 1) == 0x60 and string.byte(h, 2) == 0xEA then - local size = string.byte(h, 3) + string.byte(h, 4) * 256 - return if size > 0 and size <= 2600 then 0.9 else 0 - end - return 0 -end -end - -do -- archive/binhex -local Bytes = __include("core/Bytes") -local BANNER = "(This file must be converted with BinHex" -S["archive/binhex"] = function(r: Bytes.Reader): number - local head = r:peek(2048) - local at = string.find(head, BANNER, 1, true) - if not at then - return 0 - end - return if at == 1 then 1 else 0.8 -end -end - -do -- archive/br -local Err = __include("core/Err") -local Bytes = __include("core/Bytes") -local Brotli = lazy(function() - return __include("codecs/compress/Brotli") -end) -local SNIFF_WHOLE = 262144 -- streams up to this size are decoded whole by sniff -local SNIFF_PREFIX = 65536 -S["archive/br"] = function(r: Bytes.Reader): number - local n = r:remaining() - if n == 0 then - return 0 - end - if n <= SNIFF_WHOLE then - local out, consumed = Brotli.decompress(r.buf, r.pos, n, { maxBytes = 2 ^ 26 }) - if out and consumed == r.limit then - return if buffer.len(out) > 0 then 0.3 else 0.05 - end - return 0 - end - local _, err = Brotli.decompress(r.buf, r.pos, SNIFF_PREFIX, { maxBytes = 2 ^ 22 }) - if err and (err.code == Err.TRUNCATED or err.code == Err.LIMIT) then - return 0.05 - end - return 0 -end -end - -do -- archive/bz2 -local Bytes = __include("core/Bytes") -S["archive/bz2"] = function(r: Bytes.Reader): number - local h = r:peek(10) - if #h < 10 or string.sub(h, 1, 3) ~= "BZh" then - return 0 - end - local lv = string.byte(h, 4) - if lv < 0x31 or lv > 0x39 then - return 0 - end - local magic = string.sub(h, 5, 10) - if magic == "\x31\x41\x59\x26\x53\x59" or magic == "\x17\x72\x45\x38\x50\x90" then - return 1 - end - return 0 -end -end - -do -- archive/cab -local Bytes = __include("core/Bytes") -S["archive/cab"] = function(r: Bytes.Reader): number - if r:peek(8) == "MSCF\0\0\0\0" then - return 1 - end - return 0 -end -end - -do -- archive/cpio -local Bytes = __include("core/Bytes") -S["archive/cpio"] = function(r: Bytes.Reader): number - local m = r:peek(6) - if m == "070701" or m == "070702" or m == "070707" then - return 1 - end - local b2 = r:peek(2) - if (b2 == "\199\113" or b2 == "\113\199") and r:remaining() >= 26 then - return 0.5 - end - return 0 -end -end - -do -- archive/d64 -local Bytes = __include("core/Bytes") -type Geometry = { kind: string, tracks: number, offsets: { number }, spt: { number }, dirTrack: number, total: number } -local function geometry(kind: string, tracks: number): Geometry - local offsets, spt = {}, {} - local o = 0 - for t = 1, tracks do - local n - if kind == "d81" then - n = 40 - else - local s = if kind == "d71" and t > 35 then t - 35 else t - n = if s <= 17 then 21 elseif s <= 24 then 19 elseif s <= 30 then 18 else 17 - end - offsets[t], spt[t] = o, n - o += n * 256 - end - return { kind = kind, tracks = tracks, offsets = offsets, spt = spt, dirTrack = if kind == "d81" then 40 else 18, total = o } -end -local function detect(len: number): Geometry? - for _, g in { { "d64", 35 }, { "d64", 40 }, { "d64", 42 }, { "d71", 70 }, { "d81", 80 } } :: { { any } } do - local geo = geometry(g[1] :: string, g[2] :: number) - local sectors = geo.total // 256 - if len == geo.total or (g[1] ~= "d81" and len == geo.total + sectors) then - return geo - end - end - return nil -end -S["archive/d64"] = function(r: Bytes.Reader): number - local geo = detect(r:size()) - if not geo then - return 0 - end - -- the BAM / header sector: dir track link and DOS version byte - local h = r:sub(geo.offsets[geo.dirTrack], 256) - local t, s, v = h:u8(), h:u8(), h:u8() - if geo.kind == "d81" then - return if t == 40 and s == 3 and v == 0x44 then 0.9 else 0.3 - end - return if t == 18 and s == 1 and (v == 0x41 or v == 0) then 0.9 else 0.3 -end -end - -do -- archive/fat -local Bytes = __include("core/Bytes") -local Fat = lazy(function() - return __include("containers/Fat") -end) -S["archive/fat"] = function(r: Bytes.Reader): number - if r:remaining() < 512 then - return 0 - end - local v = Fat.open(r.buf, r.base + r.pos, r.limit - r.base - r.pos) - if not v then - return 0 - end - return if v.partition then 0.6 else 0.8 -end -end - -do -- archive/grp -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -local MAGIC = "KenSilverman" -S["archive/grp"] = function(r: Bytes.Reader): number - return Sniff.magic(r, MAGIC) -end -end - -do -- archive/gzip -local Bytes = __include("core/Bytes") -S["archive/gzip"] = function(r: Bytes.Reader): number - return if r:peek(3) == "\31\139\8" then 1 else 0 -end -end - -do -- archive/iso -local Bytes = __include("core/Bytes") -S["archive/iso"] = function(r: Bytes.Reader): number - return if r:peek(5, 16 * 2048 + 1) == "CD001" then 1 else 0 -end -end - -do -- archive/lha -local Bytes = __include("core/Bytes") -local METHODS: { [string]: boolean } = { - ["-lh0-"] = true, ["-lz4-"] = true, ["-lhd-"] = true, ["-lh1-"] = true, ["-lh4-"] = true, ["-lh5-"] = true, - ["-lh6-"] = true, ["-lh7-"] = true, ["-lhx-"] = true, ["-lzs-"] = true, ["-lz5-"] = true, ["-lh2-"] = true, - ["-lh3-"] = true, ["-pm0-"] = true, ["-pm1-"] = true, ["-pm2-"] = true, ["-lk7-"] = true, -} -local function isHeader(s: string): boolean - if #s < 22 then - return false - end - local m = string.sub(s, 3, 7) - local level = string.byte(s, 21) - return METHODS[m] == true and level <= 3 -end -S["archive/lha"] = function(r: Bytes.Reader): number - if isHeader(r:peek(22)) then - return 0.95 - end - return 0 -end -end - -do -- archive/lz4 -local Bytes = __include("core/Bytes") -S["archive/lz4"] = function(r: Bytes.Reader): number - local m = r:peek(4) - if m == "\4\34\77\24" then - return 1 - elseif m == "\2\33\76\24" then - return 0.9 - elseif #m == 4 and string.byte(m, 1) >= 0x50 and string.byte(m, 1) <= 0x5F and string.sub(m, 2) == "\42\77\24" then - -- a skippable frame (zstd shares the magic): an LZ4 frame after it - local h = r:peek(4, 4) - if #h == 4 then - local n = string.byte(h, 1) + string.byte(h, 2) * 256 + string.byte(h, 3) * 65536 + string.byte(h, 4) * 16777216 - if r:peek(4, 8 + n) == "\4\34\77\24" then - return 1 - end - end - end - return 0 -end -end - -do -- archive/macbinary -local Bytes = __include("core/Bytes") -local Crc16 = __include("core/Crc16") -local function version(b: buffer, o: number, len: number): string? - if len < 128 then - return nil - end - local u8 = function(i: number): number - return buffer.readu8(b, o + i) - end - if u8(0) ~= 0 or u8(74) ~= 0 then - return nil - end - local nameLen = u8(1) - if nameLen < 1 or nameLen > 63 then - return nil - end - local function be32(i: number): number - return u8(i) * 16777216 + u8(i + 1) * 65536 + u8(i + 2) * 256 + u8(i + 3) - end - local dlen, rlen = be32(83), be32(87) - if dlen > 0x7FFFFFFF or rlen > 0x7FFFFFFF then - return nil - end - local crc = u8(124) * 256 + u8(125) - if crc == Crc16.ccitt(b, o, 124) and (crc ~= 0 or u8(122) >= 129) then - return if buffer.readstring(b, o + 102, 4) == "mBIN" then "III" else "II" - end - if buffer.readstring(b, o + 102, 4) == "mBIN" then - return nil -- III with a bad CRC - end - -- MacBinary I: byte 82 zero, bytes 99..125 zero, the forks within the file - if u8(82) ~= 0 then - return nil - end - for i = 99, 125 do - if u8(i) ~= 0 then - return nil - end - end - local need = 128 + math.ceil(dlen / 128) * 128 + rlen - return if need <= len + 127 then "I" else nil -end -S["archive/macbinary"] = function(r: Bytes.Reader): number - local n = math.min(r:remaining(), 128) - if n < 128 then - return 0 - end - local v = version(r.buf, r.base + r.pos, r.limit - r.base - r.pos) - return if v == "III" then 0.95 elseif v == "II" then 0.8 elseif v == "I" then 0.3 else 0 -end -end - -do -- archive/mpq -local Bytes = __include("core/Bytes") -S["archive/mpq"] = function(r: Bytes.Reader): number - local m = r:peek(4) - if m == "MPQ\x1A" or m == "MPQ\x1B" then - return 1 - end - -- a prefixed archive (an installer stub): the header on a 512-byte boundary in the first 64 KB - for at = 512, math.min(65536, r:remaining() - 32), 512 do - if r:peek(4, at) == "MPQ\x1A" then - return 0.6 - end - end - return 0 -end -end - -do -- archive/pak -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["archive/pak"] = function(r: Bytes.Reader): number - if r:remaining() < 12 then - return 0 - end - return math.max(Sniff.magic(r, "PACK", 0, 0.9), Sniff.magic(r, "SPAK", 0, 0.9)) -end -end - -do -- archive/rpm -local Bytes = __include("core/Bytes") -local LEAD_MAGIC = "\237\171\238\219" -S["archive/rpm"] = function(r: Bytes.Reader): number - return if r:peek(4) == LEAD_MAGIC then 1 else 0 -end -end - -do -- archive/tar -local Bytes = __include("core/Bytes") -local Tar = lazy(function() - return __include("containers/Tar") -end) -S["archive/tar"] = function(r: Bytes.Reader): number - if r:remaining() < 512 then - return 0 - end - if not Tar.valid(r.buf, r.pos) then - return 0 - end - return if r:peek(5, 257) == "ustar" then 0.95 else 0.6 -end -end - -do -- archive/unitypackage -local Bytes = __include("core/Bytes") -local Deflate = lazy(function() - return __include("codecs/compress/Deflate") -end) -local Tar = lazy(function() - return __include("containers/Tar") -end) -local function guidOf(name: string): (string?, string?) - local n = string.gsub(name, "^%./", "") - local guid, rest = string.match(n, "^(%x+)/?(.*)$") - if guid and #guid == 32 then - return string.lower(guid), rest - end - return nil, nil -end -S["archive/unitypackage"] = function(r: Bytes.Reader): number - if r:peek(3) ~= "\31\139\8" then - return 0 - end - local head = Deflate.peek(r.buf, r.pos, r.limit - r.pos, 512) - if not head or buffer.len(head) < 512 or not Tar.valid(head, 0) then - return 0 - end - local z = 0 - while z < 100 and buffer.readu8(head, z) ~= 0 do - z += 1 - end - return if guidOf(buffer.readstring(head, 0, z)) then 1 else 0 -- ties with archive/gzip go to the extension -end -end - -do -- archive/uu -local Bytes = __include("core/Bytes") -S["archive/uu"] = function(r: Bytes.Reader): number - local head = r:peek(4096) - if string.match(head, "^begin%-base64 [0-7]+ [^\r\n]") or string.match(head, "^begin [0-7]+ [^\r\n]") then - return 0.9 - end - if string.match(head, "\nbegin%-base64 [0-7]+ [^\r\n]") or string.match(head, "\nbegin [0-7][0-7][0-7]+ [^\r\n]") then - return 0.5 - end - return 0 -end -end - -do -- archive/vpk -local Bytes = __include("core/Bytes") -S["archive/vpk"] = function(r: Bytes.Reader): number - if r:remaining() < 12 or r:peek(4) ~= "\x34\x12\xAA\x55" then - return 0 - end - local v = r:peekU8(4) - return if v == 1 or v == 2 then 1 else 0.5 -end -end - -do -- archive/vswap -local Bytes = __include("core/Bytes") -local readu8, readu16, readi16, writeu32 = buffer.readu8, buffer.readu16, buffer.readi16, buffer.writeu32 -local function header(r: Bytes.Reader): (number?, number, number) - if r:remaining() < 6 then - return nil, 0, 0 - end - local n, ss, so = readu16(r.buf, r.base), readu16(r.buf, r.base + 2), readu16(r.buf, r.base + 4) - if n == 0 or ss > so or so > n or 6 + n * 6 > r:remaining() then - return nil, 0, 0 - end - return n, ss, so -end -S["archive/vswap"] = function(r: Bytes.Reader): number - local n = header(r) - if not n then - return 0 - end - local size = r.limit - r.base - local b = r.buf - local last = 6 + n * 6 - local nonzero = 0 - for i = 0, n - 1 do - local o = buffer.readu32(b, r.base + 6 + i * 4) - local l = readu16(b, r.base + 6 + n * 4 + i * 2) - if o ~= 0 then - if o < last or o + l > size then - return 0 - end - last = o - nonzero += 1 - end - end - return if nonzero > 0 then 0.6 else 0 -end -end - -do -- archive/wad -local Bytes = __include("core/Bytes") -S["archive/wad"] = function(r: Bytes.Reader): number - if r:remaining() < 12 then - return 0 - end - local m = r:peek(4) - if m ~= "IWAD" and m ~= "PWAD" then - return 0 - end - return 0.9 -end -end - -do -- archive/wad2 -local Bytes = __include("core/Bytes") -S["archive/wad2"] = function(r: Bytes.Reader): number - if r:remaining() < 12 then - return 0 - end - local m = r:peek(4) - return if m == "WAD2" or m == "WAD3" then 0.9 else 0 -end -end - -do -- archive/xz -local Bytes = __include("core/Bytes") -local XZ_MAGIC = "\253" .. "7zXZ\0" -local function aloneScore(r: Bytes.Reader): number - local h = r:peek(14) - if #h < 14 then - return 0 - end - local d = string.byte(h, 1) - if d >= 225 or string.byte(h, 14) ~= 0 then - return 0 - end - local dict = string.byte(h, 2) + string.byte(h, 3) * 256 + string.byte(h, 4) * 65536 + string.byte(h, 5) * 16777216 - local okDict = false - for n = 12, 31 do - if dict == 2 ^ n or (n < 31 and dict == 2 ^ n + 2 ^ (n - 1)) then - okDict = true - break - end - end - if not okDict then - return 0 - end - local s = string.sub(h, 6, 13) - if s ~= string.rep("\255", 8) and (string.byte(h, 11) ~= 0 or string.byte(h, 12) ~= 0 or string.byte(h, 13) ~= 0) then - return 0 - end - return if d == 0x5D then 0.4 else 0.2 -end -S["archive/xz"] = function(r: Bytes.Reader): number - if r:peek(6) == XZ_MAGIC then - return 1 - end - return aloneScore(r) -end -end - -do -- archive/yenc -local Bytes = __include("core/Bytes") -S["archive/yenc"] = function(r: Bytes.Reader): number - local head = r:peek(4096) - if string.match(head, "^=ybegin ") then - return 0.95 - end - return if string.find(head, "\n=ybegin [^\n]*name=") then 0.6 else 0 -end -end - -do -- archive/z -local Bytes = __include("core/Bytes") -S["archive/z"] = function(r: Bytes.Reader): number - if r:peek(2) ~= "\31\157" then - return 0 - end - local f = r:peekU8(2) - return if f >= 0 and bit32.band(f, 0x60) == 0 and bit32.band(f, 0x1F) >= 9 and bit32.band(f, 0x1F) <= 16 then 1 else 0.3 -end -end - -do -- archive/zip -local Bytes = __include("core/Bytes") -S["archive/zip"] = function(r: Bytes.Reader): number - local s = r:peek(4) - -- ZIP-based formats (docx, jar, 3mf, ...) score higher in their own sniff - if s == "PK\3\4" or s == "PK\5\6" then - return 0.6 - end - if string.sub(s, 1, 2) == "MZ" then - return 0 -- a self-extractor opens with Zip.decode / opts.format = "zip" - end - return 0 -end -end - -do -- archive/zoo -local Bytes = __include("core/Bytes") -local TAG = 0xFDC4A7DC -S["archive/zoo"] = function(r: Bytes.Reader): number - local h = r:peek(24) - if #h < 24 then - return 0 - end - local tag = string.byte(h, 21) + string.byte(h, 22) * 256 + string.byte(h, 23) * 65536 + string.byte(h, 24) * 16777216 - if tag ~= TAG then - return 0 - end - return if string.sub(h, 1, 4) == "ZOO " then 1 else 0.8 -end -end - -do -- archive/zst -local Bytes = __include("core/Bytes") -local Zstd = lazy(function() - return __include("codecs/compress/Zstd") -end) -S["archive/zst"] = function(r: Bytes.Reader): number - local m = r:peek(4) - if m == Zstd.MAGIC then - return 1 - end - -- a skippable frame (0x184D2A50 .. 0x184D2A5F) is usually followed by a zstd frame - if #m == 4 and string.sub(m, 2, 4) == "\42\77\24" and bit32.band(string.byte(m, 1), 0xF0) == 0x50 then - return 0.5 - end - return 0 -end -end - -do -- data/cbor -local Bytes = __include("core/Bytes") -S["data/cbor"] = function(r: Bytes.Reader): number - return if r:peek(3) == "\217\217\247" then 1 else 0 -end -end - -do -- data/csv -local Bytes = __include("core/Bytes") -local find, sub, byte, gsub = string.find, string.sub, string.byte, string.gsub -S["data/csv"] = function(r: Bytes.Reader): number - local head = r:peek(1024) - if find(head, "%z") then - return 0 - end - local l1, l2 = string.match(head, "^([^\r\n]*)\r?\n([^\r\n]*)") - if not l1 or l1 == "" then - return 0 - end - for _, d in { ",", "\t", ";" } do - local _, c1 = gsub(l1, d, "") - local _, c2 = gsub(l2 :: string, d, "") - if c1 > 0 and c1 == c2 then - return 0.15 - end - end - return 0 -end -end - -do -- data/ini -local Bytes = __include("core/Bytes") -S["data/ini"] = function(r: Bytes.Reader): number - local head = r:peek(512) - if string.find(head, "%z") then - return 0 - end - local first = string.match(head, "^[%s]*([^\r\n]*)") - while first and string.match(first, "^[;#]") do - head = string.match(head, "^[^\n]*\n(.*)$") or "" - first = string.match(head, "^[%s]*([^\r\n]*)") - end - if first and string.match(first, "^%[[^%]]+%]%s*$") then - return 0.2 - end - return 0 -end -end - -do -- data/json -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["data/json"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 64) - local first = string.match(head, "^[ \t\r\n]*(.)") - if first == "{" then - local nxt = string.match(head, "^[^{]*{[ \t\r\n]*(.)") - return if nxt == nil or nxt == '"' or nxt == "}" then 0.6 else 0.1 - elseif first == "[" then - -- past any nested '[': a JSON value must start (TOML / INI "[section]" and "[[table]]" do not) - local nxt = string.match(head, "^[ \t\r\n]*[%[ \t\r\n]*(.)") - if nxt == nil or string.find('{"-0123456789tfn]', nxt, 1, true) then - return 0.3 - end - return 0 - end - return 0 -end -end - -do -- data/msgpack -local Bytes = __include("core/Bytes") -S["data/msgpack"] = function(_r: Bytes.Reader): number - return 0 -- no magic: by extension or opts.format only -end -end - -do -- data/nbt -local Bytes = __include("core/Bytes") -local Nbt = lazy(function() - return __include("codecs/text/Nbt") -end) -S["data/nbt"] = function(r: Bytes.Reader): number - local p = Nbt.peek(r.buf, r.base, r.limit - r.base) - if not p or p.rootType ~= "compound" then - return 0 - end - if p.compression ~= "none" then - return if p.firstType then 1 else 0.5 -- gzip wrapped NBT: ties with archive/gzip go to the extension - end - return if p.firstType and p.firstName then 0.6 else 0.2 -end -end - -do -- data/plist -local Bytes = __include("core/Bytes") -S["data/plist"] = function(r: Bytes.Reader): number - local head = r:peek(256) - if string.sub(head, 1, 6) == "bplist" then - return 1 - end - if string.find(head, "<!DOCTYPE plist", 1, true) or string.find(head, "<plist", 1, true) then - return 0.9 - end - return 0 -end -end - -do -- data/q3shader -local Bytes = __include("core/Bytes") -local KEYWORDS = { "surfaceparm", "map", "clampmap", "animmap", "blendfunc", "rgbgen", "alphagen", "tcgen", "tcmod", - "cull", "deformvertexes", "qer_editorimage", "nopicmip", "nomipmaps", "skyparms", "q3map_", "depthwrite", "alphafunc" } -S["data/q3shader"] = function(r: Bytes.Reader): number - local head = r:peek(math.min(r:remaining(), 2048)) - if #head < 4 or string.find(head, "[%z\1-\8\14-\31]") then - return 0 - end - local s = string.gsub(string.gsub(head, "/%*.-%*/", " "), "//[^\n]*", "") - if not string.match(s, "^%s*[^%s{}\"]+%s*{") then - return 0 - end - local lower = string.lower(s) - for _, k in KEYWORDS do - if string.find(lower, "%f[%w_]" .. k) then - return 0.7 - end - end - return 0.2 -end -end - -do -- data/q3skin -local Bytes = __include("core/Bytes") -S["data/q3skin"] = function(r: Bytes.Reader): number - local head = r:peek(math.min(r:remaining(), 1024)) - if #head < 3 or string.find(head, "[%z\1-\8\14-\31]") then - return 0 - end - local lines, good, paths = 0, 0, 0 - for line in string.gmatch(head, "[^\r\n]+") do - if not string.match(line, "^%s*$") then - lines += 1 - local surface, shader = string.match(line, "^%s*([%w_%-]+)%s*,%s*([^,%s]*)%s*$") - if surface and shader == "" and string.sub(string.lower(surface), 1, 4) == "tag_" then - good += 1 - elseif shader and string.find(shader, "/", 1, true) then - good += 1 - paths += 1 - end - end - end - return if lines > 0 and good == lines and paths > 0 then 0.5 else 0 -end -end - -do -- data/snbt -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["data/snbt"] = function(r: Bytes.Reader): number - -- SNBT has what JSON never has: unquoted keys, typed numbers (1b, 2.5f), [I; arrays, single-quoted strings - local head = Sniff.text(r, 512, true) - local first = string.sub(head, 1, 1) - if first ~= "{" and first ~= "[" then - return 0 - end - if string.find(head, "[{,]%s*[%a_][%w_%-%.%+]*%s*:") or string.find(head, "%d[bBsSlLfFdD]%s*[,}%]]") - or string.find(head, "%[[BIL]%s*;") or string.find(head, "[:,%[]%s*'") - then - return 0.7 - end - return 0 -end -end - -do -- data/toml -local Bytes = __include("core/Bytes") -S["data/toml"] = function(r: Bytes.Reader): number - local head = r:peek(512) - if string.find(head, "%z") then - return 0 - end - for line in string.gmatch(head, "[^\n]+") do - local l = string.match(line, "^[ \t]*(.-)[ \t\r]*$") :: string - if l ~= "" and string.sub(l, 1, 1) ~= "#" then - if string.match(l, "^%[%[?[%w_%-%.\"' ]+%]%]?$") or string.match(l, "^[%w_%-%.\"']+[ \t]*=[ \t]*[\"'%[{%dtf%+%-in]") then - return 0.2 - end - return 0 - end - end - return 0 -end -end - -do -- data/tres -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["data/tres"] = function(r: Bytes.Reader): number - local h = Sniff.text(r, 256) - if string.match(h, "^%s*%[gd_resource[%s%]]") then - return 1 - end - return 0 -end -end - -do -- data/vdf -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -local KeyValues = lazy(function() - return __include("codecs/text/KeyValues") -end) -S["data/vdf"] = function(r: Bytes.Reader): number - local n = r:remaining() - if KeyValues.isBinary(r.buf, r.pos, n) then - return 0.3 - end - local head = Sniff.text(r, 256, true) - if string.find(head, "%z") then - return 0 - end - head = string.gsub(head, "^//[^\n]*\n%s*", "") - if string.match(head, '^"[^"\n]+"%s*{') or string.match(head, '^"[^"\n]+"%s*%[[^%]\n]*%]%s*{') then - return 0.6 - end - if string.match(head, "^#base%s") or string.match(head, "^#include%s") then - return 0.5 - end - if string.match(head, '^[%w_]+%s*\n%s*{%s*\n%s*"') then - return 0.3 - end - return 0 -end -end - -do -- data/xml -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["data/xml"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 64) - if string.match(head, "^<%?xml[ \t\r\n]") or string.sub(head, 1, 4) == "\255\254<\0" or string.sub(head, 1, 4) == "\254\255\0<" then - return 0.5 - end - if string.match(head, "^[ \t\r\n]*<[%a!]") then - return 0.3 - end - return 0 -end -end - -do -- data/yaml -local Bytes = __include("core/Bytes") -S["data/yaml"] = function(r: Bytes.Reader): number - local head = r:peek(256) - if string.find(head, "%z") then - return 0 - end - if string.match(head, "^%%YAML ") then - return 0.9 - end - if string.match(head, "^%-%-%-[ \r\n]") then - return 0.5 - end - local line = string.match(head, "^[ \t\r\n]*([^\r\n]*)") - if line and (string.match(line, "^[%w_%-\"']+[%w_%- \"']*:[ ]") or string.match(line, "^[%w_%-]+:$") or string.match(line, "^%- ")) then - return 0.2 - end - return 0 -end -end - -do -- vector/gamemaps -local Bytes = __include("core/Bytes") -local MAGIC = "TED5v1.0" -S["vector/gamemaps"] = function(r: Bytes.Reader): number - if r:peek(8) == MAGIC then - return 1 - end - -- MAPHEAD: the RLEW tag 0xABCD, then 100 offsets (0 / -1 when absent) - if r:remaining() >= 402 and r:remaining() <= 1024 and buffer.readu16(r.buf, r.base) == 0xABCD then - local first = buffer.readi32(r.buf, r.base + 2) - if first > 0 then - return 0.7 - end - end - return 0 -end -end - -do -- vector/ldtk -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["vector/ldtk"] = function(r: Bytes.Reader): number - local h = Sniff.text(r, 1024) - if not string.match(h, "^%s*{") then - return 0 - end - if string.find(h, "\"fileType\"%s*:%s*\"LDtk Project JSON\"") then - return 1 - end - if string.find(h, "\"jsonVersion\"", 1, true) and string.find(h, "\"worldLayout\"", 1, true) then - return 0.8 - end - return 0 -end -end - -do -- vector/ogmo -local Bytes = __include("core/Bytes") -local Sniff = __include("core/Sniff") -S["vector/ogmo"] = function(r: Bytes.Reader): number - local h = Sniff.text(r, 2048) - if not string.match(h, "^%s*{") or not string.find(h, "\"ogmoVersion\"", 1, true) then - return 0 - end - if string.find(h, "\"layerGridDefaultSize\"", 1, true) or string.find(h, "\"levelPaths\"", 1, true) then - return 1 - end - return 0.9 -end -end - -do -- vector/svg -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["vector/svg"] = function(r: Bytes.Reader): number - local h = Sniff.text(r, 4096) - if not string.match(h, "^%s*<") then - return 0 - end - if string.find(h, "<svg[%s>:]") or string.find(h, "<%w+:svg[%s>]") then - return 0.95 - end - return 0 -end -end - -do -- vector/tiled -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -local function head(r: Bytes.Reader): string - local h = Sniff.text(r, 1024) - return h -end -S["vector/tiled"] = function(r: Bytes.Reader): number - local h = head(r) - if string.match(h, "^%s*<") then - if string.find(h, "<map[%s>]") or string.find(h, "<tileset[%s>]") then - return 0.9 - end - return 0 - end - if string.match(h, "^%s*{") then - -- Tiled writes its keys sorted: "type" comes last, so look at the tail too - local n = r:remaining() - local tail = if n > 1024 then r:peek(1024, n - 1024) else "" - for _, part in { h, tail } do - if string.find(part, "\"type\"%s*:%s*\"map\"") or string.find(part, "\"type\"%s*:%s*\"tileset\"") then - return 0.8 - end - end - if string.find(h, "\"tilewidth\"", 1, true) and (string.find(h, "\"orientation\"", 1, true) or string.find(h, "\"tilesets\"", 1, true)) then - return 0.6 - end - end - return 0 -end -end - -do -- layered/aseprite -local Bytes = __include("core/Bytes") -S["layered/aseprite"] = function(r: Bytes.Reader): number - if r:peekU8(4) == 0xE0 and r:peekU8(5) == 0xA5 then - local d = r:peekU8(12) - if (d == 32 or d == 16 or d == 8) and r:peekU8(13) == 0 then - return 1 - end - return 0.5 - end - return 0 -end -end - -do -- layered/ora -local Bytes = __include("core/Bytes") -local MIME = "image/openraster" -S["layered/ora"] = function(r: Bytes.Reader): number - -- a zip whose first (stored) entry is "mimetype" holding image/openraster - if r:peek(4) == "PK\3\4" and r:peek(8, 30) == "mimetype" and r:peek(#MIME, 38) == MIME then - return 1 - end - return 0 -end -end - -do -- layered/psd -local Bytes = __include("core/Bytes") -S["layered/psd"] = function(r: Bytes.Reader): number - local h = r:peek(6) - if string.sub(h, 1, 4) == "8BPS" and (string.sub(h, 5, 6) == "\0\1" or string.sub(h, 5, 6) == "\0\2") then - return 1 - end - return 0 -end -end - -do -- subtitle/ass -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["subtitle/ass"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 64) - if string.match(head, "^%s*%[[Ss]cript [Ii]nfo%]") then - return 1 - end - return 0 -end -end - -do -- subtitle/srt -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -local TIMING = "^%s*(%d+):(%d%d?):(%d%d?)[,.](%d+)%s*%-%->%s*(%d+):(%d%d?):(%d%d?)[,.](%d+)%s*(.-)%s*$" -local function frac(digits: string): number - return (tonumber(digits) :: number) / 10 ^ #digits -end -local function timing(line: string): (number?, number?, string?) - local h1, m1, s1, f1, h2, m2, s2, f2, rest = string.match(line, TIMING) - if not h1 then - return nil, nil, nil - end - local a = tonumber(h1) :: number * 3600 + tonumber(m1) :: number * 60 + tonumber(s1) :: number + frac(f1 :: string) - local b = tonumber(h2) :: number * 3600 + tonumber(m2) :: number * 60 + tonumber(s2) :: number + frac(f2 :: string) - return a, b, rest -end -S["subtitle/srt"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 512) - head = string.gsub(head, "\r", "\n") - local first, second = string.match(head, "^%s*([^\n]*)\n([^\n]*)") - if first and string.match(first, "^%d+%s*$") and second and timing(second) then - return 0.9 - end - if first and timing(first) then - return 0.6 - end - return 0 -end -end - -do -- subtitle/vtt -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["subtitle/vtt"] = function(r: Bytes.Reader): number - local head = Sniff.text(r, 10) - if string.sub(head, 1, 6) == "WEBVTT" then - local c = string.sub(head, 7, 7) - if c == "" or c == " " or c == "\t" or c == "\n" or c == "\r" then - return 1 - end - end - return 0 -end -end - -do -- music/669 -local Bytes = __include("core/Bytes") -local function validHeader(r: Bytes.Reader): boolean - if r:size() < 497 then - return false - end - local magic = r:peek(2) - if magic ~= "if" and magic ~= "JN" then - return false - end - local nsmp, npat, restart = r:peekU8(110), r:peekU8(111), r:peekU8(112) - if nsmp > 64 or restart >= 128 or npat > 128 then - return false - end - local bad = 0 - for i = 2, 109 do - local c = r:peekU8(i) - if c > 0 and c <= 31 then - bad += 1 - if bad > 40 then - return false - end - end - end - for i = 0, 127 do - local o, t, b = r:peekU8(113 + i), r:peekU8(241 + i), r:peekU8(369 + i) - if (o >= 128 and o < 0xFE) or (o < 128 and t == 0) or t > 15 or b >= 64 then - return false - end - end - return true -end -S["music/669"] = function(r: Bytes.Reader): number - return if validHeader(r) then 0.6 else 0 -end -end - -do -- music/ahx -local Bytes = __include("core/Bytes") -S["music/ahx"] = function(r: Bytes.Reader): number - local m = r:peek(4) - return if m and #m == 4 and string.sub(m, 1, 3) == "THX" and string.byte(m, 4) < 3 then 1 else 0 -end -end - -do -- music/far -local Bytes = __include("core/Bytes") -S["music/far"] = function(r: Bytes.Reader): number - if r:size() >= 98 and r:peek(4) == "FAR\xFE" and r:peek(3, 44) == "\r\n\x1A" and r:peekU8(47) + r:peekU8(48) * 256 >= 98 then - return 1 - end - return 0 -end -end - -do -- music/hmp -local Bytes = __include("core/Bytes") -local HMI_MAGIC = "HMI-MIDISONG061595" -S["music/hmp"] = function(r: Bytes.Reader): number - return if r:peek(8) == "HMIMIDIP" or r:peek(18) == HMI_MAGIC then 1 else 0 -end -end - -do -- music/hvl -local Bytes = __include("core/Bytes") -S["music/hvl"] = function(r: Bytes.Reader): number - local m = r:peek(4) - return if m and #m == 4 and string.sub(m, 1, 3) == "HVL" and string.byte(m, 4) <= 1 then 1 else 0 -end -end - -do -- music/it -local Bytes = __include("core/Bytes") -S["music/it"] = function(r: Bytes.Reader): number - return if r:peek(4) == "IMPM" then 1 else 0 -end -end - -do -- music/med -local Bytes = __include("core/Bytes") -local function validHeader(r: Bytes.Reader): boolean - if r:size() < 52 or r:peek(3) ~= "MMD" then - return false - end - local v = r:peekU8(3) - if v < 0x30 or v > 0x33 then - return false - end - local h = r:sub(8, 44) - local songOff = h:u32be() - h:skip(4) - local blockOff = h:u32be() - h:skip(4) - local smpOff = h:u32be() - return songOff >= 52 and songOff + 63 * 8 + 284 <= r:size() and blockOff >= 52 and (smpOff == 0 or smpOff >= 52) -end -S["music/med"] = function(r: Bytes.Reader): number - return if validHeader(r) then 1 else 0 -end -end - -do -- music/midi -local Bytes = __include("core/Bytes") -S["music/midi"] = function(r: Bytes.Reader): number - if r:peek(4) == "MThd" then - return 1 - end - if r:peek(4) == "RIFF" and r:peek(4, 8) == "RMID" then - return 1 - end - return 0 -end -end - -do -- music/mod -local Bytes = __include("core/Bytes") -local FIXED: { [string]: number } = { - ["M.K."] = 4, - ["M!K!"] = 4, - ["M&K!"] = 4, - ["N.T."] = 4, - ["FLT4"] = 4, - ["FLT8"] = 8, - ["CD81"] = 8, - ["OKTA"] = 8, - ["OCTA"] = 8, - ["EXO4"] = 4, - ["EXO8"] = 8, -} -local function signatureChannels(sig: string): number? - local fixed = FIXED[sig] - if fixed then - return fixed - end - local d = string.match(sig, "^(%d)CHN$") - if d then - local n = tonumber(d) :: number - return if n >= 1 then n else nil - end - local dd = string.match(sig, "^(%d%d)C[HN]$") - if dd then - local n = tonumber(dd) :: number - return if n >= 1 and n <= 32 then n else nil - end - local t = string.match(sig, "^TDZ(%d)$") - if t then - local n = tonumber(t) :: number - return if n >= 1 then n else nil - end - return nil -end -S["music/mod"] = function(r: Bytes.Reader): number - if r:size() < 1084 then - return 0 - end - local sig = r:peek(4, 1080) - if signatureChannels(sig) then - return 0.8 - end - return 0 -end -end - -do -- music/mtm -local Bytes = __include("core/Bytes") -S["music/mtm"] = function(r: Bytes.Reader): number - if r:size() >= 66 and r:peek(3) == "MTM" and r:peekU8(3) < 0x20 and r:peekU8(33) >= 1 and r:peekU8(33) <= 32 then - return 1 - end - return 0 -end -end - -do -- music/mus -local Bytes = __include("core/Bytes") -S["music/mus"] = function(r: Bytes.Reader): number - return if r:peek(4) == "MUS\x1a" then 1 else 0 -end -end - -do -- music/okt -local Bytes = __include("core/Bytes") -S["music/okt"] = function(r: Bytes.Reader): number - return if r:peek(8) == "OKTASONG" then 1 else 0 -end -end - -do -- music/ptm -local Bytes = __include("core/Bytes") -local function validHeader(r: Bytes.Reader): boolean - if r:size() < 608 or r:peek(4, 44) ~= "PTMF" or r:peekU8(28) ~= 26 or r:peekU8(30) > 2 then - return false - end - local h = r:sub(32, 10) - local nord, nsmp, npat, nch, flags = h:u16le(), h:u16le(), h:u16le(), h:u16le(), h:u16le() - return flags == 0 and nch >= 1 and nch <= 32 and nord >= 1 and nord <= 256 and nsmp >= 1 and nsmp <= 255 and npat >= 1 and npat <= 128 -end -S["music/ptm"] = function(r: Bytes.Reader): number - return if validHeader(r) then 1 else 0 -end -end - -do -- music/s3m -local Bytes = __include("core/Bytes") -S["music/s3m"] = function(r: Bytes.Reader): number - if r:size() >= 48 and r:peek(4, 44) == "SCRM" then - return 1 - end - return 0 -end -end - -do -- music/sf2 -local Bytes = __include("core/Bytes") -local SoundFont = lazy(function() - return __include("codecs/audio/SoundFont") -end) -S["music/sf2"] = function(r: Bytes.Reader): number - return if SoundFont.sniff(r) then 1 else 0 -end -end - -do -- music/stm -local Bytes = __include("core/Bytes") -local function validHeader(r: Bytes.Reader): boolean - if r:size() < 48 then - return false - end - local eof, ftype, major, minor = r:peekU8(28), r:peekU8(29), r:peekU8(30), r:peekU8(31) - local npat, gv = r:peekU8(33), r:peekU8(34) - if ftype ~= 2 or (eof ~= 0x1A and eof ~= 2) or major ~= 2 or (minor ~= 0 and minor ~= 10 and minor ~= 20 and minor ~= 21) then - return false - end - if npat > 64 or (gv > 64 and gv ~= 0x58) then - return false - end - for i = 20, 27 do - local c = r:peekU8(i) - if c < 0x20 or c >= 0x7F then - return false - end - end - return true -end -S["music/stm"] = function(r: Bytes.Reader): number - return if validHeader(r) then 0.7 else 0 -end -end - -do -- music/ult -local Bytes = __include("core/Bytes") -S["music/ult"] = function(r: Bytes.Reader): number - local v = r:peekU8(14) - if r:size() >= 48 and r:peek(14) == "MAS_UTrack_V00" and v >= 0x31 and v <= 0x34 then - return 1 - end - return 0 -end -end - -do -- music/umx -local Bytes = __include("core/Bytes") -local MAGIC = "\xC1\x83\x2A\x9E" -type Header = { version: number, nameCount: number, nameOffset: number, exportCount: number, exportOffset: number, importCount: number, importOffset: number } -local function header(r: Bytes.Reader): Header? - if r:size() < 36 or r:peek(4) ~= MAGIC then - return nil - end - local h = r:sub(4, 32) - local version = h:u16le() - h:skip(6) - local hd: Header = { - version = version, - nameCount = h:u32le(), - nameOffset = h:u32le(), - exportCount = h:u32le(), - exportOffset = h:u32le(), - importCount = h:u32le(), - importOffset = h:u32le(), - } - if h.err or hd.nameOffset < 36 or hd.exportOffset < 36 or hd.importOffset < 36 then - return nil - end - if hd.nameCount == 0 or hd.exportCount == 0 or hd.importCount == 0 or hd.nameCount > 2 ^ 20 or hd.exportCount > 2 ^ 20 or hd.importCount > 2 ^ 20 then - return nil - end - return hd -end -local function index(r: Bytes.Reader): number - local b = r:u8() - local neg = b >= 0x80 - local v = b % 64 - if bit32.band(b, 0x40) ~= 0 then - local shift = 6 - repeat - b = r:u8() - v += (b % 128) * 2 ^ shift - shift += 7 - until b < 0x80 or shift >= 32 - end - return if neg then -v else v -end -local function names(r: Bytes.Reader, h: Header): { string } - local list = {} - local nr = r:sub(h.nameOffset) - for _ = 1, math.min(h.nameCount, 65536) do - if nr:remaining() < 5 then - break - end - if h.version >= 64 then - index(nr) - end - table.insert(list, string.lower(nr:cstring(1024))) - nr:skip(4) - end - return list -end -S["music/umx"] = function(r: Bytes.Reader): number - local h = header(r) - if not h then - return 0 - end - return if table.find(names(r, h), "music") then 1 else 0.3 -end -end - -do -- music/xm -local Bytes = __include("core/Bytes") -local MAGIC = "Extended Module: " -S["music/xm"] = function(r: Bytes.Reader): number - return if r:peek(17) == MAGIC then 1 else 0 -end -end - -do -- music/xmi -local Bytes = __include("core/Bytes") -S["music/xmi"] = function(r: Bytes.Reader): number - local id, kind = r:peek(4), r:peek(4, 8) - if id == "FORM" and (kind == "XDIR" or kind == "XMID") then - return 1 - end - return if id == "CAT " and kind == "XMID" then 0.9 else 0 -end -end - -do -- playlist/m3u -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -S["playlist/m3u"] = function(r: Bytes.Reader): number - local s = Sniff.text(r, 512) - s = (string.match(s, "^%s*(.*)$") :: string) - if string.sub(s, 1, 7) == "#EXTM3U" then - return 0.95 - end - if string.find(s, "^#EXTINF:") or string.find(s, "^#EXT%-X%-") then - return 0.8 - end - return 0 -end -end - -do -- playlist/pls -local Sniff = __include("core/Sniff") -local Bytes = __include("core/Bytes") -local Text = lazy(function() - return __include("codecs/text/Text") -end) -S["playlist/pls"] = function(r: Bytes.Reader): number - local s = Sniff.text(r, 64) - local first = string.match(s, "^%s*([^\r\n]*)") - return if first and string.lower(Text.trim(first)) == "[playlist]" then 0.95 else 0 -end -end - -do -- playlist/xspf -local Bytes = __include("core/Bytes") -local NS = "http://xspf.org/ns/0/" -S["playlist/xspf"] = function(r: Bytes.Reader): number - local s = r:peek(1024) - local i = string.find(s, "<%w*:?playlist[%s>]") - if i and string.find(s, NS, 1, true) then - return 0.95 - end - return 0 -end -end - -return S -end -end - - - - - - archive_1 - --!optimize 2 ---!nocheck --- rosetta chunk archive_1 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 33 modules (3 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk archive_7z (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["archive/7z"] = function() @@ -80385,6 +77006,19 @@ end return Adf end +end + + + + + + archive_applesingle + --!optimize 2 +--!nocheck +-- rosetta chunk archive_applesingle (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/applesingle"] = function() -- archive/applesingle: AppleSingle (0x00051600) / AppleDouble (0x00051607) v1 and v2 (RFC 1740): data fork (1), @@ -81184,6 +77818,19 @@ end return Arj end +end + + + + + + archive_binhex + --!optimize 2 +--!nocheck +-- rosetta chunk archive_binhex (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 6 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/binhex"] = function() -- archive/binhex: BinHex 4.0 (.hqx; RFC 1741 notes): 6-bit text, RLE90, header and forks each with CRC-16/XMODEM, as @@ -82194,6 +78841,19 @@ end return CpioFormat end +end + + + + + + archive_d64 + --!optimize 2 +--!nocheck +-- rosetta chunk archive_d64 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/d64"] = function() -- archive/d64: Commodore D64 (1541: 35 / 40 / 42 tracks, error block), D71, D81 (Peter Schepers' notes); PETSCII names @@ -83101,6 +79761,19 @@ end return Iso end +end + + + + + + archive_lha + --!optimize 2 +--!nocheck +-- rosetta chunk archive_lha (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/lha"] = function() -- archive/lha: LHA / LZH (and LArc .lzs; Yoshizaki's LHa notes, lhasa's lha_file_header.c, ISC): header levels 0-3, @@ -84068,6 +80741,19 @@ end return MacBinary end +end + + + + + + archive_mpq + --!optimize 2 +--!nocheck +-- rosetta chunk archive_mpq (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/mpq"] = function() -- archive/mpq: Blizzard MPQ ("The MoPaQ Archive Format", Olbrantz / Roy; StormLib docs; no code taken). Supports: @@ -84997,6 +81683,19 @@ end return Rpm end +end + + + + + + archive_tar + --!optimize 2 +--!nocheck +-- rosetta chunk archive_tar (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/tar"] = function() -- archive/tar: tar archives (ustar, pax, GNU long names; containers/Tar). Supports: read (lazy), write from any @@ -85932,6 +82631,19 @@ end return Vpk end +end + + + + + + archive_vswap + --!optimize 2 +--!nocheck +-- rosetta chunk archive_vswap (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/vswap"] = function() -- archive/vswap: Wolfenstein 3D / Spear of Destiny page files (VSWAP.WL1 / .WL6 / .SOD / .SDM: u16 chunks, sprite @@ -86758,6 +83470,19 @@ end return Picture end +end + + + + + + archive_wad2 + --!optimize 2 +--!nocheck +-- rosetta chunk archive_wad2 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/wad2"] = function() -- archive/wad2: Quake WAD2 and Half-Life WAD3 texture / graphics WADs (wad.h of the Quake source, the GoldSrc WAD3 @@ -87140,19 +83865,6 @@ end return Xz end -end - - - - - - archive_2 - --!optimize 2 ---!nocheck --- rosetta chunk archive_2 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["archive/yenc"] = function() -- archive/yenc: yEnc 1.3 (=ybegin / =ypart / =yend, byte + 42, "=" escapes; Jürgen Helbing's draft): parts in one text @@ -87740,6 +84452,19 @@ Zip.Container = Container return Zip end +end + + + + + + archive_zoo + --!optimize 2 +--!nocheck +-- rosetta chunk archive_zoo (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["archive/zoo"] = function() -- archive/zoo: Zoo 1.x / 2.x (zoo 2.10's zoo.h / ar.h): directory entries type 1 and 2, methods 0 stored, 1 LZW @@ -88004,13 +84729,13 @@ end - + - audio + audio_aac --!optimize 2 --!nocheck --- rosetta chunk audio (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 29 modules (5 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk audio_aac (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["audio/aac"] = function() @@ -88751,6 +85476,19 @@ end return Adx end +end + + + + + + audio_aiff + --!optimize 2 +--!nocheck +-- rosetta chunk audio_aiff (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/aiff"] = function() @@ -89726,6 +86464,19 @@ end return Brstm end +end + + + + + + audio_caf + --!optimize 2 +--!nocheck +-- rosetta chunk audio_caf (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/caf"] = function() @@ -90393,6 +87144,19 @@ end return Caf end +end + + + + + + audio_flac + --!optimize 2 +--!nocheck +-- rosetta chunk audio_flac (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/flac"] = function() @@ -91477,6 +88241,19 @@ end return M4a end +end + + + + + + audio_mp3 + --!optimize 2 +--!nocheck +-- rosetta chunk audio_mp3 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/mp3"] = function() @@ -92468,6 +89245,19 @@ end return Tags end +end + + + + + + audio_mpc + --!optimize 2 +--!nocheck +-- rosetta chunk audio_mpc (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/mpc"] = function() @@ -93354,6 +90144,19 @@ end return Tta end +end + + + + + + audio_vag + --!optimize 2 +--!nocheck +-- rosetta chunk audio_vag (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/vag"] = function() @@ -93854,6 +90657,19 @@ end return Voc end +end + + + + + + audio_vorbis + --!optimize 2 +--!nocheck +-- rosetta chunk audio_vorbis (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/vorbis"] = function() @@ -95122,6 +91938,19 @@ Encode.BOOKS = BOOKS return Encode end +end + + + + + + audio_wav + --!optimize 2 +--!nocheck +-- rosetta chunk audio_wav (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["audio/wav"] = function() @@ -96134,12 +92963,12 @@ end - + - cad + cad_step --!optimize 2 --!nocheck --- rosetta chunk cad (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- rosetta chunk cad_step (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. -- 4 modules (2 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) @@ -97569,13 +94398,13 @@ end - + - codecs_audio + codecs_audio_Ac3 --!optimize 2 --!nocheck --- rosetta chunk codecs_audio (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 21 modules (10 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk codecs_audio_Ac3 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["codecs/audio/Ac3"] = function() @@ -98725,6 +95554,773 @@ end return T end +end + + + + + + codecs_audio_Adpcm + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_audio_Adpcm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) +__FILES["codecs/audio/Adpcm"] = @native function() + + + +-- codecs/audio/Adpcm: the 4-bit ADPCM family, decode (and encode where it is cheap). +-- ADX, PS-ADPCM and Nintendo DSP decoding follow vgmstream r2117 (ISC, licenses/vgmstream-LICENSE.txt) bit-exactly: the +-- ADX scale + 1 and version 3 rounding, PS-ADPCM's float filter (exact in integers below 2^17), DSP's 1024 rounding. +local readu8, readi16, readu16, readi32 = buffer.readu8, buffer.readi16, buffer.readu16, buffer.readi32 +local writef32, readf32, writei32, writeu8, writeu16 = buffer.writef32, buffer.readf32, buffer.writei32, buffer.writeu8, buffer.writeu16 +local band, rshift, bor, lshift = bit32.band, bit32.rshift, bit32.bor, bit32.lshift +local floor = math.floor + +local Adpcm = {} + +local IMA_STEP = { + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, + 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, + 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, + 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767, +} +local IMA_ADJ = { -1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8 } +-- IMA_DIFF[index * 8 + (nibble & 7) + 1]: the shift-and-add difference (step/8 + bits of step/4, step/2, step), as +-- the IMA reference computes it (not (2n + 1) * step / 8, which rounds differently) +local IMA_DIFF = table.create(89 * 8, 0) +-- IMA_NEXT[index * 16 + nibble + 1]: the next step index +local IMA_NEXT = table.create(89 * 16, 0) +for i = 0, 88 do + local step = IMA_STEP[i + 1] + for n = 0, 7 do + local d = rshift(step, 3) + if band(n, 1) ~= 0 then + d += rshift(step, 2) + end + if band(n, 2) ~= 0 then + d += rshift(step, 1) + end + if band(n, 4) ~= 0 then + d += step + end + IMA_DIFF[i * 8 + n + 1] = d + end + for n = 0, 15 do + IMA_NEXT[i * 16 + n + 1] = math.clamp(i + IMA_ADJ[n + 1], 0, 88) + end +end +Adpcm.IMA_STEP = IMA_STEP + +-- IMA nibble q is in byte p + q // 2, the low half first unless hi +@native function Adpcm.ima(src: buffer, p: number, q0: number, qs: number, count: number, hi: boolean, st: buffer, so: number, + dst: buffer, d: number, ds: number) + local pred = readi32(st, so) + local index = math.clamp(readi32(st, so + 4), 0, 88) + local q = q0 + local o = d * 4 + local os = ds * 4 + for _ = 1, count do + local b = readu8(src, p + rshift(q, 1)) + local nib + if (band(q, 1) == 0) == hi then + nib = rshift(b, 4) + else + nib = band(b, 15) + end + local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] + if nib >= 8 then + pred -= diff + if pred < -32768 then + pred = -32768 + end + else + pred += diff + if pred > 32767 then + pred = 32767 + end + end + index = IMA_NEXT[index * 16 + nib + 1] + writef32(dst, o, pred / 32768) + o += os + q += qs + end + writei32(st, so, pred) + writei32(st, so + 4, index) +end + +-- Apple ima4: 34 bytes: a big-endian header (the predictor's top 9 bits, 7-bit step index), 64 nibbles low first; +-- Apple's decoders keep the full-precision predictor while the header agrees (same step index, within 127) +@native function Adpcm.imaQt(src: buffer, p: number, st: buffer, so: number, dst: buffer, d: number, ds: number) + local h = readu8(src, p) * 256 + readu8(src, p + 1) + local pred = band(h, 0xFF80) + if pred >= 32768 then + pred -= 65536 + end + local index = band(h, 0x7F) + if index ~= readi32(st, so + 4) or math.abs(pred - readi32(st, so)) > 0x7F then + writei32(st, so, pred) + writei32(st, so + 4, index) + end + Adpcm.ima(src, p + 2, 0, 1, 64, false, st, so, dst, d, ds) +end + +-- Microsoft IMA block: per channel s16 predictor (= the first sample), u8 step index, pad; then 4-byte groups +-- (8 nibbles, low first) per channel in turn +@native function Adpcm.imaWav(src: buffer, off: number, avail: number, ch: number, spb: number, dst: buffer, d: number): number + if avail < 4 * ch then + return 0 + end + local groups = (avail - 4 * ch) // (4 * ch) + local frames = math.min(spb, 1 + groups * 8) + local o = d * 4 + for c = 0, ch - 1 do + local pred = readi16(src, off + c * 4) + local index = math.min(readu8(src, off + c * 4 + 2), 88) + writef32(dst, o + c * 4, pred / 32768) + local f = 1 + local g = 0 + while f < frames do + local p = off + 4 * ch + (g * ch + c) * 4 + local k = 0 + while k < 8 and f < frames do + local b = readu8(src, p + rshift(k, 1)) + local nib = if band(k, 1) == 0 then band(b, 15) else rshift(b, 4) + local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] + if nib >= 8 then + pred -= diff + if pred < -32768 then + pred = -32768 + end + else + pred += diff + if pred > 32767 then + pred = 32767 + end + end + index = IMA_NEXT[index * 16 + nib + 1] + writef32(dst, o + (f * ch + c) * 4, pred / 32768) + f += 1 + k += 1 + end + g += 1 + end + end + return frames +end + +local MS_ADAPT = { 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 } +Adpcm.MS_COEF1 = { 256, 512, 0, 192, 240, 460, 392 } +Adpcm.MS_COEF2 = { 0, -256, 0, 64, 0, -208, -232 } + +-- MS ADPCM block: per channel u8 predictor index, s16 delta, s16 sample 1, s16 sample 2 (each field for every channel +-- in turn), then nibbles high first, channels interleaved per nibble; coefficients 256 = 1.0 +@native function Adpcm.msBlock(src: buffer, off: number, avail: number, ch: number, spb: number, dst: buffer, d: number, + coefs: buffer, ncoef: number, state: buffer): number + local hdr = 7 * ch + if avail < hdr or ncoef < 1 then + return 0 + end + local frames = math.min(spb, 2 + ((avail - hdr) * 2) // ch) + local o = d * 4 + for c = 0, ch - 1 do + local pi = math.min(readu8(src, off + c), ncoef - 1) + local idelta = readi16(src, off + ch + c * 2) + local s1 = readi16(src, off + 3 * ch + c * 2) + local s2 = readi16(src, off + 5 * ch + c * 2) + local so = c * 20 + writei32(state, so, readi32(coefs, pi * 8)) + writei32(state, so + 4, readi32(coefs, pi * 8 + 4)) + writei32(state, so + 8, idelta) + writei32(state, so + 12, s1) + writei32(state, so + 16, s2) + writef32(dst, o + c * 4, s2 / 32768) + if frames > 1 then + writef32(dst, o + (ch + c) * 4, s1 / 32768) + end + end + local total = (frames - 2) * ch + for k = 0, total - 1 do + local b = readu8(src, off + hdr + rshift(k, 1)) + local nib = if band(k, 1) == 0 then rshift(b, 4) else band(b, 15) + local so = (k % ch) * 20 + local c1, c2 = readi32(state, so), readi32(state, so + 4) + local idelta = readi32(state, so + 8) + local s1, s2 = readi32(state, so + 12), readi32(state, so + 16) + local p = s1 * c1 + s2 * c2 + p = if p >= 0 then p // 256 else -((-p) // 256) + p += (if nib >= 8 then nib - 16 else nib) * idelta + if p > 32767 then + p = 32767 + elseif p < -32768 then + p = -32768 + end + idelta = (MS_ADAPT[nib + 1] * idelta) // 256 + if idelta < 16 then + idelta = 16 + elseif idelta > 2796202 then -- INT_MAX / 768 + idelta = 2796202 + end + writei32(state, so + 8, idelta) + writei32(state, so + 12, p) + writei32(state, so + 16, s1) + writef32(dst, o + (2 * ch + k) * 4, p / 32768) + end + return frames +end + +local F32 = buffer.create(4) +@native local function f32(x: number): number + writef32(F32, 0, x) + return readf32(F32, 0) +end + +-- coef1, coef2 (12 fractional bits): the 2-pole high-pass predictor from the header's cutoff, in single precision as +-- CRI's decoders (and vgmstream) compute it +@native function Adpcm.adxCoefs(cutoff: number, rate: number): (number, number) + if rate <= 0 then + return 0, 0 + end + local z = f32(math.cos(f32(2 * math.pi * cutoff / rate))) + local a = f32(math.sqrt(2) - z) + local b = f32(math.sqrt(2) - 1) + local c = f32(f32(a - f32(math.sqrt(f32(f32(a + b) * f32(a - b))))) / b) + local c1 = c * 8192 + local c2 = f32(c * c) * -4096 + c1 = if c1 >= 0 then floor(c1) else -floor(-c1) + c2 = if c2 >= 0 then floor(c2) else -floor(-c2) + return c1, c2 +end + +-- ADX frame: s16 big-endian scale, 32 nibbles high first. v3 shifts each product on its own; scale 0x8001 (CRI's end +-- marker) decodes as silence +@native function Adpcm.adx(src: buffer, p: number, pstride: number, nframes: number, c1: number, c2: number, v3: boolean, + st: buffer, so: number, dst: buffer, d: number, ds: number) + local h1, h2 = readi32(st, so), readi32(st, so + 4) + local o = d * 4 + local os = ds * 4 + for f = 0, nframes - 1 do + local fp = p + f * pstride + local scale = readu8(src, fp) * 256 + readu8(src, fp + 1) + if scale == 0x8001 then + scale = 0 + elseif scale >= 32768 then + scale -= 65535 -- the signed value + 1 + else + scale += 1 + end + for k = 0, 31 do + local b = readu8(src, fp + 2 + rshift(k, 1)) + local n = if band(k, 1) == 0 then rshift(b, 4) else band(b, 15) + if n >= 8 then + n -= 16 + end + local s + if v3 then + s = n * scale + (c1 * h1) // 4096 + (c2 * h2) // 4096 + else + s = n * scale + (c1 * h1 + c2 * h2) // 4096 + end + if s > 32767 then + s = 32767 + elseif s < -32768 then + s = -32768 + end + h2 = h1 + h1 = s + writef32(dst, o, s / 32768) + o += os + end + end + writei32(st, so, h1) + writei32(st, so + 4, h2) +end + +local PSX1 = { 0, 60, 115, 98, 122 } +local PSX2 = { 0, 0, -52, -55, -60 } + +-- the filter term (c1 * h1 + c2 * h2) / 64 * 256 truncated, as vgmstream's single-precision float code computes it: +-- exact in integers while the products fit a float's 24 bits +@native local function psxPred(f: number, h1: number, h2: number): number + local x = PSX1[f] * h1 + PSX2[f] * h2 + if h1 > -65536 and h1 < 65536 and h2 > -65536 and h2 < 65536 then + return 4 * x + end + local v = f32(f32(f32(PSX1[f] / 64) * h1) + f32(f32(PSX2[f] / 64) * h2)) * 256 + return if v >= 0 then floor(v) else -floor(-v) +end + +-- PS-ADPCM frame: filter << 4 | shift, flags, 28 nibbles low first. Filters past 4 decode as 0 and shifts past 12 as 9 +-- (as vgmstream); flags 7 is silence; the history keeps the unclipped value +@native function Adpcm.psx(src: buffer, p: number, pstride: number, nframes: number, st: buffer, so: number, dst: buffer, + d: number, ds: number) + local h1, h2 = readi32(st, so), readi32(st, so + 4) + local o = d * 4 + local os = ds * 4 + for f = 0, nframes - 1 do + local fp = p + f * pstride + local head = readu8(src, fp) + local filter = rshift(head, 4) + local shift = band(head, 15) + if filter > 4 then + filter = 0 + end + if shift > 12 then + shift = 9 + end + local mul = 2 ^ (20 - shift) + local fi = filter + 1 + local silent = band(readu8(src, fp + 1), 15) == 7 + for k = 0, 27 do + local s = 0 + if not silent then + local b = readu8(src, fp + 2 + rshift(k, 1)) + local n = if band(k, 1) == 0 then band(b, 15) else rshift(b, 4) + if n >= 8 then + n -= 16 + end + s = (n * mul + psxPred(fi, h1, h2)) // 256 + end + h2 = h1 + h1 = s + if s > 32767 then + s = 32767 + elseif s < -32768 then + s = -32768 + end + writef32(dst, o, s / 32768) + o += os + end + end + writei32(st, so, h1) + writei32(st, so + 4, h2) +end + +-- DSP frame: predictor << 4 | scale shift, 14 nibbles high first; coefs 8 pairs, 11 fractional bits; a predictor +-- index past 7 uses pair 7 +@native function Adpcm.dsp(src: buffer, p: number, count: number, coefs: buffer, co: number, st: buffer, so: number, + dst: buffer, d: number, ds: number) + local h1, h2 = readi32(st, so), readi32(st, so + 4) + local o = d * 4 + local os = ds * 4 + local done = 0 + local fp = p + while done < count do + local head = readu8(src, fp) + local pi = math.min(rshift(head, 4), 7) + local scale = 2 ^ band(head, 15) * 2048 + local c1, c2 = readi32(coefs, co + pi * 8), readi32(coefs, co + pi * 8 + 4) + local n14 = math.min(14, count - done) + for k = 0, n14 - 1 do + local b = readu8(src, fp + 1 + rshift(k, 1)) + local n = if band(k, 1) == 0 then rshift(b, 4) else band(b, 15) + if n >= 8 then + n -= 16 + end + local s = (n * scale + 1024 + c1 * h1 + c2 * h2) // 2048 + if s > 32767 then + s = 32767 + elseif s < -32768 then + s = -32768 + end + h2 = h1 + h1 = s + writef32(dst, o, s / 32768) + o += os + end + done += n14 + fp += 8 + end + writei32(st, so, h1) + writei32(st, so + 4, h2) +end + +@native local function toS16(x: number): number + local v = floor(x * 32768 + 0.5) + if v ~= v then + return 0 + elseif v > 32767 then + return 32767 + elseif v < -32768 then + return -32768 + end + return v +end +Adpcm.toS16 = toS16 + +@native local function imaNibble(x: number, pred: number, index: number): number + local base = index * 8 + 1 + local best, bestErr = 0, math.huge + for m = 0, 7 do + local diff = IMA_DIFF[base + m] + local up = math.min(pred + diff, 32767) + local e = math.abs(x - up) + if e < bestErr then + best, bestErr = m, e + end + local down = math.max(pred - diff, -32768) + e = math.abs(x - down) + if e < bestErr then + best, bestErr = m + 8, e + end + end + return best +end + +@native function Adpcm.imaEncode(x: buffer, xi: number, xs: number, count: number, st: buffer, so: number, out: buffer, + p: number, q0: number, qs: number, hi: boolean) + local pred = readi32(st, so) + local index = math.clamp(readi32(st, so + 4), 0, 88) + local q = q0 + for i = 0, count - 1 do + local v = toS16(readf32(x, (xi + i * xs) * 4)) + local nib = imaNibble(v, pred, index) + local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] + pred = if nib >= 8 then math.max(pred - diff, -32768) else math.min(pred + diff, 32767) + index = IMA_NEXT[index * 16 + nib + 1] + local bp = p + rshift(q, 1) + local b = readu8(out, bp) + if (band(q, 1) == 0) == hi then + b = bor(band(b, 0x0F), lshift(nib, 4)) + else + b = bor(band(b, 0xF0), nib) + end + writeu8(out, bp, b) + q += qs + end + writei32(st, so, pred) + writei32(st, so + 4, index) +end + +-- Microsoft IMA block: spb = 1 + 8k frames, 4 * ch + (spb - 1) / 2 * ch bytes +@native function Adpcm.imaWavEncode(x: buffer, xf: number, n: number, ch: number, spb: number, st: buffer, out: buffer, off: number) + local groups = (spb - 1) // 8 + for c = 0, ch - 1 do + local so = c * 8 + local first = if n > 0 then toS16(readf32(x, (xf * ch + c) * 4)) else 0 + writei32(st, so, first) + local index = math.clamp(readi32(st, so + 4), 0, 88) + writei32(st, so + 4, index) + buffer.writei16(out, off + c * 4, first) + writeu8(out, off + c * 4 + 2, index) + writeu8(out, off + c * 4 + 3, 0) + local pred = first + for g = 0, groups - 1 do + local gp = off + 4 * ch + (g * ch + c) * 4 + for k = 0, 7 do + local f = 1 + g * 8 + k + local v = if f < n then toS16(readf32(x, ((xf + f) * ch + c) * 4)) else pred + local nib = imaNibble(v, pred, index) + local diff = IMA_DIFF[index * 8 + band(nib, 7) + 1] + pred = if nib >= 8 then math.max(pred - diff, -32768) else math.min(pred + diff, 32767) + index = IMA_NEXT[index * 16 + nib + 1] + local bp = gp + rshift(k, 1) + if band(k, 1) == 0 then + writeu8(out, bp, nib) + else + writeu8(out, bp, bor(readu8(out, bp), lshift(nib, 4))) + end + end + end + writei32(st, so + 4, index) + end +end + +@native local function msTrial(xs: { number }, n: number, c1: number, c2: number, delta0: number, nibs: { number }?): number + local s1, s2 = xs[2], xs[1] + local idelta = delta0 + local err = 0 + for i = 3, n do + local p = s1 * c1 + s2 * c2 + p = if p >= 0 then p // 256 else -((-p) // 256) + local e = xs[i] - p + local nib = if e >= 0 then (e + idelta // 2) // idelta else -((-e + idelta // 2) // idelta) + nib = math.clamp(nib, -8, 7) + local v = math.clamp(p + nib * idelta, -32768, 32767) + err += (xs[i] - v) * (xs[i] - v) + if nibs then + nibs[i] = band(nib, 15) + end + idelta = math.clamp((MS_ADAPT[band(nib, 15) + 1] * idelta) // 256, 16, 2796202) + s2 = s1 + s1 = v + end + return err +end + +-- MS ADPCM block (standard 7 coefficient pairs): 7 * ch + (spb - 2) * ch / 2 bytes +@native function Adpcm.msEncode(x: buffer, xf: number, n: number, ch: number, spb: number, out: buffer, off: number) + local C1, C2 = Adpcm.MS_COEF1, Adpcm.MS_COEF2 + local xs = table.create(spb, 0) + local nibs = table.create(spb, 0) + local all = table.create(spb * ch, 0) + for c = 0, ch - 1 do + for i = 1, spb do + xs[i] = if i <= n then toS16(readf32(x, ((xf + i - 1) * ch + c) * 4)) else 0 + end + local sum = 0 + for i = 3, math.min(spb, 10) do + sum += math.abs(xs[i] - xs[i - 1]) + end + local delta0 = math.clamp(sum // 16, 16, 32767) + local best, bestErr = 1, math.huge + for k = 1, 7 do + local e = msTrial(xs, spb, C1[k], C2[k], delta0, nil) + if e < bestErr then + best, bestErr = k, e + end + end + msTrial(xs, spb, C1[best], C2[best], delta0, nibs) + writeu8(out, off + c, best - 1) + writeu16(out, off + ch + c * 2, delta0) + buffer.writei16(out, off + 3 * ch + c * 2, xs[2] or 0) + buffer.writei16(out, off + 5 * ch + c * 2, xs[1]) + for i = 3, spb do + all[(i - 3) * ch + c + 1] = nibs[i] + end + end + local total = (spb - 2) * ch + for k = 0, total - 1, 2 do + writeu8(out, off + 7 * ch + k // 2, all[k + 1] * 16 + (all[k + 2] or 0)) + end +end + +@native local function adxTrial(xs: { number }, scale: number, c1: number, c2: number, h1: number, h2: number, nibs: { number }?): (number, number, number) + local err = 0 + for k = 1, 32 do + local pred = (c1 * h1 + c2 * h2) // 4096 + local e = xs[k] - pred + local n = if e >= 0 then (e + scale // 2) // scale else -((-e + scale // 2) // scale) + n = math.clamp(n, -8, 7) + local s = math.clamp(n * scale + pred, -32768, 32767) + err += (xs[k] - s) * (xs[k] - s) + if nibs then + nibs[k] = band(n, 15) + end + h2 = h1 + h1 = s + end + return err, h1, h2 +end + +-- ADX v4 rounding; the scale is stored minus one as CRI's decoders add it back +-- (v4 rounding, the scale stored minus one as CRI's decoders add it back) at out[p], pstride bytes apart; the frame +@native function Adpcm.adxEncode(x: buffer, xi: number, xs: number, count: number, c1: number, c2: number, st: buffer, so: number, + out: buffer, p: number, pstride: number) + local h1, h2 = readi32(st, so), readi32(st, so + 4) + local v = table.create(32, 0) + local nibs = table.create(32, 0) + for f = 0, (count + 31) // 32 - 1 do + local peak = 0 + local a, b = h1, h2 + for k = 1, 32 do + local i = f * 32 + k - 1 + local s = if i < count then toS16(readf32(x, (xi + i * xs) * 4)) else 0 + v[k] = s + peak = math.max(peak, math.abs(s - (c1 * a + c2 * b) // 4096)) + b = a + a = s + end + local base = math.max(1, (peak + 6) // 7) + local best, bestErr = base, math.huge + for _, m in { 1, 0.75, 1.25, 0.5, 1.6 } do + local sc = math.clamp(floor(base * m + 0.5), 1, 0x7FFF) + local e = adxTrial(v, sc, c1, c2, h1, h2, nil) + if e < bestErr then + best, bestErr = sc, e + end + end + local _, n1, n2 = adxTrial(v, best, c1, c2, h1, h2, nibs) + h1, h2 = n1, n2 + local fp = p + f * pstride + writeu8(out, fp, rshift(best - 1, 8)) + writeu8(out, fp + 1, band(best - 1, 255)) + for k = 0, 15 do + writeu8(out, fp + 2 + k, nibs[k * 2 + 1] * 16 + nibs[k * 2 + 2]) + end + end + writei32(st, so, h1) + writei32(st, so + 4, h2) +end + +@native function Adpcm.psxEncode(x: buffer, xi: number, xs: number, count: number, st: buffer, so: number, out: buffer, + p: number, pstride: number) + local h1, h2 = readi32(st, so), readi32(st, so + 4) + local v = table.create(28, 0) + local nibs = table.create(28, 0) + for f = 0, (count + 27) // 28 - 1 do + for k = 1, 28 do + local i = f * 28 + k - 1 + v[k] = if i < count then toS16(readf32(x, (xi + i * xs) * 4)) else 0 + end + local bestErr, bestHead = math.huge, 0 + for fi = 1, 5 do + for shift = 0, 12 do + local mul = 2 ^ (20 - shift) + local a, b = h1, h2 + local err = 0 + for k = 1, 28 do + local pred = psxPred(fi, a, b) + local n = floor((v[k] * 256 - pred) / mul + 0.5) + n = if n > 7 then 7 elseif n < -8 then -8 else n + local s = (n * mul + pred) // 256 + local c = if s > 32767 then 32767 elseif s < -32768 then -32768 else s + err += (v[k] - c) * (v[k] - c) + if err >= bestErr then + break + end + b = a + a = s + end + if err < bestErr then + bestErr, bestHead = err, (fi - 1) * 16 + shift + end + end + end + local fi, shift = rshift(bestHead, 4) + 1, band(bestHead, 15) + local mul = 2 ^ (20 - shift) + for k = 1, 28 do + local pred = psxPred(fi, h1, h2) + local n = math.clamp(floor((v[k] * 256 - pred) / mul + 0.5), -8, 7) + nibs[k] = band(n, 15) + h2 = h1 + h1 = (n * mul + pred) // 256 + end + local fp = p + f * pstride + writeu8(out, fp, bestHead) + writeu8(out, fp + 1, 0) + for k = 0, 13 do + writeu8(out, fp + 2 + k, nibs[k * 2 + 1] + nibs[k * 2 + 2] * 16) + end + end + writei32(st, so, h1) + writei32(st, so + 4, h2) +end + +-- ModPlug / OpenMPT ADPCM (sample data marked 0xAD): 16 signed byte deltas, then nibbles low first, each adding its +-- delta to a wrapping signed byte; value / 128 +@native function Adpcm.modplug(src: buffer, p: number, count: number, dst: buffer, d: number) + local tab = table.create(16, 0) + for k = 0, 15 do + tab[k + 1] = buffer.readi8(src, p + k) + end + local v = 0 + for i = 0, count - 1 do + local b = readu8(src, p + 16 + rshift(i, 1)) + local nib = if band(i, 1) == 0 then band(b, 15) else rshift(b, 4) + v = (v + tab[nib + 1] + 128) % 256 - 128 + writef32(dst, (d + i) * 4, v / 128) + end +end + +-- 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 }, +} + +@native 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 + +@native 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 + +@native 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 +end __FILES["codecs/audio/Adpcm/Decoder"] = function() @@ -99028,6 +96624,19 @@ end return Decoder end +end + + + + + + codecs_audio_Alac + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_audio_Alac (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/audio/Alac"] = function() @@ -100094,6 +97703,19 @@ end return Encode end +end + + + + + + codecs_audio_Ape + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_audio_Ape (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/audio/Ape"] = function() @@ -101169,6 +98791,19 @@ end return ApeTag end +end + + + + + + codecs_audio_Mdct + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_audio_Mdct (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/audio/Mdct"] = @native function() @@ -101990,6 +99625,19 @@ end return Render end +end + + + + + + codecs_audio_Pcm + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_audio_Pcm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/audio/Pcm"] = function() @@ -102833,6 +100481,19 @@ end return Qoa end +end + + + + + + codecs_audio_Resample + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_audio_Resample (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/audio/Resample"] = @native function() @@ -103817,13 +101478,13 @@ end - + - codecs_compress + codecs_compress_Bzip2 --!optimize 2 --!nocheck --- rosetta chunk codecs_compress (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 11 modules (10 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk codecs_compress_Bzip2 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (3 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["codecs/compress/Bzip2"] = function() @@ -104848,6 +102509,19 @@ end return Lz4 end +end + + + + + + codecs_compress_Lzh + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_compress_Lzh (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (3 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/compress/Lzh"] = @native function() @@ -106154,6 +103828,19 @@ end return Lzx end +end + + + + + + codecs_compress_PackBits + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_compress_PackBits (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (4 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/compress/PackBits"] = @native function() @@ -106858,12 +104545,12 @@ end - + - codecs_entropy + codecs_entropy_Huffman --!optimize 2 --!nocheck --- rosetta chunk codecs_entropy (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- rosetta chunk codecs_entropy_Huffman (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. -- 4 modules (3 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) @@ -107634,13 +105321,13 @@ end - + - codecs_font + codecs_font_Bitmap --!optimize 2 --!nocheck --- rosetta chunk codecs_font (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 6 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk codecs_font_Bitmap (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["codecs/font/Bitmap"] = function() @@ -108635,6 +106322,19 @@ end return GlyphNames end +end + + + + + + codecs_font_TrueType + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_font_TrueType (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/font/TrueType"] = function() -- codecs/font/TrueType: the sfnt container (.ttf, .otf with CFF outlines, .ttc collections) as the standard Font value. @@ -109847,13 +107547,13 @@ end - + - codecs_image + codecs_image_Blend --!optimize 2 --!nocheck --- rosetta chunk codecs_image (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 9 modules (7 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk codecs_image_Blend (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (3 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["codecs/image/Blend"] = @native function() @@ -110602,6 +108302,19 @@ end return Half end +end + + + + + + codecs_image_Miptex + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_image_Miptex (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/image/Miptex"] = function() -- codecs/image/Miptex: Quake / GoldSrc mip textures and the WAD2 / WAD3 lump directory, read and write. @@ -111222,6 +108935,19 @@ end return Pixels end +end + + + + + + codecs_image_Quantize + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_image_Quantize (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/image/Quantize"] = @native function() @@ -111683,6 +109409,19 @@ end return Quantize end +end + + + + + + codecs_image_Raster + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_image_Raster (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/image/Raster"] = @native function() @@ -112380,6 +110119,19 @@ end return Raster end +end + + + + + + codecs_image_Texel + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_image_Texel (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/image/Texel"] = @native function() @@ -112898,17 +110650,338 @@ end return Texture end +__FILES["codecs/image/Yuv"] = @native function() + + + +-- codecs/image/Yuv: planar 4:2:0 Y'CbCr <-> rgba8, BT.601 / BT.709, limited or full range. +-- yuv -> rgb: nearest chroma, swscale's default 16-bit coefficients (within about one level of ffmpeg -pix_fmt rgba); +-- rgb -> yuv: each 2x2 block averaged for the chroma. +local Types = __include("Types") + +local readu8, writeu8, writeu32 = buffer.readu8, buffer.writeu8, buffer.writeu32 +local bcreate = buffer.create +local floor = math.floor + +local Yuv = {} + +-- coefficients (x 65536): r = y' + crv * v; g = y' - cgu * u - cgv * v; b = y' + cbu * u +-- limited: y' = (y - 16) * 255 / 219, chroma scaled by 255 / 224 +local MATRIX: { [string]: { kr: number, kb: number } } = { + bt601 = { kr = 0.299, kb = 0.114 }, + bt709 = { kr = 0.2126, kb = 0.0722 }, +} + +type Coeffs = { ys: number, yo: number, crv: number, cgu: number, cgv: number, cbu: number, cs: number, yt: { number } } + +local cache: { [string]: Coeffs } = {} +@native local function coeffs(range: string?, matrix: string?): Coeffs + local key = (range or "limited") .. (matrix or "bt601") + local c = cache[key] + if c then + return c + end + local m = MATRIX[matrix or "bt601"] or MATRIX.bt601 + local kr, kb = m.kr, m.kb + local kg = 1 - kr - kb + local full = range == "full" + local ys = if full then 1 else 255 / 219 + local cs = if full then 1 else 255 / 224 + c = { + ys = floor(ys * 65536 + 0.5), + yo = if full then 0 else 16, + crv = floor(2 * (1 - kr) * cs * 65536 + 0.5), + cbu = floor(2 * (1 - kb) * cs * 65536 + 0.5), + cgu = floor(2 * (1 - kb) * kb / kg * cs * 65536 + 0.5), + cgv = floor(2 * (1 - kr) * kr / kg * cs * 65536 + 0.5), + cs = cs, + yt = table.create(256, 0), + } + for v = 0, 255 do + c.yt[v + 1] = (c.ys * (v - c.yo) + 32768) // 65536 + 1024 + end + cache[key] = c + return c +end + +local CLIP = bcreate(2304) +for i = 0, 2303 do + writeu8(CLIP, i, math.clamp(i - 1024, 0, 255)) +end +-- CLIP's values shifted into their rgba8 byte (CB carries the alpha); indexes stay within 600..1700 +local CR: { number } = table.create(2304, 0) +local CG: { number } = table.create(2304, 0) +local CB: { number } = table.create(2304, 0) +for i = 1, 2304 do + local v = math.clamp(i - 1024, 0, 255) + CR[i] = v + CG[i] = v * 256 + CB[i] = v * 65536 + 0xff000000 +end + +-- hook: called (through pcall) every 16 rows, a cooperative yield point +@native function Yuv.toRgba(src: buffer, w: number, h: number, uo: number, vo: number, cw: number, range: string?, matrix: string?, out: buffer?, hook: (() -> ())?): buffer + local dst = out or bcreate(w * h * 4) + local c = coeffs(range, matrix) + local crv, cgu, cgv, cbu = c.crv, c.cgu, c.cgv, c.cbu + local yt, cr, cg, cb = c.yt, CR, CG, CB + local ch = (h + 1) // 2 + if buffer.len(src) < vo + cw * ch or buffer.len(dst) < w * h * 4 or uo + cw * ch > buffer.len(src) then + return dst + end + local w2 = w // 2 + local stride = w * 4 + for y = 0, h - 1, 2 do + if hook and y % 16 == 0 and y > 0 then + pcall(hook) + end + local yrow = y * w + local ci = uo + (y // 2) * cw + local dv = vo - uo + local o = yrow * 4 + local two = y + 1 < h + for _ = 1, w2 do + local u = readu8(src, ci) - 128 + local v = readu8(src, ci + dv) - 128 + ci += 1 + local rv = (crv * v + 32768) // 65536 + local gv = -((cgu * u + cgv * v + 32768) // 65536) + local bu = (cbu * u + 32768) // 65536 + local yy = yt[readu8(src, yrow) + 1] + writeu32(dst, o, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) + yy = yt[readu8(src, yrow + 1) + 1] + writeu32(dst, o + 4, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) + if two then + yy = yt[readu8(src, yrow + w) + 1] + writeu32(dst, o + stride, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) + yy = yt[readu8(src, yrow + w + 1) + 1] + writeu32(dst, o + stride + 4, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) + end + yrow += 2 + o += 8 + end + if w % 2 == 1 then + local u = readu8(src, ci) - 128 + local v = readu8(src, ci + dv) - 128 + local rv = (crv * v + 32768) // 65536 + local gv = -((cgu * u + cgv * v + 32768) // 65536) + local bu = (cbu * u + 32768) // 65536 + local yy = yt[readu8(src, yrow) + 1] + writeu32(dst, o, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) + if two then + yy = yt[readu8(src, yrow + w) + 1] + writeu32(dst, o + stride, cr[yy + rv] + cg[yy + gv] + cb[yy + bu]) + end + end + end + return dst +end + +@native function Yuv.fromRgba(src: buffer, w: number, h: number, range: string?, matrix: string?, out: buffer?): buffer + local cw, ch = (w + 1) // 2, (h + 1) // 2 + local uo, vo = w * h, w * h + cw * ch + local dst = out or bcreate(w * h + 2 * cw * ch) + if buffer.len(src) < w * h * 4 or buffer.len(dst) < w * h + 2 * cw * ch then + return dst + end + local m = MATRIX[matrix or "bt601"] or MATRIX.bt601 + local kr, kb = m.kr, m.kb + local kg = 1 - kr - kb + local full = range == "full" + local ysc = if full then 1 else 219 / 255 + local csc = if full then 1 else 224 / 255 + local yof = if full then 0.5 else 16.5 + local yr, yg, yb = floor(kr * ysc * 65536 + 0.5), floor(kg * ysc * 65536 + 0.5), floor(kb * ysc * 65536 + 0.5) + local yoff = floor(yof * 65536) + local ur = floor(-kr / (2 * (1 - kb)) * csc * 65536 + 0.5) + local ug = floor(-kg / (2 * (1 - kb)) * csc * 65536 + 0.5) + local ub = floor(0.5 * csc * 65536 + 0.5) + local vr = ub + local vg = floor(-kg / (2 * (1 - kr)) * csc * 65536 + 0.5) + local vb = floor(-kb / (2 * (1 - kr)) * csc * 65536 + 0.5) + local coff4 = floor(128.5 * 65536) * 4 + for i = 0, w * h - 1 do + local o = i * 4 + local r, g, b = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2) + writeu8(dst, i, readu8(CLIP, (yr * r + yg * g + yb * b + yoff) // 65536 + 1024)) + end + for cy = 0, ch - 1 do + local y0 = cy * 2 + local y1 = if y0 + 1 < h then y0 + 1 else y0 + for cx = 0, cw - 1 do + local x0 = cx * 2 + local x1 = if x0 + 1 < w then x0 + 1 else x0 + local a, b2, c2, d = (y0 * w + x0) * 4, (y0 * w + x1) * 4, (y1 * w + x0) * 4, (y1 * w + x1) * 4 + local r = readu8(src, a) + readu8(src, b2) + readu8(src, c2) + readu8(src, d) + local g = readu8(src, a + 1) + readu8(src, b2 + 1) + readu8(src, c2 + 1) + readu8(src, d + 1) + local b = readu8(src, a + 2) + readu8(src, b2 + 2) + readu8(src, c2 + 2) + readu8(src, d + 2) + local i = cy * cw + cx + writeu8(dst, uo + i, readu8(CLIP, (ur * r + ug * g + ub * b + coff4) // 262144 + 1024)) + writeu8(dst, vo + i, readu8(CLIP, (vr * r + vg * g + vb * b + coff4) // 262144 + 1024)) + end + end + return dst +end + +@native local function info(img: Types.Image): (string, string) + local m = img.meta + local y = m and m.yuv + if type(y) == "table" then + return y.range or "limited", y.matrix or "bt601" + end + local src = m and m.source + if type(src) == "table" and src.range == "full" then + return "full", "bt601" + end + return "limited", "bt601" +end +Yuv.info = info + +@native function Yuv.planes(w: number, h: number): (number, number, number, number) + local cw, ch = (w + 1) // 2, (h + 1) // 2 + return w * h, w * h + cw * ch, cw, ch +end + +local FULL_Y = bcreate(256) +local FULL_C = bcreate(256) +for v = 0, 255 do + writeu8(FULL_Y, v, math.clamp(floor((v - 16) * 255 / 219 + 0.5), 0, 255)) + writeu8(FULL_C, v, math.clamp(floor((v - 128) * 255 / 224 + 128.5), 0, 255)) +end + +@native function Yuv.toFullRange(img: Types.Image): Types.Image + if img.format ~= "yuv420p" or info(img) == "full" then + return img + end + local w, h = img.width, img.height + local out = Types.Image.new(w, h, "yuv420p") + local src, dst = img.pixels, out.pixels + local ny = w * h + local n = math.min(buffer.len(src), buffer.len(dst)) + for i = 0, math.min(ny, n) - 1 do + writeu8(dst, i, readu8(FULL_Y, readu8(src, i))) + end + for i = ny, n - 1 do + writeu8(dst, i, readu8(FULL_C, readu8(src, i))) + end + out.meta.yuv = { range = "full", matrix = select(2, info(img)) } + out.meta.source = img.meta.source + return out +end + +-- out: an rgba8 Image of the same size to write into (else a new one) +@native function Yuv.imageToRgba(img: Types.Image, out: Types.Image?, hook: (() -> ())?): Types.Image? + if img.format == "rgba8" then + return img + end + if img.format ~= "yuv420p" then + return nil + end + local w, h = img.width, img.height + local uo, vo, cw = Yuv.planes(w, h) + local range, matrix = info(img) + if not out or out.format ~= "rgba8" or out.width ~= w or out.height ~= h or buffer.len(out.pixels) < w * h * 4 then + out = Types.Image.new(w, h, "rgba8") + end + local o = out :: Types.Image + Yuv.toRgba(img.pixels, w, h, uo, vo, cw, range, matrix, o.pixels, hook) + o.meta.source = img.meta.source + return o +end + +@native function Yuv.imageFromRgba(img: Types.Image, range: string?, matrix: string?): Types.Image? + if img.format == "yuv420p" then + return img + end + if img.format ~= "rgba8" then + return nil + end + local out = Types.Image.new(img.width, img.height, "yuv420p") + Yuv.fromRgba(img.pixels, img.width, img.height, range, matrix, out.pixels) + out.meta.yuv = { range = range or "limited", matrix = matrix or "bt601" } + out.meta.source = img.meta.source + return out +end + +@native local function scalePlane(src: buffer, so: number, sw: number, sh: number, dst: buffer, d0: number, dw: number, dh: number, hook: (() -> ())?) + local fx, fy = sw / dw, sh / dh + for y = 0, dh - 1 do + if hook and y % 16 == 15 then + pcall(hook) + end + local sy = (y + 0.5) * fy - 0.5 + if sy < 0 then + sy = 0 + end + local y0 = floor(sy) + if y0 > sh - 1 then + y0 = sh - 1 + end + local y1 = if y0 < sh - 1 then y0 + 1 else y0 + local wy = floor((sy - y0) * 256) + local r0, r1 = so + y0 * sw, so + y1 * sw + local o = d0 + y * dw + for x = 0, dw - 1 do + local sx = (x + 0.5) * fx - 0.5 + if sx < 0 then + sx = 0 + end + local x0 = floor(sx) + if x0 > sw - 1 then + x0 = sw - 1 + end + local x1 = if x0 < sw - 1 then x0 + 1 else x0 + local wx = floor((sx - x0) * 256) + local a = readu8(src, r0 + x0) * (256 - wx) + readu8(src, r0 + x1) * wx + local b = readu8(src, r1 + x0) * (256 - wx) + readu8(src, r1 + x1) * wx + writeu8(dst, o + x, (a * (256 - wy) + b * wy + 32768) // 65536) + end + end +end + +@native function Yuv.scale(src: buffer, w: number, h: number, width: number, height: number, out: buffer?, hook: (() -> ())?): buffer + local dw: number = math.max(1, floor(width)) + local dh: number = math.max(1, floor(height)) + local cw: number = (w + 1) // 2 + local ch: number = (h + 1) // 2 + local dcw: number = (dw + 1) // 2 + local dch: number = (dh + 1) // 2 + local size = dw * dh + 2 * dcw * dch + local dst = if out and buffer.len(out) >= size then out else bcreate(size) + if w < 1 or h < 1 or buffer.len(src) < w * h + 2 * cw * ch then + return dst + end + scalePlane(src, 0, w, h, dst, 0, dw, dh, hook) + scalePlane(src, w * h, cw, ch, dst, dw * dh, dcw, dch, hook) + scalePlane(src, w * h + cw * ch, cw, ch, dst, dw * dh + dcw * dch, dcw, dch, hook) + return dst +end + +-- out: a yuv420p Image of the target size to write into (else a new one) +@native function Yuv.imageScale(img: Types.Image, dw: number, dh: number, out: Types.Image?, hook: (() -> ())?): Types.Image + local tw, th = math.max(1, floor(dw)), math.max(1, floor(dh)) + if not out or out.format ~= "yuv420p" or out.width ~= tw or out.height ~= th then + out = Types.Image.new(tw, th, "yuv420p") + end + local o = out :: Types.Image + Yuv.scale(img.pixels, img.width, img.height, tw, th, o.pixels, hook) + o.meta = table.clone(img.meta or {}) + return o +end + +return Yuv +end end - + - codecs_model + codecs_model_Brush --!optimize 2 --!nocheck --- rosetta chunk codecs_model (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 23 modules (5 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk codecs_model_Brush (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["codecs/model/Brush"] = @native function() @@ -113700,6 +111773,19 @@ end return Displacement end +end + + + + + + codecs_model_DoomMap + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_model_DoomMap (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/model/DoomMap"] = function() -- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to @@ -114654,6 +112740,19 @@ end return Mat4 end +end + + + + + + codecs_model_MeshFlatten + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_model_MeshFlatten (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/model/MeshFlatten"] = function() -- codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF). @@ -115182,6 +113281,19 @@ end return Flatten end +end + + + + + + codecs_model_Minecraft + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_model_Minecraft (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/model/Minecraft"] = function() -- codecs/model/Minecraft: what Minecraft's voxel formats share (model/schematic, model/mca). New code. @@ -116126,6 +114238,19 @@ end return Packed end +end + + + + + + codecs_model_Patch + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_model_Patch (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/model/Patch"] = @native function() @@ -116484,6 +114609,256 @@ end return Polygon end +end + + + + + + codecs_model_Rbx + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_model_Rbx (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) +__FILES["codecs/model/Rbx"] = function() + +-- codecs/model/Rbx: the Roblox instance tree and property values shared by model/rbxm and model/rbxmx. +-- Written from the rbx-dom format notes (docs/binary.md, docs/xml.md); checked against rbx-dom through rojo / lune. +-- Faces: bits Right 1, Top 2, Back 4, Left 8, Bottom 16, Front 32 +-- Axes: bits X 1, Y 2, Z 4 +-- UniqueId: 32 hex digits: random (16), time (8), index (8) + +local Rbx = {} + +type Value = { type: string, value: any } +type Instance = { + className: string, + name: string, + properties: { [string]: Value }, + children: { Instance }, + parent: Instance?, + referent: string?, + service: boolean?, -- a service (binary INST object format 1; rbxl roots) +} +type Tree = { + kind: "rbxtree", + roots: { Instance }, + place: boolean, + metadata: { [string]: string }, -- binary META / XML <Meta> entries (ExplicitAutoJoints, ...) + extra: { any }, + meta: { source: { format: string, [string]: any }?, [string]: any }, +} + +function Rbx.tree(place: boolean?): Tree + return { kind = "rbxtree", roots = {}, place = place == true, metadata = {}, extra = {}, meta = {} } +end + +function Rbx.instance(className: string, name: string?): Instance + return { className = className, name = name or className, properties = {}, children = {} } +end + +function Rbx.add(parent: any, child: Instance): Instance + if parent.kind == "rbxtree" then + child.parent = nil + table.insert(parent.roots, child) + else + child.parent = parent + table.insert(parent.children, child) + end + return child +end + +function Rbx.set(inst: Instance, name: string, typ: string, value: any) + inst.properties[name] = { type = typ, value = value } +end + +function Rbx.get(inst: Instance, name: string): any + local v = inst.properties[name] + return if v then v.value else nil +end + +function Rbx.descendants(root: any): () -> (Instance?, number?) + local stack: { any } = {} + local list = if root.kind == "rbxtree" then root.roots else root.children + for i = #list, 1, -1 do + table.insert(stack, { list[i], 1 }) + end + return function(): (Instance?, number?) + local top = table.remove(stack) + if not top then + return nil, nil + end + local inst, depth = top[1], top[2] + for i = #inst.children, 1, -1 do + table.insert(stack, { inst.children[i], depth + 1 }) + end + return inst, depth + end +end + +function Rbx.list(tree: any): { Instance } + local out = {} + for inst in Rbx.descendants(tree) do + table.insert(out, inst :: Instance) + end + return out +end + +function Rbx.find(root: any, path: string): Instance? + local cur: any = root + for part in string.gmatch(path, "[^/]+") do + local list = if cur.kind == "rbxtree" then cur.roots else cur.children + local found = nil + for _, c in list do + if c.name == part then + found = c + break + end + end + if not found then + return nil + end + cur = found + end + return if cur.kind == "rbxtree" then nil else cur +end + +function Rbx.fullName(inst: Instance): string + local parts = {} + local cur: Instance? = inst + while cur do + table.insert(parts, 1, cur.name) + cur = cur.parent + end + return table.concat(parts, ".") +end + +-- The binary format stores axis-aligned rotations as one byte: id = 6 * n(RightVector) + n(UpVector) + 1, where n is +-- the NormalId of a unit axis (+X 0, +Y 1, +Z 2, -X 3, -Y 4, -Z 5) and the third column is their cross product. +local AXES = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { -1, 0, 0 }, { 0, -1, 0 }, { 0, 0, -1 } } + +local ROTATIONS: { [number]: { number } } = {} +for a = 0, 5 do + for b = 0, 5 do + if a % 3 ~= b % 3 then + local r, u = AXES[a + 1], AXES[b + 1] + local k = { r[2] * u[3] - r[3] * u[2], r[3] * u[1] - r[1] * u[3], r[1] * u[2] - r[2] * u[1] } + -- columns: right, up, back (= right x up) + ROTATIONS[6 * a + b + 1] = { r[1], u[1], k[1] + 0, r[2], u[2], k[2] + 0, r[3], u[3], k[3] + 0 } + end + end +end +Rbx.ROTATIONS = ROTATIONS + +local function axisIndex(x: number, y: number, z: number): number? + for i, a in AXES do + if a[1] == x and a[2] == y and a[3] == z then + return i - 1 + end + end + return nil +end + +function Rbx.rotationId(cf: { number }): number + local a = axisIndex(cf[4], cf[7], cf[10]) + local b = axisIndex(cf[5], cf[8], cf[11]) + if not a or not b then + return 0 + end + local id = 6 * a + b + 1 + local rot = ROTATIONS[id] + if not rot or rot[3] ~= cf[6] or rot[6] ~= cf[9] or rot[9] ~= cf[12] then + return 0 + end + return id +end + +-- binary type ids (rbx-dom docs/binary.md) by type name, and back +Rbx.TYPE_IDS = table.freeze({ + String = 0x01, + BinaryString = 0x01, + ProtectedString = 0x01, + ContentId = 0x01, + Bool = 0x02, + Int32 = 0x03, + Float32 = 0x04, + Float64 = 0x05, + UDim = 0x06, + UDim2 = 0x07, + Ray = 0x08, + Faces = 0x09, + Axes = 0x0A, + BrickColor = 0x0B, + Color3 = 0x0C, + Vector2 = 0x0D, + Vector3 = 0x0E, + Vector2int16 = 0x0F, + CFrame = 0x10, + Enum = 0x12, + Ref = 0x13, + Vector3int16 = 0x14, + NumberSequence = 0x15, + ColorSequence = 0x16, + NumberRange = 0x17, + Rect = 0x18, + PhysicalProperties = 0x19, + Color3uint8 = 0x1A, + Int64 = 0x1B, + SharedString = 0x1C, + Bytecode = 0x1D, + OptionalCFrame = 0x1E, + UniqueId = 0x1F, + Font = 0x20, + SecurityCapabilities = 0x21, + Content = 0x22, +} :: { [string]: number }) +local NAMES: { [number]: string } = {} +for name, id in Rbx.TYPE_IDS do + if NAMES[id] == nil or name == "String" then + NAMES[id] = name + end +end +Rbx.TYPE_NAMES = table.freeze(NAMES) + +-- BrickColor 194 (Medium stone grey) is Roblox's default +local IDENTITY_CF = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 } +function Rbx.default(typ: string): any + if typ == "String" or typ == "BinaryString" or typ == "ProtectedString" or typ == "ContentId" or typ == "Bytecode" or typ == "SharedString" then + return "" + elseif typ == "Bool" then + return false + elseif typ == "BrickColor" then + return 194 + elseif typ == "UDim" or typ == "NumberRange" or typ == "Vector2" or typ == "Vector2int16" then + return { 0, 0 } + elseif typ == "UDim2" or typ == "Rect" then + return { 0, 0, 0, 0 } + elseif typ == "Vector3" or typ == "Vector3int16" or typ == "Color3" or typ == "Color3uint8" then + return { 0, 0, 0 } + elseif typ == "Ray" then + return { 0, 0, 0, 0, 0, 0 } + elseif typ == "CFrame" then + return table.clone(IDENTITY_CF) + elseif typ == "NumberSequence" then + return { { 0, 0, 0 }, { 1, 0, 0 } } + elseif typ == "ColorSequence" then + return { { 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0 } } + elseif typ == "UniqueId" then + return string.rep("0", 32) + elseif typ == "Font" then + return { family = "rbxasset://fonts/families/SourceSansPro.json", weight = 400, style = "Normal" } + elseif typ == "PhysicalProperties" or typ == "Ref" or typ == "OptionalCFrame" or typ == "Content" then + return nil + end + return 0 +end + +Rbx.STRINGS = table.freeze({ String = true, BinaryString = true, ProtectedString = true, ContentId = true, Bytecode = true } :: { [string]: boolean }) + +return Rbx +end __FILES["codecs/model/Rbx/Binary"] = @native function() @@ -117238,6 +115613,19 @@ end return Binary end +end + + + + + + codecs_model_Rig + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_model_Rig (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/model/Rig"] = function() -- codecs/model/Rig: the Scene mapping shared by game model formats (MD2 / MD3 / MDL / MD5 / SMD / ...). New code. @@ -117862,6 +116250,19 @@ end return SourceAnim end +end + + + + + + codecs_model_Vrml + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_model_Vrml (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 7 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/model/Vrml"] = function() -- codecs/model/Vrml: VRML97 / X3D scene-graph engine (classic and XML encodings) for model/vrml and model/x3d. @@ -120981,13 +119382,13 @@ end - + - codecs_text + codecs_text_GodotVariant --!optimize 2 --!nocheck --- rosetta chunk codecs_text (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 15 modules (3 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk codecs_text_GodotVariant (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["codecs/text/GodotVariant"] = function() @@ -121649,6 +120050,19 @@ end return GodotVariant end +end + + + + + + codecs_text_Json + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_text_Json (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/text/Json"] = function() -- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code. @@ -122698,6 +121112,19 @@ end return Encode end +end + + + + + + codecs_text_KeyValues + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_text_KeyValues (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/text/KeyValues"] = function() -- codecs/text/KeyValues: Valve KeyValues text (tier1/KeyValues.cpp of the Source SDK 2013, srctools' reading of it) @@ -123706,6 +122133,19 @@ end return Lexer end +end + + + + + + codecs_text_Nbt + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_text_Nbt (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/text/Nbt"] = function() -- codecs/text/Nbt: Minecraft's Named Binary Tag format and SNBT (Minecraft wiki "NBT format", wiki.vg "NBT"). @@ -125629,6 +124069,19 @@ end return Value end +end + + + + + + codecs_text_Text + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_text_Text (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/text/Text"] = function() @@ -125925,6 +124378,19 @@ end return Url end +end + + + + + + codecs_text_Xml + --!optimize 2 +--!nocheck +-- rosetta chunk codecs_text_Xml (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["codecs/text/Xml"] = function() -- codecs/text/Xml: XML 1.0 parse (DOM and pull events) and serialize. New code. @@ -127183,15 +125649,893 @@ end - + - codecs_video + codecs_video_Video --!optimize 2 --!nocheck --- rosetta chunk codecs_video (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk codecs_video_Video (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) +__FILES["codecs/video/Video"] = function() + + +-- codecs/video/Video: the video codec registry and the generic VideoDecoder. New in rosetta. +local Err = __include("core/Err") +local Types = __include("Types") +local Yuv = __include("codecs/image/Yuv") +local Disposable = __include("codecs/video/Video/Disposable") +local Pool = __include("codecs/video/Video/Pool") + +local Video = {} + +type Entry = { + id: string, + name: string, + fourcc: { string }?, -- AVI biCompression / MOV sample entry FourCCs + matroska: { string }?, -- Matroska / WebM CodecIDs + new: ((track: Types.Track, opts: any?) -> (Types.VideoCodecDecoder?, Err.Err?))?, + [string]: any, +} + +-- decodeOne -> nil, nil: a packet with no picture to show (a hidden VP8 altref frame); false: a picture skipped +function Video.simpleDecoder(decodeOne: (data: buffer, packet: Types.Packet) -> (Types.Image? | false, Err.Err?), resetFn: (() -> ())?): Types.VideoCodecDecoder + local queue: { any } = {} + local self = {} + function self.decode(_: any, packet: Types.Packet): Err.Err? + local ok, img, err = pcall(decodeOne, packet.data, packet) + if not ok then + return Err.new(Err.CORRUPT, "decoder threw: " .. tostring(img)) + end + if img ~= nil then + table.insert(queue, { img, packet.pts, packet.keyframe }) + end + return err + end + function self.receive(_: any): (Types.Image? | false, number?, boolean?) + local q = table.remove(queue, 1) + if q then + return q[1], q[2], q[3] + end + return nil, nil, nil + end + function self.flush(_: any) end + function self.reset(_: any) + table.clear(queue) + if resetFn then + resetFn() + end + end + return self :: any +end + +-- raw video: yuv420p (I420 / IYUV / y4m), yv12 (V before U), yuv422p / yuv444p / yuva444p / gray (chroma averaged +-- down to 4:2:0, alpha dropped), track.bitDepth 9..16 (little-endian 16-bit samples scaled to 8 bits), rgb24 / bgr24 / +-- bgra / rgba (AVI DIBs: track.flip = bottom-up rows, track.stride = padded rows) +local function rawPlanar(data: buffer, pf: string, bits: number, w: number, h: number): Types.Image + local img = Types.Image.new(w, h, "yuv420p") + local px = img.pixels + local cw, ch = (w + 1) // 2, (h + 1) // 2 + local bps = if bits > 8 then 2 else 1 + local shift = 2 ^ (bits - 8) + local function sample(o: number): number + if bps == 1 then + return buffer.readu8(data, o) + end + return math.min(255, buffer.readu16(data, o) // shift) + end + for i = 0, w * h - 1 do + buffer.writeu8(px, i, sample(i * bps)) + end + local scw, sch = w, h -- source chroma plane size + if pf == "yuv420p" then + scw, sch = cw, ch + elseif pf == "yuv422p" then + scw, sch = cw, h + end + local uo, vo = w * h * bps, (w * h + scw * sch) * bps + for cy = 0, ch - 1 do + for cx = 0, cw - 1 do + local i = cy * cw + cx + local u, v + if pf == "gray" then + u, v = 128, 128 + elseif pf == "yuv420p" then + u, v = sample(uo + i * bps), sample(vo + i * bps) :: number + elseif pf == "yuv422p" then + local y0, y1 = cy * 2, math.min(cy * 2 + 1, h - 1) + u = (sample(uo + (y0 * scw + cx) * bps) + sample(uo + (y1 * scw + cx) * bps) + 1) // 2 + v = (sample(vo + (y0 * scw + cx) * bps) + sample(vo + (y1 * scw + cx) * bps) + 1) // 2 + else + local x0, x1 = cx * 2, math.min(cx * 2 + 1, w - 1) + local y0, y1 = cy * 2, math.min(cy * 2 + 1, h - 1) + local a, b, c, d = (y0 * w + x0) * bps, (y0 * w + x1) * bps, (y1 * w + x0) * bps, (y1 * w + x1) * bps + u = (sample(uo + a) + sample(uo + b) + sample(uo + c) + sample(uo + d) + 2) // 4 + v = (sample(vo + a) + sample(vo + b) + sample(vo + c) + sample(vo + d) + 2) // 4 + end + buffer.writeu8(px, w * h + i, u) + buffer.writeu8(px, w * h + cw * ch + i, v) + end + end + return img +end + +local PLANAR_SIZE: { [string]: (w: number, h: number, cw: number, ch: number) -> number } = { + yuv420p = function(w, h, cw, ch) + return w * h + 2 * cw * ch + end, + yv12 = function(w, h, cw, ch) + return w * h + 2 * cw * ch + end, + yuv422p = function(w, h, cw, _ch) + return w * h + 2 * cw * h + end, + yuv444p = function(w, h) + return w * h * 3 + end, + yuva444p = function(w, h) + return w * h * 4 + end, + gray = function(w, h) + return w * h + end, +} + +local function rawDecoder(track: Types.Track, _opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local w, h = track.width or 0, track.height or 0 + if w <= 0 or h <= 0 or w * h > 2 ^ 26 then + return nil, Err.new(Err.CORRUPT, "raw video without a valid size") + end + local pf = track.pixelFormat or "yuv420p" + local bits = track.bitDepth or 8 + local cw, ch = (w + 1) // 2, (h + 1) // 2 + local flip = track.flip == true + local planar = PLANAR_SIZE[pf] + return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?) + local n = buffer.len(data) + if planar then + local need = planar(w, h, cw, ch) * (if bits > 8 then 2 else 1) + if n < need then + return nil, Err.new(Err.TRUNCATED, "raw frame: " .. n .. " of " .. need .. " bytes") + end + if pf == "yuv420p" and bits == 8 then + local img = Types.Image.new(w, h, "yuv420p") + buffer.copy(img.pixels, 0, data, 0, need) + return img, nil + elseif pf == "yv12" then + local img = Types.Image.new(w, h, "yuv420p") + buffer.copy(img.pixels, 0, data, 0, w * h) + buffer.copy(img.pixels, w * h, data, w * h + cw * ch, cw * ch) + buffer.copy(img.pixels, w * h + cw * ch, data, w * h, cw * ch) + return img, nil + end + return rawPlanar(data, pf, bits, w, h), nil + end + local bpp = if pf == "bgra" or pf == "rgba" then 4 else 3 + local stride: number = track.stride or w * bpp + if n < stride * (h - 1) + w * bpp then + return nil, Err.new(Err.TRUNCATED, "raw frame too short") + end + local img = Types.Image.new(w, h, "rgba8") + local px = img.pixels + local bgr = pf == "bgr24" or pf == "bgra" + for y = 0, h - 1 do + local s = (if flip then h - 1 - y else y) * stride + local o = y * w * 4 + for x = 0, w - 1 do + local p = s + x * bpp + local a, b, c = buffer.readu8(data, p), buffer.readu8(data, p + 1), buffer.readu8(data, p + 2) + if bgr then + a, c = c, a + end + buffer.writeu32(px, o + x * 4, a + b * 256 + c * 65536 + 0xff000000) + end + end + return img, nil + end), nil +end + +local function vp8Decoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local Vp8 = __include("codecs/image/Vp8") + local dec = Vp8.newDecoder() + local o = { maxPixels = opts and opts.maxPixels, yield = opts and opts.yield, skipDisposable = opts and opts.skipDisposable } + local self: any + self = Video.simpleDecoder(function(data: buffer): (Types.Image? | false, Err.Err?) + local img, err = dec:decodeFrame(data, 0, buffer.len(data), o) + if not img then + if err then + return nil, err + end + self.skipped += 1 + -- show_frame (RFC 6386 9.1): a shown frame keeps its place + return if buffer.readu8(data, 0) // 16 % 2 == 1 then false else nil, nil + end + local src = img.meta.source + if type(src) == "table" and src.show == false then + return nil, nil + end + img.meta.yuv = { range = "limited", matrix = "bt601" } + return img, nil + end, function() + if dec.reset then + dec:reset() + else + dec = Vp8.newDecoder() + end + end) :: any + self.skipped = 0 + function self.release(_: any, image: Types.Image): boolean + return dec:release(image) + end + return self, nil +end + +-- Motion JPEG: yuv420p straight from the planes (full range) when the layout allows, else rgba8 +local function mjpegDecoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local Jpeg = __include("codecs/image/Jpeg") + local o: Jpeg.DecodeOptions = { yuv = true, maxPixels = opts and opts.maxPixels } + return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?) + local img, err = Jpeg.decode(data, 0, buffer.len(data), o) + if img and img.format == "yuv420p" then + img.meta.yuv = { range = "full", matrix = "bt601" } + end + return img, err + end), nil +end + +-- the MJPEG encoder (writers): JPEG is full-range, so limited-range yuv420p frames are remapped first +local function mjpegEncode(img: Types.Image, opts: any?): (buffer?, Err.Err?) + local Jpeg = __include("codecs/image/Jpeg") + local src = img + if img.format == "yuv420p" then + local range = Yuv.info(img) + if range ~= "full" then + src = Yuv.toFullRange(img) + end + end + return Jpeg.encode(src, { quality = opts and opts.quality or 90 }) +end + +local function mpeg2Decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local Mpeg2 = __include("codecs/video/Mpeg2") + return Mpeg2.newVideoDecoder(track, opts) +end + +local function h264Decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local H264 = __include("codecs/video/H264") + return H264.newVideoDecoder(track, opts) +end + +local function h263Decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local H263 = __include("codecs/video/H263") + local dec = H263.new({ flv = track.codec == "flv1", maxPixels = opts and opts.maxPixels }) + return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?) + return dec:image(data) + end, function() + dec:reset() + end), nil +end + +local function theoraDecoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local Theora = __include("codecs/video/Theora") + return Theora.newVideoDecoder(track, opts) +end + +local function legacyDecoder(id: string): (track: Types.Track, opts: any?) -> (Types.VideoCodecDecoder?, Err.Err?) + return function(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + return __include("codecs/video/Legacy").newDecoder(id, track, opts) + end +end + +-- FourCCs compare case-sensitively first, then upper-cased +local BUILTIN: { Entry } = { + { id = "vp8", name = "VP8", fourcc = { "VP80", "vp08" }, matroska = { "V_VP8" }, new = vp8Decoder }, + { id = "mjpeg", name = "Motion JPEG", fourcc = { "MJPG", "mjpa", "mjpb", "jpeg", "AVRn", "AVDJ", "dmb1", "LJPG", "JPGL", "MJLS", "ijpg" }, matroska = { "V_MJPEG" }, new = mjpegDecoder, encode = mjpegEncode }, + { id = "mpeg1", name = "MPEG-1 video", fourcc = { "mpg1", "MPG1", "PIM1", "m1v " }, matroska = { "V_MPEG1" }, new = mpeg2Decoder }, + { id = "rawvideo", name = "raw video", fourcc = { "\0\0\0\0", "I420", "IYUV", "YV12", "raw ", "DIB " }, matroska = { "V_UNCOMPRESSED" }, new = rawDecoder }, + { id = "mpeg2", name = "MPEG-2 video", fourcc = { "mpg2", "MPG2", "MPEG", "mp2v", "hdv1", "hdv2", "hdv3", "hdv5", "hdv6", "hdv7", "hdv8", "hdv9", "hdva", "xdv1", "xdv2", "xdv3", "xdv4", "xdv5", "xdv6", "xdv7", "xdv8", "xdv9", "xdva", "xdvb", "xdvc", "xdvd", "xdve", "xdvf", "xd54", "xd55", "xd59", "xd5a", "xd5b", "xd5c", "xd5d", "xd5e", "xd5f", "xdhd", "xdh2", "AVmp", "mx3n", "mx3p", "mx4n", "mx4p", "mx5n", "mx5p", "mmes", "MMES", "M701", "M702", "M703", "M704", "M705", "mpgv", "m2v1", "M2V1" }, matroska = { "V_MPEG2" }, new = mpeg2Decoder }, + { id = "mpeg4", name = "MPEG-4 part 2", fourcc = { "mp4v", "FMP4", "XVID", "DIVX", "DX50", "MP4V" }, matroska = { "V_MPEG4/ISO/SP", "V_MPEG4/ISO/ASP", "V_MPEG4/ISO/AP" } }, + { id = "h264", name = "H.264 / AVC", fourcc = { "avc1", "avc3", "H264", "h264", "X264", "x264", "AVC1", "DAVC", "VSSH" }, matroska = { "V_MPEG4/ISO/AVC" }, new = h264Decoder }, + { id = "hevc", name = "H.265 / HEVC", fourcc = { "hvc1", "hev1", "HEVC", "H265" }, matroska = { "V_MPEGH/ISO/HEVC" } }, + { id = "vp9", name = "VP9", fourcc = { "VP90", "vp09" }, matroska = { "V_VP9" } }, + { id = "av1", name = "AV1", fourcc = { "AV01", "av01" }, matroska = { "V_AV1" } }, + { id = "theora", name = "Theora", matroska = { "V_THEORA" }, new = theoraDecoder }, + { id = "h263", name = "H.263", fourcc = { "H263", "h263", "s263", "U263" }, new = h263Decoder }, + { id = "flv1", name = "Sorenson Spark (FLV1)", fourcc = { "FLV1" }, new = h263Decoder }, + { id = "vp6f", name = "On2 VP6 (Flash)", fourcc = { "VP6F", "FLV4" } }, + { id = "vp6a", name = "On2 VP6 with alpha (Flash)", fourcc = { "VP6A" } }, + { id = "flashsv", name = "Flash Screen Video", fourcc = { "FSV1" } }, + { id = "flashsv2", name = "Flash Screen Video 2" }, + { id = "png", name = "PNG", fourcc = { "png ", "MPNG" }, matroska = { "V_PNG" } }, + { id = "cinepak", name = "Cinepak", fourcc = { "cvid" }, new = legacyDecoder("cinepak") }, + { id = "msvideo1", name = "Microsoft Video 1", fourcc = { "CRAM", "MSVC", "WHAM" }, new = legacyDecoder("msvideo1") }, + { id = "qtrle", name = "QuickTime Animation (RLE)", fourcc = { "rle " }, new = legacyDecoder("qtrle") }, + { id = "smc", name = "QuickTime Graphics (SMC)", fourcc = { "smc " }, new = legacyDecoder("smc") }, + { id = "flic", name = "Autodesk Animator FLIC", fourcc = { "AFLC" }, new = legacyDecoder("flic") }, + { id = "smackvid", name = "Smacker video", fourcc = { "SMK2", "SMK4" }, new = legacyDecoder("smackvid") }, +} + +local byId: { [string]: Entry } = {} +local byFourcc: { [string]: string } = {} +local byMatroska: { [string]: string } = {} + +function Video.register(entry: Entry): (boolean, Err.Err?) + if type(entry) ~= "table" or type(entry.id) ~= "string" then + return false, Err.new(Err.ARG, "register: needs an entry with an id") + end + local old = byId[entry.id] + if old and entry.new == nil then + entry.new = old.new + end + byId[entry.id] = entry + for _, f in entry.fourcc or {} do + byFourcc[f] = entry.id + end + for _, m in entry.matroska or {} do + byMatroska[m] = entry.id + end + return true, nil +end +for _, e in BUILTIN do + Video.register(e) +end + +Video.codecs = byId + +function Video.fromFourcc(fcc: string): string? + return byFourcc[fcc] or byFourcc[string.upper(fcc)] or byFourcc[string.lower(fcc)] +end + +function Video.fromMatroska(id: string): string? + return byMatroska[id] +end + +function Video.entry(id: string): Entry? + return byId[id] +end + +-- disposable: no later frame predicts from the packet's; droppable: it may also be left out unread (VP8 headers can +-- carry probability and loop filter updates, so a disposable VP8 frame is droppable only without them) +function Video.isDisposable(track: Types.Track | string, packet: Types.Packet | buffer): (boolean, boolean) + local codec = if type(track) == "table" then track.codec else track + local config = if type(track) == "table" then track.config else nil + local data = if type(packet) == "table" then packet.data else packet + if type(data) ~= "buffer" or type(codec) ~= "string" then + return false, false + end + return Disposable.check(codec, data, config) +end + +function Video.canDecode(id: string): boolean + local e = byId[id] + return e ~= nil and e.new ~= nil +end + +function Video.decoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?) + local e = byId[track.codec] + if not e or not e.new then + return nil, Err.new(Err.UNSUPPORTED, "no decoder for video codec " .. tostring(track.codec)) + end + local ok, dec, err = pcall(e.new :: any, track, opts) + if not ok then + return nil, Err.new(Err.CORRUPT, "codec " .. track.codec .. " failed to start: " .. tostring(dec)) + end + return dec, err +end + +local function toRGBA(_self: any, f: any): Types.Image + local img = if type(f) == "table" and f.image then f.image else f + local out = Yuv.imageToRgba(img) + return out or img +end + +type OpenOptions = { + rgba: boolean?, + track: number?, + maxPixels: number?, + openAudio: ((demuxer: Types.Demuxer, track: Types.Track) -> (Types.Decoder?, Err.Err?))?, + audio: boolean?, + maxSide: number?, + yield: (() -> ())?, + skipDisposable: boolean?, + reuse: boolean?, -- nextFrame may overwrite the Image of the frame it returned before + [string]: any, +} + +function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDecoder?, Err.Err?) + local o: OpenOptions = opts or {} + local track: Types.Track? = nil + if o.track then + for _, t in demuxer.tracks do + if t.id == o.track then + track = t + end + end + if not track then + return nil, Err.new(Err.ARG, "no track " .. tostring(o.track)) + end + else + track = demuxer:track("video") + end + local codec: Types.VideoCodecDecoder? = nil + local codecErr: Err.Err? = nil + if track then + codec, codecErr = Video.decoder(track, o) + else + codecErr = Err.new(Err.UNSUPPORTED, "no video track") + end + local v: any = { + kind = "video", + format = demuxer.format, + codec = if track then track.codec else "none", + width = if track then track.width or 0 else 0, + height = if track then track.height or 0 else 0, + frameRate = if track then track.frameRate or 0 else 0, + frames = if track then track.frames or 0 else 0, + duration = if track and track.duration and track.duration > 0 then track.duration else demuxer.duration, + track = track, + demuxer = demuxer, + meta = demuxer.meta or {}, + decodeError = codecErr, + toRGBA = toRGBA, + } + if v.frames == 0 and v.frameRate > 0 and v.duration > 0 then + v.frames = math.floor(v.duration * v.frameRate + 0.5) + end + if o.audio ~= false then + local at = demuxer:track("audio") + if at then + if o.openAudio then + local ok, dec, err = pcall(o.openAudio, demuxer, at) + if ok and dec then + v.audio = dec + else + v.audioError = if ok then err else Err.new(Err.CORRUPT, "audio: " .. tostring(dec)) + end + else + v.audioError = Err.new(Err.UNSUPPORTED, "no audio hook (open through the api: F.video.open)") + end + end + end + local index, flushed, skipUntil = 0, false, -math.huge + local tid = if track then track.id else -1 + local scale: number = if track and track.timescale and track.timescale > 0 then track.timescale else 1000 + local start = demuxer.startTime or 0 + v.startTime = start + local defaultDur = if v.frameRate > 0 then 1 / v.frameRate else 0 + local lastPts = nil :: number? + -- rgba8 / scaled Images made here; the codec's own go back through codec:release + local own = Pool.new(2) + local function recycle(img: any) + if img and not own:give(img) and codec and codec.release then + codec:release(img) + end + end + local lastFrame: any = nil + function v.release(self: any, frame: any) + recycle(if type(frame) == "table" and frame.kind == "image" then frame else type(frame) == "table" and frame.image) + end + function v.nextFrame(self: any): (Types.VideoFrame?, Err.Err?) + if not codec then + return nil, codecErr + end + if lastFrame then + recycle(lastFrame.image) + lastFrame = nil + end + local dec = codec :: Types.VideoCodecDecoder + while true do + local img, pts, key = dec:receive() + if img == false then + -- a picture skipped (skipDisposable): it keeps its place in output order + if index >= 0 then + index += 1 + end + elseif img then + local t = (pts or 0) / scale - start + if t + 1e-9 >= skipUntil then + if index < 0 then + -- after a seek: constant-rate index = round(pts * fps), else counted from the seek + index = if v.frameRate > 0 then math.max(0, math.floor(t * v.frameRate + 0.5)) else 0 + end + index += 1 + local d = defaultDur + if lastPts and t > (lastPts :: number) and defaultDur == 0 then + d = t - (lastPts :: number) + end + lastPts = t + local maxSide = o.maxSide + local hook = o.yield + if hook and (o.rgba or maxSide) then + pcall(hook) + end + if maxSide and maxSide >= 1 and img.format == "yuv420p" and math.max(img.width, img.height) > maxSide then + local s = maxSide / math.max(img.width, img.height) + local dw, dh = math.max(1, math.floor(img.width * s + 0.5)), math.max(1, math.floor(img.height * s + 0.5)) + local src = img + img = Yuv.imageScale(src, dw, dh, own:take(dw, dh, "yuv420p"), o.yield) + recycle(src) -- (never seen by the caller) + end + if o.rgba and img.format == "yuv420p" then + local src = img + img = Yuv.imageToRgba(src, own:take(src.width, src.height, "rgba8"), o.yield) or src + recycle(src) + end + local frame = { image = img, pts = t, duration = d, keyframe = key, index = index } + if o.reuse then + lastFrame = frame + end + return frame, nil + end + else + local p = demuxer:read(tid) + if p == nil then + if flushed then + return nil, nil + end + flushed = true + dec:flush() + else + local err = dec:decode(p) + if err then + return nil, err + end + end + end + end + end + function v.seek(self: any, seconds: number) + lastFrame = nil + demuxer:seek(seconds + start) + if codec then + codec:reset() + end + flushed = false + skipUntil = seconds + lastPts = nil + index = -1 -- recomputed from the first frame's time + if self.audio then + pcall(self.audio.seek, self.audio, seconds) + end + end + function v.reset(self: any) + self:seek(0) + skipUntil = -math.huge + index = 0 + end + return v, nil +end + +function Video.fromFrames(images: { Types.Image }, delays: (number | { number })?, opts: any?): (Types.VideoDecoder?, Err.Err?) + if type(images) ~= "table" or #images == 0 or type(images[1]) ~= "table" then + return nil, Err.new(Err.ARG, "fromFrames: needs a list of Images") + end + local w, h = images[1].width, images[1].height + local pts: { number } = {} + local durs: { number } = {} + local t = 0 + for i, img in images do + if type(img) ~= "table" or img.width ~= w or img.height ~= h then + return nil, Err.new(Err.ARG, "fromFrames: frame " .. i .. " is not a " .. w .. "x" .. h .. " Image") + end + local d = if type(delays) == "table" then delays[i] or 0.1 else (delays or 0.1) + if type(d) ~= "number" or d ~= d or d < 0 then + d = 0.1 + end + pts[i] = t + durs[i] = d + t += d + end + local n = #images + local o = opts or {} + local v: any = { + kind = "video", + format = o.format or "frames", + codec = "frames", + width = w, + height = h, + frameRate = if t > 0 then n / t else 10, + frames = n, + duration = t, + loops = o.loops, + meta = o.meta or {}, + toRGBA = toRGBA, + images = images, + } + local i = 0 + function v.nextFrame(self: any): (Types.VideoFrame?, Err.Err?) + i += 1 + if i > n then + i = n + return nil, nil + end + local img = images[i] + if o.rgba then + img = Yuv.imageToRgba(img) or img + end + return { image = img, pts = pts[i], duration = durs[i], keyframe = true, index = i }, nil + end + function v.seek(self: any, seconds: number) + local k = 0 + for j = 1, n do + if pts[j] <= seconds + 1e-9 then + k = j - 1 + end + end + i = k + end + function v.reset(self: any) + i = 0 + end + return v, nil +end + +return Video +end +__FILES["codecs/video/Video/Disposable"] = function() + + +-- codecs/video/Video/Disposable: packets whose frame no later frame predicts from (a player may skip decoding them). +-- H.264: the first VCL NAL unit has nal_ref_idc 0 (7.4.1: then every slice of the picture has), and no parameter +-- set comes before it; one access unit per packet, length-prefixed (avcC lengthSizeMinusOne) or Annex B. +-- VP8 (RFC 6386 9.3-9.11, 19.2): an inter frame that refreshes no reference (last / golden / altref, no copies) and +-- leaves the segment map; its header may still change decoder state (probabilities, loop filter deltas). +local readu8 = buffer.readu8 + +local Disposable = {} + +-- the offset of the first byte after the first start code at or after p, or -1 +local function nextStart(b: buffer, p: number, e: number): number + local i = p + while i + 2 < e do + local b2 = readu8(b, i + 2) + if b2 > 1 then + i += 3 + elseif readu8(b, i + 1) ~= 0 then + i += 2 + elseif b2 == 1 and readu8(b, i) == 0 then + return i + 3 + else + i += 1 + end + end + return -1 +end + +-- nal_unit_type 1..5: slices (decided by nal_ref_idc); 7, 8, 13, 15: parameter sets (never dropped) +local function nalVerdict(hdr: number): boolean? + local t = hdr % 32 + if t >= 1 and t <= 5 then + return hdr // 32 % 4 == 0 + elseif t == 7 or t == 8 or t == 13 or t == 15 then + return false + end + return nil +end + +function Disposable.h264(b: buffer, lengthSize: number?): boolean + local n = buffer.len(b) + if lengthSize then + local p = 0 + while p + lengthSize < n do + local len = 0 + for k = 0, lengthSize - 1 do + len = len * 256 + readu8(b, p + k) + end + p += lengthSize + if len > n - p then + return false + end + if len > 0 then + local v = nalVerdict(readu8(b, p)) + if v ~= nil then + return v + end + end + p += len + end + return false + end + if n >= 3 and readu8(b, 0) == 0 and readu8(b, 1) == 0 then + local p = nextStart(b, 0, n) + while p >= 0 and p < n do + local v = nalVerdict(readu8(b, p)) + if v ~= nil then + return v + end + p = nextStart(b, p, n) + end + return false + end + return n > 0 and nalVerdict(readu8(b, 0)) == true +end + +-- the boolean decoder of RFC 6386 7.3 (a 2-byte window), enough for the frame header +type Bool = { b: buffer, p: number, e: number, value: number, range: number, count: number } + +local function byteAt(d: Bool): number + local p = d.p + d.p = p + 1 + return if p < d.e then readu8(d.b, p) else 0 +end + +local function boolNew(b: buffer, p: number, e: number): Bool + local d: Bool = { b = b, p = p, e = e, value = 0, range = 255, count = 0 } + d.value = byteAt(d) * 256 + byteAt(d) + return d +end + +local function boolRead(d: Bool, prob: number): number + local split = 1 + (d.range - 1) * prob // 256 + local big = split * 256 + local bit = 0 + if d.value >= big then + bit = 1 + d.range -= split + d.value -= big + else + d.range = split + end + while d.range < 128 do + d.value *= 2 + d.range *= 2 + d.count += 1 + if d.count == 8 then + d.count = 0 + d.value += byteAt(d) + end + end + return bit +end + +local function lit(d: Bool, n: number): number + local v = 0 + for _ = 1, n do + v = v * 2 + boolRead(d, 128) + end + return v +end + +-- skips flag ? (n bits + sign) : nothing +local function optSigned(d: Bool, n: number) + if lit(d, 1) == 1 then + lit(d, n + 1) + end +end + +-- disposable: no reference refresh or copy and no segment map update; droppable: also no state the decoder keeps +-- (refresh_entropy_probs 0, no segment feature or loop filter delta update) +function Disposable.vp8(b: buffer): (boolean, boolean) + local n = buffer.len(b) + if n < 4 then + return false, false + end + local tag = readu8(b, 0) + readu8(b, 1) * 256 + readu8(b, 2) * 65536 + if tag % 2 == 0 then + return false, false -- key frame + end + local first = tag // 32 + if first > n - 3 then + return false, false + end + local d = boolNew(b, 3, 3 + first) + local keep = true + if lit(d, 1) == 1 then -- segmentation_enabled + local updateMap, updateData = lit(d, 1), lit(d, 1) + if updateMap == 1 then + return false, false + end + if updateData == 1 then + keep = false + lit(d, 1) -- segment_feature_mode + for _ = 1, 4 do + optSigned(d, 7) + end + for _ = 1, 4 do + optSigned(d, 6) + end + end + end + lit(d, 1 + 6 + 3) -- filter_type, loop_filter_level, sharpness_level + if lit(d, 1) == 1 and lit(d, 1) == 1 then -- loop_filter_adj_enable, mode_ref_lf_delta_update + keep = false + for _ = 1, 8 do + optSigned(d, 6) + end + end + lit(d, 2 + 7) -- log2_nbr_of_dct_partitions, y_ac_qi + for _ = 1, 5 do + optSigned(d, 4) + end + local refreshGolden, refreshAlt = lit(d, 1), lit(d, 1) + if refreshGolden == 1 or refreshAlt == 1 then + return false, false + end + if lit(d, 2) ~= 0 or lit(d, 2) ~= 0 then -- copy_buffer_to_golden, copy_buffer_to_alternate + return false, false + end + lit(d, 2) -- sign_bias_golden, sign_bias_alternate + local refreshEntropy, refreshLast = lit(d, 1), lit(d, 1) + if refreshLast == 1 or d.p > d.e + 2 then + return false, false + end + return true, keep and refreshEntropy == 0 +end + +-- the avcC NAL length size of a track (nil: Annex B or one bare NAL unit per packet) +function Disposable.lengthSize(config: buffer?): number? + if config and buffer.len(config) >= 7 and readu8(config, 0) == 1 then + return readu8(config, 4) % 4 + 1 + end + return nil +end + +-- disposable: no later frame predicts from it; droppable: it can also be left out without telling the decoder +function Disposable.check(codec: string?, data: buffer, config: buffer?): (boolean, boolean) + if codec == "h264" then + local v = Disposable.h264(data, Disposable.lengthSize(config)) + return v, v + elseif codec == "vp8" then + return Disposable.vp8(data) + end + return false, false +end + +return Disposable +end +__FILES["codecs/video/Video/Pool"] = function() + + +-- codecs/video/Video/Pool: output Images handed back by the caller (decoder:release), reused for later frames. Only +-- Images this pool made are taken back; a reused Image gets a fresh meta table. +local Types = __include("Types") + +local Pool = {} +Pool.__index = Pool + +type Pool = typeof(setmetatable({} :: { free: { Types.Image }, made: { [Types.Image]: boolean }, max: number }, Pool)) + +function Pool.new(max: number?): Pool + return setmetatable({ free = {}, made = setmetatable({}, { __mode = "k" }) :: any, max = max or 3 }, Pool) +end + +function Pool.take(self: Pool, w: number, h: number, format: Types.PixelFormat): Types.Image + local free = self.free + for i = #free, 1, -1 do + local img = free[i] + if img.width == w and img.height == h and img.format == format then + table.remove(free, i) + img.meta = {} + return img + end + end + local img = Types.Image.new(w, h, format) + self.made[img] = true + return img +end + +-- true when the Image was this pool's (it is kept for reuse, or dropped when the pool is full) +function Pool.give(self: Pool, img: any): boolean + if type(img) ~= "table" or not self.made[img] then + return false + end + local free = self.free + for _, q in free do + if q == img then + return true + end + end + if #free < self.max then + table.insert(free, img) + else + self.made[img] = nil + end + return true +end + +return Pool +end __FILES["codecs/video/Video/Source"] = function() @@ -127482,13 +126826,13 @@ end - + - containers + containers_Archive --!optimize 2 --!nocheck --- rosetta chunk containers (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 21 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk containers_Archive (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["containers/Archive"] = function() @@ -127758,6 +127102,529 @@ end return Archive end +__FILES["containers/AudioWrap"] = function() + +-- containers/AudioWrap: a video container's audio track as a stream an audio format reads (a format never requires +-- another). New in rosetta. PCM / WAVEFORMATEX -> WAV, adpcm_swf -> f32 WAV, mp1-3 / ac3 -> frames back to back, +-- flac -> fLaC + metadata blocks, opus / vorbis -> Ogg, aac -> ADTS. E-AC-3 is UNSUPPORTED. +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Types = __include("Types") +local Mux = __include("containers/Ogg/Mux") +local Adpcm = __include("codecs/audio/Adpcm") + +local AudioWrap = {} + +type PacketSource = { + count: ((self: any, track: number) -> number)?, + get: ((self: any, track: number, k: number) -> Types.Packet?)?, +} + +local function allPackets(dmx: PacketSource, track: Types.Track): { Types.Packet } + local out: { Types.Packet } = {} + local n = if dmx.count then dmx:count(track.id) else 0 + if n > 0 and dmx.get then + for k = 1, n do + local p = dmx:get(track.id, k) + if p then + table.insert(out, p) + end + end + end + return out +end + +local function concat(packets: { Types.Packet }, prefix: buffer?): buffer + local total = if prefix then buffer.len(prefix) else 0 + for _, p in packets do + total += buffer.len(p.data) + end + local out = buffer.create(total) + local o = 0 + if prefix then + buffer.copy(out, 0, prefix) + o = buffer.len(prefix) + end + for _, p in packets do + buffer.copy(out, o, p.data) + o += buffer.len(p.data) + end + return out +end + +local PCM: { [string]: { number } } = { -- tag, bits, bytes swapped (big-endian source) + pcm_u8 = { 1, 8, 0 }, + pcm_s8 = { 1, 8, 0 }, + pcm_s16le = { 1, 16, 0 }, + pcm_s24le = { 1, 24, 0 }, + pcm_s32le = { 1, 32, 0 }, + pcm_s16be = { 1, 16, 1 }, + pcm_s24be = { 1, 24, 1 }, + pcm_s32be = { 1, 32, 1 }, + pcm_f32le = { 3, 32, 0 }, + pcm_f64le = { 3, 64, 0 }, + pcm_f32be = { 3, 32, 1 }, + pcm_f64be = { 3, 64, 1 }, + pcm_alaw = { 6, 8, 0 }, + pcm_mulaw = { 7, 8, 0 }, +} + +local function wav(fmt: buffer, data: buffer): buffer + local w = Bytes.writer(buffer.len(data) + buffer.len(fmt) + 64) + local fl = buffer.len(fmt) + local dl = buffer.len(data) + w:string("RIFF") + w:u32le(4 + 8 + fl + (fl % 2) + 8 + dl + (dl % 2)) + w:string("WAVE") + w:string("fmt ") + w:u32le(fl) + w:bytes(fmt) + if fl % 2 == 1 then + w:u8(0) + end + w:string("data") + w:u32le(dl) + w:bytes(data) + if dl % 2 == 1 then + w:u8(0) + end + return w:finish() +end + +local function pcmWav(track: Types.Track, packets: { Types.Packet }): (buffer?, Err.Err?) + local spec = PCM[track.codec] + local ch = track.channels or 1 + local rate = math.floor((track.sampleRate or 0) + 0.5) + if ch < 1 or rate <= 0 then + return nil, Err.new(Err.CORRUPT, "PCM track without channels / sample rate") + end + local bits = spec[2] + local data = concat(packets) + if spec[3] == 1 then + local bps = bits // 8 + for i = 0, buffer.len(data) - bps, bps do + for k = 0, bps // 2 - 1 do + local a, b = buffer.readu8(data, i + k), buffer.readu8(data, i + bps - 1 - k) + buffer.writeu8(data, i + k, b) + buffer.writeu8(data, i + bps - 1 - k, a) + end + end + end + if track.codec == "pcm_s8" then + for i = 0, buffer.len(data) - 1 do + buffer.writeu8(data, i, (buffer.readu8(data, i) + 128) % 256) + end + end + local f = Bytes.writer(16) + local align = ch * bits // 8 + f:u16le(spec[1]) + f:u16le(ch) + f:u32le(rate) + f:u32le(rate * align) + f:u16le(align) + f:u16le(bits) + 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 + +-- the number of 48 kHz samples in an Opus packet (RFC 6716 section 3.1) +local function opusSamples(b: buffer): number + local n = buffer.len(b) + if n < 1 then + return 0 + end + local toc = buffer.readu8(b, 0) + local config = toc // 8 + local fs: number + if config < 12 then + fs = ({ 480, 960, 1920, 2880 })[config % 4 + 1] + elseif config < 16 then + fs = if config % 2 == 0 then 480 else 960 + else + fs = ({ 120, 240, 480, 960 })[config % 4 + 1] + end + local c = toc % 4 + local frames = if c == 0 then 1 elseif c == 3 then (if n >= 2 then buffer.readu8(b, 1) % 64 else 0) else 2 + return fs * frames +end + +local function opusHead(track: Types.Track): buffer + local c = track.config + if c and buffer.len(c) >= 19 and buffer.readstring(c, 0, 8) == "OpusHead" then + return c + end + local w = Bytes.writer(19) + w:string("OpusHead") + w:u8(1) + w:u8(math.clamp(track.channels or 2, 1, 2)) + w:u16le(math.floor((track.codecDelay or 0) * 48000 + 0.5)) + w:u32le(math.floor(track.sampleRate or 48000)) + w:u16le(0) + w:u8(0) + return w:finish() +end + +local function opusTags(): buffer + local w = Bytes.writer(32) + w:string("OpusTags") + local vendor = "rosetta" + w:u32le(#vendor) + w:string(vendor) + w:u32le(0) + return w:finish() +end + +local function ogg(headers: { buffer }, packets: { Types.Packet }, granuleOf: (p: Types.Packet, i: number) -> number): buffer + local mux = Mux.new({ pageSize = 4096 }) + local s = mux:stream(1) + for i, h in headers do + s:packet(h, 0, { flush = i == 1 or i == #headers }) + end + for i, p in packets do + s:packet(p.data, granuleOf(p, i), { eos = i == #packets }) + end + return mux:finish() +end + +-- Matroska's Vorbis CodecPrivate: Xiph-laced headers (count - 1, sizes, data) +local function xiphHeaders(c: buffer): { buffer }? + local n = buffer.len(c) + if n < 3 then + return nil + end + local count = buffer.readu8(c, 0) + 1 + local p = 1 + local sizes = {} + local total = 0 + for k = 1, count - 1 do + local s = 0 + while true do + if p >= n then + return nil + end + local b = buffer.readu8(c, p) + p += 1 + s += b + if b ~= 255 then + break + end + end + sizes[k] = s + total += s + end + sizes[count] = n - p - total + if sizes[count] < 0 then + return nil + end + local out = {} + for k = 1, count do + local b = buffer.create(sizes[k]) + buffer.copy(b, 0, c, p, sizes[k]) + p += sizes[k] + out[k] = b + end + return out +end + +-- Vorbis packet sizes: the block sizes from the identification header and each mode's block flag from the end of the +-- setup header (read backwards from its framing bit: mode entries are 41 bits whose window / transform types are 0, +-- preceded by the 6-bit mode count), so the Ogg granules are exact: a packet yields (previous + current block) / 4 +-- samples (the first one as if its previous block had its own size, as ffmpeg times it). +local function bit(b: buffer, k: number): number + return bit32.extract(buffer.readu8(b, k // 8), k % 8, 1) +end +local function bits(b: buffer, k: number, n: number): number + local v = 0 + for i = n - 1, 0, -1 do + v = v * 2 + bit(b, k + i) + end + return v +end + +local function vorbisModes(id: buffer, setup: buffer): ({ number }?, { boolean }?) + if buffer.len(id) < 30 or buffer.len(setup) < 8 then + return nil, nil + end + local bs = buffer.readu8(id, 28) + local sizes = { 2 ^ (bs % 16), 2 ^ (bs // 16) } + -- the framing bit: the highest set bit of the last non-zero byte + local last = buffer.len(setup) - 1 + while last > 0 and buffer.readu8(setup, last) == 0 do + last -= 1 + end + local v = buffer.readu8(setup, last) + local hb = 7 + while hb > 0 and bit32.extract(v, hb, 1) == 0 do + hb -= 1 + end + local f = last * 8 + hb + local flags: { boolean } = {} + local pos = f + while #flags < 64 and pos - 41 >= 7 * 8 do + local s0 = pos - 41 + if bits(setup, s0 + 1, 16) ~= 0 or bits(setup, s0 + 17, 16) ~= 0 then + break + end + table.insert(flags, 1, bit(setup, s0) == 1) + pos = s0 + end + -- the largest count whose 6-bit field matches + for n = #flags, 1, -1 do + local start = f - 41 * n + if start - 6 >= 0 and bits(setup, start - 6, 6) == n - 1 then + local out = {} + for i = #flags - n + 1, #flags do + table.insert(out, flags[i]) + end + return sizes, out + end + end + return nil, nil +end + +local function adts(track: Types.Track, packets: { Types.Packet }): (buffer?, Err.Err?) + local c = track.config + local profile, rateIndex, chanConfig + if c and buffer.len(c) >= 2 then + local b0, b1 = buffer.readu8(c, 0), buffer.readu8(c, 1) + profile = b0 // 8 -- audio object type + rateIndex = (b0 % 8) * 2 + b1 // 128 + chanConfig = (b1 // 8) % 16 + -- HE-AAC (5) / HE-AACv2 (29), 14496-3 1.6.2.1: ADTS carries the AAC-LC core (the decoder finds SBR / PS in it) + if (profile == 5 or profile == 29) and rateIndex ~= 15 and buffer.len(c) >= 4 then + local v = buffer.readu8(c, 1) * 65536 + buffer.readu8(c, 2) * 256 + buffer.readu8(c, 3) + local extIndex = (v // 2 ^ 15) % 16 -- after aot (5), sfi (4), channels (4): bits 13 .. 16 + local core = if extIndex == 15 then -1 else (v // 2 ^ 10) % 32 -- bits 17 .. 21 + profile = if core == 2 then 2 else -1 + end + else + local rates = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 } + profile = 2 + rateIndex = 4 + for i, r in rates do + if r == math.floor((track.sampleRate or 44100) + 0.5) then + rateIndex = i - 1 + end + end + chanConfig = track.channels or 2 + end + if profile < 1 or profile > 4 or rateIndex > 12 then + return nil, Err.new(Err.UNSUPPORTED, "AAC object type " .. tostring(profile) .. " in ADTS") + end + local w = Bytes.writer(64) + for _, p in packets do + local len = buffer.len(p.data) + 7 + w:u8(0xFF) + w:u8(0xF1) + w:u8((profile - 1) * 64 + rateIndex * 4 + chanConfig // 4) + w:u8((chanConfig % 4) * 64 + (len // 2048) % 4) + w:u8((len // 8) % 256) + w:u8((len % 8) * 32 + 0x1F) + w:u8(0xFC) + w:bytes(p.data) + end + return w:finish(), nil +end + +-- trim: a container's codec delay (Matroska CodecDelay, an MP4 edit's media time for MP2 / MP3 / AAC, as ffmpeg) +-- and end padding +function AudioWrap.trim(dec: any, skip: number, length: number?): any + if skip <= 0 and length == nil then + return dec + end + skip = math.max(0, skip) + local rate = dec.sampleRate + local w: any = setmetatable({}, { __index = dec }) + w.frames = math.max(0, (dec.frames or 0) - skip) + if length then + w.frames = if (dec.frames or 0) > 0 then math.min(w.frames, length) else length + end + w.duration = w.frames / rate + local cap = length or math.huge + local delivered = 0 + local function drop() + local left = skip + while left > 0 do + local _, n = dec:read(math.min(left, 4096)) + if not n or n <= 0 then + break + end + left -= n + end + end + local started = false + function w.read(_: any, n: number, out: buffer?): (buffer, number) + if not started then + started = true + drop() + end + local want = math.min(n, cap - delivered) + if want <= 0 then + return out or buffer.create(0), 0 + end + local b, got = dec:read(want, out) + delivered += got + return b, got + end + function w.seek(_: any, seconds: number) + started = true + if seconds <= 0 then + dec:seek(0) + drop() + delivered = 0 + else + dec:seek(seconds + skip / rate) + delivered = math.floor(seconds * rate + 0.5) + end + end + function w.position(_: any): number + return math.max(0, dec:position() - skip / rate) + end + return w +end + +function AudioWrap.wrap(dmx: any, track: Types.Track): (buffer?, string?, Err.Err?) + if type(track) ~= "table" or track.kind ~= "audio" then + return nil, nil, Err.new(Err.ARG, "not an audio track") + end + if track.unsupported then + return nil, nil, Err.new(Err.UNSUPPORTED, track.unsupported) + end + local codec = track.codec + local packets = allPackets(dmx, track) + if #packets == 0 then + return nil, nil, Err.new(Err.CORRUPT, "audio track without packets") + end + 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 + end + if codec == "mp3" or codec == "mp2" or codec == "mp1" then + return concat(packets), "mp3", nil + end + if codec == "ac3" then + return concat(packets), "ac3", nil + end + if codec == "flac" then + local c = track.config + local prefix: buffer? = nil + if c and buffer.len(c) >= 4 and buffer.readstring(c, 0, 4) == "fLaC" then + prefix = c + elseif c and buffer.len(c) >= 34 then + -- metadata blocks without the marker (MP4 dfLa payload after version / flags) + local start = if buffer.len(c) >= 38 and buffer.readu8(c, 0) == 0 and buffer.readu8(c, 4) % 128 == 0 then 4 else 0 + local b = buffer.create(4 + buffer.len(c) - start) + buffer.writestring(b, 0, "fLaC") + buffer.copy(b, 4, c, start) + prefix = b + else + return nil, nil, Err.new(Err.CORRUPT, "FLAC track without its STREAMINFO") + end + return concat(packets, prefix), "flac", nil + end + if codec == "opus" then + local head = opusHead(track) + local pre = buffer.readu16(head, 10) + local g = pre + local out = ogg({ head, opusTags() }, packets, function(p: Types.Packet): number + g += opusSamples(p.data) + local d = (p :: any).discardPadding + if type(d) == "number" and d > 0 then + return g - math.floor(d * 48000 + 0.5) -- the end trimming (WebM DiscardPadding) + end + return g + end) + return out, "opus", nil + end + if codec == "vorbis" then + local c = track.config + local headers = c and xiphHeaders(c) + if not headers or #headers ~= 3 then + return nil, nil, Err.new(Err.CORRUPT, "Vorbis track without its three headers") + end + local sizes, modes = vorbisModes(headers[1], headers[3]) + local granule, prev = 0, nil :: number? + local rate = track.sampleRate or 44100 + local scale = track.timescale + local out = ogg(headers, packets, function(p: Types.Packet): number + if not sizes or not modes then + return math.floor((p.pts + (p.duration or 0)) / scale * rate + 0.5) -- from the container's times + end + local d = p.data + if buffer.len(d) == 0 or buffer.readu8(d, 0) % 2 ~= 0 then + return granule + end + local mb = 0 + while 2 ^ mb < #(modes :: { boolean }) do + mb += 1 + end + local m = if mb > 0 and buffer.len(d) * 8 > mb then bits(d, 1, mb) else 0 + local cur = sizes[if (modes :: { boolean })[m + 1] then 2 else 1] + if prev then + granule += (prev + cur) // 4 + end + prev = cur + return granule + end) + return out, "vorbis", nil + end + if codec == "aac" then + if track.adts then + return concat(packets), "aac", nil -- already ADTS (MPEG-TS) + end + local b, err = adts(track, packets) + return b, if b then "aac" else nil, err + end + return nil, nil, Err.new(Err.UNSUPPORTED, "no audio format for codec " .. tostring(codec)) +end + +return AudioWrap +end +end + + + + + + containers_Avi + --!optimize 2 +--!nocheck +-- rosetta chunk containers_Avi (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/Avi"] = function() @@ -128311,6 +128178,19 @@ end return Avi end +end + + + + + + containers_Blend + --!optimize 2 +--!nocheck +-- rosetta chunk containers_Blend (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/Blend"] = function() -- containers/Blend: Blender .blend files (read only). New in rosetta, from the file layout: the 12-byte header @@ -129185,6 +129065,19 @@ end return Chunks end +end + + + + + + containers_Cpio + --!optimize 2 +--!nocheck +-- rosetta chunk containers_Cpio (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/Cpio"] = function() -- containers/Cpio: cpio, read and written, from cpio(5) (libarchive, GNU cpio) and POSIX.1-1988 (odc). Reads newc @@ -130213,6 +130106,19 @@ end return Ebml end +end + + + + + + containers_Fat + --!optimize 2 +--!nocheck +-- rosetta chunk containers_Fat (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/Fat"] = function() -- containers/Fat: FAT12 / FAT16 / FAT32 over a byte range (BPB, chains, VFAT long names checksum-validated against @@ -130901,6 +130807,19 @@ end return Fat end +end + + + + + + containers_Iso9660 + --!optimize 2 +--!nocheck +-- rosetta chunk containers_Iso9660 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/Iso9660"] = function() -- containers/Iso9660: ISO 9660 (ECMA-119) images, read; from ECMA-119, SUSP / RRIP 1.12, Joliet and El Torito 1.0, no @@ -131406,6 +131325,19 @@ end return Iso9660 end +end + + + + + + containers_IsoBmff + --!optimize 2 +--!nocheck +-- rosetta chunk containers_IsoBmff (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 6 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/IsoBmff"] = function() @@ -133769,6 +133701,19 @@ end return QtPalette end +end + + + + + + containers_MacFile + --!optimize 2 +--!nocheck +-- rosetta chunk containers_MacFile (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (3 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/MacFile"] = function() -- containers/MacFile: classic Mac OS files (a data fork, a resource fork and Finder info) as Archive entries, shared by @@ -134343,6 +134288,195 @@ end return Ogg end +__FILES["containers/Ogg/Mux"] = @native function() + + + +-- containers/Ogg/Mux: the Ogg page writer (RFC 3533), for Ogg Opus / Vorbis / FLAC output. New in rosetta. +-- Packets are laced into pages per logical stream; a page is closed when it reaches opts.pageSize bytes of data (or +-- 255 lacing values), when a packet asks for flush, and at the end (eos). The page granule is the granule of the last +-- packet that finishes on it (-1 when none does). Pages go to the output in the order they close, so the bos pages +-- of a multiplexed file come first when every stream's first packet is written (with flush) before any other. +-- Never throws: a bad argument returns false, Err. +local Err = __include("core/Err") +local Crc32 = __include("core/Crc32") + +local writeu8, writeu32, writei32 = buffer.writeu8, buffer.writeu32, buffer.writei32 + +local Mux = {} +Mux.__index = Mux +local Stream = {} +Stream.__index = Stream + +type Options = { + pageSize: number?, -- close a page once its data reaches this many bytes (default 4096; at most 255 * 255) +} +type PacketOptions = { + flush: boolean?, -- close the page after this packet (headers; default false) + eos: boolean?, -- this is the stream's last packet (default false: finish() writes an empty eos page if needed) +} + +@native function Mux.new(opts: Options?): any + local size = opts and opts.pageSize or 4096 + if type(size) ~= "number" or size < 1 then + size = 4096 + end + return setmetatable({ + pageSize = math.min(size, 255 * 255), + chunks = {} :: { buffer }, + total = 0, + streams = {} :: { any }, + nextSerial = 1, + }, Mux) +end + +@native function Mux.stream(self: any, serial: number?): any + local sr = serial or self.nextSerial + self.nextSerial = math.max(self.nextSerial, sr + 1) + local s = setmetatable({ + mux = self, + serial = sr % 4294967296, + seq = 0, + lacing = {} :: { number }, + parts = {} :: { any }, -- buffer, offset, length triples of the page data + dataLen = 0, + granule = -1, + continued = false, -- the page being built starts with the tail of a packet + first = true, + ended = false, + lastGranule = -1, + }, Stream) + table.insert(self.streams, s) + return s +end + +-- the CRC of a page (the crc field written as zero) +@native local function crc(b: buffer, n: number): number + return Crc32.msb(b, 0, n, 0) +end + +@native function Stream._flush(self: any, eos: boolean) + local nseg = #self.lacing + local n = 27 + nseg + self.dataLen + local b = buffer.create(n) + buffer.writestring(b, 0, "OggS") + local flags = (if self.continued then 1 else 0) + (if self.first then 2 else 0) + (if eos then 4 else 0) + writeu8(b, 5, flags) + local g = self.granule + if g < 0 then + writeu32(b, 6, 0xFFFFFFFF) + writei32(b, 10, -1) + else + writeu32(b, 6, g % 4294967296) + writeu32(b, 10, (g // 4294967296) % 4294967296) + end + writeu32(b, 14, self.serial) + writeu32(b, 18, self.seq % 4294967296) + writeu8(b, 26, nseg) + for i = 1, nseg do + writeu8(b, 26 + i, self.lacing[i]) + end + local o = 27 + nseg + local parts = self.parts + for i = 1, #parts, 3 do + buffer.copy(b, o, parts[i], parts[i + 1], parts[i + 2]) + o += parts[i + 2] + end + writeu32(b, 22, crc(b, n)) + local m = self.mux + table.insert(m.chunks, b) + m.total += n + self.seq += 1 + self.first = false + self.lacing, self.parts, self.dataLen, self.granule = {}, {}, 0, -1 + self.continued = false + if eos then + self.ended = true + end +end + +@native function Stream.packet(self: any, data: any, granule: number, opts: PacketOptions?, offset: number?, length: number?): (boolean, Err.Err?) + if self.ended then + return false, Err.new(Err.ARG, "packet after the end of stream " .. self.serial) + end + local b: buffer + if type(data) == "string" then + b = buffer.fromstring(data) + elseif type(data) == "buffer" then + b = data + else + return false, Err.new(Err.ARG, "packet: data must be a buffer or a string") + end + if type(granule) ~= "number" then + return false, Err.new(Err.ARG, "packet: granule must be a number") + end + local off = offset or 0 + local len = length or (buffer.len(b) - off) + if off < 0 or len < 0 or off + len > buffer.len(b) then + return false, Err.new(Err.ARG, "packet: range outside the buffer") + end + local pageSize = self.mux.pageSize + local left = len + local pos = off + -- lacing: 255-byte segments then one < 255 (0 when the size is a multiple of 255) + while true do + if #self.lacing == 255 or (self.dataLen >= pageSize and #self.lacing > 0) then + self:_flush(false) + self.continued = pos > off -- the next page starts inside this packet + end + local seg = math.min(left, 255) + table.insert(self.lacing, seg) + if seg > 0 then + table.insert(self.parts, b) + table.insert(self.parts, pos) + table.insert(self.parts, seg) + end + self.dataLen += seg + pos += seg + left -= seg + if seg < 255 then + break + end + end + if granule >= 0 then -- -1 (unknown) keeps the granule of an earlier packet finishing on this page + self.granule = granule + self.lastGranule = granule + end + local eos = opts and opts.eos or false + if eos then + self:_flush(true) + elseif (opts and opts.flush) or self.dataLen >= pageSize or #self.lacing == 255 then + self:_flush(false) + end + return true, nil +end + +@native function Stream.flush(self: any) + if not self.ended and #self.lacing > 0 then + self:_flush(false) + end +end + +@native function Mux.finish(self: any): buffer + for _, s in self.streams do + if not s.ended then + if #s.lacing == 0 then + s.granule = s.lastGranule + end + s:_flush(true) + end + end + local out = buffer.create(self.total) + local o = 0 + for _, c in self.chunks do + buffer.copy(out, o, c, 0, buffer.len(c)) + o += buffer.len(c) + end + return out +end + +return Mux +end __FILES["containers/Ogg/Page"] = @native function() @@ -134509,6 +134643,19 @@ end return Page end +end + + + + + + containers_Riff + --!optimize 2 +--!nocheck +-- rosetta chunk containers_Riff (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/Riff"] = function() -- containers/Riff: the RIFF chunk container (RIFF, RIFX big-endian, RF64 / BW64 with the ds64 chunk), read leniently @@ -135240,6 +135387,19 @@ end return Tar end +end + + + + + + containers_Zip + --!optimize 2 +--!nocheck +-- rosetta chunk containers_Zip (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["containers/Zip"] = function() @@ -135876,13 +136036,13 @@ end - + - core + core_Adler32 --!optimize 2 --!nocheck --- rosetta chunk core (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 6 modules (5 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk core_Adler32 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (5 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["core/Adler32"] = @native function() @@ -136466,57 +136626,156 @@ end return Bits end -__FILES["core/Crc16"] = @native function() +__FILES["core/Crc32"] = @native function() --- core/Crc16: the 16-bit CRCs old archive formats use, table driven. New code. ccitt: CRC-16/XMODEM (0x1021, MSB first, --- init 0, no final XOR; BinHex 4.0, MacBinary II / III). arc: CRC-16/ARC (0x8005 reflected = 0xA001, init 0; LHA, Zoo, --- ARC). Never throws: the range is clamped. -local band, bxor, rshift, lshift = bit32.band, bit32.bxor, bit32.rshift, bit32.lshift -local readu8 = buffer.readu8 +-- core/Crc32: CRC-32 (IEEE 802.3, the zlib / gzip / zip / PNG polynomial 0xEDB88320, reflected), slice-by-8. +-- Absorbed from deflate-luau src/Deflate/Checksum.luau (same author; no third-party code). Never throws. +local band, bxor, rshift, lshift, byteswap = bit32.band, bit32.bxor, bit32.rshift, bit32.lshift, bit32.byteswap +local readu8, readu32 = buffer.readu8, buffer.readu32 -local MSB = table.create(256, 0) -local ARC = table.create(256, 0) +local T0, T1, T2, T3 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0) +local T4, T5, T6, T7 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0) for n = 0, 255 do - local c = lshift(n, 8) + local c = n for _ = 1, 8 do - c = if band(c, 0x8000) ~= 0 then bxor(band(lshift(c, 1), 0xFFFF), 0x1021) else band(lshift(c, 1), 0xFFFF) + if band(c, 1) ~= 0 then + c = bxor(0xEDB88320, rshift(c, 1)) + else + c = rshift(c, 1) + end + end + T0[n + 1] = c +end +for n = 0, 255 do + local c = T0[n + 1] + c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) + T1[n + 1] = c + c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) + T2[n + 1] = c + c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) + T3[n + 1] = c + c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) + T4[n + 1] = c + c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) + T5[n + 1] = c + c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) + T6[n + 1] = c + c = bxor(T0[band(c, 255) + 1], rshift(c, 8)) + T7[n + 1] = c +end + +@native local function crc32(buf: buffer, off: number, len: number, crc: number?): number + local c = bxor(crc or 0, 0xFFFFFFFF) + local i, e = off, off + len + local e8 = e - 8 + while i <= e8 do + c = bxor(c, readu32(buf, i)) + local d = readu32(buf, i + 4) + c = bxor( + T7[band(c, 255) + 1], + T6[band(rshift(c, 8), 255) + 1], + T5[band(rshift(c, 16), 255) + 1], + T4[rshift(c, 24) + 1], + T3[band(d, 255) + 1], + T2[band(rshift(d, 8), 255) + 1], + T1[band(rshift(d, 16), 255) + 1], + T0[rshift(d, 24) + 1] + ) + i += 8 + end + local e4 = e - 4 + while i <= e4 do + c = bxor(c, readu32(buf, i)) + c = bxor(T3[band(c, 255) + 1], T2[band(rshift(c, 8), 255) + 1], T1[band(rshift(c, 16), 255) + 1], T0[rshift(c, 24) + 1]) + i += 4 + end + while i < e do + c = bxor(T0[band(bxor(c, readu8(buf, i)), 255) + 1], rshift(c, 8)) + i += 1 + end + return bxor(c, 0xFFFFFFFF) +end + +@native local function range(buf: buffer, offset: number?, length: number?): (number, number) + local n = buffer.len(buf) + local o = math.clamp(offset or 0, 0, n) + return o, math.clamp(length or (n - o), 0, n - o) +end + +local Crc32 = {} + +@native function Crc32.of(buf: buffer, offset: number?, length: number?, crc: number?): number + local o, l = range(buf, offset, length) + return crc32(buf, o, l, crc) +end + +@native function Crc32.string(s: string, crc: number?): number + return crc32(buffer.fromstring(s), 0, #s, crc) +end + +Crc32.raw = crc32 + +-- MSB-first CRC-32 (polynomial 0x04C11DB7, not reflected, raw register, no inversions): Ogg pages (init 0), +-- MPEG-2 PSI sections and bzip2 blocks (init 0xFFFFFFFF) +local MSB = table.create(256, 0) +for n = 0, 255 do + local c = lshift(n, 24) + for _ = 1, 8 do + c = if band(c, 0x80000000) ~= 0 then bxor(lshift(c, 1), 0x04C11DB7) else lshift(c, 1) end MSB[n + 1] = c - local r = n - for _ = 1, 8 do - r = if band(r, 1) ~= 0 then bxor(rshift(r, 1), 0xA001) else rshift(r, 1) +end +Crc32.MSB_TABLE = MSB + +-- slice-by-8 for the MSB-first CRC: M[k][n] = the CRC register after byte n and k zero bytes +local M1, M2, M3 = table.create(256, 0), table.create(256, 0), table.create(256, 0) +local M4, M5, M6, M7 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0) +for n = 0, 255 do + local c = MSB[n + 1] + c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) + M1[n + 1] = c + c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) + M2[n + 1] = c + c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) + M3[n + 1] = c + c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) + M4[n + 1] = c + c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) + M5[n + 1] = c + c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) + M6[n + 1] = c + c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1]) + M7[n + 1] = c +end + +@native function Crc32.msb(buf: buffer, off: number, len: number, init: number?): number + local c = init or 0 + local i, e = off, off + len + local e8 = e - 8 + while i <= e8 do + c = bxor(c, byteswap(readu32(buf, i))) + local d = byteswap(readu32(buf, i + 4)) + c = bxor( + M7[rshift(c, 24) + 1], + M6[band(rshift(c, 16), 255) + 1], + M5[band(rshift(c, 8), 255) + 1], + M4[band(c, 255) + 1], + M3[rshift(d, 24) + 1], + M2[band(rshift(d, 16), 255) + 1], + M1[band(rshift(d, 8), 255) + 1], + MSB[band(d, 255) + 1] + ) + i += 8 end - ARC[n + 1] = r -end - -local Crc16 = {} - -@native local function clamp(buf: buffer, off: number, len: number): (number, number) - local n = buffer.len(buf) - local o = math.clamp(math.floor(off), 0, n) - return o, math.clamp(math.floor(len), 0, n - o) -end - -@native function Crc16.ccitt(buf: buffer, off: number, len: number, crc: number?): number - local o, l = clamp(buf, off, len) - local c = crc or 0 - for i = o, o + l - 1 do - c = bxor(band(lshift(c, 8), 0xFFFF), MSB[bxor(rshift(c, 8), readu8(buf, i)) + 1]) + while i < e do + c = bxor(lshift(c, 8), MSB[bxor(rshift(c, 24), readu8(buf, i)) + 1]) + i += 1 end return c end -@native function Crc16.arc(buf: buffer, off: number, len: number, crc: number?): number - local o, l = clamp(buf, off, len) - local c = crc or 0 - for i = o, o + l - 1 do - c = bxor(rshift(c, 8), ARC[bxor(band(c, 0xFF), readu8(buf, i)) + 1]) - end - return c -end - -return Crc16 +return Crc32 end __FILES["core/Md5"] = @native function() @@ -136676,46 +136935,17 @@ end return Md5 end -__FILES["core/Sniff"] = function() - --- core/Sniff: helpers for the formats' sniff functions (which return 0..1 from the first bytes, never consuming and --- never throwing): magic comparison and the start of a text file without its UTF-8 byte order mark. -local Sniff = {} - -type Peeker = { peek: (any, number, number?) -> string } - -function Sniff.magic(r: Peeker, s: string, at: number?, score: number?): number - return if r:peek(#s, at) == s then score or 1 else 0 -end - -function Sniff.dropBom(s: string): string - return if string.sub(s, 1, 3) == "\239\187\191" then string.sub(s, 4) else s -end - -function Sniff.text(r: Peeker, n: number, trim: boolean?): string - local s = r:peek(n) - if string.sub(s, 1, 3) == "\239\187\191" then - s = string.sub(s, 4) - end - if trim then - s = string.match(s, "^%s*(.*)$") :: string - end - return s -end - -return Sniff -end end - + - data + data_cbor --!optimize 2 --!nocheck --- rosetta chunk data (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 22 modules (3 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk data_cbor (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["data/cbor"] = function() @@ -137698,6 +137928,19 @@ end return Csv end +end + + + + + + data_ini + --!optimize 2 +--!nocheck +-- rosetta chunk data_ini (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["data/ini"] = function() -- data/ini: INI files read the way Python's configparser does (interpolation off, key case kept), new code. Supports: @@ -138626,6 +138869,19 @@ NbtFormat.Nbt = Nbt return NbtFormat end +end + + + + + + data_plist + --!optimize 2 +--!nocheck +-- rosetta chunk data_plist (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["data/plist"] = function() -- data/plist: Apple property lists, new code. Supports: XML read / write (byte-identical to Python's plistlib), @@ -139597,6 +139853,19 @@ end return SnbtFormat end +end + + + + + + data_toml + --!optimize 2 +--!nocheck +-- rosetta chunk data_toml (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["data/toml"] = function() -- data/toml: TOML 1.0.0 (https://toml.io/en/v1.0.0), new code, tested against toml-test. Supports: the whole 1.0 @@ -140747,6 +141016,19 @@ end return Vdf end +end + + + + + + data_xml + --!optimize 2 +--!nocheck +-- rosetta chunk data_xml (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["data/xml"] = function() -- data/xml: XML 1.0 over codecs/text/Xml. Supports: decode to a "#document" XmlNode tree, encode a document or an @@ -140803,6 +141085,19 @@ end return XmlFormat end +end + + + + + + data_yaml + --!optimize 2 +--!nocheck +-- rosetta chunk data_yaml (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["data/yaml"] = function() -- data/yaml: YAML 1.2 (core schema), new code. Supports: block / flow styles, every scalar style, anchors and aliases @@ -142463,13 +142758,13 @@ end - + - font + font_bdf --!optimize 2 --!nocheck --- rosetta chunk font (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 14 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk font_bdf (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["font/bdf"] = function() @@ -142761,6 +143056,19 @@ end return Bdf end +end + + + + + + font_bmfont + --!optimize 2 +--!nocheck +-- rosetta chunk font_bmfont (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["font/bmfont"] = function() -- font/bmfont: AngelCode BMFont descriptors (.fnt: text, XML, binary version 3), read and written, from the BMFont @@ -143873,6 +144181,19 @@ end return Eot end +end + + + + + + font_fon + --!optimize 2 +--!nocheck +-- rosetta chunk font_fon (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["font/fon"] = function() -- font/fon: Windows raster fonts: .fnt resources (versions 2.0 / 3.0) and .fon NE / PE executables holding them as @@ -144631,6 +144952,19 @@ end return Pcf end +end + + + + + + font_psf + --!optimize 2 +--!nocheck +-- rosetta chunk font_psf (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["font/psf"] = function() -- font/psf: Linux console fonts (kbd project's psf docs, Andries Brouwer): PSF 1 (magic 36 04, UCS-2 table, FFFF / @@ -145639,6 +145973,19 @@ end return Charstring end +end + + + + + + font_woff + --!optimize 2 +--!nocheck +-- rosetta chunk font_woff (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["font/woff"] = function() -- font/woff: WOFF 1.0 (W3C Recommendation, 2012): zlib-compressed sfnt tables, rebuilt and read through @@ -146372,12 +146719,12 @@ end - + - host + host_Love --!optimize 2 --!nocheck --- rosetta chunk host (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- rosetta chunk host_Love (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. -- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) @@ -146960,13 +147307,13 @@ end - + - image_1 + image_ani --!optimize 2 --!nocheck --- rosetta chunk image_1 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 25 modules (7 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk image_ani (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["image/ani"] = function() @@ -147895,6 +148242,19 @@ end return Blp end +end + + + + + + image_bmp + --!optimize 2 +--!nocheck +-- rosetta chunk image_bmp (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/bmp"] = function() @@ -148793,6 +149153,19 @@ Dds.DXGI = DXGI return Dds end +end + + + + + + image_exr + --!optimize 2 +--!nocheck +-- rosetta chunk image_exr (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/exr"] = function() -- image/exr: OpenEXR (openexr.com file layout docs; PIZ after OpenEXR, BSD-3-Clause: licenses/openexr-LICENSE.md). @@ -150021,6 +150394,19 @@ end return Piz end +end + + + + + + image_gif + --!optimize 2 +--!nocheck +-- rosetta chunk image_gif (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/gif"] = function() -- image/gif: GIF87a / GIF89a, from the GIF89a spec (CompuServe 1990). Supports: every image, interlace, LZW code sizes @@ -151053,6 +151439,19 @@ end return Codec end +end + + + + + + image_icns + --!optimize 2 +--!nocheck +-- rosetta chunk image_icns (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/icns"] = function() -- image/icns: Apple icon images (icns resource type). Supports: is32 / il32 / ih32 / it32 (icns RLE) with s8mk / l8mk / @@ -151756,6 +152155,19 @@ end return Dib end +end + + + + + + image_ilbm + --!optimize 2 +--!nocheck +-- rosetta chunk image_ilbm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/ilbm"] = function() -- image/ilbm: IFF ILBM / PBM (EA IFF 85 "ILBM", Amiga ROM Kernel Manual). Supports: 1..8 planes + CMAP, EHB (CAMG @@ -152234,6 +152646,19 @@ end return Jpeg end +end + + + + + + image_ktx + --!optimize 2 +--!nocheck +-- rosetta chunk image_ktx (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/ktx"] = function() -- image/ktx: Khronos KTX 1.1 / KTX 2.0. Supports: KTX1 (GL compressed and uncompressed, big-endian), KTX2 (VkFormat BCn @@ -153027,6 +153452,19 @@ end return Lmp end +end + + + + + + image_pcx + --!optimize 2 +--!nocheck +-- rosetta chunk image_pcx (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/pcx"] = function() -- image/pcx: ZSoft PC Paintbrush (ZSoft "Technical Reference Manual" header and RLE). Supports: 1-bit, 1-bit x 2..4 @@ -153946,6 +154384,19 @@ end return Codec end +end + + + + + + image_qoi + --!optimize 2 +--!nocheck +-- rosetta chunk image_qoi (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/qoi"] = function() -- image/qoi: QOI, the Quite OK Image format (specification 1.0, qoiformat.org). Supports: the whole spec (RGB / RGBA, @@ -154510,19 +154961,6 @@ end return Sgi end -end - - - - - - image_2 - --!optimize 2 ---!nocheck --- rosetta chunk image_2 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 14 modules (4 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["image/spr"] = function() -- image/spr: Quake (IDSP 1), Half-Life (IDSP 2, own palette, texture formats) and DarkPlaces SPR32 (IDSP 32, rgba) @@ -154836,6 +155274,19 @@ end return Spr end +end + + + + + + image_sunras + --!optimize 2 +--!nocheck +-- rosetta chunk image_sunras (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/sunras"] = function() -- image/sunras: Sun Raster (rasterfile(5), SunOS <rasterfile.h>). Supports: 1-bit (0 = white without a colour map), @@ -155552,6 +156003,19 @@ end return Codec end +end + + + + + + image_tiff + --!optimize 2 +--!nocheck +-- rosetta chunk image_tiff (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/tiff"] = function() -- image/tiff: TIFF 6.0 (+ Adobe technote 3, BigTIFF). Supports: strips, tiles, planar 1 / 2, none / LZW (old-style too) @@ -156769,6 +157233,19 @@ end return Pixels end +end + + + + + + image_tim + --!optimize 2 +--!nocheck +-- rosetta chunk image_tim (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/tim"] = function() -- image/tim: PlayStation TIM (magic 0x10), from Sony's PSX "File Formats" documentation. Supports: 4 / 8-bit CLUT, 15 / @@ -157246,6 +157723,19 @@ end return Vtf end +end + + + + + + image_webp + --!optimize 2 +--!nocheck +-- rosetta chunk image_webp (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/webp"] = function() -- image/webp: WebP (RFC 9649); bitstreams ported from libwebp 1.6 (BSD-3-Clause, licenses/libwebp-LICENSE.txt). @@ -158248,6 +158738,19 @@ end return Xbm end +end + + + + + + image_xpm + --!optimize 2 +--!nocheck +-- rosetta chunk image_xpm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["image/xpm"] = function() -- image/xpm: X PixMap (XPM 3 C source and XPM 2 plain; Arnaud Le Hors's "XPM Manual"). Supports: the values line and @@ -158576,13 +159079,13 @@ end - + - layered + layered_aseprite --!optimize 2 --!nocheck --- rosetta chunk layered (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 4 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk layered_aseprite (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["layered/aseprite"] = function() @@ -159323,6 +159826,19 @@ end return Aseprite end +end + + + + + + layered_ora + --!optimize 2 +--!nocheck +-- rosetta chunk layered_ora (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["layered/ora"] = function() -- layered/ora: OpenRaster 0.0.6 (freedesktop.org; new code): a zip with a stored "mimetype" first, stack.xml, PNG @@ -159610,6 +160126,19 @@ end return Ora end +end + + + + + + layered_psd + --!optimize 2 +--!nocheck +-- rosetta chunk layered_psd (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["layered/psd"] = function() -- layered/psd: Adobe Photoshop PSD / PSB (Photoshop File Formats Specification, 2016). Supports: every colour mode at @@ -160701,13 +161230,13 @@ end - + - model_1 + model_3ds --!optimize 2 --!nocheck --- rosetta chunk model_1 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 19 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk model_3ds (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["model/3ds"] = function() @@ -162741,6 +163270,19 @@ end return Write end +end + + + + + + model_3mf + --!optimize 2 +--!nocheck +-- rosetta chunk model_3mf (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/3mf"] = function() -- model/3mf: 3D Manufacturing Format (core 1.3, materials extension 1.2, production extension 1.1 p:path). @@ -163816,6 +164358,19 @@ end return Write end +end + + + + + + model_ase + --!optimize 2 +--!nocheck +-- rosetta chunk model_ase (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/ase"] = function() -- model/ase: 3ds Max ASCII Scene Export (*3DSMAX_ASCIIEXPORT 200), read + write; checked against assimp's ASE loader. @@ -165045,6 +165600,19 @@ end return Write end +end + + + + + + model_b3d + --!optimize 2 +--!nocheck +-- rosetta chunk model_b3d (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/b3d"] = function() -- model/b3d: Blitz3D .b3d (BB3D chunks, version 1; blitzbasic.com "b3dfile_specs.txt", checked against assimp). @@ -165671,6 +166239,19 @@ end return Read end +end + + + + + + model_blend + --!optimize 2 +--!nocheck +-- rosetta chunk model_blend (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 9 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/blend"] = function() -- model/blend: Blender .blend files (read only), every version from 2.4x to 5.x: plain, gzip or zstd compressed; @@ -168052,19 +168633,6 @@ end return Mesh end -end - - - - - - model_2 - --!optimize 2 ---!nocheck --- rosetta chunk model_2 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 19 modules (1 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["model/blend/Normals"] = function() -- model/blend/Normals: Blender's encoded custom normals (CD_CUSTOMLOOPNORMAL / the "custom_normal" int16 x 2 corner @@ -169821,6 +170389,19 @@ end return Read end +end + + + + + + model_bsp + --!optimize 2 +--!nocheck +-- rosetta chunk model_bsp (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/bsp"] = function() -- model/bsp: compiled game maps, read: Quake 1 (BSP 29, BSP2, 2PSB), Half-Life (BSP 30), Quake II (IBSP 38), Quake III @@ -171084,6 +171665,19 @@ end return Tree end +end + + + + + + model_buildmap + --!optimize 2 +--!nocheck +-- rosetta chunk model_buildmap (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/buildmap"] = function() -- model/buildmap: Build engine maps (.map versions 7-9: Duke Nukem 3D, Shadow Warrior, eduke32), from Ken Silverman's @@ -171759,6 +172353,19 @@ end return Geometry end +end + + + + + + model_d3map + --!optimize 2 +--!nocheck +-- rosetta chunk model_d3map (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/d3map"] = function() -- model/d3map: Doom 3 / Quake 4 / Prey editor .map ("Version 2" / "Version 3"), read only. brushDef3 sides (plane @@ -172239,6 +172846,19 @@ end return Parse end +end + + + + + + model_dae + --!optimize 2 +--!nocheck +-- rosetta chunk model_dae (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/dae"] = function() -- model/dae: COLLADA 1.4.1 / 1.5.0 (Khronos specifications; .dae XML, .zae zip with manifest.xml). Supports: geometry, @@ -174694,6 +175314,19 @@ end return Write end +end + + + + + + model_fbx + --!optimize 2 +--!nocheck +-- rosetta chunk model_fbx (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 6 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/fbx"] = function() -- model/fbx: Autodesk FBX 7.x binary and ASCII, from Blender's io_scene_fbx, assimp and the FBX SDK transform docs. @@ -175567,19 +176200,6 @@ end return Binary end -end - - - - - - model_3 - --!optimize 2 ---!nocheck --- rosetta chunk model_3 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 17 modules (1 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["model/fbx/Read"] = function() -- model/fbx/Read: an FBX 7.x node tree -> Scene. Layer elements in every mapping (ByPolygonVertex, ByVertice, @@ -177968,6 +178588,19 @@ end return Xform end +end + + + + + + model_gltf + --!optimize 2 +--!nocheck +-- rosetta chunk model_gltf (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/gltf"] = function() -- model/gltf: glTF 2.0 (Khronos specification 2.0.1), .gltf JSON and .glb. Supports: the core spec, KHR_materials_*, @@ -179701,6 +180334,19 @@ end return Write end +end + + + + + + model_godot + --!optimize 2 +--!nocheck +-- rosetta chunk model_godot (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/godot"] = function() -- model/godot: Godot text scenes (.tscn, .escn; formats 2-4) as a Scene, read + write (format 3); checked against @@ -181423,6 +182069,19 @@ end return Write end +end + + + + + + model_iqm + --!optimize 2 +--!nocheck +-- rosetta chunk model_iqm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/iqm"] = function() -- model/iqm: Inter-Quake Model (IQM version 2; iqm.txt / iqm.h of Lee Salzman's IQM SDK, public domain; checked against @@ -182541,6 +183200,19 @@ end return Write end +end + + + + + + model_ldraw + --!optimize 2 +--!nocheck +-- rosetta chunk model_ldraw (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/ldraw"] = function() -- model/ldraw: LDraw (.ldr / .dat / .mpd), read; File Format spec 1.0.2 with the MPD, BFC and !COLOUR extensions @@ -182937,19 +183609,6 @@ end return Colors end -end - - - - - - model_4 - --!optimize 2 ---!nocheck --- rosetta chunk model_4 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 24 modules (0 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["model/ldraw/Read"] = function() -- model/ldraw/Read: LDraw text -> Types.Scene. Sub-files are tried as written (backslashes as slashes), then lower @@ -183527,6 +184186,19 @@ end return Read end +end + + + + + + model_lwo + --!optimize 2 +--!nocheck +-- rosetta chunk model_lwo (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/lwo"] = function() -- model/lwo: LightWave objects LWO2 (6+), LWOB (5.x) and Modo's LXOB, read; from the LWO2 / LWOB specs, checked against @@ -184608,6 +185280,19 @@ end return Parse end +end + + + + + + model_map + --!optimize 2 +--!nocheck +-- rosetta chunk model_map (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/map"] = function() -- model/map: editor .map files of Quake, Half-Life (Valve 220), Quake II (surface / content flags) and Quake III @@ -185700,6 +186385,19 @@ end return Write end +end + + + + + + model_mca + --!optimize 2 +--!nocheck +-- rosetta chunk model_mca (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/mca"] = function() -- model/mca: Minecraft Anvil region files (wiki "Region file format", "Chunk format"), read-only. Supports: gzip, zlib, @@ -186444,6 +187142,19 @@ end return Md2 end +end + + + + + + model_md3 + --!optimize 2 +--!nocheck +-- rosetta chunk model_md3 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/md3"] = function() -- model/md3: Quake III MD3 ("IDP3" v15), from qfiles.h md3Header_t / md3Surface_t and PhaethonH's "MD3 file format"; @@ -187186,6 +187897,19 @@ end return Read end +end + + + + + + model_mdl + --!optimize 2 +--!nocheck +-- rosetta chunk model_mdl (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/mdl"] = function() -- model/mdl: Quake 1 ("IDPO" v6, model/mdl/Quake) and GoldSrc ("IDST" v10, model/mdl/HalfLife) models. Quake skins @@ -187790,6 +188514,19 @@ end return Quake end +end + + + + + + model_ms3d + --!optimize 2 +--!nocheck +-- rosetta chunk model_ms3d (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/ms3d"] = function() -- model/ms3d: MilkShape 3D 1.8 (.ms3d v3 / v4), from ms3dspec.h, tested against assimp's MS3D importer (no code @@ -188777,6 +189514,19 @@ end return Write end +end + + + + + + model_obj + --!optimize 2 +--!nocheck +-- rosetta chunk model_obj (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/obj"] = function() -- model/obj: Wavefront OBJ + MTL (Paul Bourke's specs, as Blender / Maya / assimp write them). Supports: v (with @@ -189883,6 +190633,19 @@ end return Mtl end +end + + + + + + model_off + --!optimize 2 +--!nocheck +-- rosetta chunk model_off (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/off"] = function() -- model/off: Geomview OFF text (geomview.org/docs/html/OFF.html), read + write. Supports: [ST][C][N]OFF, face colours @@ -190349,13 +191112,13 @@ end - + - model_5 + model_ply --!optimize 2 --!nocheck --- rosetta chunk model_5 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 24 modules (3 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk model_ply (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["model/ply"] = function() @@ -191664,6 +192427,19 @@ end return Binary end +end + + + + + + model_pmx + --!optimize 2 +--!nocheck +-- rosetta chunk model_pmx (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/pmx"] = function() -- model/pmx: MikuMikuDance PMX 2.0 / 2.1 (PmxEditor's specification notes) and PMD 1.0 (MMD community notes); no @@ -192768,6 +193544,19 @@ end return Read end +end + + + + + + model_proc + --!optimize 2 +--!nocheck +-- rosetta chunk model_proc (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/proc"] = function() -- model/proc: Doom 3 / Quake 4 / Prey `.proc` render geometry (dmap output: "mapProcFile003", Quake 4 "PROC" "4"; the @@ -193543,6 +194332,19 @@ end return Qb end +end + + + + + + model_rbxm + --!optimize 2 +--!nocheck +-- rosetta chunk model_rbxm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/rbxm"] = function() -- model/rbxm: Roblox binary model / place (.rbxm / .rbxl, "<roblox!") to and from a codecs/model/Rbx RbxTree, from the @@ -194136,6 +194938,19 @@ end return Rbxm end +end + + + + + + model_rbxmx + --!optimize 2 +--!nocheck +-- rosetta chunk model_rbxmx (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/rbxmx"] = function() -- model/rbxmx: Roblox XML model / place (.rbxmx / .rbxlx, `<roblox version="4">`) to and from a codecs/model/Rbx @@ -194812,6 +195627,19 @@ end return Rbxmx end +end + + + + + + model_robloxmesh + --!optimize 2 +--!nocheck +-- rosetta chunk model_robloxmesh (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (2 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/robloxmesh"] = function() -- model/robloxmesh: Roblox FileMesh (.mesh), from MaximumADHD's "Roblox Mesh Format" (devforum.roblox.com/t/326114); no @@ -196037,6 +196865,19 @@ end return Write end +end + + + + + + model_schematic + --!optimize 2 +--!nocheck +-- rosetta chunk model_schematic (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/schematic"] = function() -- model/schematic: Minecraft schematics, read + write: MCEdit / WorldEdit .schematic (pre-1.13), Sponge .schem v1-3 @@ -197062,6 +197903,19 @@ end return Sponge end +end + + + + + + model_smd + --!optimize 2 +--!nocheck +-- rosetta chunk model_smd (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/smd"] = function() -- model/smd: Valve SMD (studiomdl "version 1" text, GoldSrc and Source), from the Valve Developer Community "SMD file @@ -197641,6 +198495,19 @@ end return Write end +end + + + + + + model_sourcemdl + --!optimize 2 +--!nocheck +-- rosetta chunk model_sourcemdl (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 7 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/sourcemdl"] = function() -- model/sourcemdl: Source engine studio models ("IDST" v44-49) with .vvd / .vtx (.dx90 / .dx80 / .sw) and optional .phy / @@ -198403,19 +199270,6 @@ end return Material end -end - - - - - - model_6 - --!optimize 2 ---!nocheck --- rosetta chunk model_6 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 23 modules (2 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["model/sourcemdl/Mdl"] = function() -- model/sourcemdl/Mdl: the studiohdr_t tables of Source MDL v44-49 (Source SDK 2013 public/studio.h layouts, SourceIO @@ -199342,6 +200196,19 @@ end return Vvd end +end + + + + + + model_stl + --!optimize 2 +--!nocheck +-- rosetta chunk model_stl (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/stl"] = function() -- model/stl: STL (3D Systems; Wikipedia "STL (file format)", the SLC spec), ASCII and binary, read + write. Supports: @@ -199866,6 +200733,19 @@ end return Decode end +end + + + + + + model_t3d + --!optimize 2 +--!nocheck +-- rosetta chunk model_t3d (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/t3d"] = function() -- model/t3d: Unreal T3D text (UnrealEd map / brush export: Begin Map / Level / Actor / Brush / PolyList / Polygon, @@ -200616,6 +201496,19 @@ end return Udmf end +end + + + + + + model_usda + --!optimize 2 +--!nocheck +-- rosetta chunk model_usda (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/usda"] = function() -- model/usda: USD ASCII layers (.usda, text .usd) and USDZ packages of them, from the Sdf text format and the UsdGeom / @@ -203718,6 +204611,19 @@ end return Write end +end + + + + + + model_vbsp + --!optimize 2 +--!nocheck +-- rosetta chunk model_vbsp (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/vbsp"] = function() -- model/vbsp: compiled Source engine maps (VBSP 19 / 20 / 21: HL2, TF2, L4D2's lump header, Portal 2 / CS:GO), read, @@ -204480,6 +205386,19 @@ end return Props end +end + + + + + + model_vmf + --!optimize 2 +--!nocheck +-- rosetta chunk model_vmf (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/vmf"] = function() -- model/vmf: Valve Hammer map sources (.vmf, KeyValues text), read and written. Solids through codecs/model/Brush @@ -205229,6 +206148,19 @@ end return Build end +end + + + + + + model_vox + --!optimize 2 +--!nocheck +-- rosetta chunk model_vox (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/vox"] = function() -- model/vox: MagicaVoxel .vox (ephtracy's MagicaVoxel-file-format-vox.txt / -vox-extension.txt, versions 150 and 200). @@ -206238,6 +207170,19 @@ end return Wrl end +end + + + + + + model_x + --!optimize 2 +--!nocheck +-- rosetta chunk model_x (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/x"] = function() -- model/x: DirectX .x, read only: text ("txt "), binary ("bin "), MSZIP ("tzip" / "bzip"), 32- and 64-bit floats; from @@ -206368,19 +207313,6 @@ end return X end -end - - - - - - model_7 - --!optimize 2 ---!nocheck --- rosetta chunk model_7 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. --- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). -return function(__FILES, __include) __FILES["model/x/Build"] = function() -- model/x/Build: the .x object tree to a Scene, from the DirectX template layouts. Direct3D is left-handed (y up, row @@ -207241,6 +208173,19 @@ end return Parse end +end + + + + + + model_x3d + --!optimize 2 +--!nocheck +-- rosetta chunk model_x3d (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["model/x3d"] = function() -- model/x3d: X3D (ISO/IEC 19775-1) XML (.x3d, 19776-1) and classic VRML (.x3dv, 19776-2) encodings, plain or gzipped, @@ -207323,13 +208268,13 @@ end - + - music + music_669 --!optimize 2 --!nocheck --- rosetta chunk music (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 22 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk music_669 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["music/669"] = function() @@ -208138,6 +209083,19 @@ end return Hvl end +end + + + + + + music_it + --!optimize 2 +--!nocheck +-- rosetta chunk music_it (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["music/it"] = function() @@ -208674,6 +209632,19 @@ end return Itsex end +end + + + + + + music_med + --!optimize 2 +--!nocheck +-- rosetta chunk music_med (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["music/med"] = function() @@ -209322,6 +210293,19 @@ end return Med end +end + + + + + + music_midi + --!optimize 2 +--!nocheck +-- rosetta chunk music_midi (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["music/midi"] = function() @@ -210232,6 +211216,19 @@ end return Mod end +end + + + + + + music_mtm + --!optimize 2 +--!nocheck +-- rosetta chunk music_mtm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["music/mtm"] = function() @@ -211118,6 +212115,19 @@ end return Ptm end +end + + + + + + music_s3m + --!optimize 2 +--!nocheck +-- rosetta chunk music_s3m (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 5 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["music/s3m"] = function() @@ -212153,6 +213163,19 @@ end return Umx end +end + + + + + + music_xm + --!optimize 2 +--!nocheck +-- rosetta chunk music_xm (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["music/xm"] = function() @@ -212928,13 +213951,13 @@ end - + - ops + ops_AudioOps --!optimize 2 --!nocheck --- rosetta chunk ops (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 5 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk ops_AudioOps (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["ops/AudioOps"] = function() @@ -213416,6 +214439,1320 @@ end return AudioOps end +end + + + + + + ops_ImageOps + --!optimize 2 +--!nocheck +-- rosetta chunk ops_ImageOps (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) +__FILES["ops/ImageOps"] = function() + +-- ops/ImageOps: editing on the standard Image: conversion, crop, resize, flips, rotation, compositing, pixel access, +-- animation helpers. New code; the resampling and compositing follow Pillow's C sources. +-- Conventions: angles are degrees counter-clockwise and rotate90 turns are counter-clockwise quarter turns (as +-- Pillow). Resizing and rotating filter premultiplied alpha (as Pillow does for RGBA / LA). Grey is Pillow's +-- L = (19595 R + 38470 G + 7471 B + 32768) >> 16. 8 <-> 16 bit is * 257 and +-- (v * 255 + 32767) // 65535; float <-> integer clamps to 0..1 and rounds (no gamma). alpha8 converts to white with +-- that alpha. yuv420p is JPEG-style BT.601 full range (2x2 box chroma); geometric ops on yuv420p go through rgba8. +local Err = __include("core/Err") +local Types = __include("Types") +local K = __include("ops/ImageOps/Kernels") + +local ImageOps = {} + +local MAX_PIXELS = 2 ^ 26 + +type Image = Types.Image + +local function arg(msg: string): (nil, Err.Err) + return nil, Err.new(Err.ARG, msg) +end + +local function isInt(v: any): boolean + return type(v) == "number" and v == v and v % 1 == 0 and v > -2 ^ 31 and v < 2 ^ 31 +end + +local function bytesOf(fmt: string, w: number, h: number): number? + if fmt == "yuv420p" then + return w * h + 2 * ((w + 1) // 2) * ((h + 1) // 2) + end + local bpp = Types.BPP[fmt] + return if bpp then w * h * bpp else nil +end + +local function check(img: any): (boolean?, Err.Err?) + if type(img) ~= "table" or type(img.pixels) ~= "buffer" then + return arg("expected an Image") + end + if not isInt(img.width) or not isInt(img.height) or img.width < 1 or img.height < 1 then + return arg("bad image size") + end + local need = bytesOf(img.format, img.width, img.height) + if not need then + return arg("unknown pixel format " .. tostring(img.format)) + end + if buffer.len(img.pixels) < need then + return arg("pixel buffer too small for " .. img.width .. " x " .. img.height .. " " .. img.format) + end + return true, nil +end +ImageOps.check = check + +local function limit(w: number, h: number, opts: any): (boolean?, Err.Err?) + local max: number = (type(opts) == "table" and opts.maxPixels) or MAX_PIXELS + if w * h > max then + return nil, Err.new(Err.LIMIT, string.format("%d x %d is over the %d pixel limit", w, h, max)) + end + return true, nil +end + +local function like(img: Image, w: number, h: number, fmt: string?): Image + local out = Types.Image.new(w, h, (fmt or img.format) :: any) + for k, v in img.meta do + out.meta[k] = v + end + out.loops = img.loops + return out +end + +function ImageOps.new(w: number, h: number, format: string?): (Image?, Err.Err?) + local fmt = format or "rgba8" + if not isInt(w) or not isInt(h) or w < 1 or h < 1 then + return arg("bad image size") + end + if not bytesOf(fmt, 1, 1) then + return arg("unknown pixel format " .. tostring(fmt)) + end + local ok, e = limit(w, h, nil) + if not ok then + return nil, e + end + return Types.Image.new(w, h, fmt :: any), nil +end + +function ImageOps.copy(img: Image): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + local out = like(img, img.width, img.height) + buffer.copy(out.pixels, 0, img.pixels, 0, buffer.len(out.pixels)) + out.frames = img.frames + return out, nil +end + +function ImageOps.convert(img: Image, format: string): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if not bytesOf(format, 1, 1) then + return arg("unknown pixel format " .. tostring(format)) + end + local w, h = img.width, img.height + if img.format == format then + return ImageOps.copy(img) + end + local src = img + if img.format == "yuv420p" then + local rgba = like(img, w, h, "rgba8") + K.yuvToRgba(img.pixels, w, h, rgba.pixels) + if format == "rgba8" then + return rgba, nil + end + src = rgba + end + local out = like(img, w, h, format) + if format == "yuv420p" then + local rgba = src + if src.format ~= "rgba8" then + rgba = like(img, w, h, "rgba8") + K.convert(src.pixels, K.ID[src.format], rgba.pixels, K.ID.rgba8, w * h) + end + K.rgbaToYuv(rgba.pixels, w, h, out.pixels) + return out, nil + end + K.convert(src.pixels, K.ID[src.format], out.pixels, K.ID[format], w * h) + return out, nil +end + +-- ops on yuv420p run on rgba8 and convert back +local function viaRgba(img: Image, f: (Image) -> (Image?, Err.Err?)): (Image?, Err.Err?) + if img.format ~= "yuv420p" then + return f(img) + end + local rgba = ImageOps.convert(img, "rgba8") :: Image + local res, e = f(rgba) + if not res then + return nil, e + end + return ImageOps.convert(res, "yuv420p") +end + +local ALPHA_CH: { [string]: number } = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, graya8 = 2 } + +function ImageOps.crop(img: Image, x: number, y: number, w: number, h: number): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if not (isInt(x) and isInt(y) and isInt(w) and isInt(h)) then + return arg("crop: integer x, y, w, h") + end + local x0, y0 = math.max(0, x), math.max(0, y) + local x1, y1 = math.min(img.width, x + w), math.min(img.height, y + h) + if x1 <= x0 or y1 <= y0 then + return arg("crop: the rectangle is outside the image or empty") + end + return viaRgba(img, function(im: Image): (Image?, Err.Err?) + local bpp = Types.BPP[im.format] :: number + local out = like(im, x1 - x0, y1 - y0) + K.copyRect(out.pixels, out.width, im.pixels, im.width, x0, y0, 0, 0, out.width, out.height, bpp) + return out, nil + end) +end + +function ImageOps.flip(img: Image, axis: string): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if axis ~= "h" and axis ~= "v" then + return arg("flip: axis must be \"h\" or \"v\"") + end + return viaRgba(img, function(im: Image): (Image?, Err.Err?) + local out = like(im, im.width, im.height) + K.flip(im.pixels, out.pixels, im.width, im.height, Types.BPP[im.format] :: number, axis == "h") + return out, nil + end) +end + +function ImageOps.rotate90(img: Image, turns: number): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if not isInt(turns) then + return arg("rotate90: integer turns") + end + local t = turns % 4 + if t == 0 then + return ImageOps.copy(img) + end + return viaRgba(img, function(im: Image): (Image?, Err.Err?) + local swap = t ~= 2 + local out = like(im, if swap then im.height else im.width, if swap then im.width else im.height) + K.rotate90(im.pixels, out.pixels, im.width, im.height, Types.BPP[im.format] :: number, t) + return out, nil + end) +end + +type ResizeFilter = "nearest" | "bilinear" | "lanczos" + +function ImageOps.resize(img: Image, w: number, h: number, filter: string?, opts: any?): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if not isInt(w) or not isInt(h) or w < 1 or h < 1 then + return arg("resize: bad target size") + end + local f = filter or "bilinear" + if f ~= "nearest" and f ~= "bilinear" and f ~= "lanczos" then + return arg("resize: filter must be nearest, bilinear or lanczos") + end + local lok, le = limit(w, h, opts) + if not lok then + return nil, le + end + return viaRgba(img, function(im: Image): (Image?, Err.Err?) + local fmt = im.format + local bpp = Types.BPP[fmt] :: number + local out = like(im, w, h) + if f == "nearest" then + K.nearest(im.pixels, im.width, im.height, bpp, out.pixels, w, h) + return out, nil + end + local kind, ch = K.KIND[fmt], K.CHANNELS[fmt] + local src, sw, sh = im.pixels, im.width, im.height + local alpha = ALPHA_CH[fmt] + local unAlpha = alpha + if alpha == 4 and kind == 1 and K.opaque(src, sw * sh) then + alpha = nil -- premultiplying is the identity; the resampled alpha can still round to 254: unpremultiplied below + end + if alpha then + src = buffer.create(buffer.len(im.pixels)) + buffer.copy(src, 0, im.pixels) + K.premultiply(src, sw * sh, alpha, kind, false) + end + if w ~= sw then + local tmp = buffer.create(w * sh * bpp) + K.resamplePass(src, sw, sh, ch, kind, tmp, w, K.coeffs(sw, w, f), true) + src, sw = tmp, w + end + if h ~= sh then + K.resamplePass(src, sw, sh, ch, kind, out.pixels, h, K.coeffs(sh, h, f), false) + elseif src == im.pixels or (w == im.width and alpha) then + buffer.copy(out.pixels, 0, im.pixels, 0, w * h * bpp) + return out, nil + else + out.pixels = src + end + if unAlpha then + K.premultiply(out.pixels, w * h, unAlpha, kind, true) + end + return out, nil + end) +end + +function ImageOps.rotate(img: Image, degrees: number, opts: { expand: boolean?, maxPixels: number? }?): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if type(degrees) ~= "number" or degrees ~= degrees or degrees == math.huge or degrees == -math.huge then + return arg("rotate: degrees must be a finite number") + end + local expand = not (opts and opts.expand == false) + if degrees % 90 == 0 and (expand or degrees % 180 == 0 or img.width == img.height) then + return ImageOps.rotate90(img, (degrees // 90) % 4) + end + local w, h = img.width, img.height + local ang = -math.rad(degrees) + local function r15(v: number): number + return math.floor(v * 1e15 + 0.5) / 1e15 + end + local m = { r15(math.cos(ang)), r15(math.sin(ang)), 0, r15(-math.sin(ang)), r15(math.cos(ang)), 0 } + local function tr(x: number, y: number): (number, number) + return m[1] * x + m[2] * y + m[3], m[4] * x + m[5] * y + m[6] + end + local cx, cy = w / 2, h / 2 + m[3], m[6] = tr(-cx, -cy) + m[3] += cx + m[6] += cy + local nw, nh = w, h + if expand then + local xs, ys = {}, {} + for _, p in { { 0, 0 }, { w, 0 }, { w, h }, { 0, h } } do + local x, y = tr(p[1], p[2]) + table.insert(xs, x) + table.insert(ys, y) + end + nw = math.ceil(math.max(xs[1], xs[2], xs[3], xs[4])) - math.floor(math.min(xs[1], xs[2], xs[3], xs[4])) + nh = math.ceil(math.max(ys[1], ys[2], ys[3], ys[4])) - math.floor(math.min(ys[1], ys[2], ys[3], ys[4])) + m[3], m[6] = tr(-(nw - w) / 2, -(nh - h) / 2) + end + local lok, le = limit(nw, nh, opts) + if not lok then + return nil, le + end + return viaRgba(img, function(im: Image): (Image?, Err.Err?) + local out = like(im, nw, nh) + local kind = K.KIND[im.format] + local alpha = ALPHA_CH[im.format] + local src = im.pixels + if alpha then + src = buffer.create(buffer.len(im.pixels)) + buffer.copy(src, 0, im.pixels) + K.premultiply(src, w * h, alpha, kind, false) + end + K.affine(src, w, h, K.CHANNELS[im.format], kind, out.pixels, nw, nh, m) + if alpha then + K.premultiply(out.pixels, nw * nh, alpha, kind, true) + end + return out, nil + end) +end + +local RGBA: { [string]: boolean } = { rgba8 = true, rgba16 = true, rgbaf32 = true } + +type BlitOptions = { blend: ("over" | "source")?, opacity: number? } + +function ImageOps.blit(dst: Image, src: Image, x: number, y: number, opts: BlitOptions?): (Image?, Err.Err?) + local ok, e = check(dst) + if not ok then + return nil, e + end + local ok2, e2 = check(src) + if not ok2 then + return nil, e2 + end + if not isInt(x) or not isInt(y) then + return arg("blit: integer x, y") + end + local blend = (opts and opts.blend) or "over" + if blend ~= "over" and blend ~= "source" then + return arg("blit: blend must be \"over\" or \"source\"") + end + local opacity = (opts and opts.opacity) or 1 + if type(opacity) ~= "number" or not (opacity >= 0 and opacity <= 1) then + return arg("blit: opacity must be 0..1") + end + local sx, sy = math.max(0, -x), math.max(0, -y) + local dx, dy = math.max(0, x), math.max(0, y) + local w = math.min(src.width - sx, dst.width - dx) + local h = math.min(src.height - sy, dst.height - dy) + if w <= 0 or h <= 0 then + return dst, nil + end + if dst.format == "yuv420p" or (blend == "over" and not RGBA[dst.format]) then + -- work on an rgba copy of the region, then write it back in dst's format + local region = ImageOps.crop(dst, dx, dy, w, h) :: Image + local work = if region.format == "rgba8" then region else ImageOps.convert(region, "rgba8") :: Image + ImageOps.blit(work, src, x - dx, y - dy, opts) + if dst.format == "yuv420p" then + local full = ImageOps.convert(dst, "rgba8") :: Image + ImageOps.blit(full, work, dx, dy, { blend = "source" }) + local back = ImageOps.convert(full, "yuv420p") :: Image + buffer.copy(dst.pixels, 0, back.pixels, 0, buffer.len(back.pixels)) + else + local back = ImageOps.convert(work, dst.format) :: Image + K.copyRect(dst.pixels, dst.width, back.pixels, back.width, 0, 0, dx, dy, w, h, Types.BPP[dst.format] :: number) + end + return dst, nil + end + local s = src + if src.format ~= dst.format then + s = ImageOps.convert(src, dst.format) :: Image + end + if blend == "source" then + K.copyRect(dst.pixels, dst.width, s.pixels, s.width, sx, sy, dx, dy, w, h, Types.BPP[dst.format] :: number) + elseif dst.format == "rgba8" then + K.overRgba8(dst.pixels, dst.width, s.pixels, s.width, sx, sy, dx, dy, w, h, math.floor(opacity * 255 + 0.5)) + else + K.overFloat(dst.pixels, dst.width, s.pixels, s.width, sx, sy, dx, dy, w, h, opacity, K.KIND[dst.format]) + end + return dst, nil +end + +function ImageOps.composite(dst: Image, src: Image, x: number?, y: number?, opts: BlitOptions?): (Image?, Err.Err?) + local out, e = ImageOps.copy(dst) + if not out then + return nil, e + end + out.frames = nil + return ImageOps.blit(out, src, x or 0, y or 0, opts) +end + +local function premul(img: Image, un: boolean): (Image?, Err.Err?) + local out, e = ImageOps.copy(img) + if not out then + return nil, e + end + out.frames = nil + local ch = ALPHA_CH[img.format] + if ch then + K.premultiply(out.pixels, img.width * img.height, ch, K.KIND[img.format], un) + end + return out, nil +end + +function ImageOps.premultiply(img: Image): (Image?, Err.Err?) + return premul(img, false) +end +function ImageOps.unpremultiply(img: Image): (Image?, Err.Err?) + return premul(img, true) +end + +local MAXV: { [string]: number } = { rgba8 = 255, rgba16 = 65535, rgbaf32 = 1, rgb8 = 255, gray8 = 255, gray16 = 65535, graya8 = 255, alpha8 = 255, yuv420p = 255 } + +function ImageOps.getPixel(img: Image, x: number, y: number): (any, any, number?, number?) + local ok, e = check(img) + if not ok then + return nil, e + end + if not isInt(x) or not isInt(y) or x < 0 or y < 0 or x >= img.width or y >= img.height then + return arg("getPixel: coordinates out of range") + end + local b, f, i = img.pixels, img.format, y * img.width + x + local ru8, ru16, rf = buffer.readu8, buffer.readu16, buffer.readf32 + if f == "rgba8" then + return ru8(b, i * 4), ru8(b, i * 4 + 1), ru8(b, i * 4 + 2), ru8(b, i * 4 + 3) + elseif f == "rgba16" then + return ru16(b, i * 8), ru16(b, i * 8 + 2), ru16(b, i * 8 + 4), ru16(b, i * 8 + 6) + elseif f == "rgbaf32" then + return rf(b, i * 16), rf(b, i * 16 + 4), rf(b, i * 16 + 8), rf(b, i * 16 + 12) + elseif f == "rgb8" then + return ru8(b, i * 3), ru8(b, i * 3 + 1), ru8(b, i * 3 + 2), 255 + elseif f == "gray8" then + local v = ru8(b, i) + return v, v, v, 255 + elseif f == "gray16" then + local v = ru16(b, i * 2) + return v, v, v, 65535 + elseif f == "graya8" then + local v = ru8(b, i * 2) + return v, v, v, ru8(b, i * 2 + 1) + elseif f == "alpha8" then + return 255, 255, 255, ru8(b, i) + end + local one = ImageOps.crop(img, x - x % 2, y - y % 2, 2, 2) :: Image + local rgba = ImageOps.convert(one, "rgba8") :: Image + local j = ((y % 2) * rgba.width + (x % 2)) * 4 + if j + 4 > buffer.len(rgba.pixels) then + j = 0 + end + return ru8(rgba.pixels, j), ru8(rgba.pixels, j + 1), ru8(rgba.pixels, j + 2), 255 +end + +function ImageOps.setPixel(img: Image, x: number, y: number, r: number, g: number, b: number, a: number?): (boolean?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if not isInt(x) or not isInt(y) or x < 0 or y < 0 or x >= img.width or y >= img.height then + return arg("setPixel: coordinates out of range") + end + if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" or (a ~= nil and type(a) ~= "number") then + return arg("setPixel: numeric channels") + end + local f = img.format + if f == "yuv420p" then + return arg("setPixel: not supported on yuv420p (convert to rgba8 first)") + end + local max = MAXV[f] + local al = if a == nil then max else a + local function q(v: number): number + if max == 1 then + return v + end + if v ~= v then + return 0 + end + return math.clamp(math.floor(v + 0.5), 0, max) + end + local px, i = img.pixels, y * img.width + x + local wu8, wu16, wf = buffer.writeu8, buffer.writeu16, buffer.writef32 + local function grey(): number + if max == 1 then + return (r * 19595 + g * 38470 + b * 7471) / 65536 + end + return (q(r) * 19595 + q(g) * 38470 + q(b) * 7471 + 32768) // 65536 + end + if f == "rgba8" then + wu8(px, i * 4, q(r)) + wu8(px, i * 4 + 1, q(g)) + wu8(px, i * 4 + 2, q(b)) + wu8(px, i * 4 + 3, q(al)) + elseif f == "rgba16" then + wu16(px, i * 8, q(r)) + wu16(px, i * 8 + 2, q(g)) + wu16(px, i * 8 + 4, q(b)) + wu16(px, i * 8 + 6, q(al)) + elseif f == "rgbaf32" then + wf(px, i * 16, r) + wf(px, i * 16 + 4, g) + wf(px, i * 16 + 8, b) + wf(px, i * 16 + 12, al) + elseif f == "rgb8" then + wu8(px, i * 3, q(r)) + wu8(px, i * 3 + 1, q(g)) + wu8(px, i * 3 + 2, q(b)) + elseif f == "gray8" then + wu8(px, i, grey()) + elseif f == "gray16" then + wu16(px, i * 2, grey()) + elseif f == "graya8" then + wu8(px, i * 2, grey()) + wu8(px, i * 2 + 1, q(al)) + else + wu8(px, i, q(al)) + end + return true, nil +end + +function ImageOps.fill(img: Image, r: number, g: number, b: number, a: number?): (Image?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + if img.format == "yuv420p" then + return arg("fill: not supported on yuv420p") + end + local sok, se = ImageOps.setPixel(img, 0, 0, r, g, b, a) + if not sok then + return nil, se + end + local bpp = Types.BPP[img.format] :: number + local n = img.width * img.height * bpp + local filled = bpp + while filled < n do + local c = math.min(filled, n - filled) + buffer.copy(img.pixels, filled, img.pixels, 0, c) + filled += c + end + return img, nil +end + +function ImageOps.frameCount(img: Image): number + if type(img) == "table" and type(img.frames) == "table" and #img.frames > 0 then + return #img.frames + end + return 1 +end + +function ImageOps.durations(img: Image): { number } + local out = {} + if type(img) == "table" and type(img.frames) == "table" and #img.frames > 0 then + for i, f in img.frames do + out[i] = if type(f.delay) == "number" then f.delay else 0 + end + return out + end + return { 0 } +end + +-- coalesce: dispose "none" keeps the canvas, "background" clears the frame's rectangle, "previous" restores it +function ImageOps.coalesce(img: Image): ({ Image }?, Err.Err?) + local ok, e = check(img) + if not ok then + return nil, e + end + local frames = img.frames + if type(frames) ~= "table" or #frames == 0 then + return { img }, nil + end + local fmt = if RGBA[img.format] then img.format else "rgba8" + local canvas = Types.Image.new(img.width, img.height, fmt :: any) + local bpp = Types.BPP[fmt] :: number + local out = {} + for i, f in frames do + if type(f) ~= "table" then + return arg("coalesce: frame " .. i .. " is not a Frame") + end + local fi = f.image + local fok, fe = check(fi) + if not fok then + return nil, Err.new(Err.ARG, "coalesce: frame " .. i .. ": " .. (fe :: Err.Err).message) + end + local fx, fy = if isInt(f.x) then f.x else 0, if isInt(f.y) then f.y else 0 + local saved: buffer? = nil + if f.dispose == "previous" then + local sb = buffer.create(buffer.len(canvas.pixels)) + buffer.copy(sb, 0, canvas.pixels) + saved = sb + end + local bok, be = ImageOps.blit(canvas, fi, fx, fy, { blend = if f.blend == "source" then "source" else "over" }) + if not bok then + return nil, be + end + local snap = Types.Image.new(img.width, img.height, fmt :: any) + buffer.copy(snap.pixels, 0, canvas.pixels) + for k, v in img.meta do + snap.meta[k] = v + end + snap.meta.delay = f.delay + out[i] = snap + if f.dispose == "background" then + local x0, y0 = math.max(0, fx), math.max(0, fy) + local x1, y1 = math.min(img.width, fx + fi.width), math.min(img.height, fy + fi.height) + for y = y0, y1 - 1 do + if x1 > x0 then + buffer.fill(canvas.pixels, (y * img.width + x0) * bpp, 0, (x1 - x0) * bpp) + end + end + elseif saved then + canvas.pixels = saved + end + end + return out, nil +end + +function ImageOps.fromFrames(images: { Image }, delays: (number | { number })?): (Image?, Err.Err?) + if type(images) ~= "table" or #images == 0 then + return arg("fromFrames: a non-empty list of Images") + end + local first = images[1] + local ok, e = check(first) + if not ok then + return nil, e + end + local frames = {} + for i, im in images do + local iok, ie = check(im) + if not iok then + return nil, ie + end + if im.width ~= first.width or im.height ~= first.height or im.format ~= first.format then + return arg("fromFrames: frame " .. i .. " differs in size or format from frame 1") + end + local d = 0.1 + if type(delays) == "number" then + d = delays + elseif type(delays) == "table" and type(delays[i]) == "number" then + d = delays[i] + end + frames[i] = { image = im, delay = d, x = 0, y = 0, dispose = "none", blend = "source" } + end + local out = like(first, first.width, first.height) + buffer.copy(out.pixels, 0, first.pixels, 0, buffer.len(out.pixels)) + out.frames = frames :: any + out.loops = 0 + return out, nil +end + +return ImageOps +end +__FILES["ops/ImageOps/Kernels"] = @native function() + + + +-- ops/ImageOps/Kernels: the hot loops behind ops/ImageOps; callers validate, so indexes are in range by construction. +-- Sample kinds: 1 = u8, 2 = u16, 4 = f32 (little endian). Resampling follows Pillow's Resample.c (separable, 22-bit +-- fixed point for 8-bit) and Geometry.c (affine through pixel centres); compositing is Pillow's AlphaComposite.c. +local readu8, writeu8, readu16, writeu16, readf32, writef32 = buffer.readu8, buffer.writeu8, buffer.readu16, buffer.writeu16, buffer.readf32, buffer.writef32 +local readu32, writeu32 = buffer.readu32, buffer.writeu32 +local floor, clamp = math.floor, math.clamp + +local K = {} + +-- format ids: rgba8 1, rgba16 2, rgbaf32 3, rgb8 4, gray8 5, gray16 6, graya8 7, alpha8 8 +K.ID = { rgba8 = 1, rgba16 = 2, rgbaf32 = 3, rgb8 = 4, gray8 = 5, gray16 = 6, graya8 = 7, alpha8 = 8 } :: { [string]: number } +K.KIND = { rgba8 = 1, rgba16 = 2, rgbaf32 = 4, rgb8 = 1, gray8 = 1, gray16 = 2, graya8 = 1, alpha8 = 1 } :: { [string]: number } +K.CHANNELS = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, rgb8 = 3, gray8 = 1, gray16 = 1, graya8 = 2, alpha8 = 1 } :: { [string]: number } + +@native local function rd(b: buffer, o: number, kind: number): number + if kind == 1 then + return readu8(b, o) + elseif kind == 2 then + return readu16(b, o) + end + return readf32(b, o) +end + +@native local function wr(b: buffer, o: number, kind: number, v: number) + if kind == 1 then + writeu8(b, o, clamp(floor(v + 0.5), 0, 255)) + elseif kind == 2 then + writeu16(b, o, clamp(floor(v + 0.5), 0, 65535)) + else + writef32(b, o, v) + end +end + +-- depth: 8 -> 0..255, 16 -> 0..65535, 0 -> float 0..1 +local DEPTH = { 8, 16, 0, 8, 8, 16, 8, 8 } + +@native local function depthConv(v: number, from: number, to: number): number + if from == to then + return v + end + if from == 8 then + if to == 16 then + return v * 257 + end + return v / 255 + elseif from == 16 then + if to == 8 then + return (v * 255 + 32767) // 65535 + end + return v / 65535 + end + if v ~= v then + v = 0 + end + if to == 8 then + return clamp(floor(v * 255 + 0.5), 0, 255) + end + return clamp(floor(v * 65535 + 0.5), 0, 65535) +end + +-- Pillow's L24 luma (19595 R + 38470 G + 7471 B + 0x8000) >> 16, in the source depth +@native local function luma(r: number, g: number, b: number, depth: number): number + if depth == 0 then + return (r * 19595 + g * 38470 + b * 7471) / 65536 + end + return (r * 19595 + g * 38470 + b * 7471 + 32768) // 65536 +end + +@native function K.convert(src: buffer, sf: number, dst: buffer, df: number, n: number) + if sf == 1 and df == 5 then + for i = 0, n - 1 do + local o = i * 4 + writeu8(dst, i, (readu8(src, o) * 19595 + readu8(src, o + 1) * 38470 + readu8(src, o + 2) * 7471 + 32768) // 65536) + end + return + elseif sf == 1 and df == 4 and n > 0 then + -- a u32 per pixel; its fourth byte is overwritten by the next pixel (the last one is written as 2 + 1 bytes) + for i = 0, n - 2 do + writeu32(dst, i * 3, readu32(src, i * 4)) + end + local o, d = (n - 1) * 4, (n - 1) * 3 + writeu16(dst, d, readu16(src, o)) + writeu8(dst, d + 2, readu8(src, o + 2)) + return + elseif df == 1 and (sf == 4 or sf == 5) then + for i = 0, n - 1 do + if sf == 4 then + local o = i * 3 + writeu32(dst, i * 4, readu8(src, o) + readu8(src, o + 1) * 256 + readu8(src, o + 2) * 65536 + 0xFF000000) + else + writeu32(dst, i * 4, readu8(src, i) * 0x10101 + 0xFF000000) + end + end + return + end + local sd, dd = DEPTH[sf] :: number, DEPTH[df] :: number + local smax = if sd == 8 then 255 elseif sd == 16 then 65535 else 1 + local toGray = df == 5 or df == 6 or df == 7 + for i = 0, n - 1 do + local r: number, g: number, b: number, a: number + if sf == 1 then + local o = i * 4 + r, g, b, a = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2), readu8(src, o + 3) :: number + elseif sf == 2 then + local o = i * 8 + r, g, b, a = readu16(src, o), readu16(src, o + 2), readu16(src, o + 4), readu16(src, o + 6) :: number + elseif sf == 3 then + local o = i * 16 + r, g, b, a = readf32(src, o), readf32(src, o + 4), readf32(src, o + 8), readf32(src, o + 12) :: number + elseif sf == 4 then + local o = i * 3 + r, g, b, a = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2), 255 + elseif sf == 5 then + local v = readu8(src, i) + r, g, b, a = v, v, v, 255 + elseif sf == 6 then + local v = readu16(src, i * 2) + r, g, b, a = v, v, v, 65535 + elseif sf == 7 then + local v = readu8(src, i * 2) + r, g, b, a = v, v, v, readu8(src, i * 2 + 1) :: number + else + r, g, b, a = 255, 255, 255, readu8(src, i) + end + if toGray then + local isGray = sf == 5 or sf == 6 or sf == 7 + local l = if isGray then r else luma(r, g, b, sd) + l = depthConv(l, sd, dd) + if df == 5 then + writeu8(dst, i, l) + elseif df == 6 then + writeu16(dst, i * 2, l) + else + writeu8(dst, i * 2, l) + writeu8(dst, i * 2 + 1, depthConv(a, sd, dd)) + end + elseif df == 8 then + writeu8(dst, i, depthConv(a, sd, 8)) + else + r, g, b = depthConv(r, sd, dd), depthConv(g, sd, dd), depthConv(b, sd, dd) :: number + if df == 1 then + local o = i * 4 + writeu8(dst, o, r) + writeu8(dst, o + 1, g) + writeu8(dst, o + 2, b) + writeu8(dst, o + 3, depthConv(a, sd, dd)) + elseif df == 2 then + local o = i * 8 + writeu16(dst, o, r) + writeu16(dst, o + 2, g) + writeu16(dst, o + 4, b) + writeu16(dst, o + 6, depthConv(a, sd, dd)) + elseif df == 3 then + local o = i * 16 + writef32(dst, o, r) + writef32(dst, o + 4, g) + writef32(dst, o + 8, b) + writef32(dst, o + 12, if a == smax and sd ~= 0 then 1 else depthConv(a, sd, dd)) + else -- rgb8 + local o = i * 3 + writeu8(dst, o, r) + writeu8(dst, o + 1, g) + writeu8(dst, o + 2, b) + end + end + end +end + +-- JPEG-style BT.601 full range +@native function K.rgbaToYuv(src: buffer, w: number, h: number, dst: buffer) + local cw, ch = (w + 1) // 2, (h + 1) // 2 + local uo, vo = w * h, w * h + cw * ch + for i = 0, w * h - 1 do + local o = i * 4 + local r, g, b = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2) + writeu8(dst, i, clamp(floor(0.299 * r + 0.587 * g + 0.114 * b + 0.5), 0, 255)) + end + for cy = 0, ch - 1 do + for cx = 0, cw - 1 do + local sr, sg, sb, n = 0, 0, 0, 0 + for dy = 0, 1 do + local y = cy * 2 + dy + if y < h then + for dx = 0, 1 do + local x = cx * 2 + dx + if x < w then + local o = (y * w + x) * 4 + sr += readu8(src, o) + sg += readu8(src, o + 1) + sb += readu8(src, o + 2) + n += 1 + end + end + end + end + sr, sg, sb = sr / n, sg / n, sb / n + local i = cy * cw + cx + writeu8(dst, uo + i, clamp(floor(128 - 0.168736 * sr - 0.331264 * sg + 0.5 * sb + 0.5), 0, 255)) + writeu8(dst, vo + i, clamp(floor(128 + 0.5 * sr - 0.418688 * sg - 0.081312 * sb + 0.5), 0, 255)) + end + end +end + +@native function K.yuvToRgba(src: buffer, w: number, h: number, dst: buffer) + local cw, ch = (w + 1) // 2, (h + 1) // 2 + local uo, vo = w * h, w * h + cw * ch + for y = 0, h - 1 do + local crow = (y // 2) * cw + for x = 0, w - 1 do + local yy = readu8(src, y * w + x) + local ci = crow + x // 2 + local u, v = readu8(src, uo + ci) - 128, readu8(src, vo + ci) - 128 + local o = (y * w + x) * 4 + writeu8(dst, o, clamp(floor(yy + 1.402 * v + 0.5), 0, 255)) + writeu8(dst, o + 1, clamp(floor(yy - 0.344136 * u - 0.714136 * v + 0.5), 0, 255)) + writeu8(dst, o + 2, clamp(floor(yy + 1.772 * u + 0.5), 0, 255)) + writeu8(dst, o + 3, 255) + end + end + local _ = ch +end + +@native function K.flip(src: buffer, dst: buffer, w: number, h: number, bpp: number, horizontal: boolean) + local stride = w * bpp + if not horizontal then + for y = 0, h - 1 do + buffer.copy(dst, (h - 1 - y) * stride, src, y * stride, stride) + end + return + end + for y = 0, h - 1 do + local row = y * stride + for x = 0, w - 1 do + buffer.copy(dst, row + (w - 1 - x) * bpp, src, row + x * bpp, bpp) + end + end +end + +-- counter-clockwise quarter turns 1..3 +@native function K.rotate90(src: buffer, dst: buffer, w: number, h: number, bpp: number, turns: number) + for y = 0, h - 1 do + for x = 0, w - 1 do + local ox, oy, ow + if turns == 1 then + ox, oy, ow = y, w - 1 - x, h + elseif turns == 2 then + ox, oy, ow = w - 1 - x, h - 1 - y, w + else + ox, oy, ow = h - 1 - y, x, h + end + local so, d = (y * w + x) * bpp, (oy * ow + ox) * bpp + if bpp == 4 then + buffer.writeu32(dst, d, buffer.readu32(src, so)) + else + buffer.copy(dst, d, src, so, bpp) + end + end + end +end + +@native local function bilinearF(x: number): number + if x < 0 then + x = -x + end + if x < 1 then + return 1 - x + end + return 0 +end + +@native local function sinc(x: number): number + if x == 0 then + return 1 + end + x *= math.pi + return math.sin(x) / x +end + +@native local function lanczosF(x: number): number + if x > -3 and x < 3 then + return sinc(x) * sinc(x / 3) + end + return 0 +end + +@native local function trunc(x: number): number + return if x < 0 then math.ceil(x) else floor(x) +end + +-- Pillow precompute_coeffs: per output index its first input index, tap count and weights (normalised) +type Coeffs = { start: { number }, count: { number }, weights: { { number } } } + +@native function K.coeffs(inSize: number, outSize: number, filter: string): Coeffs + local support0 = if filter == "lanczos" then 3 else 1 + local f = if filter == "lanczos" then lanczosF else bilinearF + local scale = inSize / outSize + local filterscale = math.max(scale, 1) + local support = support0 * filterscale + local ss = 1 / filterscale + local start, count, weights = table.create(outSize, 0), table.create(outSize, 0), table.create(outSize) :: { { number } } + for xx = 0, outSize - 1 do + local center = (xx + 0.5) * scale + local xmin = math.max(0, trunc(center - support + 0.5)) + local xmax = math.min(inSize, trunc(center + support + 0.5)) - xmin + local w = table.create(math.max(xmax, 0), 0) + local ww = 0 + for x = 0, xmax - 1 do + local v = f((x + xmin - center + 0.5) * ss) + w[x + 1] = v + ww += v + end + if ww ~= 0 then + for x = 1, xmax do + w[x] /= ww + end + end + start[xx + 1], count[xx + 1], weights[xx + 1] = xmin, math.max(xmax, 0), w + end + return { start = start, count = count, weights = weights } +end + +-- 8-bit RGBA: the four channels of a tap together, the pixel written as one u32 +@native local function resample4(src: buffer, w: number, h: number, dst: buffer, outN: number, start: { number }, count: { number }, iw: { { number } }, horizontal: boolean) + local o = 0 + if horizontal then + for y = 0, h - 1 do + local row = y * w * 4 + for xx = 1, outN do + local wt = iw[xx] + local p = row + start[xx] * 4 + local a0, a1, a2, a3 = 2097152, 2097152, 2097152, 2097152 + for k = 1, count[xx] do + local wk = wt[k] + a0 += readu8(src, p) * wk + a1 += readu8(src, p + 1) * wk + a2 += readu8(src, p + 2) * wk + a3 += readu8(src, p + 3) * wk + p += 4 + end + writeu32(dst, o, clamp(a0 // 4194304, 0, 255) + clamp(a1 // 4194304, 0, 255) * 256 + clamp(a2 // 4194304, 0, 255) * 65536 + clamp(a3 // 4194304, 0, 255) * 16777216) + o += 4 + end + end + else + local rs = w * 4 + for yy = 1, outN do + local wt, n = iw[yy], count[yy] + local base = start[yy] * rs + for x = 0, rs - 4, 4 do + local p = base + x + local a0, a1, a2, a3 = 2097152, 2097152, 2097152, 2097152 + for k = 1, n do + local wk = wt[k] + a0 += readu8(src, p) * wk + a1 += readu8(src, p + 1) * wk + a2 += readu8(src, p + 2) * wk + a3 += readu8(src, p + 3) * wk + p += rs + end + writeu32(dst, o, clamp(a0 // 4194304, 0, 255) + clamp(a1 // 4194304, 0, 255) * 256 + clamp(a2 // 4194304, 0, 255) * 65536 + clamp(a3 // 4194304, 0, 255) * 16777216) + o += 4 + end + end + end + local _ = h +end + +@native function K.resamplePass(src: buffer, w: number, h: number, ch: number, kind: number, dst: buffer, outN: number, c: Coeffs, horizontal: boolean) + local start, count, weights = c.start, c.count, c.weights + local size = kind + local fixed = kind == 1 + -- 8-bit: Pillow's 22-bit fixed-point coefficients + local iw: { { number } } = weights + if fixed then + iw = table.create(outN) :: { { number } } + for i = 1, outN do + local src0 = weights[i] + local t = table.create(#src0, 0) + for k = 1, #src0 do + local v = src0[k] * 4194304 + t[k] = if v < 0 then math.ceil(v - 0.5) else floor(v + 0.5) + end + iw[i] = t + end + end + if fixed and ch == 4 then + resample4(src, w, h, dst, outN, start, count, iw, horizontal) + return + end + if horizontal then + for y = 0, h - 1 do + local row = y * w + for xx = 0, outN - 1 do + local s0, n, wt = start[xx + 1], count[xx + 1], iw[xx + 1] + local o = ((y * outN) + xx) * ch * size + for cc = 0, ch - 1 do + if fixed then + local acc = 2097152 + for k = 0, n - 1 do + acc += readu8(src, (row + s0 + k) * ch + cc) * wt[k + 1] + end + writeu8(dst, o + cc, clamp(acc // 4194304, 0, 255)) + else + local acc = 0 + for k = 0, n - 1 do + acc += rd(src, ((row + s0 + k) * ch + cc) * size, kind) * wt[k + 1] + end + wr(dst, o + cc * size, kind, acc) + end + end + end + end + else + for yy = 0, outN - 1 do + local s0, n, wt = start[yy + 1], count[yy + 1], iw[yy + 1] + for x = 0, w - 1 do + local o = (yy * w + x) * ch * size + for cc = 0, ch - 1 do + if fixed then + local acc = 2097152 + for k = 0, n - 1 do + acc += readu8(src, ((s0 + k) * w + x) * ch + cc) * wt[k + 1] + end + writeu8(dst, o + cc, clamp(acc // 4194304, 0, 255)) + else + local acc = 0 + for k = 0, n - 1 do + acc += rd(src, (((s0 + k) * w + x) * ch + cc) * size, kind) * wt[k + 1] + end + wr(dst, o + cc * size, kind, acc) + end + end + end + end + end + local _ = h +end + +-- nearest: dst pixel (x, y) = src pixel (floor((x + 0.5) * w / ow), ...) +@native function K.nearest(src: buffer, w: number, h: number, bpp: number, dst: buffer, ow: number, oh: number) + local sx, sy = w / ow, h / oh + local xs = table.create(ow, 0) + for x = 0, ow - 1 do + xs[x + 1] = math.min(floor((x + 0.5) * sx), w - 1) * bpp + end + local o = 0 + for y = 0, oh - 1 do + local row = math.min(floor((y + 0.5) * sy), h - 1) * w * bpp + if bpp == 4 then + for x = 1, ow do + writeu32(dst, o, readu32(src, row + xs[x])) + o += 4 + end + else + for x = 1, ow do + buffer.copy(dst, o, src, row + xs[x], bpp) + o += bpp + end + end + end +end + +-- affine: dst pixel centres through m = { a, b, c, d, e, f } (xin = a x + b y + c), bilinear with clamped +-- neighbours; centres outside the source -> zeros (Pillow) +@native function K.affine(src: buffer, w: number, h: number, ch: number, kind: number, dst: buffer, ow: number, oh: number, m: { number }) + local a, b, c, d, e, f = m[1], m[2], m[3], m[4], m[5], m[6] + local size = kind + for y = 0, oh - 1 do + local py = y + 0.5 + for x = 0, ow - 1 do + local px = x + 0.5 + local xin = a * px + b * py + c - 0.5 + local yin = d * px + e * py + f - 0.5 + local o = (y * ow + x) * ch * size + local x0 = floor(xin) + local y0 = floor(yin) + if xin < -0.5 or xin >= w - 0.5 or yin < -0.5 or yin >= h - 0.5 then + continue -- dst starts zeroed + end + local dx, dy = xin - x0, yin - y0 + local xa, xb = clamp(x0, 0, w - 1), clamp(x0 + 1, 0, w - 1) + local ya, yb = clamp(y0, 0, h - 1), clamp(y0 + 1, 0, h - 1) + for cc = 0, ch - 1 do + local p00 = rd(src, ((ya * w + xa) * ch + cc) * size, kind) + local p01 = rd(src, ((ya * w + xb) * ch + cc) * size, kind) + local p10 = rd(src, ((yb * w + xa) * ch + cc) * size, kind) + local p11 = rd(src, ((yb * w + xb) * ch + cc) * size, kind) + local top = p00 + (p01 - p00) * dx + local bot = p10 + (p11 - p10) * dx + local v = top + (bot - top) * dy + if kind == 1 then + writeu8(dst, o + cc, clamp(floor(v), 0, 255)) -- Pillow truncates + else + wr(dst, o + cc * size, kind, v) + end + end + end + end +end + +-- Pillow's alpha_composite of src onto dst, in place +@native function K.overRgba8(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, opacity: number) + for y = 0, h - 1 do + for x = 0, w - 1 do + local so = ((sy + y) * sw + sx + x) * 4 + local doff = ((dy + y) * dw + dx + x) * 4 + local sa = readu8(src, so + 3) + if opacity < 255 then + sa = (sa * opacity + 127) // 255 + end + if sa == 0 then + continue + elseif sa == 255 then + -- coef1 = 255 * 128, coef2 = 0: the source pixel exactly + writeu32(dst, doff, readu32(src, so)) + continue + end + local da = readu8(dst, doff + 3) + local blend = da * (255 - sa) + local outa255 = sa * 255 + blend + local coef1 = (sa * 255 * 255 * 128) // outa255 + local coef2 = 255 * 128 - coef1 + for cc = 0, 2 do + local t = readu8(src, so + cc) * coef1 + readu8(dst, doff + cc) * coef2 + 0x80 * 128 + t = ((t // 256) + t) // 256 + writeu8(dst, doff + cc, t // 128) + end + local t = outa255 + 0x80 + writeu8(dst, doff + 3, ((t // 256) + t) // 256) + end + end +end + +-- overFloat: straight-alpha "over" for rgba16 (kind 2) / rgbaf32 (kind 4); max = 65535 or 1 +@native function K.overFloat(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, opacity: number, kind: number) + local max = if kind == 2 then 65535 else 1 + local px = 4 * kind + for y = 0, h - 1 do + for x = 0, w - 1 do + local so = ((sy + y) * sw + sx + x) * px + local doff = ((dy + y) * dw + dx + x) * px + local sa = rd(src, so + 3 * kind, kind) / max * opacity + if sa <= 0 then + continue + end + local da = rd(dst, doff + 3 * kind, kind) / max + local oa = sa + da * (1 - sa) + for cc = 0, 2 do + local s = rd(src, so + cc * kind, kind) + local d = rd(dst, doff + cc * kind, kind) + wr(dst, doff + cc * kind, kind, if oa > 0 then (s * sa + d * da * (1 - sa)) / oa else 0) + end + wr(dst, doff + 3 * kind, kind, oa * max) + end + end +end + +@native function K.copyRect(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, bpp: number) + for y = 0, h - 1 do + buffer.copy(dst, ((dy + y) * dw + dx) * bpp, src, ((sy + y) * sw + sx) * bpp, w * bpp) + end +end + +-- a = 255 leaves the colour as it is both ways (MULDIV255(v, 255) = v, v * 255 // 255 = v) +@native local function premultiply4(b: buffer, n: number, un: boolean) + for o = 3, n * 4 - 1, 4 do + local a = readu8(b, o) + if a == 255 then + continue + end + if a == 0 then + writeu16(b, o - 3, 0) + writeu8(b, o - 1, 0) + continue + end + for c = o - 3, o - 1 do + local v = readu8(b, c) + if un then + writeu8(b, c, math.min(255, (v * 255) // a)) -- Pillow's rgbA2rgba + else + local t = v * a + 128 -- Pillow's MULDIV255 + writeu8(b, c, ((t // 256) + t) // 256) + end + end + end +end + +@native function K.opaque(b: buffer, n: number): boolean + for o = 3, n * 4 - 1, 4 do + if readu8(b, o) ~= 255 then + return false + end + end + return true +end + +@native function K.premultiply(b: buffer, n: number, ch: number, kind: number, un: boolean) + if kind == 1 and ch == 4 then + premultiply4(b, n, un) + return + end + local max = if kind == 1 then 255 elseif kind == 2 then 65535 else 1 + local px = ch * kind + for i = 0, n - 1 do + local o = i * px + local a = rd(b, o + (ch - 1) * kind, kind) + for cc = 0, ch - 2 do + local v = rd(b, o + cc * kind, kind) + local r + if un then + if a <= 0 then + r = 0 + elseif kind == 4 then + r = v / a + elseif kind == 1 then + r = math.min(255, (v * 255) // a) -- Pillow's rgbA2rgba + else + r = math.min(max, (v * max + a // 2) // a) + end + else + if kind == 4 then + r = v * a + elseif kind == 1 then + local t = v * a + 128 -- Pillow's MULDIV255 + r = ((t // 256) + t) // 256 + else + r = (v * a + max // 2) // max + end + end + wr(b, o + cc * kind, kind, r) + end + end +end + +return K +end +end + + + + + + ops_LayerOps + --!optimize 2 +--!nocheck +-- rosetta chunk ops_LayerOps (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["ops/LayerOps"] = function() -- ops/LayerOps: editing on the Layered type (PSD, Aseprite): flatten a layer tree (or one animation frame) to an @@ -213509,6 +215846,19 @@ end return LayerOps end +end + + + + + + ops_MeshOps + --!optimize 2 +--!nocheck +-- rosetta chunk ops_MeshOps (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["ops/MeshOps"] = function() -- ops/MeshOps: editing meshes in the standard Scene type: triangulate, transform, normals (area weighted or flat), @@ -214816,6 +217166,19 @@ end return Greedy end +end + + + + + + ops_MusicOps + --!optimize 2 +--!nocheck +-- rosetta chunk ops_MusicOps (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 1 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["ops/MusicOps"] = function() @@ -215169,12 +217532,12 @@ end - + - playlist + playlist_m3u --!optimize 2 --!nocheck --- rosetta chunk playlist (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- rosetta chunk playlist_m3u (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. -- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) @@ -215916,12 +218279,12 @@ end - + - subtitle + subtitle_ass --!optimize 2 --!nocheck --- rosetta chunk subtitle (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- rosetta chunk subtitle_ass (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. -- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) @@ -216749,13 +219112,13 @@ end - + - vector + vector_gamemaps --!optimize 2 --!nocheck --- rosetta chunk vector (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 18 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk vector_gamemaps (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (1 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["vector/gamemaps"] = function() @@ -217042,6 +219405,19 @@ end return Expand end +end + + + + + + vector_ldtk + --!optimize 2 +--!nocheck +-- rosetta chunk vector_ldtk (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["vector/ldtk"] = function() -- vector/ldtk: LDtk projects (.ldtk JSON, ldtk.io/json, 1.x) as a TileMap, read + write. Supports: IntGrid, @@ -218118,6 +220494,19 @@ end return Write end +end + + + + + + vector_ogmo + --!optimize 2 +--!nocheck +-- rosetta chunk vector_ogmo (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["vector/ogmo"] = function() -- vector/ogmo: Ogmo Editor 3 levels (.json) and projects (.ogmo) as a TileMap, read + write (OgmoEditor3-CE 3.x @@ -218996,6 +221385,19 @@ end return Write end +end + + + + + + vector_svg + --!optimize 2 +--!nocheck +-- rosetta chunk vector_svg (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 6 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["vector/svg"] = function() -- vector/svg: SVG 1.1 / 2 static documents (W3C SVG 1.1 2nd ed., SVG 2 CR). Supports: shapes and paths, transforms, @@ -221185,6 +223587,19 @@ end return Write end +end + + + + + + vector_tiled + --!optimize 2 +--!nocheck +-- rosetta chunk vector_tiled (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["vector/tiled"] = function() -- vector/tiled: Tiled maps, TMX (XML) / TMJ (JSON), and TSX / TSJ tilesets (Tiled 1.12 docs: "TMX Map Format", "JSON @@ -222763,13 +225178,13 @@ end - + - video + video_avi --!optimize 2 --!nocheck --- rosetta chunk video (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 16 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- rosetta chunk video_avi (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 2 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["video/avi"] = function() @@ -223217,6 +225632,19 @@ end return Fli end +end + + + + + + video_flv + --!optimize 2 +--!nocheck +-- rosetta chunk video_flv (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["video/flv"] = function() -- video/flv: Flash Video (Adobe FLV spec v10, Enhanced RTMP FourCC tags). Reads the tags and onMetaData (AMF0) into a @@ -224179,6 +226607,19 @@ end return Format end +end + + + + + + video_mkv + --!optimize 2 +--!nocheck +-- rosetta chunk video_mkv (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["video/mkv"] = function() -- video/mkv: Matroska / WebM (RFC 9559, the WebM guidelines), on containers/Ebml. Reads every packet (all lacings, @@ -225335,6 +227776,19 @@ end return Parse end +end + + + + + + video_mp4 + --!optimize 2 +--!nocheck +-- rosetta chunk video_mp4 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 3 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["video/mp4"] = function() -- video/mp4: MP4 / M4V / MOV / 3GP (ISO/IEC 14496-12 / 14496-14, QuickTime), on containers/IsoBmff. Reads every @@ -226096,6 +228550,19 @@ end return Ts end +end + + + + + + video_ogv + --!optimize 2 +--!nocheck +-- rosetta chunk video_ogv (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. +-- 4 modules (1 native: @native); the Rosetta root requires it when one of them is first included. +-- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). +return function(__FILES, __include) __FILES["video/ogv"] = function() -- video/ogv: Ogg Theora video (Theora I spec, RFC 3533 / 5334), on containers/Ogg: Theora (granule = keyframe << shift diff --git a/build/rosetta.lua b/build/rosetta.lua index f121fb6..19d55fe 100644 --- a/build/rosetta.lua +++ b/build/rosetta.lua @@ -677,10 +677,6 @@ local Bytes = __include("core/Bytes") local Input = __include("core/Input") local Types = __include("Types") local Registry = __include("Registry") -local Video = __include("codecs/video/Video") -local AudioWrap = __include("containers/AudioWrap") -local Rbx = __include("codecs/model/Rbx") -local ImageOps = __include("ops/ImageOps") local host = __include("host") local F = {} @@ -689,7 +685,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 = {} @@ -1008,7 +1003,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, track, sbr) -local buf, fmt, err = AudioWrap.wrap(demuxer, track) +local buf, fmt, err = __include("containers/AudioWrap").wrap(demuxer, track) if not buf then return nil, err end @@ -1020,7 +1015,7 @@ local buf, fmt, err = AudioWrap.wrap(demuxer, track) local skip = (type(track.codecDelay) == "number" and track.codecDelay > 0 and{(math.floor(track.codecDelay * dec.sampleRate + 0.5) )}or{0 })[1] local length = (type(track.playDuration) == "number" and track.playDuration > 0 and{(math.floor(track.playDuration * dec.sampleRate + 0.5) )}or{nil })[1] if skip > 0 or length then - dec = AudioWrap.trim(dec, skip, length) + dec = __include("containers/AudioWrap").trim(dec, skip, length) end end return dec, oerr @@ -1200,7 +1195,7 @@ if type(v.nextFrame) ~= "function" or type(v.toRGBA) ~= "function" then 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 = __include("ops/ImageOps").fromFrames(images, delays) if not img then return nil, ierr end @@ -1486,7 +1481,7 @@ if type(img) ~= "table" or img.kind ~= "image" then 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 = __include("ops/ImageOps").coalesce(img) if not list then return nil, cerr end @@ -1496,19 +1491,18 @@ if type(img) ~= "table" or img.kind ~= "image" then delays[i] = (type(f.delay) == "number" and f.delay > 0 and{f.delay }or{0.1 })[1] end elseif img.format ~= "rgba8" and img.format ~= "yuv420p" then - local c, cerr = ImageOps.convert(img, "rgba8") + local c, cerr = __include("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 __include("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, delays, opts) -return Video.fromFrames(images, delays, opts) +return __include("codecs/video/Video").fromFrames(images, delays, opts) end -F.video.codecs = Video F.model.loadTextures = function(scene, opts) local errs= {} @@ -1537,7 +1531,7 @@ end local OPS= { image = function() - return ImageOps + return __include("ops/ImageOps") end, mesh = function() return __include("ops/MeshOps") @@ -1581,6 +1575,28 @@ local make = OPS[k] return m end, }) ) +-- F.Rbx (codecs/model/Rbx), F.video.codecs (codecs/video/Video): required on first use + +setmetatable(F, { + __index = function(t, k) +if k == "Rbx" then + local m = __include("codecs/model/Rbx") + rawset(t, k, m) + return m + end + return nil + end, +}) +setmetatable(F.video, { + __index = function(t, k) +if k == "codecs" then + local m = __include("codecs/video/Video") + rawset(t, k, m) + return m + end + return nil + end, +}) return F end @@ -1977,7 +1993,7 @@ local list= { mime = { "audio/aac", "audio/aacp", "audio/x-aac" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Aac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = false, codecs = { "aac" }, streaming = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/aac") end, @@ -1990,7 +2006,7 @@ local list= { mime = { "audio/ac3", "audio/x-ac3" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/Ac3" }, caps = { decode = true, encode = false, codecs = { "ac3" }, channels = 6, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/ac3") end, @@ -2108,7 +2124,7 @@ local list= { mime = { "audio/mp4", "audio/x-m4a", "audio/m4a" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "codecs/audio/Aac", "codecs/audio/Alac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = true, codecs = { "aac", "alac" }, encodeCodecs = { "alac" }, tags = true, streaming = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/m4a") end, @@ -2121,7 +2137,7 @@ local list= { mime = { "audio/mpeg", "audio/mp3", "audio/mpa" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Resample", "codecs/audio/Mpa/Header", "codecs/audio/Mpa/Core", "codecs/audio/Mpa/Encode3", "codecs/audio/Mpa/Encode2" }, caps = { decode = true, encode = true, streaming = true, seek = true, layers = { 1, 2, 3 }, encodeLayers = { 2, 3 }, channels = 2 }, - sniff = 1, + sniff = 0, load = function() return __include("audio/mp3") end, @@ -2134,7 +2150,7 @@ local list= { mime = { "audio/x-musepack", "audio/musepack" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/ApeTag", "codecs/audio/Musepack" }, caps = { decode = true, encode = false, codecs = { "musepack" }, versions = { 7, 8 }, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/mpc") end, @@ -2225,7 +2241,7 @@ local list= { mime = { "audio/wav", "audio/x-wav", "audio/wave", "audio/vnd.wave" }, deps = { "core/Err", "core/Bytes", "Types", "containers/Riff", "codecs/audio/Pcm", "codecs/audio/Adpcm" }, caps = { decode = true, encode = true, streaming = true, depths = { 8, 16, 24, 32 }, float = true, rf64 = true }, - sniff = 1, + sniff = 0, load = function() return __include("audio/wav") end, @@ -2317,7 +2333,7 @@ local list= { mime = { "video/mp4", "video/quicktime", "video/3gpp" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "containers/Demux", "codecs/video/Video", "codecs/video/Video/Source" }, caps = { decode = true, encode = true, streaming = true, remux = true, video = { "mjpeg", "mpeg1", "mpeg2", "h264" }, audio = true, fragments = true }, - sniff = 1, + sniff = 0, load = function() return __include("video/mp4") end, @@ -2421,7 +2437,7 @@ local list= { mime = { "model/x-ase", "text/plain" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, - sniff = 1, + sniff = 0, load = function() return __include("model/ase") end, @@ -2512,7 +2528,7 @@ local list= { mime = { "application/vnd.autodesk.fbx", "model/fbx" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/compress/Deflate", "core/Base64", "codecs/model/Mat4" }, caps = { decode = true, encode = true, binary = true, ascii = true, materials = true, animation = true, skins = true, morphTargets = true, cameras = true, lights = true, polygons = true }, - sniff = 2, + sniff = 0, load = function() return __include("model/fbx") end, @@ -2668,7 +2684,7 @@ local list= { mime = { "application/x-ms3d" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten" }, caps = { decode = true, encode = true, materials = true, skins = true, animation = true }, - sniff = 1, + sniff = 0, load = function() return __include("model/ms3d") end, @@ -3269,7 +3285,7 @@ local list= { mime = { "application/x-fat-image" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Fat" }, caps = { decode = true, encode = true, variants = { "fat12", "fat16", "fat32" } }, - sniff = 1, + sniff = 0, load = function() return __include("archive/fat") end, @@ -3399,7 +3415,7 @@ local list= { mime = { "application/x-tar" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Tar" }, caps = { decode = true, encode = true, variants = { "ustar", "pax", "gnu" } }, - sniff = 1, + sniff = 0, load = function() return __include("archive/tar") end, @@ -3724,7 +3740,7 @@ local list= { mime = { "text/x-vdf" }, deps = { "core/Err", "core/Bytes", "core/Sniff", "codecs/text/KeyValues" }, caps = { decode = true, encode = true, ordered = true, binary = true }, - sniff = 1, + sniff = 0, load = function() return __include("data/vdf") end, @@ -4088,7 +4104,7 @@ local list= { mime = { "audio/x-soundfont" }, deps = { "core/Err", "core/Bytes", "codecs/audio/SoundFont" }, caps = { decode = true, encode = false, sm24 = true, sf3 = false }, - sniff = 1, + sniff = 0, load = function() return __include("music/sf2") end, @@ -4179,7 +4195,7 @@ local list= { mime = { "audio/x-scpls", "audio/scpls" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Url", "codecs/text/Text", "core/Sniff" }, caps = { decode = true, encode = true }, - sniff = 1, + sniff = 0, load = function() return __include("playlist/pls") end, @@ -4202,7 +4218,7 @@ local list= { return list end __FILES["Sniffs"] = function() -local __compat = __compat local buffer, bit32, __iter = __compat.buffer, __compat.bit32, __compat.__iter --!strict +local __compat = __compat local buffer, bit32, utf8, type, __iter = __compat.buffer, __compat.bit32, __compat.utf8, __compat.type, __compat.__iter --!strict --!optimize 2 -- Sniffs: GENERATED by tools/gen_registry.py from the format folders - do not edit. -- Each format's sniff (format path -> sniff(r)), copied from its init.luau with the top-level locals and types it @@ -4221,6 +4237,878 @@ local m = load() }) end +local P_audio_mp3_Tags= {} +do -- audio/mp3/Tags: id3v2Size +local Tags = {} +local band, bor, lshift = bit32.band, bit32.bor, bit32.lshift +local ru8 = buffer.readu8 +local function syncsafe(b, o) +return bor(lshift(band(ru8(b, o), 0x7F), 21), lshift(band(ru8(b, o + 1), 0x7F), 14), lshift(band(ru8(b, o + 2), 0x7F), 7), band(ru8(b, o + 3), 0x7F)) +end +function Tags.id3v2Size(b, o, len) +if len - o < 10 or buffer.readstring(b, o, 3) ~= "ID3" then + return 0 + end + if band(ru8(b, o + 5), 15) ~= 0 then + return 0 + end + for k = 6, 9 do + if band(ru8(b, o + k), 0x80) ~= 0 then + return 0 + end + end + local size = syncsafe(b, o + 6) + 10 + if band(ru8(b, o + 5), 16) ~= 0 then + size =size+ 10 + end + return size +end +P_audio_mp3_Tags.id3v2Size = Tags.id3v2Size +end + +local P_codecs_audio_Aac= {} +do -- codecs/audio/Aac: adts +local Aac = {} +Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 } + + + + + + + + + + +function Aac.adts(b, o, limit) +if o < 0 or o + 7 > limit or o + 7 > buffer.len(b) then + return nil + end + local b0, b1, b2, b3, b4, b5, b6 = buffer.readu8(b, o), buffer.readu8(b, o + 1), buffer.readu8(b, o + 2), buffer.readu8(b, o + 3), buffer.readu8(b, o + 4), buffer.readu8(b, o + 5), buffer.readu8(b, o + 6) + if b0 ~= 0xFF or bit32.band(b1, 0xF6) ~= 0xF0 then -- sync, layer 0 + return nil + end + local protected = bit32.band(b1, 1) == 0 + local profile = bit32.rshift(b2, 6) + local sfi = bit32.band(bit32.rshift(b2, 2), 15) + local ch = bit32.band(b2, 1) * 4 + bit32.rshift(b3, 6) + local size = bit32.band(b3, 3) * 2048 + b4 * 8 + bit32.rshift(b5, 5) + local blocks = bit32.band(b6, 3) + 1 + local hs = protected and 9 or 7 + if sfi > 12 or size < hs then + return nil + end + return { + headerSize = hs, + frameSize = size, + objectType = profile + 1, + sfIndex = sfi, + sampleRate = Aac.RATES[sfi + 1], + channelConfig = ch, + blocks = blocks, + protected = protected, + } +end +P_codecs_audio_Aac.adts = Aac.adts +end + +local P_codecs_audio_Ac3_Tables= {} +do -- codecs/audio/Ac3/Tables: BITRATES, RATES, frameWords +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, frmsizecod) +local kbps = T.BITRATES[math.floor(frmsizecod / 2 )+ 1] + if not kbps or fscod > 2 then + return 0 + end + if fscod == 0 then + return 2 * kbps + elseif fscod == 2 then + return 3 * kbps + end + return math.floor(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= {} +do -- codecs/audio/Ac3: header +local Ac3 = {} +local T = P_codecs_audio_Ac3_Tables +local readu8 = buffer.readu8 +local NFCHANS = { [0] = 2, 1, 2, 3, 3, 4, 4, 5 } + + + + + + + + + +function Ac3.header(b, o, limit) +if o < 0 or o + 8 > limit or o + 8 > buffer.len(b) then + return nil + end + if readu8(b, o) ~= 0x0B or readu8(b, o + 1) ~= 0x77 then + return nil + end + local bsid = bit32.rshift(readu8(b, o + 5), 3) + if bsid > 10 then + if bsid > 16 then + return nil + end + -- E-AC-3: strmtyp(2) substreamid(3) frmsiz(11) fscod(2) ... + local words = bit32.band(readu8(b, o + 2), 7) * 256 + readu8(b, o + 3) + 1 + local fs = bit32.rshift(readu8(b, o + 4), 6) + return { + sampleRate = (fs < 3 and{T.RATES[fs + 1] }or{0})[1], + frameSize = words * 2, + bitrate = 0, + channels = 0, + acmod = bit32.band(bit32.rshift(readu8(b, o + 4), 1), 7), + lfeon = false, + bsid = bsid, + } + end + local b4 = readu8(b, o + 4) + local fscod, frmsizecod = bit32.rshift(b4, 6), bit32.band(b4, 63) + local words = T.frameWords(fscod, frmsizecod) + if words == 0 then + return nil + end + local acmod = bit32.rshift(readu8(b, o + 6), 5) + -- lfeon: after acmod and the optional cmixlev / surmixlev / dsurmod fields + local skip = 0 + if bit32.band(acmod, 1) == 1 and acmod ~= 1 then + skip =skip+ 2 + end + if bit32.band(acmod, 4) ~= 0 then + skip =skip+ 2 + end + if acmod == 2 then + skip =skip+ 2 + end + local w = readu8(b, o + 6) * 256 + readu8(b, o + 7) + local lfeon = bit32.extract(w, 12 - skip, 1) == 1 + local shift = (bsid > 8 and((bsid - 8 ))or(0 +)) return { + sampleRate = math.floor(T.RATES[fscod + 1] / 2 ^ shift), + frameSize = words * 2, + bitrate = math.floor(T.BITRATES[math.floor(frmsizecod / 2 )+ 1] * 1000 / 2 ^ shift), + channels = NFCHANS[acmod] + (lfeon and 1 or 0), + acmod = acmod, + lfeon = lfeon, + bsid = bsid, + } +end +P_codecs_audio_Ac3.header = Ac3.header +end + +local P_codecs_audio_Mpa_Tables= {} +do -- codecs/audio/Mpa/Tables: halfrate +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= {} +do -- codecs/audio/Mpa/Header: compare, frameBytes, padding, valid +local H = {} +local T = P_codecs_audio_Mpa_Tables +local band, bxor, rshift = bit32.band, bit32.bxor, bit32.rshift +local ru8 = buffer.readu8 +local HALFRATE = T.halfrate +local HZ = { [0] = 44100, 48000, 32000 } +function H.valid(b, o) +if ru8(b, o) ~= 0xFF then + return false + end + local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + return (band(h1, 0xF0) == 0xF0 or band(h1, 0xFE) == 0xE2) + and band(rshift(h1, 1), 3) ~= 0 + and rshift(h2, 4) ~= 15 + and band(rshift(h2, 2), 3) ~= 3 +end +local valid = H.valid +function H.compare(b, o1, o2) +if not valid(b, o2) then + return false + end + local a1, a2 = ru8(b, o1 + 1), ru8(b, o1 + 2) + local c1, c2 = ru8(b, o2 + 1), ru8(b, o2 + 2) + return band(bxor(a1, c1), 0xFE) == 0 + and band(bxor(a2, c2), 0x0C) == 0 + and (band(a2, 0xF0) == 0) == (band(c2, 0xF0) == 0) +end +function H.bitrateKbps(h1, h2) +local mpeg1 = band(h1, 8) ~= 0 and 1 or 0 + local layer = band(rshift(h1, 1), 3) + return 2 * HALFRATE[mpeg1 * 45 + (layer - 1) * 15 + rshift(h2, 4)] +end +local bitrateKbps = H.bitrateKbps +function H.sampleRate(h1, h2) +local hz = HZ[band(rshift(h2, 2), 3)] + if band(h1, 8) == 0 then + hz =math.floor(hz/ 2 +) end + if band(h1, 0x10) == 0 then + hz =math.floor(hz/ 2 +) end + return hz +end +local sampleRate = H.sampleRate +function H.frameSamples(h1) +if band(h1, 6) == 6 then + return 384 + elseif band(h1, 14) == 2 then + return 576 + end + return 1152 +end +local frameSamples = H.frameSamples +function H.frameBytes(b, o, freeSize) +local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + local hz = sampleRate(h1, h2) + local fb = math.floor(frameSamples(h1) * bitrateKbps(h1, h2) * 125 / hz +) if band(h1, 6) == 6 then + fb = band(fb, 0xFFFFFFFC) + end + return (fb ~= 0 and{fb }or{freeSize +})[1]end +function H.padding(b, o) +if band(ru8(b, o + 2), 2) == 0 then + return 0 + end + return band(ru8(b, o + 1), 6) == 6 and 4 or 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= {} +do -- codecs/audio/Musepack: magic +local Musepack = {} +function Musepack.magic(buf, p, limit) +if p + 4 > limit then + return 0 + end + local m = buffer.readstring(buf, p, 4) + if m == "MPCK" then + return 8 + end + if string.sub(m, 1, 3) == "MP+" then + return 7 + end + return 0 +end +P_codecs_audio_Musepack.magic = Musepack.magic +end + +local P_codecs_audio_SoundFont= {} +do -- codecs/audio/SoundFont: sniff +local SoundFont = {} +local Bytes = __include("core/Bytes") +function SoundFont.sniff(r) +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() + return __include("codecs/compress/Brotli") +end) + +local P_codecs_compress_Deflate_Inflate = lazy(function() + return __include("codecs/compress/Deflate/Inflate") +end) + +local P_codecs_compress_Deflate= {} +do -- codecs/compress/Deflate: peek +local Deflate = {} +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Inflate = P_codecs_compress_Deflate_Inflate +local args = Bytes.span +local function shrink(out, n) +if buffer.len(out) == n then + return out + end + local b = buffer.create(n) + buffer.copy(b, 0, out, 0, n) + return b +end +local function inflateErr(msg, at) +local code = (string.find(msg, "truncated", 1, true) and{Err.TRUNCATED }or{Err.CORRUPT +})[1] return Err.new(code, "inflate: " .. msg, at) +end +local function gzipBody(b, p, e) +local flg = buffer.readu8(b, p + 3) + if flg >= 0x20 then + return nil, Err.new(Err.CORRUPT, "gzip: reserved flags set", p + 3) + end + local q = p + 10 + if bit32.band(flg, 4) ~= 0 then -- FEXTRA + if q + 2 > e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + q =q+ (2 + buffer.readu16(b, q) +) end + for _, bit in __iter({ 8, 16 }) do -- FNAME, FCOMMENT: zero-terminated + if bit32.band(flg, bit) ~= 0 then + while q < e and buffer.readu8(b, q) ~= 0 do + q =q+ 1 + end + q =q+ 1 + end + end + if bit32.band(flg, 2) ~= 0 then -- FHCRC + q =q+ 2 + end + if q >= e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + return q, nil +end +function Deflate.peek(buf, offset, length, n) +local b, o, l, aerr = args("Deflate.peek", buf, offset, length) + if not b then + return nil, aerr + end + if type(n) ~= "number" or n < 1 then + return nil, Err.new(Err.ARG, "Deflate.peek: bad size " .. tostring(n)) + end + local e = o + l + local q = o + if l >= 18 and buffer.readu8(b, o) == 0x1f and buffer.readu8(b, o + 1) == 0x8b and buffer.readu8(b, o + 2) == 8 then + local herr + q, herr = gzipBody(b, o, e) + if not q then + return nil, herr + end + elseif l >= 6 then + local cmf, flg = buffer.readu8(b, o), buffer.readu8(b, o + 1) + if cmf % 16 == 8 and math.floor(cmf / 16 )<= 7 and (cmf * 256 + flg) % 31 == 0 and bit32.band(flg, 0x20) == 0 then + q = o + 2 + end + end + local out, k = Inflate.raw(b, q , e, n, true, true) + if not out then + return nil, inflateErr(tostring(k), q) + end + return shrink(out, k), nil +end +P_codecs_compress_Deflate.peek = Deflate.peek +end + +local P_codecs_compress_Zstd_Decode = lazy(function() + return __include("codecs/compress/Zstd/Decode") +end) + +local P_codecs_compress_Zstd= {} +do -- codecs/compress/Zstd: MAGIC, decompress +local Zstd = {} +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Decode = P_codecs_compress_Zstd_Decode + + + + +Zstd.MAGIC = "\40\181\47\253" +function Zstd.decompress(buf, offset, length, opts) +local b, o, l, aerr = Bytes.span("Zstd.decompress", buf, offset, length) + if not b then + return nil, aerr + end + local maxBytes = (opts and opts.maxBytes ~= nil and{opts.maxBytes }or{(2 ^ 30 +)})[1] if type(maxBytes) ~= "number" or maxBytes < 0 then + return nil, Err.new(Err.ARG, "Zstd.decompress: bad maxBytes " .. tostring(maxBytes)) + end + local verify = not (opts and opts.verify == false) + local out, len, consumed, at = Decode.decompress(b, o, o + l, maxBytes, verify) + if not out then + return nil, Err.from(consumed, at, len) + end + if buffer.len(out) ~= len then + local r = buffer.create(len) + buffer.copy(r, 0, out, 0, len) + out = r + 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= {} +do -- codecs/text/KeyValues/Binary: sniff +local Binary = {} +local readu8, readu32, readi32, readf32 = buffer.readu8, buffer.readu32, buffer.readi32, buffer.readf32 +function Binary.sniff(b, o, n) +if n < 3 then + return false + end + local t = readu8(b, o) + if t ~= 0 and t ~= 1 and t ~= 2 then + return false + end + for i = 1, math.min(n - 1, 64) do + local c = readu8(b, o + i) + if c == 0 then + return i > 1 + elseif c < 32 then + return false + end + end + return false +end +P_codecs_text_KeyValues_Binary.sniff = Binary.sniff +end + +local P_codecs_text_KeyValues= {} +do -- codecs/text/KeyValues: isBinary +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= {} +do -- codecs/text/Nbt/Value: NAMES +local Value = {} +Value.NAMES = { + [0] = "end", + "byte", + "short", + "int", + "long", + "float", + "double", + "byteArray", + "string", + "list", + "compound", + "intArray", + "longArray", +} +Value.IDS = {} +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= {} +do -- codecs/text/Nbt: peek +local Nbt = {} +local Deflate = P_codecs_compress_Deflate +local Value = P_codecs_text_Nbt_Value + + + + + + + + + + +local function plausibleName(b, p, n) +if p + n > buffer.len(b) or n > 256 then + return nil + end + local s = buffer.readstring(b, p, n) + if string.find(s, "[%z\1-\31\127]") then + return nil + end + return s +end +function Nbt.peek(buf, offset, length) +local o = offset or 0 + local l = length or (buffer.len(buf) - o) + if l < 3 then + return nil + end + local c0, c1 = buffer.readu8(buf, o), buffer.readu8(buf, o + 1) + local head +local comp = "none" + if c0 == 0x1f and c1 == 0x8b or (c0 % 16 == 8 and c0 < 0x80 and (c0 * 256 + c1) % 31 == 0) then + local h = Deflate.peek(buf, o, l, 1024) + if not h then + return nil + end + head, comp = h, c0 == 0x1f and"gzip" or"zlib" + else + local n = math.min(l, 1024) + head = buffer.create(n) + buffer.copy(head, 0, buf, o, n) + end + local hn = buffer.len(head) + local function at(p, endian, header) +if p + 3 > hn then + return nil + end + local t = buffer.readu8(head, p) + if t ~= 10 and t ~= 9 then + return nil + end + local function u16(q) +local a, b = buffer.readu8(head, q), buffer.readu8(head, q + 1) + return (endian == "big" and((a * 256 + b ))or((b * 256 + a +))) end + local nl = u16(p + 1) + local name = plausibleName(head, p + 3, nl) + if not name then + return nil + end + local res= { compression = comp, endian = endian , header = header, rootType = Value.NAMES[t], name = name, head = head } + local q = p + 3 + nl + if t == 10 and q < hn then + local ft = buffer.readu8(head, q) + if ft > 12 then + return nil + end + if ft == 0 then + res.firstType = "end" + elseif q + 3 <= hn then + local fname = plausibleName(head, q + 3, u16(q + 1)) + if fname == nil and q + 3 + u16(q + 1) <= hn then + return nil + end + res.firstType, res.firstName = Value.NAMES[ft], fname + end + end + return res + end + if hn >= 12 and buffer.readu32(head, 4) == ((comp == "none" and{l }or{(-1)})[1]) - 8 then + local r = at(8, "little", true) + if r then + return r + end + 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= {} +do -- codecs/text/Text: toUtf8, trim, utf16 +local Text = {} +function Text.utf8char(c) +local char = string.char + if c < 0x80 then + return char(c) + elseif c < 0x800 then + return char(0xC0 + math.floor(c / 64), 0x80 + c % 64) + elseif c < 0x10000 then + return char(0xE0 + math.floor(c / 4096), 0x80 + (math.floor(c / 64)) % 64, 0x80 + c % 64) + end + return char(0xF0 + math.floor(c / 262144), 0x80 + (math.floor(c / 4096)) % 64, 0x80 + (math.floor(c / 64)) % 64, 0x80 + c % 64) +end +Text.CP1252 = { + [0x80] = 0x20AC, [0x82] = 0x201A, [0x83] = 0x0192, [0x84] = 0x201E, [0x85] = 0x2026, [0x86] = 0x2020, + [0x87] = 0x2021, [0x88] = 0x02C6, [0x89] = 0x2030, [0x8A] = 0x0160, [0x8B] = 0x2039, [0x8C] = 0x0152, + [0x8E] = 0x017D, [0x91] = 0x2018, [0x92] = 0x2019, [0x93] = 0x201C, [0x94] = 0x201D, [0x95] = 0x2022, + [0x96] = 0x2013, [0x97] = 0x2014, [0x98] = 0x02DC, [0x99] = 0x2122, [0x9A] = 0x0161, [0x9B] = 0x203A, + [0x9C] = 0x0153, [0x9E] = 0x017E, [0x9F] = 0x0178, +} +function Text.trim(s) +return ((string.match(s, "^%s*(.-)%s*$") )) +end +function Text.utf16(b, o, n, bigEndian) +local out = {} + local k = 0 + local readu16 = buffer.readu16 + local function unit(at) +local v = readu16(b, at) + return (bigEndian and(((v % 256) * 256 + math.floor(v / 256 )))or(v +)) end + while k + 1 < n do + local c = unit(o + k) + k =k+ 2 + if c >= 0xD800 and c < 0xDC00 and k + 1 < n then + local lo = unit(o + k) + if lo >= 0xDC00 and lo < 0xE000 then + c = 0x10000 + (c - 0xD800) * 1024 + (lo - 0xDC00) + k =k+ 2 + end + end + if c >= 0xD800 and c < 0xE000 then + c = 0xFFFD + end + table.insert(out, Text.utf8char(c)) + end + return table.concat(out) +end +function Text.toUtf8(text, warnings) +if string.sub(text, 1, 3) == "\239\187\191" then + text = string.sub(text, 4) + end + if utf8.len(text) then + return text + end + if warnings then + table.insert(warnings, "text is not UTF-8: read as Windows-1252") + end + local out = table.create(#text) + for i = 1, #text do + local b = string.byte(text, i) + if b < 0x80 then + out[i] = string.char(b) + else + out[i] = utf8.char((b < 0xA0 and{Text.CP1252[b] or 0xFFFD }or{b})[1]) + end + 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= {} +do -- containers/Fat: open +local Fat = {} +local readu8, readu16, readu32 = buffer.readu8, buffer.readu16, buffer.readu32 + + + + + + + + + + + + + + + + + + + +local function bpbAt(b, o, len) +if len < 512 then + return nil, "truncated: smaller than a boot sector" + end + local jump = readu8(b, o) + local bps = readu16(b, o + 11) + local spc = readu8(b, o + 13) + if (jump ~= 0xEB and jump ~= 0xE9 and jump ~= 0xE8) or (bps ~= 512 and bps ~= 1024 and bps ~= 2048 and bps ~= 4096) then + return nil, "no FAT boot sector" + end + if spc == 0 or bit32.band(spc, spc - 1) ~= 0 then + return nil, "bad sectors per cluster" + end + local reserved, nfats, rootEntries = readu16(b, o + 14), readu8(b, o + 16), readu16(b, o + 17) + local total = readu16(b, o + 19) + if total == 0 then + total = readu32(b, o + 32) + end + local fatSectors = readu16(b, o + 22) + local fat32 = fatSectors == 0 + if fat32 then + fatSectors = readu32(b, o + 36) + end + if reserved == 0 or nfats == 0 or fatSectors == 0 or total == 0 then + return nil, "bad BPB" + end + local rootSectors = math.ceil(rootEntries * 32 / bps) + local dataSector = reserved + nfats * fatSectors + rootSectors + if dataSector >= total then + return nil, "bad BPB: no data area" + end + local clusters = math.floor((total - dataSector) / spc +) local bits = clusters < 4085 and 12 or(clusters < 65525 and 16 or 32 +) if fat32 and bits ~= 32 then + bits = 32 -- some small FAT32 volumes (mkfs.fat -F 32 on tiny images) are FAT32 regardless of the count + end + if total * bps > len then + -- images cut short at the last used sector are common: allow, reads past the end fail + total = math.floor(len / bps +) end + local labelAt = bits == 32 and 71 or 43 + local sig = readu8(b, o + (bits == 32 and 66 or 38)) + local label= (sig == 0x29 and{(string.gsub(buffer.readstring(b, o + labelAt, 11), " +$", "")) }or{nil +})[1] if label == "NO NAME" or label == "" then + label = nil + end + return { + b = b, + base = o, + limit = o + len, + bps = bps, + spc = spc, + fatOffset = reserved * bps, + fatSize = fatSectors * bps, + rootOffset = (reserved + nfats * fatSectors) * bps, + rootEntries = rootEntries, + rootCluster = (bits == 32 and{(readu32(b, o + 44) )}or{0})[1], + dataOffset = dataSector * bps, + clusters = clusters, + bits = bits, + label = label, + oem = buffer.readstring(b, o + 3, 8), + media = readu8(b, o + 21), + }, nil +end + +local FAT_TYPES = { [0x01] = true, [0x04] = true, [0x06] = true, [0x0B] = true, [0x0C] = true, [0x0E] = true, [0x11] = true, [0x14] = true, [0x16] = true, [0x1B] = true, [0x1C] = true, [0x1E] = true } +function Fat.open(b, off, len, opts) +local o= opts or {} + off = math.max(0, off) + len = math.min(len, buffer.len(b) - off) + if len < 512 then + return nil, "truncated: smaller than a boot sector" + end + if not o.partition then + local v = bpbAt(b, off, len) + if v then + return v, nil + end + end + -- an MBR: 0x55AA and four partition entries + if readu8(b, off + 510) ~= 0x55 or readu8(b, off + 511) ~= 0xAA then + return nil, "no FAT boot sector and no partition table" + end + for i = 1, 4 do + local e = off + 446 + (i - 1) * 16 + local ptype = readu8(b, e + 4) + local lba, count = readu32(b, e + 8), readu32(b, e + 12) + if (o.partition == i or (not o.partition and FAT_TYPES[ptype])) and ptype ~= 0 then + if lba * 512 >= len then + return nil, "truncated: partition " .. i .. " starts past the end" + end + local v, err = bpbAt(b, off + lba * 512, math.min(count * 512, len - lba * 512)) + if v then + v.partition = i + end + return v, err + end + end + return nil, (o.partition and(("no partition " .. o.partition ))or("no FAT partition" +))end +P_containers_Fat.open = Fat.open +end + +local P_containers_IsoBmff= {} +do -- containers/IsoBmff: sniff +local IsoBmff = {} +local Bytes = __include("core/Bytes") +local TOP= { + ftyp = true, moov = true, mdat = true, free = true, skip = true, wide = true, pnot = true, moof = true, + styp = true, sidx = true, meta = true, uuid = true, PICT = true, +} +function IsoBmff.sniff(r) +local head = r:peek(12) + if #head < 8 then + return nil + end + local typ = string.sub(head, 5, 8) + if typ == "ftyp" then + return (#head >= 12 and{(string.sub(head, 9, 12) )}or{"" +})[1] end + if TOP[typ] then + local size = string.byte(head, 1) * 16777216 + string.byte(head, 2) * 65536 + string.byte(head, 3) * 256 + string.byte(head, 4) + if size == 1 or size == 0 or size >= 8 then + return "" + end + end + return nil +end +P_containers_IsoBmff.sniff = IsoBmff.sniff +end + +local P_containers_Riff= {} +do -- containers/Riff: sniff +local Riff = {} +function Riff.sniff(r) +local magic = r:peek(4) + if magic ~= "RIFF" and magic ~= "RIFX" and magic ~= "RF64" and magic ~= "BW64" then + return nil + end + local form = r:peek(4, 8) + return (#form == 4 and{form }or{nil +})[1]end +P_containers_Riff.sniff = Riff.sniff +end + +local P_containers_Tar= {} +do -- containers/Tar: valid +local Tar = {} +local BLOCK = 512 +local function zeros(b, o) +for i = 0, BLOCK - 1, 4 do + if buffer.readu32(b, o + i) ~= 0 then + return false + end + end + return true +end +local function number(b, o, n) +local first = buffer.readu8(b, o) + if first >= 0x80 then + local v = first - (first >= 0xC0 and 0x100 or 0x80) -- 0xFF.. = negative + for i = 1, n - 1 do + v = v * 256 + buffer.readu8(b, o + i) + end + return v + end + local s = buffer.readstring(b, o, n) + s = string.match(s, "^[ %z]*([0-7]*)") or "" + if s == "" then + return 0 + end + return tonumber(s, 8) +end +local function checksum(b, o) +local u, s = 0, 0 + for i = 0, BLOCK - 1 do + local v = i >= 148 and i < 156 and 32 or buffer.readu8(b, o + i) + u =u+ v + s =s+ (v >= 128 and((v - 256 ))or(v +)) end + return u, s +end +function Tar.valid(b, o) +if o + BLOCK > buffer.len(b) or zeros(b, o) then + return false + end + local want = number(b, o + 148, 8) + 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= {} +do -- model/fbx/Binary: MAGIC +local Binary = {} +local MAGIC = "Kaydara FBX Binary \0" +Binary.MAGIC = MAGIC +P_model_fbx_Binary.MAGIC = Binary.MAGIC +end + +local P_model_ms3d_Read= {} +do -- model/ms3d/Read: MAGIC +local Read = {} +Read.MAGIC = "MS3D000000" +P_model_ms3d_Read.MAGIC = Read.MAGIC +end + do -- image/ani local Bytes = __include("core/Bytes") S["image/ani"] = function(r) @@ -4650,9 +5538,7 @@ end do -- audio/aac local Bytes = __include("core/Bytes") -local Aac = lazy(function() - return __include("codecs/audio/Aac") -end) +local Aac = P_codecs_audio_Aac local readu8 = buffer.readu8 local function id3Size(b, p, limit) if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then @@ -4682,9 +5568,7 @@ end do -- audio/ac3 local Bytes = __include("core/Bytes") -local Ac3 = lazy(function() - return __include("codecs/audio/Ac3") -end) +local Ac3 = P_codecs_audio_Ac3 S["audio/ac3"] = function(r) local b, p, limit = r.buf, r.pos, r.limit local h = Ac3.header(b, p, limit) @@ -4816,9 +5700,7 @@ end do -- audio/m4a local Bytes = __include("core/Bytes") -local IsoBmff = lazy(function() - return __include("containers/IsoBmff") -end) +local IsoBmff = P_containers_IsoBmff local AUDIO_BRANDS= { ["M4A "] = 1, ["M4B "] = 1, ["M4P "] = 1, ["M4V "] = 0.3 } S["audio/m4a"] = function(r) local brand = IsoBmff.sniff(r) @@ -4837,12 +5719,8 @@ end do -- audio/mp3 local Bytes = __include("core/Bytes") -local Header = lazy(function() - return __include("codecs/audio/Mpa/Header") -end) -local Tags = lazy(function() - return __include("audio/mp3/Tags") -end) +local Header = P_codecs_audio_Mpa_Header +local Tags = P_audio_mp3_Tags S["audio/mp3"] = function(r) local b, p, lim = r.buf, r.pos, r.limit local id3 = false @@ -4873,9 +5751,7 @@ end do -- audio/mpc local Bytes = __include("core/Bytes") -local Musepack = lazy(function() - return __include("codecs/audio/Musepack") -end) +local Musepack = P_codecs_audio_Musepack local function id3v2(b, p, limit) if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then return 0 @@ -4974,9 +5850,7 @@ end do -- audio/wav local Bytes = __include("core/Bytes") -local Riff = lazy(function() - return __include("containers/Riff") -end) +local Riff = P_containers_Riff S["audio/wav"] = function(r) return Riff.sniff(r) == "WAVE" and 1 or 0 end @@ -5080,9 +5954,7 @@ end do -- video/mp4 local Bytes = __include("core/Bytes") -local IsoBmff = lazy(function() - return __include("containers/IsoBmff") -end) +local IsoBmff = P_containers_IsoBmff local IMAGE_BRANDS = { avif = true, avis = true, heic = true, heix = true, mif1 = true, msf1 = true, ["crx "] = true } local AUDIO_BRANDS = { ["M4A "] = true, ["M4B "] = true, ["M4P "] = true } S["video/mp4"] = function(r) @@ -5245,9 +6117,7 @@ end do -- model/ase local Bytes = __include("core/Bytes") -local Text = lazy(function() - return __include("codecs/text/Text") -end) +local Text = P_codecs_text_Text local MAGIC = "*3DSMAX_ASCIIEXPORT" local function utf16(r) local h = r:peek(2) @@ -5295,12 +6165,8 @@ end do -- model/blend local Bytes = __include("core/Bytes") -local Deflate = lazy(function() - return __include("codecs/compress/Deflate") -end) -local Zstd = lazy(function() - return __include("codecs/compress/Zstd") -end) +local Deflate = P_codecs_compress_Deflate +local Zstd = P_codecs_compress_Zstd S["model/blend"] = function(r) local head = r:peek(7) if head == "BLENDER" then @@ -5429,6 +6295,25 @@ local head = r:peek(2048) end end +do -- model/fbx +local Bytes = __include("core/Bytes") +local Binary = P_model_fbx_Binary +local MAGIC = Binary.MAGIC +S["model/fbx"] = function(r) +if r:peek(21) == MAGIC then + return 1 + end + local head = r:peek(2048) + if string.find(head, "FBXHeaderExtension:", 1, true) then + return 0.95 + end + if string.find(head, "^; FBX %d") then + return 0.8 + end + return 0 +end +end + do -- model/gltf local Sniff = __include("core/Sniff") local Bytes = __include("core/Bytes") @@ -5608,9 +6493,7 @@ end do -- model/ms3d local Bytes = __include("core/Bytes") -local Read = lazy(function() - return __include("model/ms3d/Read") -end) +local Read = P_model_ms3d_Read S["model/ms3d"] = function(r) local h = r:peek(14) if string.sub(h, 1, 10) ~= Read.MAGIC then @@ -5740,9 +6623,7 @@ end do -- model/schematic local Bytes = __include("core/Bytes") -local Nbt = lazy(function() - return __include("codecs/text/Nbt") -end) +local Nbt = P_codecs_text_Nbt local LITEMATIC_HINTS = { "Regions", "EnclosingSize", "RegionCount", "TotalVolume", "MinecraftDataVersion" } local SPONGE_HINTS = { "BlockData", "PaletteMax" } -- v1 / v2 fields (some writers leave the root unnamed) local function hinted(head, hints) @@ -6205,9 +7086,7 @@ end do -- archive/br local Err = __include("core/Err") local Bytes = __include("core/Bytes") -local Brotli = lazy(function() - return __include("codecs/compress/Brotli") -end) +local Brotli = P_codecs_compress_Brotli local SNIFF_WHOLE = 262144 -- streams up to this size are decoded whole by sniff local SNIFF_PREFIX = 65536 S["archive/br"] = function(r) @@ -6320,9 +7199,7 @@ end do -- archive/fat local Bytes = __include("core/Bytes") -local Fat = lazy(function() - return __include("containers/Fat") -end) +local Fat = P_containers_Fat S["archive/fat"] = function(r) if r:remaining() < 512 then return 0 @@ -6494,9 +7371,7 @@ end do -- archive/tar local Bytes = __include("core/Bytes") -local Tar = lazy(function() - return __include("containers/Tar") -end) +local Tar = P_containers_Tar S["archive/tar"] = function(r) if r:remaining() < 512 then return 0 @@ -6510,12 +7385,8 @@ end do -- archive/unitypackage local Bytes = __include("core/Bytes") -local Deflate = lazy(function() - return __include("codecs/compress/Deflate") -end) -local Tar = lazy(function() - return __include("containers/Tar") -end) +local Deflate = P_codecs_compress_Deflate +local Tar = P_containers_Tar local function guidOf(name) local n = string.gsub(name, "^%./", "") local guid, rest = string.match(n, "^(%x+)/?(.*)$") @@ -6719,9 +7590,7 @@ end do -- archive/zst local Bytes = __include("core/Bytes") -local Zstd = lazy(function() - return __include("codecs/compress/Zstd") -end) +local Zstd = P_codecs_compress_Zstd S["archive/zst"] = function(r) local m = r:peek(4) if m == Zstd.MAGIC then @@ -6814,9 +7683,7 @@ end do -- data/nbt local Bytes = __include("core/Bytes") -local Nbt = lazy(function() - return __include("codecs/text/Nbt") -end) +local Nbt = P_codecs_text_Nbt S["data/nbt"] = function(r) local p = Nbt.peek(r.buf, r.base, r.limit - r.base) if not p or p.rootType ~= "compound" then @@ -6944,9 +7811,7 @@ end do -- data/vdf local Bytes = __include("core/Bytes") local Sniff = __include("core/Sniff") -local KeyValues = lazy(function() - return __include("codecs/text/KeyValues") -end) +local KeyValues = P_codecs_text_KeyValues S["data/vdf"] = function(r) local n = r:remaining() if KeyValues.isBinary(r.buf, r.pos, n) then @@ -7412,9 +8277,7 @@ end do -- music/sf2 local Bytes = __include("core/Bytes") -local SoundFont = lazy(function() - return __include("codecs/audio/SoundFont") -end) +local SoundFont = P_codecs_audio_SoundFont S["music/sf2"] = function(r) return SoundFont.sniff(r) and 1 or 0 end @@ -7562,9 +8425,7 @@ end do -- playlist/pls local Sniff = __include("core/Sniff") local Bytes = __include("core/Bytes") -local Text = lazy(function() - return __include("codecs/text/Text") -end) +local Text = P_codecs_text_Text S["playlist/pls"] = function(r) local s = Sniff.text(r, 64) local first = string.match(s, "^%s*([^\r\n]*)") @@ -62449,7 +63310,6 @@ local Err = __include("core/Err") local Bytes = __include("core/Bytes") local Crc32 = __include("core/Crc32") local Base64 = __include("core/Base64") -local Deflate = __include("codecs/compress/Deflate") local Decode = __include("codecs/compress/Brotli/Decode") local StaticData = __include("codecs/compress/Brotli/Static") @@ -62466,33 +63326,47 @@ return Base64.decode(s) or buffer.create(0) end local static= nil +local dictionary= nil +local dictionaryErr= nil -local function tables() -if static then - return static, nil +-- inflated on the first dictionary reference (RFC 7932 section 8) +local function loadDictionary() +if dictionary or dictionaryErr then + return dictionary end + local Deflate = __include("codecs/compress/Deflate") local z = unbase64(table.concat(StaticData.dictionary)) local dict, err = Deflate.zlib(z, 0, nil, StaticData.dictionarySize) if not dict then - return nil, err + dictionaryErr = err + return nil end if Crc32.of(dict) ~= StaticData.dictionaryCrc then - return nil, Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + dictionaryErr = Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + return nil end - static = { - dictionary = dict, + dictionary = dict + return dict +end + +local function tables() +if static then + return static + end + local s= { + dictionary = loadDictionary, context = unbase64(table.concat(StaticData.context)), prefixSuffix = unbase64(StaticData.prefixSuffix), prefixSuffixMap = StaticData.prefixSuffixMap, transforms = StaticData.transforms, } - return static, nil + static = s + return s end function Brotli.dictionary() -local s = tables() - return (s and{s.dictionary }or{nil -})[1]end +return loadDictionary() +end function Brotli.decompress(buf, offset, length, opts) local b, o, l, aerr = Bytes.span("Brotli.decompress", buf, offset, length) @@ -62507,12 +63381,11 @@ local b, o, l, aerr = Bytes.span("Brotli.decompress", buf, offset, length) if l == 0 then return nil, Err.new(Err.TRUNCATED, "brotli: empty input", o) end - local S, serr = tables() - if not S then - return nil, serr - end - local out, size, consumed = Decode.decompress(b, o, l, maxBytes, S, large) + local out, size, consumed = Decode.decompress(b, o, l, maxBytes, tables(), large) if not out then + if size == Decode.NO_DICTIONARY and dictionaryErr then + return nil, dictionaryErr + end local e = Err.from(size, o) e.message = "brotli: " .. e.message return nil, e @@ -62540,6 +63413,9 @@ local bcreate, bcopy, blen, bfill = buffer.create, buffer.copy, buffer.len, buff local Decode = {} +local NO_DICTIONARY = "static dictionary unavailable" +Decode.NO_DICTIONARY = NO_DICTIONARY + @@ -63046,7 +63922,7 @@ local ntrees = varLen8() + 1 end local maxBackward = 2 ^ wbits - 16 - local dict = S.dictionary + local dict= nil local LUT = S.context local PS = S.prefixSuffix local PSMAP = S.prefixSuffixMap @@ -63415,7 +64291,12 @@ __DARKLUA_CONTINUE_26=true break end local ws = w if wl > 0 then - bcopy(WORD, w, dict, wo, wl) + local d = dict or S.dictionary() + if d == nil then + return nil, NO_DICTIONARY + end + dict = d + bcopy(WORD, w, d, wo, wl) w =w+ wl end if ttype == 10 then diff --git a/build/rosetta.lua.linemap.json b/build/rosetta.lua.linemap.json index 9d132a5..39344ef 100644 --- a/build/rosetta.lua.linemap.json +++ b/build/rosetta.lua.linemap.json @@ -1,623 +1,623 @@ [ [671, "src/Rosetta/init.luau"], -[1588, "src/Rosetta/Registry.luau"], -[4205, "src/Rosetta/Sniffs.luau"], -[7591, "src/Rosetta/Types.luau"], -[8708, "src/Rosetta/archive/7z/init.luau"], -[9093, "src/Rosetta/archive/7z/Header.luau"], -[9620, "src/Rosetta/archive/adf/init.luau"], -[9902, "src/Rosetta/archive/applesingle/init.luau"], -[10088, "src/Rosetta/archive/ar/init.luau"], -[10491, "src/Rosetta/archive/arj/init.luau"], -[10701, "src/Rosetta/archive/binhex/init.luau"], -[10950, "src/Rosetta/archive/br/init.luau"], -[11025, "src/Rosetta/archive/bz2/init.luau"], -[11089, "src/Rosetta/archive/cab/init.luau"], -[11502, "src/Rosetta/archive/cab/Sum.luau"], -[11543, "src/Rosetta/archive/cpio/init.luau"], -[11711, "src/Rosetta/archive/d64/init.luau"], -[12125, "src/Rosetta/archive/fat/init.luau"], -[12247, "src/Rosetta/archive/grp/init.luau"], -[12361, "src/Rosetta/archive/gzip/init.luau"], -[12546, "src/Rosetta/archive/iso/init.luau"], -[12618, "src/Rosetta/archive/lha/init.luau"], -[13043, "src/Rosetta/archive/lz4/init.luau"], -[13387, "src/Rosetta/archive/macbinary/init.luau"], -[13585, "src/Rosetta/archive/mpq/init.luau"], -[13991, "src/Rosetta/archive/mpq/Crypt.luau"], -[14056, "src/Rosetta/archive/pak/init.luau"], -[14190, "src/Rosetta/archive/rpm/init.luau"], -[14514, "src/Rosetta/archive/tar/init.luau"], -[14632, "src/Rosetta/archive/unitypackage/init.luau"], -[14868, "src/Rosetta/archive/uu/init.luau"], -[15138, "src/Rosetta/archive/vpk/init.luau"], -[15449, "src/Rosetta/archive/vswap/init.luau"], -[15719, "src/Rosetta/archive/wad/init.luau"], -[16173, "src/Rosetta/archive/wad/Picture.luau"], -[16275, "src/Rosetta/archive/wad2/init.luau"], -[16557, "src/Rosetta/archive/xz/init.luau"], -[16657, "src/Rosetta/archive/yenc/init.luau"], -[16929, "src/Rosetta/archive/z/init.luau"], -[17025, "src/Rosetta/archive/zip/init.luau"], -[17244, "src/Rosetta/archive/zoo/init.luau"], -[17440, "src/Rosetta/archive/zst/init.luau"], -[17504, "src/Rosetta/audio/aac/init.luau"], -[17717, "src/Rosetta/audio/ac3/init.luau"], -[17864, "src/Rosetta/audio/adpcm/init.luau"], -[18010, "src/Rosetta/audio/adx/init.luau"], -[18242, "src/Rosetta/audio/aiff/init.luau"], -[18634, "src/Rosetta/audio/ape/init.luau"], -[18763, "src/Rosetta/audio/au/init.luau"], -[18925, "src/Rosetta/audio/brstm/init.luau"], -[19217, "src/Rosetta/audio/caf/init.luau"], -[19884, "src/Rosetta/audio/flac/init.luau"], -[20033, "src/Rosetta/audio/flac/Meta.luau"], -[20255, "src/Rosetta/audio/flac/Stream.luau"], -[20625, "src/Rosetta/audio/m4a/init.luau"], -[20968, "src/Rosetta/audio/mp3/init.luau"], -[21229, "src/Rosetta/audio/mp3/Index.luau"], -[21420, "src/Rosetta/audio/mp3/Stream.luau"], -[21647, "src/Rosetta/audio/mp3/Tags.luau"], -[21959, "src/Rosetta/audio/mpc/init.luau"], -[22054, "src/Rosetta/audio/opus/init.luau"], -[22433, "src/Rosetta/audio/opus/Encode.luau"], -[22545, "src/Rosetta/audio/qoa/init.luau"], -[22726, "src/Rosetta/audio/tta/init.luau"], -[22845, "src/Rosetta/audio/vag/init.luau"], -[23069, "src/Rosetta/audio/voc/init.luau"], -[23345, "src/Rosetta/audio/vorbis/init.luau"], -[23800, "src/Rosetta/audio/vorbis/Encode.luau"], -[24613, "src/Rosetta/audio/wav/init.luau"], -[25234, "src/Rosetta/audio/wav/Codecs.luau"], -[25413, "src/Rosetta/audio/wavpack/init.luau"], -[25621, "src/Rosetta/cad/step/init.luau"], -[26003, "src/Rosetta/cad/step/Brep.luau"], -[26238, "src/Rosetta/cad/step/Parse.luau"], -[26795, "src/Rosetta/cad/step/Write.luau"], -[27043, "src/Rosetta/codecs/audio/Aac/init.luau"], -[27451, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[28427, "src/Rosetta/codecs/audio/Aac/Ps.luau"], -[29017, "src/Rosetta/codecs/audio/Aac/Sbr.luau"], -[30084, "src/Rosetta/codecs/audio/Aac/SbrBits.luau"], -[30203, "src/Rosetta/codecs/audio/Aac/SbrDct.luau"], -[31445, "src/Rosetta/codecs/audio/Aac/SbrHf.luau"], -[31937, "src/Rosetta/codecs/audio/Aac/SbrQmf.luau"], -[32054, "src/Rosetta/codecs/audio/Aac/SbrTables.luau"], -[32467, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[32803, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[32963, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[33848, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[33950, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[34704, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[35007, "src/Rosetta/codecs/audio/Alac/init.luau"], -[35242, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[35661, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[36073, "src/Rosetta/codecs/audio/Ape/init.luau"], -[36289, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[37050, "src/Rosetta/codecs/audio/ApeTag.luau"], -[37148, "src/Rosetta/codecs/audio/Flac/init.luau"], -[37160, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[38109, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[38729, "src/Rosetta/codecs/audio/Hively/init.luau"], -[38926, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[39176, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[40135, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[40355, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[40575, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[40829, "src/Rosetta/codecs/audio/MidiRender.luau"], -[41176, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[41191, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[41250, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[42908, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[43201, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[43586, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[44227, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[44368, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[44595, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[44941, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[45835, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[46214, "src/Rosetta/codecs/audio/Opus/init.luau"], -[46229, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[48101, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[49166, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[49227, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[49691, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[50042, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[50275, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[52317, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[52691, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[52955, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[53252, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[53534, "src/Rosetta/codecs/audio/Resample/init.luau"], -[53929, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[53984, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[54128, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[54642, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[55441, "src/Rosetta/codecs/audio/Stream.luau"], -[55603, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[56086, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[56365, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[56612, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[56741, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[58730, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[58847, "src/Rosetta/codecs/audio/Tta/init.luau"], -[58965, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[59217, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[59231, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[59615, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[60188, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[60610, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[60650, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[60703, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[60926, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[62381, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[62444, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[62531, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[63507, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[64375, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[64419, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[64932, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[65345, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[65827, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[66348, "src/Rosetta/codecs/compress/Explode.luau"], -[66544, "src/Rosetta/codecs/compress/Lz4.luau"], -[66813, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[67417, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[67957, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[68024, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[68497, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[68673, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[68941, "src/Rosetta/codecs/compress/Lzx.luau"], -[69375, "src/Rosetta/codecs/compress/PackBits.luau"], -[69465, "src/Rosetta/codecs/compress/Quantum.luau"], -[69702, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[70006, "src/Rosetta/codecs/compress/Xxh32.luau"], -[70075, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[70132, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[71116, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[71268, "src/Rosetta/codecs/entropy/Huffman.luau"], -[71555, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[71566, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[71787, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[72031, "src/Rosetta/codecs/font/Bitmap.luau"], -[72232, "src/Rosetta/codecs/font/Cff/init.luau"], -[72873, "src/Rosetta/codecs/font/GlyphNames.luau"], -[73023, "src/Rosetta/codecs/font/TrueType/init.luau"], -[73337, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[73729, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[74231, "src/Rosetta/codecs/image/Bcn/init.luau"], -[74338, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[74822, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[75251, "src/Rosetta/codecs/image/Blend.luau"], -[75630, "src/Rosetta/codecs/image/Dct/init.luau"], -[76125, "src/Rosetta/codecs/image/Etc.luau"], -[76423, "src/Rosetta/codecs/image/Half.luau"], -[76492, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[76846, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[77254, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[77619, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[78384, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[79265, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[79742, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[79820, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[79887, "src/Rosetta/codecs/image/Miptex.luau"], -[80187, "src/Rosetta/codecs/image/Pixels.luau"], -[80507, "src/Rosetta/codecs/image/Quantize/init.luau"], -[80968, "src/Rosetta/codecs/image/Raster.luau"], -[81665, "src/Rosetta/codecs/image/Texel.luau"], -[82038, "src/Rosetta/codecs/image/Texture.luau"], -[82183, "src/Rosetta/codecs/image/Vp8/init.luau"], -[82325, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[84305, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[84568, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[84818, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[84960, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[85064, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[86004, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[86956, "src/Rosetta/codecs/image/Yuv.luau"], -[87277, "src/Rosetta/codecs/model/Brush.luau"], -[87917, "src/Rosetta/codecs/model/Displacement.luau"], -[88066, "src/Rosetta/codecs/model/DoomMap/init.luau"], -[88511, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], -[88761, "src/Rosetta/codecs/model/Draco/init.luau"], -[89093, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[89562, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[90751, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[90900, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[91259, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[92221, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[92695, "src/Rosetta/codecs/model/Mat4.luau"], -[92954, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[93482, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[94034, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[94113, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[94220, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[94426, "src/Rosetta/codecs/model/Patch.luau"], -[94550, "src/Rosetta/codecs/model/Polygon.luau"], -[94784, "src/Rosetta/codecs/model/Rbx/init.luau"], -[95021, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[95775, "src/Rosetta/codecs/model/Rig.luau"], -[96018, "src/Rosetta/codecs/model/Sampler.luau"], -[96178, "src/Rosetta/codecs/model/SourceAnim.luau"], -[96399, "src/Rosetta/codecs/model/Vrml/init.luau"], -[96547, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[97121, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[97284, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[98033, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[98555, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[99282, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[99514, "src/Rosetta/codecs/text/GodotVariant.luau"], -[100173, "src/Rosetta/codecs/text/Json/init.luau"], -[100442, "src/Rosetta/codecs/text/Json/Decode.luau"], -[100877, "src/Rosetta/codecs/text/Json/Encode.luau"], -[101222, "src/Rosetta/codecs/text/KeyValues/init.luau"], -[101792, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], -[102098, "src/Rosetta/codecs/text/Lexer/init.luau"], -[102230, "src/Rosetta/codecs/text/Nbt/init.luau"], -[102583, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[103275, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[103915, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[104153, "src/Rosetta/codecs/text/Text/init.luau"], -[104244, "src/Rosetta/codecs/text/Url/init.luau"], -[104449, "src/Rosetta/codecs/text/Xml/init.luau"], -[104899, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[105703, "src/Rosetta/codecs/video/Dsp.luau"], -[106541, "src/Rosetta/codecs/video/H263/init.luau"], -[106698, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[107556, "src/Rosetta/codecs/video/H263/Tables.luau"], -[107760, "src/Rosetta/codecs/video/H264/init.luau"], -[108150, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[108425, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[109556, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[110324, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[110586, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[111652, "src/Rosetta/codecs/video/H264/Inter.luau"], -[111978, "src/Rosetta/codecs/video/H264/Intra.luau"], -[112385, "src/Rosetta/codecs/video/H264/Mb.luau"], -[113339, "src/Rosetta/codecs/video/H264/Params.luau"], -[113787, "src/Rosetta/codecs/video/H264/Slice.luau"], -[114039, "src/Rosetta/codecs/video/H264/Tables.luau"], -[114081, "src/Rosetta/codecs/video/H264/Transform.luau"], -[114246, "src/Rosetta/codecs/video/Legacy/init.luau"], -[114445, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[114742, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[115109, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[115227, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[115335, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[115608, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[116003, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[116180, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[116193, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[116567, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[118094, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[118234, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[118373, "src/Rosetta/codecs/video/Theora/init.luau"], -[118637, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[119901, "src/Rosetta/codecs/video/Theora/Header.luau"], -[120265, "src/Rosetta/codecs/video/Video/init.luau"], -[120880, "src/Rosetta/codecs/video/Video/Disposable.luau"], -[121091, "src/Rosetta/codecs/video/Video/Pool.luau"], -[121143, "src/Rosetta/codecs/video/Video/Source.luau"], -[121429, "src/Rosetta/containers/Archive.luau"], -[121696, "src/Rosetta/containers/AudioWrap.luau"], -[122206, "src/Rosetta/containers/Avi/init.luau"], -[122759, "src/Rosetta/containers/Blend.luau"], -[123498, "src/Rosetta/containers/Chunks.luau"], -[123633, "src/Rosetta/containers/Cpio.luau"], -[124061, "src/Rosetta/containers/Demux.luau"], -[124347, "src/Rosetta/containers/Ebml/init.luau"], -[124661, "src/Rosetta/containers/Fat.luau"], -[125349, "src/Rosetta/containers/Iso9660.luau"], -[125854, "src/Rosetta/containers/IsoBmff/init.luau"], -[126025, "src/Rosetta/containers/IsoBmff/Box.luau"], -[126214, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[127060, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[127582, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[128099, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[128217, "src/Rosetta/containers/MacFile.luau"], -[128366, "src/Rosetta/containers/MpegEs.luau"], -[128533, "src/Rosetta/containers/MpegPs/init.luau"], -[128754, "src/Rosetta/containers/MpegTs/init.luau"], -[129547, "src/Rosetta/containers/Ogg/init.luau"], -[129972, "src/Rosetta/containers/Ogg/Mux.luau"], -[130161, "src/Rosetta/containers/Ogg/Page.luau"], -[130327, "src/Rosetta/containers/Riff/init.luau"], -[130644, "src/Rosetta/containers/Tar.luau"], -[131058, "src/Rosetta/containers/Zip/init.luau"], -[131690, "src/Rosetta/core/Adler32.luau"], -[131750, "src/Rosetta/core/Base64.luau"], -[131978, "src/Rosetta/core/Bits.luau"], -[132271, "src/Rosetta/core/Bytes.luau"], -[132798, "src/Rosetta/core/Crc16.luau"], -[132850, "src/Rosetta/core/Crc32.luau"], -[133001, "src/Rosetta/core/Err.luau"], -[133083, "src/Rosetta/core/Input.luau"], -[133159, "src/Rosetta/core/Md5.luau"], -[133317, "src/Rosetta/core/Sniff.luau"], -[133346, "src/Rosetta/data/cbor/init.luau"], -[133445, "src/Rosetta/data/cbor/Codec.luau"], -[134014, "src/Rosetta/data/csv/init.luau"], -[134326, "src/Rosetta/data/ini/init.luau"], -[134572, "src/Rosetta/data/json/init.luau"], -[134664, "src/Rosetta/data/msgpack/init.luau"], -[134753, "src/Rosetta/data/msgpack/Codec.luau"], -[135195, "src/Rosetta/data/nbt/init.luau"], -[135254, "src/Rosetta/data/plist/init.luau"], -[135560, "src/Rosetta/data/plist/Binary.luau"], -[135827, "src/Rosetta/data/q3shader/init.luau"], -[136066, "src/Rosetta/data/q3skin/init.luau"], -[136162, "src/Rosetta/data/snbt/init.luau"], -[136225, "src/Rosetta/data/toml/init.luau"], -[136292, "src/Rosetta/data/toml/Decode.luau"], -[136920, "src/Rosetta/data/toml/Encode.luau"], -[137129, "src/Rosetta/data/tres/init.luau"], -[137274, "src/Rosetta/data/vdf/init.luau"], -[137375, "src/Rosetta/data/xml/init.luau"], -[137431, "src/Rosetta/data/yaml/init.luau"], -[137504, "src/Rosetta/data/yaml/Emit.luau"], -[137794, "src/Rosetta/data/yaml/Parse.luau"], -[139087, "src/Rosetta/font/bdf/init.luau"], -[139376, "src/Rosetta/font/bmfont/init.luau"], -[139803, "src/Rosetta/font/bmfont/Parse.luau"], -[140256, "src/Rosetta/font/eot/init.luau"], -[140488, "src/Rosetta/font/fon/init.luau"], -[140771, "src/Rosetta/font/hershey/init.luau"], -[140966, "src/Rosetta/font/pcf/init.luau"], -[141246, "src/Rosetta/font/psf/init.luau"], -[141566, "src/Rosetta/font/ttf/init.luau"], -[141617, "src/Rosetta/font/type1/init.luau"], -[141976, "src/Rosetta/font/type1/Charstring.luau"], -[142254, "src/Rosetta/font/woff/init.luau"], -[142386, "src/Rosetta/font/woff2/init.luau"], -[142443, "src/Rosetta/font/woff2/Rebuild.luau"], -[142983, "src/Rosetta/host/init.luau"], -[143028, "src/Rosetta/host/Love.luau"], -[143171, "src/Rosetta/host/LuaJIT.luau"], -[143221, "src/Rosetta/host/Luau.luau"], -[143244, "src/Rosetta/host/Roblox.luau"], -[143603, "src/Rosetta/image/ani/init.luau"], -[143783, "src/Rosetta/image/art/init.luau"], -[144271, "src/Rosetta/image/blp/init.luau"], -[144529, "src/Rosetta/image/bmp/init.luau"], -[144944, "src/Rosetta/image/dds/init.luau"], -[145427, "src/Rosetta/image/exr/init.luau"], -[146187, "src/Rosetta/image/exr/Codec.luau"], -[146298, "src/Rosetta/image/exr/Piz.luau"], -[146655, "src/Rosetta/image/gif/init.luau"], -[147171, "src/Rosetta/image/gif/Decode.luau"], -[147247, "src/Rosetta/image/hdr/init.luau"], -[147476, "src/Rosetta/image/hdr/Codec.luau"], -[147687, "src/Rosetta/image/icns/init.luau"], -[148018, "src/Rosetta/image/ico/init.luau"], -[148295, "src/Rosetta/image/ico/Dib.luau"], -[148390, "src/Rosetta/image/ilbm/init.luau"], -[148709, "src/Rosetta/image/jpeg/init.luau"], -[148868, "src/Rosetta/image/ktx/init.luau"], -[149528, "src/Rosetta/image/lmp/init.luau"], -[149661, "src/Rosetta/image/pcx/init.luau"], -[149925, "src/Rosetta/image/png/init.luau"], -[150560, "src/Rosetta/image/png/Apng.luau"], -[150640, "src/Rosetta/image/png/Decode.luau"], -[151185, "src/Rosetta/image/png/Encode.luau"], -[151388, "src/Rosetta/image/pnm/init.luau"], -[151766, "src/Rosetta/image/pnm/Codec.luau"], -[152043, "src/Rosetta/image/qoi/init.luau"], -[152165, "src/Rosetta/image/qoi/Codec.luau"], -[152322, "src/Rosetta/image/sgi/init.luau"], -[152607, "src/Rosetta/image/spr/init.luau"], -[152920, "src/Rosetta/image/sunras/init.luau"], -[153166, "src/Rosetta/image/tga/init.luau"], -[153436, "src/Rosetta/image/tga/Codec.luau"], -[153636, "src/Rosetta/image/tiff/init.luau"], -[154463, "src/Rosetta/image/tiff/Pixels.luau"], -[154853, "src/Rosetta/image/tim/init.luau"], -[155095, "src/Rosetta/image/vtf/init.luau"], -[155330, "src/Rosetta/image/webp/init.luau"], -[155940, "src/Rosetta/image/webp/Alpha.luau"], -[156016, "src/Rosetta/image/webp/Anim.luau"], -[156171, "src/Rosetta/image/xbm/init.luau"], -[156332, "src/Rosetta/image/xpm/init.luau"], -[156600, "src/Rosetta/image/xpm/Names.luau"], -[156656, "src/Rosetta/layered/aseprite/init.luau"], -[157394, "src/Rosetta/layered/ora/init.luau"], -[157681, "src/Rosetta/layered/psd/init.luau"], -[158416, "src/Rosetta/layered/psd/Channels.luau"], -[158768, "src/Rosetta/model/3ds/init.luau"], -[158851, "src/Rosetta/model/3ds/Build.luau"], -[159498, "src/Rosetta/model/3ds/Read.luau"], -[159994, "src/Rosetta/model/3ds/Write.luau"], -[160799, "src/Rosetta/model/3mf/init.luau"], -[160881, "src/Rosetta/model/3mf/Read.luau"], -[161469, "src/Rosetta/model/3mf/Write.luau"], -[161874, "src/Rosetta/model/ase/init.luau"], -[161997, "src/Rosetta/model/ase/Build.luau"], -[162571, "src/Rosetta/model/ase/Parse.luau"], -[162640, "src/Rosetta/model/ase/Write.luau"], -[163103, "src/Rosetta/model/b3d/init.luau"], -[163158, "src/Rosetta/model/b3d/Read.luau"], -[163729, "src/Rosetta/model/blend/init.luau"], -[163829, "src/Rosetta/model/blend/Anim.luau"], -[164359, "src/Rosetta/model/blend/Armature.luau"], -[164895, "src/Rosetta/model/blend/Driver.luau"], -[165070, "src/Rosetta/model/blend/Material.luau"], -[165422, "src/Rosetta/model/blend/Mesh.luau"], -[166110, "src/Rosetta/model/blend/Normals.luau"], -[166271, "src/Rosetta/model/blend/Prim.luau"], -[166778, "src/Rosetta/model/blend/Read.luau"], -[167866, "src/Rosetta/model/bsp/init.luau"], -[168057, "src/Rosetta/model/bsp/Lightmap.luau"], -[168123, "src/Rosetta/model/bsp/Quake.luau"], -[168512, "src/Rosetta/model/bsp/Quake3.luau"], -[168741, "src/Rosetta/model/bsp/Tree.luau"], -[169129, "src/Rosetta/model/buildmap/init.luau"], -[169401, "src/Rosetta/model/buildmap/Geometry.luau"], -[169804, "src/Rosetta/model/d3map/init.luau"], -[170086, "src/Rosetta/model/d3map/Parse.luau"], -[170284, "src/Rosetta/model/dae/init.luau"], -[170473, "src/Rosetta/model/dae/Math.luau"], -[170520, "src/Rosetta/model/dae/Read.luau"], -[172370, "src/Rosetta/model/dae/Write.luau"], -[172739, "src/Rosetta/model/fbx/init.luau"], -[172887, "src/Rosetta/model/fbx/Ascii.luau"], -[173157, "src/Rosetta/model/fbx/Binary.luau"], -[173612, "src/Rosetta/model/fbx/Read.luau"], -[174974, "src/Rosetta/model/fbx/Write.luau"], -[175959, "src/Rosetta/model/fbx/Xform.luau"], -[176000, "src/Rosetta/model/gltf/init.luau"], -[176237, "src/Rosetta/model/gltf/Pack.luau"], -[176306, "src/Rosetta/model/gltf/Read.luau"], -[177047, "src/Rosetta/model/gltf/Write.luau"], -[177733, "src/Rosetta/model/godot/init.luau"], -[177824, "src/Rosetta/model/godot/Build.luau"], -[178366, "src/Rosetta/model/godot/Primitives.luau"], -[178641, "src/Rosetta/model/godot/Surface.luau"], -[179126, "src/Rosetta/model/godot/Write.luau"], -[179455, "src/Rosetta/model/iqm/init.luau"], -[179531, "src/Rosetta/model/iqm/Read.luau"], -[179886, "src/Rosetta/model/iqm/Write.luau"], -[180573, "src/Rosetta/model/ldraw/init.luau"], -[180651, "src/Rosetta/model/ldraw/Colors.luau"], -[180969, "src/Rosetta/model/ldraw/Read.luau"], -[181546, "src/Rosetta/model/lwo/init.luau"], -[181622, "src/Rosetta/model/lwo/Build.luau"], -[182084, "src/Rosetta/model/lwo/Parse.luau"], -[182627, "src/Rosetta/model/map/init.luau"], -[182944, "src/Rosetta/model/map/Build.luau"], -[183188, "src/Rosetta/model/map/Parse.luau"], -[183573, "src/Rosetta/model/map/Write.luau"], -[183719, "src/Rosetta/model/mca/init.luau"], -[184061, "src/Rosetta/model/mca/Chunk.luau"], -[184194, "src/Rosetta/model/mca/Lz4Block.luau"], -[184264, "src/Rosetta/model/md2/init.luau"], -[184463, "src/Rosetta/model/md3/init.luau"], -[184691, "src/Rosetta/model/md5/init.luau"], -[184772, "src/Rosetta/model/md5/Read.luau"], -[185205, "src/Rosetta/model/mdl/init.luau"], -[185287, "src/Rosetta/model/mdl/HalfLife.luau"], -[185591, "src/Rosetta/model/mdl/Quake.luau"], -[185809, "src/Rosetta/model/ms3d/init.luau"], -[185881, "src/Rosetta/model/ms3d/Read.luau"], -[186327, "src/Rosetta/model/ms3d/Write.luau"], -[186796, "src/Rosetta/model/obj/init.luau"], -[187614, "src/Rosetta/model/obj/Mtl.luau"], -[187902, "src/Rosetta/model/off/init.luau"], -[188364, "src/Rosetta/model/ply/init.luau"], -[189469, "src/Rosetta/model/ply/Binary.luau"], -[189670, "src/Rosetta/model/pmx/init.luau"], -[189739, "src/Rosetta/model/pmx/Build.luau"], -[190035, "src/Rosetta/model/pmx/Pmd.luau"], -[190370, "src/Rosetta/model/pmx/Read.luau"], -[190774, "src/Rosetta/model/proc/init.luau"], -[191156, "src/Rosetta/model/qb/init.luau"], -[191549, "src/Rosetta/model/rbxm/init.luau"], -[192142, "src/Rosetta/model/rbxmx/init.luau"], -[192818, "src/Rosetta/model/robloxmesh/init.luau"], -[193477, "src/Rosetta/model/robloxmesh/Parse.luau"], -[193934, "src/Rosetta/model/robloxmesh/Write.luau"], -[194043, "src/Rosetta/model/schematic/init.luau"], -[194364, "src/Rosetta/model/schematic/Common.luau"], -[194484, "src/Rosetta/model/schematic/Litematic.luau"], -[194695, "src/Rosetta/model/schematic/Mcedit.luau"], -[194939, "src/Rosetta/model/schematic/Sponge.luau"], -[195068, "src/Rosetta/model/smd/init.luau"], -[195135, "src/Rosetta/model/smd/Read.luau"], -[195404, "src/Rosetta/model/smd/Write.luau"], -[195647, "src/Rosetta/model/sourcemdl/init.luau"], -[195818, "src/Rosetta/model/sourcemdl/Build.luau"], -[196248, "src/Rosetta/model/sourcemdl/Material.luau"], -[196409, "src/Rosetta/model/sourcemdl/Mdl.luau"], -[196936, "src/Rosetta/model/sourcemdl/Phy.luau"], -[197059, "src/Rosetta/model/sourcemdl/Vtx.luau"], -[197241, "src/Rosetta/model/sourcemdl/Vvd.luau"], -[197335, "src/Rosetta/model/stl/init.luau"], -[197785, "src/Rosetta/model/stl/Decode.luau"], -[197859, "src/Rosetta/model/t3d/init.luau"], -[197953, "src/Rosetta/model/t3d/Build.luau"], -[198358, "src/Rosetta/model/t3d/Parse.luau"], -[198526, "src/Rosetta/model/udmf/init.luau"], -[198609, "src/Rosetta/model/usda/init.luau"], -[198818, "src/Rosetta/model/usda/Build.luau"], -[200096, "src/Rosetta/model/usda/Parse.luau"], -[200894, "src/Rosetta/model/usda/Write.luau"], -[201711, "src/Rosetta/model/vbsp/init.luau"], -[202157, "src/Rosetta/model/vbsp/Faces.luau"], -[202381, "src/Rosetta/model/vbsp/Props.luau"], -[202473, "src/Rosetta/model/vmf/init.luau"], -[202798, "src/Rosetta/model/vmf/Build.luau"], -[203222, "src/Rosetta/model/vox/init.luau"], -[204108, "src/Rosetta/model/vox/Grid.luau"], -[204165, "src/Rosetta/model/vrml/init.luau"], -[204231, "src/Rosetta/model/x/init.luau"], -[204361, "src/Rosetta/model/x/Build.luau"], -[204924, "src/Rosetta/model/x/Parse.luau"], -[205221, "src/Rosetta/model/x3d/init.luau"], -[205299, "src/Rosetta/music/669/init.luau"], -[205506, "src/Rosetta/music/ahx/init.luau"], -[205558, "src/Rosetta/music/far/init.luau"], -[205788, "src/Rosetta/music/hmp/init.luau"], -[206053, "src/Rosetta/music/hvl/init.luau"], -[206105, "src/Rosetta/music/it/init.luau"], -[206524, "src/Rosetta/music/it/Itsex.luau"], -[206641, "src/Rosetta/music/med/init.luau"], -[207289, "src/Rosetta/music/midi/init.luau"], -[207433, "src/Rosetta/music/midi/Smf.luau"], -[207845, "src/Rosetta/music/mod/init.luau"], -[208199, "src/Rosetta/music/mtm/init.luau"], -[208422, "src/Rosetta/music/mus/init.luau"], -[208580, "src/Rosetta/music/okt/init.luau"], -[208862, "src/Rosetta/music/ptm/init.luau"], -[209085, "src/Rosetta/music/s3m/init.luau"], -[209322, "src/Rosetta/music/sf2/init.luau"], -[209366, "src/Rosetta/music/stm/init.luau"], -[209598, "src/Rosetta/music/ult/init.luau"], -[209903, "src/Rosetta/music/umx/init.luau"], -[210120, "src/Rosetta/music/xm/init.luau"], -[210682, "src/Rosetta/music/xmi/init.luau"], -[210891, "src/Rosetta/ops/AudioOps.luau"], -[211370, "src/Rosetta/ops/ImageOps/init.luau"], -[212018, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[212658, "src/Rosetta/ops/LayerOps.luau"], -[212751, "src/Rosetta/ops/MeshOps/init.luau"], -[213891, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[214058, "src/Rosetta/ops/MusicOps.luau"], -[214407, "src/Rosetta/playlist/m3u/init.luau"], -[214760, "src/Rosetta/playlist/pls/init.luau"], -[214938, "src/Rosetta/playlist/xspf/init.luau"], -[215141, "src/Rosetta/subtitle/ass/init.luau"], -[215585, "src/Rosetta/subtitle/srt/init.luau"], -[215758, "src/Rosetta/subtitle/vtt/init.luau"], -[215961, "src/Rosetta/vector/gamemaps/init.luau"], -[216148, "src/Rosetta/vector/gamemaps/Expand.luau"], -[216245, "src/Rosetta/vector/ldtk/init.luau"], -[216337, "src/Rosetta/vector/ldtk/Read.luau"], -[216673, "src/Rosetta/vector/ldtk/Write.luau"], -[217321, "src/Rosetta/vector/ogmo/init.luau"], -[217440, "src/Rosetta/vector/ogmo/Read.luau"], -[217845, "src/Rosetta/vector/ogmo/Write.luau"], -[218199, "src/Rosetta/vector/svg/init.luau"], -[218285, "src/Rosetta/vector/svg/Parse.luau"], -[219031, "src/Rosetta/vector/svg/PathData.luau"], -[219399, "src/Rosetta/vector/svg/Render.luau"], -[219816, "src/Rosetta/vector/svg/Style.luau"], -[220188, "src/Rosetta/vector/svg/Write.luau"], -[220388, "src/Rosetta/vector/tiled/init.luau"], -[220568, "src/Rosetta/vector/tiled/Data.luau"], -[220719, "src/Rosetta/vector/tiled/Tmj.luau"], -[221350, "src/Rosetta/vector/tiled/Tmx.luau"], -[221962, "src/Rosetta/video/avi/init.luau"], -[222256, "src/Rosetta/video/fli/init.luau"], -[222407, "src/Rosetta/video/flv/init.luau"], -[222791, "src/Rosetta/video/flv/Amf.luau"], -[222949, "src/Rosetta/video/flv/Mux.luau"], -[223230, "src/Rosetta/video/h264/init.luau"], -[223369, "src/Rosetta/video/mkv/init.luau"], -[223525, "src/Rosetta/video/mkv/Mux.luau"], -[223804, "src/Rosetta/video/mkv/Parse.luau"], -[224525, "src/Rosetta/video/mp4/init.luau"], -[224853, "src/Rosetta/video/mpegps/init.luau"], -[225040, "src/Rosetta/video/mpegts/init.luau"], -[225286, "src/Rosetta/video/ogv/init.luau"], -[225681, "src/Rosetta/video/smk/init.luau"], -[225990, "src/Rosetta/video/smk/Audio.luau"], -[226110, "src/Rosetta/video/y4m/init.luau"] +[1604, "src/Rosetta/Registry.luau"], +[4221, "src/Rosetta/Sniffs.luau"], +[8452, "src/Rosetta/Types.luau"], +[9569, "src/Rosetta/archive/7z/init.luau"], +[9954, "src/Rosetta/archive/7z/Header.luau"], +[10481, "src/Rosetta/archive/adf/init.luau"], +[10763, "src/Rosetta/archive/applesingle/init.luau"], +[10949, "src/Rosetta/archive/ar/init.luau"], +[11352, "src/Rosetta/archive/arj/init.luau"], +[11562, "src/Rosetta/archive/binhex/init.luau"], +[11811, "src/Rosetta/archive/br/init.luau"], +[11886, "src/Rosetta/archive/bz2/init.luau"], +[11950, "src/Rosetta/archive/cab/init.luau"], +[12363, "src/Rosetta/archive/cab/Sum.luau"], +[12404, "src/Rosetta/archive/cpio/init.luau"], +[12572, "src/Rosetta/archive/d64/init.luau"], +[12986, "src/Rosetta/archive/fat/init.luau"], +[13108, "src/Rosetta/archive/grp/init.luau"], +[13222, "src/Rosetta/archive/gzip/init.luau"], +[13407, "src/Rosetta/archive/iso/init.luau"], +[13479, "src/Rosetta/archive/lha/init.luau"], +[13904, "src/Rosetta/archive/lz4/init.luau"], +[14248, "src/Rosetta/archive/macbinary/init.luau"], +[14446, "src/Rosetta/archive/mpq/init.luau"], +[14852, "src/Rosetta/archive/mpq/Crypt.luau"], +[14917, "src/Rosetta/archive/pak/init.luau"], +[15051, "src/Rosetta/archive/rpm/init.luau"], +[15375, "src/Rosetta/archive/tar/init.luau"], +[15493, "src/Rosetta/archive/unitypackage/init.luau"], +[15729, "src/Rosetta/archive/uu/init.luau"], +[15999, "src/Rosetta/archive/vpk/init.luau"], +[16310, "src/Rosetta/archive/vswap/init.luau"], +[16580, "src/Rosetta/archive/wad/init.luau"], +[17034, "src/Rosetta/archive/wad/Picture.luau"], +[17136, "src/Rosetta/archive/wad2/init.luau"], +[17418, "src/Rosetta/archive/xz/init.luau"], +[17518, "src/Rosetta/archive/yenc/init.luau"], +[17790, "src/Rosetta/archive/z/init.luau"], +[17886, "src/Rosetta/archive/zip/init.luau"], +[18105, "src/Rosetta/archive/zoo/init.luau"], +[18301, "src/Rosetta/archive/zst/init.luau"], +[18365, "src/Rosetta/audio/aac/init.luau"], +[18578, "src/Rosetta/audio/ac3/init.luau"], +[18725, "src/Rosetta/audio/adpcm/init.luau"], +[18871, "src/Rosetta/audio/adx/init.luau"], +[19103, "src/Rosetta/audio/aiff/init.luau"], +[19495, "src/Rosetta/audio/ape/init.luau"], +[19624, "src/Rosetta/audio/au/init.luau"], +[19786, "src/Rosetta/audio/brstm/init.luau"], +[20078, "src/Rosetta/audio/caf/init.luau"], +[20745, "src/Rosetta/audio/flac/init.luau"], +[20894, "src/Rosetta/audio/flac/Meta.luau"], +[21116, "src/Rosetta/audio/flac/Stream.luau"], +[21486, "src/Rosetta/audio/m4a/init.luau"], +[21829, "src/Rosetta/audio/mp3/init.luau"], +[22090, "src/Rosetta/audio/mp3/Index.luau"], +[22281, "src/Rosetta/audio/mp3/Stream.luau"], +[22508, "src/Rosetta/audio/mp3/Tags.luau"], +[22820, "src/Rosetta/audio/mpc/init.luau"], +[22915, "src/Rosetta/audio/opus/init.luau"], +[23294, "src/Rosetta/audio/opus/Encode.luau"], +[23406, "src/Rosetta/audio/qoa/init.luau"], +[23587, "src/Rosetta/audio/tta/init.luau"], +[23706, "src/Rosetta/audio/vag/init.luau"], +[23930, "src/Rosetta/audio/voc/init.luau"], +[24206, "src/Rosetta/audio/vorbis/init.luau"], +[24661, "src/Rosetta/audio/vorbis/Encode.luau"], +[25474, "src/Rosetta/audio/wav/init.luau"], +[26095, "src/Rosetta/audio/wav/Codecs.luau"], +[26274, "src/Rosetta/audio/wavpack/init.luau"], +[26482, "src/Rosetta/cad/step/init.luau"], +[26864, "src/Rosetta/cad/step/Brep.luau"], +[27099, "src/Rosetta/cad/step/Parse.luau"], +[27656, "src/Rosetta/cad/step/Write.luau"], +[27904, "src/Rosetta/codecs/audio/Aac/init.luau"], +[28312, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[29288, "src/Rosetta/codecs/audio/Aac/Ps.luau"], +[29878, "src/Rosetta/codecs/audio/Aac/Sbr.luau"], +[30945, "src/Rosetta/codecs/audio/Aac/SbrBits.luau"], +[31064, "src/Rosetta/codecs/audio/Aac/SbrDct.luau"], +[32306, "src/Rosetta/codecs/audio/Aac/SbrHf.luau"], +[32798, "src/Rosetta/codecs/audio/Aac/SbrQmf.luau"], +[32915, "src/Rosetta/codecs/audio/Aac/SbrTables.luau"], +[33328, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[33664, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[33824, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[34709, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[34811, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[35565, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[35868, "src/Rosetta/codecs/audio/Alac/init.luau"], +[36103, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[36522, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[36934, "src/Rosetta/codecs/audio/Ape/init.luau"], +[37150, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[37911, "src/Rosetta/codecs/audio/ApeTag.luau"], +[38009, "src/Rosetta/codecs/audio/Flac/init.luau"], +[38021, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[38970, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[39590, "src/Rosetta/codecs/audio/Hively/init.luau"], +[39787, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[40037, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[40996, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[41216, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[41436, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[41690, "src/Rosetta/codecs/audio/MidiRender.luau"], +[42037, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[42052, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[42111, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[43769, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[44062, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[44447, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[45088, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[45229, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[45456, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[45802, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[46696, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[47075, "src/Rosetta/codecs/audio/Opus/init.luau"], +[47090, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[48962, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[50027, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[50088, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[50552, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[50903, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[51136, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[53178, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[53552, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[53816, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[54113, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[54395, "src/Rosetta/codecs/audio/Resample/init.luau"], +[54790, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[54845, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[54989, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[55503, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[56302, "src/Rosetta/codecs/audio/Stream.luau"], +[56464, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[56947, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[57226, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[57473, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[57602, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[59591, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[59708, "src/Rosetta/codecs/audio/Tta/init.luau"], +[59826, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[60078, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[60092, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[60476, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[61049, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[61471, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[61511, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[61564, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[61787, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[63242, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[63305, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[63404, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[64388, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[65256, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[65300, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[65813, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[66226, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[66708, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[67229, "src/Rosetta/codecs/compress/Explode.luau"], +[67425, "src/Rosetta/codecs/compress/Lz4.luau"], +[67694, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[68298, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[68838, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[68905, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[69378, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[69554, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[69822, "src/Rosetta/codecs/compress/Lzx.luau"], +[70256, "src/Rosetta/codecs/compress/PackBits.luau"], +[70346, "src/Rosetta/codecs/compress/Quantum.luau"], +[70583, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[70887, "src/Rosetta/codecs/compress/Xxh32.luau"], +[70956, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[71013, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[71997, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[72149, "src/Rosetta/codecs/entropy/Huffman.luau"], +[72436, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[72447, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[72668, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[72912, "src/Rosetta/codecs/font/Bitmap.luau"], +[73113, "src/Rosetta/codecs/font/Cff/init.luau"], +[73754, "src/Rosetta/codecs/font/GlyphNames.luau"], +[73904, "src/Rosetta/codecs/font/TrueType/init.luau"], +[74218, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[74610, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[75112, "src/Rosetta/codecs/image/Bcn/init.luau"], +[75219, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[75703, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[76132, "src/Rosetta/codecs/image/Blend.luau"], +[76511, "src/Rosetta/codecs/image/Dct/init.luau"], +[77006, "src/Rosetta/codecs/image/Etc.luau"], +[77304, "src/Rosetta/codecs/image/Half.luau"], +[77373, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[77727, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[78135, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[78500, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[79265, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[80146, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[80623, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[80701, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[80768, "src/Rosetta/codecs/image/Miptex.luau"], +[81068, "src/Rosetta/codecs/image/Pixels.luau"], +[81388, "src/Rosetta/codecs/image/Quantize/init.luau"], +[81849, "src/Rosetta/codecs/image/Raster.luau"], +[82546, "src/Rosetta/codecs/image/Texel.luau"], +[82919, "src/Rosetta/codecs/image/Texture.luau"], +[83064, "src/Rosetta/codecs/image/Vp8/init.luau"], +[83206, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[85186, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[85449, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[85699, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[85841, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[85945, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[86885, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[87837, "src/Rosetta/codecs/image/Yuv.luau"], +[88158, "src/Rosetta/codecs/model/Brush.luau"], +[88798, "src/Rosetta/codecs/model/Displacement.luau"], +[88947, "src/Rosetta/codecs/model/DoomMap/init.luau"], +[89392, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], +[89642, "src/Rosetta/codecs/model/Draco/init.luau"], +[89974, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[90443, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[91632, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[91781, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[92140, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[93102, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[93576, "src/Rosetta/codecs/model/Mat4.luau"], +[93835, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[94363, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[94915, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[94994, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[95101, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[95307, "src/Rosetta/codecs/model/Patch.luau"], +[95431, "src/Rosetta/codecs/model/Polygon.luau"], +[95665, "src/Rosetta/codecs/model/Rbx/init.luau"], +[95902, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[96656, "src/Rosetta/codecs/model/Rig.luau"], +[96899, "src/Rosetta/codecs/model/Sampler.luau"], +[97059, "src/Rosetta/codecs/model/SourceAnim.luau"], +[97280, "src/Rosetta/codecs/model/Vrml/init.luau"], +[97428, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[98002, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[98165, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[98914, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[99436, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[100163, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[100395, "src/Rosetta/codecs/text/GodotVariant.luau"], +[101054, "src/Rosetta/codecs/text/Json/init.luau"], +[101323, "src/Rosetta/codecs/text/Json/Decode.luau"], +[101758, "src/Rosetta/codecs/text/Json/Encode.luau"], +[102103, "src/Rosetta/codecs/text/KeyValues/init.luau"], +[102673, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], +[102979, "src/Rosetta/codecs/text/Lexer/init.luau"], +[103111, "src/Rosetta/codecs/text/Nbt/init.luau"], +[103464, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[104156, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[104796, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[105034, "src/Rosetta/codecs/text/Text/init.luau"], +[105125, "src/Rosetta/codecs/text/Url/init.luau"], +[105330, "src/Rosetta/codecs/text/Xml/init.luau"], +[105780, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[106584, "src/Rosetta/codecs/video/Dsp.luau"], +[107422, "src/Rosetta/codecs/video/H263/init.luau"], +[107579, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[108437, "src/Rosetta/codecs/video/H263/Tables.luau"], +[108641, "src/Rosetta/codecs/video/H264/init.luau"], +[109031, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[109306, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[110437, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[111205, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[111467, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[112533, "src/Rosetta/codecs/video/H264/Inter.luau"], +[112859, "src/Rosetta/codecs/video/H264/Intra.luau"], +[113266, "src/Rosetta/codecs/video/H264/Mb.luau"], +[114220, "src/Rosetta/codecs/video/H264/Params.luau"], +[114668, "src/Rosetta/codecs/video/H264/Slice.luau"], +[114920, "src/Rosetta/codecs/video/H264/Tables.luau"], +[114962, "src/Rosetta/codecs/video/H264/Transform.luau"], +[115127, "src/Rosetta/codecs/video/Legacy/init.luau"], +[115326, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[115623, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[115990, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[116108, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[116216, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[116489, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[116884, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[117061, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[117074, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[117448, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[118975, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[119115, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[119254, "src/Rosetta/codecs/video/Theora/init.luau"], +[119518, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[120782, "src/Rosetta/codecs/video/Theora/Header.luau"], +[121146, "src/Rosetta/codecs/video/Video/init.luau"], +[121761, "src/Rosetta/codecs/video/Video/Disposable.luau"], +[121972, "src/Rosetta/codecs/video/Video/Pool.luau"], +[122024, "src/Rosetta/codecs/video/Video/Source.luau"], +[122310, "src/Rosetta/containers/Archive.luau"], +[122577, "src/Rosetta/containers/AudioWrap.luau"], +[123087, "src/Rosetta/containers/Avi/init.luau"], +[123640, "src/Rosetta/containers/Blend.luau"], +[124379, "src/Rosetta/containers/Chunks.luau"], +[124514, "src/Rosetta/containers/Cpio.luau"], +[124942, "src/Rosetta/containers/Demux.luau"], +[125228, "src/Rosetta/containers/Ebml/init.luau"], +[125542, "src/Rosetta/containers/Fat.luau"], +[126230, "src/Rosetta/containers/Iso9660.luau"], +[126735, "src/Rosetta/containers/IsoBmff/init.luau"], +[126906, "src/Rosetta/containers/IsoBmff/Box.luau"], +[127095, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[127941, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[128463, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[128980, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[129098, "src/Rosetta/containers/MacFile.luau"], +[129247, "src/Rosetta/containers/MpegEs.luau"], +[129414, "src/Rosetta/containers/MpegPs/init.luau"], +[129635, "src/Rosetta/containers/MpegTs/init.luau"], +[130428, "src/Rosetta/containers/Ogg/init.luau"], +[130853, "src/Rosetta/containers/Ogg/Mux.luau"], +[131042, "src/Rosetta/containers/Ogg/Page.luau"], +[131208, "src/Rosetta/containers/Riff/init.luau"], +[131525, "src/Rosetta/containers/Tar.luau"], +[131939, "src/Rosetta/containers/Zip/init.luau"], +[132571, "src/Rosetta/core/Adler32.luau"], +[132631, "src/Rosetta/core/Base64.luau"], +[132859, "src/Rosetta/core/Bits.luau"], +[133152, "src/Rosetta/core/Bytes.luau"], +[133679, "src/Rosetta/core/Crc16.luau"], +[133731, "src/Rosetta/core/Crc32.luau"], +[133882, "src/Rosetta/core/Err.luau"], +[133964, "src/Rosetta/core/Input.luau"], +[134040, "src/Rosetta/core/Md5.luau"], +[134198, "src/Rosetta/core/Sniff.luau"], +[134227, "src/Rosetta/data/cbor/init.luau"], +[134326, "src/Rosetta/data/cbor/Codec.luau"], +[134895, "src/Rosetta/data/csv/init.luau"], +[135207, "src/Rosetta/data/ini/init.luau"], +[135453, "src/Rosetta/data/json/init.luau"], +[135545, "src/Rosetta/data/msgpack/init.luau"], +[135634, "src/Rosetta/data/msgpack/Codec.luau"], +[136076, "src/Rosetta/data/nbt/init.luau"], +[136135, "src/Rosetta/data/plist/init.luau"], +[136441, "src/Rosetta/data/plist/Binary.luau"], +[136708, "src/Rosetta/data/q3shader/init.luau"], +[136947, "src/Rosetta/data/q3skin/init.luau"], +[137043, "src/Rosetta/data/snbt/init.luau"], +[137106, "src/Rosetta/data/toml/init.luau"], +[137173, "src/Rosetta/data/toml/Decode.luau"], +[137801, "src/Rosetta/data/toml/Encode.luau"], +[138010, "src/Rosetta/data/tres/init.luau"], +[138155, "src/Rosetta/data/vdf/init.luau"], +[138256, "src/Rosetta/data/xml/init.luau"], +[138312, "src/Rosetta/data/yaml/init.luau"], +[138385, "src/Rosetta/data/yaml/Emit.luau"], +[138675, "src/Rosetta/data/yaml/Parse.luau"], +[139968, "src/Rosetta/font/bdf/init.luau"], +[140257, "src/Rosetta/font/bmfont/init.luau"], +[140684, "src/Rosetta/font/bmfont/Parse.luau"], +[141137, "src/Rosetta/font/eot/init.luau"], +[141369, "src/Rosetta/font/fon/init.luau"], +[141652, "src/Rosetta/font/hershey/init.luau"], +[141847, "src/Rosetta/font/pcf/init.luau"], +[142127, "src/Rosetta/font/psf/init.luau"], +[142447, "src/Rosetta/font/ttf/init.luau"], +[142498, "src/Rosetta/font/type1/init.luau"], +[142857, "src/Rosetta/font/type1/Charstring.luau"], +[143135, "src/Rosetta/font/woff/init.luau"], +[143267, "src/Rosetta/font/woff2/init.luau"], +[143324, "src/Rosetta/font/woff2/Rebuild.luau"], +[143864, "src/Rosetta/host/init.luau"], +[143909, "src/Rosetta/host/Love.luau"], +[144052, "src/Rosetta/host/LuaJIT.luau"], +[144102, "src/Rosetta/host/Luau.luau"], +[144125, "src/Rosetta/host/Roblox.luau"], +[144484, "src/Rosetta/image/ani/init.luau"], +[144664, "src/Rosetta/image/art/init.luau"], +[145152, "src/Rosetta/image/blp/init.luau"], +[145410, "src/Rosetta/image/bmp/init.luau"], +[145825, "src/Rosetta/image/dds/init.luau"], +[146308, "src/Rosetta/image/exr/init.luau"], +[147068, "src/Rosetta/image/exr/Codec.luau"], +[147179, "src/Rosetta/image/exr/Piz.luau"], +[147536, "src/Rosetta/image/gif/init.luau"], +[148052, "src/Rosetta/image/gif/Decode.luau"], +[148128, "src/Rosetta/image/hdr/init.luau"], +[148357, "src/Rosetta/image/hdr/Codec.luau"], +[148568, "src/Rosetta/image/icns/init.luau"], +[148899, "src/Rosetta/image/ico/init.luau"], +[149176, "src/Rosetta/image/ico/Dib.luau"], +[149271, "src/Rosetta/image/ilbm/init.luau"], +[149590, "src/Rosetta/image/jpeg/init.luau"], +[149749, "src/Rosetta/image/ktx/init.luau"], +[150409, "src/Rosetta/image/lmp/init.luau"], +[150542, "src/Rosetta/image/pcx/init.luau"], +[150806, "src/Rosetta/image/png/init.luau"], +[151441, "src/Rosetta/image/png/Apng.luau"], +[151521, "src/Rosetta/image/png/Decode.luau"], +[152066, "src/Rosetta/image/png/Encode.luau"], +[152269, "src/Rosetta/image/pnm/init.luau"], +[152647, "src/Rosetta/image/pnm/Codec.luau"], +[152924, "src/Rosetta/image/qoi/init.luau"], +[153046, "src/Rosetta/image/qoi/Codec.luau"], +[153203, "src/Rosetta/image/sgi/init.luau"], +[153488, "src/Rosetta/image/spr/init.luau"], +[153801, "src/Rosetta/image/sunras/init.luau"], +[154047, "src/Rosetta/image/tga/init.luau"], +[154317, "src/Rosetta/image/tga/Codec.luau"], +[154517, "src/Rosetta/image/tiff/init.luau"], +[155344, "src/Rosetta/image/tiff/Pixels.luau"], +[155734, "src/Rosetta/image/tim/init.luau"], +[155976, "src/Rosetta/image/vtf/init.luau"], +[156211, "src/Rosetta/image/webp/init.luau"], +[156821, "src/Rosetta/image/webp/Alpha.luau"], +[156897, "src/Rosetta/image/webp/Anim.luau"], +[157052, "src/Rosetta/image/xbm/init.luau"], +[157213, "src/Rosetta/image/xpm/init.luau"], +[157481, "src/Rosetta/image/xpm/Names.luau"], +[157537, "src/Rosetta/layered/aseprite/init.luau"], +[158275, "src/Rosetta/layered/ora/init.luau"], +[158562, "src/Rosetta/layered/psd/init.luau"], +[159297, "src/Rosetta/layered/psd/Channels.luau"], +[159649, "src/Rosetta/model/3ds/init.luau"], +[159732, "src/Rosetta/model/3ds/Build.luau"], +[160379, "src/Rosetta/model/3ds/Read.luau"], +[160875, "src/Rosetta/model/3ds/Write.luau"], +[161680, "src/Rosetta/model/3mf/init.luau"], +[161762, "src/Rosetta/model/3mf/Read.luau"], +[162350, "src/Rosetta/model/3mf/Write.luau"], +[162755, "src/Rosetta/model/ase/init.luau"], +[162878, "src/Rosetta/model/ase/Build.luau"], +[163452, "src/Rosetta/model/ase/Parse.luau"], +[163521, "src/Rosetta/model/ase/Write.luau"], +[163984, "src/Rosetta/model/b3d/init.luau"], +[164039, "src/Rosetta/model/b3d/Read.luau"], +[164610, "src/Rosetta/model/blend/init.luau"], +[164710, "src/Rosetta/model/blend/Anim.luau"], +[165240, "src/Rosetta/model/blend/Armature.luau"], +[165776, "src/Rosetta/model/blend/Driver.luau"], +[165951, "src/Rosetta/model/blend/Material.luau"], +[166303, "src/Rosetta/model/blend/Mesh.luau"], +[166991, "src/Rosetta/model/blend/Normals.luau"], +[167152, "src/Rosetta/model/blend/Prim.luau"], +[167659, "src/Rosetta/model/blend/Read.luau"], +[168747, "src/Rosetta/model/bsp/init.luau"], +[168938, "src/Rosetta/model/bsp/Lightmap.luau"], +[169004, "src/Rosetta/model/bsp/Quake.luau"], +[169393, "src/Rosetta/model/bsp/Quake3.luau"], +[169622, "src/Rosetta/model/bsp/Tree.luau"], +[170010, "src/Rosetta/model/buildmap/init.luau"], +[170282, "src/Rosetta/model/buildmap/Geometry.luau"], +[170685, "src/Rosetta/model/d3map/init.luau"], +[170967, "src/Rosetta/model/d3map/Parse.luau"], +[171165, "src/Rosetta/model/dae/init.luau"], +[171354, "src/Rosetta/model/dae/Math.luau"], +[171401, "src/Rosetta/model/dae/Read.luau"], +[173251, "src/Rosetta/model/dae/Write.luau"], +[173620, "src/Rosetta/model/fbx/init.luau"], +[173768, "src/Rosetta/model/fbx/Ascii.luau"], +[174038, "src/Rosetta/model/fbx/Binary.luau"], +[174493, "src/Rosetta/model/fbx/Read.luau"], +[175855, "src/Rosetta/model/fbx/Write.luau"], +[176840, "src/Rosetta/model/fbx/Xform.luau"], +[176881, "src/Rosetta/model/gltf/init.luau"], +[177118, "src/Rosetta/model/gltf/Pack.luau"], +[177187, "src/Rosetta/model/gltf/Read.luau"], +[177928, "src/Rosetta/model/gltf/Write.luau"], +[178614, "src/Rosetta/model/godot/init.luau"], +[178705, "src/Rosetta/model/godot/Build.luau"], +[179247, "src/Rosetta/model/godot/Primitives.luau"], +[179522, "src/Rosetta/model/godot/Surface.luau"], +[180007, "src/Rosetta/model/godot/Write.luau"], +[180336, "src/Rosetta/model/iqm/init.luau"], +[180412, "src/Rosetta/model/iqm/Read.luau"], +[180767, "src/Rosetta/model/iqm/Write.luau"], +[181454, "src/Rosetta/model/ldraw/init.luau"], +[181532, "src/Rosetta/model/ldraw/Colors.luau"], +[181850, "src/Rosetta/model/ldraw/Read.luau"], +[182427, "src/Rosetta/model/lwo/init.luau"], +[182503, "src/Rosetta/model/lwo/Build.luau"], +[182965, "src/Rosetta/model/lwo/Parse.luau"], +[183508, "src/Rosetta/model/map/init.luau"], +[183825, "src/Rosetta/model/map/Build.luau"], +[184069, "src/Rosetta/model/map/Parse.luau"], +[184454, "src/Rosetta/model/map/Write.luau"], +[184600, "src/Rosetta/model/mca/init.luau"], +[184942, "src/Rosetta/model/mca/Chunk.luau"], +[185075, "src/Rosetta/model/mca/Lz4Block.luau"], +[185145, "src/Rosetta/model/md2/init.luau"], +[185344, "src/Rosetta/model/md3/init.luau"], +[185572, "src/Rosetta/model/md5/init.luau"], +[185653, "src/Rosetta/model/md5/Read.luau"], +[186086, "src/Rosetta/model/mdl/init.luau"], +[186168, "src/Rosetta/model/mdl/HalfLife.luau"], +[186472, "src/Rosetta/model/mdl/Quake.luau"], +[186690, "src/Rosetta/model/ms3d/init.luau"], +[186762, "src/Rosetta/model/ms3d/Read.luau"], +[187208, "src/Rosetta/model/ms3d/Write.luau"], +[187677, "src/Rosetta/model/obj/init.luau"], +[188495, "src/Rosetta/model/obj/Mtl.luau"], +[188783, "src/Rosetta/model/off/init.luau"], +[189245, "src/Rosetta/model/ply/init.luau"], +[190350, "src/Rosetta/model/ply/Binary.luau"], +[190551, "src/Rosetta/model/pmx/init.luau"], +[190620, "src/Rosetta/model/pmx/Build.luau"], +[190916, "src/Rosetta/model/pmx/Pmd.luau"], +[191251, "src/Rosetta/model/pmx/Read.luau"], +[191655, "src/Rosetta/model/proc/init.luau"], +[192037, "src/Rosetta/model/qb/init.luau"], +[192430, "src/Rosetta/model/rbxm/init.luau"], +[193023, "src/Rosetta/model/rbxmx/init.luau"], +[193699, "src/Rosetta/model/robloxmesh/init.luau"], +[194358, "src/Rosetta/model/robloxmesh/Parse.luau"], +[194815, "src/Rosetta/model/robloxmesh/Write.luau"], +[194924, "src/Rosetta/model/schematic/init.luau"], +[195245, "src/Rosetta/model/schematic/Common.luau"], +[195365, "src/Rosetta/model/schematic/Litematic.luau"], +[195576, "src/Rosetta/model/schematic/Mcedit.luau"], +[195820, "src/Rosetta/model/schematic/Sponge.luau"], +[195949, "src/Rosetta/model/smd/init.luau"], +[196016, "src/Rosetta/model/smd/Read.luau"], +[196285, "src/Rosetta/model/smd/Write.luau"], +[196528, "src/Rosetta/model/sourcemdl/init.luau"], +[196699, "src/Rosetta/model/sourcemdl/Build.luau"], +[197129, "src/Rosetta/model/sourcemdl/Material.luau"], +[197290, "src/Rosetta/model/sourcemdl/Mdl.luau"], +[197817, "src/Rosetta/model/sourcemdl/Phy.luau"], +[197940, "src/Rosetta/model/sourcemdl/Vtx.luau"], +[198122, "src/Rosetta/model/sourcemdl/Vvd.luau"], +[198216, "src/Rosetta/model/stl/init.luau"], +[198666, "src/Rosetta/model/stl/Decode.luau"], +[198740, "src/Rosetta/model/t3d/init.luau"], +[198834, "src/Rosetta/model/t3d/Build.luau"], +[199239, "src/Rosetta/model/t3d/Parse.luau"], +[199407, "src/Rosetta/model/udmf/init.luau"], +[199490, "src/Rosetta/model/usda/init.luau"], +[199699, "src/Rosetta/model/usda/Build.luau"], +[200977, "src/Rosetta/model/usda/Parse.luau"], +[201775, "src/Rosetta/model/usda/Write.luau"], +[202592, "src/Rosetta/model/vbsp/init.luau"], +[203038, "src/Rosetta/model/vbsp/Faces.luau"], +[203262, "src/Rosetta/model/vbsp/Props.luau"], +[203354, "src/Rosetta/model/vmf/init.luau"], +[203679, "src/Rosetta/model/vmf/Build.luau"], +[204103, "src/Rosetta/model/vox/init.luau"], +[204989, "src/Rosetta/model/vox/Grid.luau"], +[205046, "src/Rosetta/model/vrml/init.luau"], +[205112, "src/Rosetta/model/x/init.luau"], +[205242, "src/Rosetta/model/x/Build.luau"], +[205805, "src/Rosetta/model/x/Parse.luau"], +[206102, "src/Rosetta/model/x3d/init.luau"], +[206180, "src/Rosetta/music/669/init.luau"], +[206387, "src/Rosetta/music/ahx/init.luau"], +[206439, "src/Rosetta/music/far/init.luau"], +[206669, "src/Rosetta/music/hmp/init.luau"], +[206934, "src/Rosetta/music/hvl/init.luau"], +[206986, "src/Rosetta/music/it/init.luau"], +[207405, "src/Rosetta/music/it/Itsex.luau"], +[207522, "src/Rosetta/music/med/init.luau"], +[208170, "src/Rosetta/music/midi/init.luau"], +[208314, "src/Rosetta/music/midi/Smf.luau"], +[208726, "src/Rosetta/music/mod/init.luau"], +[209080, "src/Rosetta/music/mtm/init.luau"], +[209303, "src/Rosetta/music/mus/init.luau"], +[209461, "src/Rosetta/music/okt/init.luau"], +[209743, "src/Rosetta/music/ptm/init.luau"], +[209966, "src/Rosetta/music/s3m/init.luau"], +[210203, "src/Rosetta/music/sf2/init.luau"], +[210247, "src/Rosetta/music/stm/init.luau"], +[210479, "src/Rosetta/music/ult/init.luau"], +[210784, "src/Rosetta/music/umx/init.luau"], +[211001, "src/Rosetta/music/xm/init.luau"], +[211563, "src/Rosetta/music/xmi/init.luau"], +[211772, "src/Rosetta/ops/AudioOps.luau"], +[212251, "src/Rosetta/ops/ImageOps/init.luau"], +[212899, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[213539, "src/Rosetta/ops/LayerOps.luau"], +[213632, "src/Rosetta/ops/MeshOps/init.luau"], +[214772, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[214939, "src/Rosetta/ops/MusicOps.luau"], +[215288, "src/Rosetta/playlist/m3u/init.luau"], +[215641, "src/Rosetta/playlist/pls/init.luau"], +[215819, "src/Rosetta/playlist/xspf/init.luau"], +[216022, "src/Rosetta/subtitle/ass/init.luau"], +[216466, "src/Rosetta/subtitle/srt/init.luau"], +[216639, "src/Rosetta/subtitle/vtt/init.luau"], +[216842, "src/Rosetta/vector/gamemaps/init.luau"], +[217029, "src/Rosetta/vector/gamemaps/Expand.luau"], +[217126, "src/Rosetta/vector/ldtk/init.luau"], +[217218, "src/Rosetta/vector/ldtk/Read.luau"], +[217554, "src/Rosetta/vector/ldtk/Write.luau"], +[218202, "src/Rosetta/vector/ogmo/init.luau"], +[218321, "src/Rosetta/vector/ogmo/Read.luau"], +[218726, "src/Rosetta/vector/ogmo/Write.luau"], +[219080, "src/Rosetta/vector/svg/init.luau"], +[219166, "src/Rosetta/vector/svg/Parse.luau"], +[219912, "src/Rosetta/vector/svg/PathData.luau"], +[220280, "src/Rosetta/vector/svg/Render.luau"], +[220697, "src/Rosetta/vector/svg/Style.luau"], +[221069, "src/Rosetta/vector/svg/Write.luau"], +[221269, "src/Rosetta/vector/tiled/init.luau"], +[221449, "src/Rosetta/vector/tiled/Data.luau"], +[221600, "src/Rosetta/vector/tiled/Tmj.luau"], +[222231, "src/Rosetta/vector/tiled/Tmx.luau"], +[222843, "src/Rosetta/video/avi/init.luau"], +[223137, "src/Rosetta/video/fli/init.luau"], +[223288, "src/Rosetta/video/flv/init.luau"], +[223672, "src/Rosetta/video/flv/Amf.luau"], +[223830, "src/Rosetta/video/flv/Mux.luau"], +[224111, "src/Rosetta/video/h264/init.luau"], +[224250, "src/Rosetta/video/mkv/init.luau"], +[224406, "src/Rosetta/video/mkv/Mux.luau"], +[224685, "src/Rosetta/video/mkv/Parse.luau"], +[225406, "src/Rosetta/video/mp4/init.luau"], +[225734, "src/Rosetta/video/mpegps/init.luau"], +[225921, "src/Rosetta/video/mpegts/init.luau"], +[226167, "src/Rosetta/video/ogv/init.luau"], +[226562, "src/Rosetta/video/smk/init.luau"], +[226871, "src/Rosetta/video/smk/Audio.luau"], +[226991, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/docs/guide/README.md b/docs/guide/README.md index ae445fb..4f379b9 100644 --- a/docs/guide/README.md +++ b/docs/guide/README.md @@ -44,9 +44,10 @@ as `F`, and its input files as variables such as `pngBytes` (a buffer) or `srtTe **Roblox.** Two builds, both committed (rebuilt by `python3 -I tools/build.py roblox`): - [`build/Rosetta.rbxm`](../../build/Rosetta.rbxm), the native build: a ModuleScript `Rosetta` with child - ModuleScripts, the chunks (Core, one per heavy codec such as Mpeg2, H264, Jpeg, Opus, and the rest by folder). A - chunk is required the first time one of its modules is, so an Actor that only decodes MPEG-1 and JPEG loads only - those chunks and Core. Roblox compiles native code per ModuleScript within a budget per module; each chunk stays + ModuleScripts, the chunks (Core; Detect, the sniffs `F.detect` runs; one per heavy codec such as Mpeg2, H264, Jpeg, + Opus; and one per format folder, codec or container, small neighbours packed together). A chunk is required the + first time one of its modules is, so an Actor that only decodes MPEG-1 and JPEG loads only those chunks and Core, + and `F.detect` compiles Detect alone. Roblox compiles native code per ModuleScript within a budget per module; each chunk stays well under it (tools/bundle.py checks it). Insert the file, or mount it with Rojo (`"Rosetta": { "$path": "rosetta/build/Rosetta.rbxm" }`; this repository's `default.project.json` does, so `rojo build -o Rosetta.rbxm` or `rojo serve` works from here). [`build/Rosetta.rbxmx`](../../build/Rosetta.rbxmx) diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index afbe9c8..b774f41 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -390,7 +390,7 @@ local list: { Entry } = { mime = { "audio/aac", "audio/aacp", "audio/x-aac" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Aac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = false, codecs = { "aac" }, streaming = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/audio/aac") end, @@ -403,7 +403,7 @@ local list: { Entry } = { mime = { "audio/ac3", "audio/x-ac3" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/Ac3" }, caps = { decode = true, encode = false, codecs = { "ac3" }, channels = 6, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/audio/ac3") end, @@ -521,7 +521,7 @@ local list: { Entry } = { mime = { "audio/mp4", "audio/x-m4a", "audio/m4a" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "codecs/audio/Aac", "codecs/audio/Alac", "codecs/audio/Pcm", "codecs/audio/Stream" }, caps = { decode = true, encode = true, codecs = { "aac", "alac" }, encodeCodecs = { "alac" }, tags = true, streaming = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/audio/m4a") end, @@ -534,7 +534,7 @@ local list: { Entry } = { mime = { "audio/mpeg", "audio/mp3", "audio/mpa" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Resample", "codecs/audio/Mpa/Header", "codecs/audio/Mpa/Core", "codecs/audio/Mpa/Encode3", "codecs/audio/Mpa/Encode2" }, caps = { decode = true, encode = true, streaming = true, seek = true, layers = { 1, 2, 3 }, encodeLayers = { 2, 3 }, channels = 2 }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/audio/mp3") end, @@ -547,7 +547,7 @@ local list: { Entry } = { mime = { "audio/x-musepack", "audio/musepack" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/ApeTag", "codecs/audio/Musepack" }, caps = { decode = true, encode = false, codecs = { "musepack" }, versions = { 7, 8 }, streaming = true, lossy = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/audio/mpc") end, @@ -638,7 +638,7 @@ local list: { Entry } = { mime = { "audio/wav", "audio/x-wav", "audio/wave", "audio/vnd.wave" }, deps = { "core/Err", "core/Bytes", "Types", "containers/Riff", "codecs/audio/Pcm", "codecs/audio/Adpcm" }, caps = { decode = true, encode = true, streaming = true, depths = { 8, 16, 24, 32 }, float = true, rf64 = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/audio/wav") end, @@ -730,7 +730,7 @@ local list: { Entry } = { mime = { "video/mp4", "video/quicktime", "video/3gpp" }, deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "containers/Demux", "codecs/video/Video", "codecs/video/Video/Source" }, caps = { decode = true, encode = true, streaming = true, remux = true, video = { "mjpeg", "mpeg1", "mpeg2", "h264" }, audio = true, fragments = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/video/mp4") end, @@ -834,7 +834,7 @@ local list: { Entry } = { mime = { "model/x-ase", "text/plain" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/model/ase") end, @@ -925,7 +925,7 @@ local list: { Entry } = { mime = { "application/vnd.autodesk.fbx", "model/fbx" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/compress/Deflate", "core/Base64", "codecs/model/Mat4" }, caps = { decode = true, encode = true, binary = true, ascii = true, materials = true, animation = true, skins = true, morphTargets = true, cameras = true, lights = true, polygons = true }, - sniff = 2, + sniff = 0, load = function() return require("@rosetta/model/fbx") end, @@ -1081,7 +1081,7 @@ local list: { Entry } = { mime = { "application/x-ms3d" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten" }, caps = { decode = true, encode = true, materials = true, skins = true, animation = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/model/ms3d") end, @@ -1682,7 +1682,7 @@ local list: { Entry } = { mime = { "application/x-fat-image" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Fat" }, caps = { decode = true, encode = true, variants = { "fat12", "fat16", "fat32" } }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/archive/fat") end, @@ -1812,7 +1812,7 @@ local list: { Entry } = { mime = { "application/x-tar" }, deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Tar" }, caps = { decode = true, encode = true, variants = { "ustar", "pax", "gnu" } }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/archive/tar") end, @@ -2137,7 +2137,7 @@ local list: { Entry } = { mime = { "text/x-vdf" }, deps = { "core/Err", "core/Bytes", "core/Sniff", "codecs/text/KeyValues" }, caps = { decode = true, encode = true, ordered = true, binary = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/data/vdf") end, @@ -2501,7 +2501,7 @@ local list: { Entry } = { mime = { "audio/x-soundfont" }, deps = { "core/Err", "core/Bytes", "codecs/audio/SoundFont" }, caps = { decode = true, encode = false, sm24 = true, sf3 = false }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/music/sf2") end, @@ -2592,7 +2592,7 @@ local list: { Entry } = { mime = { "audio/x-scpls", "audio/scpls" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Url", "codecs/text/Text", "core/Sniff" }, caps = { decode = true, encode = true }, - sniff = 1, + sniff = 0, load = function() return require("@rosetta/playlist/pls") end, diff --git a/src/Rosetta/Sniffs.luau b/src/Rosetta/Sniffs.luau index 9df7fe1..236dfcf 100644 --- a/src/Rosetta/Sniffs.luau +++ b/src/Rosetta/Sniffs.luau @@ -17,6 +17,878 @@ local function lazy(load: () -> any): any }) end +local P_audio_mp3_Tags: any = {} +do -- audio/mp3/Tags: id3v2Size +local Tags = {} +local band, bor, lshift = bit32.band, bit32.bor, bit32.lshift +local ru8 = buffer.readu8 +local function syncsafe(b: buffer, o: number): number + return bor(lshift(band(ru8(b, o), 0x7F), 21), lshift(band(ru8(b, o + 1), 0x7F), 14), lshift(band(ru8(b, o + 2), 0x7F), 7), band(ru8(b, o + 3), 0x7F)) +end +function Tags.id3v2Size(b: buffer, o: number, len: number): number + if len - o < 10 or buffer.readstring(b, o, 3) ~= "ID3" then + return 0 + end + if band(ru8(b, o + 5), 15) ~= 0 then + return 0 + end + for k = 6, 9 do + if band(ru8(b, o + k), 0x80) ~= 0 then + return 0 + end + end + local size = syncsafe(b, o + 6) + 10 + if band(ru8(b, o + 5), 16) ~= 0 then + size += 10 + 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 = {} +Aac.RATES = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 } +type Adts = { + headerSize: number, -- 7, or 9 with a CRC + frameSize: number, + objectType: number, + sfIndex: number, + sampleRate: number, + channelConfig: number, + blocks: number, -- raw_data_blocks in the frame (1 .. 4) + protected: boolean, +} +function Aac.adts(b: buffer, o: number, limit: number): Adts? + if o < 0 or o + 7 > limit or o + 7 > buffer.len(b) then + return nil + end + local b0, b1, b2, b3, b4, b5, b6 = buffer.readu8(b, o), buffer.readu8(b, o + 1), buffer.readu8(b, o + 2), buffer.readu8(b, o + 3), buffer.readu8(b, o + 4), buffer.readu8(b, o + 5), buffer.readu8(b, o + 6) + if b0 ~= 0xFF or bit32.band(b1, 0xF6) ~= 0xF0 then -- sync, layer 0 + return nil + end + local protected = bit32.band(b1, 1) == 0 + local profile = bit32.rshift(b2, 6) + local sfi = bit32.band(bit32.rshift(b2, 2), 15) + local ch = bit32.band(b2, 1) * 4 + bit32.rshift(b3, 6) + local size = bit32.band(b3, 3) * 2048 + b4 * 8 + bit32.rshift(b5, 5) + local blocks = bit32.band(b6, 3) + 1 + local hs = if protected then 9 else 7 + if sfi > 12 or size < hs then + return nil + end + return { + headerSize = hs, + frameSize = size, + objectType = profile + 1, + sfIndex = sfi, + sampleRate = Aac.RATES[sfi + 1], + channelConfig = ch, + blocks = blocks, + 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 = {} +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 + local kbps = T.BITRATES[frmsizecod // 2 + 1] + if not kbps or fscod > 2 then + return 0 + end + if fscod == 0 then + return 2 * kbps + elseif fscod == 2 then + return 3 * kbps + 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 = {} +local T = P_codecs_audio_Ac3_Tables +local readu8 = buffer.readu8 +local NFCHANS = { [0] = 2, 1, 2, 3, 3, 4, 4, 5 } +type Header = { + sampleRate: number, + frameSize: number, + bitrate: number, + channels: number, + acmod: number, + lfeon: boolean, + bsid: number, +} +function Ac3.header(b: buffer, o: number, limit: number): Header? + if o < 0 or o + 8 > limit or o + 8 > buffer.len(b) then + return nil + end + if readu8(b, o) ~= 0x0B or readu8(b, o + 1) ~= 0x77 then + return nil + end + local bsid = bit32.rshift(readu8(b, o + 5), 3) + if bsid > 10 then + if bsid > 16 then + return nil + end + -- E-AC-3: strmtyp(2) substreamid(3) frmsiz(11) fscod(2) ... + local words = bit32.band(readu8(b, o + 2), 7) * 256 + readu8(b, o + 3) + 1 + local fs = bit32.rshift(readu8(b, o + 4), 6) + return { + sampleRate = if fs < 3 then T.RATES[fs + 1] else 0, + frameSize = words * 2, + bitrate = 0, + channels = 0, + acmod = bit32.band(bit32.rshift(readu8(b, o + 4), 1), 7), + lfeon = false, + bsid = bsid, + } + end + local b4 = readu8(b, o + 4) + local fscod, frmsizecod = bit32.rshift(b4, 6), bit32.band(b4, 63) + local words = T.frameWords(fscod, frmsizecod) + if words == 0 then + return nil + end + local acmod = bit32.rshift(readu8(b, o + 6), 5) + -- lfeon: after acmod and the optional cmixlev / surmixlev / dsurmod fields + local skip = 0 + if bit32.band(acmod, 1) == 1 and acmod ~= 1 then + skip += 2 + end + if bit32.band(acmod, 4) ~= 0 then + skip += 2 + end + if acmod == 2 then + skip += 2 + end + local w = readu8(b, o + 6) * 256 + readu8(b, o + 7) + local lfeon = bit32.extract(w, 12 - skip, 1) == 1 + local shift = if bsid > 8 then bsid - 8 else 0 + return { + sampleRate = T.RATES[fscod + 1] // 2 ^ shift, + frameSize = words * 2, + bitrate = T.BITRATES[frmsizecod // 2 + 1] * 1000 // 2 ^ shift, + channels = NFCHANS[acmod] + (if lfeon then 1 else 0), + acmod = acmod, + lfeon = lfeon, + 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 = {} +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 = {} +local T = P_codecs_audio_Mpa_Tables +local band, bxor, rshift = bit32.band, bit32.bxor, bit32.rshift +local ru8 = buffer.readu8 +local HALFRATE = T.halfrate +local HZ = { [0] = 44100, 48000, 32000 } +function H.valid(b: buffer, o: number): boolean + if ru8(b, o) ~= 0xFF then + return false + end + local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + return (band(h1, 0xF0) == 0xF0 or band(h1, 0xFE) == 0xE2) + and band(rshift(h1, 1), 3) ~= 0 + and rshift(h2, 4) ~= 15 + and band(rshift(h2, 2), 3) ~= 3 +end +local valid = H.valid +function H.compare(b: buffer, o1: number, o2: number): boolean + if not valid(b, o2) then + return false + end + local a1, a2 = ru8(b, o1 + 1), ru8(b, o1 + 2) + local c1, c2 = ru8(b, o2 + 1), ru8(b, o2 + 2) + return band(bxor(a1, c1), 0xFE) == 0 + and band(bxor(a2, c2), 0x0C) == 0 + and (band(a2, 0xF0) == 0) == (band(c2, 0xF0) == 0) +end +function H.bitrateKbps(h1: number, h2: number): number + local mpeg1 = if band(h1, 8) ~= 0 then 1 else 0 + local layer = band(rshift(h1, 1), 3) + return 2 * HALFRATE[mpeg1 * 45 + (layer - 1) * 15 + rshift(h2, 4)] +end +local bitrateKbps = H.bitrateKbps +function H.sampleRate(h1: number, h2: number): number + local hz = HZ[band(rshift(h2, 2), 3)] + if band(h1, 8) == 0 then + hz //= 2 + end + if band(h1, 0x10) == 0 then + hz //= 2 + end + return hz +end +local sampleRate = H.sampleRate +function H.frameSamples(h1: number): number + if band(h1, 6) == 6 then + return 384 + elseif band(h1, 14) == 2 then + return 576 + end + return 1152 +end +local frameSamples = H.frameSamples +function H.frameBytes(b: buffer, o: number, freeSize: number): number + local h1, h2 = ru8(b, o + 1), ru8(b, o + 2) + local hz = sampleRate(h1, h2) + local fb = frameSamples(h1) * bitrateKbps(h1, h2) * 125 // hz + if band(h1, 6) == 6 then + fb = band(fb, 0xFFFFFFFC) + end + return if fb ~= 0 then fb else freeSize +end +function H.padding(b: buffer, o: number): number + if band(ru8(b, o + 2), 2) == 0 then + return 0 + 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 = {} +function Musepack.magic(buf: buffer, p: number, limit: number): number + if p + 4 > limit then + return 0 + end + local m = buffer.readstring(buf, p, 4) + if m == "MPCK" then + return 8 + end + if string.sub(m, 1, 3) == "MP+" then + return 7 + 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 = {} +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() + return require("@rosetta/codecs/compress/Brotli") +end) + +local P_codecs_compress_Deflate_Inflate = lazy(function() + return require("@rosetta/codecs/compress/Deflate/Inflate") +end) + +local P_codecs_compress_Deflate: any = {} +do -- codecs/compress/Deflate: peek +local Deflate = {} +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Inflate = P_codecs_compress_Deflate_Inflate +local args = Bytes.span +local function shrink(out: buffer, n: number): buffer + if buffer.len(out) == n then + return out + end + local b = buffer.create(n) + buffer.copy(b, 0, out, 0, n) + return b +end +local function inflateErr(msg: string, at: number?): Err.Err + local code = if string.find(msg, "truncated", 1, true) then Err.TRUNCATED else Err.CORRUPT + return Err.new(code, "inflate: " .. msg, at) +end +local function gzipBody(b: buffer, p: number, e: number): (number?, Err.Err?) + local flg = buffer.readu8(b, p + 3) + if flg >= 0x20 then + return nil, Err.new(Err.CORRUPT, "gzip: reserved flags set", p + 3) + end + local q = p + 10 + if bit32.band(flg, 4) ~= 0 then -- FEXTRA + if q + 2 > e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + q += 2 + buffer.readu16(b, q) + end + for _, bit in { 8, 16 } do -- FNAME, FCOMMENT: zero-terminated + if bit32.band(flg, bit) ~= 0 then + while q < e and buffer.readu8(b, q) ~= 0 do + q += 1 + end + q += 1 + end + end + if bit32.band(flg, 2) ~= 0 then -- FHCRC + q += 2 + end + if q >= e then + return nil, Err.new(Err.TRUNCATED, "gzip: truncated header", q) + end + return q, nil +end +function Deflate.peek(buf: buffer | string, offset: number?, length: number?, n: number): (buffer?, Err.Err?) + local b, o, l, aerr = args("Deflate.peek", buf, offset, length) + if not b then + return nil, aerr + end + if type(n) ~= "number" or n < 1 then + return nil, Err.new(Err.ARG, "Deflate.peek: bad size " .. tostring(n)) + end + local e = o + l + local q = o + if l >= 18 and buffer.readu8(b, o) == 0x1f and buffer.readu8(b, o + 1) == 0x8b and buffer.readu8(b, o + 2) == 8 then + local herr + q, herr = gzipBody(b, o, e) + if not q then + return nil, herr + end + elseif l >= 6 then + local cmf, flg = buffer.readu8(b, o), buffer.readu8(b, o + 1) + if cmf % 16 == 8 and cmf // 16 <= 7 and (cmf * 256 + flg) % 31 == 0 and bit32.band(flg, 0x20) == 0 then + q = o + 2 + end + end + local out, k = Inflate.raw(b, q :: number, e, n, true, true) + if not out then + return nil, inflateErr(tostring(k), q) + end + return shrink(out, k), nil +end +P_codecs_compress_Deflate.peek = Deflate.peek +end + +local P_codecs_compress_Zstd_Decode = lazy(function() + return require("@rosetta/codecs/compress/Zstd/Decode") +end) + +local P_codecs_compress_Zstd: any = {} +do -- codecs/compress/Zstd: MAGIC, decompress +local Zstd = {} +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Decode = P_codecs_compress_Zstd_Decode +type Options = { + maxBytes: number?, + verify: boolean?, +} +Zstd.MAGIC = "\40\181\47\253" +function Zstd.decompress(buf: buffer | string, offset: number?, length: number?, opts: Options?): (buffer?, any) + local b, o, l, aerr = Bytes.span("Zstd.decompress", buf, offset, length) + if not b then + return nil, aerr + end + local maxBytes = if opts and opts.maxBytes ~= nil then opts.maxBytes else 2 ^ 30 + if type(maxBytes) ~= "number" or maxBytes < 0 then + return nil, Err.new(Err.ARG, "Zstd.decompress: bad maxBytes " .. tostring(maxBytes)) + end + local verify = not (opts and opts.verify == false) + local out, len, consumed, at = Decode.decompress(b, o, o + l, maxBytes, verify) + if not out then + return nil, Err.from(consumed, at, len) + end + if buffer.len(out) ~= len then + local r = buffer.create(len) + buffer.copy(r, 0, out, 0, len) + out = r + 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 = {} +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 + return false + end + local t = readu8(b, o) + if t ~= 0 and t ~= 1 and t ~= 2 then + return false + end + for i = 1, math.min(n - 1, 64) do + local c = readu8(b, o + i) + if c == 0 then + return i > 1 + elseif c < 32 then + return false + end + 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 = {} +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 = {} +Value.NAMES = { + [0] = "end", + "byte", + "short", + "int", + "long", + "float", + "double", + "byteArray", + "string", + "list", + "compound", + "intArray", + "longArray", +} :: { [number]: string } +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 = {} +local Deflate = P_codecs_compress_Deflate +local Value = P_codecs_text_Nbt_Value +type Peek = { + compression: string, + endian: "big" | "little", + header: boolean, + rootType: string, + name: string, + firstType: string?, + firstName: string?, + head: buffer, +} +local function plausibleName(b: buffer, p: number, n: number): string? + if p + n > buffer.len(b) or n > 256 then + return nil + end + local s = buffer.readstring(b, p, n) + if string.find(s, "[%z\1-\31\127]") then + return nil + end + return s +end +function Nbt.peek(buf: buffer, offset: number?, length: number?): Peek? + local o = offset or 0 + local l = length or (buffer.len(buf) - o) + if l < 3 then + return nil + end + local c0, c1 = buffer.readu8(buf, o), buffer.readu8(buf, o + 1) + local head: buffer + local comp = "none" + if c0 == 0x1f and c1 == 0x8b or (c0 % 16 == 8 and c0 < 0x80 and (c0 * 256 + c1) % 31 == 0) then + local h = Deflate.peek(buf, o, l, 1024) + if not h then + return nil + end + head, comp = h, if c0 == 0x1f then "gzip" else "zlib" + else + local n = math.min(l, 1024) + head = buffer.create(n) + buffer.copy(head, 0, buf, o, n) + end + local hn = buffer.len(head) + local function at(p: number, endian: string, header: boolean): Peek? + if p + 3 > hn then + return nil + end + local t = buffer.readu8(head, p) + if t ~= 10 and t ~= 9 then + return nil + end + local function u16(q: number): number + local a, b = buffer.readu8(head, q), buffer.readu8(head, q + 1) + return if endian == "big" then a * 256 + b else b * 256 + a + end + local nl = u16(p + 1) + local name = plausibleName(head, p + 3, nl) + if not name then + return nil + end + local res: Peek = { compression = comp, endian = endian :: any, header = header, rootType = Value.NAMES[t], name = name, head = head } + local q = p + 3 + nl + if t == 10 and q < hn then + local ft = buffer.readu8(head, q) + if ft > 12 then + return nil + end + if ft == 0 then + res.firstType = "end" + elseif q + 3 <= hn then + local fname = plausibleName(head, q + 3, u16(q + 1)) + if fname == nil and q + 3 + u16(q + 1) <= hn then + return nil + end + res.firstType, res.firstName = Value.NAMES[ft], fname + end + end + return res + end + if hn >= 12 and buffer.readu32(head, 4) == (if comp == "none" then l else -1) - 8 then + local r = at(8, "little", true) + if r then + return r + end + 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 = {} +function Text.utf8char(c: number): string + local char = string.char + if c < 0x80 then + return char(c) + elseif c < 0x800 then + return char(0xC0 + c // 64, 0x80 + c % 64) + elseif c < 0x10000 then + return char(0xE0 + c // 4096, 0x80 + (c // 64) % 64, 0x80 + c % 64) + end + return char(0xF0 + c // 262144, 0x80 + (c // 4096) % 64, 0x80 + (c // 64) % 64, 0x80 + c % 64) +end +Text.CP1252 = { + [0x80] = 0x20AC, [0x82] = 0x201A, [0x83] = 0x0192, [0x84] = 0x201E, [0x85] = 0x2026, [0x86] = 0x2020, + [0x87] = 0x2021, [0x88] = 0x02C6, [0x89] = 0x2030, [0x8A] = 0x0160, [0x8B] = 0x2039, [0x8C] = 0x0152, + [0x8E] = 0x017D, [0x91] = 0x2018, [0x92] = 0x2019, [0x93] = 0x201C, [0x94] = 0x201D, [0x95] = 0x2022, + [0x96] = 0x2013, [0x97] = 0x2014, [0x98] = 0x02DC, [0x99] = 0x2122, [0x9A] = 0x0161, [0x9B] = 0x203A, + [0x9C] = 0x0153, [0x9E] = 0x017E, [0x9F] = 0x0178, +} +function Text.trim(s: string): string + return (string.match(s, "^%s*(.-)%s*$") :: string) +end +function Text.utf16(b: buffer, o: number, n: number, bigEndian: boolean?): string + local out = {} + local k = 0 + local readu16 = buffer.readu16 + local function unit(at: number): number + local v = readu16(b, at) + return if bigEndian then (v % 256) * 256 + v // 256 else v + end + while k + 1 < n do + local c = unit(o + k) + k += 2 + if c >= 0xD800 and c < 0xDC00 and k + 1 < n then + local lo = unit(o + k) + if lo >= 0xDC00 and lo < 0xE000 then + c = 0x10000 + (c - 0xD800) * 1024 + (lo - 0xDC00) + k += 2 + end + end + if c >= 0xD800 and c < 0xE000 then + c = 0xFFFD + end + table.insert(out, Text.utf8char(c)) + end + return table.concat(out) +end +function Text.toUtf8(text: string, warnings: { string }?): string + if string.sub(text, 1, 3) == "\239\187\191" then + text = string.sub(text, 4) + end + if utf8.len(text) then + return text + end + if warnings then + table.insert(warnings, "text is not UTF-8: read as Windows-1252") + end + local out = table.create(#text) + for i = 1, #text do + local b = string.byte(text, i) + if b < 0x80 then + out[i] = string.char(b) + else + out[i] = utf8.char(if b < 0xA0 then Text.CP1252[b] or 0xFFFD else b) + end + 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 = {} +local readu8, readu16, readu32 = buffer.readu8, buffer.readu16, buffer.readu32 +type Volume = { + b: buffer, + base: number, -- byte offset of the volume (partition) in b + limit: number, + bps: number, -- bytes per sector + spc: number, -- sectors per cluster + fatOffset: number, -- byte offset of the first FAT (relative to base) + fatSize: number, -- bytes per FAT + rootOffset: number, -- FAT12 / 16: the fixed root directory + rootEntries: number, + rootCluster: number, -- FAT32 + dataOffset: number, -- byte offset of cluster 2 + clusters: number, -- data clusters + bits: number, -- 12 / 16 / 32 + label: string?, + oem: string, + media: number, + partition: number?, +} +local function bpbAt(b: buffer, o: number, len: number): (Volume?, string?) + if len < 512 then + return nil, "truncated: smaller than a boot sector" + end + local jump = readu8(b, o) + local bps = readu16(b, o + 11) + local spc = readu8(b, o + 13) + if (jump ~= 0xEB and jump ~= 0xE9 and jump ~= 0xE8) or (bps ~= 512 and bps ~= 1024 and bps ~= 2048 and bps ~= 4096) then + return nil, "no FAT boot sector" + end + if spc == 0 or bit32.band(spc, spc - 1) ~= 0 then + return nil, "bad sectors per cluster" + end + local reserved, nfats, rootEntries = readu16(b, o + 14), readu8(b, o + 16), readu16(b, o + 17) + local total = readu16(b, o + 19) + if total == 0 then + total = readu32(b, o + 32) + end + local fatSectors = readu16(b, o + 22) + local fat32 = fatSectors == 0 + if fat32 then + fatSectors = readu32(b, o + 36) + end + if reserved == 0 or nfats == 0 or fatSectors == 0 or total == 0 then + return nil, "bad BPB" + end + local rootSectors = math.ceil(rootEntries * 32 / bps) + local dataSector = reserved + nfats * fatSectors + rootSectors + if dataSector >= total then + return nil, "bad BPB: no data area" + end + local clusters = (total - dataSector) // spc + local bits = if clusters < 4085 then 12 elseif clusters < 65525 then 16 else 32 + if fat32 and bits ~= 32 then + bits = 32 -- some small FAT32 volumes (mkfs.fat -F 32 on tiny images) are FAT32 regardless of the count + end + if total * bps > len then + -- images cut short at the last used sector are common: allow, reads past the end fail + total = len // bps + end + local labelAt = if bits == 32 then 71 else 43 + local sig = readu8(b, o + (if bits == 32 then 66 else 38)) + local label: string? = if sig == 0x29 then (string.gsub(buffer.readstring(b, o + labelAt, 11), " +$", "")) else nil + if label == "NO NAME" or label == "" then + label = nil + end + return { + b = b, + base = o, + limit = o + len, + bps = bps, + spc = spc, + fatOffset = reserved * bps, + fatSize = fatSectors * bps, + rootOffset = (reserved + nfats * fatSectors) * bps, + rootEntries = rootEntries, + rootCluster = if bits == 32 then readu32(b, o + 44) else 0, + dataOffset = dataSector * bps, + clusters = clusters, + bits = bits, + label = label, + oem = buffer.readstring(b, o + 3, 8), + media = readu8(b, o + 21), + }, nil +end +type OpenOptions = { partition: number? } -- 1..4: the MBR partition (default: the first FAT one) +local FAT_TYPES = { [0x01] = true, [0x04] = true, [0x06] = true, [0x0B] = true, [0x0C] = true, [0x0E] = true, [0x11] = true, [0x14] = true, [0x16] = true, [0x1B] = true, [0x1C] = true, [0x1E] = true } +function Fat.open(b: buffer, off: number, len: number, opts: OpenOptions?): (Volume?, string?) + local o: OpenOptions = opts or {} + off = math.max(0, off) + len = math.min(len, buffer.len(b) - off) + if len < 512 then + return nil, "truncated: smaller than a boot sector" + end + if not o.partition then + local v = bpbAt(b, off, len) + if v then + return v, nil + end + end + -- an MBR: 0x55AA and four partition entries + if readu8(b, off + 510) ~= 0x55 or readu8(b, off + 511) ~= 0xAA then + return nil, "no FAT boot sector and no partition table" + end + for i = 1, 4 do + local e = off + 446 + (i - 1) * 16 + local ptype = readu8(b, e + 4) + local lba, count = readu32(b, e + 8), readu32(b, e + 12) + if (o.partition == i or (not o.partition and FAT_TYPES[ptype])) and ptype ~= 0 then + if lba * 512 >= len then + return nil, "truncated: partition " .. i .. " starts past the end" + end + local v, err = bpbAt(b, off + lba * 512, math.min(count * 512, len - lba * 512)) + if v then + v.partition = i + end + return v, err + end + 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 = {} +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, + styp = true, sidx = true, meta = true, uuid = true, PICT = true, +} +function IsoBmff.sniff(r: Bytes.Reader): string? + local head = r:peek(12) + if #head < 8 then + return nil + end + local typ = string.sub(head, 5, 8) + if typ == "ftyp" then + return if #head >= 12 then string.sub(head, 9, 12) else "" + end + if TOP[typ] then + local size = string.byte(head, 1) * 16777216 + string.byte(head, 2) * 65536 + string.byte(head, 3) * 256 + string.byte(head, 4) + if size == 1 or size == 0 or size >= 8 then + return "" + end + end + return nil +end +P_containers_IsoBmff.sniff = IsoBmff.sniff +end + +local P_containers_Riff: any = {} +do -- containers/Riff: sniff +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 + return nil + end + 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 = {} +local BLOCK = 512 +local function zeros(b: buffer, o: number): boolean + for i = 0, BLOCK - 1, 4 do + if buffer.readu32(b, o + i) ~= 0 then + return false + end + end + return true +end +local function number(b: buffer, o: number, n: number): number? + local first = buffer.readu8(b, o) + if first >= 0x80 then + local v = first - (if first >= 0xC0 then 0x100 else 0x80) -- 0xFF.. = negative + for i = 1, n - 1 do + v = v * 256 + buffer.readu8(b, o + i) + end + return v + end + local s = buffer.readstring(b, o, n) + s = string.match(s, "^[ %z]*([0-7]*)") or "" + if s == "" then + return 0 + end + return tonumber(s, 8) +end +local function checksum(b: buffer, o: number): (number, number) + local u, s = 0, 0 + for i = 0, BLOCK - 1 do + local v = if i >= 148 and i < 156 then 32 else buffer.readu8(b, o + i) + u += v + s += if v >= 128 then v - 256 else v + end + return u, s +end +function Tar.valid(b: buffer, o: number): boolean + if o + BLOCK > buffer.len(b) or zeros(b, o) then + return false + end + local want = number(b, o + 148, 8) + 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 = {} +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 = {} +Read.MAGIC = "MS3D000000" +P_model_ms3d_Read.MAGIC = Read.MAGIC +end + do -- image/ani local Bytes = require("@rosetta/core/Bytes") S["image/ani"] = function(r: Bytes.Reader): number @@ -446,9 +1318,7 @@ end do -- audio/aac local Bytes = require("@rosetta/core/Bytes") -local Aac = lazy(function() - return require("@rosetta/codecs/audio/Aac") -end) +local Aac = P_codecs_audio_Aac local readu8 = buffer.readu8 local function id3Size(b: buffer, p: number, limit: number): number if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then @@ -478,9 +1348,7 @@ end do -- audio/ac3 local Bytes = require("@rosetta/core/Bytes") -local Ac3 = lazy(function() - return require("@rosetta/codecs/audio/Ac3") -end) +local Ac3 = P_codecs_audio_Ac3 S["audio/ac3"] = function(r: Bytes.Reader): number local b, p, limit = r.buf, r.pos, r.limit local h = Ac3.header(b, p, limit) @@ -612,9 +1480,7 @@ end do -- audio/m4a local Bytes = require("@rosetta/core/Bytes") -local IsoBmff = lazy(function() - return require("@rosetta/containers/IsoBmff") -end) +local IsoBmff = P_containers_IsoBmff local AUDIO_BRANDS: { [string]: number } = { ["M4A "] = 1, ["M4B "] = 1, ["M4P "] = 1, ["M4V "] = 0.3 } S["audio/m4a"] = function(r: Bytes.Reader): number local brand = IsoBmff.sniff(r) @@ -633,12 +1499,8 @@ end do -- audio/mp3 local Bytes = require("@rosetta/core/Bytes") -local Header = lazy(function() - return require("@rosetta/codecs/audio/Mpa/Header") -end) -local Tags = lazy(function() - return require("@rosetta/audio/mp3/Tags") -end) +local Header = P_codecs_audio_Mpa_Header +local Tags = P_audio_mp3_Tags S["audio/mp3"] = function(r: Bytes.Reader): number local b, p, lim = r.buf, r.pos, r.limit local id3 = false @@ -669,9 +1531,7 @@ end do -- audio/mpc local Bytes = require("@rosetta/core/Bytes") -local Musepack = lazy(function() - return require("@rosetta/codecs/audio/Musepack") -end) +local Musepack = P_codecs_audio_Musepack local function id3v2(b: buffer, p: number, limit: number): number if p + 10 > limit or buffer.readstring(b, p, 3) ~= "ID3" then return 0 @@ -770,9 +1630,7 @@ end do -- audio/wav local Bytes = require("@rosetta/core/Bytes") -local Riff = lazy(function() - return require("@rosetta/containers/Riff") -end) +local Riff = P_containers_Riff S["audio/wav"] = function(r: Bytes.Reader): number return if Riff.sniff(r) == "WAVE" then 1 else 0 end @@ -876,9 +1734,7 @@ end do -- video/mp4 local Bytes = require("@rosetta/core/Bytes") -local IsoBmff = lazy(function() - return require("@rosetta/containers/IsoBmff") -end) +local IsoBmff = P_containers_IsoBmff local IMAGE_BRANDS = { avif = true, avis = true, heic = true, heix = true, mif1 = true, msf1 = true, ["crx "] = true } local AUDIO_BRANDS = { ["M4A "] = true, ["M4B "] = true, ["M4P "] = true } S["video/mp4"] = function(r: Bytes.Reader): number @@ -1041,9 +1897,7 @@ end do -- model/ase local Bytes = require("@rosetta/core/Bytes") -local Text = lazy(function() - return require("@rosetta/codecs/text/Text") -end) +local Text = P_codecs_text_Text local MAGIC = "*3DSMAX_ASCIIEXPORT" local function utf16(r: Bytes.Reader): (boolean?, boolean) local h = r:peek(2) @@ -1091,12 +1945,8 @@ end do -- model/blend local Bytes = require("@rosetta/core/Bytes") -local Deflate = lazy(function() - return require("@rosetta/codecs/compress/Deflate") -end) -local Zstd = lazy(function() - return require("@rosetta/codecs/compress/Zstd") -end) +local Deflate = P_codecs_compress_Deflate +local Zstd = P_codecs_compress_Zstd S["model/blend"] = function(r: Bytes.Reader): number local head = r:peek(7) if head == "BLENDER" then @@ -1225,6 +2075,25 @@ S["model/dae"] = function(r: Bytes.Reader): number end end +do -- model/fbx +local Bytes = require("@rosetta/core/Bytes") +local Binary = P_model_fbx_Binary +local MAGIC = Binary.MAGIC +S["model/fbx"] = function(r: Bytes.Reader): number + if r:peek(21) == MAGIC then + return 1 + end + local head = r:peek(2048) + if string.find(head, "FBXHeaderExtension:", 1, true) then + return 0.95 + end + if string.find(head, "^; FBX %d") then + return 0.8 + end + return 0 +end +end + do -- model/gltf local Sniff = require("@rosetta/core/Sniff") local Bytes = require("@rosetta/core/Bytes") @@ -1404,9 +2273,7 @@ end do -- model/ms3d local Bytes = require("@rosetta/core/Bytes") -local Read = lazy(function() - return require("@rosetta/model/ms3d/Read") -end) +local Read = P_model_ms3d_Read S["model/ms3d"] = function(r: Bytes.Reader): number local h = r:peek(14) if string.sub(h, 1, 10) ~= Read.MAGIC then @@ -1536,9 +2403,7 @@ end do -- model/schematic local Bytes = require("@rosetta/core/Bytes") -local Nbt = lazy(function() - return require("@rosetta/codecs/text/Nbt") -end) +local Nbt = P_codecs_text_Nbt local LITEMATIC_HINTS = { "Regions", "EnclosingSize", "RegionCount", "TotalVolume", "MinecraftDataVersion" } local SPONGE_HINTS = { "BlockData", "PaletteMax" } -- v1 / v2 fields (some writers leave the root unnamed) local function hinted(head: string, hints: { string }): boolean @@ -2001,9 +2866,7 @@ end do -- archive/br local Err = require("@rosetta/core/Err") local Bytes = require("@rosetta/core/Bytes") -local Brotli = lazy(function() - return require("@rosetta/codecs/compress/Brotli") -end) +local Brotli = P_codecs_compress_Brotli local SNIFF_WHOLE = 262144 -- streams up to this size are decoded whole by sniff local SNIFF_PREFIX = 65536 S["archive/br"] = function(r: Bytes.Reader): number @@ -2116,9 +2979,7 @@ end do -- archive/fat local Bytes = require("@rosetta/core/Bytes") -local Fat = lazy(function() - return require("@rosetta/containers/Fat") -end) +local Fat = P_containers_Fat S["archive/fat"] = function(r: Bytes.Reader): number if r:remaining() < 512 then return 0 @@ -2290,9 +3151,7 @@ end do -- archive/tar local Bytes = require("@rosetta/core/Bytes") -local Tar = lazy(function() - return require("@rosetta/containers/Tar") -end) +local Tar = P_containers_Tar S["archive/tar"] = function(r: Bytes.Reader): number if r:remaining() < 512 then return 0 @@ -2306,12 +3165,8 @@ end do -- archive/unitypackage local Bytes = require("@rosetta/core/Bytes") -local Deflate = lazy(function() - return require("@rosetta/codecs/compress/Deflate") -end) -local Tar = lazy(function() - return require("@rosetta/containers/Tar") -end) +local Deflate = P_codecs_compress_Deflate +local Tar = P_containers_Tar local function guidOf(name: string): (string?, string?) local n = string.gsub(name, "^%./", "") local guid, rest = string.match(n, "^(%x+)/?(.*)$") @@ -2515,9 +3370,7 @@ end do -- archive/zst local Bytes = require("@rosetta/core/Bytes") -local Zstd = lazy(function() - return require("@rosetta/codecs/compress/Zstd") -end) +local Zstd = P_codecs_compress_Zstd S["archive/zst"] = function(r: Bytes.Reader): number local m = r:peek(4) if m == Zstd.MAGIC then @@ -2610,9 +3463,7 @@ end do -- data/nbt local Bytes = require("@rosetta/core/Bytes") -local Nbt = lazy(function() - return require("@rosetta/codecs/text/Nbt") -end) +local Nbt = P_codecs_text_Nbt S["data/nbt"] = function(r: Bytes.Reader): number local p = Nbt.peek(r.buf, r.base, r.limit - r.base) if not p or p.rootType ~= "compound" then @@ -2740,9 +3591,7 @@ end do -- data/vdf local Bytes = require("@rosetta/core/Bytes") local Sniff = require("@rosetta/core/Sniff") -local KeyValues = lazy(function() - return require("@rosetta/codecs/text/KeyValues") -end) +local KeyValues = P_codecs_text_KeyValues S["data/vdf"] = function(r: Bytes.Reader): number local n = r:remaining() if KeyValues.isBinary(r.buf, r.pos, n) then @@ -3208,9 +4057,7 @@ end do -- music/sf2 local Bytes = require("@rosetta/core/Bytes") -local SoundFont = lazy(function() - return require("@rosetta/codecs/audio/SoundFont") -end) +local SoundFont = P_codecs_audio_SoundFont S["music/sf2"] = function(r: Bytes.Reader): number return if SoundFont.sniff(r) then 1 else 0 end @@ -3358,9 +4205,7 @@ end do -- playlist/pls local Sniff = require("@rosetta/core/Sniff") local Bytes = require("@rosetta/core/Bytes") -local Text = lazy(function() - return require("@rosetta/codecs/text/Text") -end) +local Text = P_codecs_text_Text S["playlist/pls"] = function(r: Bytes.Reader): number local s = Sniff.text(r, 64) local first = string.match(s, "^%s*([^\r\n]*)") diff --git a/src/Rosetta/codecs/compress/Brotli/Decode.luau b/src/Rosetta/codecs/compress/Brotli/Decode.luau index 4611571..69d3ddb 100644 --- a/src/Rosetta/codecs/compress/Brotli/Decode.luau +++ b/src/Rosetta/codecs/compress/Brotli/Decode.luau @@ -10,8 +10,11 @@ local bcreate, bcopy, blen, bfill = buffer.create, buffer.copy, buffer.len, buff local Decode = {} +local NO_DICTIONARY = "static dictionary unavailable" +Decode.NO_DICTIONARY = NO_DICTIONARY + export type Static = { - dictionary: buffer, -- 122784 bytes + dictionary: () -> buffer?, -- 122784 bytes, on first use (nil: Decode.NO_DICTIONARY) context: buffer, -- 2048 bytes: 4 modes x (256 for p1, 256 for p2) prefixSuffix: buffer, -- length-prefixed strings prefixSuffixMap: { number }, @@ -516,7 +519,7 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb end local maxBackward = 2 ^ wbits - 16 - local dict = S.dictionary + local dict: buffer? = nil local LUT = S.context local PS = S.prefixSuffix local PSMAP = S.prefixSuffixMap @@ -885,7 +888,12 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb end local ws = w if wl > 0 then - bcopy(WORD, w, dict, wo, wl) + local d = dict or S.dictionary() + if d == nil then + return nil, NO_DICTIONARY + end + dict = d + bcopy(WORD, w, d, wo, wl) w += wl end if ttype == 10 then diff --git a/src/Rosetta/codecs/compress/Brotli/init.luau b/src/Rosetta/codecs/compress/Brotli/init.luau index 698ea50..5ab6393 100644 --- a/src/Rosetta/codecs/compress/Brotli/init.luau +++ b/src/Rosetta/codecs/compress/Brotli/init.luau @@ -6,7 +6,6 @@ local Err = require("@rosetta/core/Err") local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/core/Crc32") local Base64 = require("@rosetta/core/Base64") -local Deflate = require("@rosetta/codecs/compress/Deflate") local Decode = require("@rosetta/codecs/compress/Brotli/Decode") local StaticData = require("@rosetta/codecs/compress/Brotli/Static") @@ -23,32 +22,46 @@ local function unbase64(s: string): buffer end local static: Decode.Static? = nil +local dictionary: buffer? = nil +local dictionaryErr: Err.Err? = nil -local function tables(): (Decode.Static?, Err.Err?) - if static then - return static, nil +-- inflated on the first dictionary reference (RFC 7932 section 8) +local function loadDictionary(): buffer? + if dictionary or dictionaryErr then + return dictionary end + local Deflate = require("@rosetta/codecs/compress/Deflate") local z = unbase64(table.concat(StaticData.dictionary)) local dict, err = Deflate.zlib(z, 0, nil, StaticData.dictionarySize) if not dict then - return nil, err + dictionaryErr = err + return nil end if Crc32.of(dict) ~= StaticData.dictionaryCrc then - return nil, Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + dictionaryErr = Err.new(Err.CHECKSUM, "brotli: static dictionary damaged") + return nil end - static = { - dictionary = dict, + dictionary = dict + return dict +end + +local function tables(): Decode.Static + if static then + return static + end + local s: Decode.Static = { + dictionary = loadDictionary, context = unbase64(table.concat(StaticData.context)), prefixSuffix = unbase64(StaticData.prefixSuffix), prefixSuffixMap = StaticData.prefixSuffixMap, transforms = StaticData.transforms, } - return static, nil + static = s + return s end function Brotli.dictionary(): buffer? - local s = tables() - return if s then s.dictionary else nil + return loadDictionary() end function Brotli.decompress(buf: buffer | string, offset: number?, length: number?, opts: Options?): (buffer?, any) @@ -64,12 +77,11 @@ function Brotli.decompress(buf: buffer | string, offset: number?, length: number if l == 0 then return nil, Err.new(Err.TRUNCATED, "brotli: empty input", o) end - local S, serr = tables() - if not S then - return nil, serr - end - local out, size, consumed = Decode.decompress(b, o, l, maxBytes, S, large) + local out, size, consumed = Decode.decompress(b, o, l, maxBytes, tables(), large) if not out then + if size == Decode.NO_DICTIONARY and dictionaryErr then + return nil, dictionaryErr + end local e = Err.from(size, o) e.message = "brotli: " .. e.message return nil, e diff --git a/src/Rosetta/init.luau b/src/Rosetta/init.luau index ab7b81d..cc95a91 100644 --- a/src/Rosetta/init.luau +++ b/src/Rosetta/init.luau @@ -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 diff --git a/tools/bundle.py b/tools/bundle.py index ec6f066..eace924 100644 --- a/tools/bundle.py +++ b/tools/bundle.py @@ -249,14 +249,20 @@ def bundle_roblox(): # module with no entry yet requires its chunk (require(script:FindFirstChild(name)); under the luau CLI, with no # `script`, require("@self/" .. name) over the same files in build/_modules/chunked/Rosetta). So requiring the root # loads Core (what the root runs at load time) and every other chunk on first use, per Actor. -# Chunks: Core; one per hot codec (HOT); the rest packed per family (top folder, or codecs/) in path order. +# Chunks: Core; Detect (DETECT: what F.detect runs, apart from Core); one per hot codec (HOT); then one per unit (a +# format folder, a codec or container with its submodules), small neighbours of a family (top folder, or +# codecs/) packed up to UNIT_PACK bytes; a chunk is named after its first unit (image_png, containers_Riff). +# So opening a format compiles its own modules and what they use, not its family; F.detect compiles Detect alone +# (detect_check). # A --!native module's functions get @native (a chunk can mix native and non-native modules); a chunk with no native # module has none. Outputs: build/Rosetta.rbxm (LZ4, written by model/rbxm under the luau CLI), build/Rosetta.rbxmx, # build/Rosetta.rbxm.linemap.json ({chunk: [[first line, source file], ...]}). CHUNK_SRC_MAX = 256 * 1024 +UNIT_PACK = 32 * 1024 CHUNK_IR_MAX = 1 << 18 CHUNK_ASM_MAX = 4 << 20 CHUNKED = os.path.join(MODULES, "chunked", "Rosetta") +DETECT = ["Sniffs"] # F.detect: Sniffs.luau and what it requires at load time (core/Sniff), one small chunk HOT = [ ("Mpeg2", ["codecs/video/Mpeg2", "codecs/video/Mpeg1", "codecs/video/Dsp"]), ("H263", ["codecs/video/H263"]), @@ -303,6 +309,13 @@ def eager(src): return {m.group(1) for line in src.split("\n") if line[:1] not in ("\t", " ") for m in INCLUDES.finditer(line)} +def unit(key): + """what one format or shared module brings: its folder (image/png, containers/IsoBmff, codecs/text/Text), or the + module itself at the top level""" + parts = key.split("/") + return "/".join(parts[:3] if parts[0] == "codecs" else parts[:2]) + + def plan_chunks(mods): """[(chunk name, [module keys])], deterministic: Core, HOT, then the rest packed per family""" left = dict(mods) @@ -331,16 +344,31 @@ def plan_chunks(mods): core.add(k) todo += sorted(eager(mods[k][0])) pack("Core", sorted(core)) + detect, todo = set(), [k for k in DETECT if k in left] + while todo: + k = todo.pop() + if k in left and k not in detect: + detect.add(k) + todo += sorted(eager(mods[k][0])) + pack("Detect", sorted(detect)) for name, prefixes in HOT: keys = [k for k in left if any(under(k, p) for p in prefixes)] if not keys: sys.exit("bundle: HOT chunk %s matches no module" % name) pack(name, keys) - fams = {} + units = {} for k in left: - fams.setdefault(family(k), []).append(k) - for f in sorted(fams): - pack(f, fams[f]) + units.setdefault(unit(k), []).append(k) + run, size = [], 0 + for u in sorted(units, key=lambda u: (family(u), u)): + sz = sum(len(mods[k][0]) for k in units[u]) + if run and (family(run[0]) != family(u) or size + sz > UNIT_PACK): + pack(run[0].replace("/", "_"), [k for x in run for k in units[x]]) + run, size = [], 0 + run.append(u) + size += sz + if run: + pack(run[0].replace("/", "_"), [k for x in run for k in units[x]]) return chunks @@ -435,6 +463,7 @@ def bundle_chunked(mods, native, deps): if not text.startswith("--!optimize 2\n"): sys.exit("bundle: chunk %s does not start with --!optimize 2" % name) codegen_check([("Rosetta", root)] + sources, chunks, native) + detect_check(root, sources) write_rbxm(root, sources) @@ -482,6 +511,72 @@ def codegen_check(sources, chunks, native): if bad: sys.exit("bundle: chunk budget:\n " + "\n ".join(bad)) +# ------------------------------------------------------------------------------------------------ detect check +# F.detect on common inputs loads the Detect chunk only (DETECT_CASES: a header and a name), and Detect stays under +# DETECT_MAX source bytes: requiring the root and a first F.detect compile Core + Detect, nothing else. Run under the +# luau CLI on a copy of the chunked tree whose root records the chunks it requires. +DETECT_MAX = 160 * 1024 +DETECT_CASES = [ # (format, header, file name) + ("mp4", "\\0\\0\\0\\32ftypisom\\0\\0\\2\\0isomiso2avc1mp41\\0\\0\\0\\8free", "x.mp4"), + ("png", "\\137PNG\\r\\n\\26\\n\\0\\0\\0\\13IHDR\\0\\0\\0\\1\\0\\0\\0\\1\\8\\6\\0\\0\\0", "x.png"), + ("jpeg", "\\255\\216\\255\\224\\0\\16JFIF\\0\\1\\1\\0\\0\\1\\0\\1\\0\\0", "x.jpg"), + ("wav", "RIFF\\36\\0\\0\\0WAVEfmt \\16\\0\\0\\0\\1\\0\\1\\0\\68\\172\\0\\0\\136\\88\\1\\0\\2\\0\\16\\0", "x.wav"), + ("mp3", "ID3\\3\\0\\0\\0\\0\\0\\0\\255\\251\\144\\100", "x.mp3"), + ("vorbis", "OggS\\0\\2\\0\\0\\0\\0\\0\\0\\0\\0\\1\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\1\\30\\1vorbis", "x.ogg"), + ("gltf", "glTF\\2\\0\\0\\0\\20\\0\\0\\0", "x.glb"), + ("gif", "GIF89a\\1\\0\\1\\0\\0\\0\\0", "x.gif"), + ("zip", "PK\\3\\4\\20\\0\\0\\0\\0\\0", "x.zip"), + ("flac", "fLaC\\0\\0\\0\\34", "x.flac"), +] +DETECT_CHECK = """local F = require("./Rosetta") +local __ROSETTA_CHUNKS = F._chunksLoaded +local out = {} +for _, c in __CASES__ do + local before = #__ROSETTA_CHUNKS + local name = F.detect(buffer.fromstring(c[2]), { name = c[3] }) + local got = {} + for i = before + 1, #__ROSETTA_CHUNKS do + table.insert(got, __ROSETTA_CHUNKS[i]) + end + table.insert(out, c[1] .. "\\t" .. tostring(name) .. "\\t" .. table.concat(got, " ")) +end +print(table.concat(out, "\\n")) +""" + + +def detect_check(root, sources): + d = os.path.join(MODULES, "chunked", "detect_check") + shutil.rmtree(d, ignore_errors=True) + shutil.copytree(CHUNKED, os.path.join(d, "Rosetta")) + hook = "\trequire(m)(__FILES, __include)\n" + if hook not in root: + sys.exit("bundle: detect check: the root's chunk require changed") + with open(os.path.join(d, "Rosetta", "init.luau"), "w") as f: + f.write(root.replace(hook, "\ttable.insert(__CHUNKS_LOADED, name)\n" + hook).replace( + "local __FILES = {}", "local __CHUNKS_LOADED = {}\nlocal __FILES = {}", 1).replace( + "\nreturn Rosetta\n", "\nRosetta._chunksLoaded = __CHUNKS_LOADED\nreturn Rosetta\n")) + cases = "{ " + ", ".join('{ "%s", "%s", "%s" }' % c for c in DETECT_CASES) + " }" + with open(os.path.join(d, "check.luau"), "w") as f: + f.write(DETECT_CHECK.replace("__CASES__", cases)) + r = subprocess.run(tool("luau") + ["check.luau"], capture_output=True, text=True, cwd=d) + if r.returncode != 0: + sys.exit("bundle: detect check failed:\n" + (r.stdout + r.stderr)[-3000:]) + bad = [] + for line in r.stdout.strip().split("\n"): + case, name, got = (line.split("\t") + [""])[:3] + if name != case: + bad.append("%s detected as %s" % (case, name)) + if [x for x in got.split() if x != "Detect"]: + bad.append("detect %s loads chunks %s (only Detect: copy what its sniff reads, tools/sniff_extract.py)" + % (case, got)) + size = len(dict(sources)["Detect"]) + if size > DETECT_MAX: + bad.append("Detect: %d source bytes > %d" % (size, DETECT_MAX)) + if bad: + sys.exit("bundle: detect check:\n " + "\n ".join(bad)) + print("bundle: Rosetta.rbxm detect loads Detect only (%s), %.0f KB" % ( + ", ".join(c[0] for c in DETECT_CASES), size / 1024)) + def long_string(s): n = 0 diff --git a/tools/gen_registry.py b/tools/gen_registry.py index 6c1024b..5740c49 100644 --- a/tools/gen_registry.py +++ b/tools/gen_registry.py @@ -127,7 +127,7 @@ def sniffs(formats): "\t})", "end", "", - ] + ] + sniff_extract.shared_lines() for c in formats: if c["sniff_block"] is None: continue diff --git a/tools/sniff_extract.py b/tools/sniff_extract.py index 414ff58..1df1f6d 100644 --- a/tools/sniff_extract.py +++ b/tools/sniff_extract.py @@ -5,7 +5,14 @@ # loads the module to sniff it. Requires the copy reaches: core/* as they are; any other module through a proxy that # requires it on first field access (sniff time). # cost 0: the copy needs only core/*; 1: it reaches a proxied module; 2: not copied (the module sniffs). -import re +# A field the copy reads from a proxied module (Aac.adts, Zstd.MAGIC) is copied too when it reaches only core/*, +# literals and other such fields (of that module or of modules it requires; FIELD_MAX bytes at most per module): once, +# at the top of Sniffs.luau, onto the module's shared proxy, which then loads its module only for the fields left (a +# decoder). So detection runs Sniffs alone (build/Rosetta.rbxm: one small chunk), not the codecs behind the proxies. +import os, re + +SRC = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src", "Rosetta") +FIELD_MAX = 16384 KEYWORDS = set("and break continue do else elseif end false for function if in local nil not or repeat return then " "true until while type export typeof".split()) @@ -78,7 +85,9 @@ def statements(text): def free_names(code): - """identifiers read by code that are not field / method names (an over-approximation: locals are included)""" + """identifiers read by code that are not field / method names or table / type keys ({ name = ..., name: T }; an + over-approximation: locals are included)""" + code = re.sub(r"([{,]\s*)" + NAME + r"(\s*(=(?!=)|:\s))", r"\1\2", code) return {m.group(1) for m in re.finditer(r"(? [fields the sniffs read, fields left to the proxy]; one table per module at the top of Sniffs.luau +# (shared_lines), a lazy proxy when a field is left, with the copied fields set on it. +SHARED = {} +USED = set() # the modules the sniffs read (emit also adds what their copies read) + + +def shared_name(mod): + return "P_" + re.sub(r"\W", "_", mod) + + +def used_fields(alias, texts): + pat = re.compile(r"(?= 3 or not used or alias in free_names(" ".join( + re.sub(r"(? FIELD_MAX: + return None + return out, self_name, deps + + +def share(mod, fields, depth=0): + """registers fields of mod for Sniffs.luau; -> the fields left to the proxy""" + e = SHARED.setdefault(mod, [set(), set()]) + new = set(fields) - e[0] - e[1] + if new: + if field_statements(mod, sorted(new | e[0]), depth) is not None: + e[0] |= new + else: + for f in sorted(new): # each field alone: some may copy + if field_statements(mod, sorted(e[0] | {f}), depth) is not None: + e[0].add(f) + else: + e[1].add(f) + return set(fields) & e[1] + + +def reaches_left(mod, seen=None): + """a sniff reading mod may load a module (a field left to a proxy, there or in what the copies read)""" + seen = set() if seen is None else seen + if mod in seen: + return False + seen.add(mod) + copied, left = SHARED[mod] + got = field_statements(mod, sorted(copied), 0) if copied else None + return bool(left) or (got is not None and any(reaches_left(d, seen) for d in got[2])) + + +def shared_lines(): + """the top of Sniffs.luau: the shared proxies / copies, each after the modules its copies read""" + out, done = [], set() + + def emit(mod): + if mod in done: + return + done.add(mod) + copied, left = SHARED[mod] + got = field_statements(mod, sorted(copied), 0) if copied else ([], None, []) + body, self_name, deps = got + for d in deps: + emit(d) + name = shared_name(mod) + if left: + out.append('local %s = lazy(function()\n\treturn require("@rosetta/%s")\nend)' % (name, mod)) + else: + out.append("local %s: any = {}" % name) + if copied: + out.append("do -- %s: %s" % (mod, ", ".join(sorted(copied)))) + out.append("local %s = {}" % self_name) + out.extend(body) + out.extend("%s.%s = %s.%s" % (name, f, self_name, f) for f in sorted(copied)) + out.append("end") + out.append("") + + for mod in sorted(USED): + emit(mod) + return out def has_variant(text, self_name):