emote2ss

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

commit c5cfc4dafcd131df9c4bbd70bcb134a70ce43b89
parent b1092ca1a469424fbf124705bdd1715fd8078d44
Author: bsandro <[email protected]>
Date:   Tue,  4 Jul 2023 01:44:38 +0300

Horizontal spritesheet (instead of vertical one from previous version)

Diffstat:
MMakefile | 1+
Msrc/main.c | 16+++++++++++-----
2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile @@ -24,3 +24,4 @@ run: $(NAME) test: $(NAME) @./$(NAME) FlanClap.webp + feh test01.webp diff --git a/src/main.c b/src/main.c @@ -139,7 +139,7 @@ int read_webp(const char *fname, AnimatedImage *anim) { curr_rgba = frame->rgba; frame->duration = ts - prev_ts; memcpy(curr_rgba, frame_rgba, anim->width * anim->height * NUM_CHANNELS); - // ... + // ... <- nani kore? ++frame_index; prev_ts = ts; } @@ -155,17 +155,23 @@ void write_webp(const char *fname, AnimatedImage *img) { uint8_t *out; size_t frame_size = img->width * img->height * sizeof(uint32_t); size_t frames_size = frame_size * img->frame_count; + size_t line_size = img->width * sizeof(uint32_t); + size_t full_line = line_size * img->frame_count; uint8_t *merged = malloc(frames_size); assert(merged!=NULL); bzero(merged, frames_size); - for (uint32_t i=0; i< img->frame_count; ++i) { - memcpy(merged+frame_size*i, img->frames[i].rgba, frame_size); + for (int y = 0; y < img->height; ++y) { + for (uint32_t i = 0; i < img->frame_count; ++i) { + memcpy(merged+y*full_line+i*line_size, img->frames[i].rgba+line_size*y, line_size); + } } - int stride = img->width * sizeof(uint32_t); - size_t encoded = WebPEncodeLosslessRGBA(merged, img->width, img->height*img->frame_count, stride, &out); + int stride = img->width * sizeof(uint32_t) * img->frame_count; + size_t encoded = WebPEncodeLosslessRGBA(merged, img->width * img->frame_count, img->height, stride, &out); printf("size: %lu, encoded: %lu\n", img->width*img->height*sizeof(uint32_t), encoded); + assert(encoded!=0); size_t written = fwrite(out, sizeof(uint8_t), encoded, fp); assert(written==encoded); + WebPFree(out); free(merged); fclose(fp); }