Mercurial > libavcodec.hg
comparison vp6.c @ 5711:dae0f80edbb3 libavcodec
move all model related tables into their own struct
author | aurel |
---|---|
date | Mon, 24 Sep 2007 22:29:11 +0000 |
parents | 8f52599c4c6c |
children | 314be1cfdcb0 |
comparison
equal
deleted
inserted
replaced
5710:74e4be2d2f22 | 5711:dae0f80edbb3 |
---|---|
143 | 143 |
144 static void vp6_coeff_order_table_init(vp56_context_t *s) | 144 static void vp6_coeff_order_table_init(vp56_context_t *s) |
145 { | 145 { |
146 int i, pos, idx = 1; | 146 int i, pos, idx = 1; |
147 | 147 |
148 s->coeff_index_to_pos[0] = 0; | 148 s->modelp->coeff_index_to_pos[0] = 0; |
149 for (i=0; i<16; i++) | 149 for (i=0; i<16; i++) |
150 for (pos=1; pos<64; pos++) | 150 for (pos=1; pos<64; pos++) |
151 if (s->coeff_reorder[pos] == i) | 151 if (s->modelp->coeff_reorder[pos] == i) |
152 s->coeff_index_to_pos[idx++] = pos; | 152 s->modelp->coeff_index_to_pos[idx++] = pos; |
153 } | 153 } |
154 | 154 |
155 static void vp6_default_models_init(vp56_context_t *s) | 155 static void vp6_default_models_init(vp56_context_t *s) |
156 { | 156 { |
157 s->vector_model_dct[0] = 0xA2; | 157 vp56_model_t *model = s->modelp; |
158 s->vector_model_dct[1] = 0xA4; | 158 |
159 s->vector_model_sig[0] = 0x80; | 159 model->vector_dct[0] = 0xA2; |
160 s->vector_model_sig[1] = 0x80; | 160 model->vector_dct[1] = 0xA4; |
161 | 161 model->vector_sig[0] = 0x80; |
162 memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats)); | 162 model->vector_sig[1] = 0x80; |
163 memcpy(s->vector_model_fdv, vp6_def_fdv_vector_model, sizeof(s->vector_model_fdv)); | 163 |
164 memcpy(s->vector_model_pdv, vp6_def_pdv_vector_model, sizeof(s->vector_model_pdv)); | 164 memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats)); |
165 memcpy(s->coeff_model_runv, vp6_def_runv_coeff_model, sizeof(s->coeff_model_runv)); | 165 memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv)); |
166 memcpy(s->coeff_reorder, vp6_def_coeff_reorder, sizeof(s->coeff_reorder)); | 166 memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv)); |
167 memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv)); | |
168 memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder)); | |
167 | 169 |
168 vp6_coeff_order_table_init(s); | 170 vp6_coeff_order_table_init(s); |
169 } | 171 } |
170 | 172 |
171 static void vp6_parse_vector_models(vp56_context_t *s) | 173 static void vp6_parse_vector_models(vp56_context_t *s) |
172 { | 174 { |
173 vp56_range_coder_t *c = &s->c; | 175 vp56_range_coder_t *c = &s->c; |
176 vp56_model_t *model = s->modelp; | |
174 int comp, node; | 177 int comp, node; |
175 | 178 |
176 for (comp=0; comp<2; comp++) { | 179 for (comp=0; comp<2; comp++) { |
177 if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0])) | 180 if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0])) |
178 s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7); | 181 model->vector_dct[comp] = vp56_rac_gets_nn(c, 7); |
179 if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1])) | 182 if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1])) |
180 s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7); | 183 model->vector_sig[comp] = vp56_rac_gets_nn(c, 7); |
181 } | 184 } |
182 | 185 |
183 for (comp=0; comp<2; comp++) | 186 for (comp=0; comp<2; comp++) |
184 for (node=0; node<7; node++) | 187 for (node=0; node<7; node++) |
185 if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node])) | 188 if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node])) |
186 s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7); | 189 model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7); |
187 | 190 |
188 for (comp=0; comp<2; comp++) | 191 for (comp=0; comp<2; comp++) |
189 for (node=0; node<8; node++) | 192 for (node=0; node<8; node++) |
190 if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node])) | 193 if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node])) |
191 s->vector_model_fdv[comp][node] = vp56_rac_gets_nn(c, 7); | 194 model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7); |
192 } | 195 } |
193 | 196 |
194 static void vp6_parse_coeff_models(vp56_context_t *s) | 197 static void vp6_parse_coeff_models(vp56_context_t *s) |
195 { | 198 { |
196 vp56_range_coder_t *c = &s->c; | 199 vp56_range_coder_t *c = &s->c; |
200 vp56_model_t *model = s->modelp; | |
197 int def_prob[11]; | 201 int def_prob[11]; |
198 int node, cg, ctx, pos; | 202 int node, cg, ctx, pos; |
199 int ct; /* code type */ | 203 int ct; /* code type */ |
200 int pt; /* plane type (0 for Y, 1 for U or V) */ | 204 int pt; /* plane type (0 for Y, 1 for U or V) */ |
201 | 205 |
203 | 207 |
204 for (pt=0; pt<2; pt++) | 208 for (pt=0; pt<2; pt++) |
205 for (node=0; node<11; node++) | 209 for (node=0; node<11; node++) |
206 if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) { | 210 if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) { |
207 def_prob[node] = vp56_rac_gets_nn(c, 7); | 211 def_prob[node] = vp56_rac_gets_nn(c, 7); |
208 s->coeff_model_dccv[pt][node] = def_prob[node]; | 212 model->coeff_dccv[pt][node] = def_prob[node]; |
209 } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { | 213 } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { |
210 s->coeff_model_dccv[pt][node] = def_prob[node]; | 214 model->coeff_dccv[pt][node] = def_prob[node]; |
211 } | 215 } |
212 | 216 |
213 if (vp56_rac_get(c)) { | 217 if (vp56_rac_get(c)) { |
214 for (pos=1; pos<64; pos++) | 218 for (pos=1; pos<64; pos++) |
215 if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos])) | 219 if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos])) |
216 s->coeff_reorder[pos] = vp56_rac_gets(c, 4); | 220 model->coeff_reorder[pos] = vp56_rac_gets(c, 4); |
217 vp6_coeff_order_table_init(s); | 221 vp6_coeff_order_table_init(s); |
218 } | 222 } |
219 | 223 |
220 for (cg=0; cg<2; cg++) | 224 for (cg=0; cg<2; cg++) |
221 for (node=0; node<14; node++) | 225 for (node=0; node<14; node++) |
222 if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node])) | 226 if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node])) |
223 s->coeff_model_runv[cg][node] = vp56_rac_gets_nn(c, 7); | 227 model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7); |
224 | 228 |
225 for (ct=0; ct<3; ct++) | 229 for (ct=0; ct<3; ct++) |
226 for (pt=0; pt<2; pt++) | 230 for (pt=0; pt<2; pt++) |
227 for (cg=0; cg<6; cg++) | 231 for (cg=0; cg<6; cg++) |
228 for (node=0; node<11; node++) | 232 for (node=0; node<11; node++) |
229 if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) { | 233 if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) { |
230 def_prob[node] = vp56_rac_gets_nn(c, 7); | 234 def_prob[node] = vp56_rac_gets_nn(c, 7); |
231 s->coeff_model_ract[pt][ct][cg][node] = def_prob[node]; | 235 model->coeff_ract[pt][ct][cg][node] = def_prob[node]; |
232 } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { | 236 } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { |
233 s->coeff_model_ract[pt][ct][cg][node] = def_prob[node]; | 237 model->coeff_ract[pt][ct][cg][node] = def_prob[node]; |
234 } | 238 } |
235 | 239 |
236 /* coeff_model_dcct is a linear combination of coeff_model_dccv */ | 240 /* coeff_dcct is a linear combination of coeff_dccv */ |
237 for (pt=0; pt<2; pt++) | 241 for (pt=0; pt<2; pt++) |
238 for (ctx=0; ctx<3; ctx++) | 242 for (ctx=0; ctx<3; ctx++) |
239 for (node=0; node<5; node++) | 243 for (node=0; node<5; node++) |
240 s->coeff_model_dcct[pt][ctx][node] = av_clip(((s->coeff_model_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255); | 244 model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255); |
241 } | 245 } |
242 | 246 |
243 static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect) | 247 static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect) |
244 { | 248 { |
245 vp56_range_coder_t *c = &s->c; | 249 vp56_range_coder_t *c = &s->c; |
250 vp56_model_t *model = s->modelp; | |
246 int comp; | 251 int comp; |
247 | 252 |
248 *vect = (vp56_mv_t) {0,0}; | 253 *vect = (vp56_mv_t) {0,0}; |
249 if (s->vector_candidate_pos < 2) | 254 if (s->vector_candidate_pos < 2) |
250 *vect = s->vector_candidate[0]; | 255 *vect = s->vector_candidate[0]; |
251 | 256 |
252 for (comp=0; comp<2; comp++) { | 257 for (comp=0; comp<2; comp++) { |
253 int i, delta = 0; | 258 int i, delta = 0; |
254 | 259 |
255 if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) { | 260 if (vp56_rac_get_prob(c, model->vector_dct[comp])) { |
256 static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4}; | 261 static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4}; |
257 for (i=0; i<sizeof(prob_order); i++) { | 262 for (i=0; i<sizeof(prob_order); i++) { |
258 int j = prob_order[i]; | 263 int j = prob_order[i]; |
259 delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][j])<<j; | 264 delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j; |
260 } | 265 } |
261 if (delta & 0xF0) | 266 if (delta & 0xF0) |
262 delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][3])<<3; | 267 delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3; |
263 else | 268 else |
264 delta |= 8; | 269 delta |= 8; |
265 } else { | 270 } else { |
266 delta = vp56_rac_get_tree(c, vp56_pva_tree, | 271 delta = vp56_rac_get_tree(c, vp56_pva_tree, |
267 s->vector_model_pdv[comp]); | 272 model->vector_pdv[comp]); |
268 } | 273 } |
269 | 274 |
270 if (delta && vp56_rac_get_prob(c, s->vector_model_sig[comp])) | 275 if (delta && vp56_rac_get_prob(c, model->vector_sig[comp])) |
271 delta = -delta; | 276 delta = -delta; |
272 | 277 |
273 if (!comp) | 278 if (!comp) |
274 vect->x += delta; | 279 vect->x += delta; |
275 else | 280 else |
278 } | 283 } |
279 | 284 |
280 static void vp6_parse_coeff(vp56_context_t *s) | 285 static void vp6_parse_coeff(vp56_context_t *s) |
281 { | 286 { |
282 vp56_range_coder_t *c = s->ccp; | 287 vp56_range_coder_t *c = s->ccp; |
288 vp56_model_t *model = s->modelp; | |
283 uint8_t *permute = s->scantable.permutated; | 289 uint8_t *permute = s->scantable.permutated; |
284 uint8_t *model, *model2, *model3; | 290 uint8_t *model1, *model2, *model3; |
285 int coeff, sign, coeff_idx; | 291 int coeff, sign, coeff_idx; |
286 int b, i, cg, idx, ctx; | 292 int b, i, cg, idx, ctx; |
287 int pt = 0; /* plane type (0 for Y, 1 for U or V) */ | 293 int pt = 0; /* plane type (0 for Y, 1 for U or V) */ |
288 | 294 |
289 for (b=0; b<6; b++) { | 295 for (b=0; b<6; b++) { |
292 | 298 |
293 if (b > 3) pt = 1; | 299 if (b > 3) pt = 1; |
294 | 300 |
295 ctx = s->left_block[vp56_b6to4[b]].not_null_dc | 301 ctx = s->left_block[vp56_b6to4[b]].not_null_dc |
296 + s->above_blocks[s->above_block_idx[b]].not_null_dc; | 302 + s->above_blocks[s->above_block_idx[b]].not_null_dc; |
297 model = s->coeff_model_dccv[pt]; | 303 model1 = model->coeff_dccv[pt]; |
298 model2 = s->coeff_model_dcct[pt][ctx]; | 304 model2 = model->coeff_dcct[pt][ctx]; |
299 | 305 |
300 for (coeff_idx=0; coeff_idx<64; ) { | 306 for (coeff_idx=0; coeff_idx<64; ) { |
301 if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) { | 307 if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) { |
302 /* parse a coeff */ | 308 /* parse a coeff */ |
303 if (vp56_rac_get_prob(c, model2[2])) { | 309 if (vp56_rac_get_prob(c, model2[2])) { |
304 if (vp56_rac_get_prob(c, model2[3])) { | 310 if (vp56_rac_get_prob(c, model2[3])) { |
305 idx = vp56_rac_get_tree(c, vp56_pc_tree, model); | 311 idx = vp56_rac_get_tree(c, vp56_pc_tree, model1); |
306 coeff = vp56_coeff_bias[idx]; | 312 coeff = vp56_coeff_bias[idx]; |
307 for (i=vp56_coeff_bit_length[idx]; i>=0; i--) | 313 for (i=vp56_coeff_bit_length[idx]; i>=0; i--) |
308 coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i; | 314 coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i; |
309 } else { | 315 } else { |
310 if (vp56_rac_get_prob(c, model2[4])) | 316 if (vp56_rac_get_prob(c, model2[4])) |
311 coeff = 3 + vp56_rac_get_prob(c, model[5]); | 317 coeff = 3 + vp56_rac_get_prob(c, model1[5]); |
312 else | 318 else |
313 coeff = 2; | 319 coeff = 2; |
314 } | 320 } |
315 ct = 2; | 321 ct = 2; |
316 } else { | 322 } else { |
319 } | 325 } |
320 sign = vp56_rac_get(c); | 326 sign = vp56_rac_get(c); |
321 coeff = (coeff ^ -sign) + sign; | 327 coeff = (coeff ^ -sign) + sign; |
322 if (coeff_idx) | 328 if (coeff_idx) |
323 coeff *= s->dequant_ac; | 329 coeff *= s->dequant_ac; |
324 idx = s->coeff_index_to_pos[coeff_idx]; | 330 idx = model->coeff_index_to_pos[coeff_idx]; |
325 s->block_coeff[b][permute[idx]] = coeff; | 331 s->block_coeff[b][permute[idx]] = coeff; |
326 run = 1; | 332 run = 1; |
327 } else { | 333 } else { |
328 /* parse a run */ | 334 /* parse a run */ |
329 ct = 0; | 335 ct = 0; |
330 if (coeff_idx > 0) { | 336 if (coeff_idx > 0) { |
331 if (!vp56_rac_get_prob(c, model2[1])) | 337 if (!vp56_rac_get_prob(c, model2[1])) |
332 break; | 338 break; |
333 | 339 |
334 model3 = s->coeff_model_runv[coeff_idx >= 6]; | 340 model3 = model->coeff_runv[coeff_idx >= 6]; |
335 run = vp56_rac_get_tree(c, vp6_pcr_tree, model3); | 341 run = vp56_rac_get_tree(c, vp6_pcr_tree, model3); |
336 if (!run) | 342 if (!run) |
337 for (run=9, i=0; i<6; i++) | 343 for (run=9, i=0; i<6; i++) |
338 run += vp56_rac_get_prob(c, model3[i+8]) << i; | 344 run += vp56_rac_get_prob(c, model3[i+8]) << i; |
339 } | 345 } |
340 } | 346 } |
341 | 347 |
342 cg = vp6_coeff_groups[coeff_idx+=run]; | 348 cg = vp6_coeff_groups[coeff_idx+=run]; |
343 model = model2 = s->coeff_model_ract[pt][ct][cg]; | 349 model1 = model2 = model->coeff_ract[pt][ct][cg]; |
344 } | 350 } |
345 | 351 |
346 s->left_block[vp56_b6to4[b]].not_null_dc = | 352 s->left_block[vp56_b6to4[b]].not_null_dc = |
347 s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0]; | 353 s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0]; |
348 } | 354 } |