Merge changes from topic 'missing-proto'
[aom.git] / vpx_dsp / inv_txfm.h
blob23588139edd6dc1d616c7f071070f99f5d629977
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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 */
11 #ifndef VPX_DSP_INV_TXFM_H_
12 #define VPX_DSP_INV_TXFM_H_
14 #include <assert.h>
16 #include "./vpx_config.h"
17 #include "vpx_dsp/txfm_common.h"
18 #include "vpx_ports/mem.h"
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
24 static INLINE tran_low_t check_range(tran_high_t input) {
25 #if CONFIG_COEFFICIENT_RANGE_CHECKING
26 // For valid VP9 input streams, intermediate stage coefficients should always
27 // stay within the range of a signed 16 bit integer. Coefficients can go out
28 // of this range for invalid/corrupt VP9 streams. However, strictly checking
29 // this range for every intermediate coefficient can burdensome for a decoder,
30 // therefore the following assertion is only enabled when configured with
31 // --enable-coefficient-range-checking.
32 assert(INT16_MIN <= input);
33 assert(input <= INT16_MAX);
34 #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
35 return (tran_low_t)input;
38 static INLINE tran_low_t dct_const_round_shift(tran_high_t input) {
39 tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
40 return check_range(rv);
43 #if CONFIG_VP9_HIGHBITDEPTH
44 static INLINE tran_low_t highbd_check_range(tran_high_t input,
45 int bd) {
46 #if CONFIG_COEFFICIENT_RANGE_CHECKING
47 // For valid highbitdepth VP9 streams, intermediate stage coefficients will
48 // stay within the ranges:
49 // - 8 bit: signed 16 bit integer
50 // - 10 bit: signed 18 bit integer
51 // - 12 bit: signed 20 bit integer
52 const int32_t int_max = (1 << (7 + bd)) - 1;
53 const int32_t int_min = -int_max - 1;
54 assert(int_min <= input);
55 assert(input <= int_max);
56 (void) int_min;
57 #endif // CONFIG_COEFFICIENT_RANGE_CHECKING
58 (void) bd;
59 return (tran_low_t)input;
62 static INLINE tran_low_t highbd_dct_const_round_shift(tran_high_t input,
63 int bd) {
64 tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
65 return highbd_check_range(rv, bd);
67 #endif // CONFIG_VP9_HIGHBITDEPTH
69 #if CONFIG_EMULATE_HARDWARE
70 // When CONFIG_EMULATE_HARDWARE is 1 the transform performs a
71 // non-normative method to handle overflows. A stream that causes
72 // overflows in the inverse transform is considered invalid in VP9,
73 // and a hardware implementer is free to choose any reasonable
74 // method to handle overflows. However to aid in hardware
75 // verification they can use a specific implementation of the
76 // WRAPLOW() macro below that is identical to their intended
77 // hardware implementation (and also use configure options to trigger
78 // the C-implementation of the transform).
80 // The particular WRAPLOW implementation below performs strict
81 // overflow wrapping to match common hardware implementations.
82 // bd of 8 uses trans_low with 16bits, need to remove 16bits
83 // bd of 10 uses trans_low with 18bits, need to remove 14bits
84 // bd of 12 uses trans_low with 20bits, need to remove 12bits
85 // bd of x uses trans_low with 8+x bits, need to remove 24-x bits
86 #define WRAPLOW(x, bd) ((((int32_t)(x)) << (24 - bd)) >> (24 - bd))
87 #else
88 #define WRAPLOW(x, bd) ((int32_t)(x))
89 #endif // CONFIG_EMULATE_HARDWARE
91 void idct4_c(const tran_low_t *input, tran_low_t *output);
92 void idct8_c(const tran_low_t *input, tran_low_t *output);
93 void idct16_c(const tran_low_t *input, tran_low_t *output);
94 void idct32_c(const tran_low_t *input, tran_low_t *output);
95 void iadst4_c(const tran_low_t *input, tran_low_t *output);
96 void iadst8_c(const tran_low_t *input, tran_low_t *output);
97 void iadst16_c(const tran_low_t *input, tran_low_t *output);
99 #if CONFIG_VP9_HIGHBITDEPTH
100 void vpx_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd);
101 void vpx_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd);
102 void vpx_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd);
104 void vpx_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd);
105 void vpx_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd);
106 void vpx_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd);
108 static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans,
109 int bd) {
110 trans = WRAPLOW(trans, bd);
111 return clip_pixel_highbd(WRAPLOW(dest + trans, bd), bd);
113 #endif
115 static INLINE uint8_t clip_pixel_add(uint8_t dest, tran_high_t trans) {
116 trans = WRAPLOW(trans, 8);
117 return clip_pixel(WRAPLOW(dest + trans, 8));
119 #ifdef __cplusplus
120 } // extern "C"
121 #endif
123 #endif // VPX_DSP_INV_TXFM_H_