r956: README.BUILD - add more library recommendations
[cinelerra_cv/ct.git] / libmpeg3 / video / reconstruct.c
blobba5c41775210379a49bc3e0860d8ff475df3d3c3
1 #include "mpeg3private.h"
2 #include "mpeg3protos.h"
3 #include <stdio.h>
6 static inline void rec(unsigned char *s, unsigned char *d, int lx2, int h)
8 int j;
9 for(j = 0; j < h; j++, s += lx2, d += lx2)
11 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
12 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
13 d[8] = s[8]; d[9] = s[9]; d[10] = s[10]; d[11] = s[11];
14 d[12] = s[12]; d[13] = s[13]; d[14] = s[14]; d[15] = s[15];
20 static inline void recc(unsigned char *s, unsigned char *d, int lx2, int h)
22 int j;
23 for(j = 0; j < h; j++, s += lx2, d += lx2)
25 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
26 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
30 static inline void reca(unsigned char *s, unsigned char *d, int lx2, int h)
32 int j;
33 for(j = 0; j < h; j++, s +=lx2, d +=lx2)
35 d[0] = (unsigned int)(d[0] + s[0] + 1) >> 1;
36 d[1] = (unsigned int)(d[1] + s[1] + 1) >> 1;
37 d[2] = (unsigned int)(d[2] + s[2] + 1) >> 1;
38 d[3] = (unsigned int)(d[3] + s[3] + 1) >> 1;
39 d[4] = (unsigned int)(d[4] + s[4] + 1) >> 1;
40 d[5] = (unsigned int)(d[5] + s[5] + 1) >> 1;
41 d[6] = (unsigned int)(d[6] + s[6] + 1) >> 1;
42 d[7] = (unsigned int)(d[7] + s[7] + 1) >> 1;
43 d[8] = (unsigned int)(d[8] + s[8] + 1) >> 1;
44 d[9] = (unsigned int)(d[9] + s[9] + 1) >> 1;
45 d[10] = (unsigned int)(d[10] + s[10] + 1) >> 1;
46 d[11] = (unsigned int)(d[11] + s[11] + 1) >> 1;
47 d[12] = (unsigned int)(d[12] + s[12] + 1) >> 1;
48 d[13] = (unsigned int)(d[13] + s[13] + 1) >> 1;
49 d[14] = (unsigned int)(d[14] + s[14] + 1) >> 1;
50 d[15] = (unsigned int)(d[15] + s[15] + 1) >> 1;
54 static inline void recac(unsigned char *s, unsigned char *d, int lx2, int h)
56 int j;
57 for(j = 0; j < h; j++, s += lx2, d += lx2)
59 d[0] = (unsigned int)(d[0] + s[0] + 1)>>1;
60 d[1] = (unsigned int)(d[1] + s[1] + 1)>>1;
61 d[2] = (unsigned int)(d[2] + s[2] + 1)>>1;
62 d[3] = (unsigned int)(d[3] + s[3] + 1)>>1;
63 d[4] = (unsigned int)(d[4] + s[4] + 1)>>1;
64 d[5] = (unsigned int)(d[5] + s[5] + 1)>>1;
65 d[6] = (unsigned int)(d[6] + s[6] + 1)>>1;
66 d[7] = (unsigned int)(d[7] + s[7] + 1)>>1;
70 static inline void recv(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
72 unsigned char *dp,*sp,*sp2;
73 int j;
74 sp = s;
75 sp2 = s + lx;
76 dp = d;
77 for(j = 0; j < h; j++)
79 dp[0] = (unsigned int)(sp[0] + sp2[0] + 1) >> 1;
80 dp[1] = (unsigned int)(sp[1] + sp2[1] + 1) >> 1;
81 dp[2] = (unsigned int)(sp[2] + sp2[2] + 1) >> 1;
82 dp[3] = (unsigned int)(sp[3] + sp2[3] + 1) >> 1;
83 dp[4] = (unsigned int)(sp[4] + sp2[4] + 1) >> 1;
84 dp[5] = (unsigned int)(sp[5] + sp2[5] + 1) >> 1;
85 dp[6] = (unsigned int)(sp[6] + sp2[6] + 1) >> 1;
86 dp[7] = (unsigned int)(sp[7] + sp2[7] + 1) >> 1;
87 dp[8] = (unsigned int)(sp[8] + sp2[8] + 1) >> 1;
88 dp[9] = (unsigned int)(sp[9] + sp2[9] + 1) >> 1;
89 dp[10] = (unsigned int)(sp[10] + sp2[10] + 1) >> 1;
90 dp[11] = (unsigned int)(sp[11] + sp2[11] + 1) >> 1;
91 dp[12] = (unsigned int)(sp[12] + sp2[12] + 1) >> 1;
92 dp[13] = (unsigned int)(sp[13] + sp2[13] + 1) >> 1;
93 dp[14] = (unsigned int)(sp[14] + sp2[14] + 1) >> 1;
94 dp[15] = (unsigned int)(sp[15] + sp2[15] + 1) >> 1;
95 sp+= lx2;
96 sp2+= lx2;
97 dp+= lx2;
101 static inline void recvc(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
103 unsigned char *dp,*sp,*sp2;
104 int j;
106 sp = s;
107 sp2 = s+lx;
108 dp = d;
109 for(j = 0; j < h; j++)
111 dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
112 dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
113 dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
114 dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
115 dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
116 dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
117 dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
118 dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
119 sp+= lx2;
120 sp2+= lx2;
121 dp+= lx2;
126 static inline void recva(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
128 unsigned char *dp,*sp,*sp2;
129 int j;
131 sp = s;
132 sp2 = s+lx;
133 dp = d;
134 for (j=0; j<h; j++){
135 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
136 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
137 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
138 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
139 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
140 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
141 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
142 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
143 dp[8] = (dp[8] + ((unsigned int)(sp[8]+sp2[8]+1)>>1) + 1)>>1;
144 dp[9] = (dp[9] + ((unsigned int)(sp[9]+sp2[9]+1)>>1) + 1)>>1;
145 dp[10] = (dp[10] + ((unsigned int)(sp[10]+sp2[10]+1)>>1) + 1)>>1;
146 dp[11] = (dp[11] + ((unsigned int)(sp[11]+sp2[11]+1)>>1) + 1)>>1;
147 dp[12] = (dp[12] + ((unsigned int)(sp[12]+sp2[12]+1)>>1) + 1)>>1;
148 dp[13] = (dp[13] + ((unsigned int)(sp[13]+sp2[13]+1)>>1) + 1)>>1;
149 dp[14] = (dp[14] + ((unsigned int)(sp[14]+sp2[14]+1)>>1) + 1)>>1;
150 dp[15] = (dp[15] + ((unsigned int)(sp[15]+sp2[15]+1)>>1) + 1)>>1;
151 sp+= lx2;
152 sp2+= lx2;
153 dp+= lx2;
158 static inline void recvac(unsigned char *s, unsigned char *d, int lx,int lx2, int h){
159 unsigned char *dp,*sp,*sp2;
160 int j;
162 sp = s;
163 sp2 = s+lx;
164 dp = d;
165 for (j=0; j<h; j++){
166 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
167 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
168 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
169 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
170 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
171 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
172 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
173 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
174 sp+= lx2;
175 sp2+= lx2;
176 dp+= lx2;
181 static inline void rech(unsigned char *s, unsigned char *d, int lx2, int h){
182 unsigned char *dp,*sp;
183 unsigned int s1,s2;
184 int j;
186 sp = s;
187 dp = d;
188 for (j=0; j<h; j++){
189 s1=sp[0];
190 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
191 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
192 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
193 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
194 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
195 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
196 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
197 dp[7] = (unsigned int)(s2+(s1=sp[8])+1)>>1;
198 dp[8] = (unsigned int)(s1+(s2=sp[9])+1)>>1;
199 dp[9] = (unsigned int)(s2+(s1=sp[10])+1)>>1;
200 dp[10] = (unsigned int)(s1+(s2=sp[11])+1)>>1;
201 dp[11] = (unsigned int)(s2+(s1=sp[12])+1)>>1;
202 dp[12] = (unsigned int)(s1+(s2=sp[13])+1)>>1;
203 dp[13] = (unsigned int)(s2+(s1=sp[14])+1)>>1;
204 dp[14] = (unsigned int)(s1+(s2=sp[15])+1)>>1;
205 dp[15] = (unsigned int)(s2+sp[16]+1)>>1;
206 sp+= lx2;
207 dp+= lx2;
212 static inline void rechc(unsigned char *s,unsigned char *d, int lx2, int h){
213 unsigned char *dp,*sp;
214 unsigned int s1,s2;
215 int j;
217 sp = s;
218 dp = d;
219 for (j=0; j<h; j++){
220 s1=sp[0];
221 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
222 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
223 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
224 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
225 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
226 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
227 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
228 dp[7] = (unsigned int)(s2+sp[8]+1)>>1;
229 sp+= lx2;
230 dp+= lx2;
234 static inline void recha(unsigned char *s, unsigned char *d,int lx2, int h)
236 unsigned char *dp,*sp;
237 unsigned int s1,s2;
238 int j;
240 sp = s;
241 dp = d;
242 for (j = 0; j < h; j++)
244 s1 = sp[0];
245 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
246 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
247 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
248 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
249 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
250 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
251 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
252 dp[7] = (dp[7] + ((unsigned int)(s2 + (s1 = sp[8]) + 1) >> 1) + 1) >> 1;
253 dp[8] = (dp[8] + ((unsigned int)(s1 + (s2 = sp[9]) + 1) >> 1) + 1) >> 1;
254 dp[9] = (dp[9] + ((unsigned int)(s2 + (s1 = sp[10]) + 1) >> 1) + 1) >> 1;
255 dp[10] = (dp[10] + ((unsigned int)(s1 + (s2 = sp[11]) + 1) >> 1) + 1) >> 1;
256 dp[11] = (dp[11] + ((unsigned int)(s2 + (s1 = sp[12]) + 1) >> 1) + 1) >> 1;
257 dp[12] = (dp[12] + ((unsigned int)(s1 + (s2 = sp[13]) + 1) >> 1) + 1) >> 1;
258 dp[13] = (dp[13] + ((unsigned int)(s2 + (s1 = sp[14]) + 1) >> 1) + 1) >> 1;
259 dp[14] = (dp[14] + ((unsigned int)(s1 + (s2 = sp[15]) + 1) >> 1) + 1) >> 1;
260 dp[15] = (dp[15] + ((unsigned int)(s2 + sp[16] + 1) >> 1) + 1) >> 1;
261 sp += lx2;
262 dp += lx2;
267 static inline void rechac(unsigned char *s,unsigned char *d, int lx2, int h)
269 unsigned char *dp,*sp;
270 unsigned int s1,s2;
271 int j;
273 sp = s;
274 dp = d;
275 for(j = 0; j < h; j++)
277 s1 = sp[0];
278 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
279 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
280 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
281 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
282 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
283 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
284 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
285 dp[7] = (dp[7] + ((unsigned int)(s2 + sp[8] + 1) >> 1) + 1) >> 1;
286 sp += lx2;
287 dp += lx2;
292 static inline void rec4(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
294 unsigned char *dp,*sp,*sp2;
295 unsigned int s1,s2,s3,s4;
296 int j;
298 sp = s;
299 sp2 = s+lx;
300 dp = d;
301 for (j=0; j<h; j++){
302 s1=sp[0]; s3=sp2[0];
303 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
304 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
305 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
306 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
307 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
308 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
309 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
310 dp[7] = (unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2;
311 dp[8] = (unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2;
312 dp[9] = (unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2;
313 dp[10] = (unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2;
314 dp[11] = (unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2;
315 dp[12] = (unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2;
316 dp[13] = (unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2;
317 dp[14] = (unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2;
318 dp[15] = (unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2;
319 sp+= lx2;
320 sp2+= lx2;
321 dp+= lx2;
326 static inline void rec4c(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
328 unsigned char *dp,*sp,*sp2;
329 unsigned int s1,s2,s3,s4;
330 int j;
332 sp = s;
333 sp2 = s+lx;
334 dp = d;
335 for (j=0; j<h; j++){
336 s1=sp[0]; s3=sp2[0];
337 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
338 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
339 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
340 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
341 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
342 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
343 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
344 dp[7] = (unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2;
345 sp+= lx2;
346 sp2+= lx2;
347 dp+= lx2;
352 static inline void rec4a(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
354 unsigned char *dp=d, *sp=s, *sp2=s+lx;
355 unsigned int s1, s2, s3, s4;
356 int j;
359 sp = s;
360 sp2 = s+lx;
361 dp = d;
363 for (j=0; j<h; j++){
364 s1=sp[0]; s3=sp2[0];
365 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
366 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
367 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
368 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
369 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
370 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
371 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
372 dp[7] = (dp[7] + ((unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2) + 1)>>1;
373 dp[8] = (dp[8] + ((unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2) + 1)>>1;
374 dp[9] = (dp[9] + ((unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2) + 1)>>1;
375 dp[10] = (dp[10] + ((unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2) + 1)>>1;
376 dp[11] = (dp[11] + ((unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2) + 1)>>1;
377 dp[12] = (dp[12] + ((unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2) + 1)>>1;
378 dp[13] = (dp[13] + ((unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2) + 1)>>1;
379 dp[14] = (dp[14] + ((unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2) + 1)>>1;
380 dp[15] = (dp[15] + ((unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2) + 1)>>1;
381 sp+= lx2;
382 sp2+= lx2;
383 dp+= lx2;
388 static inline void rec4ac(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
390 unsigned char *dp=d, *sp=s, *sp2=s+lx;
391 unsigned int s1,s2,s3,s4;
392 int j;
395 sp = s;
396 sp2 = s+lx;
397 dp = d;
399 for (j=0; j<h; j++)
401 s1=sp[0]; s3=sp2[0];
402 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
403 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
404 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
405 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
406 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
407 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
408 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
409 dp[7] = (dp[7] + ((unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2) + 1)>>1;
410 sp+= lx2;
411 sp2+= lx2;
412 dp+= lx2;
416 static inline
417 void recon_comp(mpeg3video_t *video,
418 unsigned char *src,
419 unsigned char *dst,
420 int lx,
421 int lx2,
422 int w,
423 int h,
424 int x,
425 int y,
426 int dx,
427 int dy,
428 int addflag)
430 int switcher;
431 unsigned char *s, *d;
433 /* half pel scaling */
434 switcher = (dx & 1) << 3 | (dy & 1) << 2 | w;
435 if(addflag) switcher |= 2;
436 /* origins */
437 s = src + lx * (y + (dy >> 1)) + x + (dx >> 1);
438 d = dst + lx * y + x;
440 // Accelerated functions
441 switch(switcher)
443 case 0x3: reca(s, d, lx2, h); break;
444 case 0x2: recac(s, d, lx2, h); break;
445 case 0x1: rec(s, d, lx2, h); break;
446 case 0x0: recc(s, d, lx2, h); break;
447 case 0x7: recva(s, d, lx, lx2, h); break;
448 case 0x6: recvac(s, d, lx, lx2, h); break;
449 case 0x5: recv(s, d, lx, lx2, h); break;
450 case 0x4: recvc(s, d, lx, lx2, h); break;
451 case 0x9: rech(s, d, lx2, h); break;
452 case 0x8: rechc(s, d, lx2, h); break;
455 // Unaccelerated functions
456 switch(switcher)
458 case 0xb: recha(s, d, lx2, h); break;
459 case 0xa: rechac(s, d, lx2, h); break;
460 case 0xf: rec4a(s, d, lx, lx2, h); break;
461 case 0xe: rec4ac(s, d, lx, lx2, h); break;
462 case 0xd: rec4(s, d, lx, lx2, h); break;
463 case 0xc: rec4c(s, d, lx, lx2, h); break;
468 unsigned char *src[]; * prediction source buffer *
469 int sfield; * prediction source field number (0 or 1) *
470 unsigned char *dst[]; * prediction destination buffer *
471 int dfield; * prediction destination field number (0 or 1)*
472 int lx,lx2; * horizontal offsets *
473 int w,h; * prediction block/sub-block width, height *
474 int x,y; * pixel co-ordinates of top-left sample in current MB *
475 int dx,dy; * horizontal, vertical motion vector *
476 int addflag; * add prediction error to prediction ? *
478 static void recon(mpeg3video_t *video,
479 unsigned char *src[],
480 int sfield,
481 unsigned char *dst[],
482 int dfield,
483 int lx,
484 int lx2,
485 int w,
486 int h,
487 int x,
488 int y,
489 int dx,
490 int dy,
491 int addflag)
494 /* Y */
495 recon_comp(video, (src[0] + (sfield ? (lx2 >> 1) : 0)),
496 dst[0] + (dfield ? (lx2 >> 1) : 0),
497 lx, lx2, w, h, x, y, dx, dy, addflag);
499 if(video->chroma_format != CHROMA444)
501 lx >>= 1;
502 dx /= 2;
503 lx2 >>= 1;
504 w = 0;
505 x >>= 1;
508 if(video->chroma_format == CHROMA420)
510 h >>= 1;
511 dy /= 2;
512 y >>= 1;
515 /* Cb */
516 recon_comp(video, (src[1] + (sfield ? (lx2 >> 1) : 0)),
517 dst[1] + (dfield ? (lx2 >> 1) : 0),
518 lx, lx2, w, h, x, y, dx, dy, addflag);
520 /* Cr */
521 recon_comp(video, (src[2] + (sfield ? (lx2 >> 1) : 0)),
522 dst[2] + (dfield ? (lx2 >> 1) : 0),
523 lx, lx2, w, h, x, y, dx, dy, addflag);
526 #define WIDTH 1
528 int mpeg3video_reconstruct(mpeg3video_t *video,
529 int bx,
530 int by,
531 int mb_type,
532 int motion_type,
533 int PMV[2][2][2],
534 int mv_field_sel[2][2],
535 int dmvector[2],
536 int stwtype)
538 int currentfield;
539 unsigned char **predframe;
540 int DMV[2][2];
541 int stwtop, stwbot;
543 stwtop = stwtype % 3; /* 0:temporal, 1 : (spat+temp) / 2, 2 : spatial */
544 stwbot = stwtype / 3;
546 if((mb_type & MB_FORWARD) || (video->pict_type == P_TYPE))
548 if(video->pict_struct == FRAME_PICTURE)
550 if((motion_type == MC_FRAME) || !(mb_type & MB_FORWARD))
552 /* frame-based prediction */
554 if(stwtop < 2)
555 recon(video, video->oldrefframe, 0, video->newframe, 0,
556 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
557 PMV[0][0][0], PMV[0][0][1], stwtop);
559 if(stwbot < 2)
560 recon(video, video->oldrefframe, 1, video->newframe, 1,
561 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
562 PMV[0][0][0], PMV[0][0][1], stwbot);
565 else if(motion_type == MC_FIELD) /* field-based prediction */
567 /* top field prediction */
568 if(stwtop < 2)
569 recon(video, video->oldrefframe, mv_field_sel[0][0], video->newframe, 0,
570 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
571 PMV[0][0][0], PMV[0][0][1] >> 1, stwtop);
573 /* bottom field prediction */
574 if(stwbot < 2)
575 recon(video, video->oldrefframe, mv_field_sel[1][0], video->newframe, 1,
576 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
577 PMV[1][0][0], PMV[1][0][1] >> 1, stwbot);
579 else if(motion_type == MC_DMV)
581 /* dual prime prediction */
582 /* calculate derived motion vectors */
583 mpeg3video_calc_dmv(video,
584 DMV,
585 dmvector,
586 PMV[0][0][0],
587 PMV[0][0][1] >> 1);
589 if(stwtop < 2)
591 /* predict top field from top field */
592 recon(video, video->oldrefframe, 0, video->newframe, 0,
593 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
594 PMV[0][0][0], PMV[0][0][1] >> 1, 0);
596 /* predict and add to top field from bottom field */
597 recon(video, video->oldrefframe, 1, video->newframe, 0,
598 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
599 DMV[0][0], DMV[0][1], 1);
602 if(stwbot < 2)
604 /* predict bottom field from bottom field */
605 recon(video, video->oldrefframe, 1, video->newframe, 1,
606 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
607 PMV[0][0][0], PMV[0][0][1]>>1, 0);
609 /* predict and add to bottom field from top field */
610 recon(video, video->oldrefframe, 0, video->newframe, 1,
611 video->coded_picture_width << 1, video->coded_picture_width<<1, WIDTH, 8, bx, by>>1,
612 DMV[1][0], DMV[1][1], 1);
615 else
616 /* invalid motion_type */
617 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
620 else
622 /* TOP_FIELD or BOTTOM_FIELD */
623 /* field picture */
624 currentfield = (video->pict_struct == BOTTOM_FIELD);
626 /* determine which frame to use for prediction */
627 if((video->pict_type == P_TYPE) && video->secondfield
628 && (currentfield != mv_field_sel[0][0]))
629 predframe = video->refframe; /* same frame */
630 else
631 predframe = video->oldrefframe; /* previous frame */
633 if((motion_type == MC_FIELD) || !(mb_type & MB_FORWARD))
635 /* field-based prediction */
636 if(stwtop < 2)
637 recon(video, predframe,mv_field_sel[0][0],video->newframe,0,
638 video->coded_picture_width << 1,video->coded_picture_width << 1,WIDTH,16,bx,by,
639 PMV[0][0][0],PMV[0][0][1],stwtop);
641 else
642 if(motion_type == MC_16X8)
644 if(stwtop < 2)
646 recon(video, predframe, mv_field_sel[0][0], video->newframe, 0,
647 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
648 PMV[0][0][0], PMV[0][0][1], stwtop);
650 /* determine which frame to use for lower half prediction */
651 if((video->pict_type==P_TYPE) && video->secondfield
652 && (currentfield!=mv_field_sel[1][0]))
653 predframe = video->refframe; /* same frame */
654 else
655 predframe = video->oldrefframe; /* previous frame */
657 recon(video, predframe, mv_field_sel[1][0], video->newframe, 0,
658 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
659 PMV[1][0][0], PMV[1][0][1], stwtop);
662 else
663 if(motion_type == MC_DMV) /* dual prime prediction */
665 if(video->secondfield)
666 predframe = video->refframe; /* same frame */
667 else
668 predframe = video->oldrefframe; /* previous frame */
670 /* calculate derived motion vectors */
671 mpeg3video_calc_dmv(video,
672 DMV,
673 dmvector,
674 PMV[0][0][0],
675 PMV[0][0][1]);
677 /* predict from field of same parity */
678 recon(video, video->oldrefframe, currentfield, video->newframe, 0,
679 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
680 PMV[0][0][0], PMV[0][0][1], 0);
682 /* predict from field of opposite parity */
683 recon(video, predframe, !currentfield, video->newframe, 0,
684 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
685 DMV[0][0], DMV[0][1], 1);
687 else
688 /* invalid motion_type */
689 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
692 stwtop = stwbot = 1;
695 if(mb_type & MB_BACKWARD)
697 if(video->pict_struct == FRAME_PICTURE)
699 if(motion_type == MC_FRAME)
701 /* frame-based prediction */
702 if(stwtop < 2)
703 recon(video, video->refframe, 0, video->newframe, 0,
704 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
705 PMV[0][1][0], PMV[0][1][1], stwtop);
707 if(stwbot < 2)
708 recon(video, video->refframe, 1, video->newframe, 1,
709 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
710 PMV[0][1][0], PMV[0][1][1], stwbot);
712 else
714 /* field-based prediction */
715 /* top field prediction */
716 if(stwtop < 2)
718 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
719 (video->coded_picture_width << 1), (video->coded_picture_width<<1), WIDTH, 8, bx, (by >> 1),
720 PMV[0][1][0], (PMV[0][1][1] >> 1), stwtop);
723 /* bottom field prediction */
724 if(stwbot < 2)
726 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 1, (video->coded_picture_width << 1),
727 (video->coded_picture_width << 1), WIDTH, 8, bx, (by>>1),
728 PMV[1][1][0], (PMV[1][1][1]>>1), stwbot);
732 else
734 /* TOP_FIELD or BOTTOM_FIELD */
735 /* field picture */
736 if(motion_type == MC_FIELD)
738 /* field-based prediction */
739 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
740 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
741 PMV[0][1][0], PMV[0][1][1], stwtop);
743 else if(motion_type==MC_16X8)
745 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
746 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
747 PMV[0][1][0], PMV[0][1][1], stwtop);
749 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 0,
750 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
751 PMV[1][1][0], PMV[1][1][1], stwtop);
753 else
754 /* invalid motion_type */
755 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
758 } /* mb_type & MB_BACKWARD */
759 return 0;