media/libvpx/vp9/common/vp9_entropy.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp9/common/vp9_entropy.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,204 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +#ifndef VP9_COMMON_VP9_ENTROPY_H_
    1.15 +#define VP9_COMMON_VP9_ENTROPY_H_
    1.16 +
    1.17 +#include "vpx/vpx_integer.h"
    1.18 +
    1.19 +#include "vp9/common/vp9_blockd.h"
    1.20 +#include "vp9/common/vp9_common.h"
    1.21 +#include "vp9/common/vp9_scan.h"
    1.22 +#include "vp9/common/vp9_treecoder.h"
    1.23 +
    1.24 +#define DIFF_UPDATE_PROB 252
    1.25 +
    1.26 +/* Coefficient token alphabet */
    1.27 +
    1.28 +#define ZERO_TOKEN              0       /* 0         Extra Bits 0+0 */
    1.29 +#define ONE_TOKEN               1       /* 1         Extra Bits 0+1 */
    1.30 +#define TWO_TOKEN               2       /* 2         Extra Bits 0+1 */
    1.31 +#define THREE_TOKEN             3       /* 3         Extra Bits 0+1 */
    1.32 +#define FOUR_TOKEN              4       /* 4         Extra Bits 0+1 */
    1.33 +#define DCT_VAL_CATEGORY1       5       /* 5-6       Extra Bits 1+1 */
    1.34 +#define DCT_VAL_CATEGORY2       6       /* 7-10      Extra Bits 2+1 */
    1.35 +#define DCT_VAL_CATEGORY3       7       /* 11-18     Extra Bits 3+1 */
    1.36 +#define DCT_VAL_CATEGORY4       8       /* 19-34     Extra Bits 4+1 */
    1.37 +#define DCT_VAL_CATEGORY5       9       /* 35-66     Extra Bits 5+1 */
    1.38 +#define DCT_VAL_CATEGORY6       10      /* 67+       Extra Bits 14+1 */
    1.39 +#define DCT_EOB_TOKEN           11      /* EOB       Extra Bits 0+0 */
    1.40 +#define MAX_ENTROPY_TOKENS      12
    1.41 +#define ENTROPY_NODES           11
    1.42 +#define EOSB_TOKEN              127     /* Not signalled, encoder only */
    1.43 +
    1.44 +#define INTER_MODE_CONTEXTS     7
    1.45 +
    1.46 +extern DECLARE_ALIGNED(16, const uint8_t,
    1.47 +                       vp9_pt_energy_class[MAX_ENTROPY_TOKENS]);
    1.48 +
    1.49 +extern const vp9_tree_index vp9_coef_tree[TREE_SIZE(MAX_ENTROPY_TOKENS)];
    1.50 +
    1.51 +#define DCT_EOB_MODEL_TOKEN     3      /* EOB       Extra Bits 0+0 */
    1.52 +extern const vp9_tree_index vp9_coefmodel_tree[];
    1.53 +
    1.54 +extern struct vp9_token vp9_coef_encodings[MAX_ENTROPY_TOKENS];
    1.55 +
    1.56 +typedef struct {
    1.57 +  const vp9_tree_index *tree;
    1.58 +  const vp9_prob *prob;
    1.59 +  int len;
    1.60 +  int base_val;
    1.61 +} vp9_extra_bit;
    1.62 +
    1.63 +// indexed by token value
    1.64 +extern const vp9_extra_bit vp9_extra_bits[MAX_ENTROPY_TOKENS];
    1.65 +
    1.66 +#define MAX_PROB                255
    1.67 +#define DCT_MAX_VALUE           16384
    1.68 +
    1.69 +/* Coefficients are predicted via a 3-dimensional probability table. */
    1.70 +
    1.71 +/* Outside dimension.  0 = Y with DC, 1 = UV */
    1.72 +#define BLOCK_TYPES 2
    1.73 +#define REF_TYPES 2  // intra=0, inter=1
    1.74 +
    1.75 +/* Middle dimension reflects the coefficient position within the transform. */
    1.76 +#define COEF_BANDS 6
    1.77 +
    1.78 +/* Inside dimension is measure of nearby complexity, that reflects the energy
    1.79 +   of nearby coefficients are nonzero.  For the first coefficient (DC, unless
    1.80 +   block type is 0), we look at the (already encoded) blocks above and to the
    1.81 +   left of the current block.  The context index is then the number (0,1,or 2)
    1.82 +   of these blocks having nonzero coefficients.
    1.83 +   After decoding a coefficient, the measure is determined by the size of the
    1.84 +   most recently decoded coefficient.
    1.85 +   Note that the intuitive meaning of this measure changes as coefficients
    1.86 +   are decoded, e.g., prior to the first token, a zero means that my neighbors
    1.87 +   are empty while, after the first token, because of the use of end-of-block,
    1.88 +   a zero means we just decoded a zero and hence guarantees that a non-zero
    1.89 +   coefficient will appear later in this block.  However, this shift
    1.90 +   in meaning is perfectly OK because our context depends also on the
    1.91 +   coefficient band (and since zigzag positions 0, 1, and 2 are in
    1.92 +   distinct bands). */
    1.93 +
    1.94 +#define PREV_COEF_CONTEXTS          6
    1.95 +
    1.96 +// #define ENTROPY_STATS
    1.97 +
    1.98 +typedef unsigned int vp9_coeff_count[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
    1.99 +                                    [MAX_ENTROPY_TOKENS];
   1.100 +typedef unsigned int vp9_coeff_stats[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
   1.101 +                                    [ENTROPY_NODES][2];
   1.102 +
   1.103 +#define SUBEXP_PARAM                4   /* Subexponential code parameter */
   1.104 +#define MODULUS_PARAM               13  /* Modulus parameter */
   1.105 +
   1.106 +struct VP9Common;
   1.107 +void vp9_default_coef_probs(struct VP9Common *cm);
   1.108 +
   1.109 +void vp9_coef_tree_initialize();
   1.110 +void vp9_adapt_coef_probs(struct VP9Common *cm);
   1.111 +
   1.112 +static INLINE void reset_skip_context(MACROBLOCKD *xd, BLOCK_SIZE bsize) {
   1.113 +  int i;
   1.114 +  for (i = 0; i < MAX_MB_PLANE; i++) {
   1.115 +    struct macroblockd_plane *const pd = &xd->plane[i];
   1.116 +    const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
   1.117 +    vpx_memset(pd->above_context, 0, sizeof(ENTROPY_CONTEXT) *
   1.118 +                   num_4x4_blocks_wide_lookup[plane_bsize]);
   1.119 +    vpx_memset(pd->left_context, 0, sizeof(ENTROPY_CONTEXT) *
   1.120 +                   num_4x4_blocks_high_lookup[plane_bsize]);
   1.121 +  }
   1.122 +}
   1.123 +
   1.124 +// This is the index in the scan order beyond which all coefficients for
   1.125 +// 8x8 transform and above are in the top band.
   1.126 +// This macro is currently unused but may be used by certain implementations
   1.127 +#define MAXBAND_INDEX 21
   1.128 +
   1.129 +extern const uint8_t vp9_coefband_trans_8x8plus[1024];
   1.130 +extern const uint8_t vp9_coefband_trans_4x4[16];
   1.131 +
   1.132 +static const uint8_t *get_band_translate(TX_SIZE tx_size) {
   1.133 +  return tx_size == TX_4X4 ? vp9_coefband_trans_4x4
   1.134 +                           : vp9_coefband_trans_8x8plus;
   1.135 +}
   1.136 +
   1.137 +// 128 lists of probabilities are stored for the following ONE node probs:
   1.138 +// 1, 3, 5, 7, ..., 253, 255
   1.139 +// In between probabilities are interpolated linearly
   1.140 +
   1.141 +#define COEFPROB_MODELS             128
   1.142 +
   1.143 +#define UNCONSTRAINED_NODES         3
   1.144 +
   1.145 +#define PIVOT_NODE                  2   // which node is pivot
   1.146 +
   1.147 +typedef vp9_prob vp9_coeff_probs_model[REF_TYPES][COEF_BANDS]
   1.148 +                                      [PREV_COEF_CONTEXTS]
   1.149 +                                      [UNCONSTRAINED_NODES];
   1.150 +
   1.151 +typedef unsigned int vp9_coeff_count_model[REF_TYPES][COEF_BANDS]
   1.152 +                                          [PREV_COEF_CONTEXTS]
   1.153 +                                          [UNCONSTRAINED_NODES + 1];
   1.154 +
   1.155 +void vp9_model_to_full_probs(const vp9_prob *model, vp9_prob *full);
   1.156 +
   1.157 +static int get_entropy_context(TX_SIZE tx_size, const ENTROPY_CONTEXT *a,
   1.158 +                                                const ENTROPY_CONTEXT *l) {
   1.159 +  ENTROPY_CONTEXT above_ec = 0, left_ec = 0;
   1.160 +
   1.161 +  switch (tx_size) {
   1.162 +    case TX_4X4:
   1.163 +      above_ec = a[0] != 0;
   1.164 +      left_ec = l[0] != 0;
   1.165 +      break;
   1.166 +    case TX_8X8:
   1.167 +      above_ec = !!*(const uint16_t *)a;
   1.168 +      left_ec  = !!*(const uint16_t *)l;
   1.169 +      break;
   1.170 +    case TX_16X16:
   1.171 +      above_ec = !!*(const uint32_t *)a;
   1.172 +      left_ec  = !!*(const uint32_t *)l;
   1.173 +      break;
   1.174 +    case TX_32X32:
   1.175 +      above_ec = !!*(const uint64_t *)a;
   1.176 +      left_ec  = !!*(const uint64_t *)l;
   1.177 +      break;
   1.178 +    default:
   1.179 +      assert(!"Invalid transform size.");
   1.180 +  }
   1.181 +
   1.182 +  return combine_entropy_contexts(above_ec, left_ec);
   1.183 +}
   1.184 +
   1.185 +static void get_scan(const MACROBLOCKD *xd, TX_SIZE tx_size,
   1.186 +                     PLANE_TYPE type, int block_idx,
   1.187 +                     const int16_t **scan, const int16_t **scan_nb) {
   1.188 +  switch (tx_size) {
   1.189 +    case TX_4X4:
   1.190 +      get_scan_nb_4x4(get_tx_type_4x4(type, xd, block_idx), scan, scan_nb);
   1.191 +      break;
   1.192 +    case TX_8X8:
   1.193 +      get_scan_nb_8x8(get_tx_type_8x8(type, xd), scan, scan_nb);
   1.194 +      break;
   1.195 +    case TX_16X16:
   1.196 +      get_scan_nb_16x16(get_tx_type_16x16(type, xd), scan, scan_nb);
   1.197 +      break;
   1.198 +    case TX_32X32:
   1.199 +      *scan = vp9_default_scan_32x32;
   1.200 +      *scan_nb = vp9_default_scan_32x32_neighbors;
   1.201 +      break;
   1.202 +    default:
   1.203 +      assert(!"Invalid transform size.");
   1.204 +  }
   1.205 +}
   1.206 +
   1.207 +#endif  // VP9_COMMON_VP9_ENTROPY_H_

mercurial