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 18 matching lines...) Expand all Loading... |
29 return cpi->twopass.section_intra_rating > 8 ? MAX_LOOP_FILTER * 3 / 4 | 29 return cpi->twopass.section_intra_rating > 8 ? MAX_LOOP_FILTER * 3 / 4 |
30 : MAX_LOOP_FILTER; | 30 : MAX_LOOP_FILTER; |
31 } | 31 } |
32 | 32 |
33 // Stub function for now Alt LF not used | 33 // Stub function for now Alt LF not used |
34 void vp9_set_alt_lf_level(VP9_COMP *cpi, int filt_val) { | 34 void vp9_set_alt_lf_level(VP9_COMP *cpi, int filt_val) { |
35 } | 35 } |
36 | 36 |
37 static int try_filter_frame(const YV12_BUFFER_CONFIG *sd, VP9_COMP *const cpi, | 37 static int try_filter_frame(const YV12_BUFFER_CONFIG *sd, VP9_COMP *const cpi, |
38 MACROBLOCKD *const xd, VP9_COMMON *const cm, | 38 MACROBLOCKD *const xd, VP9_COMMON *const cm, |
39 int filt_level, int partial) { | 39 int filt_level, int partial_frame) { |
40 int filt_err; | 40 int filt_err; |
41 | 41 |
42 vp9_set_alt_lf_level(cpi, filt_level); | 42 vp9_set_alt_lf_level(cpi, filt_level); |
43 vp9_loop_filter_frame(cm, xd, filt_level, 1, partial); | 43 vp9_loop_filter_frame(cm, xd, filt_level, 1, partial_frame); |
44 | 44 |
45 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); | 45 filt_err = vp9_calc_ss_err(sd, cm->frame_to_show); |
46 | 46 |
47 // Re-instate the unfiltered frame | 47 // Re-instate the unfiltered frame |
48 vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); | 48 vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show); |
49 | 49 |
50 return filt_err; | 50 return filt_err; |
51 } | 51 } |
52 | 52 |
53 static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, | 53 static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, |
54 int partial) { | 54 int partial_frame) { |
55 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 55 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
56 VP9_COMMON *const cm = &cpi->common; | 56 VP9_COMMON *const cm = &cpi->common; |
57 struct loopfilter *const lf = &cm->lf; | 57 struct loopfilter *const lf = &cm->lf; |
58 const int min_filter_level = get_min_filter_level(cpi, cm->base_qindex); | 58 const int min_filter_level = get_min_filter_level(cpi, cm->base_qindex); |
59 const int max_filter_level = get_max_filter_level(cpi, cm->base_qindex); | 59 const int max_filter_level = get_max_filter_level(cpi, cm->base_qindex); |
60 int best_err; | 60 int best_err; |
61 int filt_best; | 61 int filt_best; |
62 int filt_direction = 0; | 62 int filt_direction = 0; |
63 // Start the search at the previous frame filter level unless it is now out of | 63 // Start the search at the previous frame filter level unless it is now out of |
64 // range. | 64 // range. |
65 int filt_mid = clamp(lf->filter_level, min_filter_level, max_filter_level); | 65 int filt_mid = clamp(lf->filter_level, min_filter_level, max_filter_level); |
66 int filter_step = filt_mid < 16 ? 4 : filt_mid / 4; | 66 int filter_step = filt_mid < 16 ? 4 : filt_mid / 4; |
67 // Sum squared error at each filter level | 67 // Sum squared error at each filter level |
68 int ss_err[MAX_LOOP_FILTER + 1]; | 68 int ss_err[MAX_LOOP_FILTER + 1]; |
69 | 69 |
70 // Set each entry to -1 | 70 // Set each entry to -1 |
71 vpx_memset(ss_err, 0xFF, sizeof(ss_err)); | 71 vpx_memset(ss_err, 0xFF, sizeof(ss_err)); |
72 | 72 |
73 // Make a copy of the unfiltered / processed recon buffer | 73 // Make a copy of the unfiltered / processed recon buffer |
74 vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); | 74 vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); |
75 | 75 |
76 best_err = try_filter_frame(sd, cpi, xd, cm, filt_mid, partial); | 76 best_err = try_filter_frame(sd, cpi, xd, cm, filt_mid, partial_frame); |
77 filt_best = filt_mid; | 77 filt_best = filt_mid; |
78 ss_err[filt_mid] = best_err; | 78 ss_err[filt_mid] = best_err; |
79 | 79 |
80 while (filter_step > 0) { | 80 while (filter_step > 0) { |
81 const int filt_high = MIN(filt_mid + filter_step, max_filter_level); | 81 const int filt_high = MIN(filt_mid + filter_step, max_filter_level); |
82 const int filt_low = MAX(filt_mid - filter_step, min_filter_level); | 82 const int filt_low = MAX(filt_mid - filter_step, min_filter_level); |
83 int filt_err; | 83 int filt_err; |
84 | 84 |
85 // Bias against raising loop filter in favor of lowering it. | 85 // Bias against raising loop filter in favor of lowering it. |
86 int bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; | 86 int bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; |
87 | 87 |
88 if (cpi->twopass.section_intra_rating < 20) | 88 if (cpi->twopass.section_intra_rating < 20) |
89 bias = bias * cpi->twopass.section_intra_rating / 20; | 89 bias = bias * cpi->twopass.section_intra_rating / 20; |
90 | 90 |
91 // yx, bias less for large block size | 91 // yx, bias less for large block size |
92 if (cm->tx_mode != ONLY_4X4) | 92 if (cm->tx_mode != ONLY_4X4) |
93 bias >>= 1; | 93 bias >>= 1; |
94 | 94 |
95 if (filt_direction <= 0 && filt_low != filt_mid) { | 95 if (filt_direction <= 0 && filt_low != filt_mid) { |
96 // Get Low filter error score | 96 // Get Low filter error score |
97 if (ss_err[filt_low] < 0) { | 97 if (ss_err[filt_low] < 0) { |
98 filt_err = try_filter_frame(sd, cpi, xd, cm, filt_low, partial); | 98 filt_err = try_filter_frame(sd, cpi, xd, cm, filt_low, partial_frame); |
99 ss_err[filt_low] = filt_err; | 99 ss_err[filt_low] = filt_err; |
100 } else { | 100 } else { |
101 filt_err = ss_err[filt_low]; | 101 filt_err = ss_err[filt_low]; |
102 } | 102 } |
103 // If value is close to the best so far then bias towards a lower loop | 103 // If value is close to the best so far then bias towards a lower loop |
104 // filter value. | 104 // filter value. |
105 if ((filt_err - bias) < best_err) { | 105 if ((filt_err - bias) < best_err) { |
106 // Was it actually better than the previous best? | 106 // Was it actually better than the previous best? |
107 if (filt_err < best_err) | 107 if (filt_err < best_err) |
108 best_err = filt_err; | 108 best_err = filt_err; |
109 | 109 |
110 filt_best = filt_low; | 110 filt_best = filt_low; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 // Now look at filt_high | 114 // Now look at filt_high |
115 if (filt_direction >= 0 && filt_high != filt_mid) { | 115 if (filt_direction >= 0 && filt_high != filt_mid) { |
116 if (ss_err[filt_high] < 0) { | 116 if (ss_err[filt_high] < 0) { |
117 filt_err = try_filter_frame(sd, cpi, xd, cm, filt_high, partial); | 117 filt_err = try_filter_frame(sd, cpi, xd, cm, filt_high, partial_frame); |
118 ss_err[filt_high] = filt_err; | 118 ss_err[filt_high] = filt_err; |
119 } else { | 119 } else { |
120 filt_err = ss_err[filt_high]; | 120 filt_err = ss_err[filt_high]; |
121 } | 121 } |
122 // Was it better than the previous best? | 122 // Was it better than the previous best? |
123 if (filt_err < (best_err - bias)) { | 123 if (filt_err < (best_err - bias)) { |
124 best_err = filt_err; | 124 best_err = filt_err; |
125 filt_best = filt_high; | 125 filt_best = filt_high; |
126 } | 126 } |
127 } | 127 } |
(...skipping 27 matching lines...) Expand all Loading... |
155 // searched level | 155 // searched level |
156 // filt_guess = q * 0.316206 + 3.87252 | 156 // filt_guess = q * 0.316206 + 3.87252 |
157 int filt_guess = (q * 20723 + 1015158 + (1 << 17)) >> 18; | 157 int filt_guess = (q * 20723 + 1015158 + (1 << 17)) >> 18; |
158 if (cm->frame_type == KEY_FRAME) | 158 if (cm->frame_type == KEY_FRAME) |
159 filt_guess -= 4; | 159 filt_guess -= 4; |
160 lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level); | 160 lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level); |
161 } else { | 161 } else { |
162 search_filter_level(sd, cpi, method == 1); | 162 search_filter_level(sd, cpi, method == 1); |
163 } | 163 } |
164 } | 164 } |
OLD | NEW |