1 8a3b2ceb 2004-04-24 devnull #include <u.h>
2 8a3b2ceb 2004-04-24 devnull #include <libc.h>
3 8a3b2ceb 2004-04-24 devnull #include <bio.h>
4 8a3b2ceb 2004-04-24 devnull #include "sky.h"
6 8a3b2ceb 2004-04-24 devnull static int hufvals[] = {
7 8a3b2ceb 2004-04-24 devnull 1, 1, 1, 1, 1, 1, 1, 1,
8 8a3b2ceb 2004-04-24 devnull 2, 2, 2, 2, 2, 2, 2, 2,
9 8a3b2ceb 2004-04-24 devnull 4, 4, 4, 4, 4, 4, 4, 4,
10 8a3b2ceb 2004-04-24 devnull 8, 8, 8, 8, 8, 8, 8, 8,
11 8a3b2ceb 2004-04-24 devnull 3, 3, 3, 3, 5, 5, 5, 5,
12 8a3b2ceb 2004-04-24 devnull 10, 10, 10, 10, 12, 12, 12, 12,
13 8a3b2ceb 2004-04-24 devnull 15, 15, 15, 15, 6, 6, 7, 7,
14 cbeb0b26 2006-04-01 devnull 9, 9, 11, 11, 13, 13, 0, 14
17 8a3b2ceb 2004-04-24 devnull static int huflens[] = {
18 8a3b2ceb 2004-04-24 devnull 3, 3, 3, 3, 3, 3, 3, 3,
19 8a3b2ceb 2004-04-24 devnull 3, 3, 3, 3, 3, 3, 3, 3,
20 8a3b2ceb 2004-04-24 devnull 3, 3, 3, 3, 3, 3, 3, 3,
21 8a3b2ceb 2004-04-24 devnull 3, 3, 3, 3, 3, 3, 3, 3,
22 8a3b2ceb 2004-04-24 devnull 4, 4, 4, 4, 4, 4, 4, 4,
23 8a3b2ceb 2004-04-24 devnull 4, 4, 4, 4, 4, 4, 4, 4,
24 8a3b2ceb 2004-04-24 devnull 4, 4, 4, 4, 5, 5, 5, 5,
25 cbeb0b26 2006-04-01 devnull 5, 5, 5, 5, 5, 5, 6, 6
28 8a3b2ceb 2004-04-24 devnull static int buffer;
29 8a3b2ceb 2004-04-24 devnull static int bits_to_go; /* Number of bits still in buffer */
32 8a3b2ceb 2004-04-24 devnull start_inputing_bits(void)
34 8a3b2ceb 2004-04-24 devnull bits_to_go = 0;
38 8a3b2ceb 2004-04-24 devnull input_huffman(Biobuf *infile)
42 8a3b2ceb 2004-04-24 devnull if(bits_to_go < 6) {
43 8a3b2ceb 2004-04-24 devnull c = Bgetc(infile);
44 8a3b2ceb 2004-04-24 devnull if(c < 0) {
45 8a3b2ceb 2004-04-24 devnull fprint(2, "input_huffman: unexpected EOF\n");
46 8a3b2ceb 2004-04-24 devnull exits("format");
48 8a3b2ceb 2004-04-24 devnull buffer = (buffer<<8) | c;
49 8a3b2ceb 2004-04-24 devnull bits_to_go += 8;
51 8a3b2ceb 2004-04-24 devnull c = (buffer >> (bits_to_go-6)) & 0x3f;
52 8a3b2ceb 2004-04-24 devnull bits_to_go -= huflens[c];
53 8a3b2ceb 2004-04-24 devnull return hufvals[c];
57 8a3b2ceb 2004-04-24 devnull input_nybble(Biobuf *infile)
61 8a3b2ceb 2004-04-24 devnull if(bits_to_go < 4) {
62 8a3b2ceb 2004-04-24 devnull c = Bgetc(infile);
63 8a3b2ceb 2004-04-24 devnull if(c < 0){
64 8a3b2ceb 2004-04-24 devnull fprint(2, "input_nybble: unexpected EOF\n");
65 8a3b2ceb 2004-04-24 devnull exits("format");
67 8a3b2ceb 2004-04-24 devnull buffer = (buffer<<8) | c;
68 8a3b2ceb 2004-04-24 devnull bits_to_go += 8;
72 8a3b2ceb 2004-04-24 devnull * pick off the first 4 bits
74 8a3b2ceb 2004-04-24 devnull bits_to_go -= 4;
75 8a3b2ceb 2004-04-24 devnull return (buffer>>bits_to_go) & 0x0f;