emote2ss

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

commit 584e7fdfd8ae5de00cc3262b9fe4d48e36ca5463
parent 979070dfb169132e7b50a8b7d89d00781f5235e1
Author: bsandro <[email protected]>
Date:   Sat,  8 Jul 2023 23:18:25 +0300

Setting variable columns x rows works now.

Diffstat:
Msrc/main.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -162,26 +162,27 @@ void write_webp(const char *fname, AnimatedImage *img, int cols, int rows) { uint8_t *merged = malloc(frame_size * rows * cols); assert(merged!=NULL); bzero(merged, img_size); + uint8_t *merged_orig = merged; for (int row = 0; row < rows; ++row) { - for (int y = row*img->height; y < row*img->height+img->height; ++y) { + for (int y = 0; y < img->height; ++y) { for (int col = 0; col < cols; ++col) { uint32_t offset = row*cols+col; if (offset < img->frame_count) { - //printf("row %d, col %d, offset %u, y %d\n", row, col, offset, y); - memcpy(merged+y*full_line+col*line_size, img->frames[offset].rgba+y*line_size, line_size); + memcpy(merged, img->frames[offset].rgba+y*line_size, line_size); } + merged += line_size; } } } - int stride = img->width * sizeof(uint32_t) * cols; + int stride = full_line; printf("stride: %d\n", stride); - size_t encoded = WebPEncodeLosslessRGBA(merged, img->width * cols, img->height * rows, stride, &out); + size_t encoded = WebPEncodeLosslessRGBA(merged_orig, img->width * cols, img->height * rows, stride, &out); printf("size: %" PRIu32 ", encoded: %zu\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); + free(merged_orig); fclose(fp); } @@ -193,7 +194,7 @@ int main(int argc, const char **argv) { AnimatedImage img = {0}; assert(read_webp(argv[i], &img) == 0); printf("dimensions: %dx%d\nframes: %d\n", img.width, img.height, img.frame_count); - write_webp("test01.webp", &img, 6, 2); + write_webp("test01.webp", &img, 5, 4); } }