Skip to content

Commit

Permalink
Abstracted away the img blob append operation (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed May 27, 2024
1 parent a802d93 commit 7266f3f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tools/skap/include/skap_idx_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ skap_idx_image skap_idx_image_create(const char *name, Image *img);
u8 skap_idx_image_append(FILE *fd, skap_idx_image *i);

void skap_idx_image_link_blob(skap_idx_image *i, usz blob_offset, usz blob_size);

u8 skap_idx_image_blob_append(FILE *fd, const char *name, Image *img);
4 changes: 1 addition & 3 deletions tools/skap/src/skap.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ int main(void) {
}
for (usz i = 0; i < ARRLEN(imgs_paths); ++i) {
skap_idx_image_link_blob(&img_idxs[i], ftell(fd), (usz) imgs[i].width * imgs[i].height);
printf(" WRITE %s >> " SKAP_FILENAME "\n", imgs_paths[i]);
if (fwrite(imgs[i].data, sizeof(Color), (usz) imgs[i].width * imgs[i].height, fd) != (usz) imgs[i].width * imgs[i].height) {
fprintf(stderr, "ERROR: unable to write to file\n");
if (!skap_idx_image_blob_append(fd, imgs_paths[i], &imgs[i])) {
skap_file_destroy(fd);
unload_imgs();
return 1;
Expand Down
13 changes: 13 additions & 0 deletions tools/skap/src/skap_idx_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ void skap_idx_image_link_blob(skap_idx_image *i, usz blob_offset, usz blob_size)
i->blob_offset = blob_offset;
i->blob_size = blob_size;
}

u8 skap_idx_image_blob_append(FILE *fd, const char *name, Image *img) {
if (!fd || !img) {
fprintf(stderr, "ERROR: skap_idx_image_blob_append :: `fd` and `img` need to be valid pointers\n");
return 0;
}
printf(" WRITE %s >> " SKAP_FILENAME "\n", name);
if (fwrite(img->data, sizeof(Color), (usz) img->width * img->height, fd) != (usz) img->width * img->height) {
fprintf(stderr, "ERROR: skap_idx_image_blob_append :: unable to write to file\n");
return 0;
}
return 1;
}

0 comments on commit 7266f3f

Please sign in to comment.