Move TiffStrip array inside the TiffImage struct
This commit is contained in:
		| @@ -36,10 +36,9 @@ | |||||||
| TiffHdr read_tiff_header(FILE *fp); | TiffHdr read_tiff_header(FILE *fp); | ||||||
| TiffIFD read_ifd(FILE *fp, const TiffHdr *header, u32 offset, Arena *arena); | TiffIFD read_ifd(FILE *fp, const TiffHdr *header, u32 offset, Arena *arena); | ||||||
| TiffImage read_fields(FILE *fp, const TiffHdr *header, const TiffIFD *ifd); | TiffImage read_fields(FILE *fp, const TiffHdr *header, const TiffIFD *ifd); | ||||||
| bool read_strip_data(FILE *fp, const TiffHdr *header, const TiffImage *img, | bool read_strip_data(FILE *fp, const TiffHdr *header, TiffImage *img, | ||||||
|                      TiffStrip *strips); |                      Arena *arena); | ||||||
| void read_strips(FILE *fp, const TiffImage *img, const TiffStrip *strips, | void read_strips(FILE *fp, const TiffImage *img, Pixel *buf); | ||||||
|                  Pixel *buf); |  | ||||||
| bool read_field(const TiffField *field, TiffImage *img, | bool read_field(const TiffField *field, TiffImage *img, | ||||||
|                 u32 *image_type_identifier); |                 u32 *image_type_identifier); | ||||||
| bool validate_image_type(const TiffImage *img, | bool validate_image_type(const TiffImage *img, | ||||||
| @@ -95,18 +94,12 @@ Image *read_baseline_tiff(const char *file, Arena *arena) { | |||||||
|     goto READ_BASELINE_FILE_CLEANUP; |     goto READ_BASELINE_FILE_CLEANUP; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   TiffStrip *strips = |   if (!read_strip_data(fp, &header, &img, temp)) { | ||||||
|       wapp_mem_arena_alloc(temp, sizeof(TiffStrip) * img.strip_count); |  | ||||||
|   if (!strips) { |  | ||||||
|     goto READ_BASELINE_DESTROY_ARENA; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if (!read_strip_data(fp, &header, &img, strips)) { |  | ||||||
|     goto READ_BASELINE_DESTROY_ARENA; |     goto READ_BASELINE_DESTROY_ARENA; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   for (u32 i = 0; i < img.strip_count; ++i) { |   for (u32 i = 0; i < img.strip_count; ++i) { | ||||||
|     printf("%u, %u\n", strips[i].offset, strips[i].byte_count); |     printf("%u, %u\n", img.strips[i].offset, img.strips[i].byte_count); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Pixel *buf = wapp_mem_arena_alloc(temp, img_byte_count); |   Pixel *buf = wapp_mem_arena_alloc(temp, img_byte_count); | ||||||
| @@ -114,7 +107,7 @@ Image *read_baseline_tiff(const char *file, Arena *arena) { | |||||||
|     goto READ_BASELINE_DESTROY_ARENA; |     goto READ_BASELINE_DESTROY_ARENA; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   read_strips(fp, &img, strips, buf); |   read_strips(fp, &img, buf); | ||||||
|  |  | ||||||
|   img_out = create_image(img.image_width, img.image_length, buf, arena); |   img_out = create_image(img.image_width, img.image_length, buf, arena); | ||||||
|  |  | ||||||
| @@ -265,9 +258,15 @@ READ_FIELDS_RETURN_IMAGE: | |||||||
|   return img_out; |   return img_out; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool read_strip_data(FILE *fp, const TiffHdr *header, const TiffImage *img, | bool read_strip_data(FILE *fp, const TiffHdr *header, TiffImage *img, | ||||||
|                      TiffStrip *strips) { |                      Arena *arena) { | ||||||
|   if (!fp || !img || !strips) { |   if (!fp || !img || !arena) { | ||||||
|  |     return false; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   img->strips = | ||||||
|  |       wapp_mem_arena_alloc(arena, sizeof(TiffStrip) * img->strip_count); | ||||||
|  |   if (!img->strips) { | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -283,7 +282,7 @@ bool read_strip_data(FILE *fp, const TiffHdr *header, const TiffImage *img, | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   for (u32 i = 0; i < img->strip_count; ++i) { |   for (u32 i = 0; i < img->strip_count; ++i) { | ||||||
|     TiffStrip *strip = &(strips[i]); |     TiffStrip *strip = &(img->strips[i]); | ||||||
|  |  | ||||||
|     u16 offset_size = img->strip_offsets_type_byte_count; |     u16 offset_size = img->strip_offsets_type_byte_count; | ||||||
|     u16 counts_size = img->strip_byte_count_type_byte_count; |     u16 counts_size = img->strip_byte_count_type_byte_count; | ||||||
| @@ -339,11 +338,10 @@ bool read_strip_data(FILE *fp, const TiffHdr *header, const TiffImage *img, | |||||||
|   return true; |   return true; | ||||||
| } | } | ||||||
|  |  | ||||||
| void read_strips(FILE *fp, const TiffImage *img, const TiffStrip *strips, | void read_strips(FILE *fp, const TiffImage *img, Pixel *buf) { | ||||||
|                  Pixel *buf) { |  | ||||||
|   u64 position = 0; |   u64 position = 0; | ||||||
|   for (u64 i = 0; i < img->strip_count; ++i) { |   for (u64 i = 0; i < img->strip_count; ++i) { | ||||||
|     const TiffStrip *strip = &(strips[i]); |     const TiffStrip *strip = &(img->strips[i]); | ||||||
|  |  | ||||||
|     for (u64 j = 0; j < strip->byte_count / img->sample_count; ++j) { |     for (u64 j = 0; j < strip->byte_count / img->sample_count; ++j) { | ||||||
|       Pixel *p = &(buf[position]); |       Pixel *p = &(buf[position]); | ||||||
|   | |||||||
| @@ -111,6 +111,12 @@ enum tiff_planar_configuration { | |||||||
| }; | }; | ||||||
| // clang-format on | // clang-format on | ||||||
|  |  | ||||||
|  | typedef struct tiff_strip TiffStrip; | ||||||
|  | struct tiff_strip { | ||||||
|  |   u32 offset; | ||||||
|  |   u32 byte_count; | ||||||
|  | }; | ||||||
|  |  | ||||||
| typedef struct tiff_image TiffImage; | typedef struct tiff_image TiffImage; | ||||||
| struct tiff_image { | struct tiff_image { | ||||||
|   TiffImageType type; |   TiffImageType type; | ||||||
| @@ -133,12 +139,7 @@ struct tiff_image { | |||||||
|   u32 extra_samples; |   u32 extra_samples; | ||||||
|   u32 extra_samples_count; |   u32 extra_samples_count; | ||||||
|   bool extra_samples_offset; |   bool extra_samples_offset; | ||||||
| }; |   TiffStrip *strips; | ||||||
|  |  | ||||||
| typedef struct tiff_strip TiffStrip; |  | ||||||
| struct tiff_strip { |  | ||||||
|   u32 offset; |  | ||||||
|   u32 byte_count; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| Image *read_baseline_tiff(const char *file, Arena *arena); | Image *read_baseline_tiff(const char *file, Arena *arena); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user