shithub: imgtools

Download patch

ref: 172c1e097c06d3a707992034cae962f513c1c73c
parent: 2386f06afaf4eb894887704805843887798c2943
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Jan 20 06:03:04 EST 2021

resample: make width/height optional

--- a/resample.c
+++ b/resample.c
@@ -99,8 +99,6 @@
 		wp = 1;
 	}
 
-	if(ow < 1 && oh < 1)
-		usage();
 	for(f = 0; f < nelem(filters) && (filters[f] == nil || strcmp(flts, filters[f]) != 0); f++);
 	if(f >= nelem(filters))
 		sysfatal("invalid filter %s", flts);
@@ -111,7 +109,14 @@
 	memimageinit();
 	if((a = readmemimage(0)) == nil)
 		sysfatal("memory");
+	w = Dx(a->r);
+	h = Dy(a->r);
 
+	if(ow < 1)
+		ow = w;
+	if(oh < 1)
+		oh = h;
+
 	bp = 0;
 again:
 	switch(a->chan){
@@ -160,8 +165,6 @@
 		sysfatal("invalid chan %#lux", a->chan);
 	}
 
-	w = Dx(a->r);
-	h = Dy(a->r);
 	if(stmode == Stpixels){
 		st[0] /= (double)w;
 		st[1] /= (double)h;