6 readimage(Display *d, int fd, int dolock)
20 if(readn(fd, hdr, 11) != 11)
22 if(memcmp(hdr, "compressed\n", 11) == 0){
23 if(i = creadimage(d, fd, dolock))
28 if(readn(fd, hdr+11, 5*12-11) != 5*12-11)
31 chunk = d->bufsize - 32; /* a little room for header */
36 * distinguish new channel descriptor from old ldepth.
37 * channel descriptors have letters as well as numbers,
38 * while ldepths are a single digit formatted as %-11d.
48 werrstr("readimage: bad format");
53 if((chan = strtochan(hdr)) == 0){
54 werrstr("readimage: bad channel string %s", hdr);
58 ldepth = ((int)hdr[10])-'0';
59 if(ldepth<0 || ldepth>3){
60 werrstr("readimage: bad ldepth %d", ldepth);
63 chan = drawld2chan[ldepth];
66 r.min.x = atoi(hdr+1*12);
67 r.min.y = atoi(hdr+2*12);
68 r.max.x = atoi(hdr+3*12);
69 r.max.y = atoi(hdr+4*12);
70 if(r.min.x>r.max.x || r.min.y>r.max.y){
71 werrstr("readimage: bad rectangle");
78 l = bytesperline(r, chantodepth(chan));
84 i = allocimage(d, r, chan, 0, -1);
90 i = mallocz(sizeof(Image), 1);
102 m = readn(fd, tmp, n);
104 werrstr("readimage: read count %d not %d: %r", m, n);
115 if(!new) /* an old image: must flip all the bits */
116 for(j=0; j<chunk; j++)
122 if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)
131 setmalloctag(i, getcallerpc(&d));