[Mndiff-dev] [mndiff]: r19 - trunk/mnzip/mnzip.c
michael
subversion at mplayerhq.hu
Fri Jun 15 02:29:18 CEST 2007
Author: michael
Date: Fri Jun 15 02:29:18 2007
New Revision: 19
Log:
remove RLE coder
slightly better compression and simpler
Modified:
trunk/mnzip/mnzip.c
Modified: trunk/mnzip/mnzip.c
==============================================================================
--- trunk/mnzip/mnzip.c (original)
+++ trunk/mnzip/mnzip.c Fri Jun 15 02:29:18 2007
@@ -460,37 +460,14 @@ static inline int getbit(RangeCoder *c,
return b;
}
-static inline void put_symbol(RangeCoder *c, uint32_t *state, int v){
- int i;
-
- if(v){
- const int e= av_log2(v);
- const int el= MIN(e, 8);
- putbit(c, state+0, 0, prob[0]);
-
- for(i=0; i<el; i++){
- putbit(c, state+1+i, 1, prob[1+i]); //1..8
- }
- for(; i<e; i++){
- putbit(c, state+1+7, 1, prob[1+7]); //1..8
- }
- putbit(c, state+1+MIN(i,7), 0, prob[1+MIN(i,7)]);
-
- for(i=e-1; i>=el; i--){
- putbit(c, state+9+7, (v>>i)&1, prob[9+7]); //9..16
- }
- for(; i>=0; i--){
- putbit(c, state+9+i, (v>>i)&1, prob[9+i]); //9..16
- }
- }else{
- putbit(c, state+0, 1, prob[0]);
- }
-}
-
static inline void put_symbol_255(RangeCoder *c, uint32_t *state, int v){
const int e= av_log2(v);
int i;
+ putbit(c, state+14, v==0, prob[17+14]); //14
+ if(!v)
+ return;
+
assert(v);
assert(e<8);
putbit(c, state , e>3 , prob[17]); //0
@@ -504,6 +481,9 @@ static inline void put_symbol_255(RangeC
static inline int get_symbol_255(RangeCoder *c, uint32_t *state){
int e,a,i;
+ if(getbit(c, state+14, prob[17+14]))
+ return 0;
+
e =4*getbit(c, state , prob[17]); //0
e+=2*getbit(c, state+1+(e>3) , prob[17+1+(e>3)]); //1..2
e+= getbit(c, state+3+(e>>1), prob[17+3+(e>>1)]); //3..6
@@ -515,23 +495,6 @@ static inline int get_symbol_255(RangeCo
return a;
}
-static inline int get_symbol(RangeCoder *c, uint32_t *state){
- if(getbit(c, state+0, prob[0]))
- return 0;
- else{
- int i, e, a;
- e= 0;
- while(getbit(c, state+1 + MIN(e,7), prob[1 + MIN(e,7)])) //1..8
- e++;
-
- a= 1;
- for(i=e-1; i>=0; i--)
- a += a + getbit(c, state+9 + MIN(i,7), prob[9 + MIN(i,7)]); //9..16
-
- return a;
- }
-}
-
static inline int rb32(uint8_t *p){
return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3];
}
@@ -580,13 +543,11 @@ fprintf(stderr,"range coding (%d %d)\n",
}
for(i=0; i<256; i++){
- put_symbol(&c, &state[256*32*2], mtf[i]);
+ put_symbol_255(&c, &state[256*32*2], mtf[i]);
}
for(i=0; i<len; i++){
- int run, v, ndx;
- for(run=0; i<len && !tmp[i]; i++)
- run++;
+ int v, ndx;
ndx= tmp[i];
v= mtf[0];
@@ -594,7 +555,6 @@ fprintf(stderr,"range coding (%d %d)\n",
mtf[j]= mtf[j+1];
mtf[ndx]= v;
put_symbol_255(&c, &state[v*32], ndx);
- put_symbol(&c, &state[256*32 + 32*v], run);
}
//FIXME last byte mtf= 0 and run mess
//FIXME right order mtf optim
@@ -649,7 +609,7 @@ fprintf(stderr," block (%d %d %d)\n", ou
for(i=0; i<256; i++){
int test[256]={0};
- mtf[i]= get_symbol(&c, &state[256*32*2]);
+ mtf[i]= get_symbol_255(&c, &state[256*32*2]);
if(mtf[i] > 255U || test[mtf[i]]++){
fprintf(stderr, "fatal error mtf invalid\n");
return -1;
@@ -659,20 +619,13 @@ fprintf(stderr," block (%d %d %d)\n", ou
for(i=0; i<out_len; ){
int v= mtf[0];
int ndx= get_symbol_255(&c, &state[v*32]);
- int run= get_symbol(&c, &state[256*32 + 32*v]) + 1;
for(j=0; j<ndx; j++)
mtf[j]= mtf[j+1];
mtf[ndx]= v;
- if(i+run > out_len || i+run<i){
- fprintf(stderr, "fatal error, run to large\n");
- return -1;
- }
- do{
- tmp[i++]= v;
- histogram[v]++;
- }while(--run);
+ tmp[i++]= v;
+ histogram[v]++;
}
free(in);
More information about the Mndiff-dev
mailing list