commit 979070dfb169132e7b50a8b7d89d00781f5235e1
parent eb91be48e11464c04fb173a70cc9d63f8004117f
Author: bsandro <email@bsandro.tech>
Date: Fri, 7 Jul 2023 14:46:49 +0300
provisional
Diffstat:
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -158,18 +158,24 @@ void write_webp(const char *fname, AnimatedImage *img, int cols, int rows) {
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 * img->frame_count;
- uint8_t *merged = malloc(img_size);
+ size_t full_line = line_size * cols;
+ uint8_t *merged = malloc(frame_size * rows * cols);
assert(merged!=NULL);
bzero(merged, img_size);
- for (int y = 0; y < img->height; ++y) {
- //int cur_cols =
- 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);
+ for (int row = 0; row < rows; ++row) {
+ for (int y = row*img->height; y < row*img->height+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);
+ }
+ }
}
}
- int stride = img->width * sizeof(uint32_t) * img->frame_count;
- size_t encoded = WebPEncodeLosslessRGBA(merged, img->width * img->frame_count, img->height, stride, &out);
+ int stride = img->width * sizeof(uint32_t) * cols;
+ printf("stride: %d\n", stride);
+ size_t encoded = WebPEncodeLosslessRGBA(merged, 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);