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 // Macroblock analysis | 10 // Macroblock analysis |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 i4_alpha = GetAlpha(&total_histo); | 300 i4_alpha = GetAlpha(&total_histo); |
301 if (IS_BETTER_ALPHA(i4_alpha, best_alpha)) { | 301 if (IS_BETTER_ALPHA(i4_alpha, best_alpha)) { |
302 VP8SetIntra4Mode(it, modes); | 302 VP8SetIntra4Mode(it, modes); |
303 best_alpha = i4_alpha; | 303 best_alpha = i4_alpha; |
304 } | 304 } |
305 return best_alpha; | 305 return best_alpha; |
306 } | 306 } |
307 | 307 |
308 static int MBAnalyzeBestUVMode(VP8EncIterator* const it) { | 308 static int MBAnalyzeBestUVMode(VP8EncIterator* const it) { |
309 int best_alpha = DEFAULT_ALPHA; | 309 int best_alpha = DEFAULT_ALPHA; |
| 310 int smallest_alpha = 0; |
310 int best_mode = 0; | 311 int best_mode = 0; |
311 const int max_mode = MAX_UV_MODE; | 312 const int max_mode = MAX_UV_MODE; |
312 int mode; | 313 int mode; |
313 | 314 |
314 VP8MakeChroma8Preds(it); | 315 VP8MakeChroma8Preds(it); |
315 for (mode = 0; mode < max_mode; ++mode) { | 316 for (mode = 0; mode < max_mode; ++mode) { |
316 VP8Histogram histo; | 317 VP8Histogram histo; |
317 int alpha; | 318 int alpha; |
318 InitHistogram(&histo); | 319 InitHistogram(&histo); |
319 VP8CollectHistogram(it->yuv_in_ + U_OFF_ENC, | 320 VP8CollectHistogram(it->yuv_in_ + U_OFF_ENC, |
320 it->yuv_p_ + VP8UVModeOffsets[mode], | 321 it->yuv_p_ + VP8UVModeOffsets[mode], |
321 16, 16 + 4 + 4, &histo); | 322 16, 16 + 4 + 4, &histo); |
322 alpha = GetAlpha(&histo); | 323 alpha = GetAlpha(&histo); |
323 if (IS_BETTER_ALPHA(alpha, best_alpha)) { | 324 if (IS_BETTER_ALPHA(alpha, best_alpha)) { |
324 best_alpha = alpha; | 325 best_alpha = alpha; |
| 326 } |
| 327 // The best prediction mode tends to be the one with the smallest alpha. |
| 328 if (mode == 0 || alpha < smallest_alpha) { |
| 329 smallest_alpha = alpha; |
325 best_mode = mode; | 330 best_mode = mode; |
326 } | 331 } |
327 } | 332 } |
328 VP8SetIntraUVMode(it, best_mode); | 333 VP8SetIntraUVMode(it, best_mode); |
329 return best_alpha; | 334 return best_alpha; |
330 } | 335 } |
331 | 336 |
332 static void MBAnalyze(VP8EncIterator* const it, | 337 static void MBAnalyze(VP8EncIterator* const it, |
333 int alphas[MAX_ALPHA + 1], | 338 int alphas[MAX_ALPHA + 1], |
334 int* const alpha, int* const uv_alpha) { | 339 int* const alpha, int* const uv_alpha) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 enc->alpha_ = main_job.alpha / total_mb; | 497 enc->alpha_ = main_job.alpha / total_mb; |
493 enc->uv_alpha_ = main_job.uv_alpha / total_mb; | 498 enc->uv_alpha_ = main_job.uv_alpha / total_mb; |
494 AssignSegments(enc, main_job.alphas); | 499 AssignSegments(enc, main_job.alphas); |
495 } | 500 } |
496 } else { // Use only one default segment. | 501 } else { // Use only one default segment. |
497 ResetAllMBInfo(enc); | 502 ResetAllMBInfo(enc); |
498 } | 503 } |
499 return ok; | 504 return ok; |
500 } | 505 } |
501 | 506 |
OLD | NEW |