| 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 | 11 |
| 12 #include "vp9/common/vp9_onyxc_int.h" | 12 #include "vp9/common/vp9_onyxc_int.h" |
| 13 #include "vp9/encoder/vp9_onyx_int.h" | 13 #include "vp9/encoder/vp9_onyx_int.h" |
| 14 #include "vp9/encoder/vp9_picklpf.h" | 14 #include "vp9/encoder/vp9_picklpf.h" |
| 15 #include "vp9/encoder/vp9_quantize.h" | 15 #include "vp9/encoder/vp9_quantize.h" |
| 16 #include "vpx_mem/vpx_mem.h" | 16 #include "vpx_mem/vpx_mem.h" |
| 17 #include "vpx_scale/vpxscale.h" | 17 #include "vpx_scale/vpx_scale.h" |
| 18 #include "vp9/common/vp9_alloccommon.h" | 18 #include "vp9/common/vp9_alloccommon.h" |
| 19 #include "vp9/common/vp9_loopfilter.h" | 19 #include "vp9/common/vp9_loopfilter.h" |
| 20 #include "./vpx_scale_rtcd.h" | 20 #include "./vpx_scale_rtcd.h" |
| 21 | 21 |
| 22 void vp9_yv12_copy_partial_frame_c(YV12_BUFFER_CONFIG *src_ybc, | 22 void vp9_yv12_copy_partial_frame_c(YV12_BUFFER_CONFIG *src_ybc, |
| 23 YV12_BUFFER_CONFIG *dst_ybc, int Fraction) { | 23 YV12_BUFFER_CONFIG *dst_ybc, int Fraction) { |
| 24 unsigned char *src_y, *dst_y; | 24 uint8_t *src_y, *dst_y; |
| 25 int yheight; | 25 int yheight; |
| 26 int ystride; | 26 int ystride; |
| 27 int border; | |
| 28 int yoffset; | 27 int yoffset; |
| 29 int linestocopy; | 28 int linestocopy; |
| 30 | 29 |
| 31 border = src_ybc->border; | |
| 32 yheight = src_ybc->y_height; | 30 yheight = src_ybc->y_height; |
| 33 ystride = src_ybc->y_stride; | 31 ystride = src_ybc->y_stride; |
| 34 | 32 |
| 35 linestocopy = (yheight >> (Fraction + 4)); | 33 linestocopy = (yheight >> (Fraction + 4)); |
| 36 | 34 |
| 37 if (linestocopy < 1) | 35 if (linestocopy < 1) |
| 38 linestocopy = 1; | 36 linestocopy = 1; |
| 39 | 37 |
| 40 linestocopy <<= 4; | 38 linestocopy <<= 4; |
| 41 | 39 |
| 42 yoffset = ystride * ((yheight >> 5) * 16 - 8); | 40 yoffset = ystride * ((yheight >> 5) * 16 - 8); |
| 43 src_y = src_ybc->y_buffer + yoffset; | 41 src_y = src_ybc->y_buffer + yoffset; |
| 44 dst_y = dst_ybc->y_buffer + yoffset; | 42 dst_y = dst_ybc->y_buffer + yoffset; |
| 45 | 43 |
| 46 vpx_memcpy(dst_y, src_y, ystride * (linestocopy + 16)); | 44 vpx_memcpy(dst_y, src_y, ystride * (linestocopy + 16)); |
| 47 } | 45 } |
| 48 | 46 |
| 49 static int calc_partial_ssl_err(YV12_BUFFER_CONFIG *source, | 47 static int calc_partial_ssl_err(YV12_BUFFER_CONFIG *source, |
| 50 YV12_BUFFER_CONFIG *dest, int Fraction) { | 48 YV12_BUFFER_CONFIG *dest, int Fraction) { |
| 51 int i, j; | 49 int i, j; |
| 52 int Total = 0; | 50 int Total = 0; |
| 53 int srcoffset, dstoffset; | 51 int srcoffset, dstoffset; |
| 54 unsigned char *src = source->y_buffer; | 52 uint8_t *src = source->y_buffer; |
| 55 unsigned char *dst = dest->y_buffer; | 53 uint8_t *dst = dest->y_buffer; |
| 56 | 54 |
| 57 int linestocopy = (source->y_height >> (Fraction + 4)); | 55 int linestocopy = (source->y_height >> (Fraction + 4)); |
| 58 | 56 |
| 59 if (linestocopy < 1) | 57 if (linestocopy < 1) |
| 60 linestocopy = 1; | 58 linestocopy = 1; |
| 61 | 59 |
| 62 linestocopy <<= 4; | 60 linestocopy <<= 4; |
| 63 | 61 |
| 64 | 62 |
| 65 srcoffset = source->y_stride * (dest->y_height >> 5) * 16; | 63 srcoffset = source->y_stride * (dest->y_height >> 5) * 16; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 if (filt_mid < min_filter_level) | 259 if (filt_mid < min_filter_level) |
| 262 filt_mid = min_filter_level; | 260 filt_mid = min_filter_level; |
| 263 else if (filt_mid > max_filter_level) | 261 else if (filt_mid > max_filter_level) |
| 264 filt_mid = max_filter_level; | 262 filt_mid = max_filter_level; |
| 265 | 263 |
| 266 // Define the initial step size | 264 // Define the initial step size |
| 267 filter_step = (filt_mid < 16) ? 4 : filt_mid / 4; | 265 filter_step = (filt_mid < 16) ? 4 : filt_mid / 4; |
| 268 | 266 |
| 269 // Get baseline error score | 267 // Get baseline error score |
| 270 vp9_set_alt_lf_level(cpi, filt_mid); | 268 vp9_set_alt_lf_level(cpi, filt_mid); |
| 271 vp9_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_mid); | 269 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_mid, 1); |
| 272 | 270 |
| 273 best_err = vp9_calc_ss_err(sd, cm->frame_to_show); | 271 best_err = vp9_calc_ss_err(sd, cm->frame_to_show); |
| 274 filt_best = filt_mid; | 272 filt_best = filt_mid; |
| 275 | 273 |
| 276 // Re-instate the unfiltered frame | 274 // Re-instate the unfiltered frame |
| 277 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); | 275 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); |
| 278 | 276 |
| 279 while (filter_step > 0) { | 277 while (filter_step > 0) { |
| 280 Bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; // PGW change 12/1
2/06 for small images | 278 Bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; // PGW change 12/1
2/06 for small images |
| 281 | 279 |
| 282 // jbb chg: 20100118 - in sections with lots of new material coming in don't
bias as much to a low filter value | 280 // jbb chg: 20100118 - in sections with lots of new material coming in don't
bias as much to a low filter value |
| 283 if (cpi->twopass.section_intra_rating < 20) | 281 if (cpi->twopass.section_intra_rating < 20) |
| 284 Bias = Bias * cpi->twopass.section_intra_rating / 20; | 282 Bias = Bias * cpi->twopass.section_intra_rating / 20; |
| 285 | 283 |
| 286 // yx, bias less for large block size | 284 // yx, bias less for large block size |
| 287 if (cpi->common.txfm_mode != ONLY_4X4) | 285 if (cpi->common.txfm_mode != ONLY_4X4) |
| 288 Bias >>= 1; | 286 Bias >>= 1; |
| 289 | 287 |
| 290 filt_high = ((filt_mid + filter_step) > max_filter_level) ? max_filter_level
: (filt_mid + filter_step); | 288 filt_high = ((filt_mid + filter_step) > max_filter_level) ? max_filter_level
: (filt_mid + filter_step); |
| 291 filt_low = ((filt_mid - filter_step) < min_filter_level) ? min_filter_level
: (filt_mid - filter_step); | 289 filt_low = ((filt_mid - filter_step) < min_filter_level) ? min_filter_level
: (filt_mid - filter_step); |
| 292 | 290 |
| 293 if ((filt_direction <= 0) && (filt_low != filt_mid)) { | 291 if ((filt_direction <= 0) && (filt_low != filt_mid)) { |
| 294 // Get Low filter error score | 292 // Get Low filter error score |
| 295 vp9_set_alt_lf_level(cpi, filt_low); | 293 vp9_set_alt_lf_level(cpi, filt_low); |
| 296 vp9_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_low); | 294 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_low, 1); |
| 297 | 295 |
| 298 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); | 296 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); |
| 299 | 297 |
| 300 // Re-instate the unfiltered frame | 298 // Re-instate the unfiltered frame |
| 301 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); | 299 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); |
| 302 | 300 |
| 303 // If value is close to the best so far then bias towards a lower loop fil
ter value. | 301 // If value is close to the best so far then bias towards a lower loop fil
ter value. |
| 304 if ((filt_err - Bias) < best_err) { | 302 if ((filt_err - Bias) < best_err) { |
| 305 // Was it actually better than the previous best? | 303 // Was it actually better than the previous best? |
| 306 if (filt_err < best_err) | 304 if (filt_err < best_err) |
| 307 best_err = filt_err; | 305 best_err = filt_err; |
| 308 | 306 |
| 309 filt_best = filt_low; | 307 filt_best = filt_low; |
| 310 } | 308 } |
| 311 } | 309 } |
| 312 | 310 |
| 313 // Now look at filt_high | 311 // Now look at filt_high |
| 314 if ((filt_direction >= 0) && (filt_high != filt_mid)) { | 312 if ((filt_direction >= 0) && (filt_high != filt_mid)) { |
| 315 vp9_set_alt_lf_level(cpi, filt_high); | 313 vp9_set_alt_lf_level(cpi, filt_high); |
| 316 vp9_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_high); | 314 vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_high, 1); |
| 317 | 315 |
| 318 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); | 316 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); |
| 319 | 317 |
| 320 // Re-instate the unfiltered frame | 318 // Re-instate the unfiltered frame |
| 321 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); | 319 vp8_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); |
| 322 | 320 |
| 323 // Was it better than the previous best? | 321 // Was it better than the previous best? |
| 324 if (filt_err < (best_err - Bias)) { | 322 if (filt_err < (best_err - Bias)) { |
| 325 best_err = filt_err; | 323 best_err = filt_err; |
| 326 filt_best = filt_high; | 324 filt_best = filt_high; |
| 327 } | 325 } |
| 328 } | 326 } |
| 329 | 327 |
| 330 // Half the step distance if the best filter value was the same as last time | 328 // Half the step distance if the best filter value was the same as last time |
| 331 if (filt_best == filt_mid) { | 329 if (filt_best == filt_mid) { |
| 332 filter_step = filter_step / 2; | 330 filter_step = filter_step / 2; |
| 333 filt_direction = 0; | 331 filt_direction = 0; |
| 334 } else { | 332 } else { |
| 335 filt_direction = (filt_best < filt_mid) ? -1 : 1; | 333 filt_direction = (filt_best < filt_mid) ? -1 : 1; |
| 336 filt_mid = filt_best; | 334 filt_mid = filt_best; |
| 337 } | 335 } |
| 338 } | 336 } |
| 339 | 337 |
| 340 cm->filter_level = filt_best; | 338 cm->filter_level = filt_best; |
| 341 } | 339 } |
| OLD | NEW |