1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*
class for motionvectors
Copyright (C) 1999 Martin Vogt
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation.
For more information look at the file COPYRIGHT in this package
*/
#include "motionVector.h"
MotionVector::MotionVector() {
}
MotionVector::~MotionVector() {
}
/*
*--------------------------------------------------------------
*
* ComputeVector --
*
* Computes motion vector given parameters previously parsed
* and reconstructed.
*
* Results:
* Reconstructed motion vector info is put into recon_* parameters
* passed to this function. Also updated previous motion vector
* information.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
void MotionVector::computeVector(int* recon_right_ptr,
int* recon_down_ptr,
int& recon_right_prev,
int& recon_down_prev,
unsigned int& f,
unsigned int& full_pel_vector,
int& motion_h_code,
int& motion_v_code,
unsigned int& motion_h_r,
unsigned int& motion_v_r) {
int comp_h_r, comp_v_r;
int right_little, right_big, down_little, down_big;
int max, min, new_vector;
/* The following procedure for the reconstruction of motion vectors
is a direct and simple implementation of the instructions given
in the mpeg December 1991 standard draft.
*/
if (f == 1 || motion_h_code == 0)
comp_h_r = 0;
else
comp_h_r = f - 1 - motion_h_r;
if (f == 1 || motion_v_code == 0)
comp_v_r = 0;
else
comp_v_r = f - 1 - motion_v_r;
right_little = motion_h_code * f;
if (right_little == 0)
right_big = 0;
else {
if (right_little > 0) {
right_little = right_little - comp_h_r;
right_big = right_little - 32 * f;
}
else {
right_little = right_little + comp_h_r;
right_big = right_little + 32 * f;
}
}
down_little = motion_v_code * f;
if (down_little == 0)
down_big = 0;
else {
if (down_little > 0) {
down_little = down_little - comp_v_r;
down_big = down_little - 32 * f;
}
else {
down_little = down_little + comp_v_r;
down_big = down_little + 32 * f;
}
}
max = 16 * f - 1;
min = -16 * f;
new_vector = recon_right_prev + right_little;
if (new_vector <= max && new_vector >= min)
*recon_right_ptr = recon_right_prev + right_little;
/* just new_vector */
else
*recon_right_ptr = recon_right_prev + right_big;
recon_right_prev = *recon_right_ptr;
if (full_pel_vector)
*recon_right_ptr = *recon_right_ptr << 1;
new_vector = recon_down_prev + down_little;
if (new_vector <= max && new_vector >= min)
*recon_down_ptr = recon_down_prev + down_little;
/* just new_vector */
else
*recon_down_ptr = recon_down_prev + down_big;
recon_down_prev = *recon_down_ptr;
if (full_pel_vector)
*recon_down_ptr = *recon_down_ptr << 1;
}
|