1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AOM_DSP_TXFM_COMMON_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AOM_DSP_TXFM_COMMON_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/aom_dsp_common.h"
16*77c1e3ccSAndroid Build Coastguard Worker
17*77c1e3ccSAndroid Build Coastguard Worker // Constants and Macros used by all idct/dct functions
18*77c1e3ccSAndroid Build Coastguard Worker #define DCT_CONST_BITS 14
19*77c1e3ccSAndroid Build Coastguard Worker #define DCT_CONST_ROUNDING (1 << (DCT_CONST_BITS - 1))
20*77c1e3ccSAndroid Build Coastguard Worker
21*77c1e3ccSAndroid Build Coastguard Worker #define UNIT_QUANT_SHIFT 2
22*77c1e3ccSAndroid Build Coastguard Worker #define UNIT_QUANT_FACTOR (1 << UNIT_QUANT_SHIFT)
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker // block transform size
25*77c1e3ccSAndroid Build Coastguard Worker enum {
26*77c1e3ccSAndroid Build Coastguard Worker TX_4X4, // 4x4 transform
27*77c1e3ccSAndroid Build Coastguard Worker TX_8X8, // 8x8 transform
28*77c1e3ccSAndroid Build Coastguard Worker TX_16X16, // 16x16 transform
29*77c1e3ccSAndroid Build Coastguard Worker TX_32X32, // 32x32 transform
30*77c1e3ccSAndroid Build Coastguard Worker TX_64X64, // 64x64 transform
31*77c1e3ccSAndroid Build Coastguard Worker TX_4X8, // 4x8 transform
32*77c1e3ccSAndroid Build Coastguard Worker TX_8X4, // 8x4 transform
33*77c1e3ccSAndroid Build Coastguard Worker TX_8X16, // 8x16 transform
34*77c1e3ccSAndroid Build Coastguard Worker TX_16X8, // 16x8 transform
35*77c1e3ccSAndroid Build Coastguard Worker TX_16X32, // 16x32 transform
36*77c1e3ccSAndroid Build Coastguard Worker TX_32X16, // 32x16 transform
37*77c1e3ccSAndroid Build Coastguard Worker TX_32X64, // 32x64 transform
38*77c1e3ccSAndroid Build Coastguard Worker TX_64X32, // 64x32 transform
39*77c1e3ccSAndroid Build Coastguard Worker TX_4X16, // 4x16 transform
40*77c1e3ccSAndroid Build Coastguard Worker TX_16X4, // 16x4 transform
41*77c1e3ccSAndroid Build Coastguard Worker TX_8X32, // 8x32 transform
42*77c1e3ccSAndroid Build Coastguard Worker TX_32X8, // 32x8 transform
43*77c1e3ccSAndroid Build Coastguard Worker TX_16X64, // 16x64 transform
44*77c1e3ccSAndroid Build Coastguard Worker TX_64X16, // 64x16 transform
45*77c1e3ccSAndroid Build Coastguard Worker TX_SIZES_ALL, // Includes rectangular transforms
46*77c1e3ccSAndroid Build Coastguard Worker TX_SIZES = TX_4X8, // Does NOT include rectangular transforms
47*77c1e3ccSAndroid Build Coastguard Worker TX_SIZES_LARGEST = TX_64X64,
48*77c1e3ccSAndroid Build Coastguard Worker TX_INVALID = 255 // Invalid transform size
49*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(TX_SIZE);
50*77c1e3ccSAndroid Build Coastguard Worker
51*77c1e3ccSAndroid Build Coastguard Worker enum {
52*77c1e3ccSAndroid Build Coastguard Worker DCT_DCT, // DCT in both horizontal and vertical
53*77c1e3ccSAndroid Build Coastguard Worker ADST_DCT, // ADST in vertical, DCT in horizontal
54*77c1e3ccSAndroid Build Coastguard Worker DCT_ADST, // DCT in vertical, ADST in horizontal
55*77c1e3ccSAndroid Build Coastguard Worker ADST_ADST, // ADST in both directions
56*77c1e3ccSAndroid Build Coastguard Worker FLIPADST_DCT, // FLIPADST in vertical, DCT in horizontal
57*77c1e3ccSAndroid Build Coastguard Worker DCT_FLIPADST, // DCT in vertical, FLIPADST in horizontal
58*77c1e3ccSAndroid Build Coastguard Worker FLIPADST_FLIPADST, // FLIPADST in both directions
59*77c1e3ccSAndroid Build Coastguard Worker ADST_FLIPADST, // ADST in vertical, FLIPADST in horizontal
60*77c1e3ccSAndroid Build Coastguard Worker FLIPADST_ADST, // FLIPADST in vertical, ADST in horizontal
61*77c1e3ccSAndroid Build Coastguard Worker IDTX, // Identity in both directions
62*77c1e3ccSAndroid Build Coastguard Worker V_DCT, // DCT in vertical, identity in horizontal
63*77c1e3ccSAndroid Build Coastguard Worker H_DCT, // Identity in vertical, DCT in horizontal
64*77c1e3ccSAndroid Build Coastguard Worker V_ADST, // ADST in vertical, identity in horizontal
65*77c1e3ccSAndroid Build Coastguard Worker H_ADST, // Identity in vertical, ADST in horizontal
66*77c1e3ccSAndroid Build Coastguard Worker V_FLIPADST, // FLIPADST in vertical, identity in horizontal
67*77c1e3ccSAndroid Build Coastguard Worker H_FLIPADST, // Identity in vertical, FLIPADST in horizontal
68*77c1e3ccSAndroid Build Coastguard Worker TX_TYPES,
69*77c1e3ccSAndroid Build Coastguard Worker DCT_ADST_TX_MASK = 0x000F, // Either DCT or ADST in each direction
70*77c1e3ccSAndroid Build Coastguard Worker TX_TYPE_INVALID = 255, // Invalid transform type
71*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(TX_TYPE);
72*77c1e3ccSAndroid Build Coastguard Worker
73*77c1e3ccSAndroid Build Coastguard Worker enum {
74*77c1e3ccSAndroid Build Coastguard Worker // DCT only
75*77c1e3ccSAndroid Build Coastguard Worker EXT_TX_SET_DCTONLY,
76*77c1e3ccSAndroid Build Coastguard Worker // DCT + Identity only
77*77c1e3ccSAndroid Build Coastguard Worker EXT_TX_SET_DCT_IDTX,
78*77c1e3ccSAndroid Build Coastguard Worker // Discrete Trig transforms w/o flip (4) + Identity (1)
79*77c1e3ccSAndroid Build Coastguard Worker EXT_TX_SET_DTT4_IDTX,
80*77c1e3ccSAndroid Build Coastguard Worker // Discrete Trig transforms w/o flip (4) + Identity (1) + 1D Hor/vert DCT (2)
81*77c1e3ccSAndroid Build Coastguard Worker EXT_TX_SET_DTT4_IDTX_1DDCT,
82*77c1e3ccSAndroid Build Coastguard Worker // Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver DCT (2)
83*77c1e3ccSAndroid Build Coastguard Worker EXT_TX_SET_DTT9_IDTX_1DDCT,
84*77c1e3ccSAndroid Build Coastguard Worker // Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver (6)
85*77c1e3ccSAndroid Build Coastguard Worker EXT_TX_SET_ALL16,
86*77c1e3ccSAndroid Build Coastguard Worker EXT_TX_SET_TYPES
87*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(TxSetType);
88*77c1e3ccSAndroid Build Coastguard Worker
89*77c1e3ccSAndroid Build Coastguard Worker typedef struct txfm_param {
90*77c1e3ccSAndroid Build Coastguard Worker // for both forward and inverse transforms
91*77c1e3ccSAndroid Build Coastguard Worker TX_TYPE tx_type;
92*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size;
93*77c1e3ccSAndroid Build Coastguard Worker int lossless;
94*77c1e3ccSAndroid Build Coastguard Worker int bd;
95*77c1e3ccSAndroid Build Coastguard Worker // are the pixel buffers octets or shorts? This should collapse to
96*77c1e3ccSAndroid Build Coastguard Worker // bd==8 implies !is_hbd, but that's not certain right now.
97*77c1e3ccSAndroid Build Coastguard Worker int is_hbd;
98*77c1e3ccSAndroid Build Coastguard Worker TxSetType tx_set_type;
99*77c1e3ccSAndroid Build Coastguard Worker // for inverse transforms only
100*77c1e3ccSAndroid Build Coastguard Worker int eob;
101*77c1e3ccSAndroid Build Coastguard Worker } TxfmParam;
102*77c1e3ccSAndroid Build Coastguard Worker
103*77c1e3ccSAndroid Build Coastguard Worker // Constants:
104*77c1e3ccSAndroid Build Coastguard Worker // for (int i = 1; i< 32; ++i)
105*77c1e3ccSAndroid Build Coastguard Worker // printf("static const int cospi_%d_64 = %.0f;\n", i,
106*77c1e3ccSAndroid Build Coastguard Worker // round(16384 * cos(i*PI/64)));
107*77c1e3ccSAndroid Build Coastguard Worker // Note: sin(k*Pi/64) = cos((32-k)*Pi/64)
108*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_1_64 = 16364;
109*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_2_64 = 16305;
110*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_3_64 = 16207;
111*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_4_64 = 16069;
112*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_5_64 = 15893;
113*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_6_64 = 15679;
114*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_7_64 = 15426;
115*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_8_64 = 15137;
116*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_9_64 = 14811;
117*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_10_64 = 14449;
118*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_11_64 = 14053;
119*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_12_64 = 13623;
120*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_13_64 = 13160;
121*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_14_64 = 12665;
122*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_15_64 = 12140;
123*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_16_64 = 11585;
124*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_17_64 = 11003;
125*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_18_64 = 10394;
126*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_19_64 = 9760;
127*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_20_64 = 9102;
128*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_21_64 = 8423;
129*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_22_64 = 7723;
130*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_23_64 = 7005;
131*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_24_64 = 6270;
132*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_25_64 = 5520;
133*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_26_64 = 4756;
134*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_27_64 = 3981;
135*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_28_64 = 3196;
136*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_29_64 = 2404;
137*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_30_64 = 1606;
138*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t cospi_31_64 = 804;
139*77c1e3ccSAndroid Build Coastguard Worker
140*77c1e3ccSAndroid Build Coastguard Worker // 16384 * sqrt(2) * sin(kPi/9) * 2 / 3
141*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t sinpi_1_9 = 5283;
142*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t sinpi_2_9 = 9929;
143*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t sinpi_3_9 = 13377;
144*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t sinpi_4_9 = 15212;
145*77c1e3ccSAndroid Build Coastguard Worker
146*77c1e3ccSAndroid Build Coastguard Worker // 16384 * sqrt(2)
147*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t Sqrt2 = 23170;
148*77c1e3ccSAndroid Build Coastguard Worker static const tran_high_t InvSqrt2 = 11585;
149*77c1e3ccSAndroid Build Coastguard Worker
fdct_round_shift(tran_high_t input)150*77c1e3ccSAndroid Build Coastguard Worker static inline tran_high_t fdct_round_shift(tran_high_t input) {
151*77c1e3ccSAndroid Build Coastguard Worker tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
152*77c1e3ccSAndroid Build Coastguard Worker return rv;
153*77c1e3ccSAndroid Build Coastguard Worker }
154*77c1e3ccSAndroid Build Coastguard Worker
155*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_AOM_DSP_TXFM_COMMON_H_
156