annotate motion_est_template.c @ 1938:e2501e6e7ff7 libavcodec

unify table indexing (motion_val,dc_val,ac_val,coded_block changed) minor +-1 bugfix
author michael
date Fri, 16 Apr 2004 01:01:45 +0000
parents e039d79185c2
children a3c60fa850dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1 /*
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
2 * Motion estimation
1739
07a484280a82 copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents: 1708
diff changeset
3 * Copyright (c) 2002-2004 Michael Niedermayer
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
4 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
9 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
13 * Lesser General Public License for more details.
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
14 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
18 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
19 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
20
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
21 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
22 * @file motion_est_template.c
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
23 * Motion estimation template.
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
24 */
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
25 //FIXME ref2_y next_pic?
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
26 //lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
27 //Note, the last line is there to kill these ugly unused var warnings
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
28 #define LOAD_COMMON\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
29 uint32_t * const score_map= s->me.score_map;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
30 const int time_pp= s->pp_time;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
31 const int time_pb= s->pb_time;\
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
32 const int xmin= s->me.xmin;\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
33 const int ymin= s->me.ymin;\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
34 const int xmax= s->me.xmax;\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
35 const int ymax= s->me.ymax;\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
36 uint8_t * const src_y= src_data[0];\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
37 uint8_t * const src_u= src_data[1];\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
38 uint8_t * const src_v= src_data[2];\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
39 uint8_t * const ref_y= ref_data[0];\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
40 uint8_t * const ref_u= ref_data[1];\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
41 uint8_t * const ref_v= ref_data[2];\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
42 op_pixels_func (*hpel_put)[4];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
43 op_pixels_func (*hpel_avg)[4]= &s->dsp.avg_pixels_tab[size];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
44 op_pixels_func (*chroma_hpel_put)[4];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
45 qpel_mc_func (*qpel_put)[16];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
46 qpel_mc_func (*qpel_avg)[16]= &s->dsp.avg_qpel_pixels_tab[size];\
1266
ec946cb74397 Warning fixes.
mellum
parents: 1177
diff changeset
47 const __attribute__((unused)) int unu= time_pp + time_pb + (size_t)src_u + (size_t)src_v + (size_t)ref_u + (size_t)ref_v\
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
48 + (size_t)hpel_avg + (size_t)qpel_avg + (size_t)score_map\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
49 + xmin + xmax + ymin + ymax;\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
50 if(s->no_rounding /*FIXME b_type*/){\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
51 hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
52 chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
53 qpel_put= &s->dsp.put_no_rnd_qpel_pixels_tab[size];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
54 }else{\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
55 hpel_put=& s->dsp.put_pixels_tab[size];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
56 chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
57 qpel_put= &s->dsp.put_qpel_pixels_tab[size];\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
58 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
59
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
60
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
61 #ifdef CMP_HPEL
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
62
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
63 #define CHECK_HALF_MV(dx, dy, x, y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
64 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
65 const int hx= 2*(x)+(dx);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
66 const int hy= 2*(y)+(dy);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
67 CMP_HPEL(d, dx, dy, x, y, size);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
68 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
69 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
70 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
71
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
72 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
73 static int RENAME(hpel_motion_search)(MpegEncContext * s,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
74 int *mx_ptr, int *my_ptr, int dmin,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
75 int pred_x, int pred_y, uint8_t *ref_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
76 int size, uint8_t * const mv_penalty)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
77 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
78 const int xx = 16 * s->mb_x + 8*(n&1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
79 const int yy = 16 * s->mb_y + 8*(n>>1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
80 const int mx = *mx_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
81 const int my = *my_ptr;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
82 const int penalty_factor= s->me.sub_penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
83
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
84 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
85
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
86 // INIT;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
87 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
88 me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
89
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
90 if(s->no_rounding /*FIXME b_type*/){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
91 hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
92 chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
93 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
94 hpel_put=& s->dsp.put_pixels_tab[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
95 chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
96 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
97 cmp= s->dsp.me_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
98 chroma_cmp= s->dsp.me_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
99 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
100 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
101
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
102 if(s->me.skip){ //FIXME somehow move up (benchmark)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
103 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
104 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
105 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
106 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
107
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
108 if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
109 CMP_HPEL(dmin, 0, 0, mx, my, size);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
110 if(mx || my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
111 dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
112 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
113
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
114 if (mx > xmin && mx < xmax &&
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
115 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
116 int bx=2*mx, by=2*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
117 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
118
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
119 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
120 CHECK_HALF_MV(0, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
121 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
122 CHECK_HALF_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
123 CHECK_HALF_MV(1, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
124 CHECK_HALF_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
125 CHECK_HALF_MV(0, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
126 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
127
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
128 assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
129
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
130 *mx_ptr = bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
131 *my_ptr = by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
132 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
133 *mx_ptr =2*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
134 *my_ptr =2*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
135 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
136
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
137 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
138 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
139
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
140 #else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
141 static int RENAME(hpel_motion_search)(MpegEncContext * s,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
142 int *mx_ptr, int *my_ptr, int dmin,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
143 int pred_x, int pred_y, uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
144 uint8_t *ref_data[3], int stride, int uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
145 int size, int h, uint8_t * const mv_penalty)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
146 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
147 const int mx = *mx_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
148 const int my = *my_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
149 const int penalty_factor= s->me.sub_penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
150 me_cmp_func cmp_sub, chroma_cmp_sub;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
151 int bx=2*mx, by=2*my;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
152
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
153 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
154
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
155 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
156
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
157 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
158 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
159
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
160 if(s->me.skip){ //FIXME move out of hpel?
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
161 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
162 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
163 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
164 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
165
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
166 if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
167 CMP_HPEL(dmin, 0, 0, mx, my, size);
1011
michaelni
parents: 954
diff changeset
168 if(mx || my || size>0)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
169 dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
170 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
171
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
172 if (mx > xmin && mx < xmax &&
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
173 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
174 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
175 const int index= (my<<ME_MAP_SHIFT) + mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
176 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
177 + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*s->me.penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
178 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
179 + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
180 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
181 + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
182 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
183 + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*s->me.penalty_factor;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
184
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
185 #if 1
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
186 int key;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
187 int map_generation= s->me.map_generation;
1419
a7a9df478e46 removed unused variable
bellard
parents: 1266
diff changeset
188 #ifndef NDEBUG
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
189 uint32_t *map= s->me.map;
1419
a7a9df478e46 removed unused variable
bellard
parents: 1266
diff changeset
190 #endif
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
191 key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
192 assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
193 key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
194 assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
195 key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
196 assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
197 key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
198 assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
199 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
200 if(t<=b){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
201 CHECK_HALF_MV(0, 1, mx ,my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
202 if(l<=r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
203 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
204 if(t+r<=b+l){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
205 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
206 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
207 CHECK_HALF_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
208 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
209 CHECK_HALF_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
210 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
211 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
212 if(t+l<=b+r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
213 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
214 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
215 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
216 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
217 CHECK_HALF_MV(1, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
218 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
219 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
220 if(l<=r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
221 if(t+l<=b+r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
222 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
223 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
224 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
225 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
226 CHECK_HALF_MV(1, 0, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
227 CHECK_HALF_MV(1, 1, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
228 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
229 if(t+r<=b+l){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
230 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
231 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
232 CHECK_HALF_MV(1, 1, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
233 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
234 CHECK_HALF_MV(1, 0, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
235 CHECK_HALF_MV(1, 1, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
236 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
237 CHECK_HALF_MV(0, 1, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
238 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
239 assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
240 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
241
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
242 *mx_ptr = bx;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
243 *my_ptr = by;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
244
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
245 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
246 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
247 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
248
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
249 static int RENAME(hpel_get_mb_score)(MpegEncContext * s, int mx, int my, int pred_x, int pred_y, uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
250 uint8_t *ref_data[3], int stride, int uvstride,
1162
8c15d82c1893 some static -> dynamic alloc & 16->8 bit
michaelni
parents: 1106
diff changeset
251 uint8_t * const mv_penalty)
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
252 {
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
253 // const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
254 const int size= 0;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
255 const int h= 16;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
256 const int penalty_factor= s->me.mb_penalty_factor;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
257 me_cmp_func cmp_sub, chroma_cmp_sub;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
258 int d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
259
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
260 LOAD_COMMON
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
261
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
262 //FIXME factorize
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
263
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
264 cmp_sub= s->dsp.mb_cmp[size];
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
265 chroma_cmp_sub= s->dsp.mb_cmp[size+1];
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
266
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
267 assert(!s->me.skip);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
268 assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
269
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
270 CMP_HPEL(d, mx&1, my&1, mx>>1, my>>1, size);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
271 //FIXME check cbp before adding penalty for (0,0) vector
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
272 if(mx || my || size>0)
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
273 d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
274
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
275 return d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
276 }
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
277
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
278 #endif /* CMP_HPEL */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
279
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
280
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
281
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
282 #ifdef CMP_QPEL
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
283
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
284 #define CHECK_QUARTER_MV(dx, dy, x, y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
285 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
286 const int hx= 4*(x)+(dx);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
287 const int hy= 4*(y)+(dy);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
288 CMP_QPEL(d, dx, dy, x, y, size);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
289 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
290 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
291 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
292
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
293 static int RENAME(qpel_motion_search)(MpegEncContext * s,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
294 int *mx_ptr, int *my_ptr, int dmin,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
295 int pred_x, int pred_y, uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
296 uint8_t *ref_data[3], int stride, int uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
297 int size, int h, uint8_t * const mv_penalty)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
298 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
299 const int mx = *mx_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
300 const int my = *my_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
301 const int penalty_factor= s->me.sub_penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
302 const int map_generation= s->me.map_generation;
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
303 const int subpel_quality= s->avctx->me_subpel_quality;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
304 uint32_t *map= s->me.map;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
305 me_cmp_func cmp, chroma_cmp;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
306 me_cmp_func cmp_sub, chroma_cmp_sub;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
307
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
308 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
309
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
310 cmp= s->dsp.me_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
311 chroma_cmp= s->dsp.me_cmp[size+1]; //factorize FIXME
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
312 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
313
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
314 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
315 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
316
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
317 if(s->me.skip){ //FIXME somehow move up (benchmark)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
318 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
319 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
320 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
321 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
322
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
323 if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
324 CMP_QPEL(dmin, 0, 0, mx, my, size);
1011
michaelni
parents: 954
diff changeset
325 if(mx || my || size>0)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
326 dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
327 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
328
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
329 if (mx > xmin && mx < xmax &&
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
330 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
331 int bx=4*mx, by=4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
332 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
333 int i, nx, ny;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
334 const int index= (my<<ME_MAP_SHIFT) + mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
335 const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
336 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
337 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
338 const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
339 const int c= score_map[(index )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
340 int best[8];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
341 int best_pos[8][2];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
342
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
343 memset(best, 64, sizeof(int)*8);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
344 #if 1
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
345 if(s->me.dia_size>=2){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
346 const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
347 const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
348 const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
349 const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
350
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
351 for(ny= -3; ny <= 3; ny++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
352 for(nx= -3; nx <= 3; nx++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
353 const int t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
354 const int c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
355 const int b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
356 int score= ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
357 int i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
358
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
359 if((nx&3)==0 && (ny&3)==0) continue;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
360
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
361 score += 1024*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
362
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
363 // if(nx&1) score-=1024*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
364 // if(ny&1) score-=1024*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
365
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
366 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
367 if(score < best[i]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
368 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
369 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
370 best[i]= score;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
371 best_pos[i][0]= nx + 4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
372 best_pos[i][1]= ny + 4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
373 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
374 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
375 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
376 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
377 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
378 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
379 int tl;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
380 const int cx = 4*(r - l);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
381 const int cx2= r + l - 2*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
382 const int cy = 4*(b - t);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
383 const int cy2= b + t - 2*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
384 int cxy;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
385
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
386 if(map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)] == (my<<ME_MAP_MV_BITS) + mx + map_generation && 0){ //FIXME
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
387 tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
388 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
389 CMP(tl, mx-1, my-1, size); //FIXME wrong if chroma me is different
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
390 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
391
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
392 cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
393
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
394 assert(16*cx2 + 4*cx + 32*c == 32*r);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
395 assert(16*cx2 - 4*cx + 32*c == 32*l);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
396 assert(16*cy2 + 4*cy + 32*c == 32*b);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
397 assert(16*cy2 - 4*cy + 32*c == 32*t);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
398 assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
399
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
400 for(ny= -3; ny <= 3; ny++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
401 for(nx= -3; nx <= 3; nx++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
402 int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c; //FIXME factor
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
403 int i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
404
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
405 if((nx&3)==0 && (ny&3)==0) continue;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
406
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
407 score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
408 // if(nx&1) score-=32*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
409 // if(ny&1) score-=32*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
410
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
411 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
412 if(score < best[i]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
413 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
414 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
415 best[i]= score;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
416 best_pos[i][0]= nx + 4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
417 best_pos[i][1]= ny + 4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
418 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
419 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
420 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
421 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
422 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
423 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
424 for(i=0; i<subpel_quality; i++){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
425 nx= best_pos[i][0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
426 ny= best_pos[i][1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
427 CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
428 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
429
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
430 #if 0
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
431 const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
432 const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
433 const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
434 const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
435 // if(l < r && l < t && l < b && l < tl && l < bl && l < tr && l < br && bl < tl){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
436 if(tl<br){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
437
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
438 // nx= FFMAX(4*mx - bx, bx - 4*mx);
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
439 // ny= FFMAX(4*my - by, by - 4*my);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
440
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
441 static int stats[7][7], count;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
442 count++;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
443 stats[4*mx - bx + 3][4*my - by + 3]++;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
444 if(256*256*256*64 % count ==0){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
445 for(i=0; i<49; i++){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
446 if((i%7)==0) printf("\n");
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
447 printf("%6d ", stats[0][i]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
448 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
449 printf("\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
450 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
451 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
452 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
453 #else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
454
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
455 CHECK_QUARTER_MV(2, 2, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
456 CHECK_QUARTER_MV(0, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
457 CHECK_QUARTER_MV(2, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
458 CHECK_QUARTER_MV(2, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
459 CHECK_QUARTER_MV(2, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
460 CHECK_QUARTER_MV(0, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
461 CHECK_QUARTER_MV(2, 2, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
462 CHECK_QUARTER_MV(2, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
463
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
464 nx= bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
465 ny= by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
466
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
467 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
468 int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
469 int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
470 CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
471 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
472 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
473 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
474 //outer ring
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
475 CHECK_QUARTER_MV(1, 3, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
476 CHECK_QUARTER_MV(1, 2, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
477 CHECK_QUARTER_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
478 CHECK_QUARTER_MV(2, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
479 CHECK_QUARTER_MV(3, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
480 CHECK_QUARTER_MV(0, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
481 CHECK_QUARTER_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
482 CHECK_QUARTER_MV(2, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
483 CHECK_QUARTER_MV(3, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
484 CHECK_QUARTER_MV(3, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
485 CHECK_QUARTER_MV(3, 3, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
486 CHECK_QUARTER_MV(3, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
487 CHECK_QUARTER_MV(3, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
488 CHECK_QUARTER_MV(3, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
489 CHECK_QUARTER_MV(3, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
490 CHECK_QUARTER_MV(2, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
491 CHECK_QUARTER_MV(1, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
492 CHECK_QUARTER_MV(0, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
493 CHECK_QUARTER_MV(3, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
494 CHECK_QUARTER_MV(2, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
495 CHECK_QUARTER_MV(1, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
496 CHECK_QUARTER_MV(1, 2, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
497 CHECK_QUARTER_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
498 CHECK_QUARTER_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
499 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
500 assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
501
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
502 *mx_ptr = bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
503 *my_ptr = by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
504 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
505 *mx_ptr =4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
506 *my_ptr =4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
507 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
508
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
509 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
510 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
511
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
512 static int RENAME(qpel_get_mb_score)(MpegEncContext * s, int mx, int my, int pred_x, int pred_y, uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
513 uint8_t *ref_data[3], int stride, int uvstride,
1162
8c15d82c1893 some static -> dynamic alloc & 16->8 bit
michaelni
parents: 1106
diff changeset
514 uint8_t * const mv_penalty)
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
515 {
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
516 const int size= 0;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
517 const int h= 16;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
518 const int penalty_factor= s->me.mb_penalty_factor;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
519 me_cmp_func cmp_sub, chroma_cmp_sub;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
520 int d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
521
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
522 LOAD_COMMON
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
523
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
524 //FIXME factorize
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
525
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
526 cmp_sub= s->dsp.mb_cmp[size];
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
527 chroma_cmp_sub= s->dsp.mb_cmp[size+1];
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
528
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
529 assert(!s->me.skip);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
530 assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
531
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
532 CMP_QPEL(d, mx&3, my&3, mx>>2, my>>2, size);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
533 //FIXME check cbp before adding penalty for (0,0) vector
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
534 if(mx || my || size>0)
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
535 d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
536
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
537 return d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
538 }
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
539
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
540
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
541 #endif /* CMP_QPEL */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
542
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
543 #define CHECK_MV(x,y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
544 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
545 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
546 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
547 /*printf("check_mv %d %d\n", x, y);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
548 if(map[index]!=key){\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
549 CMP(d, x, y, size);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
550 map[index]= key;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
551 score_map[index]= d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
552 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
553 /*printf("score:%d\n", d);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
554 COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
555 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
556 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
557
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
558 #define CHECK_CLIPED_MV(ax,ay)\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
559 {\
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
560 const int x= ax;\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
561 const int y= ay;\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
562 const int x2= FFMAX(xmin, FFMIN(x, xmax));\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
563 const int y2= FFMAX(ymin, FFMIN(y, ymax));\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
564 CHECK_MV(x2, y2)\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
565 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
566
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
567 #define CHECK_MV_DIR(x,y,new_dir)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
568 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
569 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
570 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
571 /*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
572 if(map[index]!=key){\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
573 CMP(d, x, y, size);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
574 map[index]= key;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
575 score_map[index]= d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
576 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
577 /*printf("score:%d\n", d);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
578 if(d<dmin){\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
579 best[0]=x;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
580 best[1]=y;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
581 dmin=d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
582 next_dir= new_dir;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
583 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
584 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
585 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
586
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
587 #define check(x,y,S,v)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
588 if( (x)<(xmin<<(S)) ) printf("%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
589 if( (x)>(xmax<<(S)) ) printf("%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
590 if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
591 if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
592
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
593
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
594 static inline int RENAME(small_diamond_search)(MpegEncContext * s, int *best, int dmin,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
595 uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
596 uint8_t *ref_data[3], int stride, int uvstride,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
597 int const pred_x, int const pred_y, int const penalty_factor,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
598 int const shift,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
599 uint32_t *map, int map_generation, int size, int h, uint8_t * const mv_penalty
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
600 )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
601 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
602 me_cmp_func cmp, chroma_cmp;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
603 int next_dir=-1;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
604 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
605
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
606 cmp= s->dsp.me_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
607 chroma_cmp= s->dsp.me_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
608
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
609 { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
610 const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
611 const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
612 if(map[index]!=key){ //this will be executed only very rarey
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
613 CMP(score_map[index], best[0], best[1], size);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
614 map[index]= key;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
615 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
616 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
617
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
618 for(;;){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
619 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
620 const int dir= next_dir;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
621 const int x= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
622 const int y= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
623 next_dir=-1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
624
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
625 //printf("%d", dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
626 if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
627 if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
628 if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
629 if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
630
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
631 if(next_dir==-1){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
632 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
633 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
634 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
635 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
636
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
637 static inline int RENAME(funny_diamond_search)(MpegEncContext * s, int *best, int dmin,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
638 uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
639 uint8_t *ref_data[3], int stride, int uvstride,
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
640 int const pred_x, int const pred_y, int const penalty_factor,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
641 int const shift,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
642 uint32_t *map, int map_generation, int size, int h, uint8_t * const mv_penalty
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
643 )
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
644 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
645 me_cmp_func cmp, chroma_cmp;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
646 int dia_size;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
647 LOAD_COMMON
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
648
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
649 cmp= s->dsp.me_cmp[size];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
650 chroma_cmp= s->dsp.me_cmp[size+1];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
651
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
652 for(dia_size=1; dia_size<=4; dia_size++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
653 int dir;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
654 const int x= best[0];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
655 const int y= best[1];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
656
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
657 if(dia_size&(dia_size-1)) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
658
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
659 if( x + dia_size > xmax
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
660 || x - dia_size < xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
661 || y + dia_size > ymax
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
662 || y - dia_size < ymin)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
663 continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
664
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
665 for(dir= 0; dir<dia_size; dir+=2){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
666 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
667
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
668 CHECK_MV(x + dir , y + dia_size - dir);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
669 CHECK_MV(x + dia_size - dir, y - dir );
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
670 CHECK_MV(x - dir , y - dia_size + dir);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
671 CHECK_MV(x - dia_size + dir, y + dir );
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
672 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
673
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
674 if(x!=best[0] || y!=best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
675 dia_size=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
676 #if 0
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
677 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
678 int dx, dy, i;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
679 static int stats[8*8];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
680 dx= ABS(x-best[0]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
681 dy= ABS(y-best[1]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
682 if(dy>dx){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
683 dx^=dy; dy^=dx; dx^=dy;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
684 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
685 stats[dy*8 + dx] ++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
686 if(256*256*256*64 % (stats[0]+1)==0){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
687 for(i=0; i<64; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
688 if((i&7)==0) printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
689 printf("%8d ", stats[i]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
690 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
691 printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
692 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
693 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
694 #endif
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
695 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
696 return dmin;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
697 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
698
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
699 #define SAB_CHECK_MV(ax,ay)\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
700 {\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
701 const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
702 const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
703 /*printf("sab check %d %d\n", ax, ay);*/\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
704 if(map[index]!=key){\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
705 CMP(d, ax, ay, size);\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
706 map[index]= key;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
707 score_map[index]= d;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
708 d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
709 /*printf("score: %d\n", d);*/\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
710 if(d < minima[minima_count-1].height){\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
711 int j=0;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
712 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
713 while(d >= minima[j].height) j++;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
714 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
715 memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
716 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
717 minima[j].checked= 0;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
718 minima[j].height= d;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
719 minima[j].x= ax;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
720 minima[j].y= ay;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
721 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
722 i=-1;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
723 continue;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
724 }\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
725 }\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
726 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
727
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
728 #define MAX_SAB_SIZE 16
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
729 static inline int RENAME(sab_diamond_search)(MpegEncContext * s, int *best, int dmin,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
730 uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
731 uint8_t *ref_data[3], int stride, int uvstride,
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
732 int const pred_x, int const pred_y, int const penalty_factor,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
733 int const shift,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
734 uint32_t *map, int map_generation, int size, int h, uint8_t * const mv_penalty
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
735 )
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
736 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
737 me_cmp_func cmp, chroma_cmp;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
738 Minima minima[MAX_SAB_SIZE];
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
739 const int minima_count= ABS(s->me.dia_size);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
740 int i, j;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
741 LOAD_COMMON
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
742
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
743 cmp= s->dsp.me_cmp[size];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
744 chroma_cmp= s->dsp.me_cmp[size+1];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
745
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
746 for(j=i=0; i<ME_MAP_SIZE; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
747 uint32_t key= map[i];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
748
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
749 key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
750
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
751 if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
752
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
753 assert(j<MAX_SAB_SIZE); //max j = number of predictors
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
754
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
755 minima[j].height= score_map[i];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
756 minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
757 minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
758 minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
759 minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
760 minima[j].checked=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
761 if(minima[j].x || minima[j].y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
762 minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
763
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
764 j++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
765 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
766
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
767 qsort(minima, j, sizeof(Minima), minima_cmp);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
768
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
769 for(; j<minima_count; j++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
770 minima[j].height=256*256*256*64;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
771 minima[j].checked=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
772 minima[j].x= minima[j].y=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
773 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
774
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
775 for(i=0; i<minima_count; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
776 const int x= minima[i].x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
777 const int y= minima[i].y;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
778 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
779
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
780 if(minima[i].checked) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
781
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
782 if( x >= xmax || x <= xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
783 || y >= ymax || y <= ymin)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
784 continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
785
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
786 SAB_CHECK_MV(x-1, y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
787 SAB_CHECK_MV(x+1, y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
788 SAB_CHECK_MV(x , y-1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
789 SAB_CHECK_MV(x , y+1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
790
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
791 minima[i].checked= 1;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
792 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
793
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
794 best[0]= minima[0].x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
795 best[1]= minima[0].y;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
796 dmin= minima[0].height;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
797
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
798 if( best[0] < xmax && best[0] > xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
799 && best[1] < ymax && best[1] > ymin){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
800 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
801 //ensure that the refernece samples for hpel refinement are in the map
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
802 CHECK_MV(best[0]-1, best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
803 CHECK_MV(best[0]+1, best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
804 CHECK_MV(best[0], best[1]-1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
805 CHECK_MV(best[0], best[1]+1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
806 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
807 return dmin;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
808 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
809
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
810 static inline int RENAME(var_diamond_search)(MpegEncContext * s, int *best, int dmin,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
811 uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
812 uint8_t *ref_data[3], int stride, int uvstride,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
813 int const pred_x, int const pred_y, int const penalty_factor,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
814 int const shift,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
815 uint32_t *map, int map_generation, int size, int h, uint8_t * const mv_penalty
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
816 )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
817 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
818 me_cmp_func cmp, chroma_cmp;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
819 int dia_size;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
820 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
821
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
822 cmp= s->dsp.me_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
823 chroma_cmp= s->dsp.me_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
824
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
825 for(dia_size=1; dia_size<=s->me.dia_size; dia_size++){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
826 int dir, start, end;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
827 const int x= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
828 const int y= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
829
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
830 start= FFMAX(0, y + dia_size - ymax);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
831 end = FFMIN(dia_size, xmax - x + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
832 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
833 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
834
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
835 //check(x + dir,y + dia_size - dir,0, a0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
836 CHECK_MV(x + dir , y + dia_size - dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
837 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
838
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
839 start= FFMAX(0, x + dia_size - xmax);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
840 end = FFMIN(dia_size, y - ymin + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
841 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
842 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
843
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
844 //check(x + dia_size - dir, y - dir,0, a1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
845 CHECK_MV(x + dia_size - dir, y - dir );
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
846 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
847
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
848 start= FFMAX(0, -y + dia_size + ymin );
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
849 end = FFMIN(dia_size, x - xmin + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
850 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
851 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
852
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
853 //check(x - dir,y - dia_size + dir,0, a2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
854 CHECK_MV(x - dir , y - dia_size + dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
855 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
856
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
857 start= FFMAX(0, -x + dia_size + xmin );
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
858 end = FFMIN(dia_size, ymax - y + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
859 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
860 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
861
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
862 //check(x - dia_size + dir, y + dir,0, a3)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
863 CHECK_MV(x - dia_size + dir, y + dir );
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
864 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
865
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
866 if(x!=best[0] || y!=best[1])
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
867 dia_size=0;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
868 #if 0
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
869 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
870 int dx, dy, i;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
871 static int stats[8*8];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
872 dx= ABS(x-best[0]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
873 dy= ABS(y-best[1]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
874 stats[dy*8 + dx] ++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
875 if(256*256*256*64 % (stats[0]+1)==0){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
876 for(i=0; i<64; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
877 if((i&7)==0) printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
878 printf("%6d ", stats[i]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
879 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
880 printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
881 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
882 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
883 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
884 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
885 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
886 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
887
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
888 static int RENAME(epzs_motion_search)(MpegEncContext * s,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
889 int *mx_ptr, int *my_ptr,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
890 int P[10][2], int pred_x, int pred_y, uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
891 uint8_t *ref_data[3], int stride, int uvstride, int16_t (*last_mv)[2],
1162
8c15d82c1893 some static -> dynamic alloc & 16->8 bit
michaelni
parents: 1106
diff changeset
892 int ref_mv_scale, uint8_t * const mv_penalty)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
893 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
894 int best[2]={0, 0};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
895 int d, dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
896 const int shift= 1+s->quarter_sample;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
897 uint32_t *map= s->me.map;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
898 int map_generation;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
899 const int penalty_factor= s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
900 const int size=0;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
901 const int h=16;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
902 const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
903 const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
904 me_cmp_func cmp, chroma_cmp;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
905 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
906
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
907 cmp= s->dsp.me_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
908 chroma_cmp= s->dsp.me_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
909
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
910 map_generation= update_map_generation(s);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
911
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
912 CMP(dmin, 0, 0, size);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
913 map[0]= map_generation;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
914 score_map[0]= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
915
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
916 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
917 if (s->first_slice_line) {
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
918 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
919 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
920 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
921 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
922 if(dmin<256 && ( P_LEFT[0] |P_LEFT[1]
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
923 |P_TOP[0] |P_TOP[1]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
924 |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
925 *mx_ptr= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
926 *my_ptr= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
927 s->me.skip=1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
928 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
929 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
930 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
931 if(dmin>256*2){
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
932 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
933 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
934 CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
935 CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
936 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
937 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
938 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
939 if(dmin>256*4){
952
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
940 if(s->me.pre_pass){
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
941 CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
942 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
943 if(!s->first_slice_line)
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
944 CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
945 (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
952
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
946 }else{
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
947 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
948 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
1800
e039d79185c2 simplify MV availability check / dont use below last row MV which is always zero
michael
parents: 1799
diff changeset
949 if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
950 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
951 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
952
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
952 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
953 }
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
954
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
955 if(s->avctx->last_predictor_count){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
956 const int count= s->avctx->last_predictor_count;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
957 const int xstart= FFMAX(0, s->mb_x - count);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
958 const int ystart= FFMAX(0, s->mb_y - count);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
959 const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
960 const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
961 int mb_y;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
962
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
963 for(mb_y=ystart; mb_y<yend; mb_y++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
964 int mb_x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
965 for(mb_x=xstart; mb_x<xend; mb_x++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
966 const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
967 int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
968 int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
969
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
970 if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
971 CHECK_MV(mx,my)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
972 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
973 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
974 }
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
975
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
976 //check(best[0],best[1],0, b0)
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
977 if(s->me.dia_size==-1)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
978 dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
979 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
980 shift, map, map_generation, size, h, mv_penalty);
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
981 else if(s->me.dia_size<-1)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
982 dmin= RENAME(sab_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
983 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
984 shift, map, map_generation, size, h, mv_penalty);
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
985 else if(s->me.dia_size<2)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
986 dmin= RENAME(small_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
987 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
988 shift, map, map_generation, size, h, mv_penalty);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
989 else
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
990 dmin= RENAME(var_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
991 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
992 shift, map, map_generation, size, h, mv_penalty);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
993
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
994 //check(best[0],best[1],0, b1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
995 *mx_ptr= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
996 *my_ptr= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
997
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
998 // printf("%d %d %d \n", best[0], best[1], dmin);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
999 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1000 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1001
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1002 #ifndef CMP_DIRECT /* no 4mv search needed in direct mode */
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1003 static int RENAME(epzs_motion_search4)(MpegEncContext * s,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1004 int *mx_ptr, int *my_ptr,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1005 int P[10][2], int pred_x, int pred_y,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1006 uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1007 uint8_t *ref_data[3], int stride, int uvstride, int16_t (*last_mv)[2],
1162
8c15d82c1893 some static -> dynamic alloc & 16->8 bit
michaelni
parents: 1106
diff changeset
1008 int ref_mv_scale, uint8_t * const mv_penalty)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1009 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1010 int best[2]={0, 0};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1011 int d, dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1012 const int shift= 1+s->quarter_sample;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1013 uint32_t *map= s->me.map;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1014 int map_generation;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1015 const int penalty_factor= s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1016 const int size=1;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1017 const int h=8;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1162
diff changeset
1018 const int ref_mv_stride= s->mb_stride;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1162
diff changeset
1019 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1020 me_cmp_func cmp, chroma_cmp;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1021 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1022
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1023 cmp= s->dsp.me_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1024 chroma_cmp= s->dsp.me_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1025
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1026 map_generation= update_map_generation(s);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1027
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1028 dmin = 1000000;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1029 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1030 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1031 if (s->first_slice_line) {
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1032 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1033 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1034 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1035 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1036 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1037 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1038 //FIXME try some early stop
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1039 if(dmin>64*2){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1040 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1041 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1042 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1043 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1044 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1045 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1046 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1047 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1048 if(dmin>64*4){
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1049 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1050 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
1800
e039d79185c2 simplify MV availability check / dont use below last row MV which is always zero
michael
parents: 1799
diff changeset
1051 if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1052 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1053 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1054 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1055
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
1056 if(s->me.dia_size==-1)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1057 dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1058 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1059 shift, map, map_generation, size, h, mv_penalty);
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
1060 else if(s->me.dia_size<-1)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1061 dmin= RENAME(sab_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1062 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1063 shift, map, map_generation, size, h, mv_penalty);
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
1064 else if(s->me.dia_size<2)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1065 dmin= RENAME(small_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1066 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1067 shift, map, map_generation, size, h, mv_penalty);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1068 else
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1069 dmin= RENAME(var_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1070 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1071 shift, map, map_generation, size, h, mv_penalty);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1072
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1073
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1074 *mx_ptr= best[0];
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1075 *my_ptr= best[1];
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1076
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1077 // printf("%d %d %d \n", best[0], best[1], dmin);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1078 return dmin;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1079 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1080
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1081 //try to merge with above FIXME (needs PSNR test)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1082 static int RENAME(epzs_motion_search2)(MpegEncContext * s,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1083 int *mx_ptr, int *my_ptr,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1084 int P[10][2], int pred_x, int pred_y,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1085 uint8_t *src_data[3],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1086 uint8_t *ref_data[3], int stride, int uvstride, int16_t (*last_mv)[2],
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1087 int ref_mv_scale, uint8_t * const mv_penalty)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1088 {
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1089 int best[2]={0, 0};
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1090 int d, dmin;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1091 const int shift= 1+s->quarter_sample;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1092 uint32_t *map= s->me.map;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1093 int map_generation;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1094 const int penalty_factor= s->me.penalty_factor;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1095 const int size=0; //FIXME pass as arg
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1096 const int h=8;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1097 const int ref_mv_stride= s->mb_stride;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1098 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1099 me_cmp_func cmp, chroma_cmp;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1100 LOAD_COMMON
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1101
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1102 cmp= s->dsp.me_cmp[size];
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1103 chroma_cmp= s->dsp.me_cmp[size+1];
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1104
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1105 map_generation= update_map_generation(s);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1106
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1107 dmin = 1000000;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1108 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1109 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1110 if (s->first_slice_line) {
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1111 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1112 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1113 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1114 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1115 }else{
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1116 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1117 //FIXME try some early stop
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1118 if(dmin>64*2){
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1119 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1120 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1121 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1122 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1123 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1124 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1125 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1126 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1127 if(dmin>64*4){
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1128 CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1129 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
1800
e039d79185c2 simplify MV availability check / dont use below last row MV which is always zero
michael
parents: 1799
diff changeset
1130 if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1131 CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1132 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1133 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1134
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1135 if(s->me.dia_size==-1)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1136 dmin= RENAME(funny_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1137 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1138 shift, map, map_generation, size, h, mv_penalty);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1139 else if(s->me.dia_size<-1)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1140 dmin= RENAME(sab_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1141 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1142 shift, map, map_generation, size, h, mv_penalty);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1143 else if(s->me.dia_size<2)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1144 dmin= RENAME(small_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1145 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1146 shift, map, map_generation, size, h, mv_penalty);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1147 else
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1148 dmin= RENAME(var_diamond_search)(s, best, dmin, src_data, ref_data, stride, uvstride,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1149 pred_x, pred_y, penalty_factor,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1150 shift, map, map_generation, size, h, mv_penalty);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1151
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1152
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1153 *mx_ptr= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1154 *my_ptr= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1155
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1156 // printf("%d %d %d \n", best[0], best[1], dmin);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1157 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1158 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1159 #endif /* !CMP_DIRECT */