6 static void dodecode(Biobuf*, Pix*, int, int, uchar*);
7 static long getlong(uchar*);
13 int nx, ny, scale, sumall;
20 Bprint(&bout, "reading %s\n", file);
21 bp = Bopen(file, OREAD);
24 if(Bread(bp, buf, sizeof(buf)) != sizeof(buf) ||
25 buf[0] != 0xdd || buf[1] != 0x99){
26 werrstr("bad format");
31 scale = getlong(buf+10);
32 sumall = getlong(buf+14);
34 fprint(2, "%s: nx=%d, ny=%d, scale=%d, sumall=%d, nbitplanes=%d,%d,%d\n",
35 file, nx, ny, scale, sumall, buf[18], buf[19], buf[20]);
36 ip = malloc(sizeof(Img) + (nx*ny-1)*sizeof(int));
44 dodecode(bp, ip->a, nx, ny, buf+18);
45 ip->a[0] = sumall; /* sum of all pixels */
59 dodecode(Biobuf *infile, Pix *a, int nx, int ny, uchar *nbitplanes)
61 int nel, nx2, ny2, bits, mask;
67 memset(a, 0, nel*sizeof(*a));
70 * Initialize bit input
72 start_inputing_bits();
75 * read bit planes for each quadrant
77 qtree_decode(infile, &a[0], ny, nx2, ny2, nbitplanes[0]);
78 qtree_decode(infile, &a[ny2], ny, nx2, ny/2, nbitplanes[1]);
79 qtree_decode(infile, &a[ny*nx2], ny, nx/2, ny2, nbitplanes[1]);
80 qtree_decode(infile, &a[ny*nx2+ny2], ny, nx/2, ny/2, nbitplanes[2]);
83 * make sure there is an EOF symbol (nybble=0) at end
85 if(input_nybble(infile) != 0){
86 fprint(2, "dodecode: bad bit plane values\n");
100 bits = Bgetc(infile);
110 long getlong(uchar *p)
112 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];