entropymv.h 3.87 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

12 13
#ifndef VP10_COMMON_ENTROPYMV_H_
#define VP10_COMMON_ENTROPYMV_H_
Jingning Han's avatar
Jingning Han committed
14 15 16

#include "./vpx_config.h"

Yaowu Xu's avatar
Yaowu Xu committed
17
#include "aom_dsp/prob.h"
Jingning Han's avatar
Jingning Han committed
18

Yaowu Xu's avatar
Yaowu Xu committed
19
#include "av1/common/mv.h"
Jingning Han's avatar
Jingning Han committed
20 21 22 23 24

#ifdef __cplusplus
extern "C" {
#endif

Yaowu Xu's avatar
Yaowu Xu committed
25
struct VP10Common;
Jingning Han's avatar
Jingning Han committed
26

Yaowu Xu's avatar
Yaowu Xu committed
27
void vp10_init_mv_probs(struct VP10Common *cm);
Jingning Han's avatar
Jingning Han committed
28

Yaowu Xu's avatar
Yaowu Xu committed
29
void vp10_adapt_mv_probs(struct VP10Common *cm, int usehp);
Jingning Han's avatar
Jingning Han committed
30 31 32 33 34
int vp10_use_mv_hp(const MV *ref);

#define MV_UPDATE_PROB 252

/* Symbols for coding which components are zero jointly */
clang-format's avatar
clang-format committed
35
#define MV_JOINTS 4
Jingning Han's avatar
Jingning Han committed
36
typedef enum {
clang-format's avatar
clang-format committed
37 38 39 40
  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 */
Jingning Han's avatar
Jingning Han committed
41 42 43 44 45 46 47 48 49 50 51
} MV_JOINT_TYPE;

static INLINE int mv_joint_vertical(MV_JOINT_TYPE type) {
  return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ;
}

static INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) {
  return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ;
}

/* Symbols for coding magnitude class of nonzero components */
clang-format's avatar
clang-format committed
52
#define MV_CLASSES 11
Jingning Han's avatar
Jingning Han committed
53
typedef enum {
clang-format's avatar
clang-format committed
54 55 56 57 58 59 60 61 62 63 64
  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_8 = 8,   /* (256, 512] integer pel */
  MV_CLASS_9 = 9,   /* (512, 1024] integer pel */
  MV_CLASS_10 = 10, /* (1024,2048] integer pel */
Jingning Han's avatar
Jingning Han committed
65 66
} MV_CLASS_TYPE;

clang-format's avatar
clang-format committed
67 68
#define CLASS0_BITS 1 /* bits at integer precision for class 0 */
#define CLASS0_SIZE (1 << CLASS0_BITS)
Jingning Han's avatar
Jingning Han committed
69 70 71
#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
#define MV_FP_SIZE 4

clang-format's avatar
clang-format committed
72 73 74
#define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2)
#define MV_MAX ((1 << MV_MAX_BITS) - 1)
#define MV_VALS ((MV_MAX << 1) + 1)
Jingning Han's avatar
Jingning Han committed
75 76

#define MV_IN_USE_BITS 14
clang-format's avatar
clang-format committed
77 78
#define MV_UPP ((1 << MV_IN_USE_BITS) - 1)
#define MV_LOW (-(1 << MV_IN_USE_BITS))
Jingning Han's avatar
Jingning Han committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

extern const vpx_tree_index vp10_mv_joint_tree[];
extern const vpx_tree_index vp10_mv_class_tree[];
extern const vpx_tree_index vp10_mv_class0_tree[];
extern const vpx_tree_index vp10_mv_fp_tree[];

typedef struct {
  vpx_prob sign;
  vpx_prob classes[MV_CLASSES - 1];
  vpx_prob class0[CLASS0_SIZE - 1];
  vpx_prob bits[MV_OFFSET_BITS];
  vpx_prob class0_fp[CLASS0_SIZE][MV_FP_SIZE - 1];
  vpx_prob fp[MV_FP_SIZE - 1];
  vpx_prob class0_hp;
  vpx_prob hp;
} nmv_component;

typedef struct {
  vpx_prob joints[MV_JOINTS - 1];
  nmv_component comps[2];
} nmv_context;

static INLINE MV_JOINT_TYPE vp10_get_mv_joint(const MV *mv) {
  if (mv->row == 0) {
    return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ;
  } else {
    return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ;
  }
}

MV_CLASS_TYPE vp10_get_mv_class(int z, int *offset);

typedef struct {
  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][MV_FP_SIZE];
  unsigned int fp[MV_FP_SIZE];
  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;

127
void vp10_inc_mv(const MV *mv, nmv_context_counts *mvctx, const int usehp);
Jingning Han's avatar
Jingning Han committed
128 129 130 131 132

#ifdef __cplusplus
}  // extern "C"
#endif

133
#endif  // VP10_COMMON_ENTROPYMV_H_