Mercurial > libavcodec.hg
annotate motion_est.c @ 1051:e5a9dbf597d4 libavcodec
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
author | michaelni |
---|---|
date | Sat, 08 Feb 2003 12:00:57 +0000 |
parents | 8d686fbb6a8c |
children | f07fd48c23d4 |
rev | line source |
---|---|
0 | 1 /* |
2 * Motion estimation | |
429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
1011 | 4 * Copyright (c) 2002-2003 Michael Niedermayer |
0 | 5 * |
6 * | |
429 | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2 of the License, or (at your option) any later version. | |
0 | 11 * |
429 | 12 * This library is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | |
0 | 16 * |
429 | 17 * You should have received a copy of the GNU Lesser General Public |
18 * License along with this library; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
20 * |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
21 * new Motion Estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at> |
0 | 22 */ |
23 #include <stdlib.h> | |
24 #include <stdio.h> | |
25 #include "avcodec.h" | |
26 #include "dsputil.h" | |
27 #include "mpegvideo.h" | |
28 | |
936 | 29 //#undef NDEBUG |
30 //#include <assert.h> | |
31 | |
455 | 32 #define SQ(a) ((a)*(a)) |
284 | 33 |
455 | 34 #define P_LEFT P[1] |
35 #define P_TOP P[2] | |
36 #define P_TOPRIGHT P[3] | |
37 #define P_MEDIAN P[4] | |
38 #define P_MV1 P[9] | |
39 | |
936 | 40 static inline int sad_hpel_motion_search(MpegEncContext * s, |
41 int *mx_ptr, int *my_ptr, int dmin, | |
42 int xmin, int ymin, int xmax, int ymax, | |
43 int pred_x, int pred_y, Picture *picture, | |
44 int n, int size, uint16_t * const mv_penalty); | |
0 | 45 |
936 | 46 static inline int update_map_generation(MpegEncContext * s) |
47 { | |
48 s->me.map_generation+= 1<<(ME_MAP_MV_BITS*2); | |
49 if(s->me.map_generation==0){ | |
50 s->me.map_generation= 1<<(ME_MAP_MV_BITS*2); | |
51 memset(s->me.map, 0, sizeof(uint32_t)*ME_MAP_SIZE); | |
52 } | |
53 return s->me.map_generation; | |
54 } | |
55 | |
948 | 56 /* shape adaptive search stuff */ |
57 typedef struct Minima{ | |
58 int height; | |
59 int x, y; | |
60 int checked; | |
61 }Minima; | |
936 | 62 |
948 | 63 static int minima_cmp(const void *a, const void *b){ |
64 Minima *da = (Minima *) a; | |
65 Minima *db = (Minima *) b; | |
66 | |
67 return da->height - db->height; | |
68 } | |
936 | 69 |
70 /* SIMPLE */ | |
71 #define RENAME(a) simple_ ## a | |
72 | |
73 #define CMP(d, x, y, size)\ | |
74 d = cmp(s, src_y, (ref_y) + (x) + (y)*(stride), stride); | |
75 | |
76 #define CMP_HPEL(d, dx, dy, x, y, size)\ | |
77 {\ | |
78 const int dxy= (dx) + 2*(dy);\ | |
79 hpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride, (16>>size));\ | |
80 d = cmp_sub(s, s->me.scratchpad, src_y, stride);\ | |
81 } | |
82 | |
83 #define CMP_QPEL(d, dx, dy, x, y, size)\ | |
84 {\ | |
85 const int dxy= (dx) + 4*(dy);\ | |
86 qpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride);\ | |
87 d = cmp_sub(s, s->me.scratchpad, src_y, stride);\ | |
88 } | |
89 | |
90 #include "motion_est_template.c" | |
91 #undef RENAME | |
92 #undef CMP | |
93 #undef CMP_HPEL | |
94 #undef CMP_QPEL | |
95 #undef INIT | |
96 | |
97 /* SIMPLE CHROMA */ | |
98 #define RENAME(a) simple_chroma_ ## a | |
99 | |
100 #define CMP(d, x, y, size)\ | |
101 d = cmp(s, src_y, (ref_y) + (x) + (y)*(stride), stride);\ | |
102 if(chroma_cmp){\ | |
103 int dxy= ((x)&1) + 2*((y)&1);\ | |
104 int c= ((x)>>1) + ((y)>>1)*uvstride;\ | |
105 \ | |
106 chroma_hpel_put[0][dxy](s->me.scratchpad, ref_u + c, uvstride, 8);\ | |
107 d += chroma_cmp(s, s->me.scratchpad, src_u, uvstride);\ | |
108 chroma_hpel_put[0][dxy](s->me.scratchpad, ref_v + c, uvstride, 8);\ | |
109 d += chroma_cmp(s, s->me.scratchpad, src_v, uvstride);\ | |
110 } | |
111 | |
112 #define CMP_HPEL(d, dx, dy, x, y, size)\ | |
113 {\ | |
114 const int dxy= (dx) + 2*(dy);\ | |
115 hpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride, (16>>size));\ | |
116 d = cmp_sub(s, s->me.scratchpad, src_y, stride);\ | |
117 if(chroma_cmp_sub){\ | |
118 int cxy= (dxy) | ((x)&1) | (2*((y)&1));\ | |
119 int c= ((x)>>1) + ((y)>>1)*uvstride;\ | |
120 chroma_hpel_put[0][cxy](s->me.scratchpad, ref_u + c, uvstride, 8);\ | |
121 d += chroma_cmp_sub(s, s->me.scratchpad, src_u, uvstride);\ | |
122 chroma_hpel_put[0][cxy](s->me.scratchpad, ref_v + c, uvstride, 8);\ | |
123 d += chroma_cmp_sub(s, s->me.scratchpad, src_v, uvstride);\ | |
124 }\ | |
125 } | |
126 | |
127 #define CMP_QPEL(d, dx, dy, x, y, size)\ | |
128 {\ | |
129 const int dxy= (dx) + 4*(dy);\ | |
130 qpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride);\ | |
131 d = cmp_sub(s, s->me.scratchpad, src_y, stride);\ | |
132 if(chroma_cmp_sub){\ | |
133 int cxy, c;\ | |
134 int cx= (4*(x) + (dx))/2;\ | |
135 int cy= (4*(y) + (dy))/2;\ | |
136 cx= (cx>>1)|(cx&1);\ | |
137 cy= (cy>>1)|(cy&1);\ | |
138 cxy= (cx&1) + 2*(cy&1);\ | |
139 c= ((cx)>>1) + ((cy)>>1)*uvstride;\ | |
140 chroma_hpel_put[0][cxy](s->me.scratchpad, ref_u + c, uvstride, 8);\ | |
141 d += chroma_cmp_sub(s, s->me.scratchpad, src_u, uvstride);\ | |
142 chroma_hpel_put[0][cxy](s->me.scratchpad, ref_v + c, uvstride, 8);\ | |
143 d += chroma_cmp_sub(s, s->me.scratchpad, src_v, uvstride);\ | |
144 }\ | |
145 } | |
146 | |
147 #include "motion_est_template.c" | |
148 #undef RENAME | |
149 #undef CMP | |
150 #undef CMP_HPEL | |
151 #undef CMP_QPEL | |
152 #undef INIT | |
153 | |
154 /* SIMPLE DIRECT HPEL */ | |
155 #define RENAME(a) simple_direct_hpel_ ## a | |
156 //FIXME precalc divisions stuff | |
157 | |
158 #define CMP_DIRECT(d, dx, dy, x, y, size, cmp_func)\ | |
159 if((x) >= xmin && 2*(x) + (dx) <= 2*xmax && (y) >= ymin && 2*(y) + (dy) <= 2*ymax){\ | |
160 const int hx= 2*(x) + (dx);\ | |
161 const int hy= 2*(y) + (dy);\ | |
162 if(s->mv_type==MV_TYPE_8X8){\ | |
163 int i;\ | |
164 for(i=0; i<4; i++){\ | |
165 int fx = s->me.direct_basis_mv[i][0] + hx;\ | |
166 int fy = s->me.direct_basis_mv[i][1] + hy;\ | |
167 int bx = hx ? fx - s->me.co_located_mv[i][0] : s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + (i &1)*16;\ | |
168 int by = hy ? fy - s->me.co_located_mv[i][1] : s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + (i>>1)*16;\ | |
169 int fxy= (fx&1) + 2*(fy&1);\ | |
170 int bxy= (bx&1) + 2*(by&1);\ | |
171 \ | |
172 uint8_t *dst= s->me.scratchpad + 8*(i&1) + 8*stride*(i>>1);\ | |
173 hpel_put[1][fxy](dst, (ref_y ) + (fx>>1) + (fy>>1)*(stride), stride, 8);\ | |
174 hpel_avg[1][bxy](dst, (ref2_y) + (bx>>1) + (by>>1)*(stride), stride, 8);\ | |
175 }\ | |
176 }else{\ | |
177 int fx = s->me.direct_basis_mv[0][0] + hx;\ | |
178 int fy = s->me.direct_basis_mv[0][1] + hy;\ | |
1050 | 179 int bx = hx ? fx - s->me.co_located_mv[0][0] : (s->me.co_located_mv[0][0]*(time_pb - time_pp)/time_pp);\ |
180 int by = hy ? fy - s->me.co_located_mv[0][1] : (s->me.co_located_mv[0][1]*(time_pb - time_pp)/time_pp);\ | |
936 | 181 int fxy= (fx&1) + 2*(fy&1);\ |
182 int bxy= (bx&1) + 2*(by&1);\ | |
1050 | 183 \ |
184 assert((fx>>1) + 16*s->mb_x >= -16);\ | |
185 assert((fy>>1) + 16*s->mb_y >= -16);\ | |
186 assert((fx>>1) + 16*s->mb_x <= s->width);\ | |
187 assert((fy>>1) + 16*s->mb_y <= s->height);\ | |
188 assert((bx>>1) + 16*s->mb_x >= -16);\ | |
189 assert((by>>1) + 16*s->mb_y >= -16);\ | |
190 assert((bx>>1) + 16*s->mb_x <= s->width);\ | |
191 assert((by>>1) + 16*s->mb_y <= s->height);\ | |
936 | 192 \ |
193 hpel_put[0][fxy](s->me.scratchpad, (ref_y ) + (fx>>1) + (fy>>1)*(stride), stride, 16);\ | |
194 hpel_avg[0][bxy](s->me.scratchpad, (ref2_y) + (bx>>1) + (by>>1)*(stride), stride, 16);\ | |
195 }\ | |
196 d = cmp_func(s, s->me.scratchpad, src_y, stride);\ | |
197 }else\ | |
198 d= 256*256*256*32; | |
199 | |
200 | |
201 #define CMP_HPEL(d, dx, dy, x, y, size)\ | |
202 CMP_DIRECT(d, dx, dy, x, y, size, cmp_sub) | |
203 | |
204 #define CMP(d, x, y, size)\ | |
205 CMP_DIRECT(d, 0, 0, x, y, size, cmp) | |
206 | |
207 #include "motion_est_template.c" | |
208 #undef RENAME | |
209 #undef CMP | |
210 #undef CMP_HPEL | |
211 #undef CMP_QPEL | |
212 #undef INIT | |
213 #undef CMP_DIRECT | |
214 | |
215 /* SIMPLE DIRECT QPEL */ | |
216 #define RENAME(a) simple_direct_qpel_ ## a | |
217 | |
218 #define CMP_DIRECT(d, dx, dy, x, y, size, cmp_func)\ | |
219 if((x) >= xmin && 4*(x) + (dx) <= 4*xmax && (y) >= ymin && 4*(y) + (dy) <= 4*ymax){\ | |
220 const int qx= 4*(x) + (dx);\ | |
221 const int qy= 4*(y) + (dy);\ | |
222 if(s->mv_type==MV_TYPE_8X8){\ | |
223 int i;\ | |
224 for(i=0; i<4; i++){\ | |
225 int fx = s->me.direct_basis_mv[i][0] + qx;\ | |
226 int fy = s->me.direct_basis_mv[i][1] + qy;\ | |
227 int bx = qx ? fx - s->me.co_located_mv[i][0] : s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + (i &1)*16;\ | |
228 int by = qy ? fy - s->me.co_located_mv[i][1] : s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + (i>>1)*16;\ | |
229 int fxy= (fx&3) + 4*(fy&3);\ | |
230 int bxy= (bx&3) + 4*(by&3);\ | |
231 \ | |
232 uint8_t *dst= s->me.scratchpad + 8*(i&1) + 8*stride*(i>>1);\ | |
233 qpel_put[1][fxy](dst, (ref_y ) + (fx>>2) + (fy>>2)*(stride), stride);\ | |
234 qpel_avg[1][bxy](dst, (ref2_y) + (bx>>2) + (by>>2)*(stride), stride);\ | |
235 }\ | |
236 }else{\ | |
237 int fx = s->me.direct_basis_mv[0][0] + qx;\ | |
238 int fy = s->me.direct_basis_mv[0][1] + qy;\ | |
239 int bx = qx ? fx - s->me.co_located_mv[0][0] : s->me.co_located_mv[0][0]*(time_pb - time_pp)/time_pp;\ | |
240 int by = qy ? fy - s->me.co_located_mv[0][1] : s->me.co_located_mv[0][1]*(time_pb - time_pp)/time_pp;\ | |
241 int fxy= (fx&3) + 4*(fy&3);\ | |
242 int bxy= (bx&3) + 4*(by&3);\ | |
243 \ | |
244 qpel_put[0][fxy](s->me.scratchpad, (ref_y ) + (fx>>2) + (fy>>2)*(stride), stride);\ | |
245 qpel_avg[0][bxy](s->me.scratchpad, (ref2_y) + (bx>>2) + (by>>2)*(stride), stride);\ | |
246 }\ | |
247 d = cmp_func(s, s->me.scratchpad, src_y, stride);\ | |
248 }else\ | |
249 d= 256*256*256*32; | |
250 | |
251 | |
252 #define CMP_QPEL(d, dx, dy, x, y, size)\ | |
253 CMP_DIRECT(d, dx, dy, x, y, size, cmp_sub) | |
254 | |
255 #define CMP(d, x, y, size)\ | |
256 CMP_DIRECT(d, 0, 0, x, y, size, cmp) | |
257 | |
258 #include "motion_est_template.c" | |
259 #undef RENAME | |
260 #undef CMP | |
261 #undef CMP_HPEL | |
262 #undef CMP_QPEL | |
263 #undef INIT | |
264 #undef CMP__DIRECT | |
265 | |
266 | |
267 static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride){ | |
268 return 0; | |
269 } | |
270 | |
271 static void set_cmp(MpegEncContext *s, me_cmp_func *cmp, int type){ | |
272 DSPContext* c= &s->dsp; | |
273 int i; | |
274 | |
275 memset(cmp, 0, sizeof(void*)*11); | |
276 | |
277 switch(type&0xFF){ | |
278 case FF_CMP_SAD: | |
279 cmp[0]= c->sad[0]; | |
280 cmp[1]= c->sad[1]; | |
281 break; | |
282 case FF_CMP_SATD: | |
283 cmp[0]= c->hadamard8_diff[0]; | |
284 cmp[1]= c->hadamard8_diff[1]; | |
285 break; | |
286 case FF_CMP_SSE: | |
287 cmp[0]= c->sse[0]; | |
288 cmp[1]= c->sse[1]; | |
289 break; | |
290 case FF_CMP_DCT: | |
291 cmp[0]= c->dct_sad[0]; | |
292 cmp[1]= c->dct_sad[1]; | |
293 break; | |
294 case FF_CMP_PSNR: | |
295 cmp[0]= c->quant_psnr[0]; | |
296 cmp[1]= c->quant_psnr[1]; | |
297 break; | |
1007 | 298 case FF_CMP_BIT: |
299 cmp[0]= c->bit[0]; | |
300 cmp[1]= c->bit[1]; | |
301 break; | |
302 case FF_CMP_RD: | |
303 cmp[0]= c->rd[0]; | |
304 cmp[1]= c->rd[1]; | |
305 break; | |
936 | 306 case FF_CMP_ZERO: |
307 for(i=0; i<7; i++){ | |
308 cmp[i]= zero_cmp; | |
309 } | |
310 break; | |
311 default: | |
312 fprintf(stderr,"internal error in cmp function selection\n"); | |
313 } | |
1014
48349e11c9b2
C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (M¸«©ns Rullg¸«©rd))
michaelni
parents:
1013
diff
changeset
|
314 } |
936 | 315 |
316 static inline int get_penalty_factor(MpegEncContext *s, int type){ | |
1013 | 317 switch(type&0xFF){ |
936 | 318 default: |
319 case FF_CMP_SAD: | |
1013 | 320 return s->qscale*2; |
936 | 321 case FF_CMP_DCT: |
1013 | 322 return s->qscale*3; |
936 | 323 case FF_CMP_SATD: |
1013 | 324 return s->qscale*6; |
1007 | 325 case FF_CMP_SSE: |
1013 | 326 return s->qscale*s->qscale*2; |
1007 | 327 case FF_CMP_BIT: |
328 return 1; | |
329 case FF_CMP_RD: | |
1013 | 330 case FF_CMP_PSNR: |
331 return (s->qscale*s->qscale*185 + 64)>>7; | |
936 | 332 } |
333 } | |
334 | |
335 void ff_init_me(MpegEncContext *s){ | |
954 | 336 set_cmp(s, s->dsp.me_pre_cmp, s->avctx->me_pre_cmp); |
936 | 337 set_cmp(s, s->dsp.me_cmp, s->avctx->me_cmp); |
338 set_cmp(s, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp); | |
339 set_cmp(s, s->dsp.mb_cmp, s->avctx->mb_cmp); | |
340 | |
341 if(s->flags&CODEC_FLAG_QPEL){ | |
342 if(s->avctx->me_sub_cmp&FF_CMP_CHROMA) | |
343 s->me.sub_motion_search= simple_chroma_qpel_motion_search; | |
344 else | |
345 s->me.sub_motion_search= simple_qpel_motion_search; | |
346 }else{ | |
347 if(s->avctx->me_sub_cmp&FF_CMP_CHROMA) | |
348 s->me.sub_motion_search= simple_chroma_hpel_motion_search; | |
1013 | 349 else if( s->avctx->me_sub_cmp == FF_CMP_SAD |
350 && s->avctx-> me_cmp == FF_CMP_SAD | |
351 && s->avctx-> mb_cmp == FF_CMP_SAD) | |
936 | 352 s->me.sub_motion_search= sad_hpel_motion_search; |
353 else | |
354 s->me.sub_motion_search= simple_hpel_motion_search; | |
355 } | |
356 | |
357 if(s->avctx->me_cmp&FF_CMP_CHROMA){ | |
358 s->me.motion_search[0]= simple_chroma_epzs_motion_search; | |
359 s->me.motion_search[1]= simple_chroma_epzs_motion_search4; | |
360 }else{ | |
361 s->me.motion_search[0]= simple_epzs_motion_search; | |
362 s->me.motion_search[1]= simple_epzs_motion_search4; | |
363 } | |
954 | 364 |
365 if(s->avctx->me_pre_cmp&FF_CMP_CHROMA){ | |
366 s->me.pre_motion_search= simple_chroma_epzs_motion_search; | |
367 }else{ | |
368 s->me.pre_motion_search= simple_epzs_motion_search; | |
369 } | |
1013 | 370 |
371 if(s->flags&CODEC_FLAG_QPEL){ | |
372 if(s->avctx->mb_cmp&FF_CMP_CHROMA) | |
373 s->me.get_mb_score= simple_chroma_qpel_get_mb_score; | |
374 else | |
375 s->me.get_mb_score= simple_qpel_get_mb_score; | |
376 }else{ | |
377 if(s->avctx->mb_cmp&FF_CMP_CHROMA) | |
378 s->me.get_mb_score= simple_chroma_hpel_get_mb_score; | |
379 else | |
380 s->me.get_mb_score= simple_hpel_get_mb_score; | |
381 } | |
936 | 382 } |
383 | |
284 | 384 static int pix_dev(UINT8 * pix, int line_size, int mean) |
385 { | |
386 int s, i, j; | |
387 | |
388 s = 0; | |
389 for (i = 0; i < 16; i++) { | |
390 for (j = 0; j < 16; j += 8) { | |
391 s += ABS(pix[0]-mean); | |
392 s += ABS(pix[1]-mean); | |
393 s += ABS(pix[2]-mean); | |
394 s += ABS(pix[3]-mean); | |
395 s += ABS(pix[4]-mean); | |
396 s += ABS(pix[5]-mean); | |
397 s += ABS(pix[6]-mean); | |
398 s += ABS(pix[7]-mean); | |
399 pix += 8; | |
400 } | |
401 pix += line_size - 16; | |
402 } | |
403 return s; | |
404 } | |
405 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
406 static inline void no_motion_search(MpegEncContext * s, |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
407 int *mx_ptr, int *my_ptr) |
0 | 408 { |
409 *mx_ptr = 16 * s->mb_x; | |
410 *my_ptr = 16 * s->mb_y; | |
411 } | |
412 | |
413 static int full_motion_search(MpegEncContext * s, | |
414 int *mx_ptr, int *my_ptr, int range, | |
324 | 415 int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) |
0 | 416 { |
417 int x1, y1, x2, y2, xx, yy, x, y; | |
418 int mx, my, dmin, d; | |
419 UINT8 *pix; | |
420 | |
421 xx = 16 * s->mb_x; | |
422 yy = 16 * s->mb_y; | |
423 x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */ | |
424 if (x1 < xmin) | |
425 x1 = xmin; | |
426 x2 = xx + range - 1; | |
427 if (x2 > xmax) | |
428 x2 = xmax; | |
429 y1 = yy - range + 1; | |
430 if (y1 < ymin) | |
431 y1 = ymin; | |
432 y2 = yy + range - 1; | |
433 if (y2 > ymax) | |
434 y2 = ymax; | |
903 | 435 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
0 | 436 dmin = 0x7fffffff; |
437 mx = 0; | |
438 my = 0; | |
439 for (y = y1; y <= y2; y++) { | |
440 for (x = x1; x <= x2; x++) { | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
441 d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x, |
294 | 442 s->linesize); |
0 | 443 if (d < dmin || |
444 (d == dmin && | |
445 (abs(x - xx) + abs(y - yy)) < | |
446 (abs(mx - xx) + abs(my - yy)))) { | |
447 dmin = d; | |
448 mx = x; | |
449 my = y; | |
450 } | |
451 } | |
452 } | |
453 | |
454 *mx_ptr = mx; | |
455 *my_ptr = my; | |
456 | |
457 #if 0 | |
458 if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) || | |
459 *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) { | |
460 fprintf(stderr, "error %d %d\n", *mx_ptr, *my_ptr); | |
461 } | |
462 #endif | |
463 return dmin; | |
464 } | |
465 | |
466 | |
467 static int log_motion_search(MpegEncContext * s, | |
468 int *mx_ptr, int *my_ptr, int range, | |
324 | 469 int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) |
0 | 470 { |
471 int x1, y1, x2, y2, xx, yy, x, y; | |
472 int mx, my, dmin, d; | |
473 UINT8 *pix; | |
474 | |
475 xx = s->mb_x << 4; | |
476 yy = s->mb_y << 4; | |
477 | |
478 /* Left limit */ | |
479 x1 = xx - range; | |
480 if (x1 < xmin) | |
481 x1 = xmin; | |
482 | |
483 /* Right limit */ | |
484 x2 = xx + range; | |
485 if (x2 > xmax) | |
486 x2 = xmax; | |
487 | |
488 /* Upper limit */ | |
489 y1 = yy - range; | |
490 if (y1 < ymin) | |
491 y1 = ymin; | |
492 | |
493 /* Lower limit */ | |
494 y2 = yy + range; | |
495 if (y2 > ymax) | |
496 y2 = ymax; | |
497 | |
903 | 498 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
0 | 499 dmin = 0x7fffffff; |
500 mx = 0; | |
501 my = 0; | |
502 | |
503 do { | |
504 for (y = y1; y <= y2; y += range) { | |
505 for (x = x1; x <= x2; x += range) { | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
506 d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x, s->linesize); |
0 | 507 if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { |
508 dmin = d; | |
509 mx = x; | |
510 my = y; | |
511 } | |
512 } | |
513 } | |
514 | |
515 range = range >> 1; | |
516 | |
517 x1 = mx - range; | |
518 if (x1 < xmin) | |
519 x1 = xmin; | |
520 | |
521 x2 = mx + range; | |
522 if (x2 > xmax) | |
523 x2 = xmax; | |
524 | |
525 y1 = my - range; | |
526 if (y1 < ymin) | |
527 y1 = ymin; | |
528 | |
529 y2 = my + range; | |
530 if (y2 > ymax) | |
531 y2 = ymax; | |
532 | |
533 } while (range >= 1); | |
534 | |
535 #ifdef DEBUG | |
536 fprintf(stderr, "log - MX: %d\tMY: %d\n", mx, my); | |
537 #endif | |
538 *mx_ptr = mx; | |
539 *my_ptr = my; | |
540 return dmin; | |
541 } | |
542 | |
543 static int phods_motion_search(MpegEncContext * s, | |
544 int *mx_ptr, int *my_ptr, int range, | |
324 | 545 int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) |
0 | 546 { |
547 int x1, y1, x2, y2, xx, yy, x, y, lastx, d; | |
548 int mx, my, dminx, dminy; | |
549 UINT8 *pix; | |
550 | |
551 xx = s->mb_x << 4; | |
552 yy = s->mb_y << 4; | |
553 | |
554 /* Left limit */ | |
555 x1 = xx - range; | |
556 if (x1 < xmin) | |
557 x1 = xmin; | |
558 | |
559 /* Right limit */ | |
560 x2 = xx + range; | |
561 if (x2 > xmax) | |
562 x2 = xmax; | |
563 | |
564 /* Upper limit */ | |
565 y1 = yy - range; | |
566 if (y1 < ymin) | |
567 y1 = ymin; | |
568 | |
569 /* Lower limit */ | |
570 y2 = yy + range; | |
571 if (y2 > ymax) | |
572 y2 = ymax; | |
573 | |
903 | 574 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
0 | 575 mx = 0; |
576 my = 0; | |
577 | |
578 x = xx; | |
579 y = yy; | |
580 do { | |
581 dminx = 0x7fffffff; | |
582 dminy = 0x7fffffff; | |
583 | |
584 lastx = x; | |
585 for (x = x1; x <= x2; x += range) { | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
586 d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x, s->linesize); |
0 | 587 if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { |
588 dminx = d; | |
589 mx = x; | |
590 } | |
591 } | |
592 | |
593 x = lastx; | |
594 for (y = y1; y <= y2; y += range) { | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
595 d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x, s->linesize); |
0 | 596 if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { |
597 dminy = d; | |
598 my = y; | |
599 } | |
600 } | |
601 | |
602 range = range >> 1; | |
603 | |
604 x = mx; | |
605 y = my; | |
606 x1 = mx - range; | |
607 if (x1 < xmin) | |
608 x1 = xmin; | |
609 | |
610 x2 = mx + range; | |
611 if (x2 > xmax) | |
612 x2 = xmax; | |
613 | |
614 y1 = my - range; | |
615 if (y1 < ymin) | |
616 y1 = ymin; | |
617 | |
618 y2 = my + range; | |
619 if (y2 > ymax) | |
620 y2 = ymax; | |
621 | |
622 } while (range >= 1); | |
623 | |
624 #ifdef DEBUG | |
625 fprintf(stderr, "phods - MX: %d\tMY: %d\n", mx, my); | |
626 #endif | |
627 | |
628 /* half pixel search */ | |
629 *mx_ptr = mx; | |
630 *my_ptr = my; | |
631 return dminy; | |
632 } | |
633 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
634 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
635 #define Z_THRESHOLD 256 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
636 |
936 | 637 #define CHECK_SAD_HALF_MV(suffix, x, y) \ |
455 | 638 {\ |
639 d= pix_abs_ ## suffix(pix, ptr+((x)>>1), s->linesize);\ | |
936 | 640 d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\ |
455 | 641 COPY3_IF_LT(dminh, d, dx, x, dy, y)\ |
642 } | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
643 |
936 | 644 static inline int sad_hpel_motion_search(MpegEncContext * s, |
0 | 645 int *mx_ptr, int *my_ptr, int dmin, |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
646 int xmin, int ymin, int xmax, int ymax, |
936 | 647 int pred_x, int pred_y, Picture *picture, |
648 int n, int size, uint16_t * const mv_penalty) | |
0 | 649 { |
936 | 650 uint8_t *ref_picture= picture->data[0]; |
651 uint32_t *score_map= s->me.score_map; | |
652 const int penalty_factor= s->me.sub_penalty_factor; | |
455 | 653 int mx, my, xx, yy, dminh; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
654 UINT8 *pix, *ptr; |
936 | 655 op_pixels_abs_func pix_abs_x2; |
656 op_pixels_abs_func pix_abs_y2; | |
657 op_pixels_abs_func pix_abs_xy2; | |
658 | |
659 if(size==0){ | |
660 pix_abs_x2 = s->dsp.pix_abs16x16_x2; | |
661 pix_abs_y2 = s->dsp.pix_abs16x16_y2; | |
662 pix_abs_xy2= s->dsp.pix_abs16x16_xy2; | |
663 }else{ | |
664 pix_abs_x2 = s->dsp.pix_abs8x8_x2; | |
665 pix_abs_y2 = s->dsp.pix_abs8x8_y2; | |
666 pix_abs_xy2= s->dsp.pix_abs8x8_xy2; | |
863 | 667 } |
455 | 668 |
936 | 669 if(s->me.skip){ |
455 | 670 // printf("S"); |
671 *mx_ptr = 0; | |
672 *my_ptr = 0; | |
673 return dmin; | |
674 } | |
675 // printf("N"); | |
676 | |
677 xx = 16 * s->mb_x + 8*(n&1); | |
678 yy = 16 * s->mb_y + 8*(n>>1); | |
903 | 679 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
455 | 680 |
294 | 681 mx = *mx_ptr; |
682 my = *my_ptr; | |
455 | 683 ptr = ref_picture + ((yy + my) * s->linesize) + (xx + mx); |
684 | |
294 | 685 dminh = dmin; |
686 | |
687 if (mx > xmin && mx < xmax && | |
688 my > ymin && my < ymax) { | |
455 | 689 int dx=0, dy=0; |
690 int d, pen_x, pen_y; | |
691 const int index= (my<<ME_MAP_SHIFT) + mx; | |
692 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]; | |
693 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]; | |
694 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]; | |
695 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]; | |
696 mx<<=1; | |
697 my<<=1; | |
294 | 698 |
699 | |
700 pen_x= pred_x + mx; | |
701 pen_y= pred_y + my; | |
702 | |
703 ptr-= s->linesize; | |
455 | 704 if(t<=b){ |
936 | 705 CHECK_SAD_HALF_MV(y2 , 0, -1) |
455 | 706 if(l<=r){ |
936 | 707 CHECK_SAD_HALF_MV(xy2, -1, -1) |
455 | 708 if(t+r<=b+l){ |
936 | 709 CHECK_SAD_HALF_MV(xy2, +1, -1) |
455 | 710 ptr+= s->linesize; |
711 }else{ | |
712 ptr+= s->linesize; | |
936 | 713 CHECK_SAD_HALF_MV(xy2, -1, +1) |
455 | 714 } |
936 | 715 CHECK_SAD_HALF_MV(x2 , -1, 0) |
455 | 716 }else{ |
936 | 717 CHECK_SAD_HALF_MV(xy2, +1, -1) |
455 | 718 if(t+l<=b+r){ |
936 | 719 CHECK_SAD_HALF_MV(xy2, -1, -1) |
455 | 720 ptr+= s->linesize; |
721 }else{ | |
722 ptr+= s->linesize; | |
936 | 723 CHECK_SAD_HALF_MV(xy2, +1, +1) |
455 | 724 } |
936 | 725 CHECK_SAD_HALF_MV(x2 , +1, 0) |
455 | 726 } |
727 }else{ | |
728 if(l<=r){ | |
729 if(t+l<=b+r){ | |
936 | 730 CHECK_SAD_HALF_MV(xy2, -1, -1) |
455 | 731 ptr+= s->linesize; |
732 }else{ | |
733 ptr+= s->linesize; | |
936 | 734 CHECK_SAD_HALF_MV(xy2, +1, +1) |
455 | 735 } |
936 | 736 CHECK_SAD_HALF_MV(x2 , -1, 0) |
737 CHECK_SAD_HALF_MV(xy2, -1, +1) | |
455 | 738 }else{ |
739 if(t+r<=b+l){ | |
936 | 740 CHECK_SAD_HALF_MV(xy2, +1, -1) |
455 | 741 ptr+= s->linesize; |
742 }else{ | |
743 ptr+= s->linesize; | |
936 | 744 CHECK_SAD_HALF_MV(xy2, -1, +1) |
455 | 745 } |
936 | 746 CHECK_SAD_HALF_MV(x2 , +1, 0) |
747 CHECK_SAD_HALF_MV(xy2, +1, +1) | |
455 | 748 } |
936 | 749 CHECK_SAD_HALF_MV(y2 , 0, +1) |
455 | 750 } |
751 mx+=dx; | |
752 my+=dy; | |
294 | 753 |
754 }else{ | |
455 | 755 mx<<=1; |
756 my<<=1; | |
294 | 757 } |
758 | |
759 *mx_ptr = mx; | |
760 *my_ptr = my; | |
455 | 761 return dminh; |
294 | 762 } |
763 | |
455 | 764 static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4) |
294 | 765 { |
324 | 766 const int xy= s->mb_x + 1 + (s->mb_y + 1)*(s->mb_width + 2); |
294 | 767 |
324 | 768 s->p_mv_table[xy][0] = mx; |
769 s->p_mv_table[xy][1] = my; | |
294 | 770 |
771 /* has allready been set to the 4 MV if 4MV is done */ | |
455 | 772 if(mv4){ |
294 | 773 int mot_xy= s->block_index[0]; |
774 | |
775 s->motion_val[mot_xy ][0]= mx; | |
776 s->motion_val[mot_xy ][1]= my; | |
777 s->motion_val[mot_xy+1][0]= mx; | |
778 s->motion_val[mot_xy+1][1]= my; | |
779 | |
780 mot_xy += s->block_wrap[0]; | |
781 s->motion_val[mot_xy ][0]= mx; | |
782 s->motion_val[mot_xy ][1]= my; | |
783 s->motion_val[mot_xy+1][0]= mx; | |
784 s->motion_val[mot_xy+1][1]= my; | |
785 } | |
786 } | |
787 | |
324 | 788 static inline void get_limits(MpegEncContext *s, int *range, int *xmin, int *ymin, int *xmax, int *ymax, int f_code) |
789 { | |
790 *range = 8 * (1 << (f_code - 1)); | |
791 /* XXX: temporary kludge to avoid overflow for msmpeg4 */ | |
792 if (s->out_format == FMT_H263 && !s->h263_msmpeg4) | |
793 *range *= 2; | |
0 | 794 |
324 | 795 if (s->unrestricted_mv) { |
796 *xmin = -16; | |
797 *ymin = -16; | |
798 if (s->h263_plus) | |
799 *range *= 2; | |
951 | 800 if(s->avctx->codec->id!=CODEC_ID_MPEG4){ |
324 | 801 *xmax = s->mb_width*16; |
802 *ymax = s->mb_height*16; | |
803 }else { | |
804 *xmax = s->width; | |
805 *ymax = s->height; | |
806 } | |
807 } else { | |
808 *xmin = 0; | |
809 *ymin = 0; | |
810 *xmax = s->mb_width*16 - 16; | |
811 *ymax = s->mb_height*16 - 16; | |
812 } | |
813 } | |
814 | |
1013 | 815 static inline int h263_mv4_search(MpegEncContext *s, int xmin, int ymin, int xmax, int ymax, int mx, int my, int shift) |
455 | 816 { |
817 int block; | |
818 int P[10][2]; | |
1013 | 819 int dmin_sum=0, mx4_sum=0, my4_sum=0; |
936 | 820 uint16_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV; |
455 | 821 |
822 for(block=0; block<4; block++){ | |
823 int mx4, my4; | |
824 int pred_x4, pred_y4; | |
825 int dmin4; | |
826 static const int off[4]= {2, 1, 1, -1}; | |
827 const int mot_stride = s->block_wrap[0]; | |
828 const int mot_xy = s->block_index[block]; | |
829 // const int block_x= (block&1); | |
830 // const int block_y= (block>>1); | |
831 #if 1 // this saves us a bit of cliping work and shouldnt affect compression in a negative way | |
832 const int rel_xmin4= xmin; | |
833 const int rel_xmax4= xmax; | |
834 const int rel_ymin4= ymin; | |
835 const int rel_ymax4= ymax; | |
836 #else | |
837 const int rel_xmin4= xmin - block_x*8; | |
838 const int rel_xmax4= xmax - block_x*8 + 8; | |
839 const int rel_ymin4= ymin - block_y*8; | |
840 const int rel_ymax4= ymax - block_y*8 + 8; | |
841 #endif | |
842 P_LEFT[0] = s->motion_val[mot_xy - 1][0]; | |
843 P_LEFT[1] = s->motion_val[mot_xy - 1][1]; | |
844 | |
845 if(P_LEFT[0] > (rel_xmax4<<shift)) P_LEFT[0] = (rel_xmax4<<shift); | |
846 | |
847 /* special case for first line */ | |
952 | 848 if (s->mb_y == 0 && block<2) { |
455 | 849 pred_x4= P_LEFT[0]; |
850 pred_y4= P_LEFT[1]; | |
851 } else { | |
852 P_TOP[0] = s->motion_val[mot_xy - mot_stride ][0]; | |
853 P_TOP[1] = s->motion_val[mot_xy - mot_stride ][1]; | |
854 P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + off[block]][0]; | |
855 P_TOPRIGHT[1] = s->motion_val[mot_xy - mot_stride + off[block]][1]; | |
856 if(P_TOP[1] > (rel_ymax4<<shift)) P_TOP[1] = (rel_ymax4<<shift); | |
857 if(P_TOPRIGHT[0] < (rel_xmin4<<shift)) P_TOPRIGHT[0]= (rel_xmin4<<shift); | |
858 if(P_TOPRIGHT[0] > (rel_xmax4<<shift)) P_TOPRIGHT[0]= (rel_xmax4<<shift); | |
859 if(P_TOPRIGHT[1] > (rel_ymax4<<shift)) P_TOPRIGHT[1]= (rel_ymax4<<shift); | |
860 | |
861 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
862 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
863 | |
1013 | 864 // if(s->out_format == FMT_H263){ |
455 | 865 pred_x4 = P_MEDIAN[0]; |
866 pred_y4 = P_MEDIAN[1]; | |
1013 | 867 #if 0 |
455 | 868 }else { /* mpeg1 at least */ |
869 pred_x4= P_LEFT[0]; | |
870 pred_y4= P_LEFT[1]; | |
871 } | |
1013 | 872 #endif |
455 | 873 } |
874 P_MV1[0]= mx; | |
875 P_MV1[1]= my; | |
876 | |
936 | 877 dmin4 = s->me.motion_search[1](s, block, &mx4, &my4, P, pred_x4, pred_y4, rel_xmin4, rel_ymin4, rel_xmax4, rel_ymax4, |
948 | 878 &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty); |
455 | 879 |
936 | 880 dmin4= s->me.sub_motion_search(s, &mx4, &my4, dmin4, rel_xmin4, rel_ymin4, rel_xmax4, rel_ymax4, |
881 pred_x4, pred_y4, &s->last_picture, block, 1, mv_penalty); | |
1038 | 882 |
883 if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){ | |
1013 | 884 int dxy; |
885 const int offset= ((block&1) + (block>>1)*s->linesize)*8; | |
886 uint8_t *dest_y = s->me.scratchpad + offset; | |
887 | |
888 if(s->quarter_sample){ | |
889 uint8_t *ref= s->last_picture.data[0] + (s->mb_x*16 + (mx4>>2)) + (s->mb_y*16 + (my4>>2))*s->linesize + offset; | |
890 dxy = ((my4 & 3) << 2) | (mx4 & 3); | |
891 | |
892 if(s->no_rounding) | |
1038 | 893 s->dsp.put_no_rnd_qpel_pixels_tab[1][dxy](dest_y , ref , s->linesize); |
1013 | 894 else |
1038 | 895 s->dsp.put_qpel_pixels_tab [1][dxy](dest_y , ref , s->linesize); |
1013 | 896 }else{ |
897 uint8_t *ref= s->last_picture.data[0] + (s->mb_x*16 + (mx4>>1)) + (s->mb_y*16 + (my4>>1))*s->linesize + offset; | |
898 dxy = ((my4 & 1) << 1) | (mx4 & 1); | |
899 | |
900 if(s->no_rounding) | |
1038 | 901 s->dsp.put_no_rnd_pixels_tab[1][dxy](dest_y , ref , s->linesize, 8); |
1013 | 902 else |
1038 | 903 s->dsp.put_pixels_tab [1][dxy](dest_y , ref , s->linesize, 8); |
1013 | 904 } |
905 dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*s->me.mb_penalty_factor; | |
906 }else | |
907 dmin_sum+= dmin4; | |
908 | |
909 if(s->quarter_sample){ | |
910 mx4_sum+= mx4/2; | |
911 my4_sum+= my4/2; | |
912 }else{ | |
913 mx4_sum+= mx4; | |
914 my4_sum+= my4; | |
915 } | |
916 | |
455 | 917 s->motion_val[ s->block_index[block] ][0]= mx4; |
918 s->motion_val[ s->block_index[block] ][1]= my4; | |
1013 | 919 } |
920 | |
1038 | 921 if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){ |
1013 | 922 dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*s->linesize, s->me.scratchpad, s->linesize); |
455 | 923 } |
1013 | 924 |
925 if(s->avctx->mb_cmp&FF_CMP_CHROMA){ | |
926 int dxy; | |
927 int mx, my; | |
928 int offset; | |
929 | |
930 mx= ff_h263_round_chroma(mx4_sum); | |
931 my= ff_h263_round_chroma(my4_sum); | |
932 dxy = ((my & 1) << 1) | (mx & 1); | |
933 | |
934 offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize; | |
935 | |
936 if(s->no_rounding){ | |
937 s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8); | |
938 s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8); | |
939 }else{ | |
940 s->dsp.put_pixels_tab [1][dxy](s->me.scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8); | |
941 s->dsp.put_pixels_tab [1][dxy](s->me.scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8); | |
942 } | |
943 | |
944 dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad , s->uvlinesize); | |
945 dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad+8, s->uvlinesize); | |
946 } | |
947 | |
948 switch(s->avctx->mb_cmp&0xFF){ | |
949 /*case FF_CMP_SSE: | |
950 return dmin_sum+ 32*s->qscale*s->qscale;*/ | |
951 case FF_CMP_RD: | |
952 return dmin_sum; | |
953 default: | |
954 return dmin_sum+ 11*s->me.mb_penalty_factor; | |
955 } | |
455 | 956 } |
957 | |
324 | 958 void ff_estimate_p_frame_motion(MpegEncContext * s, |
959 int mb_x, int mb_y) | |
0 | 960 { |
961 UINT8 *pix, *ppix; | |
962 int sum, varc, vard, mx, my, range, dmin, xx, yy; | |
963 int xmin, ymin, xmax, ymax; | |
280 | 964 int rel_xmin, rel_ymin, rel_xmax, rel_ymax; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
965 int pred_x=0, pred_y=0; |
455 | 966 int P[10][2]; |
280 | 967 const int shift= 1+s->quarter_sample; |
294 | 968 int mb_type=0; |
903 | 969 uint8_t *ref_picture= s->last_picture.data[0]; |
970 Picture * const pic= &s->current_picture; | |
936 | 971 uint16_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV; |
972 | |
973 assert(s->quarter_sample==0 || s->quarter_sample==1); | |
974 | |
975 s->me.penalty_factor = get_penalty_factor(s, s->avctx->me_cmp); | |
976 s->me.sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp); | |
1013 | 977 s->me.mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp); |
0 | 978 |
324 | 979 get_limits(s, &range, &xmin, &ymin, &xmax, &ymax, s->f_code); |
455 | 980 rel_xmin= xmin - mb_x*16; |
981 rel_xmax= xmax - mb_x*16; | |
982 rel_ymin= ymin - mb_y*16; | |
983 rel_ymax= ymax - mb_y*16; | |
936 | 984 s->me.skip=0; |
324 | 985 |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
304
diff
changeset
|
986 switch(s->me_method) { |
0 | 987 case ME_ZERO: |
988 default: | |
989 no_motion_search(s, &mx, &my); | |
455 | 990 mx-= mb_x*16; |
991 my-= mb_y*16; | |
0 | 992 dmin = 0; |
993 break; | |
994 case ME_FULL: | |
324 | 995 dmin = full_motion_search(s, &mx, &my, range, xmin, ymin, xmax, ymax, ref_picture); |
455 | 996 mx-= mb_x*16; |
997 my-= mb_y*16; | |
0 | 998 break; |
999 case ME_LOG: | |
324 | 1000 dmin = log_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture); |
455 | 1001 mx-= mb_x*16; |
1002 my-= mb_y*16; | |
0 | 1003 break; |
1004 case ME_PHODS: | |
324 | 1005 dmin = phods_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture); |
455 | 1006 mx-= mb_x*16; |
1007 my-= mb_y*16; | |
0 | 1008 break; |
288 | 1009 case ME_X1: |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
1010 case ME_EPZS: |
288 | 1011 { |
294 | 1012 const int mot_stride = s->block_wrap[0]; |
1013 const int mot_xy = s->block_index[0]; | |
288 | 1014 |
455 | 1015 P_LEFT[0] = s->motion_val[mot_xy - 1][0]; |
1016 P_LEFT[1] = s->motion_val[mot_xy - 1][1]; | |
288 | 1017 |
455 | 1018 if(P_LEFT[0] > (rel_xmax<<shift)) P_LEFT[0] = (rel_xmax<<shift); |
280 | 1019 |
952 | 1020 if(mb_y) { |
455 | 1021 P_TOP[0] = s->motion_val[mot_xy - mot_stride ][0]; |
1022 P_TOP[1] = s->motion_val[mot_xy - mot_stride ][1]; | |
1023 P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + 2][0]; | |
1024 P_TOPRIGHT[1] = s->motion_val[mot_xy - mot_stride + 2][1]; | |
1025 if(P_TOP[1] > (rel_ymax<<shift)) P_TOP[1] = (rel_ymax<<shift); | |
1026 if(P_TOPRIGHT[0] < (rel_xmin<<shift)) P_TOPRIGHT[0]= (rel_xmin<<shift); | |
1027 if(P_TOPRIGHT[1] > (rel_ymax<<shift)) P_TOPRIGHT[1]= (rel_ymax<<shift); | |
280 | 1028 |
455 | 1029 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
1030 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1031 | |
1032 if(s->out_format == FMT_H263){ | |
1033 pred_x = P_MEDIAN[0]; | |
1034 pred_y = P_MEDIAN[1]; | |
1035 }else { /* mpeg1 at least */ | |
1036 pred_x= P_LEFT[0]; | |
1037 pred_y= P_LEFT[1]; | |
1038 } | |
952 | 1039 }else{ |
1040 pred_x= P_LEFT[0]; | |
1041 pred_y= P_LEFT[1]; | |
288 | 1042 } |
952 | 1043 |
280 | 1044 } |
936 | 1045 dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, |
948 | 1046 &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty); |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
1047 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
1048 break; |
0 | 1049 } |
1050 | |
1051 /* intra / predictive decision */ | |
1052 xx = mb_x * 16; | |
1053 yy = mb_y * 16; | |
1054 | |
903 | 1055 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
455 | 1056 /* At this point (mx,my) are full-pell and the relative displacement */ |
1057 ppix = ref_picture + ((yy+my) * s->linesize) + (xx+mx); | |
289
648e9245546d
seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents:
288
diff
changeset
|
1058 |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1059 sum = s->dsp.pix_sum(pix, s->linesize); |
455 | 1060 |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1061 varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; |
936 | 1062 vard = (s->dsp.sse[0](NULL, pix, ppix, s->linesize)+128)>>8; |
608 | 1063 |
455 | 1064 //printf("%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout); |
903 | 1065 pic->mb_var [s->mb_width * mb_y + mb_x] = varc; |
1066 pic->mc_mb_var[s->mb_width * mb_y + mb_x] = vard; | |
1067 pic->mb_mean [s->mb_width * mb_y + mb_x] = (sum+128)>>8; | |
1013 | 1068 // pic->mb_cmp_score[s->mb_width * mb_y + mb_x] = dmin; |
903 | 1069 pic->mb_var_sum += varc; |
1070 pic->mc_mb_var_sum += vard; | |
455 | 1071 //printf("E%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout); |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
304
diff
changeset
|
1072 |
0 | 1073 #if 0 |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1074 printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n", |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1075 varc, s->avg_mb_var, sum, vard, mx - xx, my - yy); |
0 | 1076 #endif |
294 | 1077 if(s->flags&CODEC_FLAG_HQ){ |
608 | 1078 if (vard <= 64 || vard < varc) |
1079 s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); | |
1080 else | |
913 | 1081 s->scene_change_score+= s->qscale; |
608 | 1082 |
294 | 1083 if (vard*2 + 200 > varc) |
1084 mb_type|= MB_TYPE_INTRA; | |
1085 if (varc*2 + 200 > vard){ | |
1086 mb_type|= MB_TYPE_INTER; | |
936 | 1087 s->me.sub_motion_search(s, &mx, &my, dmin, rel_xmin, rel_ymin, rel_xmax, rel_ymax, |
1088 pred_x, pred_y, &s->last_picture, 0, 0, mv_penalty); | |
304 | 1089 }else{ |
936 | 1090 mx <<=shift; |
1091 my <<=shift; | |
0 | 1092 } |
455 | 1093 if((s->flags&CODEC_FLAG_4MV) |
936 | 1094 && !s->me.skip && varc>50 && vard>10){ |
1013 | 1095 h263_mv4_search(s, rel_xmin, rel_ymin, rel_xmax, rel_ymax, mx, my, shift); |
455 | 1096 mb_type|=MB_TYPE_INTER4V; |
1097 | |
1098 set_p_mv_tables(s, mx, my, 0); | |
1099 }else | |
1100 set_p_mv_tables(s, mx, my, 1); | |
294 | 1101 }else{ |
1013 | 1102 mb_type= MB_TYPE_INTER; |
1103 | |
1104 dmin= s->me.sub_motion_search(s, &mx, &my, dmin, rel_xmin, rel_ymin, rel_xmax, rel_ymax, | |
1105 pred_x, pred_y, &s->last_picture, 0, 0, mv_penalty); | |
1106 | |
1107 if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip) | |
1108 dmin= s->me.get_mb_score(s, mx, my, pred_x, pred_y, &s->last_picture, mv_penalty); | |
1109 | |
1110 if((s->flags&CODEC_FLAG_4MV) | |
1111 && !s->me.skip && varc>50 && vard>10){ | |
1112 int dmin4= h263_mv4_search(s, rel_xmin, rel_ymin, rel_xmax, rel_ymax, mx, my, shift); | |
1113 if(dmin4 < dmin){ | |
1114 mb_type= MB_TYPE_INTER4V; | |
1115 dmin=dmin4; | |
1116 } | |
1117 } | |
1118 pic->mb_cmp_score[s->mb_width * mb_y + mb_x] = dmin; | |
1119 set_p_mv_tables(s, mx, my, mb_type!=MB_TYPE_INTER4V); | |
1120 | |
294 | 1121 if (vard <= 64 || vard < varc) { |
608 | 1122 s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
294 | 1123 }else{ |
1011 | 1124 s->scene_change_score+= s->qscale; |
294 | 1125 } |
1126 } | |
284 | 1127 |
294 | 1128 s->mb_type[mb_y*s->mb_width + mb_x]= mb_type; |
0 | 1129 } |
1130 | |
951 | 1131 int ff_pre_estimate_p_frame_motion(MpegEncContext * s, |
1132 int mb_x, int mb_y) | |
1133 { | |
1134 int mx, my, range, dmin; | |
1135 int xmin, ymin, xmax, ymax; | |
1136 int rel_xmin, rel_ymin, rel_xmax, rel_ymax; | |
1137 int pred_x=0, pred_y=0; | |
1138 int P[10][2]; | |
1139 const int shift= 1+s->quarter_sample; | |
1140 uint16_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV; | |
1141 const int mv_stride= s->mb_width + 2; | |
1142 const int xy= mb_x + 1 + (mb_y + 1)*mv_stride; | |
1143 | |
1144 assert(s->quarter_sample==0 || s->quarter_sample==1); | |
1145 | |
954 | 1146 s->me.pre_penalty_factor = get_penalty_factor(s, s->avctx->me_pre_cmp); |
951 | 1147 |
1148 get_limits(s, &range, &xmin, &ymin, &xmax, &ymax, s->f_code); | |
1149 rel_xmin= xmin - mb_x*16; | |
1150 rel_xmax= xmax - mb_x*16; | |
1151 rel_ymin= ymin - mb_y*16; | |
1152 rel_ymax= ymax - mb_y*16; | |
1153 s->me.skip=0; | |
1154 | |
1155 P_LEFT[0] = s->p_mv_table[xy + 1][0]; | |
1156 P_LEFT[1] = s->p_mv_table[xy + 1][1]; | |
1157 | |
1158 if(P_LEFT[0] < (rel_xmin<<shift)) P_LEFT[0] = (rel_xmin<<shift); | |
1159 | |
1160 /* special case for first line */ | |
1161 if (mb_y == s->mb_height-1) { | |
1162 pred_x= P_LEFT[0]; | |
1163 pred_y= P_LEFT[1]; | |
952 | 1164 P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]= |
1165 P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME | |
951 | 1166 } else { |
1167 P_TOP[0] = s->p_mv_table[xy + mv_stride ][0]; | |
1168 P_TOP[1] = s->p_mv_table[xy + mv_stride ][1]; | |
1169 P_TOPRIGHT[0] = s->p_mv_table[xy + mv_stride - 1][0]; | |
1170 P_TOPRIGHT[1] = s->p_mv_table[xy + mv_stride - 1][1]; | |
1171 if(P_TOP[1] < (rel_ymin<<shift)) P_TOP[1] = (rel_ymin<<shift); | |
1172 if(P_TOPRIGHT[0] > (rel_xmax<<shift)) P_TOPRIGHT[0]= (rel_xmax<<shift); | |
1173 if(P_TOPRIGHT[1] < (rel_ymin<<shift)) P_TOPRIGHT[1]= (rel_ymin<<shift); | |
1174 | |
1175 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
1176 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1177 | |
952 | 1178 pred_x = P_MEDIAN[0]; |
1179 pred_y = P_MEDIAN[1]; | |
951 | 1180 } |
954 | 1181 dmin = s->me.pre_motion_search(s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, |
1182 &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty); | |
952 | 1183 |
951 | 1184 s->p_mv_table[xy][0] = mx<<shift; |
1185 s->p_mv_table[xy][1] = my<<shift; | |
1186 | |
1187 return dmin; | |
1188 } | |
1189 | |
327 | 1190 int ff_estimate_motion_b(MpegEncContext * s, |
936 | 1191 int mb_x, int mb_y, int16_t (*mv_table)[2], Picture *picture, int f_code) |
0 | 1192 { |
327 | 1193 int mx, my, range, dmin; |
324 | 1194 int xmin, ymin, xmax, ymax; |
1195 int rel_xmin, rel_ymin, rel_xmax, rel_ymax; | |
1196 int pred_x=0, pred_y=0; | |
455 | 1197 int P[10][2]; |
324 | 1198 const int shift= 1+s->quarter_sample; |
1199 const int mot_stride = s->mb_width + 2; | |
1200 const int mot_xy = (mb_y + 1)*mot_stride + mb_x + 1; | |
936 | 1201 uint8_t * const ref_picture= picture->data[0]; |
1202 uint16_t * const mv_penalty= s->me.mv_penalty[f_code] + MAX_MV; | |
948 | 1203 int mv_scale; |
936 | 1204 |
1205 s->me.penalty_factor = get_penalty_factor(s, s->avctx->me_cmp); | |
1206 s->me.sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp); | |
1013 | 1207 s->me.mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp); |
936 | 1208 |
324 | 1209 get_limits(s, &range, &xmin, &ymin, &xmax, &ymax, f_code); |
455 | 1210 rel_xmin= xmin - mb_x*16; |
1211 rel_xmax= xmax - mb_x*16; | |
1212 rel_ymin= ymin - mb_y*16; | |
1213 rel_ymax= ymax - mb_y*16; | |
324 | 1214 |
1215 switch(s->me_method) { | |
1216 case ME_ZERO: | |
1217 default: | |
1218 no_motion_search(s, &mx, &my); | |
1219 dmin = 0; | |
455 | 1220 mx-= mb_x*16; |
1221 my-= mb_y*16; | |
324 | 1222 break; |
1223 case ME_FULL: | |
1224 dmin = full_motion_search(s, &mx, &my, range, xmin, ymin, xmax, ymax, ref_picture); | |
455 | 1225 mx-= mb_x*16; |
1226 my-= mb_y*16; | |
324 | 1227 break; |
1228 case ME_LOG: | |
1229 dmin = log_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture); | |
455 | 1230 mx-= mb_x*16; |
1231 my-= mb_y*16; | |
324 | 1232 break; |
1233 case ME_PHODS: | |
1234 dmin = phods_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture); | |
455 | 1235 mx-= mb_x*16; |
1236 my-= mb_y*16; | |
324 | 1237 break; |
1238 case ME_X1: | |
1239 case ME_EPZS: | |
1240 { | |
455 | 1241 P_LEFT[0] = mv_table[mot_xy - 1][0]; |
1242 P_LEFT[1] = mv_table[mot_xy - 1][1]; | |
324 | 1243 |
455 | 1244 if(P_LEFT[0] > (rel_xmax<<shift)) P_LEFT[0] = (rel_xmax<<shift); |
324 | 1245 |
1246 /* special case for first line */ | |
952 | 1247 if (mb_y) { |
455 | 1248 P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; |
1249 P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; | |
1250 P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0]; | |
1251 P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1]; | |
1252 if(P_TOP[1] > (rel_ymax<<shift)) P_TOP[1]= (rel_ymax<<shift); | |
1253 if(P_TOPRIGHT[0] < (rel_xmin<<shift)) P_TOPRIGHT[0]= (rel_xmin<<shift); | |
1254 if(P_TOPRIGHT[1] > (rel_ymax<<shift)) P_TOPRIGHT[1]= (rel_ymax<<shift); | |
324 | 1255 |
455 | 1256 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
1257 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
324 | 1258 } |
455 | 1259 pred_x= P_LEFT[0]; |
1260 pred_y= P_LEFT[1]; | |
324 | 1261 } |
948 | 1262 |
1263 if(mv_table == s->b_forw_mv_table){ | |
1264 mv_scale= (s->pb_time<<16) / (s->pp_time<<shift); | |
1265 }else{ | |
1266 mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift); | |
1267 } | |
1268 | |
936 | 1269 dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, |
948 | 1270 picture, s->p_mv_table, mv_scale, mv_penalty); |
324 | 1271 |
1272 break; | |
1273 } | |
1274 | |
936 | 1275 dmin= s->me.sub_motion_search(s, &mx, &my, dmin, rel_xmin, rel_ymin, rel_xmax, rel_ymax, |
1276 pred_x, pred_y, picture, 0, 0, mv_penalty); | |
1013 | 1277 |
1278 if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip) | |
1279 dmin= s->me.get_mb_score(s, mx, my, pred_x, pred_y, picture, mv_penalty); | |
1280 | |
455 | 1281 //printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my); |
324 | 1282 // s->mb_type[mb_y*s->mb_width + mb_x]= mb_type; |
1283 mv_table[mot_xy][0]= mx; | |
1284 mv_table[mot_xy][1]= my; | |
936 | 1285 |
327 | 1286 return dmin; |
324 | 1287 } |
1288 | |
327 | 1289 static inline int check_bidir_mv(MpegEncContext * s, |
1290 int mb_x, int mb_y, | |
1291 int motion_fx, int motion_fy, | |
1292 int motion_bx, int motion_by, | |
1293 int pred_fx, int pred_fy, | |
1294 int pred_bx, int pred_by) | |
1295 { | |
1296 //FIXME optimize? | |
936 | 1297 //FIXME move into template? |
1298 //FIXME better f_code prediction (max mv & distance) | |
1299 UINT16 *mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame | |
1300 uint8_t *dest_y = s->me.scratchpad; | |
327 | 1301 uint8_t *ptr; |
1302 int dxy; | |
1303 int src_x, src_y; | |
1304 int fbmin; | |
1305 | |
936 | 1306 if(s->quarter_sample){ |
1307 dxy = ((motion_fy & 3) << 2) | (motion_fx & 3); | |
1308 src_x = mb_x * 16 + (motion_fx >> 2); | |
1309 src_y = mb_y * 16 + (motion_fy >> 2); | |
1310 assert(src_x >=-16 && src_x<=s->width); | |
1311 assert(src_y >=-16 && src_y<=s->height); | |
327 | 1312 |
936 | 1313 ptr = s->last_picture.data[0] + (src_y * s->linesize) + src_x; |
1314 s->dsp.put_qpel_pixels_tab[0][dxy](dest_y , ptr , s->linesize); | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1315 |
936 | 1316 dxy = ((motion_by & 3) << 2) | (motion_bx & 3); |
1317 src_x = mb_x * 16 + (motion_bx >> 2); | |
1318 src_y = mb_y * 16 + (motion_by >> 2); | |
1319 assert(src_x >=-16 && src_x<=s->width); | |
1320 assert(src_y >=-16 && src_y<=s->height); | |
1321 | |
1322 ptr = s->next_picture.data[0] + (src_y * s->linesize) + src_x; | |
1323 s->dsp.avg_qpel_pixels_tab[0][dxy](dest_y , ptr , s->linesize); | |
1324 }else{ | |
1325 dxy = ((motion_fy & 1) << 1) | (motion_fx & 1); | |
1326 src_x = mb_x * 16 + (motion_fx >> 1); | |
1327 src_y = mb_y * 16 + (motion_fy >> 1); | |
1328 assert(src_x >=-16 && src_x<=s->width); | |
1329 assert(src_y >=-16 && src_y<=s->height); | |
327 | 1330 |
936 | 1331 ptr = s->last_picture.data[0] + (src_y * s->linesize) + src_x; |
1332 s->dsp.put_pixels_tab[0][dxy](dest_y , ptr , s->linesize, 16); | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1333 |
936 | 1334 dxy = ((motion_by & 1) << 1) | (motion_bx & 1); |
1335 src_x = mb_x * 16 + (motion_bx >> 1); | |
1336 src_y = mb_y * 16 + (motion_by >> 1); | |
1337 assert(src_x >=-16 && src_x<=s->width); | |
1338 assert(src_y >=-16 && src_y<=s->height); | |
1339 | |
1340 ptr = s->next_picture.data[0] + (src_y * s->linesize) + src_x; | |
1341 s->dsp.avg_pixels_tab[0][dxy](dest_y , ptr , s->linesize, 16); | |
1342 } | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1343 |
1013 | 1344 fbmin = (mv_penalty[motion_fx-pred_fx] + mv_penalty[motion_fy-pred_fy])*s->me.mb_penalty_factor |
1345 +(mv_penalty[motion_bx-pred_bx] + mv_penalty[motion_by-pred_by])*s->me.mb_penalty_factor | |
1346 + s->dsp.mb_cmp[0](s, s->new_picture.data[0] + mb_x*16 + mb_y*16*s->linesize, dest_y, s->linesize); | |
1347 | |
1348 if(s->avctx->mb_cmp&FF_CMP_CHROMA){ | |
1349 } | |
1350 //FIXME CHROMA !!! | |
1351 | |
327 | 1352 return fbmin; |
1353 } | |
1354 | |
1355 /* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/ | |
1356 static inline int bidir_refine(MpegEncContext * s, | |
1357 int mb_x, int mb_y) | |
1358 { | |
1359 const int mot_stride = s->mb_width + 2; | |
1360 const int xy = (mb_y + 1)*mot_stride + mb_x + 1; | |
1361 int fbmin; | |
1362 int pred_fx= s->b_bidir_forw_mv_table[xy-1][0]; | |
1363 int pred_fy= s->b_bidir_forw_mv_table[xy-1][1]; | |
1364 int pred_bx= s->b_bidir_back_mv_table[xy-1][0]; | |
1365 int pred_by= s->b_bidir_back_mv_table[xy-1][1]; | |
1366 int motion_fx= s->b_bidir_forw_mv_table[xy][0]= s->b_forw_mv_table[xy][0]; | |
1367 int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1]; | |
1368 int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0]; | |
1369 int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1]; | |
1370 | |
1371 //FIXME do refinement and add flag | |
1372 | |
1373 fbmin= check_bidir_mv(s, mb_x, mb_y, | |
1374 motion_fx, motion_fy, | |
1375 motion_bx, motion_by, | |
1376 pred_fx, pred_fy, | |
1377 pred_bx, pred_by); | |
1378 | |
1379 return fbmin; | |
1380 } | |
1381 | |
1382 static inline int direct_search(MpegEncContext * s, | |
1383 int mb_x, int mb_y) | |
324 | 1384 { |
455 | 1385 int P[10][2]; |
327 | 1386 const int mot_stride = s->mb_width + 2; |
1387 const int mot_xy = (mb_y + 1)*mot_stride + mb_x + 1; | |
936 | 1388 const int shift= 1+s->quarter_sample; |
1389 int dmin, i; | |
327 | 1390 const int time_pp= s->pp_time; |
664 | 1391 const int time_pb= s->pb_time; |
936 | 1392 int mx, my, xmin, xmax, ymin, ymax; |
327 | 1393 int16_t (*mv_table)[2]= s->b_direct_mv_table; |
936 | 1394 uint16_t * const mv_penalty= s->me.mv_penalty[1] + MAX_MV; |
1395 | |
1396 ymin= xmin=(-32)>>shift; | |
1397 ymax= xmax= 31>>shift; | |
1398 | |
1399 if(s->co_located_type_table[mb_x + mb_y*s->mb_width]==CO_LOCATED_TYPE_4MV){ | |
1400 s->mv_type= MV_TYPE_8X8; | |
1401 }else{ | |
1402 s->mv_type= MV_TYPE_16X16; | |
327 | 1403 } |
936 | 1404 |
1405 for(i=0; i<4; i++){ | |
1406 int index= s->block_index[i]; | |
1407 int min, max; | |
1408 | |
1409 s->me.co_located_mv[i][0]= s->motion_val[index][0]; | |
1410 s->me.co_located_mv[i][1]= s->motion_val[index][1]; | |
1411 s->me.direct_basis_mv[i][0]= s->me.co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3)); | |
1412 s->me.direct_basis_mv[i][1]= s->me.co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3)); | |
1413 // s->me.direct_basis_mv[1][i][0]= s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3); | |
1414 // s->me.direct_basis_mv[1][i][1]= s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3); | |
1415 | |
1416 max= FFMAX(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift; | |
1417 min= FFMIN(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift; | |
1050 | 1418 max+= (2*mb_x + (i& 1))*8 + 1; // +-1 is for the simpler rounding |
1419 min+= (2*mb_x + (i& 1))*8 - 1; | |
960 | 1420 xmax= FFMIN(xmax, s->width - max); |
1421 xmin= FFMAX(xmin, - 16 - min); | |
936 | 1422 |
1423 max= FFMAX(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift; | |
1424 min= FFMIN(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift; | |
1050 | 1425 max+= (2*mb_y + (i>>1))*8 + 1; // +-1 is for the simpler rounding |
1426 min+= (2*mb_y + (i>>1))*8 - 1; | |
960 | 1427 ymax= FFMIN(ymax, s->height - max); |
1428 ymin= FFMAX(ymin, - 16 - min); | |
936 | 1429 |
1430 if(s->mv_type == MV_TYPE_16X16) break; | |
327 | 1431 } |
936 | 1432 |
1433 assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16); | |
1434 | |
1435 if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){ | |
1436 s->b_direct_mv_table[mot_xy][0]= 0; | |
1437 s->b_direct_mv_table[mot_xy][1]= 0; | |
1438 | |
1439 return 256*256*256*64; | |
1440 } | |
1441 | |
950 | 1442 P_LEFT[0] = clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift); |
1443 P_LEFT[1] = clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift); | |
1444 | |
1445 /* special case for first line */ | |
952 | 1446 if (mb_y) { |
950 | 1447 P_TOP[0] = clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift); |
1448 P_TOP[1] = clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift); | |
1449 P_TOPRIGHT[0] = clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift); | |
1450 P_TOPRIGHT[1] = clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift); | |
1451 | |
1452 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); | |
1453 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1454 } | |
1013 | 1455 |
1456 //FIXME direct_search ptr in context!!! (needed for chroma anyway or this will get messy) | |
936 | 1457 if(s->flags&CODEC_FLAG_QPEL){ |
1458 dmin = simple_direct_qpel_epzs_motion_search(s, 0, &mx, &my, P, 0, 0, xmin, ymin, xmax, ymax, | |
948 | 1459 &s->last_picture, mv_table, 1<<14, mv_penalty); |
936 | 1460 dmin = simple_direct_qpel_qpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax, |
1461 0, 0, &s->last_picture, 0, 0, mv_penalty); | |
1013 | 1462 |
1463 if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip) | |
1464 dmin= simple_direct_qpel_qpel_get_mb_score(s, mx, my, 0, 0, &s->last_picture, mv_penalty); | |
936 | 1465 }else{ |
1466 dmin = simple_direct_hpel_epzs_motion_search(s, 0, &mx, &my, P, 0, 0, xmin, ymin, xmax, ymax, | |
948 | 1467 &s->last_picture, mv_table, 1<<15, mv_penalty); |
936 | 1468 dmin = simple_direct_hpel_hpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax, |
1469 0, 0, &s->last_picture, 0, 0, mv_penalty); | |
1013 | 1470 |
1471 if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip) | |
1472 dmin= simple_direct_hpel_hpel_get_mb_score(s, mx, my, 0, 0, &s->last_picture, mv_penalty); | |
327 | 1473 } |
1474 | |
1475 s->b_direct_mv_table[mot_xy][0]= mx; | |
1476 s->b_direct_mv_table[mot_xy][1]= my; | |
1477 return dmin; | |
324 | 1478 } |
1479 | |
1480 void ff_estimate_b_frame_motion(MpegEncContext * s, | |
1481 int mb_x, int mb_y) | |
1482 { | |
1013 | 1483 const int penalty_factor= s->me.mb_penalty_factor; |
327 | 1484 int fmin, bmin, dmin, fbmin; |
1485 int type=0; | |
1486 | |
1487 dmin= direct_search(s, mb_x, mb_y); | |
324 | 1488 |
1013 | 1489 fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, &s->last_picture, s->f_code) + 3*penalty_factor; |
1490 bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, &s->next_picture, s->b_code) + 2*penalty_factor; | |
324 | 1491 //printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]); |
327 | 1492 |
1013 | 1493 fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor; |
1494 //printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin); | |
612 | 1495 { |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1496 int score= fmin; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1497 type = MB_TYPE_FORWARD; |
327 | 1498 |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1499 // RAL: No MB_TYPE_DIRECT in MPEG-1 video (only MPEG-4) |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1500 if (s->codec_id != CODEC_ID_MPEG1VIDEO && dmin <= score){ |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1501 score = dmin; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1502 type = MB_TYPE_DIRECT; |
327 | 1503 } |
1504 if(bmin<score){ | |
1505 score=bmin; | |
1506 type= MB_TYPE_BACKWARD; | |
1507 } | |
1508 if(fbmin<score){ | |
1509 score=fbmin; | |
1510 type= MB_TYPE_BIDIR; | |
1511 } | |
1013 | 1512 |
807
0e1d375c537f
fixing q>0.0 assert failure caused by overflow of variance for b frames
michaelni
parents:
765
diff
changeset
|
1513 score= ((unsigned)(score*score + 128*256))>>16; |
903 | 1514 s->current_picture.mc_mb_var_sum += score; |
1013 | 1515 s->current_picture.mc_mb_var[mb_y*s->mb_width + mb_x] = score; //FIXME use SSE |
327 | 1516 } |
612 | 1517 |
1518 if(s->flags&CODEC_FLAG_HQ){ | |
1519 type= MB_TYPE_FORWARD | MB_TYPE_BACKWARD | MB_TYPE_BIDIR | MB_TYPE_DIRECT; //FIXME something smarter | |
936 | 1520 if(dmin>256*256*16) type&= ~MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB |
612 | 1521 } |
1522 | |
327 | 1523 s->mb_type[mb_y*s->mb_width + mb_x]= type; |
324 | 1524 } |
0 | 1525 |
324 | 1526 /* find best f_code for ME which do unlimited searches */ |
1527 int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) | |
1528 { | |
1529 if(s->me_method>=ME_EPZS){ | |
455 | 1530 int score[8]; |
324 | 1531 int i, y; |
1532 UINT8 * fcode_tab= s->fcode_tab; | |
455 | 1533 int best_fcode=-1; |
1534 int best_score=-10000000; | |
324 | 1535 |
936 | 1536 for(i=0; i<8; i++) score[i]= s->mb_num*(8-i); |
324 | 1537 |
1538 for(y=0; y<s->mb_height; y++){ | |
1539 int x; | |
1540 int xy= (y+1)* (s->mb_width+2) + 1; | |
1541 i= y*s->mb_width; | |
1542 for(x=0; x<s->mb_width; x++){ | |
1543 if(s->mb_type[i] & type){ | |
847 | 1544 int fcode= FFMAX(fcode_tab[mv_table[xy][0] + MAX_MV], |
1545 fcode_tab[mv_table[xy][1] + MAX_MV]); | |
455 | 1546 int j; |
1547 | |
1548 for(j=0; j<fcode && j<8; j++){ | |
903 | 1549 if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[i] < s->current_picture.mb_var[i]) |
455 | 1550 score[j]-= 170; |
1551 } | |
324 | 1552 } |
1553 i++; | |
1554 xy++; | |
1555 } | |
1556 } | |
455 | 1557 |
1558 for(i=1; i<8; i++){ | |
1559 if(score[i] > best_score){ | |
1560 best_score= score[i]; | |
1561 best_fcode= i; | |
1562 } | |
1563 // printf("%d %d\n", i, score[i]); | |
1564 } | |
327 | 1565 |
324 | 1566 // printf("fcode: %d type: %d\n", i, s->pict_type); |
455 | 1567 return best_fcode; |
324 | 1568 /* for(i=0; i<=MAX_FCODE; i++){ |
1569 printf("%d ", mv_num[i]); | |
1570 } | |
1571 printf("\n");*/ | |
1572 }else{ | |
1573 return 1; | |
0 | 1574 } |
1575 } | |
1576 | |
324 | 1577 void ff_fix_long_p_mvs(MpegEncContext * s) |
1578 { | |
1579 const int f_code= s->f_code; | |
1580 int y; | |
1581 UINT8 * fcode_tab= s->fcode_tab; | |
455 | 1582 //int clip=0; |
1583 //int noclip=0; | |
324 | 1584 /* clip / convert to intra 16x16 type MVs */ |
1585 for(y=0; y<s->mb_height; y++){ | |
1586 int x; | |
1587 int xy= (y+1)* (s->mb_width+2)+1; | |
1588 int i= y*s->mb_width; | |
1589 for(x=0; x<s->mb_width; x++){ | |
1590 if(s->mb_type[i]&MB_TYPE_INTER){ | |
1591 if( fcode_tab[s->p_mv_table[xy][0] + MAX_MV] > f_code | |
1592 || fcode_tab[s->p_mv_table[xy][0] + MAX_MV] == 0 | |
1593 || fcode_tab[s->p_mv_table[xy][1] + MAX_MV] > f_code | |
1594 || fcode_tab[s->p_mv_table[xy][1] + MAX_MV] == 0 ){ | |
1595 s->mb_type[i] &= ~MB_TYPE_INTER; | |
1596 s->mb_type[i] |= MB_TYPE_INTRA; | |
1597 s->p_mv_table[xy][0] = 0; | |
1598 s->p_mv_table[xy][1] = 0; | |
455 | 1599 //clip++; |
324 | 1600 } |
455 | 1601 //else |
1602 // noclip++; | |
324 | 1603 } |
1604 xy++; | |
1605 i++; | |
1606 } | |
1607 } | |
455 | 1608 //printf("%d no:%d %d//\n", clip, noclip, f_code); |
324 | 1609 if(s->flags&CODEC_FLAG_4MV){ |
1610 const int wrap= 2+ s->mb_width*2; | |
1611 | |
1612 /* clip / convert to intra 8x8 type MVs */ | |
1613 for(y=0; y<s->mb_height; y++){ | |
1614 int xy= (y*2 + 1)*wrap + 1; | |
1615 int i= y*s->mb_width; | |
1616 int x; | |
1617 | |
1618 for(x=0; x<s->mb_width; x++){ | |
1619 if(s->mb_type[i]&MB_TYPE_INTER4V){ | |
1620 int block; | |
1621 for(block=0; block<4; block++){ | |
1622 int off= (block& 1) + (block>>1)*wrap; | |
1623 int mx= s->motion_val[ xy + off ][0]; | |
1624 int my= s->motion_val[ xy + off ][1]; | |
1625 | |
1626 if( fcode_tab[mx + MAX_MV] > f_code | |
1627 || fcode_tab[mx + MAX_MV] == 0 | |
1628 || fcode_tab[my + MAX_MV] > f_code | |
1629 || fcode_tab[my + MAX_MV] == 0 ){ | |
1630 s->mb_type[i] &= ~MB_TYPE_INTER4V; | |
1631 s->mb_type[i] |= MB_TYPE_INTRA; | |
1632 } | |
1633 } | |
1634 } | |
502 | 1635 xy+=2; |
1636 i++; | |
324 | 1637 } |
1638 } | |
1639 } | |
1640 } | |
1641 | |
1642 void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, int type) | |
1643 { | |
1644 int y; | |
1645 UINT8 * fcode_tab= s->fcode_tab; | |
1646 | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1647 // RAL: 8 in MPEG-1, 16 in MPEG-4 |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1648 int range = (((s->codec_id == CODEC_ID_MPEG1VIDEO) ? 8 : 16) << f_code); |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1649 |
324 | 1650 /* clip / convert to intra 16x16 type MVs */ |
1651 for(y=0; y<s->mb_height; y++){ | |
1652 int x; | |
1653 int xy= (y+1)* (s->mb_width+2)+1; | |
1654 int i= y*s->mb_width; | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1655 for(x=0; x<s->mb_width; x++) |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1656 { |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1657 if (s->mb_type[i] & type) // RAL: "type" test added... |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1658 { |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1659 if (fcode_tab[mv_table[xy][0] + MAX_MV] > f_code || fcode_tab[mv_table[xy][0] + MAX_MV] == 0) |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1660 { |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1661 if(mv_table[xy][0]>0) |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1662 mv_table[xy][0]= range-1; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1663 else |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1664 mv_table[xy][0]= -range; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1665 } |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1666 if (fcode_tab[mv_table[xy][1] + MAX_MV] > f_code || fcode_tab[mv_table[xy][1] + MAX_MV] == 0) |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1667 { |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1668 if(mv_table[xy][1]>0) |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1669 mv_table[xy][1]= range-1; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1670 else |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1671 mv_table[xy][1]= -range; |
691
199b324b2693
fixing variance scaling for b frames (messed adaptive quants up)
michaelni
parents:
690
diff
changeset
|
1672 } |
324 | 1673 } |
1674 xy++; | |
1675 i++; | |
1676 } | |
1677 } | |
1678 } |