Define TiffFieldType struct
This commit is contained in:
		| @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { | |||||||
|     printf("\t    TAG: %04u (%s)\n", fields[i].tag, |     printf("\t    TAG: %04u (%s)\n", fields[i].tag, | ||||||
|            tag_names[fields[i].tag] ? tag_names[fields[i].tag] : "UNKNOWN"); |            tag_names[fields[i].tag] ? tag_names[fields[i].tag] : "UNKNOWN"); | ||||||
|     printf("\t   TYPE: 0x%04x (%s)\n", fields[i].type, |     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"); |                                             : "UNKNOWN"); | ||||||
|     printf("\t  COUNT: %04u\n", fields[i].count); |     printf("\t  COUNT: %04u\n", fields[i].count); | ||||||
|     printf("\tVAL/OFF: %04u\n", fields[i].value_offset); |     printf("\tVAL/OFF: %04u\n", fields[i].value_offset); | ||||||
|   | |||||||
| @@ -1,20 +1,20 @@ | |||||||
| #ifdef TIFF_TYPE_LOOKUP | #ifdef TIFF_TYPE_LOOKUP | ||||||
| #undef TIFF_TYPE | #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 | #else | ||||||
| #undef TIFF_TYPE | #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 */ | #endif /* ifdef TIFF_TYPE_LOOKUP */ | ||||||
|  |  | ||||||
| TIFF_TYPE("UNSIGNED BYTE"    , TIFF_ENTRY_BYTE      , 0x0001) // 8-bit unsigned integer | TIFF_TYPE("UNSIGNED BYTE"    , TIFF_ENTRY_BYTE      , 0x0001, 1) // 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("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) // 16-bit (2-byte) unsigned integer | TIFF_TYPE("UNSIGNED SHORT"   , TIFF_ENTRY_SHORT     , 0x0003, 2) // 16-bit (2-byte) unsigned integer | ||||||
| TIFF_TYPE("UNSIGNED LONG"    , TIFF_ENTRY_LONG      , 0x0004) // 32-bit (4-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) // Two LONGs: the first represents the numerator of a fraction; the second, the denominator | 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) // An 8-bit signed (twos-complement) integer | TIFF_TYPE("SIGNED BYTE"      , TIFF_ENTRY_SBYTE     , 0x0006, 1) // 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("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) // A 16-bit (2-byte) signed (twos-complement) integer | 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) // A 32-bit (4-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) // Two SLONG’s: the first represents the numerator of a fraction, the second the denominator | 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) // Single precision (4-byte) IEEE format | TIFF_TYPE("FLOAT"            , TIFF_ENTRY_FLOAT     , 0x000b, 4) // Single precision (4-byte) IEEE format | ||||||
| TIFF_TYPE("DOUBLE"           , TIFF_ENTRY_DOUBLE    , 0x000c) // Double precision (8-byte) IEEE format | TIFF_TYPE("DOUBLE"           , TIFF_ENTRY_DOUBLE    , 0x000c, 8) // Double precision (8-byte) IEEE format | ||||||
|   | |||||||
| @@ -1,6 +1,10 @@ | |||||||
| #ifndef TIFFREAD_H | #ifndef TIFFREAD_H | ||||||
| #define TIFFREAD_H | #define TIFFREAD_H | ||||||
|  |  | ||||||
|  | #ifdef __cplusplus | ||||||
|  | extern "C" { | ||||||
|  | #endif // __cplusplus | ||||||
|  |  | ||||||
| #include "aliases.h" | #include "aliases.h" | ||||||
|  |  | ||||||
| #define TAG_MAX_COUNT (UINT16_MAX * sizeof(const char *)) | #define TAG_MAX_COUNT (UINT16_MAX * sizeof(const char *)) | ||||||
| @@ -37,7 +41,13 @@ enum tiff_field_types { | |||||||
|   #include "tiff_field_types.inc" |   #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 |   #define TIFF_TYPE_LOOKUP | ||||||
|   #include "tiff_field_types.inc" |   #include "tiff_field_types.inc" | ||||||
|   #undef TIFF_TYPE_LOOKUP |   #undef TIFF_TYPE_LOOKUP | ||||||
| @@ -84,4 +94,8 @@ enum tiff_photometric_interpretation { | |||||||
| }; | }; | ||||||
| // clang-format on | // clang-format on | ||||||
|  |  | ||||||
|  | #ifdef __cplusplus | ||||||
|  | } | ||||||
|  | #endif // __cplusplus | ||||||
|  |  | ||||||
| #endif // !TIFFREAD_H | #endif // !TIFFREAD_H | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user