diff options
Diffstat (limited to 'src/infiray_irg.py')
-rw-r--r-- | src/infiray_irg.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/infiray_irg.py b/src/infiray_irg.py index dfe0d0c..291dfe3 100644 --- a/src/infiray_irg.py +++ b/src/infiray_irg.py @@ -26,7 +26,7 @@ def load(data): raise ValueError(f'Header magic not found. Got header: {header[0]:02x} {header[1]:02x}') _unk0, coarse_section_length, y_res, x_res,\ - _zero0, _unk1, _zero1, fine_offset, _unk2, jpeg_length,\ + flag0, _unk1, _zero1, fine_offset, _unk2, jpeg_length,\ y_res_2, x_res_2, _unk3, = struct.unpack('<HIHHHHHHHIHHI', header[2:34]) fine_temp_offset1, fine_temp_offset2, *rest, high_gain_mode_flag = struct.unpack('<11I', header[34:78]) @@ -39,25 +39,31 @@ def load(data): # import textwrap # print(textwrap.dedent(f''' # {_unk0=}, {coarse_section_length=}, {y_res=}, {x_res=}, -# {_zero0=}, {_unk1=}, {_zero1=}, {fine_offset=}, {_unk2=}, {jpeg_length=}, +# {flag0=}, {_unk1=}, {_zero1=}, {fine_offset=}, {_unk2=}, {jpeg_length=}, # {y_res_2=}, {x_res_2=}, {_unk3=} # {fine_temp_offset1=} {fine_temp_offset1=} {rest=}, {high_gain_mode_flag=}''')) - if (x_res, y_res) != (x_res_2, y_res_2) and model != 'p200': - raise ValueError(f'Resolution mismatch in header: {x_res}*{y_res} != {x_res_2}*{y_res_2}') - if x_res*y_res != coarse_section_length: raise ValueError('Resolution mismatch in header') + vis_jpg = None if model == 'c201': if header[-2:] != bytes([0xac,0xca]): raise ValueError(f'Header end marker not found. Got header: {header[-2]:02x} {header[-1]:02x}') coarse_img = np.frombuffer(consume(coarse_section_length), dtype=np.uint8).reshape((y_res, x_res)) - # 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) - fine_temp_offset - vis_jpg = Image.open(io.BytesIO(consume(jpeg_length))) + if flag0 == 1: # Seen in Autel Robotics Evo II Dual 640T V3 file + fine_img = (fine_img / 64) - fine_temp_offset + + else: # C201 files + # 1/16th Kelvin steps + fine_img = (fine_img / 16) - fine_temp_offset + + if jpeg_length > 0: + # I have seen a file from an Autel Robotics Evo II Dual 640T V3 that looks like a C201 file, but lacks the + # visible data. + vis_jpg = Image.open(io.BytesIO(consume(jpeg_length))) elif model == 'other': if header[-2:] != bytes([0xab,0xba]): @@ -76,7 +82,6 @@ def load(data): fine_img = fine_img / 10 - fine_temp_offset # In my example file, data now contains the JSON '{"roi":[]}' and no JPG. We ignore that. - vis_jpg = None return coarse_img, fine_img, vis_jpg |