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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 for (i = 0; i <= MAX_COEFF_THRESH; ++i) { | 134 for (i = 0; i <= MAX_COEFF_THRESH; ++i) { |
135 out->distribution[i] += in->distribution[i]; | 135 out->distribution[i] += in->distribution[i]; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 //------------------------------------------------------------------------------ | 139 //------------------------------------------------------------------------------ |
140 // Simplified k-Means, to assign Nb segments based on alpha-histogram | 140 // Simplified k-Means, to assign Nb segments based on alpha-histogram |
141 | 141 |
142 static void AssignSegments(VP8Encoder* const enc, | 142 static void AssignSegments(VP8Encoder* const enc, |
143 const int alphas[MAX_ALPHA + 1]) { | 143 const int alphas[MAX_ALPHA + 1]) { |
144 const int nb = enc->segment_hdr_.num_segments_; | 144 // 'num_segments_' is previously validated and <= NUM_MB_SEGMENTS, but an |
| 145 // explicit check is needed to avoid spurious warning about 'n + 1' exceeding |
| 146 // array bounds of 'centers' with some compilers (noticed with gcc-4.9). |
| 147 const int nb = (enc->segment_hdr_.num_segments_ < NUM_MB_SEGMENTS) ? |
| 148 enc->segment_hdr_.num_segments_ : NUM_MB_SEGMENTS; |
145 int centers[NUM_MB_SEGMENTS]; | 149 int centers[NUM_MB_SEGMENTS]; |
146 int weighted_average = 0; | 150 int weighted_average = 0; |
147 int map[MAX_ALPHA + 1]; | 151 int map[MAX_ALPHA + 1]; |
148 int a, n, k; | 152 int a, n, k; |
149 int min_a = 0, max_a = MAX_ALPHA, range_a; | 153 int min_a = 0, max_a = MAX_ALPHA, range_a; |
150 // 'int' type is ok for histo, and won't overflow | 154 // 'int' type is ok for histo, and won't overflow |
151 int accum[NUM_MB_SEGMENTS], dist_accum[NUM_MB_SEGMENTS]; | 155 int accum[NUM_MB_SEGMENTS], dist_accum[NUM_MB_SEGMENTS]; |
152 | 156 |
153 assert(nb >= 1); | 157 assert(nb >= 1); |
154 assert(nb <= NUM_MB_SEGMENTS); | 158 assert(nb <= NUM_MB_SEGMENTS); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 enc->alpha_ = main_job.alpha / total_mb; | 489 enc->alpha_ = main_job.alpha / total_mb; |
486 enc->uv_alpha_ = main_job.uv_alpha / total_mb; | 490 enc->uv_alpha_ = main_job.uv_alpha / total_mb; |
487 AssignSegments(enc, main_job.alphas); | 491 AssignSegments(enc, main_job.alphas); |
488 } | 492 } |
489 } else { // Use only one default segment. | 493 } else { // Use only one default segment. |
490 ResetAllMBInfo(enc); | 494 ResetAllMBInfo(enc); |
491 } | 495 } |
492 return ok; | 496 return ok; |
493 } | 497 } |
494 | 498 |
OLD | NEW |