ws-cleanup: codecs/compress/PackBits; UTF-16 and half floats from one place

- codecs/compress/PackBits (new, from image/tiff/Pixels): decode (lenient count + a clean flag for strict callers)
  and encode; image/tiff and layered/psd (which carried its own decoder) use it. tests/codecs/packbits.
- codecs/text/Text.utf16(buf, offset, length, bigEndian?): the UTF-16 -> UTF-8 conversion codecs/font/TrueType,
  archive/7z and layered/psd each wrote (lone surrogates -> U+FFFD everywhere now).
- image/tiff/Pixels and data/cbor use core/Bytes.half instead of their own float16 decoders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-31 12:28:33 -05:00
1 parent 434a304315
commit 9bcf061338
13 files changed
+191 -178

No files matched your search

+2 -18
View File
@@ -6,6 +6,7 @@
-- domain / MIT) as a reference for cmap 4 and the GPOS walk.
--
-- Never throws: every read is range-checked (out of range reads as 0).
local Text = require("@formats/codecs/text/Text")
local Tables = {}
local readu8 = buffer.readu8
@@ -423,24 +424,7 @@ local MAC_ROMAN_HIGH = {
}
local function utf16be(b: buffer, o: number, n: number): string
local out = {}
local k = 0
while k + 1 < n do
local c = u16(b, o + k)
k += 2
if c >= 0xD800 and c < 0xDC00 and k + 1 < n then
local lo = u16(b, 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, utf8.char(c))
end
return table.concat(out)
return Text.utf16(b, o, n, true)
end
local function macRoman(b: buffer, o: number, n: number): string