4
* Procedures to compute motion vectors.
9
* Copyright (c) 1995 The Regents of the University of California.
10
* All rights reserved.
12
* Permission to use, copy, modify, and distribute this software and its
13
* documentation for any purpose, without fee, and without written agreement is
14
* hereby granted, provided that the above copyright notice and the following
15
* two paragraphs appear in all copies of this software.
17
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
18
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
19
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
20
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
25
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
26
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
30
* Portions of this software Copyright (c) 1995 Brown University.
31
* All rights reserved.
33
* Permission to use, copy, modify, and distribute this software and its
34
* documentation for any purpose, without fee, and without written agreement
35
* is hereby granted, provided that the above copyright notice and the
36
* following two paragraphs appear in all copies of this software.
38
* IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR
39
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
40
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN
41
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
* BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
44
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
45
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
46
* BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
47
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
55
Changes to make the code reentrant:
56
deglobalize curVidStream
59
-lsh@cs.brown.edu (Loring Holden)
64
*--------------------------------------------------------------
68
* Computes motion vector given parameters previously parsed
72
* Reconstructed motion vector info is put into recon_* parameters
73
* passed to this function. Also updated previous motion vector
79
*--------------------------------------------------------------
82
#define ComputeVector(recon_right_ptr, recon_down_ptr, recon_right_prev, recon_down_prev, f, full_pel_vector, motion_h_code, motion_v_code, motion_h_r, motion_v_r) \
85
int comp_h_r, comp_v_r; \
86
int right_little, right_big, down_little, down_big; \
87
int max, min, new_vector; \
89
/* The following procedure for the reconstruction of motion vectors \
90
is a direct and simple implementation of the instructions given \
91
in the mpeg December 1991 standard draft. \
94
if (f == 1 || motion_h_code == 0) \
97
comp_h_r = f - 1 - motion_h_r; \
99
if (f == 1 || motion_v_code == 0) \
102
comp_v_r = f - 1 - motion_v_r; \
104
right_little = motion_h_code * f; \
105
if (right_little == 0) \
108
if (right_little > 0) { \
109
right_little = right_little - comp_h_r; \
110
right_big = right_little - 32 * f; \
113
right_little = right_little + comp_h_r; \
114
right_big = right_little + 32 * f; \
118
down_little = motion_v_code * f; \
119
if (down_little == 0) \
122
if (down_little > 0) { \
123
down_little = down_little - comp_v_r; \
124
down_big = down_little - 32 * f; \
127
down_little = down_little + comp_v_r; \
128
down_big = down_little + 32 * f; \
135
new_vector = recon_right_prev + right_little; \
137
if (new_vector <= max && new_vector >= min) \
138
*recon_right_ptr = recon_right_prev + right_little; \
139
/* just new_vector */ \
141
*recon_right_ptr = recon_right_prev + right_big; \
142
recon_right_prev = *recon_right_ptr; \
143
if (full_pel_vector) \
144
*recon_right_ptr = *recon_right_ptr << 1; \
146
new_vector = recon_down_prev + down_little; \
147
if (new_vector <= max && new_vector >= min) \
148
*recon_down_ptr = recon_down_prev + down_little; \
149
/* just new_vector */ \
151
*recon_down_ptr = recon_down_prev + down_big; \
152
recon_down_prev = *recon_down_ptr; \
153
if (full_pel_vector) \
154
*recon_down_ptr = *recon_down_ptr << 1; \
159
*--------------------------------------------------------------
161
* ComputeForwVector --
163
* Computes forward motion vector by calling ComputeVector
164
* with appropriate parameters.
167
* Reconstructed motion vector placed in recon_right_for_ptr and
168
* recon_down_for_ptr.
173
*--------------------------------------------------------------
176
void ComputeForwVector( int* recon_right_for_ptr, int* recon_down_for_ptr,
177
VidStream* the_stream )
183
picture = &(the_stream->picture);
184
mblock = &(the_stream->mblock);
186
ComputeVector(recon_right_for_ptr, recon_down_for_ptr,
187
mblock->recon_right_for_prev,
188
mblock->recon_down_for_prev,
189
(int) picture->forw_f,
190
picture->full_pel_forw_vector,
191
mblock->motion_h_forw_code, mblock->motion_v_forw_code,
192
mblock->motion_h_forw_r, mblock->motion_v_forw_r);
197
*--------------------------------------------------------------
199
* ComputeBackVector --
201
* Computes backward motion vector by calling ComputeVector
202
* with appropriate parameters.
205
* Reconstructed motion vector placed in recon_right_back_ptr and
206
* recon_down_back_ptr.
211
*--------------------------------------------------------------
214
void ComputeBackVector( int* recon_right_back_ptr, int* recon_down_back_ptr,
215
VidStream* the_stream )
220
picture = &(the_stream->picture);
221
mblock = &(the_stream->mblock);
223
ComputeVector(recon_right_back_ptr, recon_down_back_ptr,
224
mblock->recon_right_back_prev,
225
mblock->recon_down_back_prev,
226
(int) picture->back_f,
227
picture->full_pel_back_vector,
228
mblock->motion_h_back_code, mblock->motion_v_back_code,
229
mblock->motion_h_back_r, mblock->motion_v_back_r);