]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/resample.c
ndb/dns: remove single-ip-address assuptions
[plan9front.git] / sys / src / cmd / resample.c
index a1487a398e9ce05acb600e2664a1c0566877752c..d11e299603a2879a2b12284f994f6192456b1ce9 100644 (file)
@@ -54,14 +54,13 @@ usage(void)
 int
 getint(char *s, int *percent)
 {
+       int n;
+
        if(s == nil)
                usage();
-       *percent = (s[strlen(s)-1] == '%');
-       if(*s == '+')
-               return atoi(s+1);
-       if(*s == '-')
-               return -atoi(s+1);
-       return atoi(s);
+       n = strtol(s, &s, 0);
+       *percent = *s == '%';
+       return n;
 }
 
 void
@@ -133,7 +132,7 @@ max(int a, int b)
 Memimage*
 resample(int xsize, int ysize, Memimage *m)
 {
-       int i, j, bpl, nchan;
+       int i, j, d, bpl, nchan;
        Memimage *new;
        uchar **oscan, **nscan;
 
@@ -166,13 +165,12 @@ resample(int xsize, int ysize, Memimage *m)
        }
 
        /* resample in X */
-       nchan = m->depth/8;
+       nchan = d = m->depth/8;
+       if(m->chan == XRGB32)
+               nchan--;
        for(i=0; i<Dy(m->r); i++){
-               for(j=0; j<nchan; j++){
-                       if(j==0 && m->chan==XRGB32)
-                               continue;
-                       resamplex(oscan[i], j, nchan, Dx(m->r), nscan[i], xsize);
-               }
+               for(j=0; j<nchan; j++)
+                       resamplex(oscan[i], j, d, Dx(m->r), nscan[i], xsize);
                free(oscan[i]);
                oscan[i] = nscan[i];
                nscan[i] = malloc(bpl);
@@ -183,7 +181,7 @@ resample(int xsize, int ysize, Memimage *m)
        /* resample in Y */
        for(i=0; i<xsize; i++)
                for(j=0; j<nchan; j++)
-                       resampley(oscan, nchan*i+j, Dy(m->r), nscan, ysize);
+                       resampley(oscan, d*i+j, Dy(m->r), nscan, ysize);
 
        /* pack data into destination */
        bpl = bytesperline(new->r, m->depth);