summaryrefslogtreecommitdiff
path: root/sys/src/cmd/resize.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@centraldogma>2011-10-06 20:54:56 +0200
committercinap_lenrek <cinap_lenrek@centraldogma>2011-10-06 20:54:56 +0200
commit65e50862cf904f1b9051e9eeb87d6374625ca6ed (patch)
treee712317cafbf943fda2f2705b28bd9f5e700fe3f /sys/src/cmd/resize.c
parentd58a409a1215f3dce723768ed6489e979257741b (diff)
manpages for resize and rotate
Diffstat (limited to 'sys/src/cmd/resize.c')
-rw-r--r--sys/src/cmd/resize.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/sys/src/cmd/resize.c b/sys/src/cmd/resize.c
index a66cd90c7..626097eeb 100644
--- a/sys/src/cmd/resize.c
+++ b/sys/src/cmd/resize.c
@@ -70,10 +70,25 @@ resample(Memimage *dst, Rectangle r, Memimage *src, Rectangle sr)
}
}
+enum {
+ PERCENT = 0x80000000,
+};
+
+static int
+getsize(char *s)
+{
+ int v;
+
+ v = strtol(s, &s, 10) & ~PERCENT;
+ if(*s == '%')
+ v |= PERCENT;
+ return v;
+}
+
void
usage(void)
{
- sysfatal("Usage: %s [ -x width ] [ -y height ] [image]\n", argv0);
+ sysfatal("Usage: %s [ -x width ] [ -y height ] [ file ]\n", argv0);
}
void
@@ -86,11 +101,14 @@ main(int argc, char **argv)
xsize = ysize = 0;
ARGBEGIN{
+ case 'a':
+ xsize = ysize = getsize(EARGF(usage()));
+ break;
case 'x':
- xsize = atoi(EARGF(usage()));
+ xsize = getsize(EARGF(usage()));
break;
case 'y':
- ysize = atoi(EARGF(usage()));
+ ysize = getsize(EARGF(usage()));
break;
default:
usage();
@@ -104,6 +122,10 @@ main(int argc, char **argv)
memimageinit();
if((im = readmemimage(fd)) == nil)
sysfatal("readmemimage: %r");
+ if(xsize & PERCENT)
+ xsize = ((xsize & ~PERCENT) * Dx(im->r)) / 100;
+ if(ysize & PERCENT)
+ ysize = ((ysize & ~PERCENT) * Dy(im->r)) / 100;
if(xsize || ysize){
if(ysize == 0)
ysize = (xsize * Dy(im->r)) / Dx(im->r);