michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #ifndef VP9_COMMON_VP9_ENTROPYMV_H_ michael@0: #define VP9_COMMON_VP9_ENTROPYMV_H_ michael@0: michael@0: #include "vp9/common/vp9_treecoder.h" michael@0: #include "./vpx_config.h" michael@0: #include "vp9/common/vp9_blockd.h" michael@0: michael@0: struct VP9Common; michael@0: michael@0: void vp9_entropy_mv_init(); michael@0: void vp9_init_mv_probs(struct VP9Common *cm); michael@0: michael@0: void vp9_adapt_mv_probs(struct VP9Common *cm, int usehp); michael@0: int vp9_use_mv_hp(const MV *ref); michael@0: michael@0: #define NMV_UPDATE_PROB 252 michael@0: michael@0: /* Symbols for coding which components are zero jointly */ michael@0: #define MV_JOINTS 4 michael@0: typedef enum { michael@0: MV_JOINT_ZERO = 0, /* Zero vector */ michael@0: MV_JOINT_HNZVZ = 1, /* Vert zero, hor nonzero */ michael@0: MV_JOINT_HZVNZ = 2, /* Hor zero, vert nonzero */ michael@0: MV_JOINT_HNZVNZ = 3, /* Both components nonzero */ michael@0: } MV_JOINT_TYPE; michael@0: michael@0: static INLINE int mv_joint_vertical(MV_JOINT_TYPE type) { michael@0: return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ; michael@0: } michael@0: michael@0: static INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) { michael@0: return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ; michael@0: } michael@0: michael@0: /* Symbols for coding magnitude class of nonzero components */ michael@0: #define MV_CLASSES 11 michael@0: typedef enum { michael@0: MV_CLASS_0 = 0, /* (0, 2] integer pel */ michael@0: MV_CLASS_1 = 1, /* (2, 4] integer pel */ michael@0: MV_CLASS_2 = 2, /* (4, 8] integer pel */ michael@0: MV_CLASS_3 = 3, /* (8, 16] integer pel */ michael@0: MV_CLASS_4 = 4, /* (16, 32] integer pel */ michael@0: MV_CLASS_5 = 5, /* (32, 64] integer pel */ michael@0: MV_CLASS_6 = 6, /* (64, 128] integer pel */ michael@0: MV_CLASS_7 = 7, /* (128, 256] integer pel */ michael@0: MV_CLASS_8 = 8, /* (256, 512] integer pel */ michael@0: MV_CLASS_9 = 9, /* (512, 1024] integer pel */ michael@0: MV_CLASS_10 = 10, /* (1024,2048] integer pel */ michael@0: } MV_CLASS_TYPE; michael@0: michael@0: #define CLASS0_BITS 1 /* bits at integer precision for class 0 */ michael@0: #define CLASS0_SIZE (1 << CLASS0_BITS) michael@0: #define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2) michael@0: michael@0: #define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2) michael@0: #define MV_MAX ((1 << MV_MAX_BITS) - 1) michael@0: #define MV_VALS ((MV_MAX << 1) + 1) michael@0: michael@0: #define MV_IN_USE_BITS 14 michael@0: #define MV_UPP ((1 << MV_IN_USE_BITS) - 1) michael@0: #define MV_LOW (-(1 << MV_IN_USE_BITS)) michael@0: michael@0: extern const vp9_tree_index vp9_mv_joint_tree[TREE_SIZE(MV_JOINTS)]; michael@0: extern struct vp9_token vp9_mv_joint_encodings[MV_JOINTS]; michael@0: michael@0: extern const vp9_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)]; michael@0: extern struct vp9_token vp9_mv_class_encodings[MV_CLASSES]; michael@0: michael@0: extern const vp9_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)]; michael@0: extern struct vp9_token vp9_mv_class0_encodings[CLASS0_SIZE]; michael@0: michael@0: extern const vp9_tree_index vp9_mv_fp_tree[TREE_SIZE(4)]; michael@0: extern struct vp9_token vp9_mv_fp_encodings[4]; michael@0: michael@0: typedef struct { michael@0: vp9_prob sign; michael@0: vp9_prob classes[MV_CLASSES - 1]; michael@0: vp9_prob class0[CLASS0_SIZE - 1]; michael@0: vp9_prob bits[MV_OFFSET_BITS]; michael@0: vp9_prob class0_fp[CLASS0_SIZE][4 - 1]; michael@0: vp9_prob fp[4 - 1]; michael@0: vp9_prob class0_hp; michael@0: vp9_prob hp; michael@0: } nmv_component; michael@0: michael@0: typedef struct { michael@0: vp9_prob joints[MV_JOINTS - 1]; michael@0: nmv_component comps[2]; michael@0: } nmv_context; michael@0: michael@0: static INLINE MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv) { michael@0: if (mv->row == 0) { michael@0: return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ; michael@0: } else { michael@0: return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ; michael@0: } michael@0: } michael@0: michael@0: MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset); michael@0: int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset); michael@0: michael@0: michael@0: typedef struct { michael@0: unsigned int sign[2]; michael@0: unsigned int classes[MV_CLASSES]; michael@0: unsigned int class0[CLASS0_SIZE]; michael@0: unsigned int bits[MV_OFFSET_BITS][2]; michael@0: unsigned int class0_fp[CLASS0_SIZE][4]; michael@0: unsigned int fp[4]; michael@0: unsigned int class0_hp[2]; michael@0: unsigned int hp[2]; michael@0: } nmv_component_counts; michael@0: michael@0: typedef struct { michael@0: unsigned int joints[MV_JOINTS]; michael@0: nmv_component_counts comps[2]; michael@0: } nmv_context_counts; michael@0: michael@0: void vp9_inc_mv(const MV *mv, nmv_context_counts *mvctx); michael@0: michael@0: #endif // VP9_COMMON_VP9_ENTROPYMV_H_