Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
TIFF: reading the tags of a TIFF structured buffer

Data Structures

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

Macros

#define N_TIFF_MAGIC   42
 The magic of a plain TIFF file.
#define N_TIFF_MAGIC_DCP   0x4352
 The magic of an Adobe DCP camera profile, "RC" read little endian.

Functions

size_t n_tiff_count (const N_TIFF *tiff, uint16_t tag)
 How many values a tag has.
const N_TIFF_ENTRY * n_tiff_find (const N_TIFF *tiff, uint16_t tag)
 Find an entry by tag.
void n_tiff_free (N_TIFF **tiff)
 Release a parse, and set the pointer to NULL.
int n_tiff_get_ascii (const N_TIFF *tiff, uint16_t tag, char *out, size_t out_len)
 Read an ASCII tag.
size_t n_tiff_get_doubles (const N_TIFF *tiff, uint16_t tag, double *out, size_t max)
 Read a numeric tag as doubles.
N_TIFF * n_tiff_parse (const unsigned char *data, size_t len)
 Parse the first directory of a TIFF structured buffer.

Detailed Description


Data Structure Documentation

◆ N_TIFF

struct N_TIFF

The first directory of a TIFF structured buffer.

Examples
ex_tiff.c.

Definition at line 78 of file n_tiff.h.

Collaboration diagram for N_TIFF:
Data Fields
int big_endian 1 for "MM" (Motorola, big endian), 0 for "II"
size_t count how many
const unsigned char * data the buffer, borrowed
N_TIFF_ENTRY * entries the entries whose values lie inside the buffer, in file order
size_t len its length
uint16_t magic the 16 bit value after the byte order mark

◆ N_TIFF_ENTRY

struct N_TIFF_ENTRY

One directory entry.

Definition at line 66 of file n_tiff.h.

Collaboration diagram for N_TIFF_ENTRY:
Data Fields
uint32_t count number of values
size_t offset where the values start in the buffer, already checked to hold them
uint16_t tag tag number
uint16_t type TIFF field type, 1 BYTE to 12 DOUBLE.

Macro Definition Documentation

◆ N_TIFF_MAGIC

#define N_TIFF_MAGIC   42

The magic of a plain TIFF file.

Definition at line 61 of file n_tiff.h.

◆ N_TIFF_MAGIC_DCP

#define N_TIFF_MAGIC_DCP   0x4352

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

Examples
ex_tiff.c.

Definition at line 63 of file n_tiff.h.

Referenced by build(), and test_order().

Function Documentation

◆ n_tiff_count()

size_t n_tiff_count ( const N_TIFF * tiff,
uint16_t tag )

How many values a tag has.

Parameters
tiffthe parse
tagthe tag number
Returns
its count, 0 when the tag is not there

Definition at line 178 of file n_tiff.c.

References N_TIFF_ENTRY::count, and n_tiff_find().

Referenced by test_order().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_tiff_find()

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

Find an entry by tag.

Parameters
tiffthe parse
tagthe tag number
Returns
the first entry with that tag, or NULL

Definition at line 167 of file n_tiff.c.

References __n_assert, N_TIFF::count, N_TIFF::entries, and N_TIFF_ENTRY::tag.

Referenced by _from_tiff(), n_tiff_count(), n_tiff_get_ascii(), n_tiff_get_doubles(), and test_order().

Here is the caller graph for this function:

◆ n_tiff_free()

void n_tiff_free ( N_TIFF ** tiff)

Release a parse, and set the pointer to NULL.

The buffer is not touched.

Parameters
tiffaddress of the N_TIFF pointer, may point to NULL

Definition at line 160 of file n_tiff.c.

References Free, and FreeNoLog.

Referenced by _from_tiff(), list_file(), and test_order().

Here is the caller graph for this 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.

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

Parameters
tiffthe parse
tagthe tag number
outreceives the string
out_lensize of out, at least 1
Returns
0 when read, -1 when the tag is missing or not ASCII (out is then empty)

Definition at line 254 of file n_tiff.c.

References __n_assert, N_TIFF_ENTRY::count, N_TIFF::data, n_tiff_find(), N_TIFF_ENTRY::offset, and N_TIFF_ENTRY::type.

Referenced by test_order().

Here is the call graph for this function:
Here is the caller graph for this 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.

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

Parameters
tiffthe parse
tagthe tag number
outreceives up to max values
maxroom in out
Returns
how many values were written, 0 when the tag is missing or not numeric

Definition at line 184 of file n_tiff.c.

References __n_assert, _n_tiff_type_size(), _n_tiff_u16(), _n_tiff_u32(), _n_tiff_u64(), N_TIFF_ENTRY::count, N_TIFF::data, n_tiff_find(), N_TIFF_ENTRY::offset, and N_TIFF_ENTRY::type.

Referenced by test_order().

Here is the call graph for this function:
Here is the caller graph for this 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.

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

Parameters
datathe buffer, borrowed: it must outlive the result
lenits length in bytes
Returns
a new N_TIFF to release with n_tiff_free(), or NULL when the header or the directory is not readable

Definition at line 94 of file n_tiff.c.

References __n_assert, _n_tiff_type_size(), _n_tiff_u16(), _n_tiff_u32(), N_TIFF::big_endian, N_TIFF::count, N_TIFF_ENTRY::count, N_TIFF::data, N_TIFF::entries, Free, N_TIFF::len, N_TIFF::magic, Malloc, N_TIFF_MAX_ENTRIES, N_TIFF_ENTRY::offset, N_TIFF_ENTRY::tag, and N_TIFF_ENTRY::type.

Referenced by _from_tiff(), list_file(), test_broken(), and test_order().

Here is the call graph for this function:
Here is the caller graph for this function: