3
Copyright (C) 2000 Stefan Westerfeld
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
23
#include "huffmanlookup.h"
29
struct HuffmanLookup::decodeData HuffmanLookup::qdecode[32][256];
30
/* for initialization */
31
static HuffmanLookup l;
33
HuffmanLookup::HuffmanLookup()
37
for(table = 0; table < 32; table++)
40
for(p = 0; p < 256; p++)
45
huffmandecoder_1(&Mpegtoraw::ht[table], &x,&y);
48
qdecode[table][p].skip = (used <= 8)?used:0;
49
qdecode[table][p].x = x;
50
qdecode[table][p].y = y;
55
int HuffmanLookup::wgetbit()
57
return (pattern >> --bits) & 1;
60
int HuffmanLookup::wgetbits (int b)
63
return (pattern >> bits) & ((1 << b) - 1);
66
void HuffmanLookup::huffmandecoder_1(const HUFFMANCODETABLE *h, int *x, int *y)
68
typedef unsigned int HUFFBITS;
70
HUFFBITS level=(1<<(sizeof(HUFFBITS)*8-1));
72
/* Lookup in Huffman table. */
75
if(h->val[point][0]==0)
79
xx=h->val[point][1]>>4;
80
yy=h->val[point][1]&0xf;
84
if((h->xlen)==(unsigned)xx)xx+=wgetbits(h->linbits);
85
if(xx)if(wgetbit())xx=-xx;
86
if((h->ylen)==(unsigned)yy)yy+=wgetbits(h->linbits);
87
if(yy)if(wgetbit())yy=-yy;
91
if(xx)if(wgetbit())xx=-xx;
92
if(yy)if(wgetbit())yy=-yy;
98
point+=h->val[point][wgetbit()];
101
if(!(level || ((unsigned)point<Mpegtoraw::ht->treelen)))
105
xx=(h->xlen<<1);// set x and y to a medium value as a simple concealment
108
// h->xlen and h->ylen can't be 1 under tablename 32