entropymv.h 4.18 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9 10 11 12 13 14 15
 */


#ifndef __INC_ENTROPYMV_H
#define __INC_ENTROPYMV_H

#include "treecoder.h"
16
#include "vpx_config.h"
17
#include "blockd.h"
18

19
struct VP9Common;
20

21
void vp9_entropy_mv_init();
22
void vp9_init_mv_probs(struct VP9Common *cm);
23

24
void vp9_adapt_nmv_probs(struct VP9Common *cm, int usehp);
25
int vp9_use_nmv_hp(const MV *ref);
26

27
#define VP9_NMV_UPDATE_PROB  255
28 29 30 31 32 33 34 35 36 37 38 39 40
//#define MV_GROUP_UPDATE

#define LOW_PRECISION_MV_UPDATE  /* Use 7 bit forward update */

/* Symbols for coding which components are zero jointly */
#define MV_JOINTS     4
typedef enum {
  MV_JOINT_ZERO = 0,             /* Zero vector */
  MV_JOINT_HNZVZ = 1,            /* Vert zero, hor nonzero */
  MV_JOINT_HZVNZ = 2,            /* Hor zero, vert nonzero */
  MV_JOINT_HNZVNZ = 3,           /* Both components nonzero */
} MV_JOINT_TYPE;

41 42
extern const vp9_tree_index vp9_mv_joint_tree[2 * MV_JOINTS - 2];
extern struct vp9_token_struct vp9_mv_joint_encodings [MV_JOINTS];
43 44 45 46 47 48 49 50 51 52 53 54 55 56

/* Symbols for coding magnitude class of nonzero components */
#define MV_CLASSES     8
typedef enum {
  MV_CLASS_0 = 0,      /* (0, 2]     integer pel */
  MV_CLASS_1 = 1,      /* (2, 4]     integer pel */
  MV_CLASS_2 = 2,      /* (4, 8]     integer pel */
  MV_CLASS_3 = 3,      /* (8, 16]    integer pel */
  MV_CLASS_4 = 4,      /* (16, 32]   integer pel */
  MV_CLASS_5 = 5,      /* (32, 64]   integer pel */
  MV_CLASS_6 = 6,      /* (64, 128]  integer pel */
  MV_CLASS_7 = 7,      /* (128, 256] integer pel */
} MV_CLASS_TYPE;

57 58
extern const vp9_tree_index vp9_mv_class_tree[2 * MV_CLASSES - 2];
extern struct vp9_token_struct vp9_mv_class_encodings [MV_CLASSES];
59 60 61 62 63 64 65 66 67

#define CLASS0_BITS    1  /* bits at integer precision for class 0 */
#define CLASS0_SIZE    (1 << CLASS0_BITS)
#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)

#define MV_MAX_BITS    (MV_CLASSES + CLASS0_BITS + 2)
#define MV_MAX         ((1 << MV_MAX_BITS) - 1)
#define MV_VALS        ((MV_MAX << 1) + 1)

68 69
extern const vp9_tree_index vp9_mv_class0_tree[2 * CLASS0_SIZE - 2];
extern struct vp9_token_struct vp9_mv_class0_encodings[CLASS0_SIZE];
70

71 72
extern const vp9_tree_index vp9_mv_fp_tree[2 * 4 - 2];
extern struct vp9_token_struct vp9_mv_fp_encodings[4];
73 74

typedef struct {
75 76 77 78 79 80 81 82
  vp9_prob sign;
  vp9_prob classes[MV_CLASSES - 1];
  vp9_prob class0[CLASS0_SIZE - 1];
  vp9_prob bits[MV_OFFSET_BITS];
  vp9_prob class0_fp[CLASS0_SIZE][4 - 1];
  vp9_prob fp[4 - 1];
  vp9_prob class0_hp;
  vp9_prob hp;
83 84 85
} nmv_component;

typedef struct {
86
  vp9_prob joints[MV_JOINTS - 1];
87 88 89
  nmv_component comps[2];
} nmv_context;

90 91 92
MV_JOINT_TYPE vp9_get_mv_joint(MV mv);
MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset);
int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset);
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111


typedef struct {
  unsigned int mvcount[MV_VALS];
  unsigned int sign[2];
  unsigned int classes[MV_CLASSES];
  unsigned int class0[CLASS0_SIZE];
  unsigned int bits[MV_OFFSET_BITS][2];
  unsigned int class0_fp[CLASS0_SIZE][4];
  unsigned int fp[4];
  unsigned int class0_hp[2];
  unsigned int hp[2];
} nmv_component_counts;

typedef struct {
  unsigned int joints[MV_JOINTS];
  nmv_component_counts comps[2];
} nmv_context_counts;

112
void vp9_increment_nmv(const MV *mv, const MV *ref, nmv_context_counts *mvctx,
113
                       int usehp);
114
extern const nmv_context vp9_default_nmv_context;
115
void vp9_counts_to_nmv_context(
116 117 118 119 120 121 122 123 124 125 126 127
    nmv_context_counts *NMVcount,
    nmv_context *prob,
    int usehp,
    unsigned int (*branch_ct_joint)[2],
    unsigned int (*branch_ct_sign)[2],
    unsigned int (*branch_ct_classes)[MV_CLASSES - 1][2],
    unsigned int (*branch_ct_class0)[CLASS0_SIZE - 1][2],
    unsigned int (*branch_ct_bits)[MV_OFFSET_BITS][2],
    unsigned int (*branch_ct_class0_fp)[CLASS0_SIZE][4 - 1][2],
    unsigned int (*branch_ct_fp)[4 - 1][2],
    unsigned int (*branch_ct_class0_hp)[2],
    unsigned int (*branch_ct_hp)[2]);
Deb Mukherjee's avatar
Deb Mukherjee committed
128
void vp9_counts_process(nmv_context_counts *NMVcount, int usehp);
John Koleszar's avatar
John Koleszar committed
129
#endif