1 /***********************************************************
2 pm2.c -- extract pmext2 coding
3 ***********************************************************/
8 static off_t nextcount;
9 static unsigned long lastupdate;
11 /* repeated from slide.c */
12 static unsigned int dicsiz1;
13 #define offset (0x100 - 2)
16 decode_start_pm2(void)
18 dicsiz1 = (1 << dicbit) - 1;
23 getbits(1); /* discard bit */
27 static unsigned char gettree1;
29 static int historyBits[8] = { 3, 3, 4, 5, 5, 5, 6, 6 };
30 static int historyBase[8] = { 0, 8, 16, 32, 64, 96, 128, 192 };
31 static int repeatBits[6] = { 3, 3, 5, 6, 7, 0 };
32 static int repeatBase[6] = { 17, 25, 33, 65, 129, 256 };
38 while (lastupdate != loc) {
39 hist_update(dtext[lastupdate]);
40 lastupdate = (lastupdate + 1) & dicsiz1;
43 while (decode_count >= nextcount) {
44 /* Actually it will never loop, because decode_count doesn't grow that fast.
45 However, this is the way LHA does it.
46 Probably other encoding methods can have repeats larger than 256 bytes.
47 Note: LHA puts this code in decode_p...
70 default: /* 0x2000, 0x3000, 0x4000, ... */
71 if (getbits(1) != 0) {
79 gettree1 = tree_get(&tree1); /* value preserved for decode_p */
85 /* direct value (ret <= UCHAR_MAX) */
87 return hist_lookup(historyBase[gettree1] +
88 getbits(historyBits[gettree1]));
89 /* repeats: (ret > UCHAR_MAX) */
91 return offset + 2 + (gettree1 - 8);
93 return offset + repeatBase[gettree1 - 23]
94 + getbits(repeatBits[gettree1 - 23]);
100 /* gettree1 value preserved from decode_c */
101 int nbits, delta, gettree2;
102 if (gettree1 == 8) { /* 2-byte repeat with offset 0..63 */
106 else if (gettree1 < 28) { /* n-byte repeat with offset 0..8191 */
107 gettree2 = tree_get(&tree2);
113 nbits = 5 + gettree2;
117 else { /* 256 bytes repeat with offset 0 */
122 return delta + getbits(nbits);