ref: d758f7428946545dd5760ece0da7cbbabbea1811
parent: cd326e72db3f6609dd2093c6934f9c4b8a8abc71
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Jul 16 03:16:03 EDT 2021
resample: optional file path
--- a/resample.c
+++ b/resample.c
@@ -30,7 +30,7 @@
static void
usage(void)
{
- fprint(2, "usage: %s [-P] [-x size] [-y size] [-r x0,y0,x1,y1] [-f filter] [-c colorspace]\n", argv0);
+ fprint(2, "usage: %s [-P] [-x size] [-y size] [-r x0,y0,x1,y1] [-f filter] [-c colorspace] [file]\n", argv0);
exits("usage");
}
@@ -39,7 +39,7 @@
{
char *flts, *s, *csps, *e;
int n, bp, to, stmode;
- int alphai, flags;
+ int alphai, flags, fd;
int w, h, ow, oh, iw, ih;
int wp, hp, f, c;
Memimage *a, *b;
@@ -91,6 +91,8 @@
usage();
}ARGEND
+ if(argc > 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);
@@ -98,6 +100,10 @@
if(c >= nelem(cspaces))
sysfatal("invalid colorspace %s", csps);
+ fd = 0;
+ if(argc == 1 && (fd = open(argv[0], OREAD)) < 0)
+ sysfatal("%r");
+
if(wp && oh == 0){
oh = ow;
hp = 1;
@@ -107,7 +113,7 @@
}
memimageinit();
- if((a = readmemimage(0)) == nil)
+ if((a = readmemimage(fd)) == nil)
sysfatal("memory");
w = Dx(a->r);
h = Dy(a->r);