Re[Geotiff] ading the Value/Offset of an IFD Entry
noel.khan at rdmd.ocgov.com
Fri Dec 14 22:07:02 EST 2007
Quote "...how you to know whether the offset should be read as a
short integer vs. a long integer...."
All pointers are 4-byte LONG values; regardless of whether the pointer is
pointing to the next IFD or pointing to some tag's value.
Quote "...when the actual value of the tag will not fit into 4 bytes, then
the number represents the offset (in bytes) to where the value or values
Correct, the "Value" is actually a pointer if the size of the value is > 4
bytes. Note that this pointer is base-0 and from the beginning of the tiff
file, not from the current file position.
Quote "...the offset will always be either a 2-byte or 4-byte integer. Is
Negative. The offset/pointer will always be a LONG (4-bytes).
Quote "...The field type attribute tells you the data type of the tag value,
not the data type of offset value...."
See page 15 of the TIFF6 spec for a listing of data types and their sizes in
terms of bytes (hereinafter, "ByteSize"). Once you've read the field Type
and Count (a.k.a., "N"), the size of the tag's "Value" is calculated as:
If (ByteSize*N) > 4 bytes, then the "Value" is in fact a pointer to a value.
If (ByteSize*N) <= 4, then parse N number of DataTypes. Again, the number of
bytes per data type is known.
Quote "I'm writing a Fortran program .... must handle byte swapping in my
Fortran code when necessary."
:) I'm writing a program in VB6 that reads TIFF/GeoTIFF headers. To handle
byte order I:  utilize a function ReadNBytes(N) that reads N number of
bytes into a byte array.  That byte array is then passed by reference to
a function ByteArrayToNumber. It is here that I handle byte order: for MM, I
iterate through the bytes from 1...N; and for II from N...1.  Each
iteration, I pass each byte to a function named ByteToBitPattern, which
converts the byte into a string representation of bits.  Finally, I pass
my bit-string to a function BitPatternToValue that converts the bit-string
to a numerical value.
It may seem round-about, but it's the only way (I thought of) to create a
generic function that can read and return numerical values of any byte size
and in either order (MM/II) using Visual Basic 6.
So much fun.
However, I've been tearing my forlock out trying to figure out how Model
coordinates are encoded into the GeoTiff tags. If you've figured that out,
please share how.
View this message in context: http://www.nabble.com/Reading-the-Value-Offset-of-an-IFD-Entry-tp13428621p14339905.html
Sent from the GeoTIFF mailing list archive at Nabble.com.
More information about the Geotiff