1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/common/vp9_entropymv.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 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 + 1.15 +#ifndef VP9_COMMON_VP9_ENTROPYMV_H_ 1.16 +#define VP9_COMMON_VP9_ENTROPYMV_H_ 1.17 + 1.18 +#include "vp9/common/vp9_treecoder.h" 1.19 +#include "./vpx_config.h" 1.20 +#include "vp9/common/vp9_blockd.h" 1.21 + 1.22 +struct VP9Common; 1.23 + 1.24 +void vp9_entropy_mv_init(); 1.25 +void vp9_init_mv_probs(struct VP9Common *cm); 1.26 + 1.27 +void vp9_adapt_mv_probs(struct VP9Common *cm, int usehp); 1.28 +int vp9_use_mv_hp(const MV *ref); 1.29 + 1.30 +#define NMV_UPDATE_PROB 252 1.31 + 1.32 +/* Symbols for coding which components are zero jointly */ 1.33 +#define MV_JOINTS 4 1.34 +typedef enum { 1.35 + MV_JOINT_ZERO = 0, /* Zero vector */ 1.36 + MV_JOINT_HNZVZ = 1, /* Vert zero, hor nonzero */ 1.37 + MV_JOINT_HZVNZ = 2, /* Hor zero, vert nonzero */ 1.38 + MV_JOINT_HNZVNZ = 3, /* Both components nonzero */ 1.39 +} MV_JOINT_TYPE; 1.40 + 1.41 +static INLINE int mv_joint_vertical(MV_JOINT_TYPE type) { 1.42 + return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ; 1.43 +} 1.44 + 1.45 +static INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) { 1.46 + return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ; 1.47 +} 1.48 + 1.49 +/* Symbols for coding magnitude class of nonzero components */ 1.50 +#define MV_CLASSES 11 1.51 +typedef enum { 1.52 + MV_CLASS_0 = 0, /* (0, 2] integer pel */ 1.53 + MV_CLASS_1 = 1, /* (2, 4] integer pel */ 1.54 + MV_CLASS_2 = 2, /* (4, 8] integer pel */ 1.55 + MV_CLASS_3 = 3, /* (8, 16] integer pel */ 1.56 + MV_CLASS_4 = 4, /* (16, 32] integer pel */ 1.57 + MV_CLASS_5 = 5, /* (32, 64] integer pel */ 1.58 + MV_CLASS_6 = 6, /* (64, 128] integer pel */ 1.59 + MV_CLASS_7 = 7, /* (128, 256] integer pel */ 1.60 + MV_CLASS_8 = 8, /* (256, 512] integer pel */ 1.61 + MV_CLASS_9 = 9, /* (512, 1024] integer pel */ 1.62 + MV_CLASS_10 = 10, /* (1024,2048] integer pel */ 1.63 +} MV_CLASS_TYPE; 1.64 + 1.65 +#define CLASS0_BITS 1 /* bits at integer precision for class 0 */ 1.66 +#define CLASS0_SIZE (1 << CLASS0_BITS) 1.67 +#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2) 1.68 + 1.69 +#define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2) 1.70 +#define MV_MAX ((1 << MV_MAX_BITS) - 1) 1.71 +#define MV_VALS ((MV_MAX << 1) + 1) 1.72 + 1.73 +#define MV_IN_USE_BITS 14 1.74 +#define MV_UPP ((1 << MV_IN_USE_BITS) - 1) 1.75 +#define MV_LOW (-(1 << MV_IN_USE_BITS)) 1.76 + 1.77 +extern const vp9_tree_index vp9_mv_joint_tree[TREE_SIZE(MV_JOINTS)]; 1.78 +extern struct vp9_token vp9_mv_joint_encodings[MV_JOINTS]; 1.79 + 1.80 +extern const vp9_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)]; 1.81 +extern struct vp9_token vp9_mv_class_encodings[MV_CLASSES]; 1.82 + 1.83 +extern const vp9_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)]; 1.84 +extern struct vp9_token vp9_mv_class0_encodings[CLASS0_SIZE]; 1.85 + 1.86 +extern const vp9_tree_index vp9_mv_fp_tree[TREE_SIZE(4)]; 1.87 +extern struct vp9_token vp9_mv_fp_encodings[4]; 1.88 + 1.89 +typedef struct { 1.90 + vp9_prob sign; 1.91 + vp9_prob classes[MV_CLASSES - 1]; 1.92 + vp9_prob class0[CLASS0_SIZE - 1]; 1.93 + vp9_prob bits[MV_OFFSET_BITS]; 1.94 + vp9_prob class0_fp[CLASS0_SIZE][4 - 1]; 1.95 + vp9_prob fp[4 - 1]; 1.96 + vp9_prob class0_hp; 1.97 + vp9_prob hp; 1.98 +} nmv_component; 1.99 + 1.100 +typedef struct { 1.101 + vp9_prob joints[MV_JOINTS - 1]; 1.102 + nmv_component comps[2]; 1.103 +} nmv_context; 1.104 + 1.105 +static INLINE MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv) { 1.106 + if (mv->row == 0) { 1.107 + return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ; 1.108 + } else { 1.109 + return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ; 1.110 + } 1.111 +} 1.112 + 1.113 +MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset); 1.114 +int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset); 1.115 + 1.116 + 1.117 +typedef struct { 1.118 + unsigned int sign[2]; 1.119 + unsigned int classes[MV_CLASSES]; 1.120 + unsigned int class0[CLASS0_SIZE]; 1.121 + unsigned int bits[MV_OFFSET_BITS][2]; 1.122 + unsigned int class0_fp[CLASS0_SIZE][4]; 1.123 + unsigned int fp[4]; 1.124 + unsigned int class0_hp[2]; 1.125 + unsigned int hp[2]; 1.126 +} nmv_component_counts; 1.127 + 1.128 +typedef struct { 1.129 + unsigned int joints[MV_JOINTS]; 1.130 + nmv_component_counts comps[2]; 1.131 +} nmv_context_counts; 1.132 + 1.133 +void vp9_inc_mv(const MV *mv, nmv_context_counts *mvctx); 1.134 + 1.135 +#endif // VP9_COMMON_VP9_ENTROPYMV_H_