commit 0699592f5cc9552e660eaf9adf46603a2bbf1629
Author: prenev <an2qzavok@gmail.com>
Date: Sat, 20 Mar 2021 17:00:18 +0300
ff-pattern
Diffstat:
A | ff-pattern.c | | | 47 | +++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 47 insertions(+), 0 deletions(-)
diff --git a/ff-pattern.c b/ff-pattern.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <assert.h>
+
+int fid;
+long inx, iny, outx, outy;
+long size, i, x, y;
+uint32_t hbuf[4];
+char *buf;
+char *argv0;
+
+void
+usage(void)
+{
+ dprintf(2, "usage: %s width height\n", argv0);
+ exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+ fid = 0;
+ argv0 = argv[0];
+ if (argc < 3) usage();
+ outx = strtol(argv[1], 0, 10);
+ outy = strtol(argv[2], 0, 10);
+
+ read(fid, hbuf, 16);
+ inx = ntohl(hbuf[2]);
+ iny = ntohl(hbuf[3]);
+ size = inx * iny * 8;
+ buf = malloc(size);
+ read(fid, buf, size);
+ hbuf[2] = htonl(outx);
+ hbuf[3] = htonl(outy);
+ write(1, hbuf, 16);
+ for (i = 0; i < outx * outy; i++){
+ x = i % outx;
+ y = i / outx;
+ int d;
+ d = x%inx + y%inx * inx;
+ assert(d*8<size);
+ write(1, buf + d * 8, 8);
+ }
+ return 0;
+}