|
|
@@ -7,6 +7,7 @@ from io import BytesIO |
|
|
|
|
|
|
|
import enum |
|
|
|
import io |
|
|
|
import itertools |
|
|
|
import pathlib |
|
|
|
import string |
|
|
|
import struct |
|
|
@@ -941,14 +942,24 @@ TIFF_IFD_ENTRY_CNT = 4 # number of items returned by TIFF_IFD_ENTRY |
|
|
|
TIFF_IFD_OFFSET = 'I' |
|
|
|
|
|
|
|
def tiff_ifd(fh, endian, off): |
|
|
|
'''Iterated over the TIFF IFD that starts as off. |
|
|
|
|
|
|
|
yields the tag, data and the offset of the value if it |
|
|
|
did not fit in 4 bytes, otherwise None. |
|
|
|
|
|
|
|
When done, the tag will be None, and data will have the |
|
|
|
offset of the next IFD. |
|
|
|
''' |
|
|
|
|
|
|
|
fh.seek(off) |
|
|
|
cnt = readstruct(fh, endian + TIFF_IFD_CNT)[0] |
|
|
|
entries = readstruct(fh, endian + TIFF_IFD_ENTRY * cnt) |
|
|
|
nextifd = readstruct(fh, endian + TIFF_IFD_OFFSET)[0] |
|
|
|
|
|
|
|
entryiter = iter(entries) |
|
|
|
|
|
|
|
for i in range(cnt): |
|
|
|
tag, ttype, length, valoff = entries[i * |
|
|
|
TIFF_IFD_ENTRY_CNT:(i + 1) * TIFF_IFD_ENTRY_CNT] |
|
|
|
tag, ttype, length, valoff = itertools.islice(entryiter, TIFF_IFD_ENTRY_CNT) |
|
|
|
#print('t:', repr(tag), repr(ttype), repr(length), repr(valoff)) |
|
|
|
typefun, typequantum = tifftypes[ttype] |
|
|
|
blength = length * typequantum |
|
|
@@ -1071,7 +1082,7 @@ def idcrw(fh): |
|
|
|
hlen = readstruct(fh, endian + "H")[0] |
|
|
|
|
|
|
|
if hlen == 0x2a: |
|
|
|
#Tiff |
|
|
|
#TIFF/CR2 |
|
|
|
hoff, idstr, ver, hlen = readstruct(fh, endian + "I2sHI") |
|
|
|
if not isjpeg and (hoff != 0x10 or idstr != b'CR' or ver != 2): |
|
|
|
raise ValueError('normal TIFF, not a CR2') |
|
|
|