Update main.c to use wizapp stdlib and tiffread.h
This commit is contained in:
		
							
								
								
									
										59
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -1,62 +1,9 @@ | |||||||
|  | #include "aliases.h" | ||||||
|  | #include "tiffread.h" | ||||||
| #include <netinet/in.h> | #include <netinet/in.h> | ||||||
| #include <stdint.h> |  | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
|  |  | ||||||
| #define TAG_MAX_COUNT (UINT16_MAX * sizeof(const char *)) |  | ||||||
| // Technically, the type parameter is 2-bytes long, but there aren't so many |  | ||||||
| // types specified in the spec, so UINT8_MAX should be sufficient |  | ||||||
| #define TYPE_MAX_COUNT (UINT8_MAX * sizeof(const char *)) |  | ||||||
|  |  | ||||||
| // clang-format off |  | ||||||
| enum { |  | ||||||
|   TIFF_ORDER_LITTLE_ENDIAN = 0x4949, |  | ||||||
|   TIFF_ORDER_BIG_ENDIAN    = 0x4d4d, |  | ||||||
| }; |  | ||||||
| // clang-format on |  | ||||||
|  |  | ||||||
| typedef struct hdr TiffHdr; |  | ||||||
| struct hdr { |  | ||||||
|   uint16_t order; |  | ||||||
|   uint16_t magic; |  | ||||||
|   uint32_t first_ifd_offset; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| enum tiff_public_tags { |  | ||||||
| #include "tiff_public_tags.inc" |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| const char *tag_names[TAG_MAX_COUNT] = { |  | ||||||
| #define TIFF_TAG_LOOKUP |  | ||||||
| #include "tiff_public_tags.inc" |  | ||||||
| #undef TIFF_TAG_LOOKUP |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| enum tiff_field_types { |  | ||||||
| #include "tiff_field_types.inc" |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| const char *filed_type_names[TYPE_MAX_COUNT] = { |  | ||||||
| #define TIFF_TYPE_LOOKUP |  | ||||||
| #include "tiff_field_types.inc" |  | ||||||
| #undef TIFF_TYPE_LOOKUP |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| typedef struct field TiffField; |  | ||||||
| struct field { |  | ||||||
|   uint16_t tag; |  | ||||||
|   uint16_t type; |  | ||||||
|   uint32_t count; |  | ||||||
|   uint32_t value_offset; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| typedef struct IFD TiffIFD; |  | ||||||
| struct IFD { |  | ||||||
|   uint16_t count; |  | ||||||
|   TiffField *fields; |  | ||||||
|   uint32_t next_ifd; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||||
|   const char *file_to_open = argc > 1 ? argv[1] : "./resources/test.tif"; |   const char *file_to_open = argc > 1 ? argv[1] : "./resources/test.tif"; | ||||||
|  |  | ||||||
| @@ -79,7 +26,7 @@ int main(int argc, char *argv[]) { | |||||||
|   TiffField fields[ifd.count]; |   TiffField fields[ifd.count]; | ||||||
|   memset(fields, 0, sizeof(TiffField) * ifd.count); |   memset(fields, 0, sizeof(TiffField) * ifd.count); | ||||||
|  |  | ||||||
|   for (uint32_t i = 0; i < ifd.count; ++i) { |   for (u32 i = 0; i < ifd.count; ++i) { | ||||||
|     fread(fields + i, sizeof(TiffField), 1, fp); |     fread(fields + i, sizeof(TiffField), 1, fp); | ||||||
|     printf("ENTRY %02u\n", i); |     printf("ENTRY %02u\n", i); | ||||||
|     printf("\t    TAG: %04u (%s)\n", fields[i].tag, |     printf("\t    TAG: %04u (%s)\n", fields[i].tag, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user