ws-cleanup: F.ops facade (image / mesh / layers / audio / vector.rasterize) and ops/AudioOps
- F.ops in init.luau, loaded on first use: F.ops.image (ImageOps), F.ops.mesh (MeshOps), F.ops.layers (LayerOps), F.ops.audio (new ops/AudioOps), F.ops.vector.rasterize (the vector/svg renderer for any Vector, through F.format). - ops/AudioOps: toAudio / fromDecoder (Audio from a Decoder via codecs/Pcm), gain / gainDb / normalize, peak / rms, remix / downmix / upmix (WAVE-layout matrices, BS.775 coefficients normalised against clipping), resample (codecs/Resample), trim, concat and mix (inputs converted to the first one's rate and channels), fade. - tests/ops/audioops (39 checks, both runtimes); docs/API.md (new): the F.* API, F.ops, hooks, host. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
de2d615ec1
commit
086b0a7ffd
4 files changed
+781
No files matched your search
@@ -12,6 +12,7 @@
|
||||
-- local s = F.saveString(img, { format = "png" })
|
||||
-- local buf = F.convert(src, "png", opts?) -- load + save
|
||||
-- F.formats() -- the capability list (also docs/FORMATS.md)
|
||||
-- F.ops.image.resize(img, 64, 64) -- editing: F.ops.image / mesh / layers / audio / vector.rasterize
|
||||
--
|
||||
-- Never throws on bad data or bad arguments: every function returns nil, Err (Err.code, Err.message, tostring(err)).
|
||||
local Err = require("@formats/core/Err")
|
||||
@@ -679,4 +680,56 @@ F.model.loadTextures = function(scene: any, opts: Options?): (any, { [number]: E
|
||||
return scene, errs
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ ops
|
||||
-- F.ops: editing on the standard types, loaded on first use.
|
||||
-- F.ops.image ops/ImageOps convert, crop, resize, flip, rotate, blit / composite, coalesce, ...
|
||||
-- F.ops.mesh ops/MeshOps triangulate, transform, computeNormals / Tangents, weld, merge, meshVoxels, ...
|
||||
-- F.ops.layers ops/LayerOps flatten / flattenFrames a Layered (PSD, Aseprite), leaves
|
||||
-- F.ops.audio ops/AudioOps toAudio, gain / gainDb / normalize, mix, remix / downmix / upmix, resample, trim,
|
||||
-- concat, fade, peak, rms
|
||||
-- F.ops.vector.rasterize(vector, w?, h?, opts?) -> rgba8 Image: the SVG renderer (vector/svg) for any Vector
|
||||
local OPS: { [string]: () -> any } = {
|
||||
image = function()
|
||||
return ImageOps
|
||||
end,
|
||||
mesh = function()
|
||||
return require("@formats/ops/MeshOps")
|
||||
end,
|
||||
layers = function()
|
||||
return require("@formats/ops/LayerOps")
|
||||
end,
|
||||
audio = function()
|
||||
return require("@formats/ops/AudioOps")
|
||||
end,
|
||||
vector = function()
|
||||
return {
|
||||
rasterize = function(v: any, w: number?, h: number?, opts: any?): (any, Err.Err?)
|
||||
local svg, err = F.format("svg")
|
||||
if not svg then
|
||||
return nil, err
|
||||
end
|
||||
local ok, img, rerr = pcall(svg.rasterize, v, w, h, opts)
|
||||
if not ok then
|
||||
return nil, Err.wrap(Err.new(Err.CORRUPT, "rasterize threw: " .. tostring(img)), "svg")
|
||||
end
|
||||
if img == nil and rerr then
|
||||
return nil, Err.wrap(rerr, "svg")
|
||||
end
|
||||
return img, rerr
|
||||
end,
|
||||
}
|
||||
end,
|
||||
}
|
||||
F.ops = setmetatable({}, {
|
||||
__index = function(t: any, k: string): any
|
||||
local make = OPS[k]
|
||||
if not make then
|
||||
return nil
|
||||
end
|
||||
local m = make()
|
||||
rawset(t, k, m)
|
||||
return m
|
||||
end,
|
||||
}) :: any
|
||||
|
||||
return F
|
||||
Reference in new issue
Block a user