2006.08.29 20:44 "[Tiff] TiffReadEncodedStrip", by Richard Nolde
I am writing a tiffcrop utility (borrowing heavily from tiffcp) that will extract segments of a tiff file into a new file for use in OCR and barcode recognition programs.
Currently, I am reading the entire image into memory with TIFFReadEncodedStrip/Tile and then calculating the offsets into the buffer to pull the desired sections out of the image. IF I am reading a scanline I can assume that each call to TIFFReadScanline returns IMAGEWIDTH bytes of data with possibly padded bits, but when I read a series of encoded strips, I don't know how the ends of the scanline are handled in the buffer that comes back. A cropped section of a scanline from a bilevel image may not be a multiple of 8 pixels wide so it is important to know whether a strip as returned by TIFFReadEncodedStrip does the same thing or whether the last byte of a line in the image could also contain the first bits of the next line. In other words is a strip divided into scanlines on byte boundaries or is it a continuous bit stream from the beginning of the image to the end?
From what I have read in the current man pages and programs in the
tools directory, I assume that I can simple compute the start of each row as an offset from the beginning of the buffer. For 1 bit per sample data with one sample per pixel, something like ImageWidth / 8 bytes would be returned into the read buffer for each row in the image and the offset would be (row * IMAGEWIDTH) / (8 /bps) * samples per pixel for contiguous planes. This seems to imply that the last byte of a scanline is padded out to fill that byte. Is this correct?