Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / source / libvpx / vp9 / common / vp9_idct.h
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 VP9_COMMON_VP9_IDCT_H_
12 #define VP9_COMMON_VP9_IDCT_H_
13
14 #include <assert.h>
15
16 #include "./vpx_config.h"
17 #include "vp9/common/vp9_common.h"
18 #include "vp9/common/vp9_enums.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 // Constants and Macros used by all idct/dct functions
25 #define DCT_CONST_BITS 14
26 #define DCT_CONST_ROUNDING  (1 << (DCT_CONST_BITS - 1))
27
28 #define UNIT_QUANT_SHIFT 2
29 #define UNIT_QUANT_FACTOR (1 << UNIT_QUANT_SHIFT)
30
31 #define pair_set_epi16(a, b) \
32   _mm_set_epi16(b, a, b, a, b, a, b, a)
33
34 #define dual_set_epi16(a, b) \
35   _mm_set_epi16(b, b, b, b, a, a, a, a)
36
37 // Constants:
38 //  for (int i = 1; i< 32; ++i)
39 //    printf("static const int cospi_%d_64 = %.0f;\n", i,
40 //           round(16384 * cos(i*M_PI/64)));
41 // Note: sin(k*Pi/64) = cos((32-k)*Pi/64)
42 static const tran_high_t cospi_1_64  = 16364;
43 static const tran_high_t cospi_2_64  = 16305;
44 static const tran_high_t cospi_3_64  = 16207;
45 static const tran_high_t cospi_4_64  = 16069;
46 static const tran_high_t cospi_5_64  = 15893;
47 static const tran_high_t cospi_6_64  = 15679;
48 static const tran_high_t cospi_7_64  = 15426;
49 static const tran_high_t cospi_8_64  = 15137;
50 static const tran_high_t cospi_9_64  = 14811;
51 static const tran_high_t cospi_10_64 = 14449;
52 static const tran_high_t cospi_11_64 = 14053;
53 static const tran_high_t cospi_12_64 = 13623;
54 static const tran_high_t cospi_13_64 = 13160;
55 static const tran_high_t cospi_14_64 = 12665;
56 static const tran_high_t cospi_15_64 = 12140;
57 static const tran_high_t cospi_16_64 = 11585;
58 static const tran_high_t cospi_17_64 = 11003;
59 static const tran_high_t cospi_18_64 = 10394;
60 static const tran_high_t cospi_19_64 = 9760;
61 static const tran_high_t cospi_20_64 = 9102;
62 static const tran_high_t cospi_21_64 = 8423;
63 static const tran_high_t cospi_22_64 = 7723;
64 static const tran_high_t cospi_23_64 = 7005;
65 static const tran_high_t cospi_24_64 = 6270;
66 static const tran_high_t cospi_25_64 = 5520;
67 static const tran_high_t cospi_26_64 = 4756;
68 static const tran_high_t cospi_27_64 = 3981;
69 static const tran_high_t cospi_28_64 = 3196;
70 static const tran_high_t cospi_29_64 = 2404;
71 static const tran_high_t cospi_30_64 = 1606;
72 static const tran_high_t cospi_31_64 = 804;
73
74 //  16384 * sqrt(2) * sin(kPi/9) * 2 / 3
75 static const tran_high_t sinpi_1_9 = 5283;
76 static const tran_high_t sinpi_2_9 = 9929;
77 static const tran_high_t sinpi_3_9 = 13377;
78 static const tran_high_t sinpi_4_9 = 15212;
79
80 static INLINE tran_low_t check_range(tran_high_t input) {
81 #if CONFIG_VP9_HIGHBITDEPTH
82   // For valid highbitdepth VP9 streams, intermediate stage coefficients will
83   // stay within the ranges:
84   // - 8 bit: signed 16 bit integer
85   // - 10 bit: signed 18 bit integer
86   // - 12 bit: signed 20 bit integer
87 #elif CONFIG_COEFFICIENT_RANGE_CHECKING
88   // For valid VP9 input streams, intermediate stage coefficients should always
89   // stay within the range of a signed 16 bit integer. Coefficients can go out
90   // of this range for invalid/corrupt VP9 streams. However, strictly checking
91   // this range for every intermediate coefficient can burdensome for a decoder,
92   // therefore the following assertion is only enabled when configured with
93   // --enable-coefficient-range-checking.
94   assert(INT16_MIN <= input);
95   assert(input <= INT16_MAX);
96 #endif
97   return (tran_low_t)input;
98 }
99
100 static INLINE tran_low_t dct_const_round_shift(tran_high_t input) {
101   tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
102   return check_range(rv);
103 }
104
105 typedef void (*transform_1d)(const tran_low_t*, tran_low_t*);
106
107 typedef struct {
108   transform_1d cols, rows;  // vertical and horizontal
109 } transform_2d;
110
111 #if CONFIG_VP9_HIGHBITDEPTH
112 typedef void (*highbd_transform_1d)(const tran_low_t*, tran_low_t*, int bd);
113
114 typedef struct {
115   highbd_transform_1d cols, rows;  // vertical and horizontal
116 } highbd_transform_2d;
117 #endif  // CONFIG_VP9_HIGHBITDEPTH
118
119 void vp9_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
120                      int eob);
121 void vp9_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
122                      int eob);
123 void vp9_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
124                      int eob);
125 void vp9_idct16x16_add(const tran_low_t *input, uint8_t *dest, int stride, int
126                        eob);
127 void vp9_idct32x32_add(const tran_low_t *input, uint8_t *dest, int stride,
128                        int eob);
129
130 void vp9_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
131                     int stride, int eob);
132 void vp9_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
133                     int stride, int eob);
134 void vp9_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
135                       int stride, int eob);
136
137 #if CONFIG_VP9_HIGHBITDEPTH
138 void vp9_highbd_iwht4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
139                             int eob, int bd);
140 void vp9_highbd_idct4x4_add(const tran_low_t *input, uint8_t *dest, int stride,
141                             int eob, int bd);
142 void vp9_highbd_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride,
143                             int eob, int bd);
144 void vp9_highbd_idct16x16_add(const tran_low_t *input, uint8_t *dest,
145                               int stride, int eob, int bd);
146 void vp9_highbd_idct32x32_add(const tran_low_t *input, uint8_t *dest,
147                               int stride, int eob, int bd);
148 void vp9_highbd_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input,
149                            uint8_t *dest, int stride, int eob, int bd);
150 void vp9_highbd_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input,
151                            uint8_t *dest, int stride, int eob, int bd);
152 void vp9_highbd_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input,
153                              uint8_t *dest, int stride, int eob, int bd);
154 #endif  // CONFIG_VP9_HIGHBITDEPTH
155 #ifdef __cplusplus
156 }  // extern "C"
157 #endif
158
159 #endif  // VP9_COMMON_VP9_IDCT_H_