7 resample(Memimage *dst, Rectangle r, Memimage *src, Rectangle sr)
12 uchar *pdst0, *pdst, *psrc0, *psrc;
13 ulong s00, s01, s10, s11;
16 ssize = subpt(subpt(sr.max, sr.min), Pt(1,1));
17 dsize = subpt(subpt(r.max, r.min), Pt(1,1));
18 pdst0 = byteaddr(dst, r.min);
20 bpl = src->width*sizeof(int);
24 qp.x = (ssize.x<<12)/dsize.x;
26 qp.y = (ssize.y<<12)/dsize.y;
29 for(dp.y=0; dp.y<=dsize.y; dp.y++){
34 psrc0 = byteaddr(src, sp);
36 for(dp.x=0; dp.x<=dsize.x; dp.x++){
39 psrc = psrc0 + sp.x*bpp;
40 s00 = (0x1000-tx)*(0x1000-ty);
46 pdst[3] = (s11*psrc[bpl+bpp+3] +
51 pdst[2] = (s11*psrc[bpl+bpp+2] +
55 pdst[1] = (s11*psrc[bpl+bpp+1] +
60 pdst[0] = (s11*psrc[bpl+bpp] +
68 pdst0 += dst->width*sizeof(int);
82 v = strtol(s, &s, 10) & ~PERCENT;
91 sysfatal("Usage: %s [ -x width ] [ -y height ] [ file ]\n", argv0);
95 main(int argc, char **argv)
104 xsize = ysize = getsize(EARGF(usage()));
107 xsize = getsize(EARGF(usage()));
110 ysize = getsize(EARGF(usage()));
117 fd = open(*argv, OREAD);
119 sysfatal("open: %r");
122 if((im = readmemimage(fd)) == nil)
123 sysfatal("readmemimage: %r");
125 xsize = ((xsize & ~PERCENT) * Dx(im->r)) / 100;
127 ysize = ((ysize & ~PERCENT) * Dy(im->r)) / 100;
130 ysize = (xsize * Dy(im->r)) / Dx(im->r);
132 xsize = (ysize * Dx(im->r)) / Dy(im->r);
136 for(tchan = ochan; tchan; tchan >>= 8)
137 if(TYPE(tchan) == CAlpha){
158 if((nim = allocmemimage(im->r, tchan)) == nil)
159 sysfatal("allocimage: %r");
160 memimagedraw(nim, nim->r, im, im->r.min, nil, ZP, S);
164 if((nim = allocmemimage(
165 Rect(im->r.min.x, im->r.min.y, im->r.min.x+xsize, im->r.min.y+ysize),
167 sysfatal("addocmemimage: %r");
168 resample(nim, nim->r, im, im->r);
172 if((im = allocmemimage(nim->r, ochan)) == nil)
173 sysfatal("allocimage: %r");
174 memimagedraw(im, im->r, nim, nim->r.min, nil, ZP, S);
178 if(writememimage(1, im) < 0)
179 sysfatal("writememimage: %r");