shithub: imgtools

Download patch

ref: 248d690e93e18139e11a75fb4425832357082383
parent: 94794a38886af90b1af32cce3156db015f74339a
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Feb 17 12:19:03 EST 2021

iconv: add -u to produce uncompressed image, -r to skip the header

--- a/iconv.c
+++ b/iconv.c
@@ -26,7 +26,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-c CHAN]\n", argv0);
+	fprint(2, "usage: %s [-c CHAN] [-r] [-u] [FILE]\n", argv0);
 	exits("usage");
 }
 
@@ -33,11 +33,13 @@
 void
 main(int argc, char **argv)
 {
+	int ci, raw, uncomp;
 	Memimage *a, *b;
 	char *s;
-	int ci;
 
 	ci = -1;
+	raw = 0;
+	uncomp = 0;
 	ARGBEGIN{
 	case 'c':
 		s = EARGF(usage());
@@ -52,6 +54,12 @@
 			sysfatal("chan");
 		}
 		break;
+	case 'r':
+		raw = 1;
+		break;
+	case 'u':
+		uncomp = 1;
+		break;
 	default:
 		usage();
 	}ARGEND
@@ -66,7 +74,31 @@
 		freememimage(a);
 		a = b;
 	}
-	writememimage(1, a);
+	if(raw || uncomp){
+		char chan[32];
+		int bpl, y, n;
+		uchar *b;
+
+		if(!raw){
+			if(chantostr(chan, a->chan) == nil)
+				sysfatal("chantostr: %r");
+			fprint(1, "%11s %11d %11d %11d %11d ", chan, a->r.min.x, a->r.min.y, a->r.max.x, a->r.max.y);
+		}
+
+		bpl = bytesperline(a->r, a->depth);
+		b = malloc(bpl);
+		if(b == nil)
+			sysfatal("memory");
+		for(y = a->r.min.y; y < a->r.max.y; y++){
+			n = unloadmemimage(a, Rect(a->r.min.x, y, a->r.max.x, y+1), b, bpl);
+			if(n != bpl)
+				sysfatal("unload: %r");
+			if(write(1, b, bpl) != bpl)
+				sysfatal("%r");
+		}
+	}else{
+		writememimage(1, a);
+	}
 
 	exits(nil);
 }