PandA-2024.02
motion.c
Go to the documentation of this file.
1 /*
2 +--------------------------------------------------------------------------+
3 | CHStone : a suite of benchmark programs for C-based High-Level Synthesis |
4 | ======================================================================== |
5 | |
6 | * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, |
7 | H. Takada and K. Ishii |
8 | Nagoya University, Japan |
9 | |
10 | * Remark : |
11 | 1. This source code is modified to unify the formats of the benchmark |
12 | programs in CHStone. |
13 | 2. Test vectors are added for CHStone. |
14 | 3. If "main_result" is 0 at the end of the program, the program is |
15 | correctly executed. |
16 | 4. Please follow the copyright of each benchmark program. |
17 +--------------------------------------------------------------------------+
18 */
19 /* motion.c, motion vector decoding */
20 
21 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
22 
23 /*
24  * Disclaimer of Warranty
25  *
26  * These software programs are available to the user without any license fee or
27  * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
28  * any and all warranties, whether express, implied, or statuary, including any
29  * implied warranties or merchantability or of fitness for a particular
30  * purpose. In no event shall the copyright-holder be liable for any
31  * incidental, punitive, or consequential damages of any kind whatsoever
32  * arising from the use of these programs.
33  *
34  * This disclaimer of warranty extends to the user of these programs and user's
35  * customers, employees, agents, transferees, successors, and assigns.
36  *
37  * The MPEG Software Simulation Group does not represent or warrant that the
38  * programs furnished hereunder are free of infringement of any third-party
39  * patents.
40  *
41  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
42  * are subject to royalty fees to patent holders. Many of these patents are
43  * general enough such that they are unavoidable regardless of implementation
44  * design.
45  *
46  */
47 
48 /* private prototypes */
49 static void decode_motion_vector
50 _ANSI_ARGS_ ((int *pred, int r_size, int motion_code,
51  int motion_residualesidual, int full_pel_vector));
52 
53 /* ISO/IEC 13818-2 sections 6.2.5.2, 6.3.17.2, and 7.6.3: Motion vectors */
54 void
55 motion_vectors (PMV, dmvector, motion_vertical_field_select, s,
56  motion_vector_count, mv_format, h_r_size, v_r_size, dmv,
57  mvscale)
58  int PMV[2][2][2];
59  int dmvector[2];
60  int motion_vertical_field_select[2][2];
61  int s, motion_vector_count, mv_format, h_r_size, v_r_size, dmv, mvscale;
62 {
63  if (motion_vector_count == 1)
64  {
65  if (mv_format == MV_FIELD && !dmv)
66  {
67  motion_vertical_field_select[1][s] =
68  motion_vertical_field_select[0][s] = Get_Bits (1);
69  }
70 
71  motion_vector (PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale,
72  0);
73 
74  /* update other motion vector predictors */
75  PMV[1][s][0] = PMV[0][s][0];
76  PMV[1][s][1] = PMV[0][s][1];
77  }
78  else
79  {
80  motion_vertical_field_select[0][s] = Get_Bits (1);
81 
82  motion_vector (PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale,
83  0);
84 
85  motion_vertical_field_select[1][s] = Get_Bits (1);
86 
87  motion_vector (PMV[1][s], dmvector, h_r_size, v_r_size, dmv, mvscale,
88  0);
89  }
90 }
91 
92 /* get and decode motion vector and differential motion vector
93  for one prediction */
94 void
95 motion_vector (PMV, dmvector, h_r_size, v_r_size, dmv, mvscale,
96  full_pel_vector)
97  int *PMV;
98  int *dmvector;
99  int h_r_size;
100  int v_r_size;
101  int dmv; /* MPEG-2 only: get differential motion vectors */
102  int mvscale; /* MPEG-2 only: field vector in frame pic */
103  int full_pel_vector; /* MPEG-1 only */
104 {
105  int motion_code;
106  int motion_residual;
107 
108  /* horizontal component */
109  /* ISO/IEC 13818-2 Table B-10 */
110  motion_code = Get_motion_code ();
111 
112  motion_residual = (h_r_size != 0
113  && motion_code != 0) ? Get_Bits (h_r_size) : 0;
114 
115  decode_motion_vector (&PMV[0], h_r_size, motion_code, motion_residual,
116  full_pel_vector);
117 
118  if (dmv)
119  dmvector[0] = Get_dmvector ();
120 
121 
122  /* vertical component */
123  motion_code = Get_motion_code ();
124  motion_residual = (v_r_size != 0
125  && motion_code != 0) ? Get_Bits (v_r_size) : 0;
126 
127  if (mvscale)
128  PMV[1] >>= 1; /* DIV 2 */
129 
130  decode_motion_vector (&PMV[1], v_r_size, motion_code, motion_residual,
131  full_pel_vector);
132 
133  if (mvscale)
134  PMV[1] <<= 1;
135 
136  if (dmv)
137  dmvector[1] = Get_dmvector ();
138 
139 }
140 
141 /* calculate motion vector component */
142 /* ISO/IEC 13818-2 section 7.6.3.1: Decoding the motion vectors */
143 /* Note: the arithmetic here is more elegant than that which is shown
144  in 7.6.3.1. The end results (PMV[][][]) should, however, be the same. */
145 
146 static void
147 decode_motion_vector (pred, r_size, motion_code, motion_residual,
148  full_pel_vector)
149  int *pred;
150  int r_size, motion_code, motion_residual;
151  int full_pel_vector; /* MPEG-1 (ISO/IEC 11172-1) support */
152 {
153  int lim, vec;
154 
155  r_size = r_size % 32;
156  lim = 16 << r_size;
157  vec = full_pel_vector ? (*pred >> 1) : (*pred);
158 
159  if (motion_code > 0)
160  {
161  vec += ((motion_code - 1) << r_size) + motion_residual + 1;
162  if (vec >= lim)
163  vec -= lim + lim;
164  }
165  else if (motion_code < 0)
166  {
167  vec -= ((-motion_code - 1) << r_size) + motion_residual + 1;
168  if (vec < -lim)
169  vec += lim + lim;
170  }
171  *pred = full_pel_vector ? (vec << 1) : vec;
172 }
static void decode_motion_vector _ANSI_ARGS_((int *pred, int r_size, int motion_code, int motion_residualesidual, int full_pel_vector))
int Get_motion_code()
Definition: getvlc.c:49
unsigned int Get_Bits(int N)
Definition: getbits.c:190
void motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size, int dmv, int mvscale, int full_pel_vector)
Definition: motion.c:95
int Get_dmvector()
Definition: getvlc.c:83
void motion_vectors(PMV, dmvector, motion_vertical_field_select, int s, int motion_vector_count, int mv_format, int h_r_size, int v_r_size, int dmv, int mvscale)
Definition: motion.c:55
static void decode_motion_vector(int *pred, int r_size, int motion_code, int motion_residual, int full_pel_vector)
Definition: motion.c:147
#define MV_FIELD
Definition: mpeg2dec.h:53

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13