Line data Source code
1 : /*
2 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 : *
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.
10 : */
11 :
12 : #include "./av1_rtcd.h"
13 : #include "av1/common/enums.h"
14 : #include "av1/common/av1_txfm.h"
15 : #include "av1/common/av1_inv_txfm1d.h"
16 : #include "av1/common/av1_inv_txfm1d_cfg.h"
17 :
18 0 : static INLINE TxfmFunc inv_txfm_type_to_func(TXFM_TYPE txfm_type) {
19 0 : switch (txfm_type) {
20 0 : case TXFM_TYPE_DCT4: return av1_idct4_new;
21 0 : case TXFM_TYPE_DCT8: return av1_idct8_new;
22 0 : case TXFM_TYPE_DCT16: return av1_idct16_new;
23 0 : case TXFM_TYPE_DCT32: return av1_idct32_new;
24 0 : case TXFM_TYPE_ADST4: return av1_iadst4_new;
25 0 : case TXFM_TYPE_ADST8: return av1_iadst8_new;
26 0 : case TXFM_TYPE_ADST16: return av1_iadst16_new;
27 0 : case TXFM_TYPE_ADST32: return av1_iadst32_new;
28 : #if CONFIG_EXT_TX
29 0 : case TXFM_TYPE_IDENTITY4: return av1_iidentity4_c;
30 0 : case TXFM_TYPE_IDENTITY8: return av1_iidentity8_c;
31 0 : case TXFM_TYPE_IDENTITY16: return av1_iidentity16_c;
32 0 : case TXFM_TYPE_IDENTITY32: return av1_iidentity32_c;
33 : #endif // CONFIG_EXT_TX
34 0 : default: assert(0); return NULL;
35 : }
36 : }
37 :
38 : static const TXFM_1D_CFG *inv_txfm_col_cfg_ls[TX_TYPES_1D][TX_SIZES] = {
39 : // DCT
40 : {
41 : #if CONFIG_CHROMA_2X2
42 : NULL,
43 : #endif
44 : &inv_txfm_1d_col_cfg_dct_4, &inv_txfm_1d_col_cfg_dct_8,
45 : &inv_txfm_1d_col_cfg_dct_16, &inv_txfm_1d_col_cfg_dct_32 },
46 : // ADST
47 : {
48 : #if CONFIG_CHROMA_2X2
49 : NULL,
50 : #endif
51 : &inv_txfm_1d_col_cfg_adst_4, &inv_txfm_1d_col_cfg_adst_8,
52 : &inv_txfm_1d_col_cfg_adst_16, &inv_txfm_1d_col_cfg_adst_32 },
53 : #if CONFIG_EXT_TX
54 : // FLIPADST
55 : {
56 : #if CONFIG_CHROMA_2X2
57 : NULL,
58 : #endif
59 : &inv_txfm_1d_col_cfg_adst_4, &inv_txfm_1d_col_cfg_adst_8,
60 : &inv_txfm_1d_col_cfg_adst_16, &inv_txfm_1d_col_cfg_adst_32 },
61 : // IDENTITY
62 : {
63 : #if CONFIG_CHROMA_2X2
64 : NULL,
65 : #endif
66 : &inv_txfm_1d_cfg_identity_4, &inv_txfm_1d_cfg_identity_8,
67 : &inv_txfm_1d_cfg_identity_16, &inv_txfm_1d_cfg_identity_32 },
68 : #endif // CONFIG_EXT_TX
69 : };
70 :
71 : static const TXFM_1D_CFG *inv_txfm_row_cfg_ls[TX_TYPES_1D][TX_SIZES] = {
72 : // DCT
73 : {
74 : #if CONFIG_CHROMA_2X2
75 : NULL,
76 : #endif
77 : &inv_txfm_1d_row_cfg_dct_4, &inv_txfm_1d_row_cfg_dct_8,
78 : &inv_txfm_1d_row_cfg_dct_16, &inv_txfm_1d_row_cfg_dct_32 },
79 : // ADST
80 : {
81 : #if CONFIG_CHROMA_2X2
82 : NULL,
83 : #endif
84 : &inv_txfm_1d_row_cfg_adst_4, &inv_txfm_1d_row_cfg_adst_8,
85 : &inv_txfm_1d_row_cfg_adst_16, &inv_txfm_1d_row_cfg_adst_32 },
86 : #if CONFIG_EXT_TX
87 : // FLIPADST
88 : {
89 : #if CONFIG_CHROMA_2X2
90 : NULL,
91 : #endif
92 : &inv_txfm_1d_row_cfg_adst_4, &inv_txfm_1d_row_cfg_adst_8,
93 : &inv_txfm_1d_row_cfg_adst_16, &inv_txfm_1d_row_cfg_adst_32 },
94 : // IDENTITY
95 : {
96 : #if CONFIG_CHROMA_2X2
97 : NULL,
98 : #endif
99 : &inv_txfm_1d_cfg_identity_4, &inv_txfm_1d_cfg_identity_8,
100 : &inv_txfm_1d_cfg_identity_16, &inv_txfm_1d_cfg_identity_32 },
101 : #endif // CONFIG_EXT_TX
102 : };
103 :
104 0 : TXFM_2D_FLIP_CFG av1_get_inv_txfm_cfg(int tx_type, int tx_size) {
105 : TXFM_2D_FLIP_CFG cfg;
106 0 : set_flip_cfg(tx_type, &cfg);
107 0 : int tx_type_col = vtx_tab[tx_type];
108 0 : int tx_type_row = htx_tab[tx_type];
109 : // TODO(sarahparker) this is currently only implemented for
110 : // square transforms
111 0 : cfg.col_cfg = inv_txfm_col_cfg_ls[tx_type_col][tx_size];
112 0 : cfg.row_cfg = inv_txfm_row_cfg_ls[tx_type_row][tx_size];
113 0 : return cfg;
114 : }
115 :
116 0 : TXFM_2D_FLIP_CFG av1_get_inv_txfm_64x64_cfg(int tx_type) {
117 0 : TXFM_2D_FLIP_CFG cfg = { 0, 0, NULL, NULL };
118 0 : switch (tx_type) {
119 : case DCT_DCT:
120 0 : cfg.col_cfg = &inv_txfm_1d_col_cfg_dct_64;
121 0 : cfg.row_cfg = &inv_txfm_1d_row_cfg_dct_64;
122 0 : set_flip_cfg(tx_type, &cfg);
123 0 : break;
124 0 : default: assert(0);
125 : }
126 0 : return cfg;
127 : }
128 :
129 0 : static INLINE void inv_txfm2d_add_c(const int32_t *input, int16_t *output,
130 : int stride, TXFM_2D_FLIP_CFG *cfg,
131 : int32_t *txfm_buf) {
132 : // TODO(sarahparker) must correct for rectangular transforms in follow up
133 0 : const int txfm_size = cfg->row_cfg->txfm_size;
134 0 : const int8_t *shift = cfg->row_cfg->shift;
135 0 : const int8_t *stage_range_col = cfg->col_cfg->stage_range;
136 0 : const int8_t *stage_range_row = cfg->row_cfg->stage_range;
137 0 : const int8_t *cos_bit_col = cfg->col_cfg->cos_bit;
138 0 : const int8_t *cos_bit_row = cfg->row_cfg->cos_bit;
139 0 : const TxfmFunc txfm_func_col = inv_txfm_type_to_func(cfg->col_cfg->txfm_type);
140 0 : const TxfmFunc txfm_func_row = inv_txfm_type_to_func(cfg->row_cfg->txfm_type);
141 :
142 : // txfm_buf's length is txfm_size * txfm_size + 2 * txfm_size
143 : // it is used for intermediate data buffering
144 0 : int32_t *temp_in = txfm_buf;
145 0 : int32_t *temp_out = temp_in + txfm_size;
146 0 : int32_t *buf = temp_out + txfm_size;
147 0 : int32_t *buf_ptr = buf;
148 : int c, r;
149 :
150 : // Rows
151 0 : for (r = 0; r < txfm_size; ++r) {
152 0 : txfm_func_row(input, buf_ptr, cos_bit_row, stage_range_row);
153 0 : round_shift_array(buf_ptr, txfm_size, -shift[0]);
154 0 : input += txfm_size;
155 0 : buf_ptr += txfm_size;
156 : }
157 :
158 : // Columns
159 0 : for (c = 0; c < txfm_size; ++c) {
160 0 : if (cfg->lr_flip == 0) {
161 0 : for (r = 0; r < txfm_size; ++r) temp_in[r] = buf[r * txfm_size + c];
162 : } else {
163 : // flip left right
164 0 : for (r = 0; r < txfm_size; ++r)
165 0 : temp_in[r] = buf[r * txfm_size + (txfm_size - c - 1)];
166 : }
167 0 : txfm_func_col(temp_in, temp_out, cos_bit_col, stage_range_col);
168 0 : round_shift_array(temp_out, txfm_size, -shift[1]);
169 0 : if (cfg->ud_flip == 0) {
170 0 : for (r = 0; r < txfm_size; ++r) output[r * stride + c] += temp_out[r];
171 : } else {
172 : // flip upside down
173 0 : for (r = 0; r < txfm_size; ++r)
174 0 : output[r * stride + c] += temp_out[txfm_size - r - 1];
175 : }
176 : }
177 0 : }
178 :
179 0 : static INLINE void inv_txfm2d_add_facade(const int32_t *input, uint16_t *output,
180 : int stride, int32_t *txfm_buf,
181 : int tx_type, int tx_size, int bd) {
182 : // output contains the prediction signal which is always positive and smaller
183 : // than (1 << bd) - 1
184 : // since bd < 16-1, therefore we can treat the uint16_t* output buffer as an
185 : // int16_t*
186 0 : TXFM_2D_FLIP_CFG cfg = av1_get_inv_txfm_cfg(tx_type, tx_size);
187 0 : inv_txfm2d_add_c(input, (int16_t *)output, stride, &cfg, txfm_buf);
188 : // TODO(sarahparker) just using the cfg_row->txfm_size for now because
189 : // we are assumint this is only used for square transforms. This will
190 : // be adjusted in a follow up
191 0 : clamp_block((int16_t *)output, cfg.row_cfg->txfm_size, stride, 0,
192 0 : (1 << bd) - 1);
193 0 : }
194 :
195 0 : void av1_inv_txfm2d_add_4x4_c(const int32_t *input, uint16_t *output,
196 : int stride, int tx_type, int bd) {
197 : int txfm_buf[4 * 4 + 4 + 4];
198 0 : inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_4X4, bd);
199 0 : }
200 :
201 0 : void av1_inv_txfm2d_add_8x8_c(const int32_t *input, uint16_t *output,
202 : int stride, int tx_type, int bd) {
203 : int txfm_buf[8 * 8 + 8 + 8];
204 0 : inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_8X8, bd);
205 0 : }
206 :
207 0 : void av1_inv_txfm2d_add_16x16_c(const int32_t *input, uint16_t *output,
208 : int stride, int tx_type, int bd) {
209 : int txfm_buf[16 * 16 + 16 + 16];
210 0 : inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_16X16, bd);
211 0 : }
212 :
213 0 : void av1_inv_txfm2d_add_32x32_c(const int32_t *input, uint16_t *output,
214 : int stride, int tx_type, int bd) {
215 : int txfm_buf[32 * 32 + 32 + 32];
216 0 : inv_txfm2d_add_facade(input, output, stride, txfm_buf, tx_type, TX_32X32, bd);
217 0 : }
218 :
219 0 : void av1_inv_txfm2d_add_64x64_c(const int32_t *input, uint16_t *output,
220 : int stride, int tx_type, int bd) {
221 : int txfm_buf[64 * 64 + 64 + 64];
222 : // output contains the prediction signal which is always positive and smaller
223 : // than (1 << bd) - 1
224 : // since bd < 16-1, therefore we can treat the uint16_t* output buffer as an
225 : // int16_t*
226 0 : TXFM_2D_FLIP_CFG cfg = av1_get_inv_txfm_64x64_cfg(tx_type);
227 0 : inv_txfm2d_add_c(input, (int16_t *)output, stride, &cfg, txfm_buf);
228 0 : clamp_block((int16_t *)output, 64, stride, 0, (1 << bd) - 1);
229 0 : }
|