Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -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 | 2ab7ff0 | 2016-09-02 12:04:54 -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 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #include "./av1_rtcd.h" |
| 13 | #include "./aom_config.h" |
| 14 | #include "./aom_dsp_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 15 | |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 16 | #include "aom_dsp/bitwriter.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | #include "aom_dsp/quantize.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #include "aom_mem/aom_mem.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | #include "aom_ports/mem.h" |
| 20 | |
| 21 | #include "av1/common/idct.h" |
| 22 | #include "av1/common/reconinter.h" |
| 23 | #include "av1/common/reconintra.h" |
| 24 | #include "av1/common/scan.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/encodemb.h" |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 28 | #if CONFIG_LV_MAP |
| 29 | #include "av1/encoder/encodetxb.h" |
| 30 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | #include "av1/encoder/hybrid_fwd_txfm.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 32 | #include "av1/encoder/rd.h" |
| 33 | #include "av1/encoder/tokenize.h" |
| 34 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 35 | #if CONFIG_PVQ |
| 36 | #include "av1/encoder/encint.h" |
| 37 | #include "av1/common/partition.h" |
| 38 | #include "av1/encoder/pvq_encoder.h" |
| 39 | #endif |
| 40 | |
Luc Trudeau | e398028 | 2017-04-25 23:17:21 -0400 | [diff] [blame] | 41 | #if CONFIG_CFL |
| 42 | #include "av1/common/cfl.h" |
| 43 | #endif |
| 44 | |
Jingning Han | e325abd | 2016-12-01 09:35:10 -0800 | [diff] [blame] | 45 | // Check if one needs to use c version subtraction. |
| 46 | static int check_subtract_block_size(int w, int h) { return w < 4 || h < 4; } |
| 47 | |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 48 | static void subtract_block(const MACROBLOCKD *xd, int rows, int cols, |
| 49 | int16_t *diff, ptrdiff_t diff_stride, |
| 50 | const uint8_t *src8, ptrdiff_t src_stride, |
| 51 | const uint8_t *pred8, ptrdiff_t pred_stride) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 52 | #if !CONFIG_HIGHBITDEPTH |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 53 | (void)xd; |
| 54 | #endif |
| 55 | |
| 56 | if (check_subtract_block_size(rows, cols)) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 57 | #if CONFIG_HIGHBITDEPTH |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 58 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 59 | aom_highbd_subtract_block_c(rows, cols, diff, diff_stride, src8, |
| 60 | src_stride, pred8, pred_stride, xd->bd); |
| 61 | return; |
| 62 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 63 | #endif // CONFIG_HIGHBITDEPTH |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 64 | aom_subtract_block_c(rows, cols, diff, diff_stride, src8, src_stride, pred8, |
| 65 | pred_stride); |
| 66 | |
| 67 | return; |
| 68 | } |
| 69 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 70 | #if CONFIG_HIGHBITDEPTH |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 71 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 72 | aom_highbd_subtract_block(rows, cols, diff, diff_stride, src8, src_stride, |
| 73 | pred8, pred_stride, xd->bd); |
| 74 | return; |
| 75 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 76 | #endif // CONFIG_HIGHBITDEPTH |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 77 | aom_subtract_block(rows, cols, diff, diff_stride, src8, src_stride, pred8, |
| 78 | pred_stride); |
| 79 | } |
| 80 | |
Angie Chiang | f87e43f | 2017-04-02 16:51:19 -0700 | [diff] [blame] | 81 | void av1_subtract_txb(MACROBLOCK *x, int plane, BLOCK_SIZE plane_bsize, |
| 82 | int blk_col, int blk_row, TX_SIZE tx_size) { |
| 83 | MACROBLOCKD *const xd = &x->e_mbd; |
| 84 | struct macroblock_plane *const p = &x->plane[plane]; |
| 85 | const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane]; |
| 86 | const int diff_stride = block_size_wide[plane_bsize]; |
| 87 | const int src_stride = p->src.stride; |
| 88 | const int dst_stride = pd->dst.stride; |
| 89 | const int tx1d_width = tx_size_wide[tx_size]; |
| 90 | const int tx1d_height = tx_size_high[tx_size]; |
| 91 | uint8_t *dst = |
| 92 | &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]]; |
| 93 | uint8_t *src = |
| 94 | &p->src.buf[(blk_row * src_stride + blk_col) << tx_size_wide_log2[0]]; |
| 95 | int16_t *src_diff = |
| 96 | &p->src_diff[(blk_row * diff_stride + blk_col) << tx_size_wide_log2[0]]; |
| 97 | subtract_block(xd, tx1d_height, tx1d_width, src_diff, diff_stride, src, |
| 98 | src_stride, dst, dst_stride); |
| 99 | } |
| 100 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 101 | void av1_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 102 | struct macroblock_plane *const p = &x->plane[plane]; |
| 103 | const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane]; |
| 104 | const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); |
Jingning Han | ae5cfde | 2016-11-30 12:01:44 -0800 | [diff] [blame] | 105 | const int bw = block_size_wide[plane_bsize]; |
| 106 | const int bh = block_size_high[plane_bsize]; |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 107 | const MACROBLOCKD *xd = &x->e_mbd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 108 | |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 109 | subtract_block(xd, bh, bw, p->src_diff, bw, p->src.buf, p->src.stride, |
| 110 | pd->dst.buf, pd->dst.stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 113 | // These numbers are empirically obtained. |
| 114 | static const int plane_rd_mult[REF_TYPES][PLANE_TYPES] = { |
Thomas Davies | 1052575 | 2017-03-06 12:10:46 +0000 | [diff] [blame] | 115 | { 10, 7 }, { 8, 5 }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Yaowu Xu | 4235032 | 2017-05-05 11:12:19 -0700 | [diff] [blame] | 118 | static INLINE unsigned int get_token_bit_costs( |
| 119 | unsigned int token_costs[2][COEFF_CONTEXTS][ENTROPY_TOKENS], int skip_eob, |
| 120 | int ctx, int token) { |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 121 | (void)skip_eob; |
| 122 | return token_costs[token == ZERO_TOKEN || token == EOB_TOKEN][ctx][token]; |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Angie Chiang | 1c96e82 | 2017-05-31 14:40:55 -0700 | [diff] [blame] | 125 | #if !CONFIG_LV_MAP |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 126 | |
Angie Chiang | 7dec6c4 | 2017-05-03 17:58:17 -0700 | [diff] [blame] | 127 | static int optimize_b_greedy(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 128 | int blk_row, int blk_col, int block, |
| 129 | TX_SIZE tx_size, int ctx) { |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 130 | MACROBLOCKD *const xd = &mb->e_mbd; |
| 131 | struct macroblock_plane *const p = &mb->plane[plane]; |
| 132 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 133 | const int ref = is_inter_block(&xd->mi[0]->mbmi); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 134 | uint8_t token_cache[MAX_TX_SQUARE]; |
| 135 | const tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
| 136 | tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 137 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 138 | const int eob = p->eobs[block]; |
| 139 | const PLANE_TYPE plane_type = pd->plane_type; |
| 140 | const int16_t *const dequant_ptr = pd->dequant; |
| 141 | const uint8_t *const band_translate = get_band_translate(tx_size); |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 142 | TX_TYPE tx_type = |
| 143 | av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 144 | const SCAN_ORDER *const scan_order = |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 145 | get_scan(cm, tx_size, tx_type, &xd->mi[0]->mbmi); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 146 | const int16_t *const scan = scan_order->scan; |
| 147 | const int16_t *const nb = scan_order->neighbors; |
| 148 | int dqv; |
Jingning Han | ff70545 | 2017-04-27 11:32:15 -0700 | [diff] [blame] | 149 | const int shift = av1_get_tx_scale(tx_size); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 150 | #if CONFIG_AOM_QM |
| 151 | int seg_id = xd->mi[0]->mbmi.segment_id; |
Thomas Davies | be44e51 | 2017-06-07 11:41:07 +0100 | [diff] [blame] | 152 | // Use a flat matrix (i.e. no weighting) for 1D and Identity transforms |
| 153 | const qm_val_t *iqmatrix = |
| 154 | IS_2D_TRANSFORM(tx_type) |
| 155 | ? pd->seg_iqmatrix[seg_id][!ref][tx_size] |
| 156 | : cm->giqmatrix[NUM_QM_LEVELS - 1][0][0][tx_size]; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 157 | #endif |
| 158 | #if CONFIG_NEW_QUANT |
| 159 | int dq = get_dq_profile_from_ctx(mb->qindex, ctx, ref, plane_type); |
| 160 | const dequant_val_type_nuq *dequant_val = pd->dequant_val_nuq[dq]; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 161 | #endif // CONFIG_NEW_QUANT |
| 162 | int sz = 0; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 163 | int64_t rd_cost0, rd_cost1; |
| 164 | int16_t t0, t1; |
| 165 | int i, final_eob; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 166 | const int cat6_bits = av1_get_cat6_extrabits_size(tx_size, xd->bd); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 167 | unsigned int(*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = |
| 168 | mb->token_costs[txsize_sqr_map[tx_size]][plane_type][ref]; |
| 169 | const int default_eob = tx_size_2d[tx_size]; |
| 170 | |
Angie Chiang | 7dec6c4 | 2017-05-03 17:58:17 -0700 | [diff] [blame] | 171 | assert(mb->qindex > 0); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 172 | |
| 173 | assert((!plane_type && !plane) || (plane_type && plane)); |
| 174 | assert(eob <= default_eob); |
| 175 | |
| 176 | int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][plane_type]) >> 1; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 177 | |
| 178 | int64_t rate0, rate1; |
| 179 | for (i = 0; i < eob; i++) { |
| 180 | const int rc = scan[i]; |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 181 | token_cache[rc] = av1_pt_energy_class[av1_get_token(qcoeff[rc])]; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 182 | } |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 183 | |
| 184 | unsigned int(*token_costs_ptr)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = |
| 185 | token_costs; |
| 186 | |
| 187 | final_eob = 0; |
| 188 | |
| 189 | int64_t eob_cost0, eob_cost1; |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 190 | tran_low_t before_best_eob_qc = 0; |
| 191 | tran_low_t before_best_eob_dqc = 0; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 192 | |
| 193 | const int ctx0 = ctx; |
| 194 | /* Record the r-d cost */ |
| 195 | int64_t accu_rate = 0; |
Urvang Joshi | 6eb35eb | 2017-06-14 13:28:56 -0700 | [diff] [blame] | 196 | // Initialized to the worst possible error for the largest transform size. |
| 197 | // This ensures that it never goes negative. |
| 198 | int64_t accu_error = ((int64_t)1) << 50; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 199 | |
| 200 | rate0 = get_token_bit_costs(*(token_costs_ptr + band_translate[0]), 0, ctx0, |
| 201 | EOB_TOKEN); |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 202 | int64_t best_block_rd_cost = RDCOST(rdmult, rate0, accu_error); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 203 | |
| 204 | // int64_t best_block_rd_cost_all0 = best_block_rd_cost; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 205 | int x_prev = 1; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 206 | for (i = 0; i < eob; i++) { |
| 207 | const int rc = scan[i]; |
| 208 | int x = qcoeff[rc]; |
| 209 | sz = -(x < 0); |
| 210 | |
| 211 | int band_cur = band_translate[i]; |
| 212 | int ctx_cur = (i == 0) ? ctx : get_coef_context(nb, token_cache, i); |
| 213 | int token_tree_sel_cur = (x_prev == 0); |
| 214 | |
| 215 | if (x == 0) { |
| 216 | // no need to search when x == 0 |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 217 | int token = av1_get_token(x); |
| 218 | rate0 = get_token_bit_costs(*(token_costs_ptr + band_cur), |
| 219 | token_tree_sel_cur, ctx_cur, token); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 220 | accu_rate += rate0; |
| 221 | x_prev = 0; |
| 222 | // accu_error does not change when x==0 |
| 223 | } else { |
| 224 | /* Computing distortion |
| 225 | */ |
| 226 | // compute the distortion for the first candidate |
| 227 | // and the distortion for quantizing to 0. |
Jingning Han | 32d26bc | 2017-06-11 07:50:39 -0700 | [diff] [blame] | 228 | int dx0 = abs(coeff[rc]) * (1 << shift); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 229 | #if CONFIG_HIGHBITDEPTH |
| 230 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 231 | dx0 >>= xd->bd - 8; |
| 232 | } |
| 233 | #endif |
| 234 | int64_t d0 = (int64_t)dx0 * dx0; |
| 235 | |
| 236 | int x_a = x - 2 * sz - 1; |
| 237 | int64_t d2, d2_a; |
| 238 | |
| 239 | int dx; |
| 240 | |
| 241 | #if CONFIG_AOM_QM |
| 242 | int iwt = iqmatrix[rc]; |
| 243 | dqv = dequant_ptr[rc != 0]; |
| 244 | dqv = ((iwt * (int)dqv) + (1 << (AOM_QM_BITS - 1))) >> AOM_QM_BITS; |
| 245 | #else |
| 246 | dqv = dequant_ptr[rc != 0]; |
| 247 | #endif |
| 248 | |
| 249 | dx = (dqcoeff[rc] - coeff[rc]) * (1 << shift); |
| 250 | #if CONFIG_HIGHBITDEPTH |
| 251 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
Jingning Han | 32d26bc | 2017-06-11 07:50:39 -0700 | [diff] [blame] | 252 | int dx_sign = dx < 0 ? 1 : 0; |
| 253 | dx = abs(dx) >> (xd->bd - 8); |
| 254 | if (dx_sign) dx = -dx; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 255 | } |
| 256 | #endif // CONFIG_HIGHBITDEPTH |
| 257 | d2 = (int64_t)dx * dx; |
| 258 | |
| 259 | /* compute the distortion for the second candidate |
| 260 | * x_a = x - 2 * sz + 1; |
| 261 | */ |
| 262 | if (x_a != 0) { |
| 263 | #if CONFIG_NEW_QUANT |
| 264 | dx = av1_dequant_coeff_nuq(x, dqv, dequant_val[band_translate[i]]) - |
| 265 | (coeff[rc] << shift); |
| 266 | #if CONFIG_HIGHBITDEPTH |
| 267 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 268 | dx >>= xd->bd - 8; |
| 269 | } |
| 270 | #endif // CONFIG_HIGHBITDEPTH |
| 271 | #else // CONFIG_NEW_QUANT |
| 272 | #if CONFIG_HIGHBITDEPTH |
| 273 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 274 | dx -= ((dqv >> (xd->bd - 8)) + sz) ^ sz; |
| 275 | } else { |
| 276 | dx -= (dqv + sz) ^ sz; |
| 277 | } |
| 278 | #else |
| 279 | dx -= (dqv + sz) ^ sz; |
| 280 | #endif // CONFIG_HIGHBITDEPTH |
| 281 | #endif // CONFIG_NEW_QUANT |
| 282 | d2_a = (int64_t)dx * dx; |
| 283 | } else { |
| 284 | d2_a = d0; |
| 285 | } |
| 286 | /* Computing rates and r-d cost |
| 287 | */ |
| 288 | |
| 289 | int best_x, best_eob_x; |
| 290 | int64_t base_bits, next_bits0, next_bits1; |
| 291 | int64_t next_eob_bits0, next_eob_bits1; |
| 292 | |
| 293 | // rate cost of x |
| 294 | base_bits = av1_get_token_cost(x, &t0, cat6_bits); |
| 295 | rate0 = base_bits + get_token_bit_costs(*(token_costs_ptr + band_cur), |
| 296 | token_tree_sel_cur, ctx_cur, t0); |
| 297 | |
| 298 | base_bits = av1_get_token_cost(x_a, &t1, cat6_bits); |
| 299 | rate1 = base_bits + get_token_bit_costs(*(token_costs_ptr + band_cur), |
| 300 | token_tree_sel_cur, ctx_cur, t1); |
| 301 | |
| 302 | next_bits0 = 0; |
| 303 | next_bits1 = 0; |
| 304 | next_eob_bits0 = 0; |
| 305 | next_eob_bits1 = 0; |
| 306 | |
| 307 | if (i < default_eob - 1) { |
| 308 | int ctx_next, token_tree_sel_next; |
| 309 | int band_next = band_translate[i + 1]; |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 310 | int token_next = |
| 311 | i + 1 != eob ? av1_get_token(qcoeff[scan[i + 1]]) : EOB_TOKEN; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 312 | |
| 313 | token_cache[rc] = av1_pt_energy_class[t0]; |
| 314 | ctx_next = get_coef_context(nb, token_cache, i + 1); |
| 315 | token_tree_sel_next = (x == 0); |
| 316 | |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 317 | next_bits0 = |
| 318 | get_token_bit_costs(*(token_costs_ptr + band_next), |
| 319 | token_tree_sel_next, ctx_next, token_next); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 320 | next_eob_bits0 = |
| 321 | get_token_bit_costs(*(token_costs_ptr + band_next), |
| 322 | token_tree_sel_next, ctx_next, EOB_TOKEN); |
| 323 | |
| 324 | token_cache[rc] = av1_pt_energy_class[t1]; |
| 325 | ctx_next = get_coef_context(nb, token_cache, i + 1); |
| 326 | token_tree_sel_next = (x_a == 0); |
| 327 | |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 328 | next_bits1 = |
| 329 | get_token_bit_costs(*(token_costs_ptr + band_next), |
| 330 | token_tree_sel_next, ctx_next, token_next); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 331 | |
| 332 | if (x_a != 0) { |
| 333 | next_eob_bits1 = |
| 334 | get_token_bit_costs(*(token_costs_ptr + band_next), |
| 335 | token_tree_sel_next, ctx_next, EOB_TOKEN); |
| 336 | } |
| 337 | } |
| 338 | |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 339 | rd_cost0 = RDCOST(rdmult, (rate0 + next_bits0), d2); |
| 340 | rd_cost1 = RDCOST(rdmult, (rate1 + next_bits1), d2_a); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 341 | |
| 342 | best_x = (rd_cost1 < rd_cost0); |
| 343 | |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 344 | eob_cost0 = RDCOST(rdmult, (accu_rate + rate0 + next_eob_bits0), |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 345 | (accu_error + d2 - d0)); |
| 346 | eob_cost1 = eob_cost0; |
| 347 | if (x_a != 0) { |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 348 | eob_cost1 = RDCOST(rdmult, (accu_rate + rate1 + next_eob_bits1), |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 349 | (accu_error + d2_a - d0)); |
| 350 | best_eob_x = (eob_cost1 < eob_cost0); |
| 351 | } else { |
| 352 | best_eob_x = 0; |
| 353 | } |
| 354 | |
| 355 | int dqc, dqc_a = 0; |
| 356 | |
| 357 | dqc = dqcoeff[rc]; |
| 358 | if (best_x + best_eob_x) { |
| 359 | if (x_a != 0) { |
| 360 | #if CONFIG_NEW_QUANT |
| 361 | dqc_a = av1_dequant_abscoeff_nuq(abs(x_a), dqv, |
| 362 | dequant_val[band_translate[i]]); |
| 363 | dqc_a = shift ? ROUND_POWER_OF_TWO(dqc_a, shift) : dqc_a; |
| 364 | if (sz) dqc_a = -dqc_a; |
| 365 | #else |
David Barker | c747a78 | 2017-05-24 12:46:08 +0100 | [diff] [blame] | 366 | if (x_a < 0) |
| 367 | dqc_a = -((-x_a * dqv) >> shift); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 368 | else |
David Barker | c747a78 | 2017-05-24 12:46:08 +0100 | [diff] [blame] | 369 | dqc_a = (x_a * dqv) >> shift; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 370 | #endif // CONFIG_NEW_QUANT |
| 371 | } else { |
| 372 | dqc_a = 0; |
| 373 | } // if (x_a != 0) |
| 374 | } |
| 375 | |
| 376 | // record the better quantized value |
| 377 | if (best_x) { |
| 378 | qcoeff[rc] = x_a; |
| 379 | dqcoeff[rc] = dqc_a; |
| 380 | |
| 381 | accu_rate += rate1; |
| 382 | accu_error += d2_a - d0; |
| 383 | assert(d2_a <= d0); |
| 384 | |
| 385 | token_cache[rc] = av1_pt_energy_class[t1]; |
| 386 | } else { |
| 387 | accu_rate += rate0; |
| 388 | accu_error += d2 - d0; |
| 389 | assert(d2 <= d0); |
| 390 | |
| 391 | token_cache[rc] = av1_pt_energy_class[t0]; |
| 392 | } |
Urvang Joshi | 6eb35eb | 2017-06-14 13:28:56 -0700 | [diff] [blame] | 393 | assert(accu_error >= 0); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 394 | |
| 395 | x_prev = qcoeff[rc]; |
| 396 | |
| 397 | // determine whether to move the eob position to i+1 |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 398 | int use_a = (x_a != 0) && (best_eob_x); |
| 399 | int64_t best_eob_cost_i = use_a ? eob_cost1 : eob_cost0; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 400 | |
| 401 | if (best_eob_cost_i < best_block_rd_cost) { |
| 402 | best_block_rd_cost = best_eob_cost_i; |
| 403 | final_eob = i + 1; |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 404 | if (use_a) { |
| 405 | before_best_eob_qc = x_a; |
| 406 | before_best_eob_dqc = dqc_a; |
| 407 | } else { |
| 408 | before_best_eob_qc = x; |
| 409 | before_best_eob_dqc = dqc; |
| 410 | } |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 411 | } |
| 412 | } // if (x==0) |
| 413 | } // for (i) |
| 414 | |
| 415 | assert(final_eob <= eob); |
| 416 | if (final_eob > 0) { |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 417 | assert(before_best_eob_qc != 0); |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 418 | i = final_eob - 1; |
| 419 | int rc = scan[i]; |
Kyle Siefring | 627e2fd | 2017-07-02 15:43:07 -0400 | [diff] [blame] | 420 | qcoeff[rc] = before_best_eob_qc; |
| 421 | dqcoeff[rc] = before_best_eob_dqc; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | for (i = final_eob; i < eob; i++) { |
| 425 | int rc = scan[i]; |
| 426 | qcoeff[rc] = 0; |
| 427 | dqcoeff[rc] = 0; |
| 428 | } |
| 429 | |
| 430 | mb->plane[plane].eobs[block] = final_eob; |
| 431 | return final_eob; |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 432 | } |
Angie Chiang | 1c96e82 | 2017-05-31 14:40:55 -0700 | [diff] [blame] | 433 | #endif // !CONFIG_LV_MAP |
Dake He | 97f5664 | 2017-03-29 16:46:51 -0700 | [diff] [blame] | 434 | |
Jingning Han | 7eab9ff | 2017-07-06 10:12:54 -0700 | [diff] [blame] | 435 | int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int blk_row, |
| 436 | int blk_col, int block, BLOCK_SIZE plane_bsize, |
| 437 | TX_SIZE tx_size, const ENTROPY_CONTEXT *a, |
| 438 | const ENTROPY_CONTEXT *l) { |
Angie Chiang | 7dec6c4 | 2017-05-03 17:58:17 -0700 | [diff] [blame] | 439 | MACROBLOCKD *const xd = &mb->e_mbd; |
| 440 | struct macroblock_plane *const p = &mb->plane[plane]; |
| 441 | const int eob = p->eobs[block]; |
| 442 | assert((mb->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0)); |
| 443 | if (eob == 0) return eob; |
| 444 | if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return eob; |
Jingning Han | aba246d | 2017-06-14 12:00:16 -0700 | [diff] [blame] | 445 | |
Angie Chiang | 1c96e82 | 2017-05-31 14:40:55 -0700 | [diff] [blame] | 446 | #if CONFIG_PVQ |
| 447 | (void)cm; |
| 448 | (void)tx_size; |
| 449 | (void)a; |
| 450 | (void)l; |
| 451 | return eob; |
| 452 | #endif |
Angie Chiang | 3511c37 | 2017-05-31 12:47:07 -0700 | [diff] [blame] | 453 | |
Angie Chiang | 1c96e82 | 2017-05-31 14:40:55 -0700 | [diff] [blame] | 454 | #if !CONFIG_LV_MAP |
| 455 | (void)plane_bsize; |
Jingning Han | 7eab9ff | 2017-07-06 10:12:54 -0700 | [diff] [blame] | 456 | (void)blk_row; |
| 457 | (void)blk_col; |
Angie Chiang | 3511c37 | 2017-05-31 12:47:07 -0700 | [diff] [blame] | 458 | #if CONFIG_VAR_TX |
| 459 | int ctx = get_entropy_context(tx_size, a, l); |
| 460 | #else |
| 461 | int ctx = combine_entropy_contexts(*a, *l); |
Urvang Joshi | 09302f5 | 2017-06-08 14:24:59 -0700 | [diff] [blame] | 462 | #endif // CONFIG_VAR_TX |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 463 | return optimize_b_greedy(cm, mb, plane, blk_row, blk_col, block, tx_size, |
| 464 | ctx); |
Angie Chiang | 1c96e82 | 2017-05-31 14:40:55 -0700 | [diff] [blame] | 465 | #else // !CONFIG_LV_MAP |
| 466 | TXB_CTX txb_ctx; |
| 467 | get_txb_ctx(plane_bsize, tx_size, plane, a, l, &txb_ctx); |
Jingning Han | 7eab9ff | 2017-07-06 10:12:54 -0700 | [diff] [blame] | 468 | return av1_optimize_txb(cm, mb, plane, blk_row, blk_col, block, tx_size, |
| 469 | &txb_ctx); |
Angie Chiang | 1c96e82 | 2017-05-31 14:40:55 -0700 | [diff] [blame] | 470 | #endif // !CONFIG_LV_MAP |
Angie Chiang | 7dec6c4 | 2017-05-03 17:58:17 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 473 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 474 | typedef enum QUANT_FUNC { |
| 475 | QUANT_FUNC_LOWBD = 0, |
| 476 | QUANT_FUNC_HIGHBD = 1, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 477 | QUANT_FUNC_TYPES = 2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 478 | } QUANT_FUNC; |
| 479 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 480 | static AV1_QUANT_FACADE |
| 481 | quant_func_list[AV1_XFORM_QUANT_TYPES][QUANT_FUNC_TYPES] = { |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 482 | #if !CONFIG_NEW_QUANT |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 483 | { av1_quantize_fp_facade, av1_highbd_quantize_fp_facade }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 484 | { av1_quantize_b_facade, av1_highbd_quantize_b_facade }, |
| 485 | { av1_quantize_dc_facade, av1_highbd_quantize_dc_facade }, |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 486 | #else // !CONFIG_NEW_QUANT |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 487 | { av1_quantize_fp_nuq_facade, av1_highbd_quantize_fp_nuq_facade }, |
| 488 | { av1_quantize_b_nuq_facade, av1_highbd_quantize_b_nuq_facade }, |
| 489 | { av1_quantize_dc_nuq_facade, av1_highbd_quantize_dc_nuq_facade }, |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 490 | #endif // !CONFIG_NEW_QUANT |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 491 | { NULL, NULL } |
| 492 | }; |
Yi Luo | 0f4195c | 2017-06-27 16:07:28 -0700 | [diff] [blame] | 493 | #endif // !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 494 | |
Yi Luo | 0f4195c | 2017-06-27 16:07:28 -0700 | [diff] [blame] | 495 | typedef void (*fwdTxfmFunc)(const int16_t *diff, tran_low_t *coeff, int stride, |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 496 | TxfmParam *txfm_param); |
Yi Luo | 0f4195c | 2017-06-27 16:07:28 -0700 | [diff] [blame] | 497 | static const fwdTxfmFunc fwd_txfm_func[2] = { av1_fwd_txfm, |
| 498 | av1_highbd_fwd_txfm }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 499 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 500 | void av1_xform_quant(const AV1_COMMON *cm, MACROBLOCK *x, int plane, int block, |
| 501 | int blk_row, int blk_col, BLOCK_SIZE plane_bsize, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 502 | TX_SIZE tx_size, int ctx, |
| 503 | AV1_XFORM_QUANT xform_quant_idx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 504 | MACROBLOCKD *const xd = &x->e_mbd; |
Luc Trudeau | b6e94d9 | 2017-03-13 15:46:15 -0400 | [diff] [blame] | 505 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 506 | #if !(CONFIG_PVQ || CONFIG_DIST_8X8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 507 | const struct macroblock_plane *const p = &x->plane[plane]; |
| 508 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 509 | #else |
| 510 | struct macroblock_plane *const p = &x->plane[plane]; |
| 511 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 512 | #endif |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 513 | PLANE_TYPE plane_type = get_plane_type(plane); |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 514 | TX_TYPE tx_type = |
| 515 | av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size); |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 516 | |
| 517 | #if CONFIG_AOM_QM || CONFIG_NEW_QUANT |
Luc Trudeau | b6e94d9 | 2017-03-13 15:46:15 -0400 | [diff] [blame] | 518 | const int is_inter = is_inter_block(mbmi); |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 519 | #endif |
| 520 | |
| 521 | const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, mbmi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
| 523 | tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 524 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 525 | uint16_t *const eob = &p->eobs[block]; |
Jingning Han | ae5cfde | 2016-11-30 12:01:44 -0800 | [diff] [blame] | 526 | const int diff_stride = block_size_wide[plane_bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 527 | #if CONFIG_AOM_QM |
Luc Trudeau | b6e94d9 | 2017-03-13 15:46:15 -0400 | [diff] [blame] | 528 | int seg_id = mbmi->segment_id; |
Thomas Davies | be44e51 | 2017-06-07 11:41:07 +0100 | [diff] [blame] | 529 | // Use a flat matrix (i.e. no weighting) for 1D and Identity transforms |
| 530 | const qm_val_t *qmatrix = |
| 531 | IS_2D_TRANSFORM(tx_type) ? pd->seg_qmatrix[seg_id][!is_inter][tx_size] |
| 532 | : cm->gqmatrix[NUM_QM_LEVELS - 1][0][0][tx_size]; |
| 533 | const qm_val_t *iqmatrix = |
| 534 | IS_2D_TRANSFORM(tx_type) |
| 535 | ? pd->seg_iqmatrix[seg_id][!is_inter][tx_size] |
| 536 | : cm->giqmatrix[NUM_QM_LEVELS - 1][0][0][tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 537 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 538 | |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 539 | TxfmParam txfm_param; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 540 | |
Sarah Parker | 5b8e6d2 | 2017-07-24 15:30:53 -0700 | [diff] [blame] | 541 | #if CONFIG_PVQ || CONFIG_DIST_8X8 || CONFIG_LGT || CONFIG_MRC_TX |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 542 | uint8_t *dst; |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 543 | const int dst_stride = pd->dst.stride; |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 544 | #if CONFIG_PVQ || CONFIG_DIST_8X8 |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 545 | int16_t *pred; |
Yushin Cho | 1c602b3 | 2017-06-07 17:57:14 -0700 | [diff] [blame] | 546 | const int txw = tx_size_wide[tx_size]; |
| 547 | const int txh = tx_size_high[tx_size]; |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 548 | int i, j; |
| 549 | #endif |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 550 | #endif |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 551 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 552 | #if !CONFIG_PVQ |
| 553 | const int tx2d_size = tx_size_2d[tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 554 | QUANT_PARAM qparam; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 555 | const int16_t *src_diff; |
| 556 | |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 557 | src_diff = |
| 558 | &p->src_diff[(blk_row * diff_stride + blk_col) << tx_size_wide_log2[0]]; |
Jingning Han | ff70545 | 2017-04-27 11:32:15 -0700 | [diff] [blame] | 559 | qparam.log_scale = av1_get_tx_scale(tx_size); |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 560 | #if CONFIG_NEW_QUANT |
| 561 | qparam.tx_size = tx_size; |
| 562 | qparam.dq = get_dq_profile_from_ctx(x->qindex, ctx, is_inter, plane_type); |
| 563 | #endif // CONFIG_NEW_QUANT |
| 564 | #if CONFIG_AOM_QM |
| 565 | qparam.qmatrix = qmatrix; |
| 566 | qparam.iqmatrix = iqmatrix; |
| 567 | #endif // CONFIG_AOM_QM |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 568 | #else |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 569 | tran_low_t *ref_coeff = BLOCK_OFFSET(pd->pvq_ref_coeff, block); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 570 | int skip = 1; |
| 571 | PVQ_INFO *pvq_info = NULL; |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 572 | uint8_t *src; |
| 573 | int16_t *src_int16; |
| 574 | const int src_stride = p->src.stride; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 575 | |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 576 | (void)ctx; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 577 | (void)scan_order; |
| 578 | (void)qcoeff; |
| 579 | |
| 580 | if (x->pvq_coded) { |
| 581 | assert(block < MAX_PVQ_BLOCKS_IN_SB); |
| 582 | pvq_info = &x->pvq[block][plane]; |
| 583 | } |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 584 | src = &p->src.buf[(blk_row * src_stride + blk_col) << tx_size_wide_log2[0]]; |
| 585 | src_int16 = |
| 586 | &p->src_int16[(blk_row * diff_stride + blk_col) << tx_size_wide_log2[0]]; |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 587 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 588 | #if CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 589 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
Yushin Cho | 1c602b3 | 2017-06-07 17:57:14 -0700 | [diff] [blame] | 590 | for (j = 0; j < txh; j++) |
| 591 | for (i = 0; i < txw; i++) |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 592 | src_int16[diff_stride * j + i] = |
| 593 | CONVERT_TO_SHORTPTR(src)[src_stride * j + i]; |
| 594 | } else { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 595 | #endif // CONFIG_HIGHBITDEPTH |
Yushin Cho | 1c602b3 | 2017-06-07 17:57:14 -0700 | [diff] [blame] | 596 | for (j = 0; j < txh; j++) |
| 597 | for (i = 0; i < txw; i++) |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 598 | src_int16[diff_stride * j + i] = src[src_stride * j + i]; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 599 | #if CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 600 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 601 | #endif // CONFIG_HIGHBITDEPTH |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 602 | #endif |
| 603 | |
Sarah Parker | 5b8e6d2 | 2017-07-24 15:30:53 -0700 | [diff] [blame] | 604 | #if CONFIG_PVQ || CONFIG_DIST_8X8 || CONFIG_LGT || CONFIG_MRC_TX |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 605 | dst = &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]]; |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 606 | #if CONFIG_PVQ || CONFIG_DIST_8X8 |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 607 | pred = &pd->pred[(blk_row * diff_stride + blk_col) << tx_size_wide_log2[0]]; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 608 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 609 | // copy uint8 orig and predicted block to int16 buffer |
| 610 | // in order to use existing VP10 transform functions |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 611 | #if CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 612 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
Yushin Cho | 1c602b3 | 2017-06-07 17:57:14 -0700 | [diff] [blame] | 613 | for (j = 0; j < txh; j++) |
| 614 | for (i = 0; i < txw; i++) |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 615 | pred[diff_stride * j + i] = |
| 616 | CONVERT_TO_SHORTPTR(dst)[dst_stride * j + i]; |
| 617 | } else { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 618 | #endif // CONFIG_HIGHBITDEPTH |
Yushin Cho | 1c602b3 | 2017-06-07 17:57:14 -0700 | [diff] [blame] | 619 | for (j = 0; j < txh; j++) |
| 620 | for (i = 0; i < txw; i++) |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 621 | pred[diff_stride * j + i] = dst[dst_stride * j + i]; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 622 | #if CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 623 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 624 | #endif // CONFIG_HIGHBITDEPTH |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 625 | #endif // CONFIG_PVQ || CONFIG_DIST_8X8 |
Sarah Parker | 5b8e6d2 | 2017-07-24 15:30:53 -0700 | [diff] [blame] | 626 | #endif // CONFIG_PVQ || CONFIG_DIST_8X8 || CONFIG_LGT || CONFIG_MRC_TX |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 627 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 628 | (void)ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 629 | |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 630 | txfm_param.tx_type = tx_type; |
| 631 | txfm_param.tx_size = tx_size; |
| 632 | txfm_param.lossless = xd->lossless[mbmi->segment_id]; |
Sarah Parker | 5b8e6d2 | 2017-07-24 15:30:53 -0700 | [diff] [blame] | 633 | #if CONFIG_MRC_TX || CONFIG_LGT |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 634 | txfm_param.dst = dst; |
| 635 | txfm_param.stride = dst_stride; |
Sarah Parker | 5b8e6d2 | 2017-07-24 15:30:53 -0700 | [diff] [blame] | 636 | #endif // CONFIG_MRC_TX || CONFIG_LGT |
| 637 | #if CONFIG_LGT |
| 638 | txfm_param.is_inter = is_inter_block(mbmi); |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 639 | txfm_param.mode = get_prediction_mode(xd->mi[0], plane, tx_size, block); |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 640 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 641 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 642 | #if !CONFIG_PVQ |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 643 | txfm_param.bd = xd->bd; |
Yi Luo | 0f4195c | 2017-06-27 16:07:28 -0700 | [diff] [blame] | 644 | const int is_hbd = get_bitdepth_data_path_index(xd); |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 645 | fwd_txfm_func[is_hbd](src_diff, coeff, diff_stride, &txfm_param); |
Yi Luo | 0f4195c | 2017-06-27 16:07:28 -0700 | [diff] [blame] | 646 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 647 | if (xform_quant_idx != AV1_XFORM_QUANT_SKIP_QUANT) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 648 | if (LIKELY(!x->skip_block)) { |
Yi Luo | 0f4195c | 2017-06-27 16:07:28 -0700 | [diff] [blame] | 649 | quant_func_list[xform_quant_idx][is_hbd]( |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 650 | coeff, tx2d_size, p, qcoeff, pd, dqcoeff, eob, scan_order, &qparam); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 651 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 652 | av1_quantize_skip(tx2d_size, qcoeff, dqcoeff, eob); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 655 | #if CONFIG_LV_MAP |
| 656 | p->txb_entropy_ctx[block] = |
| 657 | (uint8_t)av1_get_txb_entropy_context(qcoeff, scan_order, *eob); |
| 658 | #endif // CONFIG_LV_MAP |
Yi Luo | 0f4195c | 2017-06-27 16:07:28 -0700 | [diff] [blame] | 659 | return; |
| 660 | #else // CONFIG_PVQ |
Angie Chiang | 2cc057c | 2017-01-03 18:31:47 -0800 | [diff] [blame] | 661 | (void)xform_quant_idx; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 662 | #if CONFIG_HIGHBITDEPTH |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 663 | txfm_param.bd = xd->bd; |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 664 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 665 | av1_highbd_fwd_txfm(src_int16, coeff, diff_stride, &txfm_param); |
| 666 | av1_highbd_fwd_txfm(pred, ref_coeff, diff_stride, &txfm_param); |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 667 | } else { |
| 668 | #endif |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 669 | av1_fwd_txfm(src_int16, coeff, diff_stride, &txfm_param); |
| 670 | av1_fwd_txfm(pred, ref_coeff, diff_stride, &txfm_param); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 671 | #if CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 672 | } |
| 673 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 674 | |
| 675 | // PVQ for inter mode block |
ltrudeau | 472f63f | 2017-01-12 15:22:32 -0500 | [diff] [blame] | 676 | if (!x->skip_block) { |
ltrudeau | e1c0929 | 2017-01-20 15:42:13 -0500 | [diff] [blame] | 677 | PVQ_SKIP_TYPE ac_dc_coded = |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 678 | av1_pvq_encode_helper(x, |
ltrudeau | e1c0929 | 2017-01-20 15:42:13 -0500 | [diff] [blame] | 679 | coeff, // target original vector |
| 680 | ref_coeff, // reference vector |
| 681 | dqcoeff, // de-quantized vector |
| 682 | eob, // End of Block marker |
| 683 | pd->dequant, // aom's quantizers |
| 684 | plane, // image plane |
| 685 | tx_size, // block size in log_2 - 2 |
| 686 | tx_type, |
| 687 | &x->rate, // rate measured |
| 688 | x->pvq_speed, |
| 689 | pvq_info); // PVQ info for a block |
| 690 | skip = ac_dc_coded == PVQ_SKIP; |
ltrudeau | 472f63f | 2017-01-12 15:22:32 -0500 | [diff] [blame] | 691 | } |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 692 | x->pvq_skip[plane] = skip; |
| 693 | |
| 694 | if (!skip) mbmi->skip = 0; |
| 695 | #endif // #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 698 | static void encode_block(int plane, int block, int blk_row, int blk_col, |
| 699 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg) { |
| 700 | struct encode_b_args *const args = arg; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 701 | AV1_COMMON *cm = args->cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | MACROBLOCK *const x = args->x; |
| 703 | MACROBLOCKD *const xd = &x->e_mbd; |
| 704 | int ctx; |
| 705 | struct macroblock_plane *const p = &x->plane[plane]; |
| 706 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 707 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 708 | uint8_t *dst; |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 709 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 710 | ENTROPY_CONTEXT *a, *l; |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 711 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 712 | #if CONFIG_VAR_TX |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 713 | int bw = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 714 | #endif |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 715 | dst = &pd->dst |
| 716 | .buf[(blk_row * pd->dst.stride + blk_col) << tx_size_wide_log2[0]]; |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 717 | |
| 718 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 719 | a = &args->ta[blk_col]; |
| 720 | l = &args->tl[blk_row]; |
| 721 | #if CONFIG_VAR_TX |
| 722 | ctx = get_entropy_context(tx_size, a, l); |
| 723 | #else |
| 724 | ctx = combine_entropy_contexts(*a, *l); |
| 725 | #endif |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 726 | #else |
| 727 | ctx = 0; |
| 728 | #endif // CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 729 | |
| 730 | #if CONFIG_VAR_TX |
Yue Chen | a1e48dc | 2016-08-29 17:29:33 -0700 | [diff] [blame] | 731 | // Assert not magic number (uninitialized). |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 732 | assert(x->blk_skip[plane][blk_row * bw + blk_col] != 234); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 733 | |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 734 | if (x->blk_skip[plane][blk_row * bw + blk_col] == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | #else |
| 736 | { |
| 737 | #endif |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 738 | av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 739 | ctx, AV1_XFORM_QUANT_FP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 740 | } |
| 741 | #if CONFIG_VAR_TX |
| 742 | else { |
| 743 | p->eobs[block] = 0; |
| 744 | } |
| 745 | #endif |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 746 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 747 | #if !CONFIG_PVQ |
Jingning Han | 7eab9ff | 2017-07-06 10:12:54 -0700 | [diff] [blame] | 748 | av1_optimize_b(cm, x, plane, blk_row, blk_col, block, plane_bsize, tx_size, a, |
| 749 | l); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 750 | |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 751 | av1_set_txb_context(x, plane, block, tx_size, a, l); |
| 752 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 753 | if (p->eobs[block]) *(args->skip) = 0; |
| 754 | |
| 755 | if (p->eobs[block] == 0) return; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 756 | #else |
| 757 | (void)ctx; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 758 | if (!x->pvq_skip[plane]) *(args->skip) = 0; |
| 759 | |
| 760 | if (x->pvq_skip[plane]) return; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 761 | #endif |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 762 | TX_TYPE tx_type = |
| 763 | av1_get_tx_type(pd->plane_type, xd, blk_row, blk_col, block, tx_size); |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 764 | #if CONFIG_LGT |
| 765 | PREDICTION_MODE mode = get_prediction_mode(xd->mi[0], plane, tx_size, block); |
| 766 | av1_inverse_transform_block(xd, dqcoeff, mode, tx_type, tx_size, dst, |
| 767 | pd->dst.stride, p->eobs[block]); |
| 768 | #else |
Angie Chiang | 44d7e66 | 2017-04-06 11:07:53 -0700 | [diff] [blame] | 769 | av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, |
| 770 | pd->dst.stride, p->eobs[block]); |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 771 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | #if CONFIG_VAR_TX |
| 775 | static void encode_block_inter(int plane, int block, int blk_row, int blk_col, |
| 776 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 777 | void *arg) { |
| 778 | struct encode_b_args *const args = arg; |
| 779 | MACROBLOCK *const x = args->x; |
| 780 | MACROBLOCKD *const xd = &x->e_mbd; |
| 781 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 782 | const BLOCK_SIZE bsize = txsize_to_bsize[tx_size]; |
| 783 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 784 | const int tx_row = blk_row >> (1 - pd->subsampling_y); |
| 785 | const int tx_col = blk_col >> (1 - pd->subsampling_x); |
| 786 | TX_SIZE plane_tx_size; |
Jingning Han | f65b870 | 2016-10-31 12:13:20 -0700 | [diff] [blame] | 787 | const int max_blocks_high = max_block_high(xd, plane_bsize, plane); |
| 788 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 789 | |
| 790 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 791 | |
Debargha Mukherjee | 2f12340 | 2016-08-30 17:43:38 -0700 | [diff] [blame] | 792 | plane_tx_size = |
| 793 | plane ? uv_txsize_lookup[bsize][mbmi->inter_tx_size[tx_row][tx_col]][0][0] |
| 794 | : mbmi->inter_tx_size[tx_row][tx_col]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 795 | |
| 796 | if (tx_size == plane_tx_size) { |
| 797 | encode_block(plane, block, blk_row, blk_col, plane_bsize, tx_size, arg); |
| 798 | } else { |
Alex Converse | e16b266 | 2017-05-24 14:00:00 -0700 | [diff] [blame] | 799 | assert(tx_size < TX_SIZES_ALL); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 800 | #if CONFIG_RECT_TX_EXT |
| 801 | int is_qttx = plane_tx_size == quarter_txsize_lookup[plane_bsize]; |
| 802 | const TX_SIZE sub_txs = is_qttx ? plane_tx_size : sub_tx_size_map[tx_size]; |
| 803 | if (is_qttx) assert(blk_row == 0 && blk_col == 0 && block == 0); |
| 804 | #else |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 805 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
Alex Converse | e16b266 | 2017-05-24 14:00:00 -0700 | [diff] [blame] | 806 | assert(sub_txs < tx_size); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 807 | #endif |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 808 | // This is the square transform block partition entry point. |
| 809 | int bsl = tx_size_wide_unit[sub_txs]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 810 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 811 | assert(bsl > 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 812 | |
| 813 | for (i = 0; i < 4; ++i) { |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 814 | #if CONFIG_RECT_TX_EXT |
| 815 | int is_wide_tx = tx_size_wide_unit[sub_txs] > tx_size_high_unit[sub_txs]; |
| 816 | const int offsetr = |
| 817 | is_qttx ? (is_wide_tx ? i * tx_size_high_unit[sub_txs] : 0) |
| 818 | : blk_row + ((i >> 1) * bsl); |
| 819 | const int offsetc = |
| 820 | is_qttx ? (is_wide_tx ? 0 : i * tx_size_wide_unit[sub_txs]) |
| 821 | : blk_col + ((i & 0x01) * bsl); |
| 822 | #else |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 823 | const int offsetr = blk_row + ((i >> 1) * bsl); |
| 824 | const int offsetc = blk_col + ((i & 0x01) * bsl); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 825 | #endif |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 826 | int step = tx_size_wide_unit[sub_txs] * tx_size_high_unit[sub_txs]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 827 | |
| 828 | if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; |
| 829 | |
Jingning Han | 98d6a1f | 2016-11-03 12:47:47 -0700 | [diff] [blame] | 830 | encode_block_inter(plane, block, offsetr, offsetc, plane_bsize, sub_txs, |
| 831 | arg); |
| 832 | block += step; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | } |
| 836 | #endif |
| 837 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 838 | typedef struct encode_block_pass1_args { |
| 839 | AV1_COMMON *cm; |
| 840 | MACROBLOCK *x; |
| 841 | } encode_block_pass1_args; |
| 842 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 843 | static void encode_block_pass1(int plane, int block, int blk_row, int blk_col, |
| 844 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 845 | void *arg) { |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 846 | encode_block_pass1_args *args = (encode_block_pass1_args *)arg; |
| 847 | AV1_COMMON *cm = args->cm; |
| 848 | MACROBLOCK *const x = args->x; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | MACROBLOCKD *const xd = &x->e_mbd; |
| 850 | struct macroblock_plane *const p = &x->plane[plane]; |
| 851 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 852 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 853 | TxfmParam txfm_param; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 854 | uint8_t *dst; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 855 | int ctx = 0; |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 856 | dst = &pd->dst |
| 857 | .buf[(blk_row * pd->dst.stride + blk_col) << tx_size_wide_log2[0]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 858 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 859 | av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 860 | ctx, AV1_XFORM_QUANT_B); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 861 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 862 | if (p->eobs[block] > 0) { |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 863 | #else |
| 864 | if (!x->pvq_skip[plane]) { |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 865 | { |
| 866 | int tx_blk_size; |
| 867 | int i, j; |
| 868 | // transform block size in pixels |
| 869 | tx_blk_size = tx_size_wide[tx_size]; |
| 870 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 871 | // Since av1 does not have separate function which does inverse transform |
| 872 | // but av1_inv_txfm_add_*x*() also does addition of predicted image to |
| 873 | // inverse transformed image, |
| 874 | // pass blank dummy image to av1_inv_txfm_add_*x*(), i.e. set dst as zeros |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 875 | #if CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 876 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 877 | for (j = 0; j < tx_blk_size; j++) |
| 878 | for (i = 0; i < tx_blk_size; i++) |
| 879 | CONVERT_TO_SHORTPTR(dst)[j * pd->dst.stride + i] = 0; |
| 880 | } else { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 881 | #endif // CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 882 | for (j = 0; j < tx_blk_size; j++) |
| 883 | for (i = 0; i < tx_blk_size; i++) dst[j * pd->dst.stride + i] = 0; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 884 | #if CONFIG_HIGHBITDEPTH |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 885 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 886 | #endif // CONFIG_HIGHBITDEPTH |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 887 | } |
Jingning Han | df07264 | 2016-11-08 16:43:38 -0800 | [diff] [blame] | 888 | #endif // !CONFIG_PVQ |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 889 | txfm_param.bd = xd->bd; |
| 890 | txfm_param.tx_type = DCT_DCT; |
| 891 | txfm_param.eob = p->eobs[block]; |
| 892 | txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id]; |
Monty Montgomery | 554d2c3 | 2017-07-11 21:01:07 -0400 | [diff] [blame] | 893 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 894 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 895 | av1_highbd_inv_txfm_add_4x4(dqcoeff, dst, pd->dst.stride, &txfm_param); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 896 | return; |
| 897 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 898 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 899 | if (xd->lossless[xd->mi[0]->mbmi.segment_id]) { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 900 | av1_iwht4x4_add(dqcoeff, dst, pd->dst.stride, &txfm_param); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 901 | } else { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 902 | av1_idct4x4_add(dqcoeff, dst, pd->dst.stride, &txfm_param); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 907 | void av1_encode_sby_pass1(AV1_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE bsize) { |
| 908 | encode_block_pass1_args args = { cm, x }; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 909 | av1_subtract_plane(x, bsize, 0); |
| 910 | av1_foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0, |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 911 | encode_block_pass1, &args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Yaowu Xu | 1e4e5b9 | 2017-05-05 11:06:42 -0700 | [diff] [blame] | 914 | void av1_encode_sb(AV1_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row, |
| 915 | int mi_col) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | MACROBLOCKD *const xd = &x->e_mbd; |
| 917 | struct optimize_ctx ctx; |
| 918 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 919 | struct encode_b_args arg = { cm, x, &ctx, &mbmi->skip, NULL, NULL, 1 }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 920 | int plane; |
| 921 | |
| 922 | mbmi->skip = 1; |
| 923 | |
| 924 | if (x->skip) return; |
| 925 | |
| 926 | for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
Jingning Han | 31b6a4f | 2017-02-23 11:05:53 -0800 | [diff] [blame] | 927 | #if CONFIG_CB4X4 && !CONFIG_CHROMA_2X2 |
Jingning Han | 2d2dac2 | 2017-04-11 09:41:10 -0700 | [diff] [blame] | 928 | const int subsampling_x = xd->plane[plane].subsampling_x; |
| 929 | const int subsampling_y = xd->plane[plane].subsampling_y; |
| 930 | |
| 931 | if (!is_chroma_reference(mi_row, mi_col, bsize, subsampling_x, |
| 932 | subsampling_y)) |
Jingning Han | ea576f3 | 2017-02-21 23:05:09 -0800 | [diff] [blame] | 933 | continue; |
Jingning Han | 2d2dac2 | 2017-04-11 09:41:10 -0700 | [diff] [blame] | 934 | |
| 935 | bsize = scale_chroma_bsize(bsize, subsampling_x, subsampling_y); |
Jingning Han | ea576f3 | 2017-02-21 23:05:09 -0800 | [diff] [blame] | 936 | #else |
| 937 | (void)mi_row; |
| 938 | (void)mi_col; |
| 939 | #endif |
| 940 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 941 | #if CONFIG_VAR_TX |
| 942 | // TODO(jingning): Clean this up. |
| 943 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 944 | const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 945 | const int mi_width = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
| 946 | const int mi_height = block_size_high[plane_bsize] >> tx_size_wide_log2[0]; |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 947 | const TX_SIZE max_tx_size = get_vartx_max_txsize(mbmi, plane_bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 948 | const BLOCK_SIZE txb_size = txsize_to_bsize[max_tx_size]; |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 949 | const int bw = block_size_wide[txb_size] >> tx_size_wide_log2[0]; |
| 950 | const int bh = block_size_high[txb_size] >> tx_size_wide_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | int idx, idy; |
| 952 | int block = 0; |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 953 | int step = tx_size_wide_unit[max_tx_size] * tx_size_high_unit[max_tx_size]; |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 954 | av1_get_entropy_contexts(bsize, 0, pd, ctx.ta[plane], ctx.tl[plane]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 955 | #else |
| 956 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 957 | const TX_SIZE tx_size = av1_get_tx_size(plane, xd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 958 | av1_get_entropy_contexts(bsize, tx_size, pd, ctx.ta[plane], ctx.tl[plane]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 959 | #endif |
Jingning Han | ea576f3 | 2017-02-21 23:05:09 -0800 | [diff] [blame] | 960 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 961 | #if !CONFIG_PVQ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 962 | av1_subtract_plane(x, bsize, plane); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 963 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 964 | arg.ta = ctx.ta[plane]; |
| 965 | arg.tl = ctx.tl[plane]; |
| 966 | |
| 967 | #if CONFIG_VAR_TX |
Jingning Han | c2b797f | 2017-07-19 09:37:11 -0700 | [diff] [blame] | 968 | const BLOCK_SIZE max_unit_bsize = get_plane_block_size(BLOCK_64X64, pd); |
| 969 | int mu_blocks_wide = |
| 970 | block_size_wide[max_unit_bsize] >> tx_size_wide_log2[0]; |
| 971 | int mu_blocks_high = |
| 972 | block_size_high[max_unit_bsize] >> tx_size_high_log2[0]; |
| 973 | |
| 974 | mu_blocks_wide = AOMMIN(mi_width, mu_blocks_wide); |
| 975 | mu_blocks_high = AOMMIN(mi_height, mu_blocks_high); |
| 976 | |
| 977 | for (idy = 0; idy < mi_height; idy += mu_blocks_high) { |
| 978 | for (idx = 0; idx < mi_width; idx += mu_blocks_wide) { |
| 979 | int blk_row, blk_col; |
| 980 | const int unit_height = AOMMIN(mu_blocks_high + idy, mi_height); |
| 981 | const int unit_width = AOMMIN(mu_blocks_wide + idx, mi_width); |
| 982 | for (blk_row = idy; blk_row < unit_height; blk_row += bh) { |
| 983 | for (blk_col = idx; blk_col < unit_width; blk_col += bw) { |
| 984 | encode_block_inter(plane, block, blk_row, blk_col, plane_bsize, |
| 985 | max_tx_size, &arg); |
| 986 | block += step; |
| 987 | } |
| 988 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 989 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 990 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 991 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 992 | av1_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block, |
| 993 | &arg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 994 | #endif |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | #if CONFIG_SUPERTX |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 999 | void av1_encode_sb_supertx(AV1_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE bsize) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1000 | MACROBLOCKD *const xd = &x->e_mbd; |
| 1001 | struct optimize_ctx ctx; |
| 1002 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1003 | struct encode_b_args arg = { cm, x, &ctx, &mbmi->skip, NULL, NULL, 1 }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1004 | int plane; |
| 1005 | |
| 1006 | mbmi->skip = 1; |
| 1007 | if (x->skip) return; |
| 1008 | |
| 1009 | for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
| 1010 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1011 | #if CONFIG_VAR_TX |
| 1012 | const TX_SIZE tx_size = TX_4X4; |
| 1013 | #else |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1014 | const TX_SIZE tx_size = av1_get_tx_size(plane, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1015 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1016 | av1_subtract_plane(x, bsize, plane); |
| 1017 | av1_get_entropy_contexts(bsize, tx_size, pd, ctx.ta[plane], ctx.tl[plane]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1018 | arg.ta = ctx.ta[plane]; |
| 1019 | arg.tl = ctx.tl[plane]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1020 | av1_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block, |
| 1021 | &arg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | #endif // CONFIG_SUPERTX |
| 1025 | |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1026 | #if !CONFIG_PVQ |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 1027 | void av1_set_txb_context(MACROBLOCK *x, int plane, int block, TX_SIZE tx_size, |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1028 | ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l) { |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1029 | (void)tx_size; |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1030 | struct macroblock_plane *p = &x->plane[plane]; |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1031 | |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 1032 | #if !CONFIG_LV_MAP |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1033 | *a = *l = p->eobs[block] > 0; |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 1034 | #else // !CONFIG_LV_MAP |
| 1035 | *a = *l = p->txb_entropy_ctx[block]; |
| 1036 | #endif // !CONFIG_LV_MAP |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 1037 | |
| 1038 | #if CONFIG_VAR_TX || CONFIG_LV_MAP |
| 1039 | int i; |
| 1040 | for (i = 0; i < tx_size_wide_unit[tx_size]; ++i) a[i] = a[0]; |
| 1041 | |
| 1042 | for (i = 0; i < tx_size_high_unit[tx_size]; ++i) l[i] = l[0]; |
| 1043 | #endif |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1044 | } |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1045 | #endif |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1046 | |
| 1047 | static void encode_block_intra_and_set_context(int plane, int block, |
| 1048 | int blk_row, int blk_col, |
| 1049 | BLOCK_SIZE plane_bsize, |
| 1050 | TX_SIZE tx_size, void *arg) { |
| 1051 | av1_encode_block_intra(plane, block, blk_row, blk_col, plane_bsize, tx_size, |
| 1052 | arg); |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1053 | #if !CONFIG_PVQ |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1054 | struct encode_b_args *const args = arg; |
| 1055 | MACROBLOCK *x = args->x; |
| 1056 | ENTROPY_CONTEXT *a = &args->ta[blk_col]; |
| 1057 | ENTROPY_CONTEXT *l = &args->tl[blk_row]; |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 1058 | av1_set_txb_context(x, plane, block, tx_size, a, l); |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1059 | #endif |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1062 | #if CONFIG_DPCM_INTRA |
| 1063 | static int get_eob(const tran_low_t *qcoeff, intptr_t n_coeffs, |
| 1064 | const int16_t *scan) { |
| 1065 | int eob = -1; |
| 1066 | for (int i = (int)n_coeffs - 1; i >= 0; i--) { |
| 1067 | const int rc = scan[i]; |
| 1068 | if (qcoeff[rc]) { |
| 1069 | eob = i; |
| 1070 | break; |
| 1071 | } |
| 1072 | } |
| 1073 | return eob + 1; |
| 1074 | } |
| 1075 | |
| 1076 | static void quantize_scaler(int coeff, int16_t zbin, int16_t round_value, |
| 1077 | int16_t quant, int16_t quant_shift, int16_t dequant, |
| 1078 | int log_scale, tran_low_t *const qcoeff, |
| 1079 | tran_low_t *const dqcoeff) { |
| 1080 | zbin = ROUND_POWER_OF_TWO(zbin, log_scale); |
| 1081 | round_value = ROUND_POWER_OF_TWO(round_value, log_scale); |
| 1082 | const int coeff_sign = (coeff >> 31); |
| 1083 | const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |
| 1084 | if (abs_coeff >= zbin) { |
| 1085 | int tmp = clamp(abs_coeff + round_value, INT16_MIN, INT16_MAX); |
| 1086 | tmp = ((((tmp * quant) >> 16) + tmp) * quant_shift) >> (16 - log_scale); |
| 1087 | *qcoeff = (tmp ^ coeff_sign) - coeff_sign; |
| 1088 | *dqcoeff = (*qcoeff * dequant) / (1 << log_scale); |
| 1089 | } |
| 1090 | } |
| 1091 | |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 1092 | #if CONFIG_HIGHBITDEPTH |
| 1093 | typedef void (*hbd_dpcm_fwd_tx_func)(const int16_t *input, int stride, |
| 1094 | TX_TYPE_1D tx_type, tran_low_t *output, |
| 1095 | int dir); |
| 1096 | |
| 1097 | static hbd_dpcm_fwd_tx_func get_hbd_dpcm_fwd_tx_func(int tx_length) { |
| 1098 | switch (tx_length) { |
| 1099 | case 4: return av1_hbd_dpcm_ft4_c; |
| 1100 | case 8: return av1_hbd_dpcm_ft8_c; |
| 1101 | case 16: return av1_hbd_dpcm_ft16_c; |
| 1102 | case 32: |
| 1103 | return av1_hbd_dpcm_ft32_c; |
| 1104 | // TODO(huisu): add support for TX_64X64. |
| 1105 | default: assert(0); return NULL; |
| 1106 | } |
| 1107 | } |
| 1108 | #endif // CONFIG_HIGHBITDEPTH |
| 1109 | |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1110 | typedef void (*dpcm_fwd_tx_func)(const int16_t *input, int stride, |
| 1111 | TX_TYPE_1D tx_type, tran_low_t *output); |
| 1112 | |
| 1113 | static dpcm_fwd_tx_func get_dpcm_fwd_tx_func(int tx_length) { |
| 1114 | switch (tx_length) { |
| 1115 | case 4: return av1_dpcm_ft4_c; |
| 1116 | case 8: return av1_dpcm_ft8_c; |
| 1117 | case 16: return av1_dpcm_ft16_c; |
| 1118 | case 32: |
| 1119 | return av1_dpcm_ft32_c; |
| 1120 | // TODO(huisu): add support for TX_64X64. |
| 1121 | default: assert(0); return NULL; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | static void process_block_dpcm_vert(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d, |
| 1126 | struct macroblockd_plane *const pd, |
| 1127 | struct macroblock_plane *const p, |
| 1128 | uint8_t *src, int src_stride, uint8_t *dst, |
| 1129 | int dst_stride, int16_t *src_diff, |
| 1130 | int diff_stride, tran_low_t *coeff, |
| 1131 | tran_low_t *qcoeff, tran_low_t *dqcoeff) { |
| 1132 | const int tx1d_width = tx_size_wide[tx_size]; |
| 1133 | dpcm_fwd_tx_func forward_tx = get_dpcm_fwd_tx_func(tx1d_width); |
| 1134 | dpcm_inv_txfm_add_func inverse_tx = |
| 1135 | av1_get_dpcm_inv_txfm_add_func(tx1d_width); |
| 1136 | const int tx1d_height = tx_size_high[tx_size]; |
| 1137 | const int log_scale = av1_get_tx_scale(tx_size); |
| 1138 | int q_idx = 0; |
| 1139 | for (int r = 0; r < tx1d_height; ++r) { |
| 1140 | // Update prediction. |
| 1141 | if (r > 0) memcpy(dst, dst - dst_stride, tx1d_width * sizeof(dst[0])); |
| 1142 | // Subtraction. |
| 1143 | for (int c = 0; c < tx1d_width; ++c) src_diff[c] = src[c] - dst[c]; |
| 1144 | // Forward transform. |
| 1145 | forward_tx(src_diff, 1, tx_type_1d, coeff); |
| 1146 | // Quantization. |
| 1147 | for (int c = 0; c < tx1d_width; ++c) { |
| 1148 | quantize_scaler(coeff[c], p->zbin[q_idx], p->round[q_idx], |
| 1149 | p->quant[q_idx], p->quant_shift[q_idx], |
| 1150 | pd->dequant[q_idx], log_scale, &qcoeff[c], &dqcoeff[c]); |
| 1151 | q_idx = 1; |
| 1152 | } |
| 1153 | // Inverse transform. |
| 1154 | inverse_tx(dqcoeff, 1, tx_type_1d, dst); |
| 1155 | // Move to the next row. |
| 1156 | coeff += tx1d_width; |
| 1157 | qcoeff += tx1d_width; |
| 1158 | dqcoeff += tx1d_width; |
| 1159 | src_diff += diff_stride; |
| 1160 | dst += dst_stride; |
| 1161 | src += src_stride; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | static void process_block_dpcm_horz(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d, |
| 1166 | struct macroblockd_plane *const pd, |
| 1167 | struct macroblock_plane *const p, |
| 1168 | uint8_t *src, int src_stride, uint8_t *dst, |
| 1169 | int dst_stride, int16_t *src_diff, |
| 1170 | int diff_stride, tran_low_t *coeff, |
| 1171 | tran_low_t *qcoeff, tran_low_t *dqcoeff) { |
| 1172 | const int tx1d_height = tx_size_high[tx_size]; |
| 1173 | dpcm_fwd_tx_func forward_tx = get_dpcm_fwd_tx_func(tx1d_height); |
| 1174 | dpcm_inv_txfm_add_func inverse_tx = |
| 1175 | av1_get_dpcm_inv_txfm_add_func(tx1d_height); |
| 1176 | const int tx1d_width = tx_size_wide[tx_size]; |
| 1177 | const int log_scale = av1_get_tx_scale(tx_size); |
| 1178 | int q_idx = 0; |
| 1179 | for (int c = 0; c < tx1d_width; ++c) { |
| 1180 | for (int r = 0; r < tx1d_height; ++r) { |
| 1181 | // Update prediction. |
| 1182 | if (c > 0) dst[r * dst_stride] = dst[r * dst_stride - 1]; |
| 1183 | // Subtraction. |
| 1184 | src_diff[r * diff_stride] = src[r * src_stride] - dst[r * dst_stride]; |
| 1185 | } |
| 1186 | // Forward transform. |
| 1187 | tran_low_t tx_buff[64]; |
| 1188 | forward_tx(src_diff, diff_stride, tx_type_1d, tx_buff); |
| 1189 | for (int r = 0; r < tx1d_height; ++r) coeff[r * tx1d_width] = tx_buff[r]; |
| 1190 | // Quantization. |
| 1191 | for (int r = 0; r < tx1d_height; ++r) { |
| 1192 | quantize_scaler(coeff[r * tx1d_width], p->zbin[q_idx], p->round[q_idx], |
| 1193 | p->quant[q_idx], p->quant_shift[q_idx], |
| 1194 | pd->dequant[q_idx], log_scale, &qcoeff[r * tx1d_width], |
| 1195 | &dqcoeff[r * tx1d_width]); |
| 1196 | q_idx = 1; |
| 1197 | } |
| 1198 | // Inverse transform. |
| 1199 | for (int r = 0; r < tx1d_height; ++r) tx_buff[r] = dqcoeff[r * tx1d_width]; |
| 1200 | inverse_tx(tx_buff, dst_stride, tx_type_1d, dst); |
| 1201 | // Move to the next column. |
| 1202 | ++coeff, ++qcoeff, ++dqcoeff, ++src_diff, ++dst, ++src; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | #if CONFIG_HIGHBITDEPTH |
| 1207 | static void hbd_process_block_dpcm_vert( |
| 1208 | TX_SIZE tx_size, TX_TYPE_1D tx_type_1d, int bd, |
| 1209 | struct macroblockd_plane *const pd, struct macroblock_plane *const p, |
| 1210 | uint8_t *src8, int src_stride, uint8_t *dst8, int dst_stride, |
| 1211 | int16_t *src_diff, int diff_stride, tran_low_t *coeff, tran_low_t *qcoeff, |
| 1212 | tran_low_t *dqcoeff) { |
| 1213 | const int tx1d_width = tx_size_wide[tx_size]; |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 1214 | hbd_dpcm_fwd_tx_func forward_tx = get_hbd_dpcm_fwd_tx_func(tx1d_width); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1215 | hbd_dpcm_inv_txfm_add_func inverse_tx = |
| 1216 | av1_get_hbd_dpcm_inv_txfm_add_func(tx1d_width); |
| 1217 | uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
| 1218 | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
| 1219 | const int tx1d_height = tx_size_high[tx_size]; |
| 1220 | const int log_scale = av1_get_tx_scale(tx_size); |
| 1221 | int q_idx = 0; |
| 1222 | for (int r = 0; r < tx1d_height; ++r) { |
| 1223 | // Update prediction. |
| 1224 | if (r > 0) memcpy(dst, dst - dst_stride, tx1d_width * sizeof(dst[0])); |
| 1225 | // Subtraction. |
| 1226 | for (int c = 0; c < tx1d_width; ++c) src_diff[c] = src[c] - dst[c]; |
| 1227 | // Forward transform. |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 1228 | forward_tx(src_diff, 1, tx_type_1d, coeff, 1); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1229 | // Quantization. |
| 1230 | for (int c = 0; c < tx1d_width; ++c) { |
| 1231 | quantize_scaler(coeff[c], p->zbin[q_idx], p->round[q_idx], |
| 1232 | p->quant[q_idx], p->quant_shift[q_idx], |
| 1233 | pd->dequant[q_idx], log_scale, &qcoeff[c], &dqcoeff[c]); |
| 1234 | q_idx = 1; |
| 1235 | } |
| 1236 | // Inverse transform. |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 1237 | inverse_tx(dqcoeff, 1, tx_type_1d, bd, dst, 1); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1238 | // Move to the next row. |
| 1239 | coeff += tx1d_width; |
| 1240 | qcoeff += tx1d_width; |
| 1241 | dqcoeff += tx1d_width; |
| 1242 | src_diff += diff_stride; |
| 1243 | dst += dst_stride; |
| 1244 | src += src_stride; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | static void hbd_process_block_dpcm_horz( |
| 1249 | TX_SIZE tx_size, TX_TYPE_1D tx_type_1d, int bd, |
| 1250 | struct macroblockd_plane *const pd, struct macroblock_plane *const p, |
| 1251 | uint8_t *src8, int src_stride, uint8_t *dst8, int dst_stride, |
| 1252 | int16_t *src_diff, int diff_stride, tran_low_t *coeff, tran_low_t *qcoeff, |
| 1253 | tran_low_t *dqcoeff) { |
| 1254 | const int tx1d_height = tx_size_high[tx_size]; |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 1255 | hbd_dpcm_fwd_tx_func forward_tx = get_hbd_dpcm_fwd_tx_func(tx1d_height); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1256 | hbd_dpcm_inv_txfm_add_func inverse_tx = |
| 1257 | av1_get_hbd_dpcm_inv_txfm_add_func(tx1d_height); |
| 1258 | uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
| 1259 | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
| 1260 | const int tx1d_width = tx_size_wide[tx_size]; |
| 1261 | const int log_scale = av1_get_tx_scale(tx_size); |
| 1262 | int q_idx = 0; |
| 1263 | for (int c = 0; c < tx1d_width; ++c) { |
| 1264 | for (int r = 0; r < tx1d_height; ++r) { |
| 1265 | // Update prediction. |
| 1266 | if (c > 0) dst[r * dst_stride] = dst[r * dst_stride - 1]; |
| 1267 | // Subtraction. |
| 1268 | src_diff[r * diff_stride] = src[r * src_stride] - dst[r * dst_stride]; |
| 1269 | } |
| 1270 | // Forward transform. |
| 1271 | tran_low_t tx_buff[64]; |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 1272 | forward_tx(src_diff, diff_stride, tx_type_1d, tx_buff, 0); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1273 | for (int r = 0; r < tx1d_height; ++r) coeff[r * tx1d_width] = tx_buff[r]; |
| 1274 | // Quantization. |
| 1275 | for (int r = 0; r < tx1d_height; ++r) { |
| 1276 | quantize_scaler(coeff[r * tx1d_width], p->zbin[q_idx], p->round[q_idx], |
| 1277 | p->quant[q_idx], p->quant_shift[q_idx], |
| 1278 | pd->dequant[q_idx], log_scale, &qcoeff[r * tx1d_width], |
| 1279 | &dqcoeff[r * tx1d_width]); |
| 1280 | q_idx = 1; |
| 1281 | } |
| 1282 | // Inverse transform. |
| 1283 | for (int r = 0; r < tx1d_height; ++r) tx_buff[r] = dqcoeff[r * tx1d_width]; |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 1284 | inverse_tx(tx_buff, dst_stride, tx_type_1d, bd, dst, 0); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1285 | // Move to the next column. |
| 1286 | ++coeff, ++qcoeff, ++dqcoeff, ++src_diff, ++dst, ++src; |
| 1287 | } |
| 1288 | } |
| 1289 | #endif // CONFIG_HIGHBITDEPTH |
| 1290 | |
| 1291 | void av1_encode_block_intra_dpcm(const AV1_COMMON *cm, MACROBLOCK *x, |
| 1292 | PREDICTION_MODE mode, int plane, int block, |
| 1293 | int blk_row, int blk_col, |
| 1294 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 1295 | TX_TYPE tx_type, ENTROPY_CONTEXT *ta, |
| 1296 | ENTROPY_CONTEXT *tl, int8_t *skip) { |
| 1297 | MACROBLOCKD *const xd = &x->e_mbd; |
| 1298 | struct macroblock_plane *const p = &x->plane[plane]; |
| 1299 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1300 | tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 1301 | const int diff_stride = block_size_wide[plane_bsize]; |
| 1302 | const int src_stride = p->src.stride; |
| 1303 | const int dst_stride = pd->dst.stride; |
| 1304 | const int tx1d_width = tx_size_wide[tx_size]; |
| 1305 | const int tx1d_height = tx_size_high[tx_size]; |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 1306 | const SCAN_ORDER *const scan_order = |
| 1307 | get_scan(cm, tx_size, tx_type, &xd->mi[0]->mbmi); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1308 | tran_low_t *coeff = BLOCK_OFFSET(p->coeff, block); |
| 1309 | tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 1310 | uint8_t *dst = |
| 1311 | &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]]; |
| 1312 | uint8_t *src = |
| 1313 | &p->src.buf[(blk_row * src_stride + blk_col) << tx_size_wide_log2[0]]; |
| 1314 | int16_t *src_diff = |
| 1315 | &p->src_diff[(blk_row * diff_stride + blk_col) << tx_size_wide_log2[0]]; |
| 1316 | uint16_t *eob = &p->eobs[block]; |
| 1317 | *eob = 0; |
| 1318 | memset(qcoeff, 0, tx1d_height * tx1d_width * sizeof(*qcoeff)); |
| 1319 | memset(dqcoeff, 0, tx1d_height * tx1d_width * sizeof(*dqcoeff)); |
| 1320 | |
| 1321 | if (LIKELY(!x->skip_block)) { |
| 1322 | TX_TYPE_1D tx_type_1d = DCT_1D; |
| 1323 | switch (tx_type) { |
| 1324 | case IDTX: tx_type_1d = IDTX_1D; break; |
| 1325 | case V_DCT: |
| 1326 | assert(mode == H_PRED); |
| 1327 | tx_type_1d = DCT_1D; |
| 1328 | break; |
| 1329 | case H_DCT: |
| 1330 | assert(mode == V_PRED); |
| 1331 | tx_type_1d = DCT_1D; |
| 1332 | break; |
| 1333 | default: assert(0); |
| 1334 | } |
| 1335 | switch (mode) { |
| 1336 | case V_PRED: |
| 1337 | #if CONFIG_HIGHBITDEPTH |
| 1338 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1339 | hbd_process_block_dpcm_vert(tx_size, tx_type_1d, xd->bd, pd, p, src, |
| 1340 | src_stride, dst, dst_stride, src_diff, |
| 1341 | diff_stride, coeff, qcoeff, dqcoeff); |
| 1342 | } else { |
| 1343 | #endif // CONFIG_HIGHBITDEPTH |
| 1344 | process_block_dpcm_vert(tx_size, tx_type_1d, pd, p, src, src_stride, |
| 1345 | dst, dst_stride, src_diff, diff_stride, coeff, |
| 1346 | qcoeff, dqcoeff); |
| 1347 | #if CONFIG_HIGHBITDEPTH |
| 1348 | } |
| 1349 | #endif // CONFIG_HIGHBITDEPTH |
| 1350 | break; |
| 1351 | case H_PRED: |
| 1352 | #if CONFIG_HIGHBITDEPTH |
| 1353 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1354 | hbd_process_block_dpcm_horz(tx_size, tx_type_1d, xd->bd, pd, p, src, |
| 1355 | src_stride, dst, dst_stride, src_diff, |
| 1356 | diff_stride, coeff, qcoeff, dqcoeff); |
| 1357 | } else { |
| 1358 | #endif // CONFIG_HIGHBITDEPTH |
| 1359 | process_block_dpcm_horz(tx_size, tx_type_1d, pd, p, src, src_stride, |
| 1360 | dst, dst_stride, src_diff, diff_stride, coeff, |
| 1361 | qcoeff, dqcoeff); |
| 1362 | #if CONFIG_HIGHBITDEPTH |
| 1363 | } |
| 1364 | #endif // CONFIG_HIGHBITDEPTH |
| 1365 | break; |
| 1366 | default: assert(0); |
| 1367 | } |
| 1368 | *eob = get_eob(qcoeff, tx1d_height * tx1d_width, scan_order->scan); |
| 1369 | } |
| 1370 | |
| 1371 | ta[blk_col] = tl[blk_row] = *eob > 0; |
| 1372 | if (*eob) *skip = 0; |
| 1373 | } |
| 1374 | #endif // CONFIG_DPCM_INTRA |
| 1375 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1376 | void av1_encode_block_intra(int plane, int block, int blk_row, int blk_col, |
| 1377 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 1378 | void *arg) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1379 | struct encode_b_args *const args = arg; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1380 | AV1_COMMON *cm = args->cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1381 | MACROBLOCK *const x = args->x; |
| 1382 | MACROBLOCKD *const xd = &x->e_mbd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1383 | struct macroblock_plane *const p = &x->plane[plane]; |
| 1384 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1385 | tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 1386 | PLANE_TYPE plane_type = get_plane_type(plane); |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1387 | const TX_TYPE tx_type = |
| 1388 | av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1389 | uint16_t *eob = &p->eobs[block]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1390 | const int dst_stride = pd->dst.stride; |
Angie Chiang | f87e43f | 2017-04-02 16:51:19 -0700 | [diff] [blame] | 1391 | uint8_t *dst = |
| 1392 | &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]]; |
Luc Trudeau | e8dfbcf | 2017-05-12 09:57:50 -0400 | [diff] [blame] | 1393 | |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1394 | av1_predict_intra_block_facade(xd, plane, block, blk_col, blk_row, tx_size); |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1395 | |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 1396 | #if CONFIG_DPCM_INTRA || CONFIG_LGT |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1397 | const PREDICTION_MODE mode = |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 1398 | get_prediction_mode(xd->mi[0], plane, tx_size, block); |
| 1399 | #if CONFIG_DPCM_INTRA |
| 1400 | const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1401 | if (av1_use_dpcm_intra(plane, mode, tx_type, mbmi)) { |
| 1402 | av1_encode_block_intra_dpcm(cm, x, mode, plane, block, blk_row, blk_col, |
| 1403 | plane_bsize, tx_size, tx_type, args->ta, |
| 1404 | args->tl, args->skip); |
| 1405 | return; |
| 1406 | } |
| 1407 | #endif // CONFIG_DPCM_INTRA |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 1408 | #endif // CONFIG_DPCM_INTRA || CONFIG_LGT |
hui su | b8a6fd6 | 2017-05-10 10:57:57 -0700 | [diff] [blame] | 1409 | |
Angie Chiang | f87e43f | 2017-04-02 16:51:19 -0700 | [diff] [blame] | 1410 | av1_subtract_txb(x, plane, plane_bsize, blk_col, blk_row, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1411 | |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1412 | const ENTROPY_CONTEXT *a = &args->ta[blk_col]; |
| 1413 | const ENTROPY_CONTEXT *l = &args->tl[blk_row]; |
Angie Chiang | 5760553 | 2017-04-03 11:51:15 -0700 | [diff] [blame] | 1414 | int ctx = combine_entropy_contexts(*a, *l); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1415 | if (args->enable_optimize_b) { |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1416 | av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 1417 | ctx, AV1_XFORM_QUANT_FP); |
Jingning Han | 7eab9ff | 2017-07-06 10:12:54 -0700 | [diff] [blame] | 1418 | av1_optimize_b(cm, x, plane, blk_row, blk_col, block, plane_bsize, tx_size, |
| 1419 | a, l); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1420 | } else { |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 1421 | av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size, |
| 1422 | ctx, AV1_XFORM_QUANT_B); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Angie Chiang | 5760553 | 2017-04-03 11:51:15 -0700 | [diff] [blame] | 1425 | #if CONFIG_PVQ |
Yushin Cho | 3827fdd | 2016-11-09 15:50:23 -0800 | [diff] [blame] | 1426 | // *(args->skip) == mbmi->skip |
| 1427 | if (!x->pvq_skip[plane]) *(args->skip) = 0; |
| 1428 | |
| 1429 | if (x->pvq_skip[plane]) return; |
Angie Chiang | 50910f6 | 2017-04-03 12:31:34 -0700 | [diff] [blame] | 1430 | #endif // CONFIG_PVQ |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 1431 | av1_inverse_transform_block(xd, dqcoeff, |
| 1432 | #if CONFIG_LGT |
| 1433 | mode, |
| 1434 | #endif |
| 1435 | tx_type, tx_size, dst, dst_stride, *eob); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1436 | #if !CONFIG_PVQ |
| 1437 | if (*eob) *(args->skip) = 0; |
| 1438 | #else |
| 1439 | // Note : *(args->skip) == mbmi->skip |
| 1440 | #endif |
Luc Trudeau | e398028 | 2017-04-25 23:17:21 -0400 | [diff] [blame] | 1441 | #if CONFIG_CFL |
| 1442 | if (plane == AOM_PLANE_Y && x->cfl_store_y) { |
Luc Trudeau | 780d249 | 2017-06-15 22:26:41 -0400 | [diff] [blame] | 1443 | // TODO (ltrudeau) Store sub-8x8 inter blocks when bottom right block is |
| 1444 | // intra predicted. |
| 1445 | cfl_store(xd->cfl, dst, dst_stride, blk_row, blk_col, tx_size, plane_bsize); |
Luc Trudeau | e398028 | 2017-04-25 23:17:21 -0400 | [diff] [blame] | 1446 | } |
| 1447 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1450 | void av1_encode_intra_block_plane(AV1_COMMON *cm, MACROBLOCK *x, |
| 1451 | BLOCK_SIZE bsize, int plane, |
Yaowu Xu | 1e4e5b9 | 2017-05-05 11:06:42 -0700 | [diff] [blame] | 1452 | int enable_optimize_b, int mi_row, |
| 1453 | int mi_col) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1454 | const MACROBLOCKD *const xd = &x->e_mbd; |
Guillaume Martres | e50d9dd | 2016-12-18 18:26:47 +0100 | [diff] [blame] | 1455 | ENTROPY_CONTEXT ta[2 * MAX_MIB_SIZE] = { 0 }; |
| 1456 | ENTROPY_CONTEXT tl[2 * MAX_MIB_SIZE] = { 0 }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1457 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1458 | struct encode_b_args arg = { |
| 1459 | cm, x, NULL, &xd->mi[0]->mbmi.skip, ta, tl, enable_optimize_b |
| 1460 | }; |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 1461 | |
| 1462 | #if CONFIG_CB4X4 |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 1463 | if (!is_chroma_reference(mi_row, mi_col, bsize, |
| 1464 | xd->plane[plane].subsampling_x, |
| 1465 | xd->plane[plane].subsampling_y)) |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 1466 | return; |
| 1467 | #else |
| 1468 | (void)mi_row; |
| 1469 | (void)mi_col; |
| 1470 | #endif |
| 1471 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1472 | if (enable_optimize_b) { |
| 1473 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1474 | const TX_SIZE tx_size = av1_get_tx_size(plane, xd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1475 | av1_get_entropy_contexts(bsize, tx_size, pd, ta, tl); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1476 | } |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1477 | av1_foreach_transformed_block_in_plane( |
| 1478 | xd, bsize, plane, encode_block_intra_and_set_context, &arg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1479 | } |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1480 | |
| 1481 | #if CONFIG_PVQ |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1482 | PVQ_SKIP_TYPE av1_pvq_encode_helper(MACROBLOCK *x, tran_low_t *const coeff, |
| 1483 | tran_low_t *ref_coeff, |
| 1484 | tran_low_t *const dqcoeff, uint16_t *eob, |
| 1485 | const int16_t *quant, int plane, |
| 1486 | int tx_size, TX_TYPE tx_type, int *rate, |
| 1487 | int speed, PVQ_INFO *pvq_info) { |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1488 | const int tx_blk_size = tx_size_wide[tx_size]; |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1489 | daala_enc_ctx *daala_enc = &x->daala_enc; |
ltrudeau | e1c0929 | 2017-01-20 15:42:13 -0500 | [diff] [blame] | 1490 | PVQ_SKIP_TYPE ac_dc_coded; |
Jingning Han | ff70545 | 2017-04-27 11:32:15 -0700 | [diff] [blame] | 1491 | int coeff_shift = 3 - av1_get_tx_scale(tx_size); |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1492 | int hbd_downshift = 0; |
Timothy B. Terriberry | e93acb2 | 2017-02-06 13:55:53 -0800 | [diff] [blame] | 1493 | int rounding_mask; |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1494 | int pvq_dc_quant; |
| 1495 | int use_activity_masking = daala_enc->use_activity_masking; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1496 | int tell; |
| 1497 | int has_dc_skip = 1; |
| 1498 | int i; |
| 1499 | int off = od_qm_offset(tx_size, plane ? 1 : 0); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1500 | |
Thomas Daede | 1dbda1b | 2017-02-06 16:06:29 -0800 | [diff] [blame] | 1501 | DECLARE_ALIGNED(16, tran_low_t, coeff_pvq[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1502 | DECLARE_ALIGNED(16, tran_low_t, ref_coeff_pvq[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1503 | DECLARE_ALIGNED(16, tran_low_t, dqcoeff_pvq[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1504 | |
Yushin Cho | 48f84db | 2016-11-07 21:20:17 -0800 | [diff] [blame] | 1505 | DECLARE_ALIGNED(16, int32_t, in_int32[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1506 | DECLARE_ALIGNED(16, int32_t, ref_int32[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1507 | DECLARE_ALIGNED(16, int32_t, out_int32[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1508 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1509 | hbd_downshift = x->e_mbd.bd - 8; |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1510 | |
| 1511 | assert(OD_COEFF_SHIFT >= 4); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1512 | // DC quantizer for PVQ |
| 1513 | if (use_activity_masking) |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 1514 | pvq_dc_quant = |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1515 | OD_MAXI(1, (quant[0] << (OD_COEFF_SHIFT - 3) >> hbd_downshift) * |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 1516 | daala_enc->state |
| 1517 | .pvq_qm_q4[plane][od_qm_get_index(tx_size, 0)] >> |
| 1518 | 4); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1519 | else |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1520 | pvq_dc_quant = |
| 1521 | OD_MAXI(1, quant[0] << (OD_COEFF_SHIFT - 3) >> hbd_downshift); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1522 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1523 | *eob = 0; |
| 1524 | |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1525 | #if !CONFIG_ANS |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1526 | tell = od_ec_enc_tell_frac(&daala_enc->w.ec); |
| 1527 | #else |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1528 | #error "CONFIG_PVQ currently requires !CONFIG_ANS." |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1529 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1530 | |
| 1531 | // Change coefficient ordering for pvq encoding. |
| 1532 | od_raster_to_coding_order(coeff_pvq, tx_blk_size, tx_type, coeff, |
| 1533 | tx_blk_size); |
| 1534 | od_raster_to_coding_order(ref_coeff_pvq, tx_blk_size, tx_type, ref_coeff, |
| 1535 | tx_blk_size); |
| 1536 | |
| 1537 | // copy int16 inputs to int32 |
| 1538 | for (i = 0; i < tx_blk_size * tx_blk_size; i++) { |
Timothy B. Terriberry | 4e6a8f3 | 2017-02-24 11:00:59 -0800 | [diff] [blame] | 1539 | ref_int32[i] = |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1540 | AOM_SIGNED_SHL(ref_coeff_pvq[i], OD_COEFF_SHIFT - coeff_shift) >> |
| 1541 | hbd_downshift; |
| 1542 | in_int32[i] = AOM_SIGNED_SHL(coeff_pvq[i], OD_COEFF_SHIFT - coeff_shift) >> |
| 1543 | hbd_downshift; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1546 | if (abs(in_int32[0] - ref_int32[0]) < pvq_dc_quant * 141 / 256) { /* 0.55 */ |
| 1547 | out_int32[0] = 0; |
| 1548 | } else { |
| 1549 | out_int32[0] = OD_DIV_R0(in_int32[0] - ref_int32[0], pvq_dc_quant); |
| 1550 | } |
| 1551 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1552 | ac_dc_coded = |
| 1553 | od_pvq_encode(daala_enc, ref_int32, in_int32, out_int32, |
| 1554 | OD_MAXI(1, quant[0] << (OD_COEFF_SHIFT - 3) >> |
| 1555 | hbd_downshift), // scale/quantizer |
| 1556 | OD_MAXI(1, quant[1] << (OD_COEFF_SHIFT - 3) >> |
| 1557 | hbd_downshift), // scale/quantizer |
| 1558 | plane, |
| 1559 | tx_size, OD_PVQ_BETA[use_activity_masking][plane][tx_size], |
Yushin Cho | 31b980a | 2017-03-23 10:28:09 -0700 | [diff] [blame] | 1560 | 0, // is_keyframe, |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1561 | daala_enc->state.qm + off, daala_enc->state.qm_inv + off, |
| 1562 | speed, // speed |
| 1563 | pvq_info); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1564 | |
| 1565 | // Encode residue of DC coeff, if required. |
| 1566 | if (!has_dc_skip || out_int32[0]) { |
Yushin Cho | c49ef3a | 2017-03-13 17:27:25 -0700 | [diff] [blame] | 1567 | generic_encode(&daala_enc->w, &daala_enc->state.adapt->model_dc[plane], |
Timothy B. Terriberry | 44bb6d0 | 2017-04-07 15:44:14 -0700 | [diff] [blame] | 1568 | abs(out_int32[0]) - has_dc_skip, |
Yushin Cho | c49ef3a | 2017-03-13 17:27:25 -0700 | [diff] [blame] | 1569 | &daala_enc->state.adapt->ex_dc[plane][tx_size][0], 2); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1570 | } |
| 1571 | if (out_int32[0]) { |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1572 | aom_write_bit(&daala_enc->w, out_int32[0] < 0); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | // need to save quantized residue of DC coeff |
| 1576 | // so that final pvq bitstream writing can know whether DC is coded. |
| 1577 | if (pvq_info) pvq_info->dq_dc_residue = out_int32[0]; |
| 1578 | |
| 1579 | out_int32[0] = out_int32[0] * pvq_dc_quant; |
| 1580 | out_int32[0] += ref_int32[0]; |
| 1581 | |
| 1582 | // copy int32 result back to int16 |
Timothy B. Terriberry | e93acb2 | 2017-02-06 13:55:53 -0800 | [diff] [blame] | 1583 | assert(OD_COEFF_SHIFT > coeff_shift); |
| 1584 | rounding_mask = (1 << (OD_COEFF_SHIFT - coeff_shift - 1)) - 1; |
| 1585 | for (i = 0; i < tx_blk_size * tx_blk_size; i++) { |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1586 | out_int32[i] = AOM_SIGNED_SHL(out_int32[i], hbd_downshift); |
Timothy B. Terriberry | e93acb2 | 2017-02-06 13:55:53 -0800 | [diff] [blame] | 1587 | dqcoeff_pvq[i] = (out_int32[i] + (out_int32[i] < 0) + rounding_mask) >> |
| 1588 | (OD_COEFF_SHIFT - coeff_shift); |
| 1589 | } |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1590 | |
| 1591 | // Back to original coefficient order |
| 1592 | od_coding_order_to_raster(dqcoeff, tx_blk_size, tx_type, dqcoeff_pvq, |
| 1593 | tx_blk_size); |
| 1594 | |
| 1595 | *eob = tx_blk_size * tx_blk_size; |
| 1596 | |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1597 | #if !CONFIG_ANS |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1598 | *rate = (od_ec_enc_tell_frac(&daala_enc->w.ec) - tell) |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1599 | << (AV1_PROB_COST_SHIFT - OD_BITRES); |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1600 | #else |
Nathan E. Egge | 476c63c | 2017-05-18 18:35:16 -0400 | [diff] [blame] | 1601 | #error "CONFIG_PVQ currently requires !CONFIG_ANS." |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1602 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1603 | assert(*rate >= 0); |
Yushin Cho | 5c20729 | 2017-02-16 15:01:33 -0800 | [diff] [blame] | 1604 | |
ltrudeau | 472f63f | 2017-01-12 15:22:32 -0500 | [diff] [blame] | 1605 | return ac_dc_coded; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Timothy B. Terriberry | 44bb6d0 | 2017-04-07 15:44:14 -0700 | [diff] [blame] | 1608 | void av1_store_pvq_enc_info(PVQ_INFO *pvq_info, int *qg, int *theta, int *k, |
| 1609 | od_coeff *y, int nb_bands, const int *off, |
| 1610 | int *size, int skip_rest, int skip_dir, |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1611 | int bs) { // block size in log_2 -2 |
| 1612 | int i; |
| 1613 | const int tx_blk_size = tx_size_wide[bs]; |
| 1614 | |
| 1615 | for (i = 0; i < nb_bands; i++) { |
| 1616 | pvq_info->qg[i] = qg[i]; |
| 1617 | pvq_info->theta[i] = theta[i]; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1618 | pvq_info->k[i] = k[i]; |
| 1619 | pvq_info->off[i] = off[i]; |
| 1620 | pvq_info->size[i] = size[i]; |
| 1621 | } |
| 1622 | |
| 1623 | memcpy(pvq_info->y, y, tx_blk_size * tx_blk_size * sizeof(od_coeff)); |
| 1624 | |
| 1625 | pvq_info->nb_bands = nb_bands; |
| 1626 | pvq_info->skip_rest = skip_rest; |
| 1627 | pvq_info->skip_dir = skip_dir; |
| 1628 | pvq_info->bs = bs; |
| 1629 | } |
| 1630 | #endif |