summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2024-02-16 17:50:50 +0100
committerjaseg <git@jaseg.de>2024-02-16 17:50:50 +0100
commita843e706c507c67f34a392f58c6c34fadb67a938 (patch)
treeb4f390d403644ae6f57b92b289217cb0772e7c27 /src
parentff9c26b083a92b4149efa787f70696687ca91200 (diff)
downloadinfiray_irg_py-a843e706c507c67f34a392f58c6c34fadb67a938.tar.gz
infiray_irg_py-a843e706c507c67f34a392f58c6c34fadb67a938.tar.bz2
infiray_irg_py-a843e706c507c67f34a392f58c6c34fadb67a938.zip
Add support for "0xbaab" format variant
Diffstat (limited to 'src')
-rw-r--r--src/infiray_irg.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/infiray_irg.py b/src/infiray_irg.py
index 9d573f6..80d04b3 100644
--- a/src/infiray_irg.py
+++ b/src/infiray_irg.py
@@ -8,11 +8,14 @@ def load(data):
nonlocal data
out, data = data[:n], data[n:]
if len(out) < n:
- raise ValueError('file is truncated')
+ raise ValueError(f'File is truncated, tried to read {n} bytes, but only {len(out)} bytes remain.')
return out
header = consume(128)
- if header[:2] != bytes([0xca, 0xac]) or header[-2:] != bytes([0xac, 0xca]):
+ if header[:2] not in [
+ bytes([0xca, 0xac]),
+ bytes([0xba, 0xab])
+ ] or header[-2:] != bytes([0xac, 0xca]):
raise ValueError('Header magic not found.')
_unk0, coarse_section_length, y_res, x_res,\
@@ -28,9 +31,19 @@ def load(data):
raise ValueError('Resolution mismatch in header')
coarse_img = np.frombuffer(consume(coarse_section_length), dtype=np.uint8).reshape((y_res, x_res))
- fine_img = np.frombuffer(consume(x_res*y_res*2), dtype=np.int16).reshape((y_res, x_res))
- fine_img = (fine_img / 16) - 273
- vis_jpg = Image.open(io.BytesIO(consume(jpeg_length)))
+ if header[:2] == bytes([0xca, 0xac]):
+ # 1/16th Kelvin steps
+ fine_img = np.frombuffer(consume(x_res*y_res*2), dtype=np.uint16).reshape((y_res, x_res))
+ fine_img = (fine_img / 16) - 273
+
+ vis_jpg = Image.open(io.BytesIO(consume(jpeg_length)))
+
+ else: # 0xbaac variant
+ # 0.1 Kelvin steps
+ fine_img = np.frombuffer(consume(x_res*y_res*2), dtype=np.uint16).reshape((y_res, x_res))
+ fine_img = fine_img / 10 - 273
+
+ vis_jpg = Image.open(io.BytesIO(data))
return coarse_img, fine_img, vis_jpg