shithub: tocursor

Download patch

ref: e712b341a4b7ba5d7f9e6a52e8ef43d2e2c60bed
parent: aa515b1b5b5071884815b1e22bb01ade901d8c03
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Tue Oct 1 13:10:52 EDT 2024

expecting r8g8b8a8, make it more clear

--- a/tocursor.c
+++ b/tocursor.c
@@ -4,37 +4,37 @@
 void
 main(int argc, char **argv)
 {
-	u32int b[1084/4];
-	uchar clr[2*16], set[2*16];
+	u32int b[5*12/4+16*16];
+	uchar clr[16*16/8], set[16*16/8];
 	int i;
 
-	if (argc < 3) {
+	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");
+	if((i = readn(0, b, sizeof(b))) != sizeof(b))
+		sysfatal("short read: %d < %d (not r8g8b8a8?)", i, sizeof(b));
 
 	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)
+	for(i = 0; i < 16*16; i++){
+		if(b[15+i] == 0x000000ff)
 			set[i/8] |= 1<<(7-i&7);
-		else if (b[15+i] == 0xffffffff)
+		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))
+	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))
+	for(i = 0; i < sizeof(set); i++){
+		if(i > 0 && !(i % 8))
 			print("\n\t ");
 		print(" 0x%02x,", set[i]);
 	}