shithub: tocursor

Download patch

ref: 58d79939a16c2de700aa081cf51ae79dff5643de
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu May 14 12:53:20 EDT 2020

lol

--- /dev/null
+++ b/LICENSE
@@ -1,0 +1,1 @@
+Public domain.
--- /dev/null
+++ b/README.md
@@ -1,0 +1,9 @@
+# tocursor
+
+Converts a Plan 9 image to `Cursor` C structure.
+
+```
+png -9t <cursor.png | tocursor -5 -4 >/dev/snarf
+```
+
+Then just paste it into the source code. Don't forget to rename lol.
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,10 @@
+</$objtype/mkfile
+
+TARG=tocursor
+BIN=/$objtype/bin
+OFILES=\
+	tocursor.$O
+
+default:V: all
+
+</sys/src/cmd/mkone
--- /dev/null
+++ b/tocursor.c
@@ -1,0 +1,44 @@
+#include <u.h>
+#include <libc.h>
+
+void
+main(int argc, char **argv)
+{
+	u32int b[1084/4];
+	uchar clr[2*16], set[2*16];
+	int i;
+
+	if (argc < 3) {
+		fprint(2, "usage: png -9t <cursor.png | %s OFFSETX OFFSETY >/dev/snarf\n", argv[0]);
+		exits("usage");
+	}
+
+	if (readn(0, b, sizeof(b)) != sizeof(b))
+		sysfatal("%r");
+
+	memset(clr, 0, sizeof(clr));
+	memset(set, 0, sizeof(set));
+	print("Cursor lol = {\n");
+	print("\t{%s, %s},\n", argv[1], argv[2]);
+	for (i = 0; i < nelem(b); i++) {
+		if (b[15+i] == 0x000000ff)
+			set[i/8] |= 1<<(7-i&7);
+		else if (b[15+i] == 0xffffffff)
+			clr[i/8] |= 1<<(7-i&7);
+	}
+	print("\t{");
+	for (i = 0; i < sizeof(clr); i++) {
+		if (i > 0 && !(i % 8))
+			print("\n\t ");
+		print(" 0x%02x,", clr[i]);
+	}
+	print("\n\t},\n\t{");
+	for (i = 0; i < sizeof(set); i++) {
+		if (i > 0 && !(i % 8))
+			print("\n\t ");
+		print(" 0x%02x,", set[i]);
+	}
+	print("\n\t},\n};\n");
+
+	exits(nil);
+}