| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // Make a copy of the unfiltered / processed recon buffer | 70 // Make a copy of the unfiltered / processed recon buffer |
| 71 vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); | 71 vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); |
| 72 | 72 |
| 73 best_err = try_filter_frame(sd, cpi, filt_mid, partial_frame); | 73 best_err = try_filter_frame(sd, cpi, filt_mid, partial_frame); |
| 74 filt_best = filt_mid; | 74 filt_best = filt_mid; |
| 75 ss_err[filt_mid] = best_err; | 75 ss_err[filt_mid] = best_err; |
| 76 | 76 |
| 77 while (filter_step > 0) { | 77 while (filter_step > 0) { |
| 78 const int filt_high = MIN(filt_mid + filter_step, max_filter_level); | 78 const int filt_high = MIN(filt_mid + filter_step, max_filter_level); |
| 79 const int filt_low = MAX(filt_mid - filter_step, min_filter_level); | 79 const int filt_low = MAX(filt_mid - filter_step, min_filter_level); |
| 80 int filt_err; | |
| 81 | 80 |
| 82 // Bias against raising loop filter in favor of lowering it. | 81 // Bias against raising loop filter in favor of lowering it. |
| 83 int bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; | 82 int bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; |
| 84 | 83 |
| 85 if ((cpi->oxcf.pass == 2) && (cpi->twopass.section_intra_rating < 20)) | 84 if ((cpi->oxcf.pass == 2) && (cpi->twopass.section_intra_rating < 20)) |
| 86 bias = (bias * cpi->twopass.section_intra_rating) / 20; | 85 bias = (bias * cpi->twopass.section_intra_rating) / 20; |
| 87 | 86 |
| 88 // yx, bias less for large block size | 87 // yx, bias less for large block size |
| 89 if (cm->tx_mode != ONLY_4X4) | 88 if (cm->tx_mode != ONLY_4X4) |
| 90 bias >>= 1; | 89 bias >>= 1; |
| 91 | 90 |
| 92 if (filt_direction <= 0 && filt_low != filt_mid) { | 91 if (filt_direction <= 0 && filt_low != filt_mid) { |
| 93 // Get Low filter error score | 92 // Get Low filter error score |
| 94 if (ss_err[filt_low] < 0) { | 93 if (ss_err[filt_low] < 0) { |
| 95 filt_err = try_filter_frame(sd, cpi, filt_low, partial_frame); | 94 ss_err[filt_low] = try_filter_frame(sd, cpi, filt_low, partial_frame); |
| 96 ss_err[filt_low] = filt_err; | |
| 97 } else { | |
| 98 filt_err = ss_err[filt_low]; | |
| 99 } | 95 } |
| 100 // If value is close to the best so far then bias towards a lower loop | 96 // If value is close to the best so far then bias towards a lower loop |
| 101 // filter value. | 97 // filter value. |
| 102 if ((filt_err - bias) < best_err) { | 98 if ((ss_err[filt_low] - bias) < best_err) { |
| 103 // Was it actually better than the previous best? | 99 // Was it actually better than the previous best? |
| 104 if (filt_err < best_err) | 100 if (ss_err[filt_low] < best_err) |
| 105 best_err = filt_err; | 101 best_err = ss_err[filt_low]; |
| 106 | 102 |
| 107 filt_best = filt_low; | 103 filt_best = filt_low; |
| 108 } | 104 } |
| 109 } | 105 } |
| 110 | 106 |
| 111 // Now look at filt_high | 107 // Now look at filt_high |
| 112 if (filt_direction >= 0 && filt_high != filt_mid) { | 108 if (filt_direction >= 0 && filt_high != filt_mid) { |
| 113 if (ss_err[filt_high] < 0) { | 109 if (ss_err[filt_high] < 0) { |
| 114 filt_err = try_filter_frame(sd, cpi, filt_high, partial_frame); | 110 ss_err[filt_high] = try_filter_frame(sd, cpi, filt_high, partial_frame); |
| 115 ss_err[filt_high] = filt_err; | |
| 116 } else { | |
| 117 filt_err = ss_err[filt_high]; | |
| 118 } | 111 } |
| 119 // Was it better than the previous best? | 112 // Was it better than the previous best? |
| 120 if (filt_err < (best_err - bias)) { | 113 if (ss_err[filt_high] < (best_err - bias)) { |
| 121 best_err = filt_err; | 114 best_err = ss_err[filt_high]; |
| 122 filt_best = filt_high; | 115 filt_best = filt_high; |
| 123 } | 116 } |
| 124 } | 117 } |
| 125 | 118 |
| 126 // Half the step distance if the best filter value was the same as last time | 119 // Half the step distance if the best filter value was the same as last time |
| 127 if (filt_best == filt_mid) { | 120 if (filt_best == filt_mid) { |
| 128 filter_step /= 2; | 121 filter_step /= 2; |
| 129 filt_direction = 0; | 122 filt_direction = 0; |
| 130 } else { | 123 } else { |
| 131 filt_direction = (filt_best < filt_mid) ? -1 : 1; | 124 filt_direction = (filt_best < filt_mid) ? -1 : 1; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 struct loopfilter *const lf = &cm->lf; | 135 struct loopfilter *const lf = &cm->lf; |
| 143 | 136 |
| 144 lf->sharpness_level = cm->frame_type == KEY_FRAME ? 0 | 137 lf->sharpness_level = cm->frame_type == KEY_FRAME ? 0 |
| 145 : cpi->oxcf.sharpness; | 138 : cpi->oxcf.sharpness; |
| 146 | 139 |
| 147 if (method == LPF_PICK_MINIMAL_LPF && lf->filter_level) { | 140 if (method == LPF_PICK_MINIMAL_LPF && lf->filter_level) { |
| 148 lf->filter_level = 0; | 141 lf->filter_level = 0; |
| 149 } else if (method >= LPF_PICK_FROM_Q) { | 142 } else if (method >= LPF_PICK_FROM_Q) { |
| 150 const int min_filter_level = 0; | 143 const int min_filter_level = 0; |
| 151 const int max_filter_level = get_max_filter_level(cpi); | 144 const int max_filter_level = get_max_filter_level(cpi); |
| 152 const int q = vp9_ac_quant(cm->base_qindex, 0); | 145 const int q = vp9_ac_quant(cm->base_qindex, 0, cm->bit_depth); |
| 153 // These values were determined by linear fitting the result of the | 146 // These values were determined by linear fitting the result of the |
| 154 // searched level, filt_guess = q * 0.316206 + 3.87252 | 147 // searched level, filt_guess = q * 0.316206 + 3.87252 |
| 155 int filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 1015158, 18); | 148 int filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 1015158, 18); |
| 156 if (cm->frame_type == KEY_FRAME) | 149 if (cm->frame_type == KEY_FRAME) |
| 157 filt_guess -= 4; | 150 filt_guess -= 4; |
| 158 lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level); | 151 lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level); |
| 159 } else { | 152 } else { |
| 160 lf->filter_level = search_filter_level(sd, cpi, | 153 lf->filter_level = search_filter_level(sd, cpi, |
| 161 method == LPF_PICK_FROM_SUBIMAGE); | 154 method == LPF_PICK_FROM_SUBIMAGE); |
| 162 } | 155 } |
| 163 } | 156 } |
| OLD | NEW |