Move TiffStrip array inside the TiffImage struct
This commit is contained in:
parent
51f79275de
commit
9312c0fb6b
@ -36,10 +36,9 @@
|
||||
TiffHdr read_tiff_header(FILE *fp);
|
||||
TiffIFD read_ifd(FILE *fp, const TiffHdr *header, u32 offset, Arena *arena);
|
||||
TiffImage read_fields(FILE *fp, const TiffHdr *header, const TiffIFD *ifd);
|
||||
bool read_strip_data(FILE *fp, const TiffHdr *header, const TiffImage *img,
|
||||
TiffStrip *strips);
|
||||
void read_strips(FILE *fp, const TiffImage *img, const TiffStrip *strips,
|
||||
Pixel *buf);
|
||||
bool read_strip_data(FILE *fp, const TiffHdr *header, TiffImage *img,
|
||||
Arena *arena);
|
||||
void read_strips(FILE *fp, const TiffImage *img, Pixel *buf);
|
||||
bool read_field(const TiffField *field, TiffImage *img,
|
||||
u32 *image_type_identifier);
|
||||
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;
|
||||
}
|
||||
|
||||
TiffStrip *strips =
|
||||
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)) {
|
||||
if (!read_strip_data(fp, &header, &img, temp)) {
|
||||
goto READ_BASELINE_DESTROY_ARENA;
|
||||
}
|
||||
|
||||
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);
|
||||
@ -114,7 +107,7 @@ Image *read_baseline_tiff(const char *file, Arena *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);
|
||||
|
||||
@ -265,9 +258,15 @@ READ_FIELDS_RETURN_IMAGE:
|
||||
return img_out;
|
||||
}
|
||||
|
||||
bool read_strip_data(FILE *fp, const TiffHdr *header, const TiffImage *img,
|
||||
TiffStrip *strips) {
|
||||
if (!fp || !img || !strips) {
|
||||
bool read_strip_data(FILE *fp, const TiffHdr *header, TiffImage *img,
|
||||
Arena *arena) {
|
||||
if (!fp || !img || !arena) {
|
||||
return false;
|
||||
}
|
||||
|
||||
img->strips =
|
||||
wapp_mem_arena_alloc(arena, sizeof(TiffStrip) * img->strip_count);
|
||||
if (!img->strips) {
|
||||
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) {
|
||||
TiffStrip *strip = &(strips[i]);
|
||||
TiffStrip *strip = &(img->strips[i]);
|
||||
|
||||
u16 offset_size = img->strip_offsets_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;
|
||||
}
|
||||
|
||||
void read_strips(FILE *fp, const TiffImage *img, const TiffStrip *strips,
|
||||
Pixel *buf) {
|
||||
void read_strips(FILE *fp, const TiffImage *img, Pixel *buf) {
|
||||
u64 position = 0;
|
||||
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) {
|
||||
Pixel *p = &(buf[position]);
|
||||
|
@ -111,6 +111,12 @@ enum tiff_planar_configuration {
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
typedef struct tiff_strip TiffStrip;
|
||||
struct tiff_strip {
|
||||
u32 offset;
|
||||
u32 byte_count;
|
||||
};
|
||||
|
||||
typedef struct tiff_image TiffImage;
|
||||
struct tiff_image {
|
||||
TiffImageType type;
|
||||
@ -133,12 +139,7 @@ struct tiff_image {
|
||||
u32 extra_samples;
|
||||
u32 extra_samples_count;
|
||||
bool extra_samples_offset;
|
||||
};
|
||||
|
||||
typedef struct tiff_strip TiffStrip;
|
||||
struct tiff_strip {
|
||||
u32 offset;
|
||||
u32 byte_count;
|
||||
TiffStrip *strips;
|
||||
};
|
||||
|
||||
Image *read_baseline_tiff(const char *file, Arena *arena);
|
||||
|
Loading…
Reference in New Issue
Block a user