Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_ENTROPYMV_H_ |
| 13 | #define AV1_COMMON_ENTROPYMV_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | |
| 17 | #include "aom_dsp/prob.h" |
| 18 | |
| 19 | #include "av1/common/mv.h" |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 25 | struct AV1Common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 27 | void av1_init_mv_probs(struct AV1Common *cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | #define MV_UPDATE_PROB 252 |
| 30 | |
| 31 | /* Symbols for coding which components are zero jointly */ |
| 32 | #define MV_JOINTS 4 |
| 33 | typedef enum { |
| 34 | MV_JOINT_ZERO = 0, /* Zero vector */ |
| 35 | MV_JOINT_HNZVZ = 1, /* Vert zero, hor nonzero */ |
| 36 | MV_JOINT_HZVNZ = 2, /* Hor zero, vert nonzero */ |
| 37 | MV_JOINT_HNZVNZ = 3, /* Both components nonzero */ |
| 38 | } MV_JOINT_TYPE; |
| 39 | |
| 40 | static INLINE int mv_joint_vertical(MV_JOINT_TYPE type) { |
| 41 | return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ; |
| 42 | } |
| 43 | |
| 44 | static INLINE int mv_joint_horizontal(MV_JOINT_TYPE type) { |
| 45 | return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ; |
| 46 | } |
| 47 | |
| 48 | /* Symbols for coding magnitude class of nonzero components */ |
Yunqing Wang | 0e745f7 | 2018-02-28 09:14:47 -0800 | [diff] [blame] | 49 | #define MV_CLASSES 12 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 50 | typedef enum { |
| 51 | MV_CLASS_0 = 0, /* (0, 2] integer pel */ |
| 52 | MV_CLASS_1 = 1, /* (2, 4] integer pel */ |
| 53 | MV_CLASS_2 = 2, /* (4, 8] integer pel */ |
| 54 | MV_CLASS_3 = 3, /* (8, 16] integer pel */ |
| 55 | MV_CLASS_4 = 4, /* (16, 32] integer pel */ |
| 56 | MV_CLASS_5 = 5, /* (32, 64] integer pel */ |
| 57 | MV_CLASS_6 = 6, /* (64, 128] integer pel */ |
| 58 | MV_CLASS_7 = 7, /* (128, 256] integer pel */ |
| 59 | MV_CLASS_8 = 8, /* (256, 512] integer pel */ |
| 60 | MV_CLASS_9 = 9, /* (512, 1024] integer pel */ |
| 61 | MV_CLASS_10 = 10, /* (1024,2048] integer pel */ |
Yunqing Wang | 0e745f7 | 2018-02-28 09:14:47 -0800 | [diff] [blame] | 62 | MV_CLASS_11 = 11, /* (2048,4096] integer pel */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | } MV_CLASS_TYPE; |
| 64 | |
| 65 | #define CLASS0_BITS 1 /* bits at integer precision for class 0 */ |
| 66 | #define CLASS0_SIZE (1 << CLASS0_BITS) |
| 67 | #define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2) |
| 68 | #define MV_FP_SIZE 4 |
| 69 | |
| 70 | #define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2) |
| 71 | #define MV_MAX ((1 << MV_MAX_BITS) - 1) |
| 72 | #define MV_VALS ((MV_MAX << 1) + 1) |
| 73 | |
Yunqing Wang | f552a31 | 2018-02-28 15:01:11 -0800 | [diff] [blame] | 74 | #define MV_IN_USE_BITS 15 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 75 | #define MV_UPP ((1 << MV_IN_USE_BITS) - 1) |
| 76 | #define MV_LOW (-(1 << MV_IN_USE_BITS)) |
| 77 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | typedef struct { |
Debargha Mukherjee | 62fcfab | 2017-11-09 00:51:17 -0800 | [diff] [blame] | 79 | aom_cdf_prob classes_cdf[CDF_SIZE(MV_CLASSES)]; |
Thomas Davies | f3eb840 | 2017-02-20 18:20:20 +0000 | [diff] [blame] | 80 | aom_cdf_prob class0_fp_cdf[CLASS0_SIZE][CDF_SIZE(MV_FP_SIZE)]; |
| 81 | aom_cdf_prob fp_cdf[CDF_SIZE(MV_FP_SIZE)]; |
Debargha Mukherjee | 62fcfab | 2017-11-09 00:51:17 -0800 | [diff] [blame] | 82 | aom_cdf_prob sign_cdf[CDF_SIZE(2)]; |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 83 | aom_cdf_prob class0_hp_cdf[CDF_SIZE(2)]; |
| 84 | aom_cdf_prob hp_cdf[CDF_SIZE(2)]; |
| 85 | aom_cdf_prob class0_cdf[CDF_SIZE(CLASS0_SIZE)]; |
Debargha Mukherjee | 62fcfab | 2017-11-09 00:51:17 -0800 | [diff] [blame] | 86 | aom_cdf_prob bits_cdf[MV_OFFSET_BITS][CDF_SIZE(2)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 87 | } nmv_component; |
| 88 | |
| 89 | typedef struct { |
Debargha Mukherjee | 62fcfab | 2017-11-09 00:51:17 -0800 | [diff] [blame] | 90 | aom_cdf_prob joints_cdf[CDF_SIZE(MV_JOINTS)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 91 | nmv_component comps[2]; |
| 92 | } nmv_context; |
| 93 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 94 | static INLINE MV_JOINT_TYPE av1_get_mv_joint(const MV *mv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 95 | if (mv->row == 0) { |
| 96 | return mv->col == 0 ? MV_JOINT_ZERO : MV_JOINT_HNZVZ; |
| 97 | } else { |
| 98 | return mv->col == 0 ? MV_JOINT_HZVNZ : MV_JOINT_HNZVNZ; |
| 99 | } |
| 100 | } |
| 101 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 102 | MV_CLASS_TYPE av1_get_mv_class(int z, int *offset); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 103 | |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 104 | typedef enum { |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 105 | MV_SUBPEL_NONE = -1, |
Alex Converse | 6b2584c | 2017-05-02 09:51:21 -0700 | [diff] [blame] | 106 | MV_SUBPEL_LOW_PRECISION = 0, |
| 107 | MV_SUBPEL_HIGH_PRECISION, |
| 108 | } MvSubpelPrecision; |
| 109 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 110 | #ifdef __cplusplus |
| 111 | } // extern "C" |
| 112 | #endif |
| 113 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 114 | #endif // AV1_COMMON_ENTROPYMV_H_ |