OSDN Git Service

b0d7d97b2d89e101c9b0355fb395c27cf6129db9
[android-x86/hardware-intel-intel-driver.git] / src / vp9_probs.h
1 /*
2  * Copyright © 2015 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */
25 /*
26  * This file defines some vp9 probability tables, and
27  * they are ported from libvpx (https://github.com/webmproject/libvpx/).
28  * The original copyright and licence statement as below.
29  */
30
31 /*
32  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
33  *
34  *  Use of this source code is governed by a BSD-style license
35  *  that can be found in the LICENSE file in the root of the source
36  *  tree. An additional intellectual property rights grant can be found
37  *  in the file PATENTS.  All contributing project authors may
38  *  be found in the AUTHORS file in the root of the source tree.
39  */
40
41 #ifndef VP9_PROBS_H
42 #define VP9_PROBS_H
43
44 #define TX_SIZE_CONTEXTS 2
45 #define TX_SIZES 4
46 #define PLANE_TYPES 2
47 #define SKIP_CONTEXTS 3
48 #define INTER_MODE_CONTEXTS 7
49 #define INTER_MODES 4
50 #define SWITCHABLE_FILTERS 3
51 #define SWITCHABLE_FILTER_CONTEXTS (SWITCHABLE_FILTERS + 1)
52 #define MAX_SEGMENTS 8
53 #define PREDICTION_PROBS 3
54 #define SEG_TREE_PROBS (MAX_SEGMENTS-1)
55 #define MV_JOINTS 4
56 #define INTRA_INTER_CONTEXTS 4
57 #define COMP_INTER_CONTEXTS 5
58 #define REF_CONTEXTS 5
59 #define BLOCK_SIZE_GROUPS 4
60 #define INTRA_MODES 10
61 #define PARTITION_PLOFFSET   4  // number of probability models per block size
62 #define PARTITION_CONTEXTS (4 * PARTITION_PLOFFSET)
63 #define PARTITION_TYPES 4
64 #define REF_TYPES 2  // intra=0, inter=1
65 #define COEF_BANDS 6
66 #define COEFF_CONTEXTS 6
67 #define UNCONSTRAINED_NODES         3
68 #define MV_CLASSES 11
69 #define CLASS0_BITS    1  /* bits at integer precision for class 0 */
70 #define CLASS0_SIZE    (1 << CLASS0_BITS)
71 #define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
72 #define MV_MAX_BITS    (MV_CLASSES + CLASS0_BITS + 2)
73 #define MV_FP_SIZE 4
74 #define FRAME_CONTEXTS_LOG2 2
75 #define FRAME_CONTEXTS (1 << FRAME_CONTEXTS_LOG2)
76
77 #define COEFF_PROB_SIZE 132
78 #define COEFF_PROB_NUM 3
79
80 #define TX_PROBS_IDX 0
81 #define COEFF_PROBS_IDX 64
82 #define INTRA_PROBS_IDX 1603
83 #define SEG_PROBS_IDX 2010
84
85 typedef uint8_t vp9_prob;
86
87 #define vpx_memset  memset
88 #define vpx_memcpy  memcpy
89
90 #define vp9_zero(dest) memset(&dest, 0, sizeof(dest))
91
92 #define vp9_copy(dest, src) {            \
93     assert(sizeof(dest) == sizeof(src)); \
94     vpx_memcpy(dest, src, sizeof(src));  \
95 }
96
97 struct tx_probs {
98   vp9_prob p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 3];
99   vp9_prob p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 2];
100   vp9_prob p32x32[TX_SIZE_CONTEXTS][TX_SIZES - 1];
101 };
102
103 struct tx_counts {
104   unsigned int p32x32[TX_SIZE_CONTEXTS][TX_SIZES];
105   unsigned int p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 1];
106   unsigned int p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 2];
107   unsigned int tx_totals[TX_SIZES];
108 };
109
110 typedef struct {
111   vp9_prob sign;
112   vp9_prob classes[MV_CLASSES - 1];
113   vp9_prob class0[CLASS0_SIZE - 1];
114   vp9_prob bits[MV_OFFSET_BITS];
115 } nmv_component;
116
117 //Modified the nmv_context from libvpx to suit our HW needs
118 typedef struct {
119   vp9_prob joints[MV_JOINTS-1];
120   nmv_component comps[2];
121   vp9_prob class0_fp0[CLASS0_SIZE][MV_FP_SIZE - 1];
122   vp9_prob fp0[MV_FP_SIZE - 1];
123   vp9_prob class0_fp1[CLASS0_SIZE][MV_FP_SIZE - 1];
124   vp9_prob fp1[MV_FP_SIZE - 1];
125   vp9_prob class0_hp[2];
126   vp9_prob hp[2];
127 } nmv_context;
128
129 //Modified the FRAME_CONTEXT from libvpx to suit our HW needs
130 typedef struct frame_contexts {
131   struct tx_probs tx_probs;
132   vp9_prob dummy1[52];
133   vp9_prob coeff_probs4x4[COEFF_PROB_SIZE][COEFF_PROB_NUM];
134   vp9_prob coeff_probs8x8[COEFF_PROB_SIZE][COEFF_PROB_NUM];
135   vp9_prob coeff_probs16x16[COEFF_PROB_SIZE][COEFF_PROB_NUM];
136   vp9_prob coeff_probs32x32[COEFF_PROB_SIZE][COEFF_PROB_NUM];
137   vp9_prob dummy2[16];
138   vp9_prob skip_probs[SKIP_CONTEXTS];
139   vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
140   vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
141                                  [SWITCHABLE_FILTERS - 1];
142   vp9_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
143   vp9_prob comp_inter_prob[COMP_INTER_CONTEXTS];
144   vp9_prob single_ref_prob[REF_CONTEXTS][2];
145   vp9_prob comp_ref_prob[REF_CONTEXTS];
146   vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
147   vp9_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
148   nmv_context nmvc;
149   vp9_prob dummy3[47];
150   vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
151   vp9_prob seg_tree_probs[SEG_TREE_PROBS];
152   vp9_prob seg_pred_probs[PREDICTION_PROBS];
153   vp9_prob dummy4[28];
154   int initialized;
155 } FRAME_CONTEXT;
156
157
158 extern struct tx_probs default_tx_probs;
159
160 extern vp9_prob default_skip_probs[SKIP_CONTEXTS];
161
162 extern vp9_prob default_inter_mode_probs[INTER_MODE_CONTEXTS]
163                                         [INTER_MODES - 1];
164
165 extern vp9_prob default_switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
166                                               [SWITCHABLE_FILTERS - 1];
167
168 extern vp9_prob default_intra_inter_p[INTRA_INTER_CONTEXTS];
169
170 extern vp9_prob default_comp_inter_p[COMP_INTER_CONTEXTS];
171
172 extern vp9_prob default_single_ref_p[REF_CONTEXTS][2];
173
174 extern vp9_prob default_comp_ref_p[REF_CONTEXTS];
175
176 extern vp9_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
177
178 extern vp9_prob default_if_y_probs[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
179
180 extern vp9_prob default_if_uv_probs[INTRA_MODES][INTRA_MODES - 1];
181
182 extern vp9_prob default_seg_tree_probs[SEG_TREE_PROBS];
183
184 extern vp9_prob default_seg_pred_probs[PREDICTION_PROBS];
185
186 extern vp9_prob vp9_kf_partition_probs[PARTITION_CONTEXTS]
187                                       [PARTITION_TYPES - 1];
188
189 extern vp9_prob default_partition_probs[PARTITION_CONTEXTS]
190                                        [PARTITION_TYPES - 1];
191
192 extern nmv_context default_nmv_context;
193
194 extern vp9_prob default_coef_probs_4x4[COEFF_PROB_SIZE][COEFF_PROB_NUM];
195
196 extern vp9_prob default_coef_probs_8x8[COEFF_PROB_SIZE][COEFF_PROB_NUM];
197
198 extern vp9_prob default_coef_probs_16x16[COEFF_PROB_SIZE][COEFF_PROB_NUM];
199
200 extern vp9_prob default_coef_probs_32x32[COEFF_PROB_SIZE][COEFF_PROB_NUM];
201
202 #endif /*VP9_PROBS_H */