AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2016.10.24 14:54 "Re: [Tiff] Question regarding tag StripOffsets when there is only one strip", by Recursive
2016.10.24 06:41 "[Tiff] Question regarding tag StripOffsets when there is only one strip", by Recursive
2016.10.24 11:01 "Re: [Tiff] Question regarding tag StripOffsets when there is only one strip", by Paavo Helde
2016.10.24 18:43 "Re: [Tiff] Question regarding tag StripOffsets when there is only one strip", by Paavo Helde
2016.10.25 08:53 "Re: [Tiff] Question regarding tag StripOffsets when there is only one strip", by Recursive

2016.10.24 11:01 "Re: [Tiff] Question regarding tag StripOffsets when there is only one strip", by Paavo Helde

On 24.10.2016 9:41, Recursive wrote:

Dear all,

yesterday, I have studied the TIFF specification mentioned on LibTiff's home page (http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf). That left me with a few questions. The first of them:

One one hand, the value of a StripOffsets tag is the offset to a table which in turn contains the offset for every strip of the image. This is logic and understandable.

The TIFF standard does not say that StripOffsets is an offset to a table. Instead, it says:

StripOffsets
Tag
= 273 (111.H)
Type = SHORT or LONG

For each strip, the byte offset of that strip.

So indeed, if these values fit in 4 bytes they are written directly in the IFD entry.

On the other hand, from page 15 of the specification mentioned above:

"Value/Offset

To save time and space the Value Offset contains the Value instead of pointing to the Value if and only if the Value fits into 4 bytes. If the Value is shorter than 4 bytes, it is left-justified within the 4-byte Value Offset, i.e., stored in the lowernumbered bytes. Whether the Value fits within 4 bytes is determined by the Type and Count of the field."

Now, if having LONG values for the offsets, if there is only one strip in the image, its offset would fit directly into the value field of the respective tag, so actually there is no need for a table of offsets. In that sense, I would have to put the offset of the strip directly into the value field of tag 273 if and only if there is exactly one strip in the image, but I would have to make a table containing the strip offsets and put the offset to that table into the value field of tag 273 if there is more than one strip.

To make things worse, there could be SHORT values for offsets as well. The situation would be like above, except that now two offsets would fit into the value field of tag 273 directly.

Yes, that's the case.

I just would like to know if I got this right, i.e. if I really need to implement a special treatment for images with only one strip (or two strips, depending on the type of the offsets). Of course, there are analogies to other tags (StripByteCounts, TileOffsets and so on), so this question is generally about how to handle tables when there is only one table entry.

You do not need to write special treatment for StripOffsets. Instead, you implement a general IFD entry reading function which for each IFD entry just calculates size-of(field type)*(field count) and then reads the data either from directly the IFD entry or from an offset, without any attention to the TIFF tag value.

In practice, I strongly suggest not to write your own TIFF processing code, but rather rely on libTIFF instead. There are lots of quirks and variations (e.g. BigTIFF) and the libTIFF implementation is the de facto standard.

Cheers
Paavo