Compare commits

..

No commits in common. "c46535c20bcd2c6f68f32bfd9e6c84daed33d948" and "69c13b83eac2eabac55cfbae3cbc9b820303815b" have entirely different histories.

4 changed files with 7 additions and 36 deletions

View File

@ -8,18 +8,17 @@ Image *create_image(u64 width, u64 height, Pixel *data, Arena *arena) {
return NULL;
}
u64 pixel_count = width * height;
u64 buf_length = sizeof(Pixel) * pixel_count;
u64 alloc_size = sizeof(Image) + buf_length;
u64 buf_length = width * height;
u64 total_size = sizeof(Image) + sizeof(Pixel) * buf_length;
Image *img = wapp_mem_arena_alloc(arena, alloc_size);
Image *img = wapp_mem_arena_alloc(arena, total_size);
if (!img) {
return NULL;
}
img->width = width;
img->height = height;
img->pixel_count = pixel_count;
img->buf_length = buf_length;
memcpy(img->data, data, buf_length);
return img;

View File

@ -20,7 +20,7 @@ typedef struct image Image;
struct image {
u64 width;
u64 height;
u64 pixel_count;
u64 buf_length;
Pixel data[];
};

View File

@ -60,7 +60,7 @@ int main(int argc, char *argv[]) {
char max[] = {'2', '5', '5', '\n'};
fwrite(max, sizeof(max), 1, out);
for (u64 i = 0; i < img->pixel_count; ++i) {
for (u64 i = 0; i < img->buf_length; i += 4) {
fwrite(&(img->data[i]), sizeof(u8), 3, out);
}

View File

@ -36,8 +36,6 @@ 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 TiffImage *img, TiffStrip *strips);
void read_strips(FILE *fp, const TiffImage *img, const TiffStrip *strips,
Pixel *buf);
bool read_field(const TiffField *field, TiffImage *img,
u32 *image_type_identifier);
bool validate_image_type(const TiffImage *img,
@ -82,11 +80,9 @@ Image *read_baseline_tiff(const char *file, Arena *arena) {
TiffIFD ifd = read_ifd(fp, &header, header.first_ifd_offset, arena);
TiffImage img = read_fields(fp, &header, &ifd);
u64 img_byte_count = sizeof(Pixel) * img.image_width * img.image_length;
Arena *temp = NULL;
u64 temp_size = 1 * 1024 * 1024 + img_byte_count;
if (!wapp_mem_arena_init(&temp, temp_size)) {
if (!wapp_mem_arena_init(&temp, 1 * 1024 * 1024)) {
goto READ_BASELINE_FILE_CLEANUP;
}
@ -104,15 +100,6 @@ Image *read_baseline_tiff(const char *file, Arena *arena) {
printf("%u, %u\n", strips[i].offset, strips[i].byte_count);
}
Pixel *buf = wapp_mem_arena_alloc(temp, img_byte_count);
if (!buf) {
goto READ_BASELINE_DESTROY_ARENA;
}
read_strips(fp, &img, strips, buf);
img_out = create_image(img.image_width, img.image_length, buf, arena);
READ_BASELINE_DESTROY_ARENA:
wapp_mem_arena_destroy(&temp);
@ -301,21 +288,6 @@ bool read_strip_data(FILE *fp, const TiffImage *img, TiffStrip *strips) {
return true;
}
void read_strips(FILE *fp, const TiffImage *img, const TiffStrip *strips,
Pixel *buf) {
for (u64 i = 0; i < img->strip_count; ++i) {
const TiffStrip *strip = &(strips[i]);
for (u64 j = 0; j < img->image_width * img->image_length; ++j) {
Pixel *p = &(buf[j]);
read_from_file_with_offset(fp, p, 3, strip->offset + j * 3);
p->a = 255;
}
}
}
bool read_field(const TiffField *field, TiffImage *img,
u32 *image_type_identifier) {
switch (field->tag) {