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
Memimage*
resample(int xsize, int ysize, Memimage *m)
{
- int i, j, bpl, nchan;
+ int i, j, d, bpl, nchan;
Memimage *new;
uchar **oscan, **nscan;
}
/* 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);
/* 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);
Memimage *m, *new, *t1, *t2;
char *file;
ulong tchan;
- char tmp[100];
double v;
for(i=-K2; i<=K2; i++){
if(xsize == 0)
xsize = (ysize * Dx(m->r)) / Dy(m->r);
- new = nil;
switch(m->chan){
+ default:
+ for(tchan = m->chan; tchan; tchan >>= 8)
+ if(TYPE(tchan) == CAlpha){
+ tchan = RGBA32;
+ goto Convert;
+ }
+ tchan = RGB24;
+ goto Convert;
case GREY8:
case RGB24:
new = resample(xsize, ysize, m);
break;
- case CMAP8:
- case RGB15:
- case RGB16:
- tchan = RGB24;
- goto Convert;
-
case GREY1:
case GREY2:
case GREY4:
memimagedraw(new, new->r, t2, t2->r.min, nil, ZP, S);
freememimage(t2);
break;
-
- default:
- sysfatal("can't handle channel type %s", chantostr(tmp, m->chan));
}
assert(new);