|
37 | 37 | Public data files can be requested from the author. |
38 | 38 | Private data files are not available due to size and copyright restrictions. |
39 | 39 |
|
40 | | -:Version: 2025.5.26 |
| 40 | +:Version: 2025.6.1 |
41 | 41 |
|
42 | 42 | """ |
43 | 43 |
|
@@ -17933,6 +17933,56 @@ def strips(): |
17933 | 17933 | assert_array_equal(imread(fname), data) |
17934 | 17934 |
|
17935 | 17935 |
|
| 17936 | +@pytest.mark.parametrize('compression', [1, 8]) |
| 17937 | +def test_write_iter_tiles_tuple(compression): |
| 17938 | + """Test write tiles from iterator of tuple of bytes and bytecount.""" |
| 17939 | + # https://github.com/cgohlke/tifffile/issues/301 |
| 17940 | + data = random_data(numpy.uint16, (5, 3, 15, 17)) |
| 17941 | + align = 4096 |
| 17942 | + |
| 17943 | + with TempFileName(f'write_iter_tiles_tuple_{compression}') as fname: |
| 17944 | + imwrite( |
| 17945 | + fname + 'f', |
| 17946 | + data, |
| 17947 | + tile=(16, 16), |
| 17948 | + compression=compression, |
| 17949 | + planarconfig='separate', |
| 17950 | + photometric='rgb', |
| 17951 | + ) |
| 17952 | + |
| 17953 | + def tiles(): |
| 17954 | + with TiffFile(fname + 'f') as tif: |
| 17955 | + fh = tif.filehandle |
| 17956 | + for page in tif.pages: |
| 17957 | + for offset, bytecount in zip( |
| 17958 | + page.dataoffsets, page.databytecounts |
| 17959 | + ): |
| 17960 | + fh.seek(offset) |
| 17961 | + strip = fh.read(bytecount) |
| 17962 | + strip += b'\x00' * (align - (len(strip) % align)) |
| 17963 | + assert len(strip) % align == 0 |
| 17964 | + yield strip, bytecount |
| 17965 | + |
| 17966 | + imwrite( |
| 17967 | + fname, |
| 17968 | + tiles(), |
| 17969 | + shape=data.shape, |
| 17970 | + dtype=data.dtype, |
| 17971 | + tile=(16, 16), |
| 17972 | + compression=compression, |
| 17973 | + planarconfig='separate', |
| 17974 | + photometric='rgb', |
| 17975 | + align=align, |
| 17976 | + ) |
| 17977 | + assert_array_equal(imread(fname), data) |
| 17978 | + with TiffFile(fname) as tif: |
| 17979 | + for page in tif.pages: |
| 17980 | + assert page.is_tiled |
| 17981 | + assert not page.is_contiguous |
| 17982 | + for offset in page.dataoffsets: |
| 17983 | + assert align % 4096 == 0 |
| 17984 | + |
| 17985 | + |
17936 | 17986 | @pytest.mark.parametrize('compression', [1, 8]) |
17937 | 17987 | @pytest.mark.parametrize('rowsperstrip', [5, 16]) |
17938 | 17988 | def test_write_iter_pages_none(compression, rowsperstrip): |
|
0 commit comments