2005.08.03 08:00 "[Tiff] Padding", by anil kumar

2005.08.03 14:32 "Re: [Tiff] Padding", by Andrey Kiselev

On Wed, Aug 03, 2005 at 09:55:47AM -0400, Frank Warmerdam wrote:

  1. I need to get the count/information of "DIB padding" bytes from a tiff file, which tag should I use to extract this information

Are you asking what sort of padding is used in TIFF scanlines on disk? There is no explicit tag addressing this, but there are rules.

My understanding based on a quick review of my own code, and a vague recollection is that each scanline of data is passed out to the nearest byte but that there is never a whole byte of passing space. The intent I gather is to ensure that each scanline starts on a byte boundary. Of course, for 8bit imagery this is already the case so there is no padding.

In addition there is a quote from the specification (see the Compression
tag definition):

1 = No compression, but pack data into bytes as tightly as possible leaving
    no unused bits except at the end of a row.

If Then the sample values are stored
                                         as an array of type:

    BitsPerSample = 16 for all samples                         SHORT
    BitsPerSample = 32 for all samples                         LONG
    Otherwise                                                  BYTE

Each row is padded to the next BYTE/SHORT/LONG boundary, consistent with the preceding BitsPerSample rule.

If the image data is stored as an array of SHORTs or LONGs, the byte ordering must be consistent with that specified in bytes 0 and 1 of the TIFF file header. Therefore, little-endian format files will have the least significant bytes preceding the most significant bytes, while big-endian format files will have the opposite order.

If the number of bits per component is not a power of 2, and you are willing to give up some space for better performance, use the next higher power of 2. For example, if your data can be represented in 6 bits, set BitsPerSample to 8 instead of 6, and then convert the range of the values from [0,63] to [0,255].

Rows must begin on byte boundaries. (SHORT boundaries if the data is stored as SHORTs, LONG boundaries if the data is stored as LONGs).

Some graphics systems require image data rows to be word-aligned or double-word-aligned, and padded to word-boundaries or double-word boundaries. Uncompressed TIFF rows will need to be copied into word-aligned or double-word-aligned row buffers before being passed to the graphics routines in these environments.

Things become a bit more complicated in case of tiled image.


Andrey V. Kiselev

Home phone: +7 812 5970603 ICQ# 26871517