| 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 |
| 11 #include <assert.h> | 11 #include <assert.h> |
| 12 #include <limits.h> | 12 #include <limits.h> |
| 13 #include "vp9/common/vp9_onyxc_int.h" | 13 #include "vp9/common/vp9_onyxc_int.h" |
| 14 #include "vp9/encoder/vp9_onyx_int.h" | 14 #include "vp9/encoder/vp9_onyx_int.h" |
| 15 #include "vp9/encoder/vp9_picklpf.h" | 15 #include "vp9/encoder/vp9_picklpf.h" |
| 16 #include "vp9/encoder/vp9_quantize.h" | 16 #include "vp9/encoder/vp9_quantize.h" |
| 17 #include "vpx_mem/vpx_mem.h" | 17 #include "vpx_mem/vpx_mem.h" |
| 18 #include "vpx_scale/vpx_scale.h" | 18 #include "vpx_scale/vpx_scale.h" |
| 19 #include "vp9/common/vp9_alloccommon.h" | 19 #include "vp9/common/vp9_alloccommon.h" |
| 20 #include "vp9/common/vp9_loopfilter.h" | 20 #include "vp9/common/vp9_loopfilter.h" |
| 21 #include "./vpx_scale_rtcd.h" | 21 #include "./vpx_scale_rtcd.h" |
| 22 | 22 |
| 23 void vp9_yv12_copy_partial_frame_c(YV12_BUFFER_CONFIG *src_ybc, | 23 void vp9_yv12_copy_partial_frame_c(YV12_BUFFER_CONFIG *src_ybc, |
| 24 YV12_BUFFER_CONFIG *dst_ybc, int Fraction) { | 24 YV12_BUFFER_CONFIG *dst_ybc, int fraction) { |
| 25 uint8_t *src_y, *dst_y; | 25 const int height = src_ybc->y_height; |
| 26 int yheight; | 26 const int stride = src_ybc->y_stride; |
| 27 int ystride; | 27 const int offset = stride * ((height >> 5) * 16 - 8); |
| 28 int yoffset; | 28 const int lines_to_copy = MAX(height >> (fraction + 4), 1) << 4; |
| 29 int linestocopy; | |
| 30 | 29 |
| 31 assert(src_ybc->y_stride == dst_ybc->y_stride); | 30 assert(src_ybc->y_stride == dst_ybc->y_stride); |
| 32 yheight = src_ybc->y_height; | 31 vpx_memcpy(dst_ybc->y_buffer + offset, src_ybc->y_buffer + offset, |
| 33 ystride = src_ybc->y_stride; | 32 stride * (lines_to_copy + 16)); |
| 34 | |
| 35 linestocopy = (yheight >> (Fraction + 4)); | |
| 36 | |
| 37 if (linestocopy < 1) | |
| 38 linestocopy = 1; | |
| 39 | |
| 40 linestocopy <<= 4; | |
| 41 | |
| 42 yoffset = ystride * ((yheight >> 5) * 16 - 8); | |
| 43 src_y = src_ybc->y_buffer + yoffset; | |
| 44 dst_y = dst_ybc->y_buffer + yoffset; | |
| 45 | |
| 46 vpx_memcpy(dst_y, src_y, ystride * (linestocopy + 16)); | |
| 47 } | 33 } |
| 48 | 34 |
| 49 static int calc_partial_ssl_err(YV12_BUFFER_CONFIG *source, | 35 static int calc_partial_ssl_err(YV12_BUFFER_CONFIG *source, |
| 50 YV12_BUFFER_CONFIG *dest, int Fraction) { | 36 YV12_BUFFER_CONFIG *dest, int Fraction) { |
| 51 int i, j; | 37 int i, j; |
| 52 int Total = 0; | 38 int Total = 0; |
| 53 int srcoffset, dstoffset; | 39 int srcoffset, dstoffset; |
| 54 uint8_t *src = source->y_buffer; | 40 uint8_t *src = source->y_buffer; |
| 55 uint8_t *dst = dest->y_buffer; | 41 uint8_t *dst = dest->y_buffer; |
| 56 | 42 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 max_filter_level = MAX_LOOP_FILTER * 3 / 4; | 104 max_filter_level = MAX_LOOP_FILTER * 3 / 4; |
| 119 | 105 |
| 120 return max_filter_level; | 106 return max_filter_level; |
| 121 } | 107 } |
| 122 | 108 |
| 123 | 109 |
| 124 // Stub function for now Alt LF not used | 110 // Stub function for now Alt LF not used |
| 125 void vp9_set_alt_lf_level(VP9_COMP *cpi, int filt_val) { | 111 void vp9_set_alt_lf_level(VP9_COMP *cpi, int filt_val) { |
| 126 } | 112 } |
| 127 | 113 |
| 128 void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) { | 114 void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, int partial) { |
| 129 VP9_COMMON *cm = &cpi->common; | 115 VP9_COMMON *const cm = &cpi->common; |
| 130 struct loopfilter *lf = &cpi->mb.e_mbd.lf; | 116 struct loopfilter *const lf = &cm->lf; |
| 131 | 117 |
| 132 int best_err = 0; | 118 int best_err = 0; |
| 133 int filt_err = 0; | 119 int filt_err = 0; |
| 134 int min_filter_level = get_min_filter_level(cpi, cm->base_qindex); | 120 const int min_filter_level = get_min_filter_level(cpi, cm->base_qindex); |
| 135 int max_filter_level = get_max_filter_level(cpi, cm->base_qindex); | 121 const int max_filter_level = get_max_filter_level(cpi, cm->base_qindex); |
| 136 | 122 |
| 137 int filter_step; | 123 int filter_step; |
| 138 int filt_high = 0; | 124 int filt_high = 0; |
| 139 // Start search at previous frame filter level | 125 // Start search at previous frame filter level |
| 140 int filt_mid = lf->filter_level; | 126 int filt_mid = lf->filter_level; |
| 141 int filt_low = 0; | 127 int filt_low = 0; |
| 142 int filt_best; | 128 int filt_best; |
| 143 int filt_direction = 0; | 129 int filt_direction = 0; |
| 144 | 130 |
| 145 int Bias = 0; // Bias against raising loop filter and in
favour of lowering it | 131 int Bias = 0; // Bias against raising loop filter and in
favour of lowering it |
| 146 | 132 |
| 147 // Make a copy of the unfiltered / processed recon buffer | 133 // Make a copy of the unfiltered / processed recon buffer |
| 148 vp8_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); | 134 vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); |
| 149 | 135 |
| 150 if (cm->frame_type == KEY_FRAME) | 136 lf->sharpness_level = cm->frame_type == KEY_FRAME ? 0 |
| 151 lf->sharpness_level = 0; | 137 : cpi->oxcf.Sharpness; |
| 152 else | |
| 153 lf->sharpness_level = cpi->oxcf.Sharpness; | |
| 154 | 138 |
| 155 // Start the search at the previous frame filter level unless it is now out of
range. | 139 // Start the search at the previous frame filter level unless it is now out of
range. |
| 156 filt_mid = lf->filter_level; | 140 filt_mid = clamp(lf->filter_level, min_filter_level, max_filter_level); |
| 157 | |
| 158 if (filt_mid < min_filter_level) | |
| 159 filt_mid = min_filter_level; | |
| 160 else if (filt_mid > max_filter_level) | |
| 161 filt_mid = max_filter_level; | |
| 162 | 141 |
| 163 // Define the initial step size | 142 // Define the initial step size |
| 164 filter_step = (filt_mid < 16) ? 4 : filt_mid / 4; | 143 filter_step = filt_mid < 16 ? 4 : filt_mid / 4; |
| 165 | 144 |
| 166 // Get baseline error score | 145 // Get baseline error score |
| 167 vp9_set_alt_lf_level(cpi, filt_mid); | 146 vp9_set_alt_lf_level(cpi, filt_mid); |
| 168 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_mid, 1); | 147 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_mid, 1, partial); |
| 169 | 148 |
| 170 best_err = vp9_calc_ss_err(sd, cm->frame_to_show); | 149 best_err = vp9_calc_ss_err(sd, cm->frame_to_show); |
| 171 filt_best = filt_mid; | 150 filt_best = filt_mid; |
| 172 | 151 |
| 173 // Re-instate the unfiltered frame | 152 // Re-instate the unfiltered frame |
| 174 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); | 153 vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); |
| 175 | 154 |
| 176 while (filter_step > 0) { | 155 while (filter_step > 0) { |
| 177 Bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; // PGW change 12/1
2/06 for small images | 156 Bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; // PGW change 12/1
2/06 for small images |
| 178 | 157 |
| 179 // jbb chg: 20100118 - in sections with lots of new material coming in don't
bias as much to a low filter value | 158 // jbb chg: 20100118 - in sections with lots of new material coming in don't
bias as much to a low filter value |
| 180 if (cpi->twopass.section_intra_rating < 20) | 159 if (cpi->twopass.section_intra_rating < 20) |
| 181 Bias = Bias * cpi->twopass.section_intra_rating / 20; | 160 Bias = Bias * cpi->twopass.section_intra_rating / 20; |
| 182 | 161 |
| 183 // yx, bias less for large block size | 162 // yx, bias less for large block size |
| 184 if (cpi->common.tx_mode != ONLY_4X4) | 163 if (cpi->common.tx_mode != ONLY_4X4) |
| 185 Bias >>= 1; | 164 Bias >>= 1; |
| 186 | 165 |
| 187 filt_high = ((filt_mid + filter_step) > max_filter_level) ? max_filter_level
: (filt_mid + filter_step); | 166 filt_high = ((filt_mid + filter_step) > max_filter_level) ? max_filter_level
: (filt_mid + filter_step); |
| 188 filt_low = ((filt_mid - filter_step) < min_filter_level) ? min_filter_level
: (filt_mid - filter_step); | 167 filt_low = ((filt_mid - filter_step) < min_filter_level) ? min_filter_level
: (filt_mid - filter_step); |
| 189 | 168 |
| 190 if ((filt_direction <= 0) && (filt_low != filt_mid)) { | 169 if ((filt_direction <= 0) && (filt_low != filt_mid)) { |
| 191 // Get Low filter error score | 170 // Get Low filter error score |
| 192 vp9_set_alt_lf_level(cpi, filt_low); | 171 vp9_set_alt_lf_level(cpi, filt_low); |
| 193 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_low, 1); | 172 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_low, 1, partial); |
| 194 | 173 |
| 195 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); | 174 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); |
| 196 | 175 |
| 197 // Re-instate the unfiltered frame | 176 // Re-instate the unfiltered frame |
| 198 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); | 177 vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); |
| 199 | 178 |
| 200 // If value is close to the best so far then bias towards a lower loop fil
ter value. | 179 // If value is close to the best so far then bias towards a lower loop fil
ter value. |
| 201 if ((filt_err - Bias) < best_err) { | 180 if ((filt_err - Bias) < best_err) { |
| 202 // Was it actually better than the previous best? | 181 // Was it actually better than the previous best? |
| 203 if (filt_err < best_err) | 182 if (filt_err < best_err) |
| 204 best_err = filt_err; | 183 best_err = filt_err; |
| 205 | 184 |
| 206 filt_best = filt_low; | 185 filt_best = filt_low; |
| 207 } | 186 } |
| 208 } | 187 } |
| 209 | 188 |
| 210 // Now look at filt_high | 189 // Now look at filt_high |
| 211 if ((filt_direction >= 0) && (filt_high != filt_mid)) { | 190 if ((filt_direction >= 0) && (filt_high != filt_mid)) { |
| 212 vp9_set_alt_lf_level(cpi, filt_high); | 191 vp9_set_alt_lf_level(cpi, filt_high); |
| 213 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_high, 1); | 192 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_high, 1, partial); |
| 214 | 193 |
| 215 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); | 194 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); |
| 216 | 195 |
| 217 // Re-instate the unfiltered frame | 196 // Re-instate the unfiltered frame |
| 218 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); | 197 vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); |
| 219 | 198 |
| 220 // Was it better than the previous best? | 199 // Was it better than the previous best? |
| 221 if (filt_err < (best_err - Bias)) { | 200 if (filt_err < (best_err - Bias)) { |
| 222 best_err = filt_err; | 201 best_err = filt_err; |
| 223 filt_best = filt_high; | 202 filt_best = filt_high; |
| 224 } | 203 } |
| 225 } | 204 } |
| 226 | 205 |
| 227 // Half the step distance if the best filter value was the same as last time | 206 // Half the step distance if the best filter value was the same as last time |
| 228 if (filt_best == filt_mid) { | 207 if (filt_best == filt_mid) { |
| 229 filter_step = filter_step / 2; | 208 filter_step = filter_step / 2; |
| 230 filt_direction = 0; | 209 filt_direction = 0; |
| 231 } else { | 210 } else { |
| 232 filt_direction = (filt_best < filt_mid) ? -1 : 1; | 211 filt_direction = (filt_best < filt_mid) ? -1 : 1; |
| 233 filt_mid = filt_best; | 212 filt_mid = filt_best; |
| 234 } | 213 } |
| 235 } | 214 } |
| 236 | 215 |
| 237 lf->filter_level = filt_best; | 216 lf->filter_level = filt_best; |
| 238 } | 217 } |
| 218 |
| OLD | NEW |