ws-tex: docs/guide sections (textures / HDR, OpenRaster); DDS / KTX pixelFormat option; XBM / XPM names from F.save
F.save sets opts.format to the file format, so the DDS / KTX layout option is pixelFormat; XBM / XPM make a C identifier of opts.name (F.save passes the file name).
This commit is contained in:
1 parent
d618795ce7
commit
918c8310af
10 files changed
+90
-30
No files matched your search
@@ -40,7 +40,7 @@ export type DecodeOptions = {
|
||||
maxPixels: number?, -- refuse larger images (default 2^26, counted over every decoded surface)
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
format: ("rgba8" | "bgra8" | "bc1" | "bc3" | "bc4" | "bc5" | "rgba16" | "rgba16f" | "rgba32f")?, -- default:
|
||||
pixelFormat: ("rgba8" | "bgra8" | "bc1" | "bc3" | "bc4" | "bc5" | "rgba16" | "rgba16f" | "rgba32f")?, -- default:
|
||||
-- rgba8 for rgba8 images, rgba16 / rgba32f for rgba16 / rgbaf32 ones
|
||||
mips: boolean?, -- write a full mip chain (default false)
|
||||
dx10: boolean?, -- always write the DX10 header (default: only when the format needs it, or for arrays)
|
||||
@@ -440,13 +440,13 @@ function Dds.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
if pf ~= "rgba8" and pf ~= "rgba16" and pf ~= "rgbaf32" then
|
||||
return nil, Err.new(Err.ARG, "needs an rgba8, rgba16 or rgbaf32 Image (got " .. tostring(pf) .. ")")
|
||||
end
|
||||
local f: string = (opts and opts.format) or (if pf == "rgba8" then "rgba8" elseif pf == "rgba16" then "rgba16" else "rgba32f")
|
||||
local f: string = (opts and opts.pixelFormat) or (if pf == "rgba8" then "rgba8" elseif pf == "rgba16" then "rgba16" else "rgba32f")
|
||||
if not DX10_OUT[f] then
|
||||
return nil, Err.new(Err.ARG, "unknown format " .. tostring(f))
|
||||
return nil, Err.new(Err.ARG, "unknown pixelFormat " .. tostring(f))
|
||||
end
|
||||
local needs = if f == "rgba16" then "rgba16" elseif f == "rgba16f" or f == "rgba32f" then "rgbaf32" else "rgba8"
|
||||
if pf ~= needs then
|
||||
return nil, Err.new(Err.ARG, string.format("format %s needs an %s Image", f, needs))
|
||||
return nil, Err.new(Err.ARG, string.format("pixelFormat %s needs an %s Image", f, needs))
|
||||
end
|
||||
-- surfaces: the frames (array / cube faces) or the image
|
||||
local images: { Types.Image } = { img }
|
||||
|
||||
@@ -39,7 +39,7 @@ export type DecodeOptions = {
|
||||
maxPixels: number?, -- refuse larger images (default 2^26, over every decoded surface)
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
format: ("rgba8" | "rgba16" | "rgba16f" | "rgba32f")?, -- default: the image's own (rgbaf32 -> rgba32f)
|
||||
pixelFormat: ("rgba8" | "rgba16" | "rgba16f" | "rgba32f")?, -- default: the image's own (rgbaf32 -> rgba32f)
|
||||
srgb: boolean?, -- rgba8 as R8G8B8A8_SRGB (default: meta.colorSpace == "srgb")
|
||||
mips: boolean?, -- a full mip chain (box filter; default false)
|
||||
cube: boolean?, -- img.frames as cube faces (default: meta.layout == "cube")
|
||||
@@ -543,14 +543,14 @@ function Ktx.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
if pf ~= "rgba8" and pf ~= "rgba16" and pf ~= "rgbaf32" then
|
||||
return nil, Err.new(Err.ARG, "needs an rgba8, rgba16 or rgbaf32 Image (got " .. tostring(pf) .. ")")
|
||||
end
|
||||
local f: string = (opts and opts.format) or (if pf == "rgbaf32" then "rgba32f" else pf)
|
||||
local f: string = (opts and opts.pixelFormat) or (if pf == "rgbaf32" then "rgba32f" else pf)
|
||||
local spec = OUT[f]
|
||||
if not spec then
|
||||
return nil, Err.new(Err.ARG, "unknown format " .. tostring(f))
|
||||
return nil, Err.new(Err.ARG, "unknown pixelFormat " .. tostring(f))
|
||||
end
|
||||
local needs = if f == "rgba16f" or f == "rgba32f" then "rgbaf32" else f
|
||||
if pf ~= needs then
|
||||
return nil, Err.new(Err.ARG, string.format("format %s needs an %s Image", f, needs))
|
||||
return nil, Err.new(Err.ARG, string.format("pixelFormat %s needs an %s Image", f, needs))
|
||||
end
|
||||
local srgb = f == "rgba8" and (if opts and opts.srgb ~= nil then opts.srgb else (img.meta and img.meta.colorSpace == "srgb"))
|
||||
local images: { Types.Image } = { img }
|
||||
|
||||
@@ -26,7 +26,7 @@ export type DecodeOptions = {
|
||||
maxPixels: number?, -- refuse larger images (default 2^26)
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
name: string?, -- the C identifier prefix (default "image")
|
||||
name: string?, -- the C identifier prefix (default "image"; an extension is dropped, other characters become _)
|
||||
threshold: number?, -- luminance below this is black (default 128)
|
||||
}
|
||||
|
||||
@@ -120,9 +120,10 @@ function Xbm.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
if w < 1 or h < 1 then
|
||||
return nil, Err.new(Err.ARG, "bad size")
|
||||
end
|
||||
local name = opts and opts.name or "image"
|
||||
if not string.match(name, "^[%a_][%w_]*$") then
|
||||
return nil, Err.new(Err.ARG, "name must be a C identifier")
|
||||
-- a C identifier from opts.name (F.save passes the file name: "out.xbm" -> out)
|
||||
local name = string.gsub(string.gsub(opts and opts.name or "image", "%.[^.]*$", ""), "[^%w_]", "_")
|
||||
if name == "" or string.match(name, "^%d") then
|
||||
name = "_" .. name
|
||||
end
|
||||
local th = opts and opts.threshold or 128
|
||||
local px = img.pixels
|
||||
|
||||
@@ -28,7 +28,7 @@ export type DecodeOptions = {
|
||||
maxPixels: number?, -- refuse larger images (default 2^26)
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
name: string?, -- the C identifier (default "image")
|
||||
name: string?, -- the C identifier (default "image"; an extension is dropped, other characters become _)
|
||||
}
|
||||
|
||||
-- the characters of pixel codes (printable ASCII without '"' and '\')
|
||||
@@ -214,9 +214,10 @@ function Xpm.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
if w < 1 or h < 1 then
|
||||
return nil, Err.new(Err.ARG, "bad size")
|
||||
end
|
||||
local name = opts and opts.name or "image"
|
||||
if not string.match(name, "^[%a_][%w_]*$") then
|
||||
return nil, Err.new(Err.ARG, "name must be a C identifier")
|
||||
-- a C identifier from opts.name (F.save passes the file name: "out.xbm" -> out)
|
||||
local name = string.gsub(string.gsub(opts and opts.name or "image", "%.[^.]*$", ""), "[^%w_]", "_")
|
||||
if name == "" or string.match(name, "^%d") then
|
||||
name = "_" .. name
|
||||
end
|
||||
local px = img.pixels
|
||||
local index: { [number]: number } = {}
|
||||
|
||||
Reference in new issue
Block a user