Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -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 | 9c01aa1 | 2016-09-01 14:32:49 -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 | #ifndef AOM_DSP_TXFM_COMMON_H_ |
| 13 | #define AOM_DSP_TXFM_COMMON_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | |
| 17 | // Constants and Macros used by all idct/dct functions |
| 18 | #define DCT_CONST_BITS 14 |
| 19 | #define DCT_CONST_ROUNDING (1 << (DCT_CONST_BITS - 1)) |
| 20 | |
| 21 | #define UNIT_QUANT_SHIFT 2 |
| 22 | #define UNIT_QUANT_FACTOR (1 << UNIT_QUANT_SHIFT) |
| 23 | |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame^] | 24 | typedef struct txfm_param { |
| 25 | // for both forward and inverse transforms |
| 26 | int tx_type; |
| 27 | int tx_size; |
| 28 | int lossless; |
| 29 | int bd; |
| 30 | #if CONFIG_LGT |
| 31 | int is_inter; |
| 32 | int stride; |
| 33 | int mode; |
| 34 | uint8_t *dst; |
| 35 | #endif |
| 36 | // for inverse transforms only |
| 37 | #if CONFIG_ADAPT_SCAN |
| 38 | const int16_t *eob_threshold; |
| 39 | #endif |
| 40 | int eob; |
| 41 | } TxfmParam; |
| 42 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | // Constants: |
| 44 | // for (int i = 1; i< 32; ++i) |
| 45 | // printf("static const int cospi_%d_64 = %.0f;\n", i, |
| 46 | // round(16384 * cos(i*M_PI/64))); |
| 47 | // Note: sin(k*Pi/64) = cos((32-k)*Pi/64) |
| 48 | static const tran_high_t cospi_1_64 = 16364; |
| 49 | static const tran_high_t cospi_2_64 = 16305; |
| 50 | static const tran_high_t cospi_3_64 = 16207; |
| 51 | static const tran_high_t cospi_4_64 = 16069; |
| 52 | static const tran_high_t cospi_5_64 = 15893; |
| 53 | static const tran_high_t cospi_6_64 = 15679; |
| 54 | static const tran_high_t cospi_7_64 = 15426; |
| 55 | static const tran_high_t cospi_8_64 = 15137; |
| 56 | static const tran_high_t cospi_9_64 = 14811; |
| 57 | static const tran_high_t cospi_10_64 = 14449; |
| 58 | static const tran_high_t cospi_11_64 = 14053; |
| 59 | static const tran_high_t cospi_12_64 = 13623; |
| 60 | static const tran_high_t cospi_13_64 = 13160; |
| 61 | static const tran_high_t cospi_14_64 = 12665; |
| 62 | static const tran_high_t cospi_15_64 = 12140; |
| 63 | static const tran_high_t cospi_16_64 = 11585; |
| 64 | static const tran_high_t cospi_17_64 = 11003; |
| 65 | static const tran_high_t cospi_18_64 = 10394; |
| 66 | static const tran_high_t cospi_19_64 = 9760; |
| 67 | static const tran_high_t cospi_20_64 = 9102; |
| 68 | static const tran_high_t cospi_21_64 = 8423; |
| 69 | static const tran_high_t cospi_22_64 = 7723; |
| 70 | static const tran_high_t cospi_23_64 = 7005; |
| 71 | static const tran_high_t cospi_24_64 = 6270; |
| 72 | static const tran_high_t cospi_25_64 = 5520; |
| 73 | static const tran_high_t cospi_26_64 = 4756; |
| 74 | static const tran_high_t cospi_27_64 = 3981; |
| 75 | static const tran_high_t cospi_28_64 = 3196; |
| 76 | static const tran_high_t cospi_29_64 = 2404; |
| 77 | static const tran_high_t cospi_30_64 = 1606; |
| 78 | static const tran_high_t cospi_31_64 = 804; |
| 79 | |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 80 | // 16384 * sqrt(2) * sin(kPi/9) * 2 / 3 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 81 | static const tran_high_t sinpi_1_9 = 5283; |
| 82 | static const tran_high_t sinpi_2_9 = 9929; |
| 83 | static const tran_high_t sinpi_3_9 = 13377; |
| 84 | static const tran_high_t sinpi_4_9 = 15212; |
| 85 | |
| 86 | // 16384 * sqrt(2) |
| 87 | static const tran_high_t Sqrt2 = 23170; |
| 88 | |
Sarah Parker | 31c6650 | 2017-05-19 16:51:07 -0700 | [diff] [blame] | 89 | static INLINE tran_high_t fdct_round_shift(tran_high_t input) { |
| 90 | tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS); |
| 91 | return rv; |
| 92 | } |
Lester Lu | ad8290b | 2017-06-12 18:26:18 -0700 | [diff] [blame] | 93 | |
| 94 | #if CONFIG_LGT |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 95 | // The Line Graph Transforms (LGTs) matrices are written as follows. |
| 96 | // Each 2D array is 16384 times an LGT matrix, which is the matrix of |
| 97 | // eigenvectors of the graph Laplacian matrices for the line graph. |
| 98 | |
| 99 | // LGT4 name: lgt4_140 |
| 100 | // Self loops: 1.400, 0.000, 0.000, 0.000 |
Lester Lu | ad8290b | 2017-06-12 18:26:18 -0700 | [diff] [blame] | 101 | // Edges: 1.000, 1.000, 1.000 |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 102 | static const tran_high_t lgt4_140[4][4] = { |
| 103 | { 4206, 9518, 13524, 15674 }, |
| 104 | { 11552, 14833, 1560, -13453 }, |
| 105 | { 15391, -1906, -14393, 9445 }, |
| 106 | { 12201, -14921, 12016, -4581 }, |
Lester Lu | ad8290b | 2017-06-12 18:26:18 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 109 | // LGT4 name: lgt4_170 |
| 110 | // Self loops: 1.700, 0.000, 0.000, 0.000 |
| 111 | // Edges: 1.000, 1.000, 1.000 |
| 112 | static const tran_high_t lgt4_170[4][4] = { |
| 113 | { 3636, 9287, 13584, 15902 }, |
| 114 | { 10255, 15563, 2470, -13543 }, |
| 115 | { 14786, 711, -15249, 9231 }, |
| 116 | { 14138, -14420, 10663, -3920 }, |
| 117 | }; |
| 118 | |
| 119 | // LGT8 name: lgt8_150 |
| 120 | // Self loops: 1.500, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 |
| 121 | // Edges: 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000 |
| 122 | static const tran_high_t lgt8_150[8][8] = { |
| 123 | { 2075, 5110, 7958, 10511, 12677, 14376, 15544, 16140 }, |
| 124 | { 6114, 13307, 16196, 13845, 7015, -2084, -10509, -15534 }, |
| 125 | { 9816, 16163, 8717, -6168, -15790, -11936, 2104, 14348 }, |
| 126 | { 12928, 12326, -7340, -15653, 242, 15763, 6905, -12632 }, |
| 127 | { 15124, 3038, -16033, 1758, 15507, -6397, -13593, 10463 }, |
| 128 | { 15895, -7947, -7947, 15895, -7947, -7947, 15895, -7947 }, |
| 129 | { 14325, -15057, 9030, 1050, -10659, 15483, -13358, 5236 }, |
| 130 | { 9054, -12580, 14714, -15220, 14043, -11312, 7330, -2537 }, |
| 131 | }; |
| 132 | |
Lester Lu | ad8290b | 2017-06-12 18:26:18 -0700 | [diff] [blame] | 133 | // LGT8 name: lgt8_170 |
| 134 | // Self loops: 1.700, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 |
| 135 | // Edges: 1.000, 1.000, 1.000, 1.000, 1.000, 1.000, 1.000 |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 136 | static const tran_high_t lgt8_170[8][8] = { |
Lester Lu | ad8290b | 2017-06-12 18:26:18 -0700 | [diff] [blame] | 137 | { 1858, 4947, 7850, 10458, 12672, 14411, 15607, 16217 }, |
| 138 | { 5494, 13022, 16256, 14129, 7343, -1864, -10456, -15601 }, |
| 139 | { 8887, 16266, 9500, -5529, -15749, -12273, 1876, 14394 }, |
| 140 | { 11870, 13351, -6199, -15984, -590, 15733, 7273, -12644 }, |
| 141 | { 14248, 5137, -15991, 291, 15893, -5685, -13963, 10425 }, |
| 142 | { 15716, -5450, -10010, 15929, -6665, -8952, 16036, -7835 }, |
| 143 | { 15533, -13869, 6559, 3421, -12009, 15707, -13011, 5018 }, |
| 144 | { 11357, -13726, 14841, -14600, 13025, -10259, 6556, -2254 }, |
| 145 | }; |
| 146 | #endif // CONFIG_LGT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 147 | #endif // AOM_DSP_TXFM_COMMON_H_ |