google / brunsli

Practical JPEG Repacker
MIT License
730 stars 51 forks source link

Is brunsli's ANS using static probability distributions? #102

Closed xiaoxiongli closed 4 years ago

xiaoxiongli commented 4 years ago

Dear All: In the brunsli's code, it seems run like below: 1) context modeling, let's say we get 27 x 9 bins(histogram) for example. 2) cluster the histogram(27x9) to reduce the context bin's count, for example after cluster, 27x9 reduce to 5. 3) build 5 ANS table. 4) during encode, get a context value and map it to one of the 5 ANS table then perform ANS encode(PutSymbol).

it seems that we need know all of the DCT coefficients, and then we perform encode with ANS, in other words, when ANS table is built, for each symbol(18 in brunsli) the probability never changed, it use static probability distributions. am i right?

As you know, in dropbox's lepton there is a arithmetic encoder to encode the residual of the DCT coefficents, the arithmetic encoder can adjust the probability internally, see below red line:

image so, in this way, during lepton's arithmetic encoding, the probability is dynamic adjust locally.

my concern is since ANS is using static probability distributions instead of dynamic adjust it locally, the finally compression ratio maybe will get worse, am I right? if it is true, could we adjust probability dynamically in brunsli's ANS to improve the compression ratio?

eustas commented 4 years ago

Brunsli uses ANS for decoding "outline" of the value. For many things that constitute the resulting DCT values Brunsli uses arithmetic code (see https://github.com/google/brunsli/blob/master/c/dec/arith_decode.h)

xiaoxiongli commented 4 years ago

Dear @eustas ,

Thank you for your reply.

What's the meaning of "outline" of the value?

In brunsli's code, it seems use ANS to encode the residual of the DCT coefficents and use Arithmetic encoder to encode some flags(usually 1 bit).