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 | |
Jingning Han | e325abd | 2016-12-01 09:35:10 -0800 | [diff] [blame] | 41 | // Check if one needs to use c version subtraction. |
| 42 | static int check_subtract_block_size(int w, int h) { return w < 4 || h < 4; } |
| 43 | |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 44 | static void subtract_block(const MACROBLOCKD *xd, int rows, int cols, |
| 45 | int16_t *diff, ptrdiff_t diff_stride, |
| 46 | const uint8_t *src8, ptrdiff_t src_stride, |
| 47 | const uint8_t *pred8, ptrdiff_t pred_stride) { |
| 48 | #if !CONFIG_AOM_HIGHBITDEPTH |
| 49 | (void)xd; |
| 50 | #endif |
| 51 | |
| 52 | if (check_subtract_block_size(rows, cols)) { |
| 53 | #if CONFIG_AOM_HIGHBITDEPTH |
| 54 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 55 | aom_highbd_subtract_block_c(rows, cols, diff, diff_stride, src8, |
| 56 | src_stride, pred8, pred_stride, xd->bd); |
| 57 | return; |
| 58 | } |
| 59 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 60 | aom_subtract_block_c(rows, cols, diff, diff_stride, src8, src_stride, pred8, |
| 61 | pred_stride); |
| 62 | |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | #if CONFIG_AOM_HIGHBITDEPTH |
| 67 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 68 | aom_highbd_subtract_block(rows, cols, diff, diff_stride, src8, src_stride, |
| 69 | pred8, pred_stride, xd->bd); |
| 70 | return; |
| 71 | } |
| 72 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 73 | aom_subtract_block(rows, cols, diff, diff_stride, src8, src_stride, pred8, |
| 74 | pred_stride); |
| 75 | } |
| 76 | |
Angie Chiang | f87e43f | 2017-04-02 16:51:19 -0700 | [diff] [blame] | 77 | void av1_subtract_txb(MACROBLOCK *x, int plane, BLOCK_SIZE plane_bsize, |
| 78 | int blk_col, int blk_row, TX_SIZE tx_size) { |
| 79 | MACROBLOCKD *const xd = &x->e_mbd; |
| 80 | struct macroblock_plane *const p = &x->plane[plane]; |
| 81 | const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane]; |
| 82 | const int diff_stride = block_size_wide[plane_bsize]; |
| 83 | const int src_stride = p->src.stride; |
| 84 | const int dst_stride = pd->dst.stride; |
| 85 | const int tx1d_width = tx_size_wide[tx_size]; |
| 86 | const int tx1d_height = tx_size_high[tx_size]; |
| 87 | uint8_t *dst = |
| 88 | &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]]; |
| 89 | uint8_t *src = |
| 90 | &p->src.buf[(blk_row * src_stride + blk_col) << tx_size_wide_log2[0]]; |
| 91 | int16_t *src_diff = |
| 92 | &p->src_diff[(blk_row * diff_stride + blk_col) << tx_size_wide_log2[0]]; |
| 93 | subtract_block(xd, tx1d_height, tx1d_width, src_diff, diff_stride, src, |
| 94 | src_stride, dst, dst_stride); |
| 95 | } |
| 96 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 97 | void av1_subtract_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | struct macroblock_plane *const p = &x->plane[plane]; |
| 99 | const struct macroblockd_plane *const pd = &x->e_mbd.plane[plane]; |
| 100 | const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); |
Jingning Han | ae5cfde | 2016-11-30 12:01:44 -0800 | [diff] [blame] | 101 | const int bw = block_size_wide[plane_bsize]; |
| 102 | const int bh = block_size_high[plane_bsize]; |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 103 | const MACROBLOCKD *xd = &x->e_mbd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 104 | |
Angie Chiang | 19407b5 | 2017-04-02 15:27:57 -0700 | [diff] [blame] | 105 | subtract_block(xd, bh, bw, p->src_diff, bw, p->src.buf, p->src.stride, |
| 106 | pd->dst.buf, pd->dst.stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 109 | typedef struct av1_token_state { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 110 | int64_t error; |
Alex Converse | c9d2fcc | 2017-03-17 17:32:56 -0700 | [diff] [blame] | 111 | int rate; |
| 112 | int16_t next; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 113 | int16_t token; |
| 114 | tran_low_t qc; |
| 115 | tran_low_t dqc; |
Alex Converse | c9d2fcc | 2017-03-17 17:32:56 -0700 | [diff] [blame] | 116 | uint8_t best_index; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 117 | } av1_token_state; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 118 | |
| 119 | // These numbers are empirically obtained. |
| 120 | static const int plane_rd_mult[REF_TYPES][PLANE_TYPES] = { |
Thomas Davies | 1052575 | 2017-03-06 12:10:46 +0000 | [diff] [blame] | 121 | #if CONFIG_EC_ADAPT |
| 122 | { 10, 7 }, { 8, 5 }, |
| 123 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 124 | { 10, 6 }, { 8, 5 }, |
Thomas Davies | 1052575 | 2017-03-06 12:10:46 +0000 | [diff] [blame] | 125 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | #define UPDATE_RD_COST() \ |
| 129 | { \ |
| 130 | rd_cost0 = RDCOST(rdmult, rddiv, rate0, error0); \ |
| 131 | rd_cost1 = RDCOST(rdmult, rddiv, rate1, error1); \ |
| 132 | } |
| 133 | |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 134 | static inline int64_t get_token_bit_costs( |
| 135 | unsigned int token_costs[2][COEFF_CONTEXTS][ENTROPY_TOKENS], int skip_eob, |
| 136 | int ctx, int token) { |
| 137 | #if CONFIG_NEW_TOKENSET |
| 138 | (void)skip_eob; |
| 139 | return token_costs[token == ZERO_TOKEN || token == EOB_TOKEN][ctx][token]; |
| 140 | #else |
| 141 | return token_costs[skip_eob][ctx][token]; |
| 142 | #endif |
| 143 | } |
| 144 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 145 | int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block, |
| 146 | TX_SIZE tx_size, int ctx) { |
Angie Chiang | 5760553 | 2017-04-03 11:51:15 -0700 | [diff] [blame] | 147 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 148 | MACROBLOCKD *const xd = &mb->e_mbd; |
| 149 | struct macroblock_plane *const p = &mb->plane[plane]; |
| 150 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 151 | const int ref = is_inter_block(&xd->mi[0]->mbmi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 152 | av1_token_state tokens[MAX_TX_SQUARE + 1][2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 153 | uint8_t token_cache[MAX_TX_SQUARE]; |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 154 | const tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 155 | tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 156 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 157 | const int eob = p->eobs[block]; |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 158 | const PLANE_TYPE plane_type = pd->plane_type; |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 159 | const int default_eob = tx_size_2d[tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 160 | const int16_t *const dequant_ptr = pd->dequant; |
| 161 | const uint8_t *const band_translate = get_band_translate(tx_size); |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 162 | TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size); |
Urvang Joshi | 03f6fdc | 2016-10-14 15:53:39 -0700 | [diff] [blame] | 163 | const SCAN_ORDER *const scan_order = |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 164 | get_scan(cm, tx_size, tx_type, is_inter_block(&xd->mi[0]->mbmi)); |
Urvang Joshi | 03f6fdc | 2016-10-14 15:53:39 -0700 | [diff] [blame] | 165 | const int16_t *const scan = scan_order->scan; |
| 166 | const int16_t *const nb = scan_order->neighbors; |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 167 | int dqv; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 168 | const int shift = get_tx_scale(tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | #if CONFIG_AOM_QM |
| 170 | int seg_id = xd->mi[0]->mbmi.segment_id; |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 171 | const qm_val_t *iqmatrix = pd->seg_iqmatrix[seg_id][!ref][tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 173 | #if CONFIG_NEW_QUANT |
David Barker | d7d78c8 | 2016-10-24 10:55:35 +0100 | [diff] [blame] | 174 | int dq = get_dq_profile_from_ctx(mb->qindex, ctx, ref, plane_type); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 175 | const dequant_val_type_nuq *dequant_val = pd->dequant_val_nuq[dq]; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 176 | #elif !CONFIG_AOM_QM |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 177 | const int dq_step[2] = { dequant_ptr[0] >> shift, dequant_ptr[1] >> shift }; |
| 178 | #endif // CONFIG_NEW_QUANT |
| 179 | int next = eob, sz = 0; |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 180 | const int64_t rdmult = (mb->rdmult * plane_rd_mult[ref][plane_type]) >> 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 181 | const int64_t rddiv = mb->rddiv; |
| 182 | int64_t rd_cost0, rd_cost1; |
| 183 | int rate0, rate1; |
| 184 | int64_t error0, error1; |
| 185 | int16_t t0, t1; |
| 186 | int best, band = (eob < default_eob) ? band_translate[eob] |
| 187 | : band_translate[eob - 1]; |
| 188 | int pt, i, final_eob; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 189 | #if CONFIG_AOM_HIGHBITDEPTH |
Alex Converse | da3d94f | 2017-03-15 14:54:29 -0700 | [diff] [blame] | 190 | const int cat6_bits = av1_get_cat6_extrabits_size(tx_size, xd->bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 191 | #else |
Alex Converse | da3d94f | 2017-03-15 14:54:29 -0700 | [diff] [blame] | 192 | const int cat6_bits = av1_get_cat6_extrabits_size(tx_size, 8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 193 | #endif |
| 194 | unsigned int(*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 195 | mb->token_costs[txsize_sqr_map[tx_size]][plane_type][ref]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | const uint16_t *band_counts = &band_count_table[tx_size][band]; |
| 197 | uint16_t band_left = eob - band_cum_count_table[tx_size][band] + 1; |
| 198 | int shortcut = 0; |
| 199 | int next_shortcut = 0; |
| 200 | |
David Barker | d7d78c8 | 2016-10-24 10:55:35 +0100 | [diff] [blame] | 201 | assert((mb->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0)); |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 202 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 203 | token_costs += band; |
| 204 | |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 205 | assert((!plane_type && !plane) || (plane_type && plane)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 206 | assert(eob <= default_eob); |
| 207 | |
| 208 | /* Now set up a Viterbi trellis to evaluate alternative roundings. */ |
| 209 | /* Initialize the sentinel node of the trellis. */ |
| 210 | tokens[eob][0].rate = 0; |
| 211 | tokens[eob][0].error = 0; |
| 212 | tokens[eob][0].next = default_eob; |
| 213 | tokens[eob][0].token = EOB_TOKEN; |
| 214 | tokens[eob][0].qc = 0; |
| 215 | tokens[eob][1] = tokens[eob][0]; |
| 216 | |
| 217 | for (i = 0; i < eob; i++) { |
| 218 | const int rc = scan[i]; |
Alex Converse | da3d94f | 2017-03-15 14:54:29 -0700 | [diff] [blame] | 219 | tokens[i][0].rate = av1_get_token_cost(qcoeff[rc], &t0, cat6_bits); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 220 | tokens[i][0].token = t0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 221 | token_cache[rc] = av1_pt_energy_class[t0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | for (i = eob; i-- > 0;) { |
| 225 | int base_bits, dx; |
| 226 | int64_t d2; |
| 227 | const int rc = scan[i]; |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 228 | int x = qcoeff[rc]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 229 | #if CONFIG_AOM_QM |
| 230 | int iwt = iqmatrix[rc]; |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 231 | dqv = dequant_ptr[rc != 0]; |
| 232 | dqv = ((iwt * (int)dqv) + (1 << (AOM_QM_BITS - 1))) >> AOM_QM_BITS; |
| 233 | #else |
| 234 | dqv = dequant_ptr[rc != 0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 236 | next_shortcut = shortcut; |
| 237 | |
| 238 | /* Only add a trellis state for non-zero coefficients. */ |
| 239 | if (UNLIKELY(x)) { |
| 240 | error0 = tokens[next][0].error; |
| 241 | error1 = tokens[next][1].error; |
| 242 | /* Evaluate the first possibility for this state. */ |
| 243 | rate0 = tokens[next][0].rate; |
| 244 | rate1 = tokens[next][1].rate; |
| 245 | |
| 246 | if (next_shortcut) { |
| 247 | /* Consider both possible successor states. */ |
| 248 | if (next < default_eob) { |
| 249 | pt = get_coef_context(nb, token_cache, i + 1); |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 250 | rate0 += |
| 251 | get_token_bit_costs(*token_costs, 0, pt, tokens[next][0].token); |
| 252 | rate1 += |
| 253 | get_token_bit_costs(*token_costs, 0, pt, tokens[next][1].token); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 254 | } |
| 255 | UPDATE_RD_COST(); |
| 256 | /* And pick the best. */ |
| 257 | best = rd_cost1 < rd_cost0; |
| 258 | } else { |
| 259 | if (next < default_eob) { |
| 260 | pt = get_coef_context(nb, token_cache, i + 1); |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 261 | rate0 += |
| 262 | get_token_bit_costs(*token_costs, 0, pt, tokens[next][0].token); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 263 | } |
| 264 | best = 0; |
| 265 | } |
| 266 | |
| 267 | dx = (dqcoeff[rc] - coeff[rc]) * (1 << shift); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 268 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 269 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 270 | dx >>= xd->bd - 8; |
| 271 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 272 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 273 | d2 = (int64_t)dx * dx; |
| 274 | tokens[i][0].rate += (best ? rate1 : rate0); |
| 275 | tokens[i][0].error = d2 + (best ? error1 : error0); |
| 276 | tokens[i][0].next = next; |
| 277 | tokens[i][0].qc = x; |
| 278 | tokens[i][0].dqc = dqcoeff[rc]; |
Alex Converse | c9d2fcc | 2017-03-17 17:32:56 -0700 | [diff] [blame] | 279 | tokens[i][0].best_index = best; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 280 | |
| 281 | /* Evaluate the second possibility for this state. */ |
| 282 | rate0 = tokens[next][0].rate; |
| 283 | rate1 = tokens[next][1].rate; |
| 284 | |
| 285 | // The threshold of 3 is empirically obtained. |
| 286 | if (UNLIKELY(abs(x) > 3)) { |
| 287 | shortcut = 0; |
| 288 | } else { |
| 289 | #if CONFIG_NEW_QUANT |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 290 | shortcut = ((av1_dequant_abscoeff_nuq(abs(x), dqv, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 291 | dequant_val[band_translate[i]]) > |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 292 | (abs(coeff[rc]) << shift)) && |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 293 | (av1_dequant_abscoeff_nuq(abs(x) - 1, dqv, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 294 | dequant_val[band_translate[i]]) < |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 295 | (abs(coeff[rc]) << shift))); |
| 296 | #else // CONFIG_NEW_QUANT |
| 297 | #if CONFIG_AOM_QM |
| 298 | if ((abs(x) * dequant_ptr[rc != 0] * iwt > |
| 299 | ((abs(coeff[rc]) << shift) << AOM_QM_BITS)) && |
| 300 | (abs(x) * dequant_ptr[rc != 0] * iwt < |
| 301 | (((abs(coeff[rc]) << shift) + dequant_ptr[rc != 0]) |
| 302 | << AOM_QM_BITS))) |
| 303 | #else |
| 304 | if ((abs(x) * dequant_ptr[rc != 0] > (abs(coeff[rc]) << shift)) && |
| 305 | (abs(x) * dequant_ptr[rc != 0] < |
| 306 | (abs(coeff[rc]) << shift) + dequant_ptr[rc != 0])) |
| 307 | #endif // CONFIG_AOM_QM |
| 308 | shortcut = 1; |
| 309 | else |
| 310 | shortcut = 0; |
| 311 | #endif // CONFIG_NEW_QUANT |
| 312 | } |
| 313 | |
| 314 | if (shortcut) { |
| 315 | sz = -(x < 0); |
| 316 | x -= 2 * sz + 1; |
| 317 | } else { |
| 318 | tokens[i][1] = tokens[i][0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | next = i; |
| 320 | |
| 321 | if (UNLIKELY(!(--band_left))) { |
| 322 | --band_counts; |
| 323 | band_left = *band_counts; |
| 324 | --token_costs; |
| 325 | } |
| 326 | continue; |
| 327 | } |
| 328 | |
| 329 | /* Consider both possible successor states. */ |
| 330 | if (!x) { |
| 331 | /* If we reduced this coefficient to zero, check to see if |
| 332 | * we need to move the EOB back here. |
| 333 | */ |
| 334 | t0 = tokens[next][0].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN; |
| 335 | t1 = tokens[next][1].token == EOB_TOKEN ? EOB_TOKEN : ZERO_TOKEN; |
| 336 | base_bits = 0; |
| 337 | } else { |
Alex Converse | da3d94f | 2017-03-15 14:54:29 -0700 | [diff] [blame] | 338 | base_bits = av1_get_token_cost(x, &t0, cat6_bits); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | t1 = t0; |
| 340 | } |
| 341 | |
| 342 | if (next_shortcut) { |
| 343 | if (LIKELY(next < default_eob)) { |
| 344 | if (t0 != EOB_TOKEN) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 345 | token_cache[rc] = av1_pt_energy_class[t0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 346 | pt = get_coef_context(nb, token_cache, i + 1); |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 347 | rate0 += get_token_bit_costs(*token_costs, !x, pt, |
| 348 | tokens[next][0].token); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | } |
| 350 | if (t1 != EOB_TOKEN) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 351 | token_cache[rc] = av1_pt_energy_class[t1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 352 | pt = get_coef_context(nb, token_cache, i + 1); |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 353 | rate1 += get_token_bit_costs(*token_costs, !x, pt, |
| 354 | tokens[next][1].token); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
| 358 | UPDATE_RD_COST(); |
| 359 | /* And pick the best. */ |
| 360 | best = rd_cost1 < rd_cost0; |
| 361 | } else { |
| 362 | // The two states in next stage are identical. |
| 363 | if (next < default_eob && t0 != EOB_TOKEN) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 364 | token_cache[rc] = av1_pt_energy_class[t0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 365 | pt = get_coef_context(nb, token_cache, i + 1); |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 366 | rate0 += |
| 367 | get_token_bit_costs(*token_costs, !x, pt, tokens[next][0].token); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 368 | } |
| 369 | best = 0; |
| 370 | } |
| 371 | |
| 372 | #if CONFIG_NEW_QUANT |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 373 | dx = av1_dequant_coeff_nuq(x, dqv, dequant_val[band_translate[i]]) - |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 374 | (coeff[rc] << shift); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 375 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 376 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 377 | dx >>= xd->bd - 8; |
| 378 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 379 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 380 | #else // CONFIG_NEW_QUANT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 381 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 382 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 383 | dx -= ((dqv >> (xd->bd - 8)) + sz) ^ sz; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 384 | } else { |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 385 | dx -= (dqv + sz) ^ sz; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | } |
| 387 | #else |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 388 | dx -= (dqv + sz) ^ sz; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 389 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 390 | #endif // CONFIG_NEW_QUANT |
| 391 | d2 = (int64_t)dx * dx; |
| 392 | |
| 393 | tokens[i][1].rate = base_bits + (best ? rate1 : rate0); |
| 394 | tokens[i][1].error = d2 + (best ? error1 : error0); |
| 395 | tokens[i][1].next = next; |
| 396 | tokens[i][1].token = best ? t1 : t0; |
| 397 | tokens[i][1].qc = x; |
| 398 | |
| 399 | if (x) { |
| 400 | #if CONFIG_NEW_QUANT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 401 | tokens[i][1].dqc = av1_dequant_abscoeff_nuq( |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 402 | abs(x), dqv, dequant_val[band_translate[i]]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 403 | tokens[i][1].dqc = shift ? ROUND_POWER_OF_TWO(tokens[i][1].dqc, shift) |
| 404 | : tokens[i][1].dqc; |
| 405 | if (sz) tokens[i][1].dqc = -tokens[i][1].dqc; |
| 406 | #else |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 407 | // The 32x32 transform coefficient uses half quantization step size. |
| 408 | // Account for the rounding difference in the dequantized coefficeint |
| 409 | // value when the quantization index is dropped from an even number |
| 410 | // to an odd number. |
Thomas Davies | e0f8c55 | 2016-11-15 17:28:03 +0000 | [diff] [blame] | 411 | |
| 412 | #if CONFIG_AOM_QM |
| 413 | tran_low_t offset = dqv >> shift; |
| 414 | #else |
| 415 | tran_low_t offset = dq_step[rc != 0]; |
| 416 | #endif |
| 417 | if (shift & x) offset += (dqv & 0x01); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 418 | |
| 419 | if (sz == 0) |
| 420 | tokens[i][1].dqc = dqcoeff[rc] - offset; |
| 421 | else |
| 422 | tokens[i][1].dqc = dqcoeff[rc] + offset; |
| 423 | #endif // CONFIG_NEW_QUANT |
| 424 | } else { |
| 425 | tokens[i][1].dqc = 0; |
| 426 | } |
| 427 | |
Alex Converse | c9d2fcc | 2017-03-17 17:32:56 -0700 | [diff] [blame] | 428 | tokens[i][1].best_index = best; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 429 | /* Finally, make this the new head of the trellis. */ |
| 430 | next = i; |
| 431 | } else { |
| 432 | /* There's no choice to make for a zero coefficient, so we don't |
| 433 | * add a new trellis node, but we do need to update the costs. |
| 434 | */ |
| 435 | t0 = tokens[next][0].token; |
| 436 | t1 = tokens[next][1].token; |
| 437 | pt = get_coef_context(nb, token_cache, i + 1); |
| 438 | /* Update the cost of each path if we're past the EOB token. */ |
| 439 | if (t0 != EOB_TOKEN) { |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 440 | tokens[next][0].rate += get_token_bit_costs(*token_costs, 1, pt, t0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | tokens[next][0].token = ZERO_TOKEN; |
| 442 | } |
| 443 | if (t1 != EOB_TOKEN) { |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 444 | tokens[next][1].rate += get_token_bit_costs(*token_costs, 1, pt, t1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 445 | tokens[next][1].token = ZERO_TOKEN; |
| 446 | } |
Alex Converse | c9d2fcc | 2017-03-17 17:32:56 -0700 | [diff] [blame] | 447 | tokens[i][0].best_index = tokens[i][1].best_index = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 448 | shortcut = (tokens[next][0].rate != tokens[next][1].rate); |
| 449 | /* Don't update next, because we didn't add a new node. */ |
| 450 | } |
| 451 | |
| 452 | if (UNLIKELY(!(--band_left))) { |
| 453 | --band_counts; |
| 454 | band_left = *band_counts; |
| 455 | --token_costs; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | /* Now pick the best path through the whole trellis. */ |
| 460 | rate0 = tokens[next][0].rate; |
| 461 | rate1 = tokens[next][1].rate; |
| 462 | error0 = tokens[next][0].error; |
| 463 | error1 = tokens[next][1].error; |
| 464 | t0 = tokens[next][0].token; |
| 465 | t1 = tokens[next][1].token; |
Thomas Davies | ed8e2d2 | 2017-01-04 16:42:09 +0000 | [diff] [blame] | 466 | rate0 += get_token_bit_costs(*token_costs, 0, ctx, t0); |
| 467 | rate1 += get_token_bit_costs(*token_costs, 0, ctx, t1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 468 | UPDATE_RD_COST(); |
| 469 | best = rd_cost1 < rd_cost0; |
| 470 | |
| 471 | final_eob = -1; |
| 472 | |
| 473 | for (i = next; i < eob; i = next) { |
| 474 | const int x = tokens[i][best].qc; |
| 475 | const int rc = scan[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 476 | if (x) final_eob = i; |
| 477 | qcoeff[rc] = x; |
| 478 | dqcoeff[rc] = tokens[i][best].dqc; |
| 479 | |
| 480 | next = tokens[i][best].next; |
Alex Converse | c9d2fcc | 2017-03-17 17:32:56 -0700 | [diff] [blame] | 481 | best = tokens[i][best].best_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 482 | } |
| 483 | final_eob++; |
| 484 | |
| 485 | mb->plane[plane].eobs[block] = final_eob; |
| 486 | assert(final_eob <= default_eob); |
| 487 | return final_eob; |
Angie Chiang | 5760553 | 2017-04-03 11:51:15 -0700 | [diff] [blame] | 488 | #else // !CONFIG_PVQ |
| 489 | (void)cm; |
| 490 | (void)tx_size; |
| 491 | (void)ctx; |
| 492 | struct macroblock_plane *const p = &mb->plane[plane]; |
| 493 | return p->eobs[block]; |
| 494 | #endif // !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 497 | #if !CONFIG_PVQ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 498 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 499 | typedef enum QUANT_FUNC { |
| 500 | QUANT_FUNC_LOWBD = 0, |
| 501 | QUANT_FUNC_HIGHBD = 1, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 502 | QUANT_FUNC_TYPES = 2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 503 | } QUANT_FUNC; |
| 504 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 505 | static AV1_QUANT_FACADE |
| 506 | quant_func_list[AV1_XFORM_QUANT_TYPES][QUANT_FUNC_TYPES] = { |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 507 | #if !CONFIG_NEW_QUANT |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 508 | { av1_quantize_fp_facade, av1_highbd_quantize_fp_facade }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 509 | { av1_quantize_b_facade, av1_highbd_quantize_b_facade }, |
| 510 | { av1_quantize_dc_facade, av1_highbd_quantize_dc_facade }, |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 511 | #else // !CONFIG_NEW_QUANT |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 512 | { av1_quantize_fp_nuq_facade, av1_highbd_quantize_fp_nuq_facade }, |
| 513 | { av1_quantize_b_nuq_facade, av1_highbd_quantize_b_nuq_facade }, |
| 514 | { av1_quantize_dc_nuq_facade, av1_highbd_quantize_dc_nuq_facade }, |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 515 | #endif // !CONFIG_NEW_QUANT |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 516 | { NULL, NULL } |
| 517 | }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 519 | #else |
Yaowu Xu | 02d4c3b | 2016-11-07 10:45:56 -0800 | [diff] [blame] | 520 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 521 | typedef enum QUANT_FUNC { |
| 522 | QUANT_FUNC_LOWBD = 0, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 523 | QUANT_FUNC_TYPES = 1 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 524 | } QUANT_FUNC; |
| 525 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 526 | static AV1_QUANT_FACADE quant_func_list[AV1_XFORM_QUANT_TYPES] |
| 527 | [QUANT_FUNC_TYPES] = { |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 528 | #if !CONFIG_NEW_QUANT |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 529 | { av1_quantize_fp_facade }, |
| 530 | { av1_quantize_b_facade }, |
| 531 | { av1_quantize_dc_facade }, |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 532 | #else // !CONFIG_NEW_QUANT |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 533 | { av1_quantize_fp_nuq_facade }, |
| 534 | { av1_quantize_b_nuq_facade }, |
| 535 | { av1_quantize_dc_nuq_facade }, |
Angie Chiang | 6a71ad1 | 2017-04-03 11:19:00 -0700 | [diff] [blame] | 536 | #endif // !CONFIG_NEW_QUANT |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 537 | { NULL } |
| 538 | }; |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 539 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 540 | #endif // CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 541 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 542 | void av1_xform_quant(const AV1_COMMON *cm, MACROBLOCK *x, int plane, int block, |
| 543 | int blk_row, int blk_col, BLOCK_SIZE plane_bsize, |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 544 | TX_SIZE tx_size, int ctx, |
| 545 | AV1_XFORM_QUANT xform_quant_idx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 546 | MACROBLOCKD *const xd = &x->e_mbd; |
Luc Trudeau | b6e94d9 | 2017-03-13 15:46:15 -0400 | [diff] [blame] | 547 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 548 | #if !(CONFIG_PVQ || CONFIG_DAALA_DIST) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 549 | const struct macroblock_plane *const p = &x->plane[plane]; |
| 550 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 551 | #else |
| 552 | struct macroblock_plane *const p = &x->plane[plane]; |
| 553 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 554 | #endif |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 555 | PLANE_TYPE plane_type = get_plane_type(plane); |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 556 | TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size); |
Luc Trudeau | b6e94d9 | 2017-03-13 15:46:15 -0400 | [diff] [blame] | 557 | const int is_inter = is_inter_block(mbmi); |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 558 | const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, is_inter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 559 | tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
| 560 | tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 561 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 562 | uint16_t *const eob = &p->eobs[block]; |
Jingning Han | ae5cfde | 2016-11-30 12:01:44 -0800 | [diff] [blame] | 563 | const int diff_stride = block_size_wide[plane_bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 564 | #if CONFIG_AOM_QM |
Luc Trudeau | b6e94d9 | 2017-03-13 15:46:15 -0400 | [diff] [blame] | 565 | int seg_id = mbmi->segment_id; |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 566 | const qm_val_t *qmatrix = pd->seg_qmatrix[seg_id][!is_inter][tx_size]; |
| 567 | const qm_val_t *iqmatrix = pd->seg_iqmatrix[seg_id][!is_inter][tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 568 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 569 | |
| 570 | FWD_TXFM_PARAM fwd_txfm_param; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 571 | |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 572 | #if CONFIG_PVQ || CONFIG_DAALA_DIST |
| 573 | uint8_t *dst; |
| 574 | int16_t *pred; |
| 575 | const int dst_stride = pd->dst.stride; |
| 576 | int tx_blk_size; |
| 577 | int i, j; |
| 578 | #endif |
| 579 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 580 | #if !CONFIG_PVQ |
| 581 | const int tx2d_size = tx_size_2d[tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 582 | QUANT_PARAM qparam; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 583 | const int16_t *src_diff; |
| 584 | |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 585 | src_diff = |
| 586 | &p->src_diff[(blk_row * diff_stride + blk_col) << tx_size_wide_log2[0]]; |
Debargha Mukherjee | 0e11912 | 2016-11-04 12:10:23 -0700 | [diff] [blame] | 587 | qparam.log_scale = get_tx_scale(tx_size); |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 588 | #if CONFIG_NEW_QUANT |
| 589 | qparam.tx_size = tx_size; |
| 590 | qparam.dq = get_dq_profile_from_ctx(x->qindex, ctx, is_inter, plane_type); |
| 591 | #endif // CONFIG_NEW_QUANT |
| 592 | #if CONFIG_AOM_QM |
| 593 | qparam.qmatrix = qmatrix; |
| 594 | qparam.iqmatrix = iqmatrix; |
| 595 | #endif // CONFIG_AOM_QM |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 596 | #else |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 597 | tran_low_t *ref_coeff = BLOCK_OFFSET(pd->pvq_ref_coeff, block); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 598 | int skip = 1; |
| 599 | PVQ_INFO *pvq_info = NULL; |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 600 | uint8_t *src; |
| 601 | int16_t *src_int16; |
| 602 | const int src_stride = p->src.stride; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 603 | |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 604 | (void)ctx; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 605 | (void)scan_order; |
| 606 | (void)qcoeff; |
| 607 | |
| 608 | if (x->pvq_coded) { |
| 609 | assert(block < MAX_PVQ_BLOCKS_IN_SB); |
| 610 | pvq_info = &x->pvq[block][plane]; |
| 611 | } |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 612 | src = &p->src.buf[(blk_row * src_stride + blk_col) << tx_size_wide_log2[0]]; |
| 613 | src_int16 = |
| 614 | &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] | 615 | |
| 616 | // transform block size in pixels |
| 617 | tx_blk_size = tx_size_wide[tx_size]; |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 618 | #if CONFIG_AOM_HIGHBITDEPTH |
| 619 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 620 | for (j = 0; j < tx_blk_size; j++) |
| 621 | for (i = 0; i < tx_blk_size; i++) |
| 622 | src_int16[diff_stride * j + i] = |
| 623 | CONVERT_TO_SHORTPTR(src)[src_stride * j + i]; |
| 624 | } else { |
| 625 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 626 | for (j = 0; j < tx_blk_size; j++) |
| 627 | for (i = 0; i < tx_blk_size; i++) |
| 628 | src_int16[diff_stride * j + i] = src[src_stride * j + i]; |
| 629 | #if CONFIG_AOM_HIGHBITDEPTH |
| 630 | } |
| 631 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 632 | #endif |
| 633 | |
| 634 | #if CONFIG_PVQ || CONFIG_DAALA_DIST |
| 635 | dst = &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]]; |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 636 | 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] | 637 | |
| 638 | // transform block size in pixels |
| 639 | tx_blk_size = tx_size_wide[tx_size]; |
| 640 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 641 | // copy uint8 orig and predicted block to int16 buffer |
| 642 | // in order to use existing VP10 transform functions |
| 643 | #if CONFIG_AOM_HIGHBITDEPTH |
| 644 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 645 | for (j = 0; j < tx_blk_size; j++) |
| 646 | for (i = 0; i < tx_blk_size; i++) |
| 647 | pred[diff_stride * j + i] = |
| 648 | CONVERT_TO_SHORTPTR(dst)[dst_stride * j + i]; |
| 649 | } else { |
| 650 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 651 | for (j = 0; j < tx_blk_size; j++) |
| 652 | for (i = 0; i < tx_blk_size; i++) |
| 653 | pred[diff_stride * j + i] = dst[dst_stride * j + i]; |
| 654 | #if CONFIG_AOM_HIGHBITDEPTH |
| 655 | } |
| 656 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 657 | #endif |
Yushin Cho | 7a428ba | 2017-01-12 16:28:49 -0800 | [diff] [blame] | 658 | |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 659 | (void)ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | |
| 661 | fwd_txfm_param.tx_type = tx_type; |
| 662 | fwd_txfm_param.tx_size = tx_size; |
Luc Trudeau | b6e94d9 | 2017-03-13 15:46:15 -0400 | [diff] [blame] | 663 | fwd_txfm_param.lossless = xd->lossless[mbmi->segment_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 664 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 665 | #if !CONFIG_PVQ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 666 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 667 | fwd_txfm_param.bd = xd->bd; |
| 668 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
hui su | f11fb88 | 2017-03-27 14:56:33 -0700 | [diff] [blame] | 669 | av1_highbd_fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 670 | if (xform_quant_idx != AV1_XFORM_QUANT_SKIP_QUANT) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 671 | if (LIKELY(!x->skip_block)) { |
| 672 | quant_func_list[xform_quant_idx][QUANT_FUNC_HIGHBD]( |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 673 | coeff, tx2d_size, p, qcoeff, pd, dqcoeff, eob, scan_order, &qparam); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 674 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 675 | av1_quantize_skip(tx2d_size, qcoeff, dqcoeff, eob); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 676 | } |
| 677 | } |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 678 | #if CONFIG_LV_MAP |
| 679 | p->txb_entropy_ctx[block] = |
| 680 | (uint8_t)av1_get_txb_entropy_context(qcoeff, scan_order, *eob); |
| 681 | #endif // CONFIG_LV_MAP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 682 | return; |
| 683 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 684 | #endif // CONFIG_AOM_HIGHBITDEPTH |
hui su | f11fb88 | 2017-03-27 14:56:33 -0700 | [diff] [blame] | 685 | av1_fwd_txfm(src_diff, coeff, diff_stride, &fwd_txfm_param); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 686 | if (xform_quant_idx != AV1_XFORM_QUANT_SKIP_QUANT) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 687 | if (LIKELY(!x->skip_block)) { |
| 688 | quant_func_list[xform_quant_idx][QUANT_FUNC_LOWBD]( |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 689 | coeff, tx2d_size, p, qcoeff, pd, dqcoeff, eob, scan_order, &qparam); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 690 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 691 | av1_quantize_skip(tx2d_size, qcoeff, dqcoeff, eob); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 692 | } |
| 693 | } |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 694 | #if CONFIG_LV_MAP |
| 695 | p->txb_entropy_ctx[block] = |
| 696 | (uint8_t)av1_get_txb_entropy_context(qcoeff, scan_order, *eob); |
| 697 | #endif // CONFIG_LV_MAP |
| 698 | #else // #if !CONFIG_PVQ |
Angie Chiang | 2cc057c | 2017-01-03 18:31:47 -0800 | [diff] [blame] | 699 | (void)xform_quant_idx; |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 700 | #if CONFIG_AOM_HIGHBITDEPTH |
| 701 | fwd_txfm_param.bd = xd->bd; |
| 702 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
hui su | f11fb88 | 2017-03-27 14:56:33 -0700 | [diff] [blame] | 703 | av1_highbd_fwd_txfm(src_int16, coeff, diff_stride, &fwd_txfm_param); |
| 704 | av1_highbd_fwd_txfm(pred, ref_coeff, diff_stride, &fwd_txfm_param); |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 705 | } else { |
| 706 | #endif |
hui su | f11fb88 | 2017-03-27 14:56:33 -0700 | [diff] [blame] | 707 | av1_fwd_txfm(src_int16, coeff, diff_stride, &fwd_txfm_param); |
| 708 | av1_fwd_txfm(pred, ref_coeff, diff_stride, &fwd_txfm_param); |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 709 | #if CONFIG_AOM_HIGHBITDEPTH |
| 710 | } |
| 711 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 712 | |
| 713 | // PVQ for inter mode block |
ltrudeau | 472f63f | 2017-01-12 15:22:32 -0500 | [diff] [blame] | 714 | if (!x->skip_block) { |
ltrudeau | e1c0929 | 2017-01-20 15:42:13 -0500 | [diff] [blame] | 715 | PVQ_SKIP_TYPE ac_dc_coded = |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 716 | av1_pvq_encode_helper(x, |
ltrudeau | e1c0929 | 2017-01-20 15:42:13 -0500 | [diff] [blame] | 717 | coeff, // target original vector |
| 718 | ref_coeff, // reference vector |
| 719 | dqcoeff, // de-quantized vector |
| 720 | eob, // End of Block marker |
| 721 | pd->dequant, // aom's quantizers |
| 722 | plane, // image plane |
| 723 | tx_size, // block size in log_2 - 2 |
| 724 | tx_type, |
| 725 | &x->rate, // rate measured |
| 726 | x->pvq_speed, |
| 727 | pvq_info); // PVQ info for a block |
| 728 | skip = ac_dc_coded == PVQ_SKIP; |
ltrudeau | 472f63f | 2017-01-12 15:22:32 -0500 | [diff] [blame] | 729 | } |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 730 | x->pvq_skip[plane] = skip; |
| 731 | |
| 732 | if (!skip) mbmi->skip = 0; |
| 733 | #endif // #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 736 | static void encode_block(int plane, int block, int blk_row, int blk_col, |
| 737 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg) { |
| 738 | struct encode_b_args *const args = arg; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 739 | AV1_COMMON *cm = args->cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 740 | MACROBLOCK *const x = args->x; |
| 741 | MACROBLOCKD *const xd = &x->e_mbd; |
| 742 | int ctx; |
| 743 | struct macroblock_plane *const p = &x->plane[plane]; |
| 744 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 745 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 746 | uint8_t *dst; |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 747 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 748 | ENTROPY_CONTEXT *a, *l; |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 749 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 750 | #if CONFIG_VAR_TX |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 751 | int bw = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | #endif |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 753 | dst = &pd->dst |
| 754 | .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] | 755 | |
| 756 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 757 | a = &args->ta[blk_col]; |
| 758 | l = &args->tl[blk_row]; |
| 759 | #if CONFIG_VAR_TX |
| 760 | ctx = get_entropy_context(tx_size, a, l); |
| 761 | #else |
| 762 | ctx = combine_entropy_contexts(*a, *l); |
| 763 | #endif |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 764 | #else |
| 765 | ctx = 0; |
| 766 | #endif // CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 767 | |
| 768 | #if CONFIG_VAR_TX |
Yue Chen | a1e48dc | 2016-08-29 17:29:33 -0700 | [diff] [blame] | 769 | // Assert not magic number (uninitialized). |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 770 | assert(x->blk_skip[plane][blk_row * bw + blk_col] != 234); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 771 | |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 772 | if (x->blk_skip[plane][blk_row * bw + blk_col] == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 773 | #else |
| 774 | { |
| 775 | #endif |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 776 | 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] | 777 | ctx, AV1_XFORM_QUANT_FP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 778 | } |
| 779 | #if CONFIG_VAR_TX |
| 780 | else { |
| 781 | p->eobs[block] = 0; |
| 782 | } |
| 783 | #endif |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 784 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 785 | #if !CONFIG_PVQ |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 786 | if (p->eobs[block] && !xd->lossless[xd->mi[0]->mbmi.segment_id]) |
| 787 | av1_optimize_b(cm, x, plane, block, tx_size, ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 789 | av1_set_txb_context(x, plane, block, tx_size, a, l); |
| 790 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | if (p->eobs[block]) *(args->skip) = 0; |
| 792 | |
| 793 | if (p->eobs[block] == 0) return; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 794 | #else |
| 795 | (void)ctx; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 796 | if (!x->pvq_skip[plane]) *(args->skip) = 0; |
| 797 | |
| 798 | if (x->pvq_skip[plane]) return; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 799 | #endif |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 800 | TX_TYPE tx_type = get_tx_type(pd->plane_type, xd, block, tx_size); |
Angie Chiang | 44d7e66 | 2017-04-06 11:07:53 -0700 | [diff] [blame] | 801 | av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, |
| 802 | pd->dst.stride, p->eobs[block]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | #if CONFIG_VAR_TX |
| 806 | static void encode_block_inter(int plane, int block, int blk_row, int blk_col, |
| 807 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 808 | void *arg) { |
| 809 | struct encode_b_args *const args = arg; |
| 810 | MACROBLOCK *const x = args->x; |
| 811 | MACROBLOCKD *const xd = &x->e_mbd; |
| 812 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 813 | const BLOCK_SIZE bsize = txsize_to_bsize[tx_size]; |
| 814 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 815 | const int tx_row = blk_row >> (1 - pd->subsampling_y); |
| 816 | const int tx_col = blk_col >> (1 - pd->subsampling_x); |
| 817 | TX_SIZE plane_tx_size; |
Jingning Han | f65b870 | 2016-10-31 12:13:20 -0700 | [diff] [blame] | 818 | const int max_blocks_high = max_block_high(xd, plane_bsize, plane); |
| 819 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 820 | |
| 821 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 822 | |
Debargha Mukherjee | 2f12340 | 2016-08-30 17:43:38 -0700 | [diff] [blame] | 823 | plane_tx_size = |
| 824 | plane ? uv_txsize_lookup[bsize][mbmi->inter_tx_size[tx_row][tx_col]][0][0] |
| 825 | : mbmi->inter_tx_size[tx_row][tx_col]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 826 | |
| 827 | if (tx_size == plane_tx_size) { |
| 828 | encode_block(plane, block, blk_row, blk_col, plane_bsize, tx_size, arg); |
| 829 | } else { |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 830 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
| 831 | // This is the square transform block partition entry point. |
| 832 | int bsl = tx_size_wide_unit[sub_txs]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 834 | assert(bsl > 0); |
Jingning Han | d3fada8 | 2016-11-22 10:46:55 -0800 | [diff] [blame] | 835 | assert(tx_size < TX_SIZES_ALL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 836 | |
| 837 | for (i = 0; i < 4; ++i) { |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 838 | const int offsetr = blk_row + ((i >> 1) * bsl); |
| 839 | const int offsetc = blk_col + ((i & 0x01) * bsl); |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 840 | 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] | 841 | |
| 842 | if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; |
| 843 | |
Jingning Han | 98d6a1f | 2016-11-03 12:47:47 -0700 | [diff] [blame] | 844 | encode_block_inter(plane, block, offsetr, offsetc, plane_bsize, sub_txs, |
| 845 | arg); |
| 846 | block += step; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | } |
| 850 | #endif |
| 851 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 852 | typedef struct encode_block_pass1_args { |
| 853 | AV1_COMMON *cm; |
| 854 | MACROBLOCK *x; |
| 855 | } encode_block_pass1_args; |
| 856 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 857 | static void encode_block_pass1(int plane, int block, int blk_row, int blk_col, |
| 858 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 859 | void *arg) { |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 860 | encode_block_pass1_args *args = (encode_block_pass1_args *)arg; |
| 861 | AV1_COMMON *cm = args->cm; |
| 862 | MACROBLOCK *const x = args->x; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 863 | MACROBLOCKD *const xd = &x->e_mbd; |
| 864 | struct macroblock_plane *const p = &x->plane[plane]; |
| 865 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 866 | tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 867 | uint8_t *dst; |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 868 | int ctx = 0; |
Jingning Han | 8149226 | 2016-12-05 15:48:47 -0800 | [diff] [blame] | 869 | dst = &pd->dst |
| 870 | .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] | 871 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 872 | 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] | 873 | ctx, AV1_XFORM_QUANT_B); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 874 | #if !CONFIG_PVQ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 875 | if (p->eobs[block] > 0) { |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 876 | #else |
| 877 | if (!x->pvq_skip[plane]) { |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 878 | { |
| 879 | int tx_blk_size; |
| 880 | int i, j; |
| 881 | // transform block size in pixels |
| 882 | tx_blk_size = tx_size_wide[tx_size]; |
| 883 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 884 | // Since av1 does not have separate function which does inverse transform |
| 885 | // but av1_inv_txfm_add_*x*() also does addition of predicted image to |
| 886 | // inverse transformed image, |
| 887 | // pass blank dummy image to av1_inv_txfm_add_*x*(), i.e. set dst as zeros |
| 888 | #if CONFIG_AOM_HIGHBITDEPTH |
| 889 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 890 | for (j = 0; j < tx_blk_size; j++) |
| 891 | for (i = 0; i < tx_blk_size; i++) |
| 892 | CONVERT_TO_SHORTPTR(dst)[j * pd->dst.stride + i] = 0; |
| 893 | } else { |
| 894 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 895 | for (j = 0; j < tx_blk_size; j++) |
| 896 | for (i = 0; i < tx_blk_size; i++) dst[j * pd->dst.stride + i] = 0; |
| 897 | #if CONFIG_AOM_HIGHBITDEPTH |
| 898 | } |
| 899 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 900 | } |
Jingning Han | df07264 | 2016-11-08 16:43:38 -0800 | [diff] [blame] | 901 | #endif // !CONFIG_PVQ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 902 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 903 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 904 | if (xd->lossless[xd->mi[0]->mbmi.segment_id]) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 905 | av1_highbd_iwht4x4_add(dqcoeff, dst, pd->dst.stride, p->eobs[block], |
| 906 | xd->bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 907 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 908 | av1_highbd_idct4x4_add(dqcoeff, dst, pd->dst.stride, p->eobs[block], |
| 909 | xd->bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 910 | } |
| 911 | return; |
| 912 | } |
Jingning Han | e38d63c | 2016-11-08 12:05:29 -0800 | [diff] [blame] | 913 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 914 | if (xd->lossless[xd->mi[0]->mbmi.segment_id]) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 915 | av1_iwht4x4_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 917 | av1_idct4x4_add(dqcoeff, dst, pd->dst.stride, p->eobs[block]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | } |
| 921 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 922 | void av1_encode_sby_pass1(AV1_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE bsize) { |
| 923 | encode_block_pass1_args args = { cm, x }; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 924 | av1_subtract_plane(x, bsize, 0); |
| 925 | av1_foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0, |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 926 | encode_block_pass1, &args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 929 | void av1_encode_sb(AV1_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE bsize, |
| 930 | const int mi_row, const int mi_col) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 931 | MACROBLOCKD *const xd = &x->e_mbd; |
| 932 | struct optimize_ctx ctx; |
| 933 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 934 | 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] | 935 | int plane; |
| 936 | |
| 937 | mbmi->skip = 1; |
| 938 | |
| 939 | if (x->skip) return; |
| 940 | |
| 941 | for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
Jingning Han | 31b6a4f | 2017-02-23 11:05:53 -0800 | [diff] [blame] | 942 | #if CONFIG_CB4X4 && !CONFIG_CHROMA_2X2 |
Jingning Han | 2d2dac2 | 2017-04-11 09:41:10 -0700 | [diff] [blame^] | 943 | const int subsampling_x = xd->plane[plane].subsampling_x; |
| 944 | const int subsampling_y = xd->plane[plane].subsampling_y; |
| 945 | |
| 946 | if (!is_chroma_reference(mi_row, mi_col, bsize, subsampling_x, |
| 947 | subsampling_y)) |
Jingning Han | ea576f3 | 2017-02-21 23:05:09 -0800 | [diff] [blame] | 948 | continue; |
Jingning Han | 2d2dac2 | 2017-04-11 09:41:10 -0700 | [diff] [blame^] | 949 | |
| 950 | bsize = scale_chroma_bsize(bsize, subsampling_x, subsampling_y); |
Jingning Han | ea576f3 | 2017-02-21 23:05:09 -0800 | [diff] [blame] | 951 | #else |
| 952 | (void)mi_row; |
| 953 | (void)mi_col; |
| 954 | #endif |
| 955 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 956 | #if CONFIG_VAR_TX |
| 957 | // TODO(jingning): Clean this up. |
| 958 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 959 | const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 960 | const int mi_width = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
| 961 | const int mi_height = block_size_high[plane_bsize] >> tx_size_wide_log2[0]; |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 962 | const TX_SIZE max_tx_size = max_txsize_rect_lookup[plane_bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 963 | const BLOCK_SIZE txb_size = txsize_to_bsize[max_tx_size]; |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 964 | const int bw = block_size_wide[txb_size] >> tx_size_wide_log2[0]; |
| 965 | 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] | 966 | int idx, idy; |
| 967 | int block = 0; |
Jingning Han | de953b9 | 2016-10-25 12:35:43 -0700 | [diff] [blame] | 968 | 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] | 969 | 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] | 970 | #else |
| 971 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Angie Chiang | 7fcfee4 | 2017-02-24 15:51:03 -0800 | [diff] [blame] | 972 | const TX_SIZE tx_size = get_tx_size(plane, xd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 973 | 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] | 974 | #endif |
Jingning Han | ea576f3 | 2017-02-21 23:05:09 -0800 | [diff] [blame] | 975 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 976 | #if !CONFIG_PVQ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 977 | av1_subtract_plane(x, bsize, plane); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 978 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 979 | arg.ta = ctx.ta[plane]; |
| 980 | arg.tl = ctx.tl[plane]; |
| 981 | |
| 982 | #if CONFIG_VAR_TX |
Jingning Han | fe45b21 | 2016-11-22 10:30:23 -0800 | [diff] [blame] | 983 | for (idy = 0; idy < mi_height; idy += bh) { |
| 984 | for (idx = 0; idx < mi_width; idx += bw) { |
| 985 | encode_block_inter(plane, block, idy, idx, plane_bsize, max_tx_size, |
| 986 | &arg); |
| 987 | block += step; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 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 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 991 | av1_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block, |
| 992 | &arg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 993 | #endif |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | #if CONFIG_SUPERTX |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 998 | 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] | 999 | MACROBLOCKD *const xd = &x->e_mbd; |
| 1000 | struct optimize_ctx ctx; |
| 1001 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1002 | 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] | 1003 | int plane; |
| 1004 | |
| 1005 | mbmi->skip = 1; |
| 1006 | if (x->skip) return; |
| 1007 | |
| 1008 | for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
| 1009 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1010 | #if CONFIG_VAR_TX |
| 1011 | const TX_SIZE tx_size = TX_4X4; |
| 1012 | #else |
Angie Chiang | 7fcfee4 | 2017-02-24 15:51:03 -0800 | [diff] [blame] | 1013 | const TX_SIZE tx_size = get_tx_size(plane, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1014 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1015 | av1_subtract_plane(x, bsize, plane); |
| 1016 | 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] | 1017 | arg.ta = ctx.ta[plane]; |
| 1018 | arg.tl = ctx.tl[plane]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1019 | av1_foreach_transformed_block_in_plane(xd, bsize, plane, encode_block, |
| 1020 | &arg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | #endif // CONFIG_SUPERTX |
| 1024 | |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1025 | #if !CONFIG_PVQ |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 1026 | 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] | 1027 | ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l) { |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1028 | (void)tx_size; |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1029 | struct macroblock_plane *p = &x->plane[plane]; |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1030 | |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 1031 | #if !CONFIG_LV_MAP |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1032 | *a = *l = p->eobs[block] > 0; |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 1033 | #else // !CONFIG_LV_MAP |
| 1034 | *a = *l = p->txb_entropy_ctx[block]; |
| 1035 | #endif // !CONFIG_LV_MAP |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 1036 | |
| 1037 | #if CONFIG_VAR_TX || CONFIG_LV_MAP |
| 1038 | int i; |
| 1039 | for (i = 0; i < tx_size_wide_unit[tx_size]; ++i) a[i] = a[0]; |
| 1040 | |
| 1041 | for (i = 0; i < tx_size_high_unit[tx_size]; ++i) l[i] = l[0]; |
| 1042 | #endif |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1043 | } |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1044 | #endif |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1045 | |
| 1046 | static void encode_block_intra_and_set_context(int plane, int block, |
| 1047 | int blk_row, int blk_col, |
| 1048 | BLOCK_SIZE plane_bsize, |
| 1049 | TX_SIZE tx_size, void *arg) { |
| 1050 | av1_encode_block_intra(plane, block, blk_row, blk_col, plane_bsize, tx_size, |
| 1051 | arg); |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1052 | #if !CONFIG_PVQ |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1053 | struct encode_b_args *const args = arg; |
| 1054 | MACROBLOCK *x = args->x; |
| 1055 | ENTROPY_CONTEXT *a = &args->ta[blk_col]; |
| 1056 | ENTROPY_CONTEXT *l = &args->tl[blk_row]; |
Angie Chiang | db0c7d4 | 2017-03-23 16:05:37 -0700 | [diff] [blame] | 1057 | av1_set_txb_context(x, plane, block, tx_size, a, l); |
Yushin Cho | 6341f5c | 2017-03-24 14:36:28 -0700 | [diff] [blame] | 1058 | #endif |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1061 | void av1_encode_block_intra(int plane, int block, int blk_row, int blk_col, |
| 1062 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 1063 | void *arg) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1064 | struct encode_b_args *const args = arg; |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1065 | AV1_COMMON *cm = args->cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1066 | MACROBLOCK *const x = args->x; |
| 1067 | MACROBLOCKD *const xd = &x->e_mbd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1068 | struct macroblock_plane *const p = &x->plane[plane]; |
| 1069 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1070 | tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 1071 | PLANE_TYPE plane_type = get_plane_type(plane); |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1072 | const TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1073 | uint16_t *eob = &p->eobs[block]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1074 | const int dst_stride = pd->dst.stride; |
Angie Chiang | f87e43f | 2017-04-02 16:51:19 -0700 | [diff] [blame] | 1075 | uint8_t *dst = |
| 1076 | &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]]; |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1077 | av1_predict_intra_block_facade(xd, plane, block, blk_col, blk_row, tx_size); |
Angie Chiang | f87e43f | 2017-04-02 16:51:19 -0700 | [diff] [blame] | 1078 | 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] | 1079 | |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1080 | const ENTROPY_CONTEXT *a = &args->ta[blk_col]; |
| 1081 | const ENTROPY_CONTEXT *l = &args->tl[blk_row]; |
Angie Chiang | 5760553 | 2017-04-03 11:51:15 -0700 | [diff] [blame] | 1082 | int ctx = combine_entropy_contexts(*a, *l); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1083 | if (args->enable_optimize_b) { |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1084 | 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] | 1085 | ctx, AV1_XFORM_QUANT_FP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1086 | if (p->eobs[block]) { |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1087 | av1_optimize_b(cm, x, plane, block, tx_size, ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1088 | } |
| 1089 | } else { |
Debargha Mukherjee | f030558 | 2016-11-24 09:55:34 -0800 | [diff] [blame] | 1090 | av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size, |
| 1091 | ctx, AV1_XFORM_QUANT_B); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Angie Chiang | 5760553 | 2017-04-03 11:51:15 -0700 | [diff] [blame] | 1094 | #if CONFIG_PVQ |
Yushin Cho | 3827fdd | 2016-11-09 15:50:23 -0800 | [diff] [blame] | 1095 | // *(args->skip) == mbmi->skip |
| 1096 | if (!x->pvq_skip[plane]) *(args->skip) = 0; |
| 1097 | |
| 1098 | if (x->pvq_skip[plane]) return; |
Angie Chiang | 50910f6 | 2017-04-03 12:31:34 -0700 | [diff] [blame] | 1099 | #endif // CONFIG_PVQ |
Angie Chiang | d92d4bf | 2017-04-02 17:49:18 -0700 | [diff] [blame] | 1100 | av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, dst_stride, |
| 1101 | *eob); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1102 | #if !CONFIG_PVQ |
| 1103 | if (*eob) *(args->skip) = 0; |
| 1104 | #else |
| 1105 | // Note : *(args->skip) == mbmi->skip |
| 1106 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1109 | void av1_encode_intra_block_plane(AV1_COMMON *cm, MACROBLOCK *x, |
| 1110 | BLOCK_SIZE bsize, int plane, |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 1111 | int enable_optimize_b, const int mi_row, |
| 1112 | const int mi_col) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1113 | const MACROBLOCKD *const xd = &x->e_mbd; |
Guillaume Martres | e50d9dd | 2016-12-18 18:26:47 +0100 | [diff] [blame] | 1114 | ENTROPY_CONTEXT ta[2 * MAX_MIB_SIZE] = { 0 }; |
| 1115 | ENTROPY_CONTEXT tl[2 * MAX_MIB_SIZE] = { 0 }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1116 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 1117 | struct encode_b_args arg = { |
| 1118 | cm, x, NULL, &xd->mi[0]->mbmi.skip, ta, tl, enable_optimize_b |
| 1119 | }; |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 1120 | |
| 1121 | #if CONFIG_CB4X4 |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 1122 | if (!is_chroma_reference(mi_row, mi_col, bsize, |
| 1123 | xd->plane[plane].subsampling_x, |
| 1124 | xd->plane[plane].subsampling_y)) |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 1125 | return; |
| 1126 | #else |
| 1127 | (void)mi_row; |
| 1128 | (void)mi_col; |
| 1129 | #endif |
| 1130 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1131 | if (enable_optimize_b) { |
| 1132 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Angie Chiang | 7fcfee4 | 2017-02-24 15:51:03 -0800 | [diff] [blame] | 1133 | const TX_SIZE tx_size = get_tx_size(plane, xd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1134 | av1_get_entropy_contexts(bsize, tx_size, pd, ta, tl); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1135 | } |
Angie Chiang | 36aca33 | 2017-03-23 14:16:24 -0700 | [diff] [blame] | 1136 | av1_foreach_transformed_block_in_plane( |
| 1137 | xd, bsize, plane, encode_block_intra_and_set_context, &arg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1138 | } |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1139 | |
| 1140 | #if CONFIG_PVQ |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1141 | PVQ_SKIP_TYPE av1_pvq_encode_helper(MACROBLOCK *x, tran_low_t *const coeff, |
| 1142 | tran_low_t *ref_coeff, |
| 1143 | tran_low_t *const dqcoeff, uint16_t *eob, |
| 1144 | const int16_t *quant, int plane, |
| 1145 | int tx_size, TX_TYPE tx_type, int *rate, |
| 1146 | int speed, PVQ_INFO *pvq_info) { |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1147 | const int tx_blk_size = tx_size_wide[tx_size]; |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1148 | daala_enc_ctx *daala_enc = &x->daala_enc; |
ltrudeau | e1c0929 | 2017-01-20 15:42:13 -0500 | [diff] [blame] | 1149 | PVQ_SKIP_TYPE ac_dc_coded; |
Timothy B. Terriberry | e93acb2 | 2017-02-06 13:55:53 -0800 | [diff] [blame] | 1150 | int coeff_shift = 3 - get_tx_scale(tx_size); |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1151 | int hbd_downshift = 0; |
Timothy B. Terriberry | e93acb2 | 2017-02-06 13:55:53 -0800 | [diff] [blame] | 1152 | int rounding_mask; |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1153 | int pvq_dc_quant; |
| 1154 | int use_activity_masking = daala_enc->use_activity_masking; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1155 | int tell; |
| 1156 | int has_dc_skip = 1; |
| 1157 | int i; |
| 1158 | int off = od_qm_offset(tx_size, plane ? 1 : 0); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1159 | |
Thomas Daede | 1dbda1b | 2017-02-06 16:06:29 -0800 | [diff] [blame] | 1160 | DECLARE_ALIGNED(16, tran_low_t, coeff_pvq[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1161 | DECLARE_ALIGNED(16, tran_low_t, ref_coeff_pvq[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1162 | 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] | 1163 | |
Yushin Cho | 48f84db | 2016-11-07 21:20:17 -0800 | [diff] [blame] | 1164 | DECLARE_ALIGNED(16, int32_t, in_int32[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1165 | DECLARE_ALIGNED(16, int32_t, ref_int32[OD_TXSIZE_MAX * OD_TXSIZE_MAX]); |
| 1166 | 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] | 1167 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1168 | #if CONFIG_AOM_HIGHBITDEPTH |
| 1169 | hbd_downshift = x->e_mbd.bd - 8; |
| 1170 | #endif |
| 1171 | |
| 1172 | assert(OD_COEFF_SHIFT >= 4); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1173 | // DC quantizer for PVQ |
| 1174 | if (use_activity_masking) |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 1175 | pvq_dc_quant = |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1176 | OD_MAXI(1, (quant[0] << (OD_COEFF_SHIFT - 3) >> hbd_downshift) * |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 1177 | daala_enc->state |
| 1178 | .pvq_qm_q4[plane][od_qm_get_index(tx_size, 0)] >> |
| 1179 | 4); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1180 | else |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1181 | pvq_dc_quant = |
| 1182 | OD_MAXI(1, quant[0] << (OD_COEFF_SHIFT - 3) >> hbd_downshift); |
Yushin Cho | 7066912 | 2016-12-08 09:53:14 -1000 | [diff] [blame] | 1183 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1184 | *eob = 0; |
| 1185 | |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1186 | #if CONFIG_DAALA_EC |
| 1187 | tell = od_ec_enc_tell_frac(&daala_enc->w.ec); |
| 1188 | #else |
| 1189 | #error "CONFIG_PVQ currently requires CONFIG_DAALA_EC." |
| 1190 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1191 | |
| 1192 | // Change coefficient ordering for pvq encoding. |
| 1193 | od_raster_to_coding_order(coeff_pvq, tx_blk_size, tx_type, coeff, |
| 1194 | tx_blk_size); |
| 1195 | od_raster_to_coding_order(ref_coeff_pvq, tx_blk_size, tx_type, ref_coeff, |
| 1196 | tx_blk_size); |
| 1197 | |
| 1198 | // copy int16 inputs to int32 |
| 1199 | for (i = 0; i < tx_blk_size * tx_blk_size; i++) { |
Timothy B. Terriberry | 4e6a8f3 | 2017-02-24 11:00:59 -0800 | [diff] [blame] | 1200 | ref_int32[i] = |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1201 | AOM_SIGNED_SHL(ref_coeff_pvq[i], OD_COEFF_SHIFT - coeff_shift) >> |
| 1202 | hbd_downshift; |
| 1203 | in_int32[i] = AOM_SIGNED_SHL(coeff_pvq[i], OD_COEFF_SHIFT - coeff_shift) >> |
| 1204 | hbd_downshift; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1207 | if (abs(in_int32[0] - ref_int32[0]) < pvq_dc_quant * 141 / 256) { /* 0.55 */ |
| 1208 | out_int32[0] = 0; |
| 1209 | } else { |
| 1210 | out_int32[0] = OD_DIV_R0(in_int32[0] - ref_int32[0], pvq_dc_quant); |
| 1211 | } |
| 1212 | |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1213 | ac_dc_coded = |
| 1214 | od_pvq_encode(daala_enc, ref_int32, in_int32, out_int32, |
| 1215 | OD_MAXI(1, quant[0] << (OD_COEFF_SHIFT - 3) >> |
| 1216 | hbd_downshift), // scale/quantizer |
| 1217 | OD_MAXI(1, quant[1] << (OD_COEFF_SHIFT - 3) >> |
| 1218 | hbd_downshift), // scale/quantizer |
| 1219 | plane, |
| 1220 | tx_size, OD_PVQ_BETA[use_activity_masking][plane][tx_size], |
| 1221 | OD_ROBUST_STREAM, |
Yushin Cho | 31b980a | 2017-03-23 10:28:09 -0700 | [diff] [blame] | 1222 | 0, // is_keyframe, |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1223 | daala_enc->state.qm + off, daala_enc->state.qm_inv + off, |
| 1224 | speed, // speed |
| 1225 | pvq_info); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1226 | |
| 1227 | // Encode residue of DC coeff, if required. |
| 1228 | if (!has_dc_skip || out_int32[0]) { |
Yushin Cho | c49ef3a | 2017-03-13 17:27:25 -0700 | [diff] [blame] | 1229 | generic_encode(&daala_enc->w, &daala_enc->state.adapt->model_dc[plane], |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1230 | abs(out_int32[0]) - has_dc_skip, -1, |
Yushin Cho | c49ef3a | 2017-03-13 17:27:25 -0700 | [diff] [blame] | 1231 | &daala_enc->state.adapt->ex_dc[plane][tx_size][0], 2); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1232 | } |
| 1233 | if (out_int32[0]) { |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1234 | aom_write_bit(&daala_enc->w, out_int32[0] < 0); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | // need to save quantized residue of DC coeff |
| 1238 | // so that final pvq bitstream writing can know whether DC is coded. |
| 1239 | if (pvq_info) pvq_info->dq_dc_residue = out_int32[0]; |
| 1240 | |
| 1241 | out_int32[0] = out_int32[0] * pvq_dc_quant; |
| 1242 | out_int32[0] += ref_int32[0]; |
| 1243 | |
| 1244 | // copy int32 result back to int16 |
Timothy B. Terriberry | e93acb2 | 2017-02-06 13:55:53 -0800 | [diff] [blame] | 1245 | assert(OD_COEFF_SHIFT > coeff_shift); |
| 1246 | rounding_mask = (1 << (OD_COEFF_SHIFT - coeff_shift - 1)) - 1; |
| 1247 | for (i = 0; i < tx_blk_size * tx_blk_size; i++) { |
Thomas Daede | 6ff6af6 | 2017-02-03 16:29:24 -0800 | [diff] [blame] | 1248 | out_int32[i] = AOM_SIGNED_SHL(out_int32[i], hbd_downshift); |
Timothy B. Terriberry | e93acb2 | 2017-02-06 13:55:53 -0800 | [diff] [blame] | 1249 | dqcoeff_pvq[i] = (out_int32[i] + (out_int32[i] < 0) + rounding_mask) >> |
| 1250 | (OD_COEFF_SHIFT - coeff_shift); |
| 1251 | } |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1252 | |
| 1253 | // Back to original coefficient order |
| 1254 | od_coding_order_to_raster(dqcoeff, tx_blk_size, tx_type, dqcoeff_pvq, |
| 1255 | tx_blk_size); |
| 1256 | |
| 1257 | *eob = tx_blk_size * tx_blk_size; |
| 1258 | |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1259 | #if CONFIG_DAALA_EC |
| 1260 | *rate = (od_ec_enc_tell_frac(&daala_enc->w.ec) - tell) |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1261 | << (AV1_PROB_COST_SHIFT - OD_BITRES); |
Nathan E. Egge | 6675be0 | 2016-12-21 13:02:43 -0500 | [diff] [blame] | 1262 | #else |
| 1263 | #error "CONFIG_PVQ currently requires CONFIG_DAALA_EC." |
| 1264 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1265 | assert(*rate >= 0); |
Yushin Cho | 5c20729 | 2017-02-16 15:01:33 -0800 | [diff] [blame] | 1266 | |
ltrudeau | 472f63f | 2017-01-12 15:22:32 -0500 | [diff] [blame] | 1267 | return ac_dc_coded; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | void av1_store_pvq_enc_info(PVQ_INFO *pvq_info, int *qg, int *theta, |
| 1271 | int *max_theta, int *k, od_coeff *y, int nb_bands, |
| 1272 | const int *off, int *size, int skip_rest, |
| 1273 | int skip_dir, |
| 1274 | int bs) { // block size in log_2 -2 |
| 1275 | int i; |
| 1276 | const int tx_blk_size = tx_size_wide[bs]; |
| 1277 | |
| 1278 | for (i = 0; i < nb_bands; i++) { |
| 1279 | pvq_info->qg[i] = qg[i]; |
| 1280 | pvq_info->theta[i] = theta[i]; |
| 1281 | pvq_info->max_theta[i] = max_theta[i]; |
| 1282 | pvq_info->k[i] = k[i]; |
| 1283 | pvq_info->off[i] = off[i]; |
| 1284 | pvq_info->size[i] = size[i]; |
| 1285 | } |
| 1286 | |
| 1287 | memcpy(pvq_info->y, y, tx_blk_size * tx_blk_size * sizeof(od_coeff)); |
| 1288 | |
| 1289 | pvq_info->nb_bands = nb_bands; |
| 1290 | pvq_info->skip_rest = skip_rest; |
| 1291 | pvq_info->skip_dir = skip_dir; |
| 1292 | pvq_info->bs = bs; |
| 1293 | } |
| 1294 | #endif |