emote2ss

Animated webp to spritesheets converting tool
git clone git://bsandro.tech/emote2ss
Log | Files | Refs

commit d6a310081623ba3bbbe496e136950920290a0684
parent faf71a2091dae01b8ec5c3f26ffb598e8eea11c2
Author: bsandro <email@bsandro.tech>
Date:   Thu, 13 Jul 2023 01:12:32 +0300

Command line arguments accept filename and columns count now. Only single file processed at time.

Diffstat:
MMakefile | 2+-
Msrc/main.c | 36+++++++++++++++++++-----------------
2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile @@ -23,5 +23,5 @@ run: $(NAME) @./$(NAME) test: $(NAME) - @./$(NAME) FlanClap.webp + @./$(NAME) FlanClap.webp 5 feh atlas_FlanClap.webp diff --git a/src/main.c b/src/main.c @@ -149,19 +149,19 @@ int read_webp(const char *fname, AnimatedImage *anim) { return 0; } -void write_webp(const char *fname, AnimatedImage *img, int cols, int rows) { - // validate that we have enough space in resulting picture for all the frames - assert(rows*cols >= (int)img->frame_count); +void write_webp(const char *fname, AnimatedImage *img, int cols) { + int rows = (int)img->frame_count / cols; + if ((int)img->frame_count % cols > 0) { + ++rows; + } FILE *fp = fopen(fname, "wb"); assert(fp!=NULL); uint8_t *out; size_t frame_size = img->width * img->height * sizeof(uint32_t); - size_t img_size = frame_size * img->frame_count; size_t line_size = img->width * sizeof(uint32_t); size_t full_line = line_size * cols; - uint8_t *merged = malloc(frame_size * rows * cols); + uint8_t *merged = calloc(rows * cols, frame_size); assert(merged!=NULL); - bzero(merged, img_size); uint8_t *merged_orig = merged; for (int row = 0; row < rows; ++row) { for (int y = 0; y < img->height; ++y) { @@ -189,19 +189,21 @@ void write_webp(const char *fname, AnimatedImage *img, int cols, int rows) { int main(int argc, const char **argv) { atexit(print_webp_version); + if (argc < 3) { + printf("Usage: %s anim_file.webp COLUMNS\n", argc>0?argv[0]:"emote2ss"); + return 0; + } + char *outname = calloc(255, 1); assert(outname!=NULL); - if (argc >= 1) { - for (int i=1; i<argc; ++i) { - AnimatedImage img = {0}; - const char *inname = argv[i]; - assert(read_webp(inname, &img) == 0); - int n = snprintf(outname, 254, "atlas_%s", inname); - assert(n>0); - printf("[%s -> %s]\ndimensions: %dx%d\nframes: %d\n", inname, outname, img.width, img.height, img.frame_count); - write_webp(outname, &img, 5, 4); - } - } + AnimatedImage img = {0}; + const char *inname = argv[1]; + int cols = atoi(argv[2]); + assert(read_webp(inname, &img) == 0); + int n = snprintf(outname, 254, "atlas_%s", inname); + assert(n>0); + printf("[%s -> %s(%d)]\ndimensions: %dx%d\nframes: %d\n", inname, outname, cols, img.width, img.height, img.frame_count); + write_webp(outname, &img, cols); free(outname); return 0;