ws-cleanup: consistency (lower-case tags, WAVE channel order, loops = play count, Err messages, caps)

- Audio tags keys are lower case everywhere (Types.Tags): FLAC no longer returns TITLE / ARTIST (the raw fields stay
  in meta.source.comments; also for Vorbis and Opus); Vorbis / Opus / FLAC read and write tags through
  codecs/VorbisComment (TRACKNUMBER -> track, DISCNUMBER -> disc, DESCRIPTION -> comment); MP3 albumArtist ->
  albumartist and year -> date (ID3 TYER / TDRC, ID3v1); RIFF INFO / CAF / MP4 freeform names are lower-cased (MP4
  writes iTunSMPB / iTunNORM back in their usual spelling; m4a reads tags.itunsmpb).
- Channel order: Vorbis (and Opus mapping family 1) decode to WAVE order like FLAC / WAV / AAC (both used to return
  the Vorbis order); the Vorbis encoder takes WAVE order and writes Vorbis order. Pcm.WAVE_FROM_VORBIS / Pcm.reorder;
  Vorbis.packetDecoder gives pd.order. Tests reorder oggdec's / opusdec's raw (Vorbis-order) references.
- img.loops is the play count in GIF, APNG and WebP (they already agreed; Types / WebP docs said "loop count");
  tests/api round-trips loops 0 / 1 / 3 through all three.
- Err: messages without the format name (png / midi encoders said "png encode: ..."); codecs/Bzip2 and codecs/Zstd
  check arguments through Bytes.span.
- caps: mp3 encodeLayers = { 2, 3 }, opus encodeChannels = 2.
This commit is contained in:
4DBug committed 2026-10-31 11:01:22 -05:00
1 parent f784b4eb9b
commit c0eafd29a5
27 files changed
+164 -170

No files matched your search

+5 -5
View File
@@ -413,7 +413,7 @@ local function animationFrames(img: Types.Image, opts: EncodeOptions?): ({ Types
return nil, nil
end
if frames ~= nil and type(frames) ~= "table" then
return nil, Err.new(Err.ARG, "png encode: frames must be a list")
return nil, Err.new(Err.ARG, "frames must be a list")
end
if frames == nil or #frames == 0 then
if mode then
@@ -445,12 +445,12 @@ end
function Png.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
if not validImage(img) then
return nil, Err.new(Err.ARG, "png encode: needs an rgba8 Image")
return nil, Err.new(Err.ARG, "needs an rgba8 Image")
end
local w, h = img.width, img.height
local level = opts and opts.level or 6
if type(level) ~= "number" or level < 0 or level > 9 then
return nil, Err.new(Err.ARG, "png encode: level must be 0..9")
return nil, Err.new(Err.ARG, "level must be 0..9")
end
local frames, ferr = animationFrames(img, opts)
if ferr then
@@ -458,7 +458,7 @@ function Png.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
end
local loops = img.loops or 0
if frames and (type(loops) ~= "number" or loops < 0 or loops > 4294967295 or loops % 1 ~= 0) then
return nil, Err.new(Err.ARG, "png encode: loops must be an integer 0..2^32-1")
return nil, Err.new(Err.ARG, "loops must be an integer 0..2^32-1")
end
local want = opts and opts.colorType or "auto"
local ctName: string = want
@@ -480,7 +480,7 @@ function Png.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
end
local ct = CT_CODES[ctName]
if ct == nil then
return nil, Err.new(Err.ARG, "png encode: unknown colorType " .. tostring(want))
return nil, Err.new(Err.ARG, "unknown colorType " .. tostring(want))
end
local function zdata(im: Types.Image): buffer
return Deflate.zlibCompress(Encode.filter(im.pixels, im.width, im.height, ct), { level = level }) :: buffer
+1 -1
View File
@@ -49,7 +49,7 @@ export type EncodeOptions = {
lossless: boolean?, -- must be true or nil (lossy encoding is not supported)
effort: number?, -- 0..9, default 5: VP8L encoder effort (more = smaller, slower)
exact: boolean?, -- keep the RGB of fully transparent pixels (default false: they may be changed)
loops: number?, -- animations: loop count (default img.loops; 0 = forever)
loops: number?, -- animations: play count (default img.loops; 0 = forever)
background: { number }?, -- animations: ANIM background colour { r, g, b, a } (default meta.background or 0)
}