Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: third_party/libwebp/dec/tree.c

Issue 116213006: Update libwebp to 0.4.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: After Blink Roll Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libwebp/dec/quant.c ('k') | third_party/libwebp/dec/vp8.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 Google Inc. All Rights Reserved. 1 // Copyright 2010 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source 4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // Coding trees and probas 10 // Coding trees and probas
11 // 11 //
12 // Author: Skal (pascal.massimino@gmail.com) 12 // Author: Skal (pascal.massimino@gmail.com)
13 13
14 #include "vp8i.h" 14 #include "vp8i.h"
15 15
16 #define USE_GENERIC_TREE 16 #define USE_GENERIC_TREE
17 17
18 #if defined(__cplusplus) || defined(c_plusplus)
19 extern "C" {
20 #endif
21
22 #ifdef USE_GENERIC_TREE 18 #ifdef USE_GENERIC_TREE
23 static const int8_t kYModesIntra4[18] = { 19 static const int8_t kYModesIntra4[18] = {
24 -B_DC_PRED, 1, 20 -B_DC_PRED, 1,
25 -B_TM_PRED, 2, 21 -B_TM_PRED, 2,
26 -B_VE_PRED, 3, 22 -B_VE_PRED, 3,
27 4, 6, 23 4, 6,
28 -B_HE_PRED, 5, 24 -B_HE_PRED, 5,
29 -B_RD_PRED, -B_VR_PRED, 25 -B_RD_PRED, -B_VR_PRED,
30 -B_LD_PRED, 7, 26 -B_LD_PRED, 7,
31 -B_VL_PRED, 8, 27 -B_VL_PRED, 8,
32 -B_HD_PRED, -B_HU_PRED 28 -B_HD_PRED, -B_HU_PRED
33 }; 29 };
34 #endif 30 #endif
35 31
36 #ifndef ONLY_KEYFRAME_CODE
37
38 // inter prediction modes
39 enum {
40 LEFT4 = 0, ABOVE4 = 1, ZERO4 = 2, NEW4 = 3,
41 NEARESTMV, NEARMV, ZEROMV, NEWMV, SPLITMV };
42
43 static const int8_t kYModesInter[8] = {
44 -DC_PRED, 1,
45 2, 3,
46 -V_PRED, -H_PRED,
47 -TM_PRED, -B_PRED
48 };
49
50 static const int8_t kMBSplit[6] = {
51 -3, 1,
52 -2, 2,
53 -0, -1
54 };
55
56 static const int8_t kMVRef[8] = {
57 -ZEROMV, 1,
58 -NEARESTMV, 2,
59 -NEARMV, 3,
60 -NEWMV, -SPLITMV
61 };
62
63 static const int8_t kMVRef4[6] = {
64 -LEFT4, 1,
65 -ABOVE4, 2,
66 -ZERO4, -NEW4
67 };
68 #endif
69
70 //------------------------------------------------------------------------------ 32 //------------------------------------------------------------------------------
71 // Default probabilities 33 // Default probabilities
72 34
73 // Inter
74 #ifndef ONLY_KEYFRAME_CODE
75 static const uint8_t kYModeProbaInter0[4] = { 112, 86, 140, 37 };
76 static const uint8_t kUVModeProbaInter0[3] = { 162, 101, 204 };
77 static const uint8_t kMVProba0[2][NUM_MV_PROBAS] = {
78 { 162, 128, 225, 146, 172, 147, 214, 39,
79 156, 128, 129, 132, 75, 145, 178, 206,
80 239, 254, 254 },
81 { 164, 128, 204, 170, 119, 235, 140, 230,
82 228, 128, 130, 130, 74, 148, 180, 203,
83 236, 254, 254 }
84 };
85 #endif
86
87 // Paragraph 13.5 35 // Paragraph 13.5
88 static const uint8_t 36 static const uint8_t
89 CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS] = { 37 CoeffsProba0[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS] = {
90 // genereated using vp8_default_coef_probs() in entropy.c:129
91 { { { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, 38 { { { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
92 { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, 39 { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
93 { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } 40 { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }
94 }, 41 },
95 { { 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128 }, 42 { { 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128 },
96 { 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128 }, 43 { 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128 },
97 { 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128 } 44 { 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128 }
98 }, 45 },
99 { { 1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128 }, 46 { { 1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128 },
100 { 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128 }, 47 { 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128 },
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 { 71, 30, 17, 119, 118, 255, 17, 18, 138 }, 268 { 71, 30, 17, 119, 118, 255, 17, 18, 138 },
322 { 101, 38, 60, 138, 55, 70, 43, 26, 142 }, 269 { 101, 38, 60, 138, 55, 70, 43, 26, 142 },
323 { 146, 36, 19, 30, 171, 255, 97, 27, 20 }, 270 { 146, 36, 19, 30, 171, 255, 97, 27, 20 },
324 { 138, 45, 61, 62, 219, 1, 81, 188, 64 }, 271 { 138, 45, 61, 62, 219, 1, 81, 188, 64 },
325 { 32, 41, 20, 117, 151, 142, 20, 21, 163 }, 272 { 32, 41, 20, 117, 151, 142, 20, 21, 163 },
326 { 112, 19, 12, 61, 195, 128, 48, 4, 24 } } 273 { 112, 19, 12, 61, 195, 128, 48, 4, 24 } }
327 }; 274 };
328 275
329 void VP8ResetProba(VP8Proba* const proba) { 276 void VP8ResetProba(VP8Proba* const proba) {
330 memset(proba->segments_, 255u, sizeof(proba->segments_)); 277 memset(proba->segments_, 255u, sizeof(proba->segments_));
331 memcpy(proba->coeffs_, CoeffsProba0, sizeof(CoeffsProba0)); 278 // proba->bands_[][] is initialized later
332 #ifndef ONLY_KEYFRAME_CODE
333 memcpy(proba->mv_, kMVProba0, sizeof(kMVProba0));
334 memcpy(proba->ymode_, kYModeProbaInter0, sizeof(kYModeProbaInter0));
335 memcpy(proba->uvmode_, kUVModeProbaInter0, sizeof(kUVModeProbaInter0));
336 #endif
337 } 279 }
338 280
339 void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec) { 281 void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec) {
340 uint8_t* const top = dec->intra_t_ + 4 * dec->mb_x_; 282 uint8_t* const top = dec->intra_t_ + 4 * dec->mb_x_;
341 uint8_t* const left = dec->intra_l_; 283 uint8_t* const left = dec->intra_l_;
342 // Hardcoded 16x16 intra-mode decision tree. 284 VP8MBData* const block = dec->mb_data_ + dec->mb_x_;
343 dec->is_i4x4_ = !VP8GetBit(br, 145); // decide for B_PRED first 285
344 if (!dec->is_i4x4_) { 286 block->is_i4x4_ = !VP8GetBit(br, 145); // decide for B_PRED first
287 if (!block->is_i4x4_) {
288 // Hardcoded 16x16 intra-mode decision tree.
345 const int ymode = 289 const int ymode =
346 VP8GetBit(br, 156) ? (VP8GetBit(br, 128) ? TM_PRED : H_PRED) 290 VP8GetBit(br, 156) ? (VP8GetBit(br, 128) ? TM_PRED : H_PRED)
347 : (VP8GetBit(br, 163) ? V_PRED : DC_PRED); 291 : (VP8GetBit(br, 163) ? V_PRED : DC_PRED);
348 dec->imodes_[0] = ymode; 292 block->imodes_[0] = ymode;
349 memset(top, ymode, 4 * sizeof(top[0])); 293 memset(top, ymode, 4 * sizeof(*top));
350 memset(left, ymode, 4 * sizeof(left[0])); 294 memset(left, ymode, 4 * sizeof(*left));
351 } else { 295 } else {
352 uint8_t* modes = dec->imodes_; 296 uint8_t* modes = block->imodes_;
353 int y; 297 int y;
354 for (y = 0; y < 4; ++y) { 298 for (y = 0; y < 4; ++y) {
355 int ymode = left[y]; 299 int ymode = left[y];
356 int x; 300 int x;
357 for (x = 0; x < 4; ++x) { 301 for (x = 0; x < 4; ++x) {
358 const uint8_t* const prob = kBModesProba[top[x]][ymode]; 302 const uint8_t* const prob = kBModesProba[top[x]][ymode];
359 #ifdef USE_GENERIC_TREE 303 #ifdef USE_GENERIC_TREE
360 // Generic tree-parsing 304 // Generic tree-parsing
361 int i = 0; 305 int i = kYModesIntra4[VP8GetBit(br, prob[0])];
362 do { 306 while (i > 0) {
363 i = kYModesIntra4[2 * i + VP8GetBit(br, prob[i])]; 307 i = kYModesIntra4[2 * i + VP8GetBit(br, prob[i])];
364 } while (i > 0); 308 }
365 ymode = -i; 309 ymode = -i;
366 #else 310 #else
367 // Hardcoded tree parsing 311 // Hardcoded tree parsing
368 ymode = !VP8GetBit(br, prob[0]) ? B_DC_PRED : 312 ymode = !VP8GetBit(br, prob[0]) ? B_DC_PRED :
369 !VP8GetBit(br, prob[1]) ? B_TM_PRED : 313 !VP8GetBit(br, prob[1]) ? B_TM_PRED :
370 !VP8GetBit(br, prob[2]) ? B_VE_PRED : 314 !VP8GetBit(br, prob[2]) ? B_VE_PRED :
371 !VP8GetBit(br, prob[3]) ? 315 !VP8GetBit(br, prob[3]) ?
372 (!VP8GetBit(br, prob[4]) ? B_HE_PRED : 316 (!VP8GetBit(br, prob[4]) ? B_HE_PRED :
373 (!VP8GetBit(br, prob[5]) ? B_RD_PRED : B_VR_PRED)) : 317 (!VP8GetBit(br, prob[5]) ? B_RD_PRED : B_VR_PRED)) :
374 (!VP8GetBit(br, prob[6]) ? B_LD_PRED : 318 (!VP8GetBit(br, prob[6]) ? B_LD_PRED :
375 (!VP8GetBit(br, prob[7]) ? B_VL_PRED : 319 (!VP8GetBit(br, prob[7]) ? B_VL_PRED :
376 (!VP8GetBit(br, prob[8]) ? B_HD_PRED : B_HU_PRED))); 320 (!VP8GetBit(br, prob[8]) ? B_HD_PRED : B_HU_PRED)));
377 #endif // USE_GENERIC_TREE 321 #endif // USE_GENERIC_TREE
378 top[x] = ymode; 322 top[x] = ymode;
379 *modes++ = ymode;
380 } 323 }
324 memcpy(modes, top, 4 * sizeof(*top));
325 modes += 4;
381 left[y] = ymode; 326 left[y] = ymode;
382 } 327 }
383 } 328 }
384 // Hardcoded UVMode decision tree 329 // Hardcoded UVMode decision tree
385 dec->uvmode_ = !VP8GetBit(br, 142) ? DC_PRED 330 block->uvmode_ = !VP8GetBit(br, 142) ? DC_PRED
386 : !VP8GetBit(br, 114) ? V_PRED 331 : !VP8GetBit(br, 114) ? V_PRED
387 : VP8GetBit(br, 183) ? TM_PRED : H_PRED; 332 : VP8GetBit(br, 183) ? TM_PRED : H_PRED;
388 } 333 }
389 334
390 //------------------------------------------------------------------------------ 335 //------------------------------------------------------------------------------
391 // Paragraph 13 336 // Paragraph 13
392 337
393 static const uint8_t 338 static const uint8_t
394 CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS] = { 339 CoeffsUpdateProba[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS] = {
395 { { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 340 { { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
396 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 341 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
397 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } 342 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 464 { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
520 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } 465 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }
521 }, 466 },
522 { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 467 { { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
523 { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 468 { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
524 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 } 469 { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }
525 } 470 }
526 } 471 }
527 }; 472 };
528 473
529 #ifndef ONLY_KEYFRAME_CODE
530 static const uint8_t MVUpdateProba[2][NUM_MV_PROBAS] = {
531 { 237, 246, 253, 253, 254, 254, 254, 254,
532 254, 254, 254, 254, 254, 254, 250, 250,
533 252, 254, 254 },
534 { 231, 243, 245, 253, 254, 254, 254, 254,
535 254, 254, 254, 254, 254, 254, 251, 251,
536 254, 254, 254 }
537 };
538 #endif
539
540 // Paragraph 9.9 474 // Paragraph 9.9
541 void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec) { 475 void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec) {
542 VP8Proba* const proba = &dec->proba_; 476 VP8Proba* const proba = &dec->proba_;
543 int t, b, c, p; 477 int t, b, c, p;
544 for (t = 0; t < NUM_TYPES; ++t) { 478 for (t = 0; t < NUM_TYPES; ++t) {
545 for (b = 0; b < NUM_BANDS; ++b) { 479 for (b = 0; b < NUM_BANDS; ++b) {
546 for (c = 0; c < NUM_CTX; ++c) { 480 for (c = 0; c < NUM_CTX; ++c) {
547 for (p = 0; p < NUM_PROBAS; ++p) { 481 for (p = 0; p < NUM_PROBAS; ++p) {
548 if (VP8GetBit(br, CoeffsUpdateProba[t][b][c][p])) { 482 const int v = VP8GetBit(br, CoeffsUpdateProba[t][b][c][p]) ?
549 proba->coeffs_[t][b][c][p] = VP8GetValue(br, 8); 483 VP8GetValue(br, 8) : CoeffsProba0[t][b][c][p];
550 } 484 proba->bands_[t][b].probas_[c][p] = v;
551 } 485 }
552 } 486 }
553 } 487 }
554 } 488 }
555 dec->use_skip_proba_ = VP8Get(br); 489 dec->use_skip_proba_ = VP8Get(br);
556 if (dec->use_skip_proba_) { 490 if (dec->use_skip_proba_) {
557 dec->skip_p_ = VP8GetValue(br, 8); 491 dec->skip_p_ = VP8GetValue(br, 8);
558 } 492 }
559 #ifndef ONLY_KEYFRAME_CODE
560 if (!dec->frm_hdr_.key_frame_) {
561 int i;
562 dec->intra_p_ = VP8GetValue(br, 8);
563 dec->last_p_ = VP8GetValue(br, 8);
564 dec->golden_p_ = VP8GetValue(br, 8);
565 if (VP8Get(br)) { // update y-mode
566 for (i = 0; i < 4; ++i) {
567 proba->ymode_[i] = VP8GetValue(br, 8);
568 }
569 }
570 if (VP8Get(br)) { // update uv-mode
571 for (i = 0; i < 3; ++i) {
572 proba->uvmode_[i] = VP8GetValue(br, 8);
573 }
574 }
575 // update MV
576 for (i = 0; i < 2; ++i) {
577 int k;
578 for (k = 0; k < NUM_MV_PROBAS; ++k) {
579 if (VP8GetBit(br, MVUpdateProba[i][k])) {
580 const int v = VP8GetValue(br, 7);
581 proba->mv_[i][k] = v ? v << 1 : 1;
582 }
583 }
584 }
585 }
586 #endif
587 } 493 }
588 494
589 #if defined(__cplusplus) || defined(c_plusplus)
590 } // extern "C"
591 #endif
OLDNEW
« no previous file with comments | « third_party/libwebp/dec/quant.c ('k') | third_party/libwebp/dec/vp8.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698