diff options
Diffstat (limited to 'bin/ff-catwalk.c')
| -rw-r--r-- | bin/ff-catwalk.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/ff-catwalk.c b/bin/ff-catwalk.c new file mode 100644 index 0000000..69b827e --- /dev/null +++ b/bin/ff-catwalk.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <endian.h> + +int +main(int argc, char *argv[]) +{ + if (argc != 5) { + fprintf(stderr, "Usage: %s LATTE FRAPPE MACCHIATO MOCHA\n", argv[0]); + return 1; + } + FILE *images[4]; + uint32_t headers[16]; + for (int i = 0; i < 4; i++) { + images[i] = fopen(argv[i+1], "r"); + if (!images[i]) { + perror(argv[i+1]); + return 1; + } + if (fread(&headers + i*16, 16, 1, images[i]) != 1 || memcmp(&headers, &headers + i*16, 16)) { + fprintf(stderr, "error: header mismatch"); + return 1; + } + } + uint32_t width = be32toh(headers[2]); + uint32_t height = be32toh(headers[3]); + char *buf = calloc(width, 8); + + fwrite(&headers, 16, 1, stdout); + for (uint32_t row = 0; row < height; row++) { + for (int i = 0; i < 4; i++) { + if (fread(buf, 8, width, images[i]) != width) { + if (ferror(images[i])) { + perror("fread"); + } else { + perror("fread: unexpected EOF"); + } + return 1; + } + uint32_t start = width / 4 * i + width / 8 - width / 4 * row / height; + uint32_t end = start + width / 4; + if (i == 0) start = 0; + if (i == 3) end = width; + fwrite(buf + 8 * start, 8, end - start, stdout); + } + } + return 0; +} |
