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