txfm_common.h 5.9 KB

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