190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/*
2f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber *
4f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Use of this source code is governed by a BSD-style license
5f71323e297a928af368937089d3ed71239786f86Andreas Huber *  that can be found in the LICENSE file in the root of the source
6f71323e297a928af368937089d3ed71239786f86Andreas Huber *  tree. An additional intellectual property rights grant can be found
7f71323e297a928af368937089d3ed71239786f86Andreas Huber *  in the file PATENTS.  All contributing project authors may
8f71323e297a928af368937089d3ed71239786f86Andreas Huber *  be found in the AUTHORS file in the root of the source tree.
990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber */
1090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
12b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifndef VP8_COMMON_ENTROPY_H_
13b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#define VP8_COMMON_ENTROPY_H_
1490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "treecoder.h"
1690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "blockd.h"
1790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
18b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifdef __cplusplus
19b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanianextern "C" {
20b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#endif
21b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
2290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* Coefficient token alphabet */
2390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
24538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define ZERO_TOKEN              0       /* 0         Extra Bits 0+0 */
25538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define ONE_TOKEN               1       /* 1         Extra Bits 0+1 */
26538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define TWO_TOKEN               2       /* 2         Extra Bits 0+1 */
27538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define THREE_TOKEN             3       /* 3         Extra Bits 0+1 */
28538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define FOUR_TOKEN              4       /* 4         Extra Bits 0+1 */
29538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define DCT_VAL_CATEGORY1       5       /* 5-6       Extra Bits 1+1 */
30538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define DCT_VAL_CATEGORY2       6       /* 7-10      Extra Bits 2+1 */
3179f15823c34ae1e423108295e416213200bb280fAndreas Huber#define DCT_VAL_CATEGORY3       7       /* 11-18     Extra Bits 3+1 */
3279f15823c34ae1e423108295e416213200bb280fAndreas Huber#define DCT_VAL_CATEGORY4       8       /* 19-34     Extra Bits 4+1 */
3379f15823c34ae1e423108295e416213200bb280fAndreas Huber#define DCT_VAL_CATEGORY5       9       /* 35-66     Extra Bits 5+1 */
3479f15823c34ae1e423108295e416213200bb280fAndreas Huber#define DCT_VAL_CATEGORY6       10      /* 67+       Extra Bits 11+1 */
35538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber#define DCT_EOB_TOKEN           11      /* EOB       Extra Bits 0+0 */
3690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
371b362b15af34006e6a11974088a46d42b903418eJohann#define MAX_ENTROPY_TOKENS 12
3890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define ENTROPY_NODES 11
3990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberextern const vp8_tree_index vp8_coef_tree[];
4190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
421b362b15af34006e6a11974088a46d42b903418eJohannextern const struct vp8_token_struct vp8_coef_encodings[MAX_ENTROPY_TOKENS];
4390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
4590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
4690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    vp8_tree_p tree;
4790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    const vp8_prob *prob;
4890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int Len;
4990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int base_val;
5090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} vp8_extra_bit_struct;
5190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
521b362b15af34006e6a11974088a46d42b903418eJohannextern const vp8_extra_bit_struct vp8_extra_bits[12];    /* indexed by token value */
5390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define PROB_UPDATE_BASELINE_COST   7
5590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define MAX_PROB                255
5790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define DCT_MAX_VALUE           2048
5890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* Coefficients are predicted via a 3-dimensional probability table. */
6190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* Outside dimension.  0 = Y no DC, 1 = Y2, 2 = UV, 3 = Y with DC */
6390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define BLOCK_TYPES 4
6590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* Middle dimension is a coarsening of the coefficient's
6790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   position within the 4x4 DCT. */
6890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define COEF_BANDS 8
7090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberextern DECLARE_ALIGNED(16, const unsigned char, vp8_coef_bands[16]);
7190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
7290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* Inside dimension is 3-valued measure of nearby complexity, that is,
7390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   the extent to which nearby coefficients are nonzero.  For the first
7490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   coefficient (DC, unless block type is 0), we look at the (already encoded)
7590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   blocks above and to the left of the current block.  The context index is
7690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   then the number (0,1,or 2) of these blocks having nonzero coefficients.
7790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   After decoding a coefficient, the measure is roughly the size of the
7890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   most recently decoded coefficient (0 for 0, 1 for 1, 2 for >1).
7990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   Note that the intuitive meaning of this measure changes as coefficients
8090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   are decoded, e.g., prior to the first token, a zero means that my neighbors
8190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   are empty while, after the first token, because of the use of end-of-block,
8290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   a zero means we just decoded a zero and hence guarantees that a non-zero
8390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   coefficient will appear later in this block.  However, this shift
8490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   in meaning is perfectly OK because our context depends also on the
8590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   coefficient band (and since zigzag positions 0, 1, and 2 are in
8690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber   distinct bands). */
8790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
88538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber/*# define DC_TOKEN_CONTEXTS        3*/ /* 00, 0!0, !0!0 */
8990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#   define PREV_COEF_CONTEXTS       3
9090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
911b362b15af34006e6a11974088a46d42b903418eJohannextern DECLARE_ALIGNED(16, const unsigned char, vp8_prev_token_class[MAX_ENTROPY_TOKENS]);
9290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
931b362b15af34006e6a11974088a46d42b903418eJohannextern const vp8_prob vp8_coef_update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
9490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberstruct VP8Common;
9790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubervoid vp8_default_coef_probs(struct VP8Common *);
9890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberextern DECLARE_ALIGNED(16, const int, vp8_default_zig_zag1d[16]);
10079f15823c34ae1e423108295e416213200bb280fAndreas Huberextern DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]);
1011b362b15af34006e6a11974088a46d42b903418eJohannextern DECLARE_ALIGNED(16, const short, vp8_default_zig_zag_mask[16]);
10290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberextern const int vp8_mb_feature_data_bits[MB_LVL_MAX];
10390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
10490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubervoid vp8_coef_tree_initialize(void);
105b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifdef __cplusplus
106b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian}  // extern "C"
10790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
108b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
109b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#endif  // VP8_COMMON_ENTROPY_H_
110