6 Module N_TIFF
gullradriel edited this page 2026-10-25 10:46:33 +01:00

TIFF: reading the tags of a TIFF structured buffer

Structures

Name
struct N_TIFF_ENTRY
One directory entry.
struct N_TIFF
The first directory of a TIFF structured buffer.

Functions

Name
N_TIFF * n_tiff_parse_ifd(const unsigned char * data, size_t len, size_t ifd)
Parse a directory at a given offset of a TIFF structured buffer: a sub-directory such as EXIF's, whose offset another directory's pointer tag holds.
N_TIFF * n_tiff_parse(const unsigned char * data, size_t len)
Parse the first directory of a TIFF structured buffer.
size_t n_tiff_get_doubles(const N_TIFF * tiff, uint16_t tag, double * out, size_t max)
Read a numeric tag as doubles.
int n_tiff_get_ascii(const N_TIFF * tiff, uint16_t tag, char * out, size_t out_len)
Read an ASCII tag.
void n_tiff_free(N_TIFF ** tiff)
Release a parse, and set the pointer to NULL.
const N_TIFF_ENTRY * n_tiff_find(const N_TIFF * tiff, uint16_t tag)
Find an entry by tag.
size_t n_tiff_count(const N_TIFF * tiff, uint16_t tag)
How many values a tag has.

Defines

Name
N_TIFF_MAGIC_DCP
The magic of an Adobe DCP camera profile, "RC" read little endian.
N_TIFF_MAGIC
The magic of a plain TIFF file.

Functions Documentation

function n_tiff_parse_ifd

N_TIFF * n_tiff_parse_ifd(
    const unsigned char * data,
    size_t len,
    size_t ifd
)

Parse a directory at a given offset of a TIFF structured buffer: a sub-directory such as EXIF's, whose offset another directory's pointer tag holds.

Parameters:

  • data the buffer from its TIFF header, borrowed: it must outlive the result
  • len its length in bytes
  • ifd the directory's offset from the header, as a pointer tag gives it

Return: a new N_TIFF to release with n_tiff_free(), or NULL when the header or the directory is not readable

The byte order is the header's, as the offsets inside are relative to the header; the same checks as n_tiff_parse() apply.

function n_tiff_parse

N_TIFF * n_tiff_parse(
    const unsigned char * data,
    size_t len
)

Parse the first directory of a TIFF structured buffer.

Parameters:

  • data the buffer, borrowed: it must outlive the result
  • len its length in bytes

Return: a new N_TIFF to release with n_tiff_free(), or NULL when the header or the directory is not readable

Entries of an unknown type or whose values lie outside the buffer are skipped.

function n_tiff_get_doubles

size_t n_tiff_get_doubles(
    const N_TIFF * tiff,
    uint16_t tag,
    double * out,
    size_t max
)

Read a numeric tag as doubles.

Parameters:

  • tiff the parse
  • tag the tag number
  • out receives up to max values
  • max room in out

Return: how many values were written, 0 when the tag is missing or not numeric

BYTE, SHORT, LONG, RATIONAL and their signed forms, FLOAT and DOUBLE are converted; a rational with a zero denominator reads as 0.

function n_tiff_get_ascii

int n_tiff_get_ascii(
    const N_TIFF * tiff,
    uint16_t tag,
    char * out,
    size_t out_len
)

Read an ASCII tag.

Parameters:

  • tiff the parse
  • tag the tag number
  • out receives the string
  • out_len size of out, at least 1

Return: 0 when read, -1 when the tag is missing or not ASCII (out is then empty)

The string is cut to the first NUL and to out_len - 1 bytes, and always terminated.

function n_tiff_free

void n_tiff_free(
    N_TIFF ** tiff
)

Release a parse, and set the pointer to NULL.

Parameters:

  • tiff address of the N_TIFF pointer, may point to NULL

The buffer is not touched.

function n_tiff_find

const N_TIFF_ENTRY * n_tiff_find(
    const N_TIFF * tiff,
    uint16_t tag
)

Find an entry by tag.

Parameters:

  • tiff the parse
  • tag the tag number

Return: the first entry with that tag, or NULL

function n_tiff_count

size_t n_tiff_count(
    const N_TIFF * tiff,
    uint16_t tag
)

How many values a tag has.

Parameters:

  • tiff the parse
  • tag the tag number

Return: its count, 0 when the tag is not there

Macros Documentation

define N_TIFF_MAGIC_DCP

#define N_TIFF_MAGIC_DCP 0x4352

The magic of an Adobe DCP camera profile, "RC" read little endian.

define N_TIFF_MAGIC

#define N_TIFF_MAGIC 42

The magic of a plain TIFF file.