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 #ifndef AOM_AOM_DSP_TXFM_COMMON_H_
13 #define AOM_AOM_DSP_TXFM_COMMON_H_
14 
15 #include "aom_dsp/aom_dsp_common.h"
16 #include "av1/common/enums.h"
17 
18 // Constants and Macros used by all idct/dct functions
19 #define DCT_CONST_BITS 14
20 #define DCT_CONST_ROUNDING (1 << (DCT_CONST_BITS - 1))
21 
22 #define UNIT_QUANT_SHIFT 2
23 #define UNIT_QUANT_FACTOR (1 << UNIT_QUANT_SHIFT)
24 
25 typedef struct txfm_param {
26   // for both forward and inverse transforms
27   TX_TYPE tx_type;
28   TX_SIZE tx_size;
29   int lossless;
30   int bd;
31   // are the pixel buffers octets or shorts?  This should collapse to
32   // bd==8 implies !is_hbd, but that's not certain right now.
33   int is_hbd;
34   TxSetType tx_set_type;
35   // for inverse transforms only
36   int eob;
37 } TxfmParam;
38 
39 // Constants:
40 //  for (int i = 1; i< 32; ++i)
41 //    printf("static const int cospi_%d_64 = %.0f;\n", i,
42 //           round(16384 * cos(i*M_PI/64)));
43 // Note: sin(k*Pi/64) = cos((32-k)*Pi/64)
44 static const tran_high_t cospi_1_64 = 16364;
45 static const tran_high_t cospi_2_64 = 16305;
46 static const tran_high_t cospi_3_64 = 16207;
47 static const tran_high_t cospi_4_64 = 16069;
48 static const tran_high_t cospi_5_64 = 15893;
49 static const tran_high_t cospi_6_64 = 15679;
50 static const tran_high_t cospi_7_64 = 15426;
51 static const tran_high_t cospi_8_64 = 15137;
52 static const tran_high_t cospi_9_64 = 14811;
53 static const tran_high_t cospi_10_64 = 14449;
54 static const tran_high_t cospi_11_64 = 14053;
55 static const tran_high_t cospi_12_64 = 13623;
56 static const tran_high_t cospi_13_64 = 13160;
57 static const tran_high_t cospi_14_64 = 12665;
58 static const tran_high_t cospi_15_64 = 12140;
59 static const tran_high_t cospi_16_64 = 11585;
60 static const tran_high_t cospi_17_64 = 11003;
61 static const tran_high_t cospi_18_64 = 10394;
62 static const tran_high_t cospi_19_64 = 9760;
63 static const tran_high_t cospi_20_64 = 9102;
64 static const tran_high_t cospi_21_64 = 8423;
65 static const tran_high_t cospi_22_64 = 7723;
66 static const tran_high_t cospi_23_64 = 7005;
67 static const tran_high_t cospi_24_64 = 6270;
68 static const tran_high_t cospi_25_64 = 5520;
69 static const tran_high_t cospi_26_64 = 4756;
70 static const tran_high_t cospi_27_64 = 3981;
71 static const tran_high_t cospi_28_64 = 3196;
72 static const tran_high_t cospi_29_64 = 2404;
73 static const tran_high_t cospi_30_64 = 1606;
74 static const tran_high_t cospi_31_64 = 804;
75 
76 //  16384 * sqrt(2) * sin(kPi/9) * 2 / 3
77 static const tran_high_t sinpi_1_9 = 5283;
78 static const tran_high_t sinpi_2_9 = 9929;
79 static const tran_high_t sinpi_3_9 = 13377;
80 static const tran_high_t sinpi_4_9 = 15212;
81 
82 // 16384 * sqrt(2)
83 static const tran_high_t Sqrt2 = 23170;
84 static const tran_high_t InvSqrt2 = 11585;
85 
fdct_round_shift(tran_high_t input)86 static INLINE tran_high_t fdct_round_shift(tran_high_t input) {
87   tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
88   return rv;
89 }
90 
91 #endif  // AOM_AOM_DSP_TXFM_COMMON_H_
92