6 readimage(Display *d, int fd, int dolock)
20 if(readn(fd, hdr, 11) != 11)
22 if(memcmp(hdr, "compressed\n", 11) == 0)
23 return creadimage(d, fd, dolock);
24 if(readn(fd, hdr+11, 5*12-11) != 5*12-11)
27 chunk = d->bufsize - 32; /* a little room for header */
32 * distinguish new channel descriptor from old ldepth.
33 * channel descriptors have letters as well as numbers,
34 * while ldepths are a single digit formatted as %-11d.
44 werrstr("readimage: bad format");
49 if((chan = strtochan(hdr)) == 0){
50 werrstr("readimage: bad channel string %s", hdr);
54 ldepth = ((int)hdr[10])-'0';
55 if(ldepth<0 || ldepth>3){
56 werrstr("readimage: bad ldepth %d", ldepth);
59 chan = drawld2chan[ldepth];
62 r.min.x = atoi(hdr+1*12);
63 r.min.y = atoi(hdr+2*12);
64 r.max.x = atoi(hdr+3*12);
65 r.max.y = atoi(hdr+4*12);
66 if(r.min.x>r.max.x || r.min.y>r.max.y){
67 werrstr("readimage: bad rectangle");
74 l = bytesperline(r, chantodepth(chan));
78 i = allocimage(d, r, chan, 0, -1);
84 i = mallocz(sizeof(Image), 1);
97 werrstr("readimage: image too wide for buffer");
101 m = readn(fd, tmp, n);
103 werrstr("readimage: read count %d not %d: %r", m, n);
114 if(!new) /* an old image: must flip all the bits */
115 for(j=0; j<chunk; j++)
121 if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)