imgA: jpeg opts.native (grey files -> gray8); Dct local type annotations

This commit is contained in:
4DBug committed 2026-10-31 08:44:49 -05:00
1 parent d741722b52
commit 11ad899fa3
3 files changed
+16 -1

No files matched your search

+1 -1
View File
@@ -293,7 +293,7 @@ function Dct.fdctQuantize(src: buffer, stride: number, x: number, y: number, w:
local lastX, lastY = w - 1, h - 1
for r = 0, 7 do
local row = math.min(y + r, lastY) * stride
local d0, d1, d2, d3, d4, d5, d6, d7
local d0: number, d1: number, d2: number, d3: number, d4: number, d5: number, d6: number, d7: number
if x + 7 <= lastX then
local p = row + x
d0, d1, d2, d3 = readu8(src, p), readu8(src, p + 1), readu8(src, p + 2), readu8(src, p + 3)
+8
View File
@@ -34,6 +34,7 @@ local Jpeg = {
export type DecodeOptions = {
scale: number?, -- 1 (default), 2, 4 or 8: decode at ceil(size / scale) (8 reads the DC coefficients only)
orient: boolean?, -- apply the EXIF orientation (default false: reported in meta.orientation only)
native: boolean?, -- grey files decode to gray8 (default false: rgba8)
maxPixels: number?, -- refuse larger images (default 2^26)
}
export type EncodeOptions = {
@@ -160,6 +161,13 @@ function Jpeg.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.
end
local img = Types.Image.new(1, 1)
img.width, img.height, img.pixels = w, h, px
if opts and opts.native and space == "gray" then
local g = buffer.create(w * h)
for i = 0, w * h - 1 do
buffer.writeu8(g, i, buffer.readu8(px, i * 4))
end
img.pixels, img.format = g, "gray8"
end
local f = st.frame
local sampling = {}
for _, c in f.comps do