| cr88192 2005-11-21, 6:55 pm |
|
"cr88192" <cr88192@NOSPAM.hotmail.com> wrote in message
news:ef4a9$43824c00$ca83a7e9$20625@saipa
n.com...
>
I just noticed a very obvious flaw with the example below:
it is necessary to take the context into account when decoding, otherwise,
crap is all screwed over. I could either reset the context as well whenever
the range collapses (this does risk somewhat hurting compression) or
generate a much larger table (context+range bits).
so, for example, with the latter approach, the table would contain around
65k elements, and be accessed sort of like:
r=r|((value>>offs)&0xFF);
s=table[r];
c=counts[r];
a compromise might be trauncating the context bits (to, say, 4 bits) which
might be ok, but I don't know.
this mostly just risks hurting speed a little due to things not fitting as
well in cache...
other problems may exist.
I don't know...
>
> partial example of what the core of the decoder might look like:
>
> byte **table;
> int *counts;
> int value; //16 bit temp value
> int offs; //shift offset
>
> byte *decode_range(byte *obuf, int r)
> {
> byte *s;
> int c;
>
> s=table[r];
> c=counts[r];
>
> while(c>=8)
> {
> value|=(*s++)<<offs;
> *obuf++=value>>8;
> value<<=8;
> c-=8;
> }
> value|=(*s++)<<offs;
> offs-=c;
>
> if(offs<=0)
> {
> *obuf++=value>>8;
> value<<=8;
> offs+=8;
> }
>
> return(obuf);
> }
>
|