Multiplier-free entropy coder
This commit is contained in:
parent
aeb4467d7f
commit
2ec8d9e522
26 changed files with 1597 additions and 2 deletions
32
libentcode/probmod.c
Normal file
32
libentcode/probmod.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "probmod.h"
|
||||
#include "bitree.h"
|
||||
|
||||
void ec_probmod_init(ec_probmod *_this,unsigned _sz){
|
||||
ec_probmod_init_full(_this,_sz,1U,1U<<23,NULL);
|
||||
}
|
||||
|
||||
void ec_probmod_init_from_counts(ec_probmod *_this,unsigned _sz,
|
||||
const unsigned *_counts){
|
||||
ec_probmod_init_full(_this,_sz,1U,1U<<23,_counts);
|
||||
}
|
||||
|
||||
void ec_probmod_init_full(ec_probmod *_this,unsigned _sz,unsigned _inc,
|
||||
unsigned _thresh,const unsigned *_counts){
|
||||
unsigned s;
|
||||
_this->sz=_sz;
|
||||
for(s=1;s<=_this->sz;s<<=1);
|
||||
_this->split=s>>1;
|
||||
_this->inc=_inc;
|
||||
_this->thresh=_thresh;
|
||||
_this->bitree=(unsigned *)malloc(_sz*sizeof(*_this->bitree));
|
||||
if(_counts!=NULL)memcpy(_this->bitree,_counts,_sz*sizeof(*_this->bitree));
|
||||
else for(s=0;s<_this->sz;s++)_this->bitree[s]=1;
|
||||
ec_bitree_from_counts(_this->bitree,_sz);
|
||||
_this->ft=ec_bitree_get_cumul(_this->bitree,_sz);
|
||||
}
|
||||
|
||||
void ec_probmod_clear(ec_probmod *_this){
|
||||
free(_this->bitree);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue