[GIF] "gif -9t",
[JPEG] "jpg -9t",
[PNG] "png -9t",
-[PIC] "fb/3to1 /lib/fb/cmap/rgbv",
-[TIFF] "/sys/lib/mothra/tiffcvt",
-[XBM] "fb/xbm2pic",
+[BMP] "bmp -9t",
+[ICO] "ico -c",
};
-void storebitmap(Rtext *t, Image *b){
- t->b=b;
- free(t->text);
- t->text=0;
-}
-
void getimage(Rtext *t, Www *w){
int pfd[2];
Action *ap;
Url url;
Image *b;
- int fd;
- char err[512];
+ int fd, typ;
+ char err[512], buf[80], *s;
Pix *p;
ap=t->user;
seturl(&url, ap->image, w->url->fullname);
for(p=w->pix;p!=nil; p=p->next)
if(strcmp(ap->image, p->name)==0 && ap->width==p->width && ap->height==p->height){
- storebitmap(t, p->b);
+ t->b = p->b;
w->changed=1;
return;
}
- fd=urlopen(&url, GET, 0);
+ fd=urlget(&url, -1);
if(fd==-1){
Err:
- snprint(err, sizeof(err), "[%s: %r]", url.fullname);
+ snprint(err, sizeof(err), "[img: %s: %r]", url.reltext);
free(t->text);
t->text=strdup(err);
w->changed=1;
close(fd);
return;
}
- if(url.type!=GIF
- && url.type!=JPEG
- && url.type!=PNG
- && url.type!=PIC
- && url.type!=TIFF
- && url.type!=XBM){
+ typ = snooptype(fd);
+ if(typ < 0 || typ >= nelem(pixcmd) || pixcmd[typ] == nil){
werrstr("unknown image type");
goto Err;
}
-
- if((fd = pipeline(pixcmd[url.type], fd)) < 0)
+ if((fd = pipeline(fd, "exec %s", pixcmd[typ])) < 0)
goto Err;
if(ap->width>0 || ap->height>0){
- char buf[80];
- char *p;
-
- p = buf;
- p += sprint(p, "resize");
+ s = buf;
+ s += sprint(s, "exec resize");
if(ap->width>0)
- p += sprint(p, " -x %d", ap->width);
+ s += sprint(s, " -x %d", ap->width);
if(ap->height>0)
- p += sprint(p, " -y %d", ap->height);
- if((fd = pipeline(buf, fd)) < 0)
+ s += sprint(s, " -y %d", ap->height);
+ if((fd = pipeline(fd, buf)) < 0)
goto Err;
}
b=readimage(display, fd, 1);
goto Err;
}
close(fd);
- p = emallocz(sizeof(Pix), 1);
- strncpy(p->name, ap->image, sizeof(p->name));
+ p=emalloc(sizeof(Pix));
+ nstrcpy(p->name, ap->image, sizeof(p->name));
p->b=b;
p->width=ap->width;
p->height=ap->height;
p->next=w->pix;
w->pix=p;
- storebitmap(t, b);
+ t->b=b;
w->changed=1;
}
}
}
-void freepix(void *p)
-{
+ulong countpix(void *p){
+ ulong n=0;
+ Pix *x;
+ for(x = p; x; x = x->next)
+ n += Dy(x->b->r)*bytesperline(x->b->r, x->b->depth);
+ return n;
+}
+
+void freepix(void *p){
Pix *x, *xx;
xx = p;
while(x = xx){