1 /*
2 * Copyright(c) 2019 Intel Corporation
3 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 *
5 * This source code is subject to the terms of the BSD 2 Clause License and
6 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
7 * was not distributed with this source code in the LICENSE file, you can
8 * obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open
9 * Media Patent License 1.0 was not distributed with this source code in the
10 * PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
11 */
12 
13 #ifndef EbTransforms_h
14 #define EbTransforms_h
15 
16 #include "EbDefinitions.h"
17 #include "EbCoefficients.h"
18 #include "EbInvTransforms.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include "EbEncDecProcess.h"
25 
26 static const int8_t fwd_shift_4x4[3]   = {2, 0, 0};
27 static const int8_t fwd_shift_8x8[3]   = {2, -1, 0};
28 static const int8_t fwd_shift_16x16[3] = {2, -2, 0};
29 static const int8_t fwd_shift_32x32[3] = {2, -4, 0};
30 static const int8_t fwd_shift_64x64[3] = {0, -2, -2};
31 static const int8_t fwd_shift_4x8[3]   = {2, -1, 0};
32 static const int8_t fwd_shift_8x4[3]   = {2, -1, 0};
33 static const int8_t fwd_shift_8x16[3]  = {2, -2, 0};
34 static const int8_t fwd_shift_16x8[3]  = {2, -2, 0};
35 static const int8_t fwd_shift_16x32[3] = {2, -4, 0};
36 static const int8_t fwd_shift_32x16[3] = {2, -4, 0};
37 static const int8_t fwd_shift_32x64[3] = {0, -2, -2};
38 static const int8_t fwd_shift_64x32[3] = {2, -4, -2};
39 static const int8_t fwd_shift_4x16[3]  = {2, -1, 0};
40 static const int8_t fwd_shift_16x4[3]  = {2, -1, 0};
41 static const int8_t fwd_shift_8x32[3]  = {2, -2, 0};
42 static const int8_t fwd_shift_32x8[3]  = {2, -2, 0};
43 static const int8_t fwd_shift_16x64[3] = {0, -2, 0};
44 static const int8_t fwd_shift_64x16[3] = {2, -4, 0};
45 
46 static const int8_t fwd_cos_bit_col[MAX_TXWH_IDX /*txw_idx*/][MAX_TXWH_IDX /*txh_idx*/] = {
47     {13, 13, 13, 0, 0},
48     {13, 13, 13, 12, 0},
49     {13, 13, 13, 12, 13},
50     {0, 13, 13, 12, 13},
51     {0, 0, 13, 12, 13}};
52 static const int8_t fwd_cos_bit_row[MAX_TXWH_IDX /*txw_idx*/][MAX_TXWH_IDX /*txh_idx*/] = {
53     {13, 13, 12, 0, 0},
54     {13, 13, 13, 12, 0},
55     {13, 13, 12, 13, 12},
56     {0, 12, 13, 12, 11},
57     {0, 0, 12, 11, 10}};
58 
59 static const int8_t fdct4_range_mult2[4]    = {0, 2, 3, 3};
60 static const int8_t fdct8_range_mult2[6]    = {0, 2, 4, 5, 5, 5};
61 static const int8_t fdct16_range_mult2[8]   = {0, 2, 4, 6, 7, 7, 7, 7};
62 static const int8_t fdct32_range_mult2[10]  = {0, 2, 4, 6, 8, 9, 9, 9, 9, 9};
63 static const int8_t fdct64_range_mult2[12]  = {0, 2, 4, 6, 8, 10, 11, 11, 11, 11, 11, 11};
64 static const int8_t fadst4_range_mult2[7]   = {0, 2, 4, 3, 3, 3, 3};
65 static const int8_t fadst8_range_mult2[8]   = {0, 0, 1, 3, 3, 5, 5, 5};
66 static const int8_t fadst16_range_mult2[10] = {0, 0, 1, 3, 3, 5, 5, 7, 7, 7};
67 static const int8_t fadst32_range_mult2[12] = {0, 0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 9};
68 static const int8_t fidtx4_range_mult2[1]   = {1};
69 static const int8_t fidtx8_range_mult2[1]   = {2};
70 static const int8_t fidtx16_range_mult2[1]  = {3};
71 static const int8_t fidtx32_range_mult2[1]  = {4};
72 static const int8_t fidtx64_range_mult2[1]  = {5};
73 
74 #define BLOCK_SIZES_ALL 22
is_rect_tx(TxSize tx_size)75 static INLINE int is_rect_tx(TxSize tx_size) { return tx_size >= TX_SIZES; }
is_rect_tx_allowed_bsize(BlockSize bsize)76 static INLINE int is_rect_tx_allowed_bsize(BlockSize bsize) {
77     static const char lut[BLOCK_SIZES_ALL] = {
78         0, // BLOCK_4X4
79         1, // BLOCK_4X8
80         1, // BLOCK_8X4
81         0, // BLOCK_8X8
82         1, // BLOCK_8X16
83         1, // BLOCK_16X8
84         0, // BLOCK_16X16
85         1, // BLOCK_16X32
86         1, // BLOCK_32X16
87         0, // BLOCK_32X32
88         1, // BLOCK_32X64
89         1, // BLOCK_64X32
90         0, // BLOCK_64X64
91         0, // BLOCK_64X128
92         0, // BLOCK_128X64
93         0, // BLOCK_128X128
94         1, // BLOCK_4X16
95         1, // BLOCK_16X4
96         1, // BLOCK_8X32
97         1, // BLOCK_32X8
98         1, // BLOCK_16X64
99         1, // BLOCK_64X16
100     };
101 
102     return lut[bsize];
103 }
is_rect_tx_allowed(const MbModeInfo * mbmi)104 static INLINE int is_rect_tx_allowed(/*const MacroBlockD *xd,*/
105                                      const MbModeInfo *mbmi) {
106     return is_rect_tx_allowed_bsize(mbmi->block_mi.sb_type) /*&&
107             !xd->lossless[mbmi->segment_id]*/
108         ;
109 }
110 
111 ////////////////////// QUANTIZATION//////////////
112 typedef struct QuantParam {
113     int32_t      log_scale;
114     TxSize       tx_size;
115     const QmVal *qmatrix;
116     const QmVal *iqmatrix;
117 } QuantParam;
118 
119 static const uint32_t q_func[] = {26214, 23302, 20560, 18396, 16384, 14564};
120 
121 extern EbErrorType av1_estimate_transform(int16_t *residual_buffer, uint32_t residual_stride,
122                                           int32_t *coeff_buffer, uint32_t coeff_stride,
123                                           TxSize transform_size, uint64_t *three_quad_energy,
124                                           uint32_t bit_depth, TxType transform_type,
125                                           PlaneType            component_type,
126                                           EB_TRANS_COEFF_SHAPE trans_coeff_shape);
127 
128 extern int32_t av1_quantize_inv_quantize(
129     PictureControlSet *pcs_ptr, ModeDecisionContext *md_context, int32_t *coeff,
130     const uint32_t coeff_stride, int32_t *quant_coeff, int32_t *recon_coeff, uint32_t qindex,
131     int32_t segmentation_qp_offset, uint32_t width, uint32_t height, TxSize txsize, uint16_t *eob,
132     uint32_t *y_count_non_zero_coeffs, uint32_t component_type, uint32_t bit_increment,
133     TxType tx_type, ModeDecisionCandidateBuffer *candidate_buffer, int16_t txb_skip_context,
134     int16_t dc_sign_context, PredictionMode pred_mode, EbBool is_intra_bc, uint32_t lambda,
135     EbBool is_encode_pass);
136 void svt_av1_wht_fwd_txfm(int16_t *src_diff, int bw,
137                   int32_t *coeff, TxSize tx_size, EB_TRANS_COEFF_SHAPE pf_shape,
138                   int bit_depth, int is_hbd);
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif // EbTransforms_h
145