xref: /aosp_15_r20/external/libaom/av1/common/entropymv.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_COMMON_ENTROPYMV_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_COMMON_ENTROPYMV_H_
14*77c1e3ccSAndroid Build Coastguard Worker 
15*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
16*77c1e3ccSAndroid Build Coastguard Worker 
17*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/prob.h"
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/mv.h"
20*77c1e3ccSAndroid Build Coastguard Worker 
21*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
22*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
23*77c1e3ccSAndroid Build Coastguard Worker #endif
24*77c1e3ccSAndroid Build Coastguard Worker 
25*77c1e3ccSAndroid Build Coastguard Worker struct AV1Common;
26*77c1e3ccSAndroid Build Coastguard Worker 
27*77c1e3ccSAndroid Build Coastguard Worker void av1_init_mv_probs(struct AV1Common *cm);
28*77c1e3ccSAndroid Build Coastguard Worker 
29*77c1e3ccSAndroid Build Coastguard Worker #define MV_UPDATE_PROB 252
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker /* Symbols for coding which components are zero jointly */
32*77c1e3ccSAndroid Build Coastguard Worker #define MV_JOINTS 4
33*77c1e3ccSAndroid Build Coastguard Worker enum {
34*77c1e3ccSAndroid Build Coastguard Worker   MV_JOINT_ZERO = 0,   /* Zero vector */
35*77c1e3ccSAndroid Build Coastguard Worker   MV_JOINT_HNZVZ = 1,  /* Vert zero, hor nonzero */
36*77c1e3ccSAndroid Build Coastguard Worker   MV_JOINT_HZVNZ = 2,  /* Hor zero, vert nonzero */
37*77c1e3ccSAndroid Build Coastguard Worker   MV_JOINT_HNZVNZ = 3, /* Both components nonzero */
38*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(MV_JOINT_TYPE);
39*77c1e3ccSAndroid Build Coastguard Worker 
mv_joint_vertical(MV_JOINT_TYPE type)40*77c1e3ccSAndroid Build Coastguard Worker static inline int mv_joint_vertical(MV_JOINT_TYPE type) {
41*77c1e3ccSAndroid Build Coastguard Worker   return type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ;
42*77c1e3ccSAndroid Build Coastguard Worker }
43*77c1e3ccSAndroid Build Coastguard Worker 
mv_joint_horizontal(MV_JOINT_TYPE type)44*77c1e3ccSAndroid Build Coastguard Worker static inline int mv_joint_horizontal(MV_JOINT_TYPE type) {
45*77c1e3ccSAndroid Build Coastguard Worker   return type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ;
46*77c1e3ccSAndroid Build Coastguard Worker }
47*77c1e3ccSAndroid Build Coastguard Worker 
48*77c1e3ccSAndroid Build Coastguard Worker /* Symbols for coding magnitude class of nonzero components */
49*77c1e3ccSAndroid Build Coastguard Worker #define MV_CLASSES 11
50*77c1e3ccSAndroid Build Coastguard Worker enum {
51*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_0 = 0,   /* (0, 2]     integer pel */
52*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_1 = 1,   /* (2, 4]     integer pel */
53*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_2 = 2,   /* (4, 8]     integer pel */
54*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_3 = 3,   /* (8, 16]    integer pel */
55*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_4 = 4,   /* (16, 32]   integer pel */
56*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_5 = 5,   /* (32, 64]   integer pel */
57*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_6 = 6,   /* (64, 128]  integer pel */
58*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_7 = 7,   /* (128, 256] integer pel */
59*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_8 = 8,   /* (256, 512] integer pel */
60*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_9 = 9,   /* (512, 1024] integer pel */
61*77c1e3ccSAndroid Build Coastguard Worker   MV_CLASS_10 = 10, /* (1024,2048] integer pel */
62*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(MV_CLASS_TYPE);
63*77c1e3ccSAndroid Build Coastguard Worker 
64*77c1e3ccSAndroid Build Coastguard Worker #define CLASS0_BITS 1 /* bits at integer precision for class 0 */
65*77c1e3ccSAndroid Build Coastguard Worker #define CLASS0_SIZE (1 << CLASS0_BITS)
66*77c1e3ccSAndroid Build Coastguard Worker #define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
67*77c1e3ccSAndroid Build Coastguard Worker #define MV_BITS_CONTEXTS 6
68*77c1e3ccSAndroid Build Coastguard Worker #define MV_FP_SIZE 4
69*77c1e3ccSAndroid Build Coastguard Worker 
70*77c1e3ccSAndroid Build Coastguard Worker #define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2)
71*77c1e3ccSAndroid Build Coastguard Worker #define MV_MAX ((1 << MV_MAX_BITS) - 1)
72*77c1e3ccSAndroid Build Coastguard Worker #define MV_VALS ((MV_MAX << 1) + 1)
73*77c1e3ccSAndroid Build Coastguard Worker 
74*77c1e3ccSAndroid Build Coastguard Worker #define MV_IN_USE_BITS 14
75*77c1e3ccSAndroid Build Coastguard Worker #define MV_UPP (1 << MV_IN_USE_BITS)
76*77c1e3ccSAndroid Build Coastguard Worker #define MV_LOW (-(1 << MV_IN_USE_BITS))
77*77c1e3ccSAndroid Build Coastguard Worker 
78*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
79*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob classes_cdf[CDF_SIZE(MV_CLASSES)];
80*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob class0_fp_cdf[CLASS0_SIZE][CDF_SIZE(MV_FP_SIZE)];
81*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob fp_cdf[CDF_SIZE(MV_FP_SIZE)];
82*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob sign_cdf[CDF_SIZE(2)];
83*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob class0_hp_cdf[CDF_SIZE(2)];
84*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob hp_cdf[CDF_SIZE(2)];
85*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob class0_cdf[CDF_SIZE(CLASS0_SIZE)];
86*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob bits_cdf[MV_OFFSET_BITS][CDF_SIZE(2)];
87*77c1e3ccSAndroid Build Coastguard Worker } nmv_component;
88*77c1e3ccSAndroid Build Coastguard Worker 
89*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
90*77c1e3ccSAndroid Build Coastguard Worker   aom_cdf_prob joints_cdf[CDF_SIZE(MV_JOINTS)];
91*77c1e3ccSAndroid Build Coastguard Worker   nmv_component comps[2];
92*77c1e3ccSAndroid Build Coastguard Worker } nmv_context;
93*77c1e3ccSAndroid Build Coastguard Worker 
94*77c1e3ccSAndroid Build Coastguard Worker enum {
95*77c1e3ccSAndroid Build Coastguard Worker   MV_SUBPEL_NONE = -1,
96*77c1e3ccSAndroid Build Coastguard Worker   MV_SUBPEL_LOW_PRECISION = 0,
97*77c1e3ccSAndroid Build Coastguard Worker   MV_SUBPEL_HIGH_PRECISION,
98*77c1e3ccSAndroid Build Coastguard Worker } SENUM1BYTE(MvSubpelPrecision);
99*77c1e3ccSAndroid Build Coastguard Worker 
100*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
101*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
102*77c1e3ccSAndroid Build Coastguard Worker #endif
103*77c1e3ccSAndroid Build Coastguard Worker 
104*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AV1_COMMON_ENTROPYMV_H_
105