36#define N_TIFF_MAX_ENTRIES 4096
70 return (uint16_t)((p[0] << 8) | p[1]);
71 return (uint16_t)((p[1] << 8) | p[0]);
80 return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | (uint32_t)p[3];
81 return ((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16) | ((uint32_t)p[1] << 8) | (uint32_t)p[0];
91 return (hi << 32) | lo;
107 if (data[0] ==
'I' && data[1] ==
'I')
109 else if (data[0] ==
'M' && data[1] ==
'M')
117 if (ifd < 8 || ifd > len - 2) {
131 for (i = 0; i < count; i++) {
132 const unsigned char* e = data + ifd + 2 + i * 12;
141 if (size == 0 || entry.
count == 0)
144 if ((
size_t)entry.
count > len / size)
146 bytes = size * entry.
count;
149 entry.
offset = (size_t)(e + 8 - data);
171 for (i = 0; i < tiff->
count; i++) {
181 return entry ? entry->
count : 0;
192 if (!entry || entry->
type == 2 || entry->
type == 7)
195 for (i = 0; i < n; i++) {
198 switch (entry->
type) {
200 out[i] = (double)p[0];
203 out[i] = (double)(int8_t)p[0];
221 out[i] = den ? (double)num / (
double)den : 0.0;
228 out[i] = den ? (double)num / (
double)den : 0.0;
235 memcpy(&value, &bits,
sizeof(value));
236 out[i] = (double)value;
243 memcpy(&value, &bits,
sizeof(value));
265 if (!entry || entry->
type != 2)
267 n = entry->
count < out_len - 1 ? entry->
count : out_len - 1;
268 for (i = 0; i < n && tiff->
data[entry->
offset + i] !=
'\0'; i++)
static void type(N_GUI_CTX *gui, const char *s)
Type a whole string into whatever has focus.
#define FreeNoLog(__ptr)
Free Handler without log.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
size_t offset
where the values start in the buffer, already checked to hold them
N_TIFF_ENTRY * entries
the entries whose values lie inside the buffer, in file order
uint16_t type
TIFF field type, 1 BYTE to 12 DOUBLE.
const unsigned char * data
the buffer, borrowed
uint32_t count
number of values
int big_endian
1 for "MM" (Motorola, big endian), 0 for "II"
uint16_t magic
the 16 bit value after the byte order mark
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_count(const N_TIFF *tiff, uint16_t tag)
How many values a tag has.
size_t n_tiff_get_doubles(const N_TIFF *tiff, uint16_t tag, double *out, size_t max)
Read a numeric tag as doubles.
const N_TIFF_ENTRY * n_tiff_find(const N_TIFF *tiff, uint16_t tag)
Find an entry by tag.
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.
The first directory of a TIFF structured buffer.
Common headers and low-level functions & define.
static size_t _n_tiff_type_size(uint16_t type)
Bytes one value of a field type takes.
static uint64_t _n_tiff_u64(const N_TIFF *tiff, const unsigned char *p)
Read a 64 bit value in the buffer's byte order.
#define N_TIFF_MAX_ENTRIES
Most entries a directory is read for: a real TIFF directory holds tens, a DCP a few dozen; a count pa...
static uint16_t _n_tiff_u16(const N_TIFF *tiff, const unsigned char *p)
Read a 16 bit value in the buffer's byte order.
static uint32_t _n_tiff_u32(const N_TIFF *tiff, const unsigned char *p)
Read a 32 bit value in the buffer's byte order.
Reading the tags of a TIFF structured buffer.