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)
26 chunk = d->bufsize - 32; /* a little room for header */
29 * distinguish new channel descriptor from old ldepth.
30 * channel descriptors have letters as well as numbers,
31 * while ldepths are a single digit formatted as %-11d.
41 werrstr("readimage: bad format");
46 if((chan = strtochan(hdr)) == 0){
47 werrstr("readimage: bad channel string %s", hdr);
51 ldepth = ((int)hdr[10])-'0';
52 if(ldepth<0 || ldepth>3){
53 werrstr("readimage: bad ldepth %d", ldepth);
56 chan = drawld2chan[ldepth];
59 r.min.x = atoi(hdr+1*12);
60 r.min.y = atoi(hdr+2*12);
61 r.max.x = atoi(hdr+3*12);
62 r.max.y = atoi(hdr+4*12);
63 if(r.min.x>r.max.x || r.min.y>r.max.y){
64 werrstr("readimage: bad rectangle");
71 l = bytesperline(r, chantodepth(chan));
74 i = allocimage(d, r, chan, 0, -1);
87 werrstr("readimage: image too wide for buffer");
91 m = readn(fd, tmp, n);
93 werrstr("readimage: read count %d not %d: %r", m, n);
104 if(!new) /* an old image: must flip all the bits */
105 for(j=0; j<chunk; j++)
110 if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)