media/libvpx/vp8/encoder/tokenize.c

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11
michael@0 12 #include <math.h>
michael@0 13 #include <stdio.h>
michael@0 14 #include <string.h>
michael@0 15 #include <assert.h>
michael@0 16 #include "onyx_int.h"
michael@0 17 #include "tokenize.h"
michael@0 18 #include "vpx_mem/vpx_mem.h"
michael@0 19
michael@0 20 /* Global event counters used for accumulating statistics across several
michael@0 21 compressions, then generating context.c = initial stats. */
michael@0 22
michael@0 23 #ifdef VP8_ENTROPY_STATS
michael@0 24 _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
michael@0 25 #endif
michael@0 26 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t) ;
michael@0 27 void vp8_fix_contexts(MACROBLOCKD *x);
michael@0 28
michael@0 29 #include "dct_value_tokens.h"
michael@0 30 #include "dct_value_cost.h"
michael@0 31
michael@0 32 const TOKENVALUE *const vp8_dct_value_tokens_ptr = dct_value_tokens +
michael@0 33 DCT_MAX_VALUE;
michael@0 34 const short *const vp8_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
michael@0 35
michael@0 36 #if 0
michael@0 37 int skip_true_count = 0;
michael@0 38 int skip_false_count = 0;
michael@0 39 #endif
michael@0 40
michael@0 41 /* function used to generate dct_value_tokens and dct_value_cost tables */
michael@0 42 /*
michael@0 43 static void fill_value_tokens()
michael@0 44 {
michael@0 45
michael@0 46 TOKENVALUE *t = dct_value_tokens + DCT_MAX_VALUE;
michael@0 47 const vp8_extra_bit_struct *e = vp8_extra_bits;
michael@0 48
michael@0 49 int i = -DCT_MAX_VALUE;
michael@0 50 int sign = 1;
michael@0 51
michael@0 52 do
michael@0 53 {
michael@0 54 if (!i)
michael@0 55 sign = 0;
michael@0 56
michael@0 57 {
michael@0 58 const int a = sign ? -i : i;
michael@0 59 int eb = sign;
michael@0 60
michael@0 61 if (a > 4)
michael@0 62 {
michael@0 63 int j = 4;
michael@0 64
michael@0 65 while (++j < 11 && e[j].base_val <= a) {}
michael@0 66
michael@0 67 t[i].Token = --j;
michael@0 68 eb |= (a - e[j].base_val) << 1;
michael@0 69 }
michael@0 70 else
michael@0 71 t[i].Token = a;
michael@0 72
michael@0 73 t[i].Extra = eb;
michael@0 74 }
michael@0 75
michael@0 76 // initialize the cost for extra bits for all possible coefficient value.
michael@0 77 {
michael@0 78 int cost = 0;
michael@0 79 const vp8_extra_bit_struct *p = vp8_extra_bits + t[i].Token;
michael@0 80
michael@0 81 if (p->base_val)
michael@0 82 {
michael@0 83 const int extra = t[i].Extra;
michael@0 84 const int Length = p->Len;
michael@0 85
michael@0 86 if (Length)
michael@0 87 cost += vp8_treed_cost(p->tree, p->prob, extra >> 1, Length);
michael@0 88
michael@0 89 cost += vp8_cost_bit(vp8_prob_half, extra & 1); // sign
michael@0 90 dct_value_cost[i + DCT_MAX_VALUE] = cost;
michael@0 91 }
michael@0 92
michael@0 93 }
michael@0 94
michael@0 95 }
michael@0 96 while (++i < DCT_MAX_VALUE);
michael@0 97
michael@0 98 vp8_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE;
michael@0 99 vp8_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
michael@0 100 }
michael@0 101 */
michael@0 102
michael@0 103 static void tokenize2nd_order_b
michael@0 104 (
michael@0 105 MACROBLOCK *x,
michael@0 106 TOKENEXTRA **tp,
michael@0 107 VP8_COMP *cpi
michael@0 108 )
michael@0 109 {
michael@0 110 MACROBLOCKD *xd = &x->e_mbd;
michael@0 111 int pt; /* near block/prev token context index */
michael@0 112 int c; /* start at DC */
michael@0 113 TOKENEXTRA *t = *tp;/* store tokens starting here */
michael@0 114 const BLOCKD *b;
michael@0 115 const short *qcoeff_ptr;
michael@0 116 ENTROPY_CONTEXT * a;
michael@0 117 ENTROPY_CONTEXT * l;
michael@0 118 int band, rc, v, token;
michael@0 119 int eob;
michael@0 120
michael@0 121 b = xd->block + 24;
michael@0 122 qcoeff_ptr = b->qcoeff;
michael@0 123 a = (ENTROPY_CONTEXT *)xd->above_context + 8;
michael@0 124 l = (ENTROPY_CONTEXT *)xd->left_context + 8;
michael@0 125 eob = xd->eobs[24];
michael@0 126 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
michael@0 127
michael@0 128 if(!eob)
michael@0 129 {
michael@0 130 /* c = band for this case */
michael@0 131 t->Token = DCT_EOB_TOKEN;
michael@0 132 t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
michael@0 133 t->skip_eob_node = 0;
michael@0 134
michael@0 135 ++x->coef_counts [1] [0] [pt] [DCT_EOB_TOKEN];
michael@0 136 t++;
michael@0 137 *tp = t;
michael@0 138 *a = *l = 0;
michael@0 139 return;
michael@0 140 }
michael@0 141
michael@0 142 v = qcoeff_ptr[0];
michael@0 143 t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
michael@0 144 token = vp8_dct_value_tokens_ptr[v].Token;
michael@0 145 t->Token = token;
michael@0 146
michael@0 147 t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
michael@0 148 t->skip_eob_node = 0;
michael@0 149 ++x->coef_counts [1] [0] [pt] [token];
michael@0 150 pt = vp8_prev_token_class[token];
michael@0 151 t++;
michael@0 152 c = 1;
michael@0 153
michael@0 154 for (; c < eob; c++)
michael@0 155 {
michael@0 156 rc = vp8_default_zig_zag1d[c];
michael@0 157 band = vp8_coef_bands[c];
michael@0 158 v = qcoeff_ptr[rc];
michael@0 159
michael@0 160 t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
michael@0 161 token = vp8_dct_value_tokens_ptr[v].Token;
michael@0 162
michael@0 163 t->Token = token;
michael@0 164 t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt];
michael@0 165
michael@0 166 t->skip_eob_node = ((pt == 0));
michael@0 167
michael@0 168 ++x->coef_counts [1] [band] [pt] [token];
michael@0 169
michael@0 170 pt = vp8_prev_token_class[token];
michael@0 171 t++;
michael@0 172 }
michael@0 173 if (c < 16)
michael@0 174 {
michael@0 175 band = vp8_coef_bands[c];
michael@0 176 t->Token = DCT_EOB_TOKEN;
michael@0 177 t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt];
michael@0 178
michael@0 179 t->skip_eob_node = 0;
michael@0 180
michael@0 181 ++x->coef_counts [1] [band] [pt] [DCT_EOB_TOKEN];
michael@0 182
michael@0 183 t++;
michael@0 184 }
michael@0 185
michael@0 186 *tp = t;
michael@0 187 *a = *l = 1;
michael@0 188
michael@0 189 }
michael@0 190
michael@0 191 static void tokenize1st_order_b
michael@0 192 (
michael@0 193 MACROBLOCK *x,
michael@0 194 TOKENEXTRA **tp,
michael@0 195 int type, /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */
michael@0 196 VP8_COMP *cpi
michael@0 197 )
michael@0 198 {
michael@0 199 MACROBLOCKD *xd = &x->e_mbd;
michael@0 200 unsigned int block;
michael@0 201 const BLOCKD *b;
michael@0 202 int pt; /* near block/prev token context index */
michael@0 203 int c;
michael@0 204 int token;
michael@0 205 TOKENEXTRA *t = *tp;/* store tokens starting here */
michael@0 206 const short *qcoeff_ptr;
michael@0 207 ENTROPY_CONTEXT * a;
michael@0 208 ENTROPY_CONTEXT * l;
michael@0 209 int band, rc, v;
michael@0 210 int tmp1, tmp2;
michael@0 211
michael@0 212 b = xd->block;
michael@0 213 /* Luma */
michael@0 214 for (block = 0; block < 16; block++, b++)
michael@0 215 {
michael@0 216 tmp1 = vp8_block2above[block];
michael@0 217 tmp2 = vp8_block2left[block];
michael@0 218 qcoeff_ptr = b->qcoeff;
michael@0 219 a = (ENTROPY_CONTEXT *)xd->above_context + tmp1;
michael@0 220 l = (ENTROPY_CONTEXT *)xd->left_context + tmp2;
michael@0 221
michael@0 222 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
michael@0 223
michael@0 224 c = type ? 0 : 1;
michael@0 225
michael@0 226 if(c >= *b->eob)
michael@0 227 {
michael@0 228 /* c = band for this case */
michael@0 229 t->Token = DCT_EOB_TOKEN;
michael@0 230 t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt];
michael@0 231 t->skip_eob_node = 0;
michael@0 232
michael@0 233 ++x->coef_counts [type] [c] [pt] [DCT_EOB_TOKEN];
michael@0 234 t++;
michael@0 235 *tp = t;
michael@0 236 *a = *l = 0;
michael@0 237 continue;
michael@0 238 }
michael@0 239
michael@0 240 v = qcoeff_ptr[c];
michael@0 241
michael@0 242 t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
michael@0 243 token = vp8_dct_value_tokens_ptr[v].Token;
michael@0 244 t->Token = token;
michael@0 245
michael@0 246 t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt];
michael@0 247 t->skip_eob_node = 0;
michael@0 248 ++x->coef_counts [type] [c] [pt] [token];
michael@0 249 pt = vp8_prev_token_class[token];
michael@0 250 t++;
michael@0 251 c++;
michael@0 252
michael@0 253 for (; c < *b->eob; c++)
michael@0 254 {
michael@0 255 rc = vp8_default_zig_zag1d[c];
michael@0 256 band = vp8_coef_bands[c];
michael@0 257 v = qcoeff_ptr[rc];
michael@0 258
michael@0 259 t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
michael@0 260 token = vp8_dct_value_tokens_ptr[v].Token;
michael@0 261
michael@0 262 t->Token = token;
michael@0 263 t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
michael@0 264
michael@0 265 t->skip_eob_node = (pt == 0);
michael@0 266 ++x->coef_counts [type] [band] [pt] [token];
michael@0 267
michael@0 268 pt = vp8_prev_token_class[token];
michael@0 269 t++;
michael@0 270 }
michael@0 271 if (c < 16)
michael@0 272 {
michael@0 273 band = vp8_coef_bands[c];
michael@0 274 t->Token = DCT_EOB_TOKEN;
michael@0 275 t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
michael@0 276
michael@0 277 t->skip_eob_node = 0;
michael@0 278 ++x->coef_counts [type] [band] [pt] [DCT_EOB_TOKEN];
michael@0 279
michael@0 280 t++;
michael@0 281 }
michael@0 282 *tp = t;
michael@0 283 *a = *l = 1;
michael@0 284 }
michael@0 285
michael@0 286 /* Chroma */
michael@0 287 for (block = 16; block < 24; block++, b++)
michael@0 288 {
michael@0 289 tmp1 = vp8_block2above[block];
michael@0 290 tmp2 = vp8_block2left[block];
michael@0 291 qcoeff_ptr = b->qcoeff;
michael@0 292 a = (ENTROPY_CONTEXT *)xd->above_context + tmp1;
michael@0 293 l = (ENTROPY_CONTEXT *)xd->left_context + tmp2;
michael@0 294
michael@0 295 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
michael@0 296
michael@0 297 if(!(*b->eob))
michael@0 298 {
michael@0 299 /* c = band for this case */
michael@0 300 t->Token = DCT_EOB_TOKEN;
michael@0 301 t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
michael@0 302 t->skip_eob_node = 0;
michael@0 303
michael@0 304 ++x->coef_counts [2] [0] [pt] [DCT_EOB_TOKEN];
michael@0 305 t++;
michael@0 306 *tp = t;
michael@0 307 *a = *l = 0;
michael@0 308 continue;
michael@0 309 }
michael@0 310
michael@0 311 v = qcoeff_ptr[0];
michael@0 312
michael@0 313 t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
michael@0 314 token = vp8_dct_value_tokens_ptr[v].Token;
michael@0 315 t->Token = token;
michael@0 316
michael@0 317 t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
michael@0 318 t->skip_eob_node = 0;
michael@0 319 ++x->coef_counts [2] [0] [pt] [token];
michael@0 320 pt = vp8_prev_token_class[token];
michael@0 321 t++;
michael@0 322 c = 1;
michael@0 323
michael@0 324 for (; c < *b->eob; c++)
michael@0 325 {
michael@0 326 rc = vp8_default_zig_zag1d[c];
michael@0 327 band = vp8_coef_bands[c];
michael@0 328 v = qcoeff_ptr[rc];
michael@0 329
michael@0 330 t->Extra = vp8_dct_value_tokens_ptr[v].Extra;
michael@0 331 token = vp8_dct_value_tokens_ptr[v].Token;
michael@0 332
michael@0 333 t->Token = token;
michael@0 334 t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt];
michael@0 335
michael@0 336 t->skip_eob_node = (pt == 0);
michael@0 337
michael@0 338 ++x->coef_counts [2] [band] [pt] [token];
michael@0 339
michael@0 340 pt = vp8_prev_token_class[token];
michael@0 341 t++;
michael@0 342 }
michael@0 343 if (c < 16)
michael@0 344 {
michael@0 345 band = vp8_coef_bands[c];
michael@0 346 t->Token = DCT_EOB_TOKEN;
michael@0 347 t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt];
michael@0 348
michael@0 349 t->skip_eob_node = 0;
michael@0 350
michael@0 351 ++x->coef_counts [2] [band] [pt] [DCT_EOB_TOKEN];
michael@0 352
michael@0 353 t++;
michael@0 354 }
michael@0 355 *tp = t;
michael@0 356 *a = *l = 1;
michael@0 357 }
michael@0 358 }
michael@0 359
michael@0 360
michael@0 361 static int mb_is_skippable(MACROBLOCKD *x, int has_y2_block)
michael@0 362 {
michael@0 363 int skip = 1;
michael@0 364 int i = 0;
michael@0 365
michael@0 366 if (has_y2_block)
michael@0 367 {
michael@0 368 for (i = 0; i < 16; i++)
michael@0 369 skip &= (x->eobs[i] < 2);
michael@0 370 }
michael@0 371
michael@0 372 for (; i < 24 + has_y2_block; i++)
michael@0 373 skip &= (!x->eobs[i]);
michael@0 374
michael@0 375 return skip;
michael@0 376 }
michael@0 377
michael@0 378
michael@0 379 void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
michael@0 380 {
michael@0 381 MACROBLOCKD *xd = &x->e_mbd;
michael@0 382 int plane_type;
michael@0 383 int has_y2_block;
michael@0 384
michael@0 385 has_y2_block = (xd->mode_info_context->mbmi.mode != B_PRED
michael@0 386 && xd->mode_info_context->mbmi.mode != SPLITMV);
michael@0 387
michael@0 388 xd->mode_info_context->mbmi.mb_skip_coeff =
michael@0 389 mb_is_skippable(xd, has_y2_block);
michael@0 390 if (xd->mode_info_context->mbmi.mb_skip_coeff)
michael@0 391 {
michael@0 392 if (!cpi->common.mb_no_coeff_skip)
michael@0 393 {
michael@0 394 vp8_stuff_mb(cpi, x, t);
michael@0 395 }
michael@0 396 else
michael@0 397 {
michael@0 398 vp8_fix_contexts(xd);
michael@0 399 x->skip_true_count++;
michael@0 400 }
michael@0 401
michael@0 402 return;
michael@0 403 }
michael@0 404
michael@0 405 plane_type = 3;
michael@0 406 if(has_y2_block)
michael@0 407 {
michael@0 408 tokenize2nd_order_b(x, t, cpi);
michael@0 409 plane_type = 0;
michael@0 410 }
michael@0 411
michael@0 412 tokenize1st_order_b(x, t, plane_type, cpi);
michael@0 413 }
michael@0 414
michael@0 415
michael@0 416 #ifdef VP8_ENTROPY_STATS
michael@0 417
michael@0 418 void init_context_counters(void)
michael@0 419 {
michael@0 420 vpx_memset(context_counters, 0, sizeof(context_counters));
michael@0 421 }
michael@0 422
michael@0 423 void print_context_counters()
michael@0 424 {
michael@0 425
michael@0 426 int type, band, pt, t;
michael@0 427
michael@0 428 FILE *const f = fopen("context.c", "w");
michael@0 429
michael@0 430 fprintf(f, "#include \"entropy.h\"\n");
michael@0 431
michael@0 432 fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
michael@0 433
michael@0 434 fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];\n\n");
michael@0 435
michael@0 436 fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {");
michael@0 437
michael@0 438 # define Comma( X) (X? ",":"")
michael@0 439
michael@0 440 type = 0;
michael@0 441
michael@0 442 do
michael@0 443 {
michael@0 444 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type);
michael@0 445
michael@0 446 band = 0;
michael@0 447
michael@0 448 do
michael@0 449 {
michael@0 450 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band);
michael@0 451
michael@0 452 pt = 0;
michael@0 453
michael@0 454 do
michael@0 455 {
michael@0 456 fprintf(f, "%s\n {", Comma(pt));
michael@0 457
michael@0 458 t = 0;
michael@0 459
michael@0 460 do
michael@0 461 {
michael@0 462 const _int64 x = context_counters [type] [band] [pt] [t];
michael@0 463 const int y = (int) x;
michael@0 464
michael@0 465 assert(x == (_int64) y); /* no overflow handling yet */
michael@0 466 fprintf(f, "%s %d", Comma(t), y);
michael@0 467
michael@0 468 }
michael@0 469 while (++t < MAX_ENTROPY_TOKENS);
michael@0 470
michael@0 471 fprintf(f, "}");
michael@0 472 }
michael@0 473 while (++pt < PREV_COEF_CONTEXTS);
michael@0 474
michael@0 475 fprintf(f, "\n }");
michael@0 476
michael@0 477 }
michael@0 478 while (++band < COEF_BANDS);
michael@0 479
michael@0 480 fprintf(f, "\n }");
michael@0 481 }
michael@0 482 while (++type < BLOCK_TYPES);
michael@0 483
michael@0 484 fprintf(f, "\n};\n");
michael@0 485 fclose(f);
michael@0 486 }
michael@0 487 #endif
michael@0 488
michael@0 489
michael@0 490 static void stuff2nd_order_b
michael@0 491 (
michael@0 492 TOKENEXTRA **tp,
michael@0 493 ENTROPY_CONTEXT *a,
michael@0 494 ENTROPY_CONTEXT *l,
michael@0 495 VP8_COMP *cpi,
michael@0 496 MACROBLOCK *x
michael@0 497 )
michael@0 498 {
michael@0 499 int pt; /* near block/prev token context index */
michael@0 500 TOKENEXTRA *t = *tp; /* store tokens starting here */
michael@0 501 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
michael@0 502
michael@0 503 t->Token = DCT_EOB_TOKEN;
michael@0 504 t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt];
michael@0 505 t->skip_eob_node = 0;
michael@0 506 ++x->coef_counts [1] [0] [pt] [DCT_EOB_TOKEN];
michael@0 507 ++t;
michael@0 508
michael@0 509 *tp = t;
michael@0 510 pt = 0;
michael@0 511 *a = *l = pt;
michael@0 512 }
michael@0 513
michael@0 514 static void stuff1st_order_b
michael@0 515 (
michael@0 516 TOKENEXTRA **tp,
michael@0 517 ENTROPY_CONTEXT *a,
michael@0 518 ENTROPY_CONTEXT *l,
michael@0 519 int type,
michael@0 520 VP8_COMP *cpi,
michael@0 521 MACROBLOCK *x
michael@0 522 )
michael@0 523 {
michael@0 524 int pt; /* near block/prev token context index */
michael@0 525 int band;
michael@0 526 TOKENEXTRA *t = *tp; /* store tokens starting here */
michael@0 527 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
michael@0 528 band = type ? 0 : 1;
michael@0 529 t->Token = DCT_EOB_TOKEN;
michael@0 530 t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
michael@0 531 t->skip_eob_node = 0;
michael@0 532 ++x->coef_counts [type] [band] [pt] [DCT_EOB_TOKEN];
michael@0 533 ++t;
michael@0 534 *tp = t;
michael@0 535 pt = 0; /* 0 <-> all coeff data is zero */
michael@0 536 *a = *l = pt;
michael@0 537 }
michael@0 538
michael@0 539 static
michael@0 540 void stuff1st_order_buv
michael@0 541 (
michael@0 542 TOKENEXTRA **tp,
michael@0 543 ENTROPY_CONTEXT *a,
michael@0 544 ENTROPY_CONTEXT *l,
michael@0 545 VP8_COMP *cpi,
michael@0 546 MACROBLOCK *x
michael@0 547 )
michael@0 548 {
michael@0 549 int pt; /* near block/prev token context index */
michael@0 550 TOKENEXTRA *t = *tp; /* store tokens starting here */
michael@0 551 VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
michael@0 552
michael@0 553 t->Token = DCT_EOB_TOKEN;
michael@0 554 t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt];
michael@0 555 t->skip_eob_node = 0;
michael@0 556 ++x->coef_counts[2] [0] [pt] [DCT_EOB_TOKEN];
michael@0 557 ++t;
michael@0 558 *tp = t;
michael@0 559 pt = 0; /* 0 <-> all coeff data is zero */
michael@0 560 *a = *l = pt;
michael@0 561 }
michael@0 562
michael@0 563 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
michael@0 564 {
michael@0 565 MACROBLOCKD *xd = &x->e_mbd;
michael@0 566 ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)xd->above_context;
michael@0 567 ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)xd->left_context;
michael@0 568 int plane_type;
michael@0 569 int b;
michael@0 570 plane_type = 3;
michael@0 571 if((xd->mode_info_context->mbmi.mode != B_PRED
michael@0 572 && xd->mode_info_context->mbmi.mode != SPLITMV))
michael@0 573 {
michael@0 574 stuff2nd_order_b(t,
michael@0 575 A + vp8_block2above[24], L + vp8_block2left[24], cpi, x);
michael@0 576 plane_type = 0;
michael@0 577 }
michael@0 578
michael@0 579 for (b = 0; b < 16; b++)
michael@0 580 stuff1st_order_b(t,
michael@0 581 A + vp8_block2above[b],
michael@0 582 L + vp8_block2left[b], plane_type, cpi, x);
michael@0 583
michael@0 584 for (b = 16; b < 24; b++)
michael@0 585 stuff1st_order_buv(t,
michael@0 586 A + vp8_block2above[b],
michael@0 587 L + vp8_block2left[b], cpi, x);
michael@0 588
michael@0 589 }
michael@0 590 void vp8_fix_contexts(MACROBLOCKD *x)
michael@0 591 {
michael@0 592 /* Clear entropy contexts for Y2 blocks */
michael@0 593 if (x->mode_info_context->mbmi.mode != B_PRED && x->mode_info_context->mbmi.mode != SPLITMV)
michael@0 594 {
michael@0 595 vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
michael@0 596 vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
michael@0 597 }
michael@0 598 else
michael@0 599 {
michael@0 600 vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
michael@0 601 vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1);
michael@0 602 }
michael@0 603
michael@0 604 }

mercurial