comparison cabac.c @ 2323:1c39d9786efd libavcodec

optimization
author michael
date Tue, 26 Oct 2004 03:12:21 +0000
parents 48d9f86fb047
children 582e635cfa08
comparison
equal deleted inserted replaced
2322:4140f2e78ebc 2323:1c39d9786efd
67 29,30,30,30,31,32,32,33, 67 29,30,30,30,31,32,32,33,
68 33,33,34,34,35,35,35,36, 68 33,33,34,34,35,35,35,36,
69 36,36,37,37,37,38,38,63, 69 36,36,37,37,37,38,38,63,
70 }; 70 };
71 71
72 const uint8_t ff_h264_norm_shift[256]= {
73 8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,
74 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
75 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
76 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
77 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
78 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
79 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
80 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
81 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
82 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
83 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
84 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
85 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
86 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
87 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
88 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
89 };
90
72 /** 91 /**
73 * 92 *
74 * @param buf_size size of buf in bits 93 * @param buf_size size of buf in bits
75 */ 94 */
76 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size){ 95 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size){
93 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){ 112 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){
94 c->bytestream_start= 113 c->bytestream_start=
95 c->bytestream= buf; 114 c->bytestream= buf;
96 c->bytestream_end= buf + buf_size; 115 c->bytestream_end= buf + buf_size;
97 116
98 c->low= *c->bytestream++; 117 #if CABAC_BITS == 16
99 c->low= (c->low<<9) + ((*c->bytestream++)<<1); 118 c->low = (*c->bytestream++)<<18;
100 c->range= 0x1FE00; 119 c->low+= (*c->bytestream++)<<10;
101 c->bits_left= 7; 120 #else
121 c->low = (*c->bytestream++)<<10;
122 #endif
123 c->low+= ((*c->bytestream++)<<2) + 2;
124 c->range= 0x1FE<<(CABAC_BITS + 1);
102 } 125 }
103 126
104 void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4], 127 void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4],
105 uint8_t const *mps_state, uint8_t const *lps_state, int state_count){ 128 uint8_t const *mps_state, uint8_t const *lps_state, int state_count){
106 int i, j; 129 int i, j;
107 130
108 for(i=0; i<state_count; i++){ 131 for(i=0; i<state_count; i++){
109 for(j=0; j<4; j++){ //FIXME check if this is worth the 1 shift we save 132 for(j=0; j<4; j++){ //FIXME check if this is worth the 1 shift we save
110 c->lps_range[2*i+0][j]= 133 c->lps_range[2*i+0][j+4]=
111 c->lps_range[2*i+1][j]= lps_range[i][j]; 134 c->lps_range[2*i+1][j+4]= lps_range[i][j];
112 } 135 }
113 136
114 c->mps_state[2*i+0]= 2*mps_state[i]; 137 c->mps_state[2*i+0]= 2*mps_state[i];
115 c->mps_state[2*i+1]= 2*mps_state[i]+1; 138 c->mps_state[2*i+1]= 2*mps_state[i]+1;
116 139