From 3e0b1762d15fc0ee4ce84e2fd2d8d4c81ee2cc3d Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 20 Apr 2024 18:26:42 +0100 Subject: [PATCH] Define TiffFieldType struct --- src/main.c | 2 +- src/tiff_field_types.inc | 28 ++++++++++++++-------------- src/tiffread.h | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 310c07a..0252f58 100644 --- a/src/main.c +++ b/src/main.c @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { printf("\t TAG: %04u (%s)\n", fields[i].tag, tag_names[fields[i].tag] ? tag_names[fields[i].tag] : "UNKNOWN"); printf("\t TYPE: 0x%04x (%s)\n", fields[i].type, - filed_type_names[fields[i].type] ? filed_type_names[fields[i].type] + filed_types[fields[i].type].name ? filed_types[fields[i].type].name : "UNKNOWN"); printf("\t COUNT: %04u\n", fields[i].count); printf("\tVAL/OFF: %04u\n", fields[i].value_offset); diff --git a/src/tiff_field_types.inc b/src/tiff_field_types.inc index 140233c..ce23a57 100644 --- a/src/tiff_field_types.inc +++ b/src/tiff_field_types.inc @@ -1,20 +1,20 @@ #ifdef TIFF_TYPE_LOOKUP #undef TIFF_TYPE -#define TIFF_TYPE(NAME, ID, VALUE) [VALUE] = NAME, +#define TIFF_TYPE(NAME, ID, VALUE, BYTES) [VALUE] = (TiffFieldType){.name = NAME, .byte_count = BYTES}, #else #undef TIFF_TYPE -#define TIFF_TYPE(NAME, ID, VALUE) ID = VALUE, +#define TIFF_TYPE(NAME, ID, VALUE, BYTES) ID = VALUE, #endif /* ifdef TIFF_TYPE_LOOKUP */ -TIFF_TYPE("UNSIGNED BYTE" , TIFF_ENTRY_BYTE , 0x0001) // 8-bit unsigned integer -TIFF_TYPE("ASCII" , TIFF_ENTRY_ASCII , 0x0002) // 8-bit byte that contains a 7-bit ASCII code; the last byte must be NUL (binary zero) -TIFF_TYPE("UNSIGNED SHORT" , TIFF_ENTRY_SHORT , 0x0003) // 16-bit (2-byte) unsigned integer -TIFF_TYPE("UNSIGNED LONG" , TIFF_ENTRY_LONG , 0x0004) // 32-bit (4-byte) unsigned integer -TIFF_TYPE("UNSIGNED RATIONAL", TIFF_ENTRY_RATIONAL , 0x0005) // Two LONGs: the first represents the numerator of a fraction; the second, the denominator -TIFF_TYPE("SIGNED BYTE" , TIFF_ENTRY_SBYTE , 0x0006) // An 8-bit signed (twos-complement) integer -TIFF_TYPE("UNDEFINED" , TIFF_ENTRY_UNDEFINED , 0x0007) // An 8-bit byte that may contain anything, depending on the definition of the field -TIFF_TYPE("SIGNED SHORT" , TIFF_ENTRY_SSHORT , 0x0008) // A 16-bit (2-byte) signed (twos-complement) integer -TIFF_TYPE("SIGNED LONG" , TIFF_ENTRY_SLONG , 0x0009) // A 32-bit (4-byte) signed (twos-complement) integer -TIFF_TYPE("SIGNED RATIONAL" , TIFF_ENTRY_SRATIONAL , 0x000a) // Two SLONG’s: the first represents the numerator of a fraction, the second the denominator -TIFF_TYPE("FLOAT" , TIFF_ENTRY_FLOAT , 0x000b) // Single precision (4-byte) IEEE format -TIFF_TYPE("DOUBLE" , TIFF_ENTRY_DOUBLE , 0x000c) // Double precision (8-byte) IEEE format +TIFF_TYPE("UNSIGNED BYTE" , TIFF_ENTRY_BYTE , 0x0001, 1) // 8-bit unsigned integer +TIFF_TYPE("ASCII" , TIFF_ENTRY_ASCII , 0x0002, 1) // 8-bit byte that contains a 7-bit ASCII code; the last byte must be NUL (binary zero) +TIFF_TYPE("UNSIGNED SHORT" , TIFF_ENTRY_SHORT , 0x0003, 2) // 16-bit (2-byte) unsigned integer +TIFF_TYPE("UNSIGNED LONG" , TIFF_ENTRY_LONG , 0x0004, 4) // 32-bit (4-byte) unsigned integer +TIFF_TYPE("UNSIGNED RATIONAL", TIFF_ENTRY_RATIONAL , 0x0005, 8) // Two LONGs: the first represents the numerator of a fraction; the second, the denominator +TIFF_TYPE("SIGNED BYTE" , TIFF_ENTRY_SBYTE , 0x0006, 1) // An 8-bit signed (twos-complement) integer +TIFF_TYPE("UNDEFINED" , TIFF_ENTRY_UNDEFINED , 0x0007, 1) // An 8-bit byte that may contain anything, depending on the definition of the field +TIFF_TYPE("SIGNED SHORT" , TIFF_ENTRY_SSHORT , 0x0008, 2) // A 16-bit (2-byte) signed (twos-complement) integer +TIFF_TYPE("SIGNED LONG" , TIFF_ENTRY_SLONG , 0x0009, 4) // A 32-bit (4-byte) signed (twos-complement) integer +TIFF_TYPE("SIGNED RATIONAL" , TIFF_ENTRY_SRATIONAL , 0x000a, 8) // Two SLONG’s: the first represents the numerator of a fraction, the second the denominator +TIFF_TYPE("FLOAT" , TIFF_ENTRY_FLOAT , 0x000b, 4) // Single precision (4-byte) IEEE format +TIFF_TYPE("DOUBLE" , TIFF_ENTRY_DOUBLE , 0x000c, 8) // Double precision (8-byte) IEEE format diff --git a/src/tiffread.h b/src/tiffread.h index 11a23ba..7b6ac1c 100644 --- a/src/tiffread.h +++ b/src/tiffread.h @@ -1,6 +1,10 @@ #ifndef TIFFREAD_H #define TIFFREAD_H +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + #include "aliases.h" #define TAG_MAX_COUNT (UINT16_MAX * sizeof(const char *)) @@ -37,7 +41,13 @@ enum tiff_field_types { #include "tiff_field_types.inc" }; -const char *filed_type_names[TYPE_MAX_COUNT] = { +typedef struct field_type TiffFieldType; +struct field_type { + const char *name; + u16 byte_count; +}; + +TiffFieldType filed_types[TYPE_MAX_COUNT] = { #define TIFF_TYPE_LOOKUP #include "tiff_field_types.inc" #undef TIFF_TYPE_LOOKUP @@ -84,4 +94,8 @@ enum tiff_photometric_interpretation { }; // clang-format on +#ifdef __cplusplus +} +#endif // __cplusplus + #endif // !TIFFREAD_H