20 if(readn(fd, hdr, 11) != 11){
21 werrstr("readimage: short header");
24 if(memcmp(hdr, "compressed\n", 11) == 0)
25 return creadmemimage(fd);
26 if(readn(fd, hdr+11, 5*12-11) != 5*12-11){
27 werrstr("readimage: short header (2)");
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));
75 i = allocmemimage(r, chan);
89 werrstr("readmemimage: image too wide for buffer");
93 m = readn(fd, tmp, n);
95 werrstr("readmemimage: read count %d not %d: %r", m, n);
101 if(!new) /* an old image: must flip all the bits */
102 for(j=0; j<chunk; j++)
105 if(loadmemimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)