Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <assert.h> |
| 13 | #include <limits.h> |
| 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "aom_dsp/aom_dsp_common.h" |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 18 | #include "aom_dsp/psnr.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 19 | #include "aom_mem/aom_mem.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | #include "aom_ports/mem.h" |
| 21 | |
Tom Finegan | 17ce8b1 | 2017-02-08 12:46:31 -0800 | [diff] [blame] | 22 | #include "av1/common/av1_loopfilter.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | #include "av1/common/onyxc_int.h" |
| 24 | #include "av1/common/quant_common.h" |
| 25 | |
Tom Finegan | 17ce8b1 | 2017-02-08 12:46:31 -0800 | [diff] [blame] | 26 | #include "av1/encoder/av1_quantize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | #include "av1/encoder/encoder.h" |
| 28 | #include "av1/encoder/picklpf.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 30 | static void yv12_copy_plane(const YV12_BUFFER_CONFIG *src_bc, |
| 31 | YV12_BUFFER_CONFIG *dst_bc, int plane) { |
| 32 | switch (plane) { |
| 33 | case 0: aom_yv12_copy_y(src_bc, dst_bc); break; |
| 34 | case 1: aom_yv12_copy_u(src_bc, dst_bc); break; |
| 35 | case 2: aom_yv12_copy_v(src_bc, dst_bc); break; |
| 36 | default: assert(plane >= 0 && plane <= 2); break; |
| 37 | } |
| 38 | } |
| 39 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 40 | int av1_get_max_filter_level(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 41 | if (cpi->oxcf.pass == 2) { |
| 42 | return cpi->twopass.section_intra_rating > 8 ? MAX_LOOP_FILTER * 3 / 4 |
| 43 | : MAX_LOOP_FILTER; |
| 44 | } else { |
| 45 | return MAX_LOOP_FILTER; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | static int64_t try_filter_frame(const YV12_BUFFER_CONFIG *sd, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | AV1_COMP *const cpi, int filt_level, |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 51 | int partial_frame |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 52 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 53 | , |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 54 | int plane, int dir |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 55 | #endif |
| 56 | ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 57 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | int64_t filt_err; |
| 59 | |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 60 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 61 | assert(plane >= 0 && plane <= 2); |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 62 | int filter_level[2] = { filt_level, filt_level }; |
| 63 | if (plane == 0 && dir == 0) filter_level[1] = cm->lf.filter_level[1]; |
| 64 | if (plane == 0 && dir == 1) filter_level[0] = cm->lf.filter_level[0]; |
| 65 | |
| 66 | av1_loop_filter_frame(cm->frame_to_show, cm, &cpi->td.mb.e_mbd, |
| 67 | filter_level[0], filter_level[1], plane, partial_frame); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 68 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | av1_loop_filter_frame(cm->frame_to_show, cm, &cpi->td.mb.e_mbd, filt_level, 1, |
| 70 | partial_frame); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 71 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 73 | int highbd = 0; |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 74 | highbd = cm->use_highbitdepth; |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 75 | |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 76 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 77 | filt_err = aom_get_sse_plane(sd, cm->frame_to_show, plane, highbd); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 78 | |
| 79 | // Re-instate the unfiltered frame |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 80 | yv12_copy_plane(&cpi->last_frame_uf, cm->frame_to_show, plane); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 81 | #else |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 82 | filt_err = aom_get_sse_plane(sd, cm->frame_to_show, 0, highbd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 83 | |
| 84 | // Re-instate the unfiltered frame |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 85 | yv12_copy_plane(&cpi->last_frame_uf, cm->frame_to_show, 0); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 86 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 87 | |
| 88 | return filt_err; |
| 89 | } |
| 90 | |
Cheng Chen | 1545bdb | 2017-09-05 16:32:12 -0700 | [diff] [blame] | 91 | static int search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi, |
| 92 | int partial_frame, double *best_cost_ret |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 93 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 1545bdb | 2017-09-05 16:32:12 -0700 | [diff] [blame] | 94 | , |
| 95 | int plane, int dir |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 96 | #endif |
Cheng Chen | 1545bdb | 2017-09-05 16:32:12 -0700 | [diff] [blame] | 97 | ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 98 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 99 | const struct loopfilter *const lf = &cm->lf; |
| 100 | const int min_filter_level = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 101 | const int max_filter_level = av1_get_max_filter_level(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 102 | int filt_direction = 0; |
| 103 | int64_t best_err; |
| 104 | int filt_best; |
| 105 | MACROBLOCK *x = &cpi->td.mb; |
| 106 | |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 107 | // Start the search at the previous frame filter level unless it is now out of |
| 108 | // range. |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 109 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 110 | int lvl; |
| 111 | switch (plane) { |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 112 | case 0: lvl = (dir == 1) ? lf->filter_level[1] : lf->filter_level[0]; break; |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 113 | case 1: lvl = lf->filter_level_u; break; |
| 114 | case 2: lvl = lf->filter_level_v; break; |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 115 | default: assert(plane >= 0 && plane <= 2); return 0; |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 116 | } |
| 117 | int filt_mid = clamp(lvl, min_filter_level, max_filter_level); |
| 118 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 119 | int filt_mid = clamp(lf->filter_level, min_filter_level, max_filter_level); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 120 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 121 | int filter_step = filt_mid < 16 ? 4 : filt_mid / 4; |
| 122 | // Sum squared error at each filter level |
| 123 | int64_t ss_err[MAX_LOOP_FILTER + 1]; |
| 124 | |
| 125 | // Set each entry to -1 |
| 126 | memset(ss_err, 0xFF, sizeof(ss_err)); |
| 127 | |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 128 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 129 | yv12_copy_plane(cm->frame_to_show, &cpi->last_frame_uf, plane); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 130 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 131 | // Make a copy of the unfiltered / processed recon buffer |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 132 | aom_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 133 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 135 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 136 | best_err = try_filter_frame(sd, cpi, filt_mid, partial_frame, plane, dir); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 137 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 138 | best_err = try_filter_frame(sd, cpi, filt_mid, partial_frame); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 139 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | filt_best = filt_mid; |
| 141 | ss_err[filt_mid] = best_err; |
| 142 | |
| 143 | while (filter_step > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 144 | const int filt_high = AOMMIN(filt_mid + filter_step, max_filter_level); |
| 145 | const int filt_low = AOMMAX(filt_mid - filter_step, min_filter_level); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 146 | |
| 147 | // Bias against raising loop filter in favor of lowering it. |
| 148 | int64_t bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; |
| 149 | |
| 150 | if ((cpi->oxcf.pass == 2) && (cpi->twopass.section_intra_rating < 20)) |
| 151 | bias = (bias * cpi->twopass.section_intra_rating) / 20; |
| 152 | |
| 153 | // yx, bias less for large block size |
| 154 | if (cm->tx_mode != ONLY_4X4) bias >>= 1; |
| 155 | |
| 156 | if (filt_direction <= 0 && filt_low != filt_mid) { |
| 157 | // Get Low filter error score |
| 158 | if (ss_err[filt_low] < 0) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 159 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 160 | ss_err[filt_low] = |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 161 | try_filter_frame(sd, cpi, filt_low, partial_frame, plane, dir); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 162 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 163 | ss_err[filt_low] = try_filter_frame(sd, cpi, filt_low, partial_frame); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 164 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | } |
| 166 | // If value is close to the best so far then bias towards a lower loop |
| 167 | // filter value. |
| 168 | if (ss_err[filt_low] < (best_err + bias)) { |
| 169 | // Was it actually better than the previous best? |
| 170 | if (ss_err[filt_low] < best_err) { |
| 171 | best_err = ss_err[filt_low]; |
| 172 | } |
| 173 | filt_best = filt_low; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Now look at filt_high |
| 178 | if (filt_direction >= 0 && filt_high != filt_mid) { |
| 179 | if (ss_err[filt_high] < 0) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 180 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 181 | ss_err[filt_high] = |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 182 | try_filter_frame(sd, cpi, filt_high, partial_frame, plane, dir); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 183 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 184 | ss_err[filt_high] = try_filter_frame(sd, cpi, filt_high, partial_frame); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 185 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 186 | } |
| 187 | // If value is significantly better than previous best, bias added against |
| 188 | // raising filter value |
| 189 | if (ss_err[filt_high] < (best_err - bias)) { |
| 190 | best_err = ss_err[filt_high]; |
| 191 | filt_best = filt_high; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // Half the step distance if the best filter value was the same as last time |
| 196 | if (filt_best == filt_mid) { |
| 197 | filter_step /= 2; |
| 198 | filt_direction = 0; |
| 199 | } else { |
| 200 | filt_direction = (filt_best < filt_mid) ? -1 : 1; |
| 201 | filt_mid = filt_best; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Update best error |
| 206 | best_err = ss_err[filt_best]; |
| 207 | |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 208 | if (best_cost_ret) *best_cost_ret = RDCOST_DBL(x->rdmult, 0, best_err); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 209 | return filt_best; |
| 210 | } |
| 211 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 212 | void av1_pick_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi, |
| 213 | LPF_PICK_METHOD method) { |
| 214 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 215 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 216 | struct loopfilter *const lf = &cm->lf; |
Cheng Chen | 765e34e | 2017-12-11 11:43:35 -0800 | [diff] [blame] | 217 | (void)sd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 218 | |
| 219 | lf->sharpness_level = cm->frame_type == KEY_FRAME ? 0 : cpi->oxcf.sharpness; |
| 220 | |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 221 | if (method == LPF_PICK_MINIMAL_LPF) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 222 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 223 | lf->filter_level[0] = 0; |
| 224 | lf->filter_level[1] = 0; |
| 225 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | lf->filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 227 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 228 | } else if (method >= LPF_PICK_FROM_Q) { |
| 229 | const int min_filter_level = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 230 | const int max_filter_level = av1_get_max_filter_level(cpi); |
Monty Montgomery | 60f2a22 | 2017-11-01 19:48:38 -0400 | [diff] [blame] | 231 | const int q = av1_ac_quant_Q3(cm->base_qindex, 0, cm->bit_depth); |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 232 | // These values were determined by linear fitting the result of the |
| 233 | // searched level for 8 bit depth: |
| 234 | // Keyframes: filt_guess = q * 0.06699 - 1.60817 |
| 235 | // Other frames: filt_guess = q * 0.02295 + 2.48225 |
| 236 | // |
| 237 | // And high bit depth separately: |
| 238 | // filt_guess = q * 0.316206 + 3.87252 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 239 | int filt_guess; |
| 240 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 241 | case AOM_BITS_8: |
Alexander Bokov | ac504f7 | 2017-10-10 13:15:13 -0700 | [diff] [blame] | 242 | filt_guess = (cm->frame_type == KEY_FRAME) |
| 243 | ? ROUND_POWER_OF_TWO(q * 17563 - 421574, 18) |
| 244 | : ROUND_POWER_OF_TWO(q * 6017 + 650707, 18); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 245 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 246 | case AOM_BITS_10: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 247 | filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 4060632, 20); |
| 248 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 249 | case AOM_BITS_12: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 250 | filt_guess = ROUND_POWER_OF_TWO(q * 20723 + 16242526, 22); |
| 251 | break; |
| 252 | default: |
| 253 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 254 | "bit_depth should be AOM_BITS_8, AOM_BITS_10 " |
| 255 | "or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 256 | return; |
| 257 | } |
Alexander Bokov | ac504f7 | 2017-10-10 13:15:13 -0700 | [diff] [blame] | 258 | if (cm->bit_depth != AOM_BITS_8 && cm->frame_type == KEY_FRAME) |
| 259 | filt_guess -= 4; |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 260 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 765e34e | 2017-12-11 11:43:35 -0800 | [diff] [blame] | 261 | // TODO(chengchen): retrain the model for Y, U, V filter levels |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 262 | lf->filter_level[0] = clamp(filt_guess, min_filter_level, max_filter_level); |
| 263 | lf->filter_level[1] = clamp(filt_guess, min_filter_level, max_filter_level); |
Cheng Chen | 765e34e | 2017-12-11 11:43:35 -0800 | [diff] [blame] | 264 | lf->filter_level_u = clamp(filt_guess, min_filter_level, max_filter_level); |
| 265 | lf->filter_level_v = clamp(filt_guess, min_filter_level, max_filter_level); |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 266 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 267 | lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level); |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 268 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 269 | } else { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 270 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 1545bdb | 2017-09-05 16:32:12 -0700 | [diff] [blame] | 271 | lf->filter_level[0] = lf->filter_level[1] = search_filter_level( |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 272 | sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 0, 2); |
Cheng Chen | 1545bdb | 2017-09-05 16:32:12 -0700 | [diff] [blame] | 273 | lf->filter_level[0] = search_filter_level( |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 274 | sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 0, 0); |
Cheng Chen | 1545bdb | 2017-09-05 16:32:12 -0700 | [diff] [blame] | 275 | lf->filter_level[1] = search_filter_level( |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 276 | sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 0, 1); |
| 277 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 278 | if (num_planes > 1) { |
| 279 | lf->filter_level_u = search_filter_level( |
| 280 | sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 1, 0); |
| 281 | lf->filter_level_v = search_filter_level( |
| 282 | sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 2, 0); |
| 283 | } |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 284 | #else |
Cheng Chen | 1545bdb | 2017-09-05 16:32:12 -0700 | [diff] [blame] | 285 | lf->filter_level = |
| 286 | search_filter_level(sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 287 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 288 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 289 | } |