layered formats: comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:52:39 -05:00
1 parent 0bd7b87d2b
commit 5d4addfc01
4 files changed
+33 -88

No files matched your search

+9 -17
View File
@@ -1,13 +1,7 @@
--!strict
-- layered/ora: OpenRaster (the OpenRaster 0.0.6 specification, freedesktop.org; new code): a zip (containers/Zip) with
-- a stored "mimetype" first, stack.xml (codecs/text/Xml), PNG layers, mergedimage.png and Thumbnails/thumbnail.png.
-- Decode: the stack tree (nested <stack> = groups: isolation="auto" is passThrough; <layer> name / src / x / y /
-- opacity / visibility / composite-op, svg:* ops mapped to the codecs/image/Blend names, unknown ones kept as written),
-- layers bottom to top as Types.Layered, the PNGs through the api hook opts.decodeImage (F.load passes it; without it:
-- UNSUPPORTED), mergedimage.png as meta.composite, the resolution (meta.dpi). Encode: a Layered (rgba8 layers, groups)
-- with every layer, the merged image (codecs/image/Blend flattens the tree, or opts.composite) and a thumbnail (up to
-- 256 px, nearest) as PNGs through opts.encodeImage. Not supported: non-PNG layer sources, the <text> / <filter> /
-- <selection> elements (ignored).
-- layered/ora: OpenRaster 0.0.6 (freedesktop.org; new code): a zip with a stored "mimetype" first, stack.xml, PNG
-- layers, mergedimage.png, Thumbnails/thumbnail.png. Supports: nested stacks (isolation="auto" = passThrough), layer
-- attributes, svg:* ops; PNGs via opts.decodeImage / encodeImage. Not supported: non-PNG sources, <text> / <filter>.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
@@ -29,14 +23,14 @@ local Ora = {
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = {
decodeImage: ((buffer) -> (Types.Image?, Err.Err?))?, -- decodes the PNG layers (the api passes one)
composite: boolean?, -- decode mergedimage.png into meta.composite (default true)
decodeImage: ((buffer) -> (Types.Image?, Err.Err?))?,
composite: boolean?, -- default true
maxLayers: number?, -- default 10000
}
export type EncodeOptions = {
encodeImage: ((Types.Image, string) -> (buffer?, Err.Err?))?, -- writes the PNGs (the api passes one)
composite: Types.Image?, -- the merged image (default: the layers flattened with codecs/image/Blend)
thumbnail: boolean?, -- write Thumbnails/thumbnail.png (default true)
encodeImage: ((Types.Image, string) -> (buffer?, Err.Err?))?,
composite: Types.Image?, -- default: the layers flattened
thumbnail: boolean?, -- default true
}
-- ------------------------------------------------------------------------------------------------ constants
@@ -110,7 +104,7 @@ function Ora.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Layered?, Err
end
return img, nil
end
-- a <stack>'s children, top first in the file -> bottom to top
-- stack.xml lists a <stack>'s children top first
local function stack(node: any, ox: number, oy: number): ({ Types.Layer }?, Err.Err?)
local out: { Types.Layer } = {}
for _, ch in node.children do
@@ -179,7 +173,6 @@ function Ora.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Layered?, Err
end
-- ------------------------------------------------------------------------------------------------ encode
-- nearest-neighbour downscale to fit max x max
local function thumbnail(img: Types.Image, max: number): Types.Image
local w, h = img.width, img.height
local s = math.min(1, max / math.max(w, h))
@@ -218,7 +211,6 @@ function Ora.encode(doc: Types.Layered, opts: EncodeOptions?): (buffer?, Err.Err
end
return data, nil
end
-- layers bottom to top -> xml children top first
local function stack(layers: { Types.Layer }): ({ any }?, Err.Err?)
local kids = {}
for i = #layers, 1, -1 do