| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 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 // frame coding and analysis | 10 // frame coding and analysis |
| 11 // | 11 // |
| 12 // Author: Skal (pascal.massimino@gmail.com) | 12 // Author: Skal (pascal.massimino@gmail.com) |
| 13 | 13 |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 #include <math.h> | 15 #include <math.h> |
| 16 | 16 |
| 17 #include "./cost.h" | 17 #include "./cost_enc.h" |
| 18 #include "./vp8enci.h" | 18 #include "./vp8i_enc.h" |
| 19 #include "../dsp/dsp.h" | 19 #include "../dsp/dsp.h" |
| 20 #include "../webp/format_constants.h" // RIFF constants | 20 #include "../webp/format_constants.h" // RIFF constants |
| 21 | 21 |
| 22 #define SEGMENT_VISU 0 | 22 #define SEGMENT_VISU 0 |
| 23 #define DEBUG_SEARCH 0 // useful to track search convergence | 23 #define DEBUG_SEARCH 0 // useful to track search convergence |
| 24 | 24 |
| 25 //------------------------------------------------------------------------------ | 25 //------------------------------------------------------------------------------ |
| 26 // multi-pass convergence | 26 // multi-pass convergence |
| 27 | 27 |
| 28 #define HEADER_SIZE_ESTIMATE (RIFF_HEADER_SIZE + CHUNK_HEADER_SIZE + \ | 28 #define HEADER_SIZE_ESTIMATE (RIFF_HEADER_SIZE + CHUNK_HEADER_SIZE + \ |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 const int sign = c < 0; | 241 const int sign = c < 0; |
| 242 int v = sign ? -c : c; | 242 int v = sign ? -c : c; |
| 243 if (!VP8PutBit(bw, v != 0, p[1])) { | 243 if (!VP8PutBit(bw, v != 0, p[1])) { |
| 244 p = res->prob[VP8EncBands[n]][0]; | 244 p = res->prob[VP8EncBands[n]][0]; |
| 245 continue; | 245 continue; |
| 246 } | 246 } |
| 247 if (!VP8PutBit(bw, v > 1, p[2])) { | 247 if (!VP8PutBit(bw, v > 1, p[2])) { |
| 248 p = res->prob[VP8EncBands[n]][1]; | 248 p = res->prob[VP8EncBands[n]][1]; |
| 249 } else { | 249 } else { |
| 250 if (!VP8PutBit(bw, v > 4, p[3])) { | 250 if (!VP8PutBit(bw, v > 4, p[3])) { |
| 251 if (VP8PutBit(bw, v != 2, p[4])) | 251 if (VP8PutBit(bw, v != 2, p[4])) { |
| 252 VP8PutBit(bw, v == 4, p[5]); | 252 VP8PutBit(bw, v == 4, p[5]); |
| 253 } |
| 253 } else if (!VP8PutBit(bw, v > 10, p[6])) { | 254 } else if (!VP8PutBit(bw, v > 10, p[6])) { |
| 254 if (!VP8PutBit(bw, v > 6, p[7])) { | 255 if (!VP8PutBit(bw, v > 6, p[7])) { |
| 255 VP8PutBit(bw, v == 6, 159); | 256 VP8PutBit(bw, v == 6, 159); |
| 256 } else { | 257 } else { |
| 257 VP8PutBit(bw, v >= 9, 165); | 258 VP8PutBit(bw, v >= 9, 165); |
| 258 VP8PutBit(bw, !(v & 1), 145); | 259 VP8PutBit(bw, !(v & 1), 145); |
| 259 } | 260 } |
| 260 } else { | 261 } else { |
| 261 int mask; | 262 int mask; |
| 262 const uint8_t* tab; | 263 const uint8_t* tab; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 VP8ModeScore info; | 551 VP8ModeScore info; |
| 551 VP8IteratorImport(&it, NULL); | 552 VP8IteratorImport(&it, NULL); |
| 552 if (VP8Decimate(&it, &info, rd_opt)) { | 553 if (VP8Decimate(&it, &info, rd_opt)) { |
| 553 // Just record the number of skips and act like skip_proba is not used. | 554 // Just record the number of skips and act like skip_proba is not used. |
| 554 enc->proba_.nb_skip_++; | 555 enc->proba_.nb_skip_++; |
| 555 } | 556 } |
| 556 RecordResiduals(&it, &info); | 557 RecordResiduals(&it, &info); |
| 557 size += info.R + info.H; | 558 size += info.R + info.H; |
| 558 size_p0 += info.H; | 559 size_p0 += info.H; |
| 559 distortion += info.D; | 560 distortion += info.D; |
| 560 if (percent_delta && !VP8IteratorProgress(&it, percent_delta)) | 561 if (percent_delta && !VP8IteratorProgress(&it, percent_delta)) { |
| 561 return 0; | 562 return 0; |
| 563 } |
| 562 VP8IteratorSaveBoundary(&it); | 564 VP8IteratorSaveBoundary(&it); |
| 563 } while (VP8IteratorNext(&it) && --nb_mbs > 0); | 565 } while (VP8IteratorNext(&it) && --nb_mbs > 0); |
| 564 | 566 |
| 565 size_p0 += enc->segment_hdr_.size_; | 567 size_p0 += enc->segment_hdr_.size_; |
| 566 if (s->do_size_search) { | 568 if (s->do_size_search) { |
| 567 size += FinalizeSkipProba(enc); | 569 size += FinalizeSkipProba(enc); |
| 568 size += FinalizeTokenProbas(&enc->proba_); | 570 size += FinalizeTokenProbas(&enc->proba_); |
| 569 size = ((size + size_p0 + 1024) >> 11) + HEADER_SIZE_ESTIMATE; | 571 size = ((size + size_p0 + 1024) >> 11) + HEADER_SIZE_ESTIMATE; |
| 570 s->value = (double)size; | 572 s->value = (double)size; |
| 571 } else { | 573 } else { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 | 845 |
| 844 int VP8EncTokenLoop(VP8Encoder* const enc) { | 846 int VP8EncTokenLoop(VP8Encoder* const enc) { |
| 845 (void)enc; | 847 (void)enc; |
| 846 return 0; // we shouldn't be here. | 848 return 0; // we shouldn't be here. |
| 847 } | 849 } |
| 848 | 850 |
| 849 #endif // DISABLE_TOKEN_BUFFER | 851 #endif // DISABLE_TOKEN_BUFFER |
| 850 | 852 |
| 851 //------------------------------------------------------------------------------ | 853 //------------------------------------------------------------------------------ |
| 852 | 854 |
| OLD | NEW |