Clean up namespace pollution

This commit is contained in:
Přemysl Eric Janouch 2023-05-28 10:11:29 +02:00
parent 859736e5be
commit a710692725
Signed by: p
GPG Key ID: A0420B94F92B9493
3 changed files with 42 additions and 37 deletions

View File

@ -1197,7 +1197,7 @@ parse_mpf_index_ifd(struct tiffer *T)
struct tiffer_entry entry = {}; struct tiffer_entry entry = {};
while (tiffer_next_entry(T, &entry)) { while (tiffer_next_entry(T, &entry)) {
// 5.2.3.3. MP Entry // 5.2.3.3. MP Entry
if (entry.tag == MPF_MPEntry && entry.type == UNDEFINED && if (entry.tag == MPF_MPEntry && entry.type == TIFFER_UNDEFINED &&
!(entry.remaining_count % 16)) { !(entry.remaining_count % 16)) {
return parse_mpf_index_entries(T, &entry); return parse_mpf_index_entries(T, &entry);
} }
@ -2013,13 +2013,13 @@ load_tiff_ep(
// In any case, chained TIFFs are relatively rare. // In any case, chained TIFFs are relatively rare.
struct tiffer_entry entry = {}; struct tiffer_entry entry = {};
bool is_tiffep = tiffer_find(T, TIFF_TIFF_EPStandardID, &entry) && bool is_tiffep = tiffer_find(T, TIFF_TIFF_EPStandardID, &entry) &&
entry.type == BYTE && entry.remaining_count == 4 && entry.type == TIFFER_BYTE && entry.remaining_count == 4 &&
entry.p[0] == 1 && !entry.p[1] && !entry.p[2] && !entry.p[3]; entry.p[0] == 1 && !entry.p[1] && !entry.p[2] && !entry.p[3];
// Apple ProRAW, e.g., does not claim TIFF/EP compatibility, // Apple ProRAW, e.g., does not claim TIFF/EP compatibility,
// but we should still be able to make sense of it. // but we should still be able to make sense of it.
bool is_supported_dng = tiffer_find(T, TIFF_DNGBackwardVersion, &entry) && bool is_supported_dng = tiffer_find(T, TIFF_DNGBackwardVersion, &entry) &&
entry.type == BYTE && entry.remaining_count == 4 && entry.type == TIFFER_BYTE && entry.remaining_count == 4 &&
entry.p[0] == 1 && entry.p[1] <= 6 && !entry.p[2] && !entry.p[3]; entry.p[0] == 1 && entry.p[1] <= 6 && !entry.p[2] && !entry.p[3];
if (!is_tiffep && !is_supported_dng) { if (!is_tiffep && !is_supported_dng) {
set_error(error, "not a supported TIFF/EP or DNG image"); set_error(error, "not a supported TIFF/EP or DNG image");
@ -3714,7 +3714,7 @@ fiv_io_exif_orientation(const guint8 *tiff, gsize len)
while (tiffer_next_entry(&T, &entry)) { while (tiffer_next_entry(&T, &entry)) {
int64_t orientation = 0; int64_t orientation = 0;
if (G_UNLIKELY(entry.tag == TIFF_Orientation) && if (G_UNLIKELY(entry.tag == TIFF_Orientation) &&
entry.type == SHORT && entry.remaining_count == 1 && entry.type == TIFFER_SHORT && entry.remaining_count == 1 &&
tiffer_integer(&T, &entry, &orientation) && tiffer_integer(&T, &entry, &orientation) &&
orientation >= 1 && orientation <= 8) orientation >= 1 && orientation <= 8)
return orientation; return orientation;

View File

@ -170,31 +170,36 @@ tiffer_subifd(
} }
enum tiffer_type { enum tiffer_type {
BYTE = 1, ASCII, SHORT, LONG, RATIONAL, TIFFER_BYTE = 1, TIFFER_ASCII, TIFFER_SHORT, TIFFER_LONG,
SBYTE, UNDEFINED, SSHORT, SLONG, SRATIONAL, FLOAT, DOUBLE, TIFFER_RATIONAL,
IFD // This last type from TIFF Technical Note 1 isn't really used much. TIFFER_SBYTE, TIFFER_UNDEFINED, TIFFER_SSHORT, TIFFER_SLONG,
TIFFER_SRATIONAL,
TIFFER_FLOAT,
TIFFER_DOUBLE,
// This last type from TIFF Technical Note 1 isn't really used much.
TIFFER_IFD,
}; };
static size_t static size_t
tiffer_value_size(enum tiffer_type type) tiffer_value_size(enum tiffer_type type)
{ {
switch (type) { switch (type) {
case BYTE: case TIFFER_BYTE:
case SBYTE: case TIFFER_SBYTE:
case ASCII: case TIFFER_ASCII:
case UNDEFINED: case TIFFER_UNDEFINED:
return 1; return 1;
case SHORT: case TIFFER_SHORT:
case SSHORT: case TIFFER_SSHORT:
return 2; return 2;
case LONG: case TIFFER_LONG:
case SLONG: case TIFFER_SLONG:
case FLOAT: case TIFFER_FLOAT:
case IFD: case TIFFER_IFD:
return 4; return 4;
case RATIONAL: case TIFFER_RATIONAL:
case SRATIONAL: case TIFFER_SRATIONAL:
case DOUBLE: case TIFFER_DOUBLE:
return 8; return 8;
default: default:
return 0; return 0;
@ -232,25 +237,25 @@ tiffer_integer(
// TIFF 6.0 only directly suggests that a reader is should accept // TIFF 6.0 only directly suggests that a reader is should accept
// any of BYTE/SHORT/LONG for unsigned integers. // any of BYTE/SHORT/LONG for unsigned integers.
switch (entry->type) { switch (entry->type) {
case BYTE: case TIFFER_BYTE:
case ASCII: case TIFFER_ASCII:
case UNDEFINED: case TIFFER_UNDEFINED:
*out = *entry->p; *out = *entry->p;
return true; return true;
case SBYTE: case TIFFER_SBYTE:
*out = (int8_t) *entry->p; *out = (int8_t) *entry->p;
return true; return true;
case SHORT: case TIFFER_SHORT:
*out = self->un->u16(entry->p); *out = self->un->u16(entry->p);
return true; return true;
case SSHORT: case TIFFER_SSHORT:
*out = (int16_t) self->un->u16(entry->p); *out = (int16_t) self->un->u16(entry->p);
return true; return true;
case LONG: case TIFFER_LONG:
case IFD: case TIFFER_IFD:
*out = self->un->u32(entry->p); *out = self->un->u32(entry->p);
return true; return true;
case SLONG: case TIFFER_SLONG:
*out = (int32_t) self->un->u32(entry->p); *out = (int32_t) self->un->u32(entry->p);
return true; return true;
default: default:
@ -267,11 +272,11 @@ tiffer_rational(const struct tiffer *self, const struct tiffer_entry *entry,
// Somewhat excessively lenient, intended for display. // Somewhat excessively lenient, intended for display.
switch (entry->type) { switch (entry->type) {
case RATIONAL: case TIFFER_RATIONAL:
*numerator = self->un->u32(entry->p); *numerator = self->un->u32(entry->p);
*denominator = self->un->u32(entry->p + 4); *denominator = self->un->u32(entry->p + 4);
return true; return true;
case SRATIONAL: case TIFFER_SRATIONAL:
*numerator = (int32_t) self->un->u32(entry->p); *numerator = (int32_t) self->un->u32(entry->p);
*denominator = (int32_t) self->un->u32(entry->p + 4); *denominator = (int32_t) self->un->u32(entry->p + 4);
return true; return true;
@ -295,10 +300,10 @@ tiffer_real(
// Assuming the host architecture uses IEEE 754. // Assuming the host architecture uses IEEE 754.
switch (entry->type) { switch (entry->type) {
int64_t numerator, denominator; int64_t numerator, denominator;
case FLOAT: case TIFFER_FLOAT:
*out = *(float *) entry->p; *out = *(float *) entry->p;
return true; return true;
case DOUBLE: case TIFFER_DOUBLE:
*out = *(double *) entry->p; *out = *(double *) entry->p;
return true; return true;
default: default:

View File

@ -193,11 +193,11 @@ parse_exif_entry(jv o, const struct tiffer *T, struct tiffer_entry *entry,
double real = 0; double real = 0;
if (!entry->remaining_count) { if (!entry->remaining_count) {
v = jv_null(); v = jv_null();
} else if (entry->type == IFD || subentries) { } else if (entry->type == TIFFER_IFD || subentries) {
v = parse_exif_subifds(T, entry, subentries); v = parse_exif_subifds(T, entry, subentries);
} else if (entry->type == ASCII) { } else if (entry->type == TIFFER_ASCII) {
v = parse_exif_extract_sole_array_element(parse_exif_ascii(entry)); v = parse_exif_extract_sole_array_element(parse_exif_ascii(entry));
} else if (entry->type == UNDEFINED && !info->values) { } else if (entry->type == TIFFER_UNDEFINED && !info->values) {
// Several Exif entries of UNDEFINED type contain single-byte numbers. // Several Exif entries of UNDEFINED type contain single-byte numbers.
v = parse_exif_undefined(entry); v = parse_exif_undefined(entry);
} else if (tiffer_real(T, entry, &real)) { } else if (tiffer_real(T, entry, &real)) {
@ -682,7 +682,7 @@ parse_mpf_index_entry(jv o, uint32_t **offsets, const struct tiffer *T,
struct tiffer_entry *entry) struct tiffer_entry *entry)
{ {
// 5.2.3.3. MP Entry // 5.2.3.3. MP Entry
if (entry->tag != MPF_MPEntry || entry->type != UNDEFINED || if (entry->tag != MPF_MPEntry || entry->type != TIFFER_UNDEFINED ||
entry->remaining_count % 16) { entry->remaining_count % 16) {
return parse_exif_entry(o, T, entry, mpf_entries); return parse_exif_entry(o, T, entry, mpf_entries);
} }