shithub: ifilter

Download patch

ref: 989ecb1ad9eab0de1363c8a59a3ed33616e1b8c8
parent: 2b8de34339eaee77261ac891ce3e701b2e66a84f
author: phil9 <[email protected]>
date: Wed Nov 24 14:57:24 EST 2021

avoid a call to loadmemimage/writememimage

	Instead of loading then writing the image we directly
	dump the buffer with the correct image(6) header.

	Thanks to qwx for the tip.

--- a/ifilter.c
+++ b/ifilter.c
@@ -121,12 +121,11 @@
 		sysfatal("malloc: %r");
 	if(unloadmemimage(i, i->r, buf, n)<0)
 		sysfatal("unloadmemimage: %r");
+	freememimage(i);
 	for(p = 0; p < n; p+=4)
 		f->filter(buf+p, factor);
-	if(loadmemimage(i, i->r, buf, n)<0)
-		sysfatal("unloadmemimage: %r");
-	writememimage(1, i);
-	freememimage(i);
+	print("   x8r8g8b8 %11d %11d %11d %11d ", 0, 0, w, h);
+	write(1, buf, n);
 	exits(nil);
 }