Skip to content

Commit

Permalink
Handle detecting the need for big tiff in offsets.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Feb 22, 2021
1 parent 675d75c commit ce608a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Change Log

## Unreleased
- More tags
## Version 1.2.1

### Improvements
- More tags (#42)

### Bug fixes
- Better detect the need to write bigtiff files (#43)

## Version 1.2.0

Expand Down
17 changes: 17 additions & 0 deletions tests/test_write_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ def test_write_bigtiff_with_long_data(tmp_path):
assert destinfo['bigtiff'] is True


def test_write_bigtiff_with_offset_data(tmp_path):
path = datastore.fetch('hamamatsu.ndpi')
info = tifftools.read_tiff(path)
info['ifds'][0]['tags'][tifftools.Tag.FreeOffsets.value] = {
'datatype': tifftools.Datatype.LONG,
'data': [8] * 256,
}
info['ifds'][0]['tags'][tifftools.Tag.FreeByteCounts.value] = {
'datatype': tifftools.Datatype.LONG,
'data': [16777216] * 256,
}
destpath = tmp_path / 'sample.tiff'
tifftools.write_tiff(info, destpath)
destinfo = tifftools.read_tiff(destpath)
assert destinfo['bigtiff'] is True


def test_write_bytecount_data(tmp_path):
path = os.path.join(os.path.dirname(__file__), 'data', 'good_single.tif')
info = tifftools.read_tiff(path)
Expand Down
3 changes: 3 additions & 0 deletions tifftools/tifftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ def write_ifd(dest, bom, bigtiff, ifd, ifdPtr, tagSet=Tag):
else:
data = write_tag_data(
dest, src, data, [tag.bytecounts] * count, ifd['size'])
if not bigtiff and any(val for val in data if val >= 0x100000000):
raise MustBeBigTiffException(
'The file is large enough it must be in bigtiff format.')
taginfo = taginfo.copy()
taginfo['datatype'] = Datatype.LONG8 if bigtiff else Datatype.LONG
if not bigtiff and Datatype[taginfo['datatype']] in {Datatype.LONG8, Datatype.SLONG8}:
Expand Down

0 comments on commit ce608a8

Please sign in to comment.