imgA: JPEG-in-TIFF pixel check through F.load (image/jpeg via the decodeImage hook) against tifffile

This commit is contained in:
4DBug committed 2026-10-31 08:53:29 -05:00
1 parent fb3dc75282
commit 9b2bc84b39
2 files changed
+22 -2

No files matched your search

+9 -2
View File
@@ -1,7 +1,8 @@
# TIFF fixtures (tools/fixtures.py): files written by tifffile (+ imagecodecs) and ImageMagick, with references from
# tifffile's decode (the native sample arrays) turned into what image/tiff must produce.
# tests/gen/tiff.luau { cases = { { name, data, width, height, pages = { { crc, native, ncrc } } } },
# jpeg = { name, data } (a JPEG-compressed TIFF for the decodeImage hook test) }
# jpeg = data (a JPEG-compressed TIFF for the decodeImage hook test),
# jpegRef = { width, height, rgb } (tifffile + imagecodecs' libjpeg-turbo decode of it) }
# crc CRC-32 of the default rgba8 decode
# native / ncrc: the opts.native pixel format and the CRC-32 of its little-endian bytes
# Every case is decoded by tifffile; the expected pixels follow image/tiff's rules: unsigned samples v / (2^bits - 1),
@@ -191,6 +192,10 @@ for name, path in cases:
w, h = pages[0].imagewidth, pages[0].imagelength
emit(name.encode()); emit(open(path, "rb").read()); emit(("%d %d " % (w, h) + " ".join(info)).encode())
emit(open(jp, "rb").read())
with tifffile.TiffFile(jp) as t:
a = t.pages[0].asarray()
emit(("%d %d" % (a.shape[1], a.shape[0])).encode())
emit(np.ascontiguousarray(a[:, :, 0:3]).astype(np.uint8).tobytes())
'''
@@ -216,4 +221,6 @@ def generate(ctx):
crc, kind, ncrc = s.split(":")
pages.append({"crc": int(crc), "native": kind, "ncrc": int(ncrc)})
cases.append({"name": name.decode(), "data": data, "width": int(info[0]), "height": int(info[1]), "pages": pages})
ctx.emit("tiff", {"cases": cases, "jpeg": items[1 + count * 3]})
jw, jh = map(int, items[2 + count * 3].decode().split())
ctx.emit("tiff", {"cases": cases, "jpeg": items[1 + count * 3],
"jpegRef": {"width": jw, "height": jh, "rgb": items[3 + count * 3]}})