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 extern void __builtin_bambu_time_start();
49 extern void __builtin_bambu_time_stop();
50 
51 /* private prototypes */
52 static void decode_motion_vector
53 _ANSI_ARGS_ ((int *pred, int r_size, int motion_code,
54  int motion_residualesidual, int full_pel_vector));
55 
56 /* ISO/IEC 13818-2 sections 6.2.5.2, 6.3.17.2, and 7.6.3: Motion vectors */
57 void
58 __attribute__ ((noinline))
59 motion_vectors (PMV, dmvector, motion_vertical_field_select, s,
60  motion_vector_count, mv_format, h_r_size, v_r_size, dmv,
61  mvscale)
62  int PMV[2][2][2];
63  int dmvector[2];
64  int motion_vertical_field_select[2][2];
65  int s, motion_vector_count, mv_format, h_r_size, v_r_size, dmv, mvscale;
66 {
68  if (motion_vector_count == 1)
69  {
70  if (mv_format == MV_FIELD && !dmv)
71  {
72  motion_vertical_field_select[1][s] =
73  motion_vertical_field_select[0][s] = Get_Bits (1);
74  }
75 
76  motion_vector (PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale,
77  0);
78 
79  /* update other motion vector predictors */
80  PMV[1][s][0] = PMV[0][s][0];
81  PMV[1][s][1] = PMV[0][s][1];
82  }
83  else
84  {
85  motion_vertical_field_select[0][s] = Get_Bits (1);
86 
87  motion_vector (PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale,
88  0);
89 
90  motion_vertical_field_select[1][s] = Get_Bits (1);
91 
92  motion_vector (PMV[1][s], dmvector, h_r_size, v_r_size, dmv, mvscale,
93  0);
94  }
96 }
97 
98 /* get and decode motion vector and differential motion vector
99  for one prediction */
100 void
101 motion_vector (PMV, dmvector, h_r_size, v_r_size, dmv, mvscale,
102  full_pel_vector)
103  int *PMV;
104  int *dmvector;
105  int h_r_size;
106  int v_r_size;
107  int dmv; /* MPEG-2 only: get differential motion vectors */
108  int mvscale; /* MPEG-2 only: field vector in frame pic */
109  int full_pel_vector; /* MPEG-1 only */
110 {
111  int motion_code;
112  int motion_residual;
113 
114  /* horizontal component */
115  /* ISO/IEC 13818-2 Table B-10 */
116  motion_code = Get_motion_code ();
117 
118  motion_residual = (h_r_size != 0
119  && motion_code != 0) ? Get_Bits (h_r_size) : 0;
120 
121  decode_motion_vector (&PMV[0], h_r_size, motion_code, motion_residual,
122  full_pel_vector);
123 
124  if (dmv)
125  dmvector[0] = Get_dmvector ();
126 
127 
128  /* vertical component */
129  motion_code = Get_motion_code ();
130  motion_residual = (v_r_size != 0
131  && motion_code != 0) ? Get_Bits (v_r_size) : 0;
132 
133  if (mvscale)
134  PMV[1] >>= 1; /* DIV 2 */
135 
136  decode_motion_vector (&PMV[1], v_r_size, motion_code, motion_residual,
137  full_pel_vector);
138 
139  if (mvscale)
140  PMV[1] <<= 1;
141 
142  if (dmv)
143  dmvector[1] = Get_dmvector ();
144 
145 }
146 
147 /* calculate motion vector component */
148 /* ISO/IEC 13818-2 section 7.6.3.1: Decoding the motion vectors */
149 /* Note: the arithmetic here is more elegant than that which is shown
150  in 7.6.3.1. The end results (PMV[][][]) should, however, be the same. */
151 
152 static void
153 decode_motion_vector (pred, r_size, motion_code, motion_residual,
154  full_pel_vector)
155  int *pred;
156  int r_size, motion_code, motion_residual;
157  int full_pel_vector; /* MPEG-1 (ISO/IEC 11172-1) support */
158 {
159  int lim, vec;
160 
161  r_size = r_size % 32;
162  lim = 16 << r_size;
163  vec = full_pel_vector ? (*pred >> 1) : (*pred);
164 
165  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  else if (motion_code < 0)
172  {
173  vec -= ((-motion_code - 1) << r_size) + motion_residual + 1;
174  if (vec < -lim)
175  vec += lim + lim;
176  }
177  *pred = full_pel_vector ? (vec << 1) : vec;
178 }
int Get_motion_code()
Definition: getvlc.c:49
unsigned int Get_Bits(int N)
Definition: getbits.c:190
static void decode_motion_vector(int *pred, int r_size, int motion_code, int motion_residual, int full_pel_vector)
Definition: motion.c:153
void __builtin_bambu_time_stop()
void __attribute__((noinline))
Definition: motion.c:58
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
void __builtin_bambu_time_start()
int Get_dmvector()
Definition: getvlc.c:83
static void decode_motion_vector _ANSI_ARGS_((int *pred, int r_size, int motion_code, int motion_residualesidual, int full_pel_vector))
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
#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