| 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 // Paginated token buffer | 10 // Paginated token buffer |
| 11 // | 11 // |
| 12 // A 'token' is a bit value associated with a probability, either fixed | 12 // A 'token' is a bit value associated with a probability, either fixed |
| 13 // or a later-to-be-determined after statistics have been collected. | 13 // or a later-to-be-determined after statistics have been collected. |
| 14 // For dynamic probability, we just record the slot id (idx) for the probability | 14 // For dynamic probability, we just record the slot id (idx) for the probability |
| 15 // value in the final probability array (uint8_t* probas in VP8EmitTokens). | 15 // value in the final probability array (uint8_t* probas in VP8EmitTokens). |
| 16 // | 16 // |
| 17 // Author: Skal (pascal.massimino@gmail.com) | 17 // Author: Skal (pascal.massimino@gmail.com) |
| 18 | 18 |
| 19 #include <assert.h> | 19 #include <assert.h> |
| 20 #include <stdlib.h> | 20 #include <stdlib.h> |
| 21 #include <string.h> | 21 #include <string.h> |
| 22 | 22 |
| 23 #include "./cost.h" | 23 #include "./cost_enc.h" |
| 24 #include "./vp8enci.h" | 24 #include "./vp8i_enc.h" |
| 25 #include "../utils/utils.h" | 25 #include "../utils/utils.h" |
| 26 | 26 |
| 27 #if !defined(DISABLE_TOKEN_BUFFER) | 27 #if !defined(DISABLE_TOKEN_BUFFER) |
| 28 | 28 |
| 29 // we use pages to reduce the number of memcpy() | 29 // we use pages to reduce the number of memcpy() |
| 30 #define MIN_PAGE_SIZE 8192 // minimum number of token per page | 30 #define MIN_PAGE_SIZE 8192 // minimum number of token per page |
| 31 #define FIXED_PROBA_BIT (1u << 14) | 31 #define FIXED_PROBA_BIT (1u << 14) |
| 32 | 32 |
| 33 typedef uint16_t token_t; // bit #15: bit value | 33 typedef uint16_t token_t; // bit #15: bit value |
| 34 // bit #14: flags for constant proba or idx | 34 // bit #14: flags for constant proba or idx |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 if (!AddToken(tokens, v != 0, base_id + 1, s + 1)) { | 130 if (!AddToken(tokens, v != 0, base_id + 1, s + 1)) { |
| 131 base_id = TOKEN_ID(coeff_type, VP8EncBands[n], 0); // ctx=0 | 131 base_id = TOKEN_ID(coeff_type, VP8EncBands[n], 0); // ctx=0 |
| 132 s = res->stats[VP8EncBands[n]][0]; | 132 s = res->stats[VP8EncBands[n]][0]; |
| 133 continue; | 133 continue; |
| 134 } | 134 } |
| 135 if (!AddToken(tokens, v > 1, base_id + 2, s + 2)) { | 135 if (!AddToken(tokens, v > 1, base_id + 2, s + 2)) { |
| 136 base_id = TOKEN_ID(coeff_type, VP8EncBands[n], 1); // ctx=1 | 136 base_id = TOKEN_ID(coeff_type, VP8EncBands[n], 1); // ctx=1 |
| 137 s = res->stats[VP8EncBands[n]][1]; | 137 s = res->stats[VP8EncBands[n]][1]; |
| 138 } else { | 138 } else { |
| 139 if (!AddToken(tokens, v > 4, base_id + 3, s + 3)) { | 139 if (!AddToken(tokens, v > 4, base_id + 3, s + 3)) { |
| 140 if (AddToken(tokens, v != 2, base_id + 4, s + 4)) | 140 if (AddToken(tokens, v != 2, base_id + 4, s + 4)) { |
| 141 AddToken(tokens, v == 4, base_id + 5, s + 5); | 141 AddToken(tokens, v == 4, base_id + 5, s + 5); |
| 142 } |
| 142 } else if (!AddToken(tokens, v > 10, base_id + 6, s + 6)) { | 143 } else if (!AddToken(tokens, v > 10, base_id + 6, s + 6)) { |
| 143 if (!AddToken(tokens, v > 6, base_id + 7, s + 7)) { | 144 if (!AddToken(tokens, v > 6, base_id + 7, s + 7)) { |
| 144 AddConstantToken(tokens, v == 6, 159); | 145 AddConstantToken(tokens, v == 6, 159); |
| 145 } else { | 146 } else { |
| 146 AddConstantToken(tokens, v >= 9, 165); | 147 AddConstantToken(tokens, v >= 9, 165); |
| 147 AddConstantToken(tokens, !(v & 1), 145); | 148 AddConstantToken(tokens, !(v & 1), 145); |
| 148 } | 149 } |
| 149 } else { | 150 } else { |
| 150 int mask; | 151 int mask; |
| 151 const uint8_t* tab; | 152 const uint8_t* tab; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 285 |
| 285 void VP8TBufferInit(VP8TBuffer* const b) { | 286 void VP8TBufferInit(VP8TBuffer* const b) { |
| 286 (void)b; | 287 (void)b; |
| 287 } | 288 } |
| 288 void VP8TBufferClear(VP8TBuffer* const b) { | 289 void VP8TBufferClear(VP8TBuffer* const b) { |
| 289 (void)b; | 290 (void)b; |
| 290 } | 291 } |
| 291 | 292 |
| 292 #endif // !DISABLE_TOKEN_BUFFER | 293 #endif // !DISABLE_TOKEN_BUFFER |
| 293 | 294 |
| OLD | NEW |