tiffcrop: generation of strange section images
Summary and Steps to reproduce
tiffcrop -H 10 -V 10 -S 31:1 test\images\palette-1c-4b.tiff palette-1c-4b-sections31.tiff
The image width is 157 and length is 151. Thus we would expect thirty-one images with thirty images of fife columns and one last image with seven columns (157 / 31 = 5,06). However, the output generates 26 images with size of 6 columns x 151 rows and then one image with size 1 x 151 and four images with size 1 x 1.
Similar behaviour could be found for “-S 30:1” to “-S 21:1”. For 20 sections and below, the results are ok.
Analysis
The error seems to be in function computeOutputPixelOffsets()
, where the macro TIFFhowmany()
always rounds up but the code does not check for “rounding overflows” because the hidden assumption in the code is that for
y = TIFFhowmany(size, parts)
which equal to y = ceil( size / parts)
always (y-1) * parts <= size
is true. But this is not true for the above mentioned error cases.
Version
LibTiff, Version 4.3.0
Platform
Windows 10, x64, VisualStudio 2019 wit cmake