2 * Copyright © 2015 Intel Corporation
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
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.
32 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
46 #define TX_SIZE_CONTEXTS 2
49 #define SKIP_CONTEXTS 3
50 #define INTER_MODE_CONTEXTS 7
52 #define SWITCHABLE_FILTERS 3
53 #define SWITCHABLE_FILTER_CONTEXTS (SWITCHABLE_FILTERS + 1)
54 #define MAX_SEGMENTS 8
55 #define PREDICTION_PROBS 3
56 #define SEG_TREE_PROBS (MAX_SEGMENTS-1)
58 #define INTRA_INTER_CONTEXTS 4
59 #define COMP_INTER_CONTEXTS 5
60 #define REF_CONTEXTS 5
61 #define BLOCK_SIZE_GROUPS 4
62 #define INTRA_MODES 10
63 #define PARTITION_PLOFFSET 4 // number of probability models per block size
64 #define PARTITION_CONTEXTS (4 * PARTITION_PLOFFSET)
65 #define PARTITION_TYPES 4
66 #define REF_TYPES 2 // intra=0, inter=1
68 #define COEFF_CONTEXTS 6
69 #define UNCONSTRAINED_NODES 3
71 #define CLASS0_BITS 1 /* bits at integer precision for class 0 */
72 #define CLASS0_SIZE (1 << CLASS0_BITS)
73 #define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
74 #define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2)
76 #define FRAME_CONTEXTS_LOG2 2
77 #define FRAME_CONTEXTS (1 << FRAME_CONTEXTS_LOG2)
79 #define COEFF_PROB_SIZE 132
80 #define COEFF_PROB_NUM 3
82 #define TX_PROBS_IDX 0
83 #define COEFF_PROBS_IDX 64
84 #define INTRA_PROBS_IDX 1603
85 #define SEG_PROBS_IDX 2010
87 typedef uint8_t vp9_prob;
89 #define vpx_memset memset
90 #define vpx_memcpy memcpy
92 #define vp9_zero(dest) memset(&dest, 0, sizeof(dest))
94 #define vp9_copy(dest, src) { \
95 assert(sizeof(dest) == sizeof(src)); \
96 vpx_memcpy(dest, src, sizeof(src)); \
100 vp9_prob p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 3];
101 vp9_prob p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 2];
102 vp9_prob p32x32[TX_SIZE_CONTEXTS][TX_SIZES - 1];
106 unsigned int p32x32[TX_SIZE_CONTEXTS][TX_SIZES];
107 unsigned int p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 1];
108 unsigned int p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 2];
109 unsigned int tx_totals[TX_SIZES];
114 vp9_prob classes[MV_CLASSES - 1];
115 vp9_prob class0[CLASS0_SIZE - 1];
116 vp9_prob bits[MV_OFFSET_BITS];
119 //Modified the nmv_context from libvpx to suit our HW needs
121 vp9_prob joints[MV_JOINTS-1];
122 nmv_component comps[2];
123 vp9_prob class0_fp0[CLASS0_SIZE][MV_FP_SIZE - 1];
124 vp9_prob fp0[MV_FP_SIZE - 1];
125 vp9_prob class0_fp1[CLASS0_SIZE][MV_FP_SIZE - 1];
126 vp9_prob fp1[MV_FP_SIZE - 1];
127 vp9_prob class0_hp[2];
131 //Modified the FRAME_CONTEXT from libvpx to suit our HW needs
132 typedef struct frame_contexts {
133 struct tx_probs tx_probs;
135 vp9_prob coeff_probs4x4[COEFF_PROB_SIZE][COEFF_PROB_NUM];
136 vp9_prob coeff_probs8x8[COEFF_PROB_SIZE][COEFF_PROB_NUM];
137 vp9_prob coeff_probs16x16[COEFF_PROB_SIZE][COEFF_PROB_NUM];
138 vp9_prob coeff_probs32x32[COEFF_PROB_SIZE][COEFF_PROB_NUM];
140 vp9_prob skip_probs[SKIP_CONTEXTS];
141 vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
142 vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
143 [SWITCHABLE_FILTERS - 1];
144 vp9_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
145 vp9_prob comp_inter_prob[COMP_INTER_CONTEXTS];
146 vp9_prob single_ref_prob[REF_CONTEXTS][2];
147 vp9_prob comp_ref_prob[REF_CONTEXTS];
148 vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
149 vp9_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
152 vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
153 vp9_prob seg_tree_probs[SEG_TREE_PROBS];
154 vp9_prob seg_pred_probs[PREDICTION_PROBS];
160 extern struct tx_probs default_tx_probs;
162 extern vp9_prob default_skip_probs[SKIP_CONTEXTS];
164 extern vp9_prob default_inter_mode_probs[INTER_MODE_CONTEXTS]
167 extern vp9_prob default_switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
168 [SWITCHABLE_FILTERS - 1];
170 extern vp9_prob default_intra_inter_p[INTRA_INTER_CONTEXTS];
172 extern vp9_prob default_comp_inter_p[COMP_INTER_CONTEXTS];
174 extern vp9_prob default_single_ref_p[REF_CONTEXTS][2];
176 extern vp9_prob default_comp_ref_p[REF_CONTEXTS];
178 extern vp9_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
180 extern vp9_prob default_if_y_probs[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
182 extern vp9_prob default_if_uv_probs[INTRA_MODES][INTRA_MODES - 1];
184 extern vp9_prob default_seg_tree_probs[SEG_TREE_PROBS];
186 extern vp9_prob default_seg_pred_probs[PREDICTION_PROBS];
188 extern vp9_prob vp9_kf_partition_probs[PARTITION_CONTEXTS]
189 [PARTITION_TYPES - 1];
191 extern vp9_prob default_partition_probs[PARTITION_CONTEXTS]
192 [PARTITION_TYPES - 1];
194 extern nmv_context default_nmv_context;
196 extern vp9_prob default_coef_probs_4x4[COEFF_PROB_SIZE][COEFF_PROB_NUM];
198 extern vp9_prob default_coef_probs_8x8[COEFF_PROB_SIZE][COEFF_PROB_NUM];
200 extern vp9_prob default_coef_probs_16x16[COEFF_PROB_SIZE][COEFF_PROB_NUM];
202 extern vp9_prob default_coef_probs_32x32[COEFF_PROB_SIZE][COEFF_PROB_NUM];
204 extern void intel_init_default_vp9_probs(FRAME_CONTEXT *frame_context);
206 extern void intel_vp9_copy_frame_context(FRAME_CONTEXT *dst,
210 extern void intel_update_intra_frame_context(FRAME_CONTEXT *frame_context);
213 typedef struct _vp9_header_bitoffset_ {
214 unsigned int bit_offset_ref_lf_delta;
215 unsigned int bit_offset_mode_lf_delta;
216 unsigned int bit_offset_lf_level;
217 unsigned int bit_offset_qindex;
218 unsigned int bit_offset_first_partition_size;
219 unsigned int bit_offset_segmentation;
220 unsigned int bit_size_segmentation;
221 } vp9_header_bitoffset;
224 extern bool intel_write_uncompressed_header(struct encode_state *encode_state,
228 vp9_header_bitoffset *header_bitoffset);
231 ONLY_4X4 = 0, // only 4x4 transform used
232 ALLOW_8X8 = 1, // allow block transform size up to 8x8
233 ALLOW_16X16 = 2, // allow block transform size up to 16x16
234 ALLOW_32X32 = 3, // allow block transform size up to 32x32
235 TX_MODE_SELECT = 4, // transform specified for each block
240 SINGLE_REFERENCE = 0,
241 COMPOUND_REFERENCE = 1,
242 REFERENCE_MODE_SELECT = 2,
246 extern const unsigned short vp9_quant_dc[256];
247 extern const unsigned short vp9_quant_ac[256];
249 #endif /*VP9_PROBS_H */