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

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

Issue 12942006: libwebp: update snapshot to v0.3.0-rc6 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: local webkit layout expectations Created 7 years, 9 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
OLDNEW
1 // Copyright 2010 Google Inc. All Rights Reserved. 1 // Copyright 2010 Google Inc. All Rights Reserved.
2 // 2 //
3 // This code is licensed under the same terms as WebM: 3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/ 4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // ----------------------------------------------------------------------------- 6 // -----------------------------------------------------------------------------
7 // 7 //
8 // main entry for the decoder 8 // main entry for the decoder
9 // 9 //
10 // Author: Skal (pascal.massimino@gmail.com) 10 // Author: Skal (pascal.massimino@gmail.com)
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 229 }
230 } 230 }
231 for (i = 0; i < NUM_MODE_LF_DELTAS; ++i) { 231 for (i = 0; i < NUM_MODE_LF_DELTAS; ++i) {
232 if (VP8Get(br)) { 232 if (VP8Get(br)) {
233 hdr->mode_lf_delta_[i] = VP8GetSignedValue(br, 6); 233 hdr->mode_lf_delta_[i] = VP8GetSignedValue(br, 6);
234 } 234 }
235 } 235 }
236 } 236 }
237 } 237 }
238 dec->filter_type_ = (hdr->level_ == 0) ? 0 : hdr->simple_ ? 1 : 2; 238 dec->filter_type_ = (hdr->level_ == 0) ? 0 : hdr->simple_ ? 1 : 2;
239 if (dec->filter_type_ > 0) { // precompute filter levels per segment
240 if (dec->segment_hdr_.use_segment_) {
241 int s;
242 for (s = 0; s < NUM_MB_SEGMENTS; ++s) {
243 int strength = dec->segment_hdr_.filter_strength_[s];
244 if (!dec->segment_hdr_.absolute_delta_) {
245 strength += hdr->level_;
246 }
247 dec->filter_levels_[s] = strength;
248 }
249 } else {
250 dec->filter_levels_[0] = hdr->level_;
251 }
252 }
253 return !br->eof_; 239 return !br->eof_;
254 } 240 }
255 241
256 // Topmost call 242 // Topmost call
257 int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) { 243 int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) {
258 const uint8_t* buf; 244 const uint8_t* buf;
259 size_t buf_size; 245 size_t buf_size;
260 VP8FrameHeader* frm_hdr; 246 VP8FrameHeader* frm_hdr;
261 VP8PictureHeader* pic_hdr; 247 VP8PictureHeader* pic_hdr;
262 VP8BitReader* br; 248 VP8BitReader* br;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 #endif 437 #endif
452 438
453 // sanitized state 439 // sanitized state
454 dec->ready_ = 1; 440 dec->ready_ = 1;
455 return 1; 441 return 1;
456 } 442 }
457 443
458 //------------------------------------------------------------------------------ 444 //------------------------------------------------------------------------------
459 // Residual decoding (Paragraph 13.2 / 13.3) 445 // Residual decoding (Paragraph 13.2 / 13.3)
460 446
461 static const uint8_t kBands[16 + 1] = { 447 static const int kBands[16 + 1] = {
462 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 448 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7,
463 0 // extra entry as sentinel 449 0 // extra entry as sentinel
464 }; 450 };
465 451
466 static const uint8_t kCat3[] = { 173, 148, 140, 0 }; 452 static const uint8_t kCat3[] = { 173, 148, 140, 0 };
467 static const uint8_t kCat4[] = { 176, 155, 140, 135, 0 }; 453 static const uint8_t kCat4[] = { 176, 155, 140, 135, 0 };
468 static const uint8_t kCat5[] = { 180, 157, 141, 134, 130, 0 }; 454 static const uint8_t kCat5[] = { 180, 157, 141, 134, 130, 0 };
469 static const uint8_t kCat6[] = 455 static const uint8_t kCat6[] =
470 { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0 }; 456 { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0 };
471 static const uint8_t* const kCat3456[] = { kCat3, kCat4, kCat5, kCat6 }; 457 static const uint8_t* const kCat3456[] = { kCat3, kCat4, kCat5, kCat6 };
472 static const uint8_t kZigzag[16] = { 458 static const uint8_t kZigzag[16] = {
473 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 459 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
474 }; 460 };
475 461
476 typedef const uint8_t (*ProbaArray)[NUM_CTX][NUM_PROBAS]; // for const-casting 462 typedef const uint8_t (*ProbaArray)[NUM_CTX][NUM_PROBAS]; // for const-casting
463 typedef const uint8_t (*ProbaCtxArray)[NUM_PROBAS];
464
465 // See section 13-2: http://tools.ietf.org/html/rfc6386#section-13.2
466 static int GetLargeValue(VP8BitReader* const br, const uint8_t* const p) {
467 int v;
468 if (!VP8GetBit(br, p[3])) {
469 if (!VP8GetBit(br, p[4])) {
470 v = 2;
471 } else {
472 v = 3 + VP8GetBit(br, p[5]);
473 }
474 } else {
475 if (!VP8GetBit(br, p[6])) {
476 if (!VP8GetBit(br, p[7])) {
477 v = 5 + VP8GetBit(br, 159);
478 } else {
479 v = 7 + 2 * VP8GetBit(br, 165);
480 v += VP8GetBit(br, 145);
481 }
482 } else {
483 const uint8_t* tab;
484 const int bit1 = VP8GetBit(br, p[8]);
485 const int bit0 = VP8GetBit(br, p[9 + bit1]);
486 const int cat = 2 * bit1 + bit0;
487 v = 0;
488 for (tab = kCat3456[cat]; *tab; ++tab) {
489 v += v + VP8GetBit(br, *tab);
490 }
491 v += 3 + (8 << cat);
492 }
493 }
494 return v;
495 }
477 496
478 // Returns the position of the last non-zero coeff plus one 497 // Returns the position of the last non-zero coeff plus one
479 // (and 0 if there's no coeff at all) 498 // (and 0 if there's no coeff at all)
480 static int GetCoeffs(VP8BitReader* const br, ProbaArray prob, 499 static int GetCoeffs(VP8BitReader* const br, ProbaArray prob,
481 int ctx, const quant_t dq, int n, int16_t* out) { 500 int ctx, const quant_t dq, int n, int16_t* out) {
482 // n is either 0 or 1 here. kBands[n] is not necessary for extracting '*p'. 501 // n is either 0 or 1 here. kBands[n] is not necessary for extracting '*p'.
483 const uint8_t* p = prob[n][ctx]; 502 const uint8_t* p = prob[n][ctx];
484 if (!VP8GetBit(br, p[0])) { // first EOB is more a 'CBP' bit. 503 if (!VP8GetBit(br, p[0])) { // first EOB is more a 'CBP' bit.
485 return 0; 504 return 0;
486 } 505 }
487 while (1) { 506 for (; n < 16; ++n) {
488 ++n; 507 const ProbaCtxArray p_ctx = prob[kBands[n + 1]];
489 if (!VP8GetBit(br, p[1])) { 508 if (!VP8GetBit(br, p[1])) {
490 p = prob[kBands[n]][0]; 509 p = p_ctx[0];
491 } else { // non zero coeff 510 } else { // non zero coeff
492 int v, j; 511 int v;
493 if (!VP8GetBit(br, p[2])) { 512 if (!VP8GetBit(br, p[2])) {
494 p = prob[kBands[n]][1];
495 v = 1; 513 v = 1;
514 p = p_ctx[1];
496 } else { 515 } else {
497 if (!VP8GetBit(br, p[3])) { 516 v = GetLargeValue(br, p);
498 if (!VP8GetBit(br, p[4])) { 517 p = p_ctx[2];
499 v = 2;
500 } else {
501 v = 3 + VP8GetBit(br, p[5]);
502 }
503 } else {
504 if (!VP8GetBit(br, p[6])) {
505 if (!VP8GetBit(br, p[7])) {
506 v = 5 + VP8GetBit(br, 159);
507 } else {
508 v = 7 + 2 * VP8GetBit(br, 165);
509 v += VP8GetBit(br, 145);
510 }
511 } else {
512 const uint8_t* tab;
513 const int bit1 = VP8GetBit(br, p[8]);
514 const int bit0 = VP8GetBit(br, p[9 + bit1]);
515 const int cat = 2 * bit1 + bit0;
516 v = 0;
517 for (tab = kCat3456[cat]; *tab; ++tab) {
518 v += v + VP8GetBit(br, *tab);
519 }
520 v += 3 + (8 << cat);
521 }
522 }
523 p = prob[kBands[n]][2];
524 } 518 }
525 j = kZigzag[n - 1]; 519 out[kZigzag[n]] = VP8GetSigned(br, v) * dq[n > 0];
526 out[j] = VP8GetSigned(br, v) * dq[j > 0]; 520 if (n < 15 && !VP8GetBit(br, p[0])) { // EOB
527 if (n == 16 || !VP8GetBit(br, p[0])) { // EOB 521 return n + 1;
528 return n;
529 } 522 }
530 } 523 }
531 if (n == 16) {
532 return 16;
533 }
534 } 524 }
525 return 16;
535 } 526 }
536 527
537 // Alias-safe way of converting 4bytes to 32bits. 528 // Alias-safe way of converting 4bytes to 32bits.
538 typedef union { 529 typedef union {
539 uint8_t i8[4]; 530 uint8_t i8[4];
540 uint32_t i32; 531 uint32_t i32;
541 } PackedNz; 532 } PackedNz;
542 533
543 // Table to unpack four bits into four bytes 534 // Table to unpack four bits into four bytes
544 static const PackedNz kUnpackTab[16] = { 535 static const PackedNz kUnpackTab[16] = {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 ParseResiduals(dec, info, token_br); 654 ParseResiduals(dec, info, token_br);
664 } else { 655 } else {
665 left->nz_ = info->nz_ = 0; 656 left->nz_ = info->nz_ = 0;
666 if (!dec->is_i4x4_) { 657 if (!dec->is_i4x4_) {
667 left->dc_nz_ = info->dc_nz_ = 0; 658 left->dc_nz_ = info->dc_nz_ = 0;
668 } 659 }
669 dec->non_zero_ = 0; 660 dec->non_zero_ = 0;
670 dec->non_zero_ac_ = 0; 661 dec->non_zero_ac_ = 0;
671 } 662 }
672 663
664 if (dec->filter_type_ > 0) { // store filter info
665 VP8FInfo* const finfo = dec->f_info_ + dec->mb_x_;
666 *finfo = dec->fstrengths_[dec->segment_][dec->is_i4x4_];
667 finfo->f_inner_ = (!info->skip_ || dec->is_i4x4_);
668 }
669
673 return (!token_br->eof_); 670 return (!token_br->eof_);
674 } 671 }
675 672
676 void VP8InitScanline(VP8Decoder* const dec) { 673 void VP8InitScanline(VP8Decoder* const dec) {
677 VP8MB* const left = dec->mb_info_ - 1; 674 VP8MB* const left = dec->mb_info_ - 1;
678 left->nz_ = 0; 675 left->nz_ = 0;
679 left->dc_nz_ = 0; 676 left->dc_nz_ = 0;
680 memset(dec->intra_l_, B_DC_PRED, sizeof(dec->intra_l_)); 677 memset(dec->intra_l_, B_DC_PRED, sizeof(dec->intra_l_));
681 dec->filter_row_ = 678 dec->filter_row_ =
682 (dec->filter_type_ > 0) && 679 (dec->filter_type_ > 0) &&
683 (dec->mb_y_ >= dec->tl_mb_y_) && (dec->mb_y_ <= dec->br_mb_y_); 680 (dec->mb_y_ >= dec->tl_mb_y_) && (dec->mb_y_ <= dec->br_mb_y_);
684 } 681 }
685 682
686 static int ParseFrame(VP8Decoder* const dec, VP8Io* io) { 683 static int ParseFrame(VP8Decoder* const dec, VP8Io* io) {
687 for (dec->mb_y_ = 0; dec->mb_y_ < dec->br_mb_y_; ++dec->mb_y_) { 684 for (dec->mb_y_ = 0; dec->mb_y_ < dec->br_mb_y_; ++dec->mb_y_) {
688 VP8BitReader* const token_br = 685 VP8BitReader* const token_br =
689 &dec->parts_[dec->mb_y_ & (dec->num_parts_ - 1)]; 686 &dec->parts_[dec->mb_y_ & (dec->num_parts_ - 1)];
690 VP8InitScanline(dec); 687 VP8InitScanline(dec);
691 for (dec->mb_x_ = 0; dec->mb_x_ < dec->mb_w_; dec->mb_x_++) { 688 for (dec->mb_x_ = 0; dec->mb_x_ < dec->mb_w_; dec->mb_x_++) {
692 if (!VP8DecodeMB(dec, token_br)) { 689 if (!VP8DecodeMB(dec, token_br)) {
693 return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA, 690 return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA,
694 "Premature end-of-file encountered."); 691 "Premature end-of-file encountered.");
695 } 692 }
693 // Reconstruct and emit samples.
696 VP8ReconstructBlock(dec); 694 VP8ReconstructBlock(dec);
697
698 // Store data and save block's filtering params
699 VP8StoreBlock(dec);
700 } 695 }
701 if (!VP8ProcessRow(dec, io)) { 696 if (!VP8ProcessRow(dec, io)) {
702 return VP8SetError(dec, VP8_STATUS_USER_ABORT, "Output aborted."); 697 return VP8SetError(dec, VP8_STATUS_USER_ABORT, "Output aborted.");
703 } 698 }
704 } 699 }
705 if (dec->use_threads_ && !WebPWorkerSync(&dec->worker_)) { 700 if (dec->use_threads_ && !WebPWorkerSync(&dec->worker_)) {
706 return 0; 701 return 0;
707 } 702 }
708 703
709 // Finish 704 // Finish
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 dec->mem_size_ = 0; 773 dec->mem_size_ = 0;
779 memset(&dec->br_, 0, sizeof(dec->br_)); 774 memset(&dec->br_, 0, sizeof(dec->br_));
780 dec->ready_ = 0; 775 dec->ready_ = 0;
781 } 776 }
782 777
783 //------------------------------------------------------------------------------ 778 //------------------------------------------------------------------------------
784 779
785 #if defined(__cplusplus) || defined(c_plusplus) 780 #if defined(__cplusplus) || defined(c_plusplus)
786 } // extern "C" 781 } // extern "C"
787 #endif 782 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698