annotate motion_est_template.c @ 2013:85e547a18d87 libavcodec

dummy avcodec_thread_init() to avoid linking issues
author michael
date Mon, 10 May 2004 23:38:53 +0000
parents a3c60fa850dc
children 15c885db82a8
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 */
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
25
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 ...)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
27 #define LOAD_COMMON\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
28 uint32_t * const score_map= s->me.score_map;\
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
29 const int xmin= s->me.xmin;\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
30 const int ymin= s->me.ymin;\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
31 const int xmax= s->me.xmax;\
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
32 const int ymax= s->me.ymax;\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
33 uint8_t *mv_penalty= s->me.current_mv_penalty;\
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
34 const int pred_x= s->me.pred_x;\
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
35 const int pred_y= s->me.pred_y;\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
36
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
37 #define CHECK_HALF_MV(dx, dy, x, y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
38 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
39 const int hx= 2*(x)+(dx);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
40 const int hy= 2*(y)+(dy);\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
41 d= cmp(s, x, y, dx, dy, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
42 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
43 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
44 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
45
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
46 #if 0
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
47 static int hpel_motion_search)(MpegEncContext * s,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
48 int *mx_ptr, int *my_ptr, int dmin,
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
49 uint8_t *ref_data[3],
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
50 int size)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
51 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
52 const int xx = 16 * s->mb_x + 8*(n&1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
53 const int yy = 16 * s->mb_y + 8*(n>>1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
54 const int mx = *mx_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
55 const int my = *my_ptr;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
56 const int penalty_factor= s->me.sub_penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
57
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
58 LOAD_COMMON
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
59
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
60 // INIT;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
61 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
62 me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
63
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
64 if(s->no_rounding /*FIXME b_type*/){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
65 hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
66 chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
67 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
68 hpel_put=& s->dsp.put_pixels_tab[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
69 chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
70 }
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
71 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
72 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
73 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
74 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
75
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
76 if(s->me.skip){ //FIXME somehow move up (benchmark)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
77 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
78 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
79 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
80 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
81
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
82 if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
83 CMP_HPEL(dmin, 0, 0, mx, my, size);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
84 if(mx || my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
85 dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
86 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
87
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
88 if (mx > xmin && mx < xmax &&
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
89 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
90 int bx=2*mx, by=2*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
91 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
92
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
93 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
94 CHECK_HALF_MV(0, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
95 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
96 CHECK_HALF_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
97 CHECK_HALF_MV(1, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
98 CHECK_HALF_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
99 CHECK_HALF_MV(0, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
100 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
101
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
102 assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
103
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
104 *mx_ptr = bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
105 *my_ptr = by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
106 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
107 *mx_ptr =2*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
108 *my_ptr =2*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
109 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
110
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
111 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
112 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
113
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
114 #else
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
115 static int hpel_motion_search(MpegEncContext * s,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
116 int *mx_ptr, int *my_ptr, int dmin,
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
117 int src_index, int ref_index,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
118 int size, int h)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
119 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
120 const int mx = *mx_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
121 const int my = *my_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
122 const int penalty_factor= s->me.sub_penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
123 me_cmp_func cmp_sub, chroma_cmp_sub;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
124 int bx=2*mx, by=2*my;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
125
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
126 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
127 int flags= s->me.sub_flags;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
128
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
129 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
130
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
131 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
132 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
133
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
134 if(s->me.skip){ //FIXME move out of hpel?
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
135 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
136 *my_ptr = 0;
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 if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
141 dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
1011
michaelni
parents: 954
diff changeset
142 if(mx || my || size>0)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
143 dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
144 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
145
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
146 if (mx > xmin && mx < xmax &&
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
147 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
148 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
149 const int index= (my<<ME_MAP_SHIFT) + mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
150 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
151 + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*s->me.penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
152 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
153 + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
154 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
155 + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
156 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
157 + (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
158
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
159 #if 1
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
160 int key;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
161 int map_generation= s->me.map_generation;
1419
a7a9df478e46 removed unused variable
bellard
parents: 1266
diff changeset
162 #ifndef NDEBUG
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
163 uint32_t *map= s->me.map;
1419
a7a9df478e46 removed unused variable
bellard
parents: 1266
diff changeset
164 #endif
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
165 key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
166 assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
167 key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
168 assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
169 key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
170 assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
171 key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
172 assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
173 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
174 if(t<=b){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
175 CHECK_HALF_MV(0, 1, mx ,my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
176 if(l<=r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
177 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
178 if(t+r<=b+l){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
179 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
180 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
181 CHECK_HALF_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
182 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
183 CHECK_HALF_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
184 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
185 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
186 if(t+l<=b+r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
187 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
188 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
189 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
190 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
191 CHECK_HALF_MV(1, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
192 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
193 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
194 if(l<=r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
195 if(t+l<=b+r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
196 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
197 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
198 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
199 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
200 CHECK_HALF_MV(1, 0, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
201 CHECK_HALF_MV(1, 1, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
202 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
203 if(t+r<=b+l){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
204 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
205 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
206 CHECK_HALF_MV(1, 1, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
207 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
208 CHECK_HALF_MV(1, 0, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
209 CHECK_HALF_MV(1, 1, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
210 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
211 CHECK_HALF_MV(0, 1, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
212 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
213 assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
214 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
215
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
216 *mx_ptr = bx;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
217 *my_ptr = by;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
218
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
219 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
220 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
221 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
222
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
223 static int inline get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
224 int ref_index)
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
225 {
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
226 // const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
227 const int size= 0;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
228 const int h= 16;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
229 const int penalty_factor= s->me.mb_penalty_factor;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
230 const int flags= s->me.mb_flags;
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
231 const int qpel= flags & FLAG_QPEL;
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
232 const int mask= 1+2*qpel;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
233 me_cmp_func cmp_sub, chroma_cmp_sub;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
234 int d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
235
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
236 LOAD_COMMON
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
237
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
238 //FIXME factorize
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
239
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
240 cmp_sub= s->dsp.mb_cmp[size];
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
241 chroma_cmp_sub= s->dsp.mb_cmp[size+1];
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
242
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
243 assert(!s->me.skip);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
244 assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp);
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
245
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
246 d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
247 //FIXME check cbp before adding penalty for (0,0) vector
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
248 if(mx || my || size>0)
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
249 d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
250
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
251 return d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
252 }
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
253
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
254 #define CHECK_QUARTER_MV(dx, dy, x, y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
255 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
256 const int hx= 4*(x)+(dx);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
257 const int hy= 4*(y)+(dy);\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
258 d= cmp(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
259 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
260 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
261 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
262
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
263 static int qpel_motion_search(MpegEncContext * s,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
264 int *mx_ptr, int *my_ptr, int dmin,
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
265 int src_index, int ref_index,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
266 int size, int h)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
267 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
268 const int mx = *mx_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
269 const int my = *my_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
270 const int penalty_factor= s->me.sub_penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
271 const int map_generation= s->me.map_generation;
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
272 const int subpel_quality= s->avctx->me_subpel_quality;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
273 uint32_t *map= s->me.map;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
274 me_cmp_func cmpf, chroma_cmpf;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
275 me_cmp_func cmp_sub, chroma_cmp_sub;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
276
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
277 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
278 int flags= s->me.sub_flags;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
279
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
280 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
281 chroma_cmpf= s->dsp.me_cmp[size+1]; //factorize FIXME
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
282 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
283
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
284 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
285 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
286
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
287 if(s->me.skip){ //FIXME somehow move up (benchmark)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
288 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
289 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
290 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
291 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
292
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
293 if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
294 dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
1011
michaelni
parents: 954
diff changeset
295 if(mx || my || size>0)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
296 dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
297 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
298
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
299 if (mx > xmin && mx < xmax &&
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
300 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
301 int bx=4*mx, by=4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
302 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
303 int i, nx, ny;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
304 const int index= (my<<ME_MAP_SHIFT) + mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
305 const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
306 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
307 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
308 const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
309 const int c= score_map[(index )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
310 int best[8];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
311 int best_pos[8][2];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
312
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
313 memset(best, 64, sizeof(int)*8);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
314 #if 1
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
315 if(s->me.dia_size>=2){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
316 const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
317 const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
318 const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
319 const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
320
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
321 for(ny= -3; ny <= 3; ny++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
322 for(nx= -3; nx <= 3; nx++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
323 const int t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
324 const int c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
325 const int b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
326 int score= ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
327 int i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
328
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
329 if((nx&3)==0 && (ny&3)==0) continue;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
330
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
331 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
332
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
333 // if(nx&1) score-=1024*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
334 // if(ny&1) score-=1024*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
335
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
336 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
337 if(score < best[i]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
338 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
339 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
340 best[i]= score;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
341 best_pos[i][0]= nx + 4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
342 best_pos[i][1]= ny + 4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
343 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
344 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
345 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
346 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
347 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
348 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
349 int tl;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
350 const int cx = 4*(r - l);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
351 const int cx2= r + l - 2*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
352 const int cy = 4*(b - t);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
353 const int cy2= b + t - 2*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
354 int cxy;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
355
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
356 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
357 tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
358 }else{
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
359 tl= cmp(s, mx-1, my-1, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);//FIXME wrong if chroma me is different
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
360 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
361
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
362 cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
363
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
364 assert(16*cx2 + 4*cx + 32*c == 32*r);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
365 assert(16*cx2 - 4*cx + 32*c == 32*l);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
366 assert(16*cy2 + 4*cy + 32*c == 32*b);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
367 assert(16*cy2 - 4*cy + 32*c == 32*t);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
368 assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
369
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
370 for(ny= -3; ny <= 3; ny++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
371 for(nx= -3; nx <= 3; nx++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
372 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
373 int i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
374
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
375 if((nx&3)==0 && (ny&3)==0) continue;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
376
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
377 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
378 // if(nx&1) score-=32*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
379 // if(ny&1) score-=32*s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
380
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
381 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
382 if(score < best[i]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
383 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
384 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
385 best[i]= score;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
386 best_pos[i][0]= nx + 4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
387 best_pos[i][1]= ny + 4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
388 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
389 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
390 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
391 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
392 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
393 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
394 for(i=0; i<subpel_quality; i++){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
395 nx= best_pos[i][0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
396 ny= best_pos[i][1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
397 CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
398 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
399
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
400 #if 0
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
401 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
402 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
403 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
404 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
405 // 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
406 if(tl<br){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
407
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
408 // nx= FFMAX(4*mx - bx, bx - 4*mx);
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
409 // ny= FFMAX(4*my - by, by - 4*my);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
410
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
411 static int stats[7][7], count;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
412 count++;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
413 stats[4*mx - bx + 3][4*my - by + 3]++;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
414 if(256*256*256*64 % count ==0){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
415 for(i=0; i<49; i++){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
416 if((i%7)==0) printf("\n");
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
417 printf("%6d ", stats[0][i]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
418 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
419 printf("\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
420 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
421 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
422 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
423 #else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
424
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
425 CHECK_QUARTER_MV(2, 2, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
426 CHECK_QUARTER_MV(0, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
427 CHECK_QUARTER_MV(2, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
428 CHECK_QUARTER_MV(2, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
429 CHECK_QUARTER_MV(2, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
430 CHECK_QUARTER_MV(0, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
431 CHECK_QUARTER_MV(2, 2, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
432 CHECK_QUARTER_MV(2, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
433
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
434 nx= bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
435 ny= by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
436
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
437 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
438 int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
439 int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
440 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
441 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
442 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
443 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
444 //outer ring
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
445 CHECK_QUARTER_MV(1, 3, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
446 CHECK_QUARTER_MV(1, 2, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
447 CHECK_QUARTER_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
448 CHECK_QUARTER_MV(2, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
449 CHECK_QUARTER_MV(3, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
450 CHECK_QUARTER_MV(0, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
451 CHECK_QUARTER_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
452 CHECK_QUARTER_MV(2, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
453 CHECK_QUARTER_MV(3, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
454 CHECK_QUARTER_MV(3, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
455 CHECK_QUARTER_MV(3, 3, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
456 CHECK_QUARTER_MV(3, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
457 CHECK_QUARTER_MV(3, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
458 CHECK_QUARTER_MV(3, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
459 CHECK_QUARTER_MV(3, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
460 CHECK_QUARTER_MV(2, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
461 CHECK_QUARTER_MV(1, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
462 CHECK_QUARTER_MV(0, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
463 CHECK_QUARTER_MV(3, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
464 CHECK_QUARTER_MV(2, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
465 CHECK_QUARTER_MV(1, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
466 CHECK_QUARTER_MV(1, 2, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
467 CHECK_QUARTER_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
468 CHECK_QUARTER_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
469 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
470 assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
471
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
472 *mx_ptr = bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
473 *my_ptr = by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
474 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
475 *mx_ptr =4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
476 *my_ptr =4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
477 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
478
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
479 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
480 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
481
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
482
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
483 #define CHECK_MV(x,y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
484 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
485 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
486 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
487 /*printf("check_mv %d %d\n", x, y);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
488 if(map[index]!=key){\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
489 d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
490 map[index]= key;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
491 score_map[index]= d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
492 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
493 /*printf("score:%d\n", d);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
494 COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
495 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
496 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
497
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
498 #define CHECK_CLIPED_MV(ax,ay)\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
499 {\
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
500 const int x= ax;\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
501 const int y= ay;\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
502 const int x2= FFMAX(xmin, FFMIN(x, xmax));\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
503 const int y2= FFMAX(ymin, FFMIN(y, ymax));\
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
504 CHECK_MV(x2, y2)\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
505 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
506
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
507 #define CHECK_MV_DIR(x,y,new_dir)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
508 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
509 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
510 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
511 /*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
512 if(map[index]!=key){\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
513 d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
514 map[index]= key;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
515 score_map[index]= d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
516 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
517 /*printf("score:%d\n", d);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
518 if(d<dmin){\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
519 best[0]=x;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
520 best[1]=y;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
521 dmin=d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
522 next_dir= new_dir;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
523 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
524 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
525 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
526
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
527 #define check(x,y,S,v)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
528 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
529 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
530 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
531 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
532
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
533 #define LOAD_COMMON2\
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
534 uint32_t *map= s->me.map;\
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
535 const int qpel= flags&FLAG_QPEL;\
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
536 const int shift= 1+qpel;\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
537
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
538 static always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
539 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
540 int size, int h, int flags)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
541 {
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
542 me_cmp_func cmpf, chroma_cmpf;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
543 int next_dir=-1;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
544 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
545 LOAD_COMMON2
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
546 int map_generation= s->me.map_generation;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
547
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
548 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
549 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
550
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
551 { /* 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
552 const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
553 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
554 if(map[index]!=key){ //this will be executed only very rarey
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
555 score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
556 map[index]= key;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
557 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
558 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
559
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
560 for(;;){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
561 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
562 const int dir= next_dir;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
563 const int x= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
564 const int y= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
565 next_dir=-1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
566
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
567 //printf("%d", dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
568 if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
569 if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
570 if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
571 if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
572
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
573 if(next_dir==-1){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
574 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
575 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
576 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
577 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
578
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
579 static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
580 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
581 int size, int h, int flags)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
582 {
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
583 me_cmp_func cmpf, chroma_cmpf;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
584 int dia_size;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
585 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
586 LOAD_COMMON2
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
587 int map_generation= s->me.map_generation;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
588
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
589 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
590 chroma_cmpf= s->dsp.me_cmp[size+1];
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
591
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
592 for(dia_size=1; dia_size<=4; dia_size++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
593 int dir;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
594 const int x= best[0];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
595 const int y= best[1];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
596
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
597 if(dia_size&(dia_size-1)) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
598
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
599 if( x + dia_size > xmax
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
600 || x - dia_size < xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
601 || y + dia_size > ymax
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
602 || y - dia_size < ymin)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
603 continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
604
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
605 for(dir= 0; dir<dia_size; dir+=2){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
606 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
607
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
608 CHECK_MV(x + dir , y + dia_size - dir);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
609 CHECK_MV(x + dia_size - dir, y - dir );
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
610 CHECK_MV(x - dir , y - dia_size + dir);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
611 CHECK_MV(x - dia_size + dir, y + dir );
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
612 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
613
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
614 if(x!=best[0] || y!=best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
615 dia_size=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
616 #if 0
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
617 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
618 int dx, dy, i;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
619 static int stats[8*8];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
620 dx= ABS(x-best[0]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
621 dy= ABS(y-best[1]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
622 if(dy>dx){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
623 dx^=dy; dy^=dx; dx^=dy;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
624 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
625 stats[dy*8 + dx] ++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
626 if(256*256*256*64 % (stats[0]+1)==0){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
627 for(i=0; i<64; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
628 if((i&7)==0) printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
629 printf("%8d ", stats[i]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
630 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
631 printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
632 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
633 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
634 #endif
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
635 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
636 return dmin;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
637 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
638
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
639 #define SAB_CHECK_MV(ax,ay)\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
640 {\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
641 const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
642 const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
643 /*printf("sab check %d %d\n", ax, ay);*/\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
644 if(map[index]!=key){\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
645 d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
646 map[index]= key;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
647 score_map[index]= d;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
648 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
649 /*printf("score: %d\n", d);*/\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
650 if(d < minima[minima_count-1].height){\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
651 int j=0;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
652 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
653 while(d >= minima[j].height) j++;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
654 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
655 memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
656 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
657 minima[j].checked= 0;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
658 minima[j].height= d;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
659 minima[j].x= ax;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
660 minima[j].y= ay;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
661 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
662 i=-1;\
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 }\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
666 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
667
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
668 #define MAX_SAB_SIZE 16
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
669 static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
670 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
671 int size, int h, int flags)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
672 {
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
673 me_cmp_func cmpf, chroma_cmpf;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
674 Minima minima[MAX_SAB_SIZE];
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
675 const int minima_count= ABS(s->me.dia_size);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
676 int i, j;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
677 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
678 LOAD_COMMON2
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
679 int map_generation= s->me.map_generation;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
680
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
681 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
682 chroma_cmpf= s->dsp.me_cmp[size+1];
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
683
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
684 for(j=i=0; i<ME_MAP_SIZE; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
685 uint32_t key= map[i];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
686
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
687 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
688
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
689 if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
690
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
691 assert(j<MAX_SAB_SIZE); //max j = number of predictors
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
692
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
693 minima[j].height= score_map[i];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
694 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
695 minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
696 minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
697 minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
698 minima[j].checked=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
699 if(minima[j].x || minima[j].y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
700 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
701
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
702 j++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
703 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
704
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
705 qsort(minima, j, sizeof(Minima), minima_cmp);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
706
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
707 for(; j<minima_count; j++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
708 minima[j].height=256*256*256*64;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
709 minima[j].checked=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
710 minima[j].x= minima[j].y=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
711 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
712
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
713 for(i=0; i<minima_count; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
714 const int x= minima[i].x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
715 const int y= minima[i].y;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
716 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
717
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
718 if(minima[i].checked) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
719
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
720 if( x >= xmax || x <= xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
721 || y >= ymax || y <= ymin)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
722 continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
723
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
724 SAB_CHECK_MV(x-1, y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
725 SAB_CHECK_MV(x+1, y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
726 SAB_CHECK_MV(x , y-1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
727 SAB_CHECK_MV(x , y+1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
728
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
729 minima[i].checked= 1;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
730 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
731
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
732 best[0]= minima[0].x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
733 best[1]= minima[0].y;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
734 dmin= minima[0].height;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
735
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
736 if( best[0] < xmax && best[0] > xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
737 && best[1] < ymax && best[1] > ymin){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
738 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
739 //ensure that the refernece samples for hpel refinement are in the map
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
740 CHECK_MV(best[0]-1, best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
741 CHECK_MV(best[0]+1, best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
742 CHECK_MV(best[0], best[1]-1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
743 CHECK_MV(best[0], best[1]+1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
744 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
745 return dmin;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
746 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
747
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
748 static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
749 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
750 int size, int h, int flags)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
751 {
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
752 me_cmp_func cmpf, chroma_cmpf;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
753 int dia_size;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
754 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
755 LOAD_COMMON2
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
756 int map_generation= s->me.map_generation;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
757
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
758 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
759 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
760
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
761 for(dia_size=1; dia_size<=s->me.dia_size; dia_size++){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
762 int dir, start, end;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
763 const int x= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
764 const int y= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
765
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
766 start= FFMAX(0, y + dia_size - ymax);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
767 end = FFMIN(dia_size, xmax - x + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
768 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
769 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
770
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
771 //check(x + dir,y + dia_size - dir,0, a0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
772 CHECK_MV(x + dir , y + dia_size - dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
773 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
774
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
775 start= FFMAX(0, x + dia_size - xmax);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
776 end = FFMIN(dia_size, y - ymin + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
777 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
778 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
779
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
780 //check(x + dia_size - dir, y - dir,0, a1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
781 CHECK_MV(x + dia_size - dir, y - dir );
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
782 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
783
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
784 start= FFMAX(0, -y + dia_size + ymin );
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
785 end = FFMIN(dia_size, x - xmin + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
786 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
787 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
788
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
789 //check(x - dir,y - dia_size + dir,0, a2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
790 CHECK_MV(x - dir , y - dia_size + dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
791 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
792
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
793 start= FFMAX(0, -x + dia_size + xmin );
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
794 end = FFMIN(dia_size, ymax - y + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
795 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
796 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
797
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
798 //check(x - dia_size + dir, y + dir,0, a3)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
799 CHECK_MV(x - dia_size + dir, y + dir );
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
800 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
801
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
802 if(x!=best[0] || y!=best[1])
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
803 dia_size=0;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
804 #if 0
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
805 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
806 int dx, dy, i;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
807 static int stats[8*8];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
808 dx= ABS(x-best[0]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
809 dy= ABS(y-best[1]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
810 stats[dy*8 + dx] ++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
811 if(256*256*256*64 % (stats[0]+1)==0){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
812 for(i=0; i<64; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
813 if((i&7)==0) printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
814 printf("%6d ", stats[i]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
815 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
816 printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
817 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
818 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
819 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
820 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
821 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
822 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
823
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
824 static always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
825 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
826 int size, int h, int flags){
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
827 if(s->me.dia_size==-1)
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
828 return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
829 else if(s->me.dia_size<-1)
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
830 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
831 else if(s->me.dia_size<2)
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
832 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
833 else
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
834 return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
835 }
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
836
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
837 static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
838 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
839 int ref_mv_scale, int flags)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
840 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
841 int best[2]={0, 0};
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
842 int d, dmin;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
843 int map_generation;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
844 const int penalty_factor= s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
845 const int size=0;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
846 const int h=16;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
847 const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
848 const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
849 me_cmp_func cmpf, chroma_cmpf;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
850
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
851 LOAD_COMMON
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
852 LOAD_COMMON2
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
853
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
854 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
855 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
856
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
857 map_generation= update_map_generation(s);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
858
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
859 dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
860 map[0]= map_generation;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
861 score_map[0]= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
862
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
863 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
864 if (s->first_slice_line) {
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
865 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
866 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
867 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
868 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
869 if(dmin<256 && ( P_LEFT[0] |P_LEFT[1]
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
870 |P_TOP[0] |P_TOP[1]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
871 |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
872 *mx_ptr= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
873 *my_ptr= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
874 s->me.skip=1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
875 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
876 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
877 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
878 if(dmin>256*2){
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
879 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
880 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
881 CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
882 CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
883 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
884 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
885 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
886 if(dmin>256*4){
952
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
887 if(s->me.pre_pass){
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
888 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
889 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
890 if(!s->first_slice_line)
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
891 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
892 (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
893 }else{
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
894 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
895 (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
896 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
897 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
898 (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
899 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
900 }
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
901
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
902 if(s->avctx->last_predictor_count){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
903 const int count= s->avctx->last_predictor_count;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
904 const int xstart= FFMAX(0, s->mb_x - count);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
905 const int ystart= FFMAX(0, s->mb_y - count);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
906 const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
907 const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
908 int mb_y;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
909
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
910 for(mb_y=ystart; mb_y<yend; mb_y++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
911 int mb_x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
912 for(mb_x=xstart; mb_x<xend; mb_x++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
913 const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
914 int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
915 int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
916
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
917 if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
918 CHECK_MV(mx,my)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
919 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
920 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
921 }
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
922
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
923 //check(best[0],best[1],0, b0)
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
924 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
925
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
926 //check(best[0],best[1],0, b1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
927 *mx_ptr= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
928 *my_ptr= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
929
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
930 // printf("%d %d %d \n", best[0], best[1], dmin);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
931 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
932 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
933
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
934 //this function is dedicated to the braindamaged gcc
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
935 static inline int epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
936 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
937 int ref_mv_scale)
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
938 {
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
939 //FIXME convert other functions in the same way if faster
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
940 switch(s->me.flags){
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
941 case 0:
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
942 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0);
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
943 // case FLAG_QPEL:
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
944 // return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
945 default:
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
946 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, s->me.flags);
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
947 }
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
948 }
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
949
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
950 static int epzs_motion_search4(MpegEncContext * s,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
951 int *mx_ptr, int *my_ptr, int P[10][2],
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
952 int src_index, int ref_index, int16_t (*last_mv)[2],
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
953 int ref_mv_scale)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
954 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
955 int best[2]={0, 0};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
956 int d, dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
957 int map_generation;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
958 const int penalty_factor= s->me.penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
959 const int size=1;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
960 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
961 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
962 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
963 me_cmp_func cmpf, chroma_cmpf;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
964 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
965 int flags= s->me.flags;
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
966 LOAD_COMMON2
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
967
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
968 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
969 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
970
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
971 map_generation= update_map_generation(s);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
972
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
973 dmin = 1000000;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
974 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
975 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
976 if (s->first_slice_line) {
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
977 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
978 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
979 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
980 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
981 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
982 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
983 //FIXME try some early stop
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
984 if(dmin>64*2){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
985 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
986 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
987 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
988 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
989 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
990 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
991 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
992 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
993 if(dmin>64*4){
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
994 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
995 (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
996 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
997 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
998 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
999 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1000
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1001 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1002
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1003 *mx_ptr= best[0];
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1004 *my_ptr= best[1];
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1005
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1006 // printf("%d %d %d \n", best[0], best[1], dmin);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1007 return dmin;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1008 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1009
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1010 //try to merge with above FIXME (needs PSNR test)
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1011 static int epzs_motion_search2(MpegEncContext * s,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1012 int *mx_ptr, int *my_ptr, int P[10][2],
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1013 int src_index, int ref_index, int16_t (*last_mv)[2],
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1014 int ref_mv_scale)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1015 {
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1016 int best[2]={0, 0};
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1017 int d, dmin;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1018 int map_generation;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1019 const int penalty_factor= s->me.penalty_factor;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1020 const int size=0; //FIXME pass as arg
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1021 const int h=8;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1022 const int ref_mv_stride= s->mb_stride;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1023 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1024 me_cmp_func cmpf, chroma_cmpf;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1025 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1026 int flags= s->me.flags;
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1027 LOAD_COMMON2
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1028
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1029 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1030 chroma_cmpf= s->dsp.me_cmp[size+1];
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1031
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1032 map_generation= update_map_generation(s);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1033
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1034 dmin = 1000000;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1035 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1036 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1037 if (s->first_slice_line) {
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1038 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1039 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1040 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1041 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1042 }else{
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1043 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1044 //FIXME try some early stop
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1045 if(dmin>64*2){
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1046 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1047 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1048 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1049 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1050 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1051 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1052 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1053 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1054 if(dmin>64*4){
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1055 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
1056 (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
1057 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
1058 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
1059 (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
1060 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1061
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1062 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1063
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1064 *mx_ptr= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1065 *my_ptr= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1066
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1067 // printf("%d %d %d \n", best[0], best[1], dmin);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1068 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1069 }