1233d2500723e5594f3e7c70896ffeeef32b9c950ywan/* 2233d2500723e5594f3e7c70896ffeeef32b9c950ywan * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3233d2500723e5594f3e7c70896ffeeef32b9c950ywan * 4233d2500723e5594f3e7c70896ffeeef32b9c950ywan * Use of this source code is governed by a BSD-style license 5233d2500723e5594f3e7c70896ffeeef32b9c950ywan * that can be found in the LICENSE file in the root of the source 6233d2500723e5594f3e7c70896ffeeef32b9c950ywan * tree. An additional intellectual property rights grant can be found 7233d2500723e5594f3e7c70896ffeeef32b9c950ywan * in the file PATENTS. All contributing project authors may 8233d2500723e5594f3e7c70896ffeeef32b9c950ywan * be found in the AUTHORS file in the root of the source tree. 9233d2500723e5594f3e7c70896ffeeef32b9c950ywan */ 10233d2500723e5594f3e7c70896ffeeef32b9c950ywan 11233d2500723e5594f3e7c70896ffeeef32b9c950ywan 12233d2500723e5594f3e7c70896ffeeef32b9c950ywan#ifndef VP9_COMMON_VP9_ENTROPYMV_H_ 13233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define VP9_COMMON_VP9_ENTROPYMV_H_ 14233d2500723e5594f3e7c70896ffeeef32b9c950ywan 15233d2500723e5594f3e7c70896ffeeef32b9c950ywan#include "./vpx_config.h" 16233d2500723e5594f3e7c70896ffeeef32b9c950ywan#include "vp9/common/vp9_blockd.h" 17233d2500723e5594f3e7c70896ffeeef32b9c950ywan 18233d2500723e5594f3e7c70896ffeeef32b9c950ywan#ifdef __cplusplus 19233d2500723e5594f3e7c70896ffeeef32b9c950ywanextern "C" { 20233d2500723e5594f3e7c70896ffeeef32b9c950ywan#endif 21233d2500723e5594f3e7c70896ffeeef32b9c950ywan 22233d2500723e5594f3e7c70896ffeeef32b9c950ywanstruct VP9Common; 23233d2500723e5594f3e7c70896ffeeef32b9c950ywan 24233d2500723e5594f3e7c70896ffeeef32b9c950ywanvoid vp9_init_mv_probs(struct VP9Common *cm); 25233d2500723e5594f3e7c70896ffeeef32b9c950ywan 26233d2500723e5594f3e7c70896ffeeef32b9c950ywanvoid vp9_adapt_mv_probs(struct VP9Common *cm, int usehp); 27233d2500723e5594f3e7c70896ffeeef32b9c950ywanint vp9_use_mv_hp(const MV *ref); 28233d2500723e5594f3e7c70896ffeeef32b9c950ywan 29233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_UPDATE_PROB 252 30233d2500723e5594f3e7c70896ffeeef32b9c950ywan 31233d2500723e5594f3e7c70896ffeeef32b9c950ywan/* Symbols for coding which components are zero jointly */ 32233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_JOINTS 4 33233d2500723e5594f3e7c70896ffeeef32b9c950ywantypedef enum { 34233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_JOINT_ZERO = 0, /* Zero vector */ 35233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_JOINT_HNZVZ = 1, /* Vert zero, hor nonzero */ 36233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_JOINT_HZVNZ = 2, /* Hor zero, vert nonzero */ 37233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_JOINT_HNZVNZ = 3, /* Both components nonzero */ 38233d2500723e5594f3e7c70896ffeeef32b9c950ywan} MV_JOINT_TYPE; 39233d2500723e5594f3e7c70896ffeeef32b9c950ywan 40233d2500723e5594f3e7c70896ffeeef32b9c950ywanstatic INLINE int mv_joint_vertical(MV_JOINT_TYPE type) { 41233d2500723e5594f3e7c70896ffeeef32b9c950ywan return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ; 42233d2500723e5594f3e7c70896ffeeef32b9c950ywan} 43233d2500723e5594f3e7c70896ffeeef32b9c950ywan 44233d2500723e5594f3e7c70896ffeeef32b9c950ywanstatic INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) { 45233d2500723e5594f3e7c70896ffeeef32b9c950ywan return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ; 46233d2500723e5594f3e7c70896ffeeef32b9c950ywan} 47233d2500723e5594f3e7c70896ffeeef32b9c950ywan 48233d2500723e5594f3e7c70896ffeeef32b9c950ywan/* Symbols for coding magnitude class of nonzero components */ 49233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_CLASSES 11 50233d2500723e5594f3e7c70896ffeeef32b9c950ywantypedef enum { 51233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_0 = 0, /* (0, 2] integer pel */ 52233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_1 = 1, /* (2, 4] integer pel */ 53233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_2 = 2, /* (4, 8] integer pel */ 54233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_3 = 3, /* (8, 16] integer pel */ 55233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_4 = 4, /* (16, 32] integer pel */ 56233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_5 = 5, /* (32, 64] integer pel */ 57233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_6 = 6, /* (64, 128] integer pel */ 58233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_7 = 7, /* (128, 256] integer pel */ 59233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_8 = 8, /* (256, 512] integer pel */ 60233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_9 = 9, /* (512, 1024] integer pel */ 61233d2500723e5594f3e7c70896ffeeef32b9c950ywan MV_CLASS_10 = 10, /* (1024,2048] integer pel */ 62233d2500723e5594f3e7c70896ffeeef32b9c950ywan} MV_CLASS_TYPE; 63233d2500723e5594f3e7c70896ffeeef32b9c950ywan 64233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define CLASS0_BITS 1 /* bits at integer precision for class 0 */ 65233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define CLASS0_SIZE (1 << CLASS0_BITS) 66233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2) 67233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_FP_SIZE 4 68233d2500723e5594f3e7c70896ffeeef32b9c950ywan 69233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2) 70233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_MAX ((1 << MV_MAX_BITS) - 1) 71233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_VALS ((MV_MAX << 1) + 1) 72233d2500723e5594f3e7c70896ffeeef32b9c950ywan 73233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_IN_USE_BITS 14 74233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_UPP ((1 << MV_IN_USE_BITS) - 1) 75233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MV_LOW (-(1 << MV_IN_USE_BITS)) 76233d2500723e5594f3e7c70896ffeeef32b9c950ywan 77233d2500723e5594f3e7c70896ffeeef32b9c950ywanextern const vp9_tree_index vp9_mv_joint_tree[]; 78233d2500723e5594f3e7c70896ffeeef32b9c950ywanextern const vp9_tree_index vp9_mv_class_tree[]; 79233d2500723e5594f3e7c70896ffeeef32b9c950ywanextern const vp9_tree_index vp9_mv_class0_tree[]; 80233d2500723e5594f3e7c70896ffeeef32b9c950ywanextern const vp9_tree_index vp9_mv_fp_tree[]; 81233d2500723e5594f3e7c70896ffeeef32b9c950ywan 82233d2500723e5594f3e7c70896ffeeef32b9c950ywantypedef struct { 83233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob sign; 84233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob classes[MV_CLASSES - 1]; 85233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob class0[CLASS0_SIZE - 1]; 86233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob bits[MV_OFFSET_BITS]; 87233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob class0_fp[CLASS0_SIZE][MV_FP_SIZE - 1]; 88233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob fp[MV_FP_SIZE - 1]; 89233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob class0_hp; 90233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob hp; 91233d2500723e5594f3e7c70896ffeeef32b9c950ywan} nmv_component; 92233d2500723e5594f3e7c70896ffeeef32b9c950ywan 93233d2500723e5594f3e7c70896ffeeef32b9c950ywantypedef struct { 94233d2500723e5594f3e7c70896ffeeef32b9c950ywan vp9_prob joints[MV_JOINTS - 1]; 95233d2500723e5594f3e7c70896ffeeef32b9c950ywan nmv_component comps[2]; 96233d2500723e5594f3e7c70896ffeeef32b9c950ywan} nmv_context; 97233d2500723e5594f3e7c70896ffeeef32b9c950ywan 98233d2500723e5594f3e7c70896ffeeef32b9c950ywanstatic INLINE MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv) { 99233d2500723e5594f3e7c70896ffeeef32b9c950ywan if (mv->row == 0) { 100233d2500723e5594f3e7c70896ffeeef32b9c950ywan return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ; 101233d2500723e5594f3e7c70896ffeeef32b9c950ywan } else { 102233d2500723e5594f3e7c70896ffeeef32b9c950ywan return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ; 103233d2500723e5594f3e7c70896ffeeef32b9c950ywan } 104233d2500723e5594f3e7c70896ffeeef32b9c950ywan} 105233d2500723e5594f3e7c70896ffeeef32b9c950ywan 106233d2500723e5594f3e7c70896ffeeef32b9c950ywanMV_CLASS_TYPE vp9_get_mv_class(int z, int *offset); 107233d2500723e5594f3e7c70896ffeeef32b9c950ywanint vp9_get_mv_mag(MV_CLASS_TYPE c, int offset); 108233d2500723e5594f3e7c70896ffeeef32b9c950ywan 109233d2500723e5594f3e7c70896ffeeef32b9c950ywan 110233d2500723e5594f3e7c70896ffeeef32b9c950ywantypedef struct { 111233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int sign[2]; 112233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int classes[MV_CLASSES]; 113233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int class0[CLASS0_SIZE]; 114233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int bits[MV_OFFSET_BITS][2]; 115233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int class0_fp[CLASS0_SIZE][MV_FP_SIZE]; 116233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int fp[MV_FP_SIZE]; 117233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int class0_hp[2]; 118233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int hp[2]; 119233d2500723e5594f3e7c70896ffeeef32b9c950ywan} nmv_component_counts; 120233d2500723e5594f3e7c70896ffeeef32b9c950ywan 121233d2500723e5594f3e7c70896ffeeef32b9c950ywantypedef struct { 122233d2500723e5594f3e7c70896ffeeef32b9c950ywan unsigned int joints[MV_JOINTS]; 123233d2500723e5594f3e7c70896ffeeef32b9c950ywan nmv_component_counts comps[2]; 124233d2500723e5594f3e7c70896ffeeef32b9c950ywan} nmv_context_counts; 125233d2500723e5594f3e7c70896ffeeef32b9c950ywan 126233d2500723e5594f3e7c70896ffeeef32b9c950ywanvoid vp9_inc_mv(const MV *mv, nmv_context_counts *mvctx); 127233d2500723e5594f3e7c70896ffeeef32b9c950ywan 128233d2500723e5594f3e7c70896ffeeef32b9c950ywan#ifdef __cplusplus 129233d2500723e5594f3e7c70896ffeeef32b9c950ywan} // extern "C" 130233d2500723e5594f3e7c70896ffeeef32b9c950ywan#endif 131233d2500723e5594f3e7c70896ffeeef32b9c950ywan 132233d2500723e5594f3e7c70896ffeeef32b9c950ywan#endif // VP9_COMMON_VP9_ENTROPYMV_H_ 133