Classic TIFF IFD Entries: Distinguish Inline Values from File Offsets in a Drone Raster Review
Inspect a constructed classic TIFF directory entry using type size and count, handling inline bytes and external values without confusing metadata storage with raster validity.

Resolve the storage rule before following a pointer
A TIFF metadata review can go wrong before any raster pixels are decoded. The last four bytes of a classic image-file-directory entry can hold the value itself or an offset to values elsewhere in the file. Reading those bytes as a pointer in every case can send a small metadata value to an unrelated position. Reading them as values in every case can turn an address into invented sample metadata. Identify the type and count before choosing either interpretation.
This tutorial examines separately supplied twelve-byte entries and a tiny constructed file-byte buffer. It does not open a real orthomosaic, discover directories, decode image strips, or establish a NiVO export format. The catalogue photograph provides separate product context. The function supports only BYTE, SHORT, and LONG in classic TIFF, with a small count limit for the exercise. It demonstrates value storage and byte order, leaving image validity, geospatial meaning, complete directory structure, and receiving-application behavior to separate checks.
Read type size, value count, and byte order together
The TIFF 6.0 specification defines a classic directory entry with a tag, type, count, and four-byte value-or-offset slot. Count is the number of values rather than the total byte length. BYTE uses one byte, SHORT two, and LONG four. Multiply the selected type size by count to determine storage length. Values fitting within four bytes occupy the slot itself; shorter values begin at its lower-numbered bytes. Otherwise, the slot contains an offset measured from the beginning of the file.
In the little-endian constructed examples, two SHORT values occupy four bytes: 08 00 10 00 represents eight and sixteen inline. Three SHORT values need six bytes, so the slot 18 00 00 00 instead identifies file offset twenty-four, where the six value bytes reside. The same storage rule applies to big-endian data, but multibyte integers must follow that byte order. Do not select an interpretation by whether a number looks plausible; determine it from the entry metadata and the verified file context.

Product context only; this photograph does not depict the constructed examples in this article.
Inspect one supplied classic entry with bounded inputs
Run this Python example locally. Supply an immutable twelve-byte entry, immutable file bytes no larger than the teaching limit, and an explicit byte-order label. The function rejects unknown types, zero or excessive counts, and an external value extent outside the supplied buffer. It also checks the even alignment expected for external values. These restrictions make the example inspectable; they are not universal TIFF capacity limits. The caller remains responsible for verifying the actual file header and locating the entry correctly.
The function returns the tag, type, count, storage choice, optional file offset, and decoded unsigned values. Inline decoding slices only the bytes required by type and count, so unused slot bytes are not accidentally interpreted as another value. External decoding takes the declared number of bytes from the absolute file offset. The sample uses tag two hundred fifty-eight to demonstrate metadata storage, but the buffer is not a complete image and the code does not validate that tag against an actual image or sample layout.
import struct
def inspect_classic_entry(entry, file_bytes, byte_order):
if type(entry) is not bytes or len(entry) != 12:
raise ValueError("Expected one 12-byte classic entry")
if type(file_bytes) is not bytes or len(file_bytes) > 4096:
raise ValueError("Expected a small immutable teaching buffer")
if byte_order not in ("little", "big"):
raise ValueError("Supply verified classic TIFF byte order")
prefix = "<" if byte_order == "little" else ">"
tag, kind, count = struct.unpack(prefix + "HHI", entry[:8])
sizes = {1: (1, "B"), 3: (2, "H"), 4: (4, "I")}
if kind not in sizes or not 1 <= count <= 8:
raise ValueError("Unsupported type or teaching count")
size, code = sizes[kind]
needed = size * count
offset = None
if needed <= 4:
raw, storage = entry[8:8 + needed], "inline"
else:
offset = int.from_bytes(entry[8:12], byte_order)
if offset % 2 or offset + needed > len(file_bytes):
raise ValueError("Unaligned or out-of-bounds value extent")
raw, storage = file_bytes[offset:offset + needed], "offset"
return {"tag": tag, "type": kind, "count": count,
"storage": storage, "offset": offset,
"values": struct.unpack(prefix + str(count) + code, raw)}
# Constructed entries and buffer; not a complete TIFF image.
inline = struct.pack("<HHIHH", 258, 3, 2, 8, 16)
external = struct.pack("<HHII", 258, 3, 3, 24)
buffer = bytes(24) + struct.pack("<HHH", 8, 16, 32)
print(inspect_classic_entry(inline, buffer, "little"))
print(inspect_classic_entry(external, buffer, "little"))Test the four-byte boundary in both byte orders
Test SHORT counts one, two, and three. The first two take the inline path, while the third follows an offset. Test a single LONG as another exact four-byte inline case, and multiple LONG values as external data. Repeat with independently assembled big-endian bytes and compare the decoded values. The storage choice should depend on size and count, not on byte order. For a one-value SHORT case, change the unused two slot bytes and confirm that the single decoded value stays unchanged.
Include truncated entries, unsupported types, zero counts, odd offsets, and an external extent that ends beyond the available bytes. A declared extent ending exactly at the buffer boundary should remain readable. Keep failure cases as explicit errors rather than guessing another type, reversing byte order until a value looks familiar, or treating missing external bytes as zeros. Those repairs would change the interpretation without evidence. A limited reader should stop with the original bytes and a precise explanation of the unsupported or inconsistent input.
Keep this classic layout separate from full TIFF validation
The full TIFF header establishes byte order and points to the first directory. This function does neither job, and it does not follow the directory chain or check required fields, sorting, overlaps, or image-data references. An aligned in-bounds offset can still point to inappropriate bytes in a real file. Bounds checking demonstrates that bytes are available, not that their use is semantically correct. Preserve the actual directory location and file identity when applying the storage rule within a complete reader.
Do not apply this twelve-byte entry layout to BigTIFF. Likewise, decoding a field says nothing by itself about compression support, sample interpretation, map coordinates, or the usability of an orthomosaic. A metadata value may be structurally readable while disagreeing with another field or the receiving application. Keep those findings separate. For an actual delivery, use an established TIFF-aware tool alongside any isolated inspection, preserve its version and output, and verify the complete file against the requirements of the intended workflow.
The storage distinction also matters when discussing a proposed metadata copy. Copying twelve entry bytes into another file does not, by itself, copy the values referenced by an external offset. The same numeric address can identify unrelated bytes in the destination. Conversely, moving inline values does not require following that slot as an address. This tutorial performs no relocation or file editing. If an authorized workflow needs to rewrite a TIFF, use a complete format-aware writer and verify the resulting file separately rather than treating the small inspection function as a safe copying procedure.
Deliver the original bytes with an explicit storage trace
For a real raster handoff, retain the unchanged file identity, verified header byte order, directory and entry location, raw entry bytes, type size, count, computed length, storage path, external extent if used, and reader version. Include one independently checked boundary example. Record unsupported types and unresolved structural questions without converting them into fabricated metadata. A later reviewer should be able to distinguish a correct byte-level extraction from a separate claim about what the image represents or whether a delivery is acceptable.
In a NiVO-related raster review, this method explains why the same four-byte slot can contain two SHORT values in one entry and a file offset in another. It makes no claim about actual product output, surveyed terrain, customer imagery, or measurement accuracy. Preserve the original file and continue the independent image and geospatial checks needed for the real task. The useful result is a reproducible storage interpretation whose boundaries remain visible, rather than a plausible-looking metadata number obtained by following the wrong path.



