From Python 2.7, I'm using pylibtiff developed by Pearu Peterson. I have installed libtiff3.dll in my path etc. I know that pylibtiff and libtiff are more than 5 years old, but it allows me to control the writing of TIFF files more than I can do with e.g. tiffile.py developed by Christoph Gohlke. I prefer to deal with the data row by row and this is possible when I use RowsPerStrip=1.
Thus I'm able to read TIFF files strip by strip but not to write in the same way. I'd like to write my data to disk in the same way, with data in a buffer of limited size. Eventually I hope to apply my code to large files. The second time the method TIFFWriteEncodedStrip is invoked via the libtiff method WriteEncodedStrip, a "WindowsError: exception: integer divide by zero" occurs. What am I doing wrong?
from libtiff import TIFF
width = 600
height = 600
tif = TIFF.open('filename.tif', mode='w')
tif.SetField("ImageWidth", width)
tif.SetField("ImageLength", height)
# Set CCITTFAX3 settings etc.
tif.SetField("ImageWidth", width)
tif.SetField("ImageLength", height)
tif.GetField("RowsPerStrip", 1)
...
for i in range(height):
# fill buffer
buf = ...
bytesPerStrip = math.ceil(width / 8)
tif.WriteEncodedStrip(i, buf.ctypes.data, int(bytesPerStrip))
tif.WriteDirectory()
tif.close()