ws-cleanup: codecs/ grouped by domain; containers/Chunks, codecs/audio/Stream, codecs/image/Pixels, codecs/model/Mat4
C2, the hierarchy (tools/move.py, every reference rewritten mechanically): - codecs/compress: Deflate Lzma Zstd Brotli Bzip2 Lzw; codecs/entropy: Huffman (from core) RangeCoder; codecs/image: Jpeg Dct Vp8 Vp8L Yuv Quantize Raster Blend Pixels; codecs/audio: Mdct Aac Alac Pcm Resample VorbisComment Tracker SoundFont Stream; codecs/video: H264 Mpeg1 Video; codecs/text: Json Xml Text Url; codecs/font: TrueType Cff; codecs/model: MeshFlatten Mat4. containers/ stays flat; core/ keeps Bytes Bits Err Crc32 Adler32 Base64 Md5 Input Sniff. - LAYERS lint: codecs must sit in a domain folder; gen_registry lists codecs by domain (docs/FORMATS.md). - Checked: build.py both targets, rojo build of build/roblox, the full suite on both runtimes. C3, generic code out of format folders: - containers/Chunks (new): the chunked-file walker (RIFF / RIFX / IFF / PNG / CAF layouts: endianness, size first, trailer, padding, lenient missing pad, open-ended ids, size hooks). containers/Riff walks with it (RF64 ds64 through the resize hook); image/png, audio/aiff and audio/caf list their chunk handlers over it. - codecs/audio/Stream (new): Stream.packets, the packet-decoder Decoder (read / seek with pre-roll / position, priming and end trimming) that aac, caf and m4a each carried (~70 lines each). - codecs/image/Pixels: image/bmp/Pixels promoted (+ rgb555); image/ico's DIB decoder uses its row loops instead of its own (the AND mask / alpha rule stay ICO's). - codecs/model/Mat4 (new): matrices / quaternions / TRS shared by FBX (Xform keeps only the FBX transform model), Collada (Math keeps only <lookat> / <skew>) and USD (its matrix helpers and general 4x4 inverse); Mat4.mul is Types.Scene.mul. The Collada normal matrix is now the inverse transpose (it was the inverse; same result for the fixtures' bind shapes). - README rewritten (install for Rojo and LÖVE / LuaJIT, quick start per category, F.* and F.ops, host notes: FORMATS_NO_JIT_TUNE, paths, layout); docs/STYLE.md: the codec domains, "what belongs in a format folder" with the shared building blocks and the DUP rule, conventions (WAVE order, lower-case tags, loops, the api hooks decodeImage / encodeImage / openAudio / plugins / resolve, the codecs/video/Video registry), Err.from, the type baseline. New tests: tests/containers/chunks, tests/codecs/mat4. Type baseline 93.
This commit is contained in:
1 parent
763f4a7c04
commit
51b08575c4
283 files changed
+1877
-1660
No files matched your search
@@ -1,247 +0,0 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- image/bmp/Pixels: the pixel loops (native), decode and encode. Absorbed from bmp-luau b86aed6 (same author, no
|
||||
-- third-party code); the encoder loops are new. They never throw: the caller (init.luau) validates every size first, and
|
||||
-- hands in a source buffer that holds every byte an uncompressed loop can read (a truncated file is copied into a
|
||||
-- zero-padded buffer). The RLE loop checks each read against its end offset. Output: RGBA8, top-down rows, one
|
||||
-- u32 per pixel (R | G << 8 | B << 16 | A << 24, little-endian = bytes R, G, B, A).
|
||||
local readu8, readu16, readu32, writeu32, writeu8 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.writeu32, buffer.writeu8
|
||||
local band, rshift, bor, lshift = bit32.band, bit32.rshift, bit32.bor, bit32.lshift
|
||||
|
||||
local Pixels = {}
|
||||
|
||||
-- 1, 2, 4 and 8 bpp through a 256-entry u32 palette (pal)
|
||||
function Pixels.indexed(src: buffer, base: number, stride: number, bpp: number, dst: buffer, w: number, h: number,
|
||||
topDown: boolean, pal: buffer)
|
||||
local mask = lshift(1, bpp) - 1
|
||||
for r = 0, h - 1 do
|
||||
local so = base + r * stride
|
||||
local d = (if topDown then r else h - 1 - r) * w * 4
|
||||
if bpp == 8 then
|
||||
for x = 0, w - 1 do
|
||||
writeu32(dst, d + x * 4, readu32(pal, readu8(src, so + x) * 4))
|
||||
end
|
||||
elseif bpp == 4 then
|
||||
for x = 0, w - 1 do
|
||||
local b = readu8(src, so + rshift(x, 1))
|
||||
local i = if band(x, 1) == 0 then rshift(b, 4) else band(b, 15)
|
||||
writeu32(dst, d + x * 4, readu32(pal, i * 4))
|
||||
end
|
||||
else
|
||||
for x = 0, w - 1 do
|
||||
local bit = x * bpp
|
||||
local b = readu8(src, so + rshift(bit, 3))
|
||||
local i = band(rshift(b, 8 - bpp - band(bit, 7)), mask)
|
||||
writeu32(dst, d + x * 4, readu32(pal, i * 4))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 24 bpp BI_RGB: B, G, R
|
||||
function Pixels.bgr24(src: buffer, base: number, stride: number, dst: buffer, w: number, h: number, topDown: boolean)
|
||||
for r = 0, h - 1 do
|
||||
local so = base + r * stride
|
||||
local d = (if topDown then r else h - 1 - r) * w * 4
|
||||
for x = 0, w - 1 do
|
||||
local s = so + x * 3
|
||||
writeu32(dst, d + x * 4,
|
||||
bor(readu8(src, s + 2), lshift(readu8(src, s + 1), 8), lshift(readu8(src, s), 16), 0xFF000000))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 32 bpp B, G, R, A (BI_RGB, or BITFIELDS with the standard masks). Returns the OR of every alpha byte.
|
||||
function Pixels.bgra32(src: buffer, base: number, stride: number, dst: buffer, w: number, h: number,
|
||||
topDown: boolean): number
|
||||
local aor = 0
|
||||
for r = 0, h - 1 do
|
||||
local so = base + r * stride
|
||||
local d = (if topDown then r else h - 1 - r) * w * 4
|
||||
for x = 0, w - 1 do
|
||||
local p = readu32(src, so + x * 4)
|
||||
-- swap R and B: B G R A -> R G B A
|
||||
writeu32(dst, d + x * 4, bor(band(p, 0xFF00FF00), band(rshift(p, 16), 0xFF), lshift(band(p, 0xFF), 16)))
|
||||
aor = bor(aor, p)
|
||||
end
|
||||
end
|
||||
return rshift(aor, 24)
|
||||
end
|
||||
|
||||
-- 16 / 24 / 32 bpp through bit masks. sh* = shift of each mask, m* = mask >> shift, t* = scale tables (u8, one entry
|
||||
-- per masked value). A channel without a mask has m = 0 and a 1-entry table (0 for colour, 255 for alpha).
|
||||
-- Returns the OR of every masked alpha value (before scaling).
|
||||
function Pixels.masked(src: buffer, base: number, stride: number, bpp: number, dst: buffer, w: number, h: number,
|
||||
topDown: boolean, shr: number, mr: number, tr: buffer, shg: number, mg: number, tg: buffer, shb: number,
|
||||
mb: number, tb: buffer, sha: number, ma: number, ta: buffer): number
|
||||
local bytes = rshift(bpp, 3)
|
||||
local aor = 0
|
||||
for r = 0, h - 1 do
|
||||
local so = base + r * stride
|
||||
local d = (if topDown then r else h - 1 - r) * w * 4
|
||||
for x = 0, w - 1 do
|
||||
local s = so + x * bytes
|
||||
local p
|
||||
if bytes == 2 then
|
||||
p = readu16(src, s)
|
||||
elseif bytes == 4 then
|
||||
p = readu32(src, s)
|
||||
else
|
||||
p = bor(readu16(src, s), lshift(readu8(src, s + 2), 16))
|
||||
end
|
||||
local a = band(rshift(p, sha), ma)
|
||||
aor = bor(aor, a)
|
||||
local o = d + x * 4
|
||||
writeu8(dst, o, readu8(tr, band(rshift(p, shr), mr)))
|
||||
writeu8(dst, o + 1, readu8(tg, band(rshift(p, shg), mg)))
|
||||
writeu8(dst, o + 2, readu8(tb, band(rshift(p, shb), mb)))
|
||||
writeu8(dst, o + 3, readu8(ta, a))
|
||||
end
|
||||
end
|
||||
return aor
|
||||
end
|
||||
|
||||
-- Sets every alpha byte to 255 (32-bit images whose alpha channel is all zero are opaque).
|
||||
function Pixels.opaque(dst: buffer, n: number)
|
||||
for i = 0, n - 1 do
|
||||
writeu8(dst, i * 4 + 3, 255)
|
||||
end
|
||||
end
|
||||
|
||||
-- RLE8 / RLE4 from src[pos, stop) into dst (pre-filled with transparent black; pixels the stream skips with a
|
||||
-- delta, an early end of line or an early end of bitmap stay transparent). Malformed or truncated data stops the
|
||||
-- decode and keeps what was drawn. Returns the number of pixels written.
|
||||
function Pixels.rle(src: buffer, pos: number, stop: number, rle4: boolean, dst: buffer, w: number, h: number,
|
||||
topDown: boolean, pal: buffer): number
|
||||
local x, y = 0, 0
|
||||
local written = 0
|
||||
local row = (if topDown then 0 else h - 1) * w * 4
|
||||
local rowStep = if topDown then w * 4 else -w * 4
|
||||
while y < h and pos + 1 < stop do
|
||||
local n = readu8(src, pos)
|
||||
local v = readu8(src, pos + 1)
|
||||
pos += 2
|
||||
if n > 0 then
|
||||
-- encoded run: n pixels of index v (RLE4: alternating high / low nibble)
|
||||
local e = math.min(x + n, w)
|
||||
if rle4 then
|
||||
local hi, lo = readu32(pal, rshift(v, 4) * 4), readu32(pal, band(v, 15) * 4)
|
||||
for i = x, e - 1 do
|
||||
writeu32(dst, row + i * 4, if band(i - x, 1) == 0 then hi else lo)
|
||||
end
|
||||
else
|
||||
local c = readu32(pal, v * 4)
|
||||
for i = x, e - 1 do
|
||||
writeu32(dst, row + i * 4, c)
|
||||
end
|
||||
end
|
||||
if e > x then
|
||||
written += e - x
|
||||
end
|
||||
x += n
|
||||
elseif v == 0 then
|
||||
-- end of line
|
||||
x = 0
|
||||
y += 1
|
||||
row += rowStep
|
||||
elseif v == 1 then
|
||||
break -- end of bitmap
|
||||
elseif v == 2 then
|
||||
-- delta: right dx, up (in file rows) dy
|
||||
if pos + 1 >= stop then
|
||||
break
|
||||
end
|
||||
local dx, dy = readu8(src, pos), readu8(src, pos + 1)
|
||||
pos += 2
|
||||
x += dx
|
||||
y += dy
|
||||
row += rowStep * dy
|
||||
else
|
||||
-- absolute run of v pixels, padded to a 16-bit boundary
|
||||
local nb = if rle4 then rshift(v + 1, 1) else v
|
||||
if pos + nb > stop then
|
||||
break
|
||||
end
|
||||
local e = math.min(x + v, w)
|
||||
for i = x, e - 1 do
|
||||
local k = i - x
|
||||
local idx
|
||||
if rle4 then
|
||||
local b = readu8(src, pos + rshift(k, 1))
|
||||
idx = if band(k, 1) == 0 then rshift(b, 4) else band(b, 15)
|
||||
else
|
||||
idx = readu8(src, pos + k)
|
||||
end
|
||||
writeu32(dst, row + i * 4, readu32(pal, idx * 4))
|
||||
end
|
||||
if e > x then
|
||||
written += e - x
|
||||
end
|
||||
x += v
|
||||
pos += nb + band(nb, 1)
|
||||
end
|
||||
end
|
||||
return written
|
||||
end
|
||||
|
||||
-- Encoder: rgba8 (top-down) -> 24 bpp BGR rows, bottom-up, each padded to stride (dst is zero-filled)
|
||||
function Pixels.encode24(src: buffer, w: number, h: number, dst: buffer, base: number, stride: number)
|
||||
for y = 0, h - 1 do
|
||||
local s = y * w * 4
|
||||
local d = base + (h - 1 - y) * stride
|
||||
for x = 0, w - 1 do
|
||||
local v = readu32(src, s + x * 4)
|
||||
writeu8(dst, d, band(rshift(v, 16), 255))
|
||||
writeu8(dst, d + 1, band(rshift(v, 8), 255))
|
||||
writeu8(dst, d + 2, band(v, 255))
|
||||
d += 3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- rgba8 -> 32 bpp BGRA, bottom-up
|
||||
function Pixels.encode32(src: buffer, w: number, h: number, dst: buffer, base: number)
|
||||
for y = 0, h - 1 do
|
||||
local s = y * w * 4
|
||||
local d = base + (h - 1 - y) * w * 4
|
||||
for x = 0, w - 1 do
|
||||
local v = readu32(src, s + x * 4)
|
||||
-- R G B A (little-endian u32: R | G << 8 | B << 16 | A << 24) -> B G R A
|
||||
writeu32(dst, d + x * 4, bor(band(v, 0xFF00FF00), band(rshift(v, 16), 255), lshift(band(v, 255), 16)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- rgba8 -> 8 bpp indexes through idx (a table colour -> index, colours as R | G << 8 | B << 16), bottom-up
|
||||
function Pixels.encode8(src: buffer, w: number, h: number, dst: buffer, base: number, stride: number, idx: { [number]: number })
|
||||
for y = 0, h - 1 do
|
||||
local s = y * w * 4
|
||||
local d = base + (h - 1 - y) * stride
|
||||
for x = 0, w - 1 do
|
||||
writeu8(dst, d + x, idx[band(readu32(src, s + x * 4), 0xFFFFFF)] or 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- colours(src, n, max) -> the distinct RGB colours in first-appearance order (R | G << 8 | B << 16), whether any
|
||||
-- alpha is below 255; stops counting at max + 1 colours
|
||||
function Pixels.colours(src: buffer, n: number, max: number): ({ number }, boolean)
|
||||
local seen: { [number]: boolean } = {}
|
||||
local list: { number } = {}
|
||||
local alpha = false
|
||||
for i = 0, n - 1 do
|
||||
local v = readu32(src, i * 4)
|
||||
if v < 0xFF000000 then
|
||||
alpha = true
|
||||
end
|
||||
local c = band(v, 0xFFFFFF)
|
||||
if #list <= max and not seen[c] then
|
||||
seen[c] = true
|
||||
list[#list + 1] = c
|
||||
end
|
||||
end
|
||||
return list, alpha
|
||||
end
|
||||
|
||||
return Pixels
|
||||
@@ -16,7 +16,7 @@
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Types = require("@formats/Types")
|
||||
local Pixels = require("@formats/image/bmp/Pixels")
|
||||
local Pixels = require("@formats/codecs/image/Pixels")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Bmp = {
|
||||
@@ -24,7 +24,7 @@ local Bmp = {
|
||||
category = "image",
|
||||
extensions = { "bmp", "dib" },
|
||||
mime = { "image/bmp", "image/x-bmp", "image/x-ms-bmp" },
|
||||
deps = { "core/Err", "core/Bytes", "Types" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/image/Pixels" },
|
||||
caps = { decode = true, encode = true, alpha = true, depths = { 1, 2, 4, 8, 16, 24, 32 }, rle = true },
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
-- (global / local colour tables, interlaced rows, LZW minimum code sizes 2..8 and the odd 1, transparency, frames
|
||||
-- smaller than or outside the canvas), animation (Graphic Control Extension delays, disposal none / background /
|
||||
-- previous, NETSCAPE2.0 / ANIMEXTS1.0 loop counts), comments (meta.text.comment); truncated files keep the frames
|
||||
-- read so far (meta.truncated). Encode of rgba8 images and animations (Types.Frame lists) through codecs/Quantize
|
||||
-- read so far (meta.truncated). Encode of rgba8 images and animations (Types.Frame lists) through codecs/image/Quantize
|
||||
-- (median cut or octree, optional Floyd-Steinberg dithering; exact palettes, so lossless, at <= 256 colours) with
|
||||
-- alpha < 128 as the transparent index.
|
||||
-- Not supported: the plain text extension (skipped), the aspect ratio (kept in meta.source.aspect), the "user input"
|
||||
@@ -17,8 +17,8 @@
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Lzw = require("@formats/codecs/Lzw")
|
||||
local Quantize = require("@formats/codecs/Quantize")
|
||||
local Lzw = require("@formats/codecs/compress/Lzw")
|
||||
local Quantize = require("@formats/codecs/image/Quantize")
|
||||
local Types = require("@formats/Types")
|
||||
local Decode = require("@formats/image/gif/Decode")
|
||||
|
||||
@@ -28,7 +28,7 @@ local Gif = {
|
||||
category = "image",
|
||||
extensions = { "gif" },
|
||||
mime = { "image/gif" },
|
||||
deps = { "core/Err", "core/Bytes", "codecs/Lzw", "codecs/Quantize", "Types" },
|
||||
deps = { "core/Err", "core/Bytes", "codecs/compress/Lzw", "codecs/image/Quantize", "Types" },
|
||||
caps = { decode = true, encode = true, animation = true, alpha = true, palette = true, depths = { 1, 2, 4, 8 } },
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
-- image/ico/Dib: the BMP device-independent bitmaps inside ICO / CUR entries (native; never throws). Written from
|
||||
-- the Microsoft ICO / BITMAPINFOHEADER documentation: a colour (XOR) bitmap of 1 / 4 / 8 / 16 (5-5-5) / 24 / 32-bit
|
||||
-- pixels, bottom-up rows padded to 4 bytes, then a 1-bit AND mask (1 = transparent). 32-bit entries use their alpha
|
||||
-- channel unless it is all zero (old icons), in which case the AND mask decides.
|
||||
local readu8, readu16, readu32, writeu32 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.writeu32
|
||||
-- channel unless it is all zero (old icons), in which case the AND mask decides. The row loops are
|
||||
-- codecs/image/Pixels (shared with BMP); the AND mask and the alpha rule are ICO's.
|
||||
local Pixels = require("@formats/codecs/image/Pixels")
|
||||
|
||||
local readu8, readu32, writeu32 = buffer.readu8, buffer.readu32, buffer.writeu32
|
||||
|
||||
local Dib = {}
|
||||
|
||||
@@ -18,29 +21,19 @@ function Dib.decode(b: buffer, p: number, e: number, w: number, h: number, bpp:
|
||||
end
|
||||
local hasMask = p + stride * h + maskStride * h <= e
|
||||
local anyAlpha = false
|
||||
for y = 0, h - 1 do
|
||||
local row = p + (h - 1 - y) * stride
|
||||
for x = 0, w - 1 do
|
||||
local v
|
||||
if bpp == 32 then
|
||||
v = readu8(b, row + x * 4 + 2) + readu8(b, row + x * 4 + 1) * 256 + readu8(b, row + x * 4) * 65536 + readu8(b, row + x * 4 + 3) * 16777216
|
||||
if v >= 16777216 then
|
||||
anyAlpha = true
|
||||
end
|
||||
elseif bpp == 24 then
|
||||
v = readu8(b, row + x * 3 + 2) + readu8(b, row + x * 3 + 1) * 256 + readu8(b, row + x * 3) * 65536 + 0xFF000000
|
||||
elseif bpp == 16 then
|
||||
local s = readu16(b, row + x * 2)
|
||||
local r, g, bl = (s // 1024) % 32, (s // 32) % 32, s % 32
|
||||
v = (r * 255 + 15) // 31 + ((g * 255 + 15) // 31) * 256 + ((bl * 255 + 15) // 31) * 65536 + 0xFF000000
|
||||
else
|
||||
local bit = x * bpp
|
||||
local byte = readu8(b, row + bit // 8)
|
||||
local idx = (byte // 2 ^ (8 - bpp - bit % 8)) % 2 ^ bpp
|
||||
v = if idx < palN then readu32(pal, idx * 4) else 0xFF000000
|
||||
end
|
||||
writeu32(out, (y * w + x) * 4, v)
|
||||
if bpp == 32 then
|
||||
anyAlpha = Pixels.bgra32(b, p, stride, out, w, h, false) ~= 0
|
||||
elseif bpp == 24 then
|
||||
Pixels.bgr24(b, p, stride, out, w, h, false)
|
||||
elseif bpp == 16 then
|
||||
Pixels.rgb555(b, p, stride, out, w, h, false)
|
||||
else
|
||||
-- palette indexes past palN read as opaque black
|
||||
local full = buffer.create(1024)
|
||||
for i = 0, 255 do
|
||||
writeu32(full, i * 4, if i < palN then readu32(pal, i * 4) else 0xFF000000)
|
||||
end
|
||||
Pixels.indexed(b, p, stride, bpp, out, w, h, false, full)
|
||||
end
|
||||
if bpp == 32 and anyAlpha then
|
||||
return true, nil
|
||||
|
||||
@@ -22,7 +22,7 @@ local Ico = {
|
||||
category = "image",
|
||||
extensions = { "ico", "cur" },
|
||||
mime = { "image/vnd.microsoft.icon", "image/x-icon" },
|
||||
deps = { "core/Err", "core/Bytes", "Types" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/image/Pixels" },
|
||||
caps = { decode = true, encode = true, alpha = true, frames = true, depths = { 1, 4, 8, 16, 24, 32 } },
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
--!strict
|
||||
-- image/jpeg: JPEG / JFIF / EXIF (ITU T.81), a thin format over codecs/Jpeg (the engine, shared with the Motion-JPEG
|
||||
-- image/jpeg: JPEG / JFIF / EXIF (ITU T.81), a thin format over codecs/image/Jpeg (the engine, shared with the Motion-JPEG
|
||||
-- video tracks; absorbed from jpeg-luau 1.0, same author, bit-exact with libjpeg-turbo's djpeg and byte-identical
|
||||
-- with cjpeg; IJG-derived parts: licenses/libjpeg-turbo-LICENSE.md). This module is the contract, the sniff, the
|
||||
-- options and the meta segments: meta.exif (APP1), meta.icc (APP2 chunks), meta.text.comment (COM) and meta.dpi
|
||||
@@ -20,7 +20,7 @@
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Types = require("@formats/Types")
|
||||
local Codec = require("@formats/codecs/Jpeg")
|
||||
local Codec = require("@formats/codecs/image/Jpeg")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Jpeg = {
|
||||
@@ -28,7 +28,7 @@ local Jpeg = {
|
||||
category = "image",
|
||||
extensions = { "jpg", "jpeg", "jpe", "jfif" },
|
||||
mime = { "image/jpeg" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/Jpeg" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/image/Jpeg" },
|
||||
caps = { decode = true, encode = true, lossy = true, alpha = false, depths = { 8, 12 }, progressive = true, arithmetic = true },
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Deflate = require("@formats/codecs/Deflate")
|
||||
local Deflate = require("@formats/codecs/compress/Deflate")
|
||||
local Types = require("@formats/Types")
|
||||
local Chunks = require("@formats/containers/Chunks")
|
||||
local Decode = require("@formats/image/png/Decode")
|
||||
local Encode = require("@formats/image/png/Encode")
|
||||
local Apng = require("@formats/image/png/Apng")
|
||||
@@ -26,7 +27,7 @@ local Png = {
|
||||
category = "image",
|
||||
extensions = { "png", "apng" },
|
||||
mime = { "image/png", "image/apng" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Crc32", "codecs/Deflate", "Types" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Crc32", "codecs/compress/Deflate", "Types", "containers/Chunks" },
|
||||
caps = { decode = true, encode = true, animation = true, alpha = true, depths = { 1, 2, 4, 8, 16 } },
|
||||
}
|
||||
|
||||
@@ -193,13 +194,15 @@ function Png.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
||||
local animPixels = 0
|
||||
local p = r.base + 8
|
||||
local first = true
|
||||
while p + 12 <= n do
|
||||
local len = be32(b, p)
|
||||
local typ = buffer.readstring(b, p + 4, 4)
|
||||
if len > n - p - 12 then
|
||||
for _, c in Chunks.walk(b, p, n, Chunks.PNG) do
|
||||
local len, typ, d = c.size, c.id, c.offset
|
||||
p = c.start
|
||||
if c.truncated then
|
||||
if p + 12 > n then
|
||||
break -- not even a whole chunk header + CRC left (a cut tail)
|
||||
end
|
||||
return nil, Err.new(Err.TRUNCATED, "chunk " .. typ .. " runs past the end", p)
|
||||
end
|
||||
local d = p + 8
|
||||
if checkCrc then
|
||||
local want = be32(b, d + len)
|
||||
if Crc32.raw(b, p + 4, len + 4) ~= want then
|
||||
@@ -305,7 +308,6 @@ function Png.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
||||
elseif bit32.band(readu8(b, p + 4), 0x20) == 0 and typ ~= "IHDR" then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "unknown critical chunk " .. typ, p)
|
||||
end
|
||||
p = d + len + 4
|
||||
end
|
||||
if #idat == 0 then
|
||||
return nil, Err.new(Err.TRUNCATED, "no image data", p)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
--!strict
|
||||
-- image/tiff: TIFF 6.0 (+ Adobe technote 3 floating point, BigTIFF). New code from the TIFF 6.0 specification.
|
||||
-- Decode: both byte orders, classic and BigTIFF, strips and tiles, planar configuration 1 and 2, compression none /
|
||||
-- LZW (codecs/Lzw, also old-style) / Deflate (8 and 32946, codecs/Deflate) / PackBits, JPEG (7) through the api's
|
||||
-- LZW (codecs/compress/Lzw, also old-style) / Deflate (8 and 32946, codecs/compress/Deflate) / PackBits, JPEG (7) through the api's
|
||||
-- opts.decodeImage hook (JPEGTables stitched to each strip / tile), predictors 2 (8 / 16 / 32-bit) and 3 (float),
|
||||
-- 1..32-bit unsigned / signed integer and 16 / 32 / 64-bit float samples, min-is-white / min-is-black, RGB, palette,
|
||||
-- CMYK (naive conversion), extra samples (associated alpha is un-premultiplied), fill order 2, every page as
|
||||
@@ -15,8 +15,8 @@
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Types = require("@formats/Types")
|
||||
local Deflate = require("@formats/codecs/Deflate")
|
||||
local Lzw = require("@formats/codecs/Lzw")
|
||||
local Deflate = require("@formats/codecs/compress/Deflate")
|
||||
local Lzw = require("@formats/codecs/compress/Lzw")
|
||||
local Pixels = require("@formats/image/tiff/Pixels")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
@@ -25,7 +25,7 @@ local Tiff = {
|
||||
category = "image",
|
||||
extensions = { "tif", "tiff" },
|
||||
mime = { "image/tiff" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/Deflate", "codecs/Lzw" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/compress/Deflate", "codecs/compress/Lzw" },
|
||||
caps = { decode = true, encode = true, alpha = true, pages = true, depths = { 1, 2, 4, 8, 16, 32 }, float = true },
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
-- image/webp/Alpha: the ALPH chunk (RFC 9649 section 2.7.1.2): header byte (compression, filter, pre-processing),
|
||||
-- raw or VP8L-compressed alpha (the green channel of a headerless VP8L stream), and the horizontal / vertical /
|
||||
-- gradient unfilters of libwebp src/dsp/filters.c (BSD-3-Clause, licenses/libwebp-LICENSE.txt). Never throws.
|
||||
local Vp8L = require("@formats/codecs/Vp8L")
|
||||
local Vp8L = require("@formats/codecs/image/Vp8L")
|
||||
|
||||
local readu8, writeu8 = buffer.readu8, buffer.writeu8
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--!strict
|
||||
-- image/webp: WebP (RFC 9649; Google's "WebP Container Specification"). New code: the bitstreams are ports of libwebp 1.6
|
||||
-- (codecs/Vp8, codecs/Vp8L; BSD-3-Clause, licenses/libwebp-LICENSE.txt), the chunks go through containers/Riff, the
|
||||
-- (codecs/image/Vp8, codecs/image/Vp8L; BSD-3-Clause, licenses/libwebp-LICENSE.txt), the chunks go through containers/Riff, the
|
||||
-- container rules and the compositing follow libwebp's demux / WebPAnimDecoder.
|
||||
-- Supports: decode of lossy (VP8 key frames: bit-exact with dwebp, fancy or point chroma upsampling, or the raw
|
||||
-- yuv420p planes with opts.native), lossless (VP8L, bit-exact), alpha (ALPH raw or lossless, every filter), the
|
||||
@@ -18,8 +18,8 @@
|
||||
local Err = require("@formats/core/Err")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Types = require("@formats/Types")
|
||||
local Vp8 = require("@formats/codecs/Vp8")
|
||||
local Vp8L = require("@formats/codecs/Vp8L")
|
||||
local Vp8 = require("@formats/codecs/image/Vp8")
|
||||
local Vp8L = require("@formats/codecs/image/Vp8L")
|
||||
local Riff = require("@formats/containers/Riff")
|
||||
local Alpha = require("@formats/image/webp/Alpha")
|
||||
local Anim = require("@formats/image/webp/Anim")
|
||||
@@ -30,7 +30,7 @@ local Webp = {
|
||||
category = "image",
|
||||
extensions = { "webp" },
|
||||
mime = { "image/webp" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/Vp8", "codecs/Vp8L", "containers/Riff" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/image/Vp8", "codecs/image/Vp8L", "containers/Riff" },
|
||||
caps = { decode = true, encode = true, animation = true, alpha = true, lossy = true, lossless = true, depths = { 8 } },
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ end
|
||||
-- subChunks(f, c) -> the chunks inside an ANMF payload (after its 16-byte header)
|
||||
local function subChunks(f: Riff.File, c: Chunk): ({ Chunk }?, Err.Err?)
|
||||
local n = c.size - 12
|
||||
return convert(Riff.list(f, { id = c.id, offset = c.off + 12, size = n, declared = n, avail = n, truncated = false, streamed = false }))
|
||||
return convert(Riff.list(f, { id = c.id, start = c.off + 4, offset = c.off + 12, size = n, declared = n, avail = n, truncated = false, streamed = false }))
|
||||
end
|
||||
|
||||
type Bitstream = { rgba: buffer?, yuv: Types.Image?, w: number, h: number, hasAlpha: boolean, source: { [string]: any } }
|
||||
|
||||
Reference in new issue
Block a user