2
0

inv_txfm.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef VPX_VPX_DSP_INV_TXFM_H_
  11. #define VPX_VPX_DSP_INV_TXFM_H_
  12. #include <assert.h>
  13. #include "./vpx_config.h"
  14. #include "vpx_dsp/txfm_common.h"
  15. #include "vpx_ports/mem.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. static INLINE tran_high_t check_range(tran_high_t input) {
  20. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  21. // For valid VP9 input streams, intermediate stage coefficients should always
  22. // stay within the range of a signed 16 bit integer. Coefficients can go out
  23. // of this range for invalid/corrupt VP9 streams. However, strictly checking
  24. // this range for every intermediate coefficient can burdensome for a decoder,
  25. // therefore the following assertion is only enabled when configured with
  26. // --enable-coefficient-range-checking.
  27. assert(INT16_MIN <= input);
  28. assert(input <= INT16_MAX);
  29. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  30. return input;
  31. }
  32. static INLINE tran_high_t dct_const_round_shift(tran_high_t input) {
  33. tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
  34. return (tran_high_t)rv;
  35. }
  36. #if CONFIG_VP9_HIGHBITDEPTH
  37. static INLINE tran_high_t highbd_check_range(tran_high_t input, int bd) {
  38. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  39. // For valid highbitdepth VP9 streams, intermediate stage coefficients will
  40. // stay within the ranges:
  41. // - 8 bit: signed 16 bit integer
  42. // - 10 bit: signed 18 bit integer
  43. // - 12 bit: signed 20 bit integer
  44. const int32_t int_max = (1 << (7 + bd)) - 1;
  45. const int32_t int_min = -int_max - 1;
  46. assert(int_min <= input);
  47. assert(input <= int_max);
  48. (void)int_min;
  49. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  50. (void)bd;
  51. return input;
  52. }
  53. #endif // CONFIG_VP9_HIGHBITDEPTH
  54. #if CONFIG_EMULATE_HARDWARE
  55. // When CONFIG_EMULATE_HARDWARE is 1 the transform performs a
  56. // non-normative method to handle overflows. A stream that causes
  57. // overflows in the inverse transform is considered invalid in VP9,
  58. // and a hardware implementer is free to choose any reasonable
  59. // method to handle overflows. However to aid in hardware
  60. // verification they can use a specific implementation of the
  61. // WRAPLOW() macro below that is identical to their intended
  62. // hardware implementation (and also use configure options to trigger
  63. // the C-implementation of the transform).
  64. //
  65. // The particular WRAPLOW implementation below performs strict
  66. // overflow wrapping to match common hardware implementations.
  67. // bd of 8 uses trans_low with 16bits, need to remove 16bits
  68. // bd of 10 uses trans_low with 18bits, need to remove 14bits
  69. // bd of 12 uses trans_low with 20bits, need to remove 12bits
  70. // bd of x uses trans_low with 8+x bits, need to remove 24-x bits
  71. #define WRAPLOW(x) ((((int32_t)check_range(x)) << 16) >> 16)
  72. #if CONFIG_VP9_HIGHBITDEPTH
  73. #define HIGHBD_WRAPLOW(x, bd) \
  74. ((((int32_t)highbd_check_range((x), bd)) << (24 - bd)) >> (24 - bd))
  75. #endif // CONFIG_VP9_HIGHBITDEPTH
  76. #else // CONFIG_EMULATE_HARDWARE
  77. #define WRAPLOW(x) ((int32_t)check_range(x))
  78. #if CONFIG_VP9_HIGHBITDEPTH
  79. #define HIGHBD_WRAPLOW(x, bd) ((int32_t)highbd_check_range((x), bd))
  80. #endif // CONFIG_VP9_HIGHBITDEPTH
  81. #endif // CONFIG_EMULATE_HARDWARE
  82. void idct4_c(const tran_low_t *input, tran_low_t *output);
  83. void idct8_c(const tran_low_t *input, tran_low_t *output);
  84. void idct16_c(const tran_low_t *input, tran_low_t *output);
  85. void idct32_c(const tran_low_t *input, tran_low_t *output);
  86. void iadst4_c(const tran_low_t *input, tran_low_t *output);
  87. void iadst8_c(const tran_low_t *input, tran_low_t *output);
  88. void iadst16_c(const tran_low_t *input, tran_low_t *output);
  89. #if CONFIG_VP9_HIGHBITDEPTH
  90. void vpx_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd);
  91. void vpx_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd);
  92. void vpx_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd);
  93. void vpx_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd);
  94. void vpx_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd);
  95. void vpx_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd);
  96. static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans,
  97. int bd) {
  98. trans = HIGHBD_WRAPLOW(trans, bd);
  99. return clip_pixel_highbd(dest + (int)trans, bd);
  100. }
  101. #endif
  102. static INLINE uint8_t clip_pixel_add(uint8_t dest, tran_high_t trans) {
  103. trans = WRAPLOW(trans);
  104. return clip_pixel(dest + (int)trans);
  105. }
  106. #ifdef __cplusplus
  107. } // extern "C"
  108. #endif
  109. #endif // VPX_VPX_DSP_INV_TXFM_H_