inv_txfm.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_DSP_INV_TXFM_H_
  11. #define 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,
  38. int bd) {
  39. #if CONFIG_COEFFICIENT_RANGE_CHECKING
  40. // For valid highbitdepth VP9 streams, intermediate stage coefficients will
  41. // stay within the ranges:
  42. // - 8 bit: signed 16 bit integer
  43. // - 10 bit: signed 18 bit integer
  44. // - 12 bit: signed 20 bit integer
  45. const int32_t int_max = (1 << (7 + bd)) - 1;
  46. const int32_t int_min = -int_max - 1;
  47. assert(int_min <= input);
  48. assert(input <= int_max);
  49. (void) int_min;
  50. #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
  51. (void) bd;
  52. return input;
  53. }
  54. static INLINE tran_high_t highbd_dct_const_round_shift(tran_high_t input) {
  55. tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
  56. return (tran_high_t)rv;
  57. }
  58. #endif // CONFIG_VP9_HIGHBITDEPTH
  59. #if CONFIG_EMULATE_HARDWARE
  60. // When CONFIG_EMULATE_HARDWARE is 1 the transform performs a
  61. // non-normative method to handle overflows. A stream that causes
  62. // overflows in the inverse transform is considered invalid in VP9,
  63. // and a hardware implementer is free to choose any reasonable
  64. // method to handle overflows. However to aid in hardware
  65. // verification they can use a specific implementation of the
  66. // WRAPLOW() macro below that is identical to their intended
  67. // hardware implementation (and also use configure options to trigger
  68. // the C-implementation of the transform).
  69. //
  70. // The particular WRAPLOW implementation below performs strict
  71. // overflow wrapping to match common hardware implementations.
  72. // bd of 8 uses trans_low with 16bits, need to remove 16bits
  73. // bd of 10 uses trans_low with 18bits, need to remove 14bits
  74. // bd of 12 uses trans_low with 20bits, need to remove 12bits
  75. // bd of x uses trans_low with 8+x bits, need to remove 24-x bits
  76. #define WRAPLOW(x) ((((int32_t)check_range(x)) << 16) >> 16)
  77. #if CONFIG_VP9_HIGHBITDEPTH
  78. #define HIGHBD_WRAPLOW(x, bd) \
  79. ((((int32_t)highbd_check_range((x), bd)) << (24 - bd)) >> (24 - bd))
  80. #endif // CONFIG_VP9_HIGHBITDEPTH
  81. #else // CONFIG_EMULATE_HARDWARE
  82. #define WRAPLOW(x) ((int32_t)check_range(x))
  83. #if CONFIG_VP9_HIGHBITDEPTH
  84. #define HIGHBD_WRAPLOW(x, bd) \
  85. ((int32_t)highbd_check_range((x), bd))
  86. #endif // CONFIG_VP9_HIGHBITDEPTH
  87. #endif // CONFIG_EMULATE_HARDWARE
  88. void idct4_c(const tran_low_t *input, tran_low_t *output);
  89. void idct8_c(const tran_low_t *input, tran_low_t *output);
  90. void idct16_c(const tran_low_t *input, tran_low_t *output);
  91. void idct32_c(const tran_low_t *input, tran_low_t *output);
  92. void iadst4_c(const tran_low_t *input, tran_low_t *output);
  93. void iadst8_c(const tran_low_t *input, tran_low_t *output);
  94. void iadst16_c(const tran_low_t *input, tran_low_t *output);
  95. #if CONFIG_VP9_HIGHBITDEPTH
  96. void vpx_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd);
  97. void vpx_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd);
  98. void vpx_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd);
  99. void vpx_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd);
  100. void vpx_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd);
  101. void vpx_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd);
  102. static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans,
  103. int bd) {
  104. trans = HIGHBD_WRAPLOW(trans, bd);
  105. return clip_pixel_highbd(dest + (int)trans, bd);
  106. }
  107. #endif
  108. static INLINE uint8_t clip_pixel_add(uint8_t dest, tran_high_t trans) {
  109. trans = WRAPLOW(trans);
  110. return clip_pixel(dest + (int)trans);
  111. }
  112. #ifdef __cplusplus
  113. } // extern "C"
  114. #endif
  115. #endif // VPX_DSP_INV_TXFM_H_