summaryrefslogtreecommitdiff
path: root/bin/ff-catwalk.c
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2024-10-15 13:29:10 -0400
committerSam Nystrom <sam@samnystrom.dev>2024-10-15 13:29:10 -0400
commit2c98bbacc8db3b251e1679f9da84cf1f5ed5726a (patch)
tree10d44c9b82d275d66d880ff8ec33992cddda12b5 /bin/ff-catwalk.c
parentc8c79e6c6a5c4bb1e0ba44f309ce5ae612f97e1c (diff)
update ~/bin
Diffstat (limited to 'bin/ff-catwalk.c')
-rw-r--r--bin/ff-catwalk.c50
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;
+}