• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_VPX_DSP_INV_TXFM_H_
12 #define VPX_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 
check_range(tran_high_t input)24 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   return input;
36 }
37 
dct_const_round_shift(tran_high_t input)38 static INLINE tran_high_t dct_const_round_shift(tran_high_t input) {
39   tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
40   return (tran_high_t)rv;
41 }
42 
43 #if CONFIG_VP9_HIGHBITDEPTH
highbd_check_range(tran_high_t input,int bd)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 #define WRAPLOW(x) ((((int32_t)check_range(x)) << 16) >> 16)
80 #if CONFIG_VP9_HIGHBITDEPTH
81 #define HIGHBD_WRAPLOW(x, bd) \
82   ((((int32_t)highbd_check_range((x), bd)) << (24 - bd)) >> (24 - bd))
83 #endif  // CONFIG_VP9_HIGHBITDEPTH
84 
85 #else  // CONFIG_EMULATE_HARDWARE
86 
87 #define WRAPLOW(x) ((int32_t)check_range(x))
88 #if CONFIG_VP9_HIGHBITDEPTH
89 #define HIGHBD_WRAPLOW(x, bd) ((int32_t)highbd_check_range((x), bd))
90 #endif  // CONFIG_VP9_HIGHBITDEPTH
91 #endif  // CONFIG_EMULATE_HARDWARE
92 
93 void idct4_c(const tran_low_t *input, tran_low_t *output);
94 void idct8_c(const tran_low_t *input, tran_low_t *output);
95 void idct16_c(const tran_low_t *input, tran_low_t *output);
96 void idct32_c(const tran_low_t *input, tran_low_t *output);
97 void iadst4_c(const tran_low_t *input, tran_low_t *output);
98 void iadst8_c(const tran_low_t *input, tran_low_t *output);
99 void iadst16_c(const tran_low_t *input, tran_low_t *output);
100 
101 #if CONFIG_VP9_HIGHBITDEPTH
102 void vpx_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd);
103 void vpx_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd);
104 void vpx_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd);
105 
106 void vpx_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd);
107 void vpx_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd);
108 void vpx_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd);
109 
highbd_clip_pixel_add(uint16_t dest,tran_high_t trans,int bd)110 static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans,
111                                              int bd) {
112   trans = HIGHBD_WRAPLOW(trans, bd);
113   return clip_pixel_highbd(dest + (int)trans, bd);
114 }
115 #endif
116 
clip_pixel_add(uint8_t dest,tran_high_t trans)117 static INLINE uint8_t clip_pixel_add(uint8_t dest, tran_high_t trans) {
118   trans = WRAPLOW(trans);
119   return clip_pixel(dest + (int)trans);
120 }
121 #ifdef __cplusplus
122 }  // extern "C"
123 #endif
124 
125 #endif  // VPX_VPX_DSP_INV_TXFM_H_
126