annotate motion_est_template.c @ 12530:63edd10ad4bc libavcodec tip

Try to fix crashes introduced by r25218 r25218 made assumptions about the existence of past reference frames that weren't necessarily true.
author darkshikari
date Tue, 28 Sep 2010 09:06:22 +0000
parents 495b13d86191
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1 /*
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
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 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3293
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3293
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3293
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3293
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3293
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
15 * Lesser General Public License for more details.
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
16 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3293
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
20 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
21
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11573
diff changeset
23 * @file
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
24 * Motion estimation template.
1e39f273ecd6 per file doxy
michaelni
parents: 1013
diff changeset
25 */
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
26
7377
3f819263176e cosmetics: Fix two common typos: wont --> will not, lets --> let us.
diego
parents: 7229
diff changeset
27 //Let us 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
28 #define LOAD_COMMON\
5083
ce36118abbbb rename attribute_unused to av_unused and moves its declaration to common.h
benoit
parents: 4758
diff changeset
29 uint32_t av_unused * const score_map= c->score_map;\
ce36118abbbb rename attribute_unused to av_unused and moves its declaration to common.h
benoit
parents: 4758
diff changeset
30 const int av_unused xmin= c->xmin;\
ce36118abbbb rename attribute_unused to av_unused and moves its declaration to common.h
benoit
parents: 4758
diff changeset
31 const int av_unused ymin= c->ymin;\
ce36118abbbb rename attribute_unused to av_unused and moves its declaration to common.h
benoit
parents: 4758
diff changeset
32 const int av_unused xmax= c->xmax;\
ce36118abbbb rename attribute_unused to av_unused and moves its declaration to common.h
benoit
parents: 4758
diff changeset
33 const int av_unused ymax= c->ymax;\
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
34 uint8_t *mv_penalty= c->current_mv_penalty;\
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
35 const int pred_x= c->pred_x;\
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
36 const int pred_y= c->pred_y;\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
37
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
38 #define CHECK_HALF_MV(dx, dy, x, y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
39 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
40 const int hx= 2*(x)+(dx);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
41 const int hy= 2*(y)+(dy);\
11573
a734f92c94b4 slice dice, inline and outline cmp()
michael
parents: 8718
diff changeset
42 d= cmp_hpel(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
43 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
44 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
45 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
46
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
47 #if 0
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
48 static int hpel_motion_search)(MpegEncContext * s,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
49 int *mx_ptr, int *my_ptr, int dmin,
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
50 uint8_t *ref_data[3],
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
51 int size)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
52 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
53 const int xx = 16 * s->mb_x + 8*(n&1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
54 const int yy = 16 * s->mb_y + 8*(n>>1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
55 const int mx = *mx_ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
56 const int my = *my_ptr;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
57 const int penalty_factor= c->sub_penalty_factor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
58
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
59 LOAD_COMMON
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
60
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
61 // INIT;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
62 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
63 me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
64
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
65 if(s->no_rounding /*FIXME b_type*/){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
66 hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
67 chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
68 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
69 hpel_put=& s->dsp.put_pixels_tab[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
70 chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
71 }
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
72 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
73 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
74 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
75 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
76
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
77 if(c->skip){ //FIXME somehow move up (benchmark)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
78 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
79 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
80 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
81 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
82
2015
3ab8f3e2ae6a moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents: 2014
diff changeset
83 if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
84 CMP_HPEL(dmin, 0, 0, mx, my, size);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
85 if(mx || my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
86 dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
87 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
88
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
89 if (mx > xmin && mx < xmax &&
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
90 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
91 int bx=2*mx, by=2*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
92 int d= dmin;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
93
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
94 CHECK_HALF_MV(1, 1, mx-1, my-1)
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
95 CHECK_HALF_MV(0, 1, mx , my-1)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
96 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
97 CHECK_HALF_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
98 CHECK_HALF_MV(1, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
99 CHECK_HALF_MV(1, 1, mx-1, my )
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
100 CHECK_HALF_MV(0, 1, mx , my )
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
101 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
102
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
103 assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
104
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
105 *mx_ptr = bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
106 *my_ptr = by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
107 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
108 *mx_ptr =2*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
109 *my_ptr =2*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
110 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
111
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
112 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
113 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
114
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
115 #else
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
116 static int hpel_motion_search(MpegEncContext * s,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
117 int *mx_ptr, int *my_ptr, int dmin,
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
118 int src_index, int ref_index,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
119 int size, int h)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
120 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
121 MotionEstContext * const c= &s->me;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
122 const int mx = *mx_ptr;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
123 const int my = *my_ptr;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
124 const int penalty_factor= c->sub_penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
125 me_cmp_func cmp_sub, chroma_cmp_sub;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
126 int bx=2*mx, by=2*my;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
127
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
128 LOAD_COMMON
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
129 int flags= c->sub_flags;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
130
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
131 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
132
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
133 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
134 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
135
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
136 if(c->skip){ //FIXME move out of hpel?
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
137 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
138 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
139 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
140 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
141
2015
3ab8f3e2ae6a moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents: 2014
diff changeset
142 if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
143 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
144 if(mx || my || size>0)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
145 dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
146 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
147
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
148 if (mx > xmin && mx < xmax &&
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
149 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
150 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
151 const int index= (my<<ME_MAP_SHIFT) + mx;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
152 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
153 + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
154 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
155 + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
156 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
157 + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
158 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
159 + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
160
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
161 #if 1
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
162 int key;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
163 int map_generation= c->map_generation;
1419
a7a9df478e46 removed unused variable
bellard
parents: 1266
diff changeset
164 #ifndef NDEBUG
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
165 uint32_t *map= c->map;
1419
a7a9df478e46 removed unused variable
bellard
parents: 1266
diff changeset
166 #endif
948
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+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
170 assert(map[(index+(1<<ME_MAP_SHIFT))&(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 key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
174 assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
175 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
176 if(t<=b){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
177 CHECK_HALF_MV(0, 1, mx ,my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
178 if(l<=r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
179 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
180 if(t+r<=b+l){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
181 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
182 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
183 CHECK_HALF_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
184 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
185 CHECK_HALF_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
186 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
187 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
188 if(t+l<=b+r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
189 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
190 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
191 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
192 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
193 CHECK_HALF_MV(1, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
194 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
195 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
196 if(l<=r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
197 if(t+l<=b+r){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
198 CHECK_HALF_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
199 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
200 CHECK_HALF_MV(1, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
201 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
202 CHECK_HALF_MV(1, 0, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
203 CHECK_HALF_MV(1, 1, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
204 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
205 if(t+r<=b+l){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
206 CHECK_HALF_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
207 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
208 CHECK_HALF_MV(1, 1, mx-1, my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
209 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
210 CHECK_HALF_MV(1, 0, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
211 CHECK_HALF_MV(1, 1, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
212 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
213 CHECK_HALF_MV(0, 1, mx , my)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
214 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
215 assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
216 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
217
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
218 *mx_ptr = bx;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
219 *my_ptr = by;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
220
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
221 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
222 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
223 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
224
2327
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
225 static int no_sub_motion_search(MpegEncContext * s,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
226 int *mx_ptr, int *my_ptr, int dmin,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
227 int src_index, int ref_index,
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
228 int size, int h)
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
229 {
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
230 (*mx_ptr)<<=1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
231 (*my_ptr)<<=1;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
232 return dmin;
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
233 }
5e5cf598a48b H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents: 2226
diff changeset
234
3959
rathann
parents: 3947
diff changeset
235 inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
2189
70b27300a496 quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents: 2184
diff changeset
236 int ref_index, int size, int h, int add_rate)
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
237 {
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
238 // const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
239 MotionEstContext * const c= &s->me;
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
240 const int penalty_factor= c->mb_penalty_factor;
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
241 const int flags= c->mb_flags;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
242 const int qpel= flags & FLAG_QPEL;
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
243 const int mask= 1+2*qpel;
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
244 me_cmp_func cmp_sub, chroma_cmp_sub;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
245 int d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
246
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
247 LOAD_COMMON
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
248
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
249 //FIXME factorize
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
250
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
251 cmp_sub= s->dsp.mb_cmp[size];
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
252 chroma_cmp_sub= s->dsp.mb_cmp[size+1];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
253
2189
70b27300a496 quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents: 2184
diff changeset
254 // assert(!c->skip);
70b27300a496 quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents: 2184
diff changeset
255 // assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
256
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
257 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
258 //FIXME check cbp before adding penalty for (0,0) vector
2189
70b27300a496 quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents: 2184
diff changeset
259 if(add_rate && (mx || my || size>0))
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
260 d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
261
1013
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
262 return d;
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
263 }
5d4c95f323d0 finetuneing thresholds/factors
michaelni
parents: 1011
diff changeset
264
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
265 #define CHECK_QUARTER_MV(dx, dy, x, y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
266 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
267 const int hx= 4*(x)+(dx);\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
268 const int hy= 4*(y)+(dy);\
11573
a734f92c94b4 slice dice, inline and outline cmp()
michael
parents: 8718
diff changeset
269 d= cmp_qpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
270 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
271 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
272 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
273
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
274 static int qpel_motion_search(MpegEncContext * s,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
275 int *mx_ptr, int *my_ptr, int dmin,
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
276 int src_index, int ref_index,
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
277 int size, int h)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
278 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
279 MotionEstContext * const c= &s->me;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
280 const int mx = *mx_ptr;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
281 const int my = *my_ptr;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
282 const int penalty_factor= c->sub_penalty_factor;
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
283 const int map_generation= c->map_generation;
2015
3ab8f3e2ae6a moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents: 2014
diff changeset
284 const int subpel_quality= c->avctx->me_subpel_quality;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
285 uint32_t *map= c->map;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
286 me_cmp_func cmpf, chroma_cmpf;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
287 me_cmp_func cmp_sub, chroma_cmp_sub;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
288
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
289 LOAD_COMMON
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
290 int flags= c->sub_flags;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
291
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
292 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
293 chroma_cmpf= s->dsp.me_cmp[size+1]; //factorize FIXME
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
294 //FIXME factorize
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
295
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
296 cmp_sub= s->dsp.me_sub_cmp[size];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
297 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
298
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
299 if(c->skip){ //FIXME somehow move up (benchmark)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
300 *mx_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
301 *my_ptr = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
302 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
303 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
304
2015
3ab8f3e2ae6a moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents: 2014
diff changeset
305 if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
306 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
307 if(mx || my || size>0)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
308 dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
309 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
310
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
311 if (mx > xmin && mx < xmax &&
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
312 my > ymin && my < ymax) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
313 int bx=4*mx, by=4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
314 int d= dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
315 int i, nx, ny;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
316 const int index= (my<<ME_MAP_SHIFT) + mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
317 const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
318 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
319 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
320 const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
321 const int c= score_map[(index )&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
322 int best[8];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
323 int best_pos[8][2];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
324
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
325 memset(best, 64, sizeof(int)*8);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
326 #if 1
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
327 if(s->me.dia_size>=2){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
328 const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
329 const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
330 const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
331 const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
332
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
333 for(ny= -3; ny <= 3; ny++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
334 for(nx= -3; nx <= 3; nx++){
2079
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
335 //FIXME this could overflow (unlikely though)
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
336 const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
337 const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
338 const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
339 int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
340 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
341
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
342 if((nx&3)==0 && (ny&3)==0) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
343
2079
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
344 score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
345
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
346 // if(nx&1) score-=1024*c->penalty_factor;
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
347 // if(ny&1) score-=1024*c->penalty_factor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
348
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
349 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
350 if(score < best[i]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
351 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
352 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
353 best[i]= score;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
354 best_pos[i][0]= nx + 4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
355 best_pos[i][1]= ny + 4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
356 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
357 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
358 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
359 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
360 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
361 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
362 int tl;
2079
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
363 //FIXME this could overflow (unlikely though)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
364 const int cx = 4*(r - l);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
365 const int cx2= r + l - 2*c;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
366 const int cy = 4*(b - t);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
367 const int cy2= b + t - 2*c;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
368 int cxy;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
369
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
370 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
371 tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
372 }else{
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
373 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
374 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
375
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
376 cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
377
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
378 assert(16*cx2 + 4*cx + 32*c == 32*r);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
379 assert(16*cx2 - 4*cx + 32*c == 32*l);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
380 assert(16*cy2 + 4*cy + 32*c == 32*b);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
381 assert(16*cy2 - 4*cy + 32*c == 32*t);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
382 assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
383
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
384 for(ny= -3; ny <= 3; ny++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
385 for(nx= -3; nx <= 3; nx++){
2079
75aae96e6b54 fewer overflows
michael
parents: 2072
diff changeset
386 //FIXME this could overflow (unlikely though)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
387 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
388 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
389
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
390 if((nx&3)==0 && (ny&3)==0) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
391
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
392 score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
393 // if(nx&1) score-=32*c->penalty_factor;
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
394 // if(ny&1) score-=32*c->penalty_factor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
395
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
396 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
397 if(score < best[i]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
398 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
399 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
400 best[i]= score;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
401 best_pos[i][0]= nx + 4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
402 best_pos[i][1]= ny + 4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
403 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
404 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
405 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
406 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
407 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
408 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
409 for(i=0; i<subpel_quality; i++){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
410 nx= best_pos[i][0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
411 ny= best_pos[i][1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
412 CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
413 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
414
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
415 #if 0
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
416 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
417 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
418 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
419 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
420 // 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
421 if(tl<br){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
422
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
423 // nx= FFMAX(4*mx - bx, bx - 4*mx);
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
424 // ny= FFMAX(4*my - by, by - 4*my);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
425
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
426 static int stats[7][7], count;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
427 count++;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
428 stats[4*mx - bx + 3][4*my - by + 3]++;
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
429 if(256*256*256*64 % count ==0){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
430 for(i=0; i<49; i++){
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
431 if((i%7)==0) printf("\n");
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
432 printf("%6d ", stats[0][i]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
433 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
434 printf("\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
435 }
954
13aec7e50c52 qpel in mmx2/3dnow
michaelni
parents: 952
diff changeset
436 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
437 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
438 #else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
439
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
440 CHECK_QUARTER_MV(2, 2, mx-1, my-1)
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
441 CHECK_QUARTER_MV(0, 2, mx , my-1)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
442 CHECK_QUARTER_MV(2, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
443 CHECK_QUARTER_MV(2, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
444 CHECK_QUARTER_MV(2, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
445 CHECK_QUARTER_MV(0, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
446 CHECK_QUARTER_MV(2, 2, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
447 CHECK_QUARTER_MV(2, 0, mx-1, my )
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
448
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
449 nx= bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
450 ny= by;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
451
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
452 for(i=0; i<8; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
453 int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
454 int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
455 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
456 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
457 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
458 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
459 //outer ring
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
460 CHECK_QUARTER_MV(1, 3, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
461 CHECK_QUARTER_MV(1, 2, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
462 CHECK_QUARTER_MV(1, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
463 CHECK_QUARTER_MV(2, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
464 CHECK_QUARTER_MV(3, 1, mx-1, my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
465 CHECK_QUARTER_MV(0, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
466 CHECK_QUARTER_MV(1, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
467 CHECK_QUARTER_MV(2, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
468 CHECK_QUARTER_MV(3, 1, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
469 CHECK_QUARTER_MV(3, 2, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
470 CHECK_QUARTER_MV(3, 3, mx , my-1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
471 CHECK_QUARTER_MV(3, 0, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
472 CHECK_QUARTER_MV(3, 1, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
473 CHECK_QUARTER_MV(3, 2, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
474 CHECK_QUARTER_MV(3, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
475 CHECK_QUARTER_MV(2, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
476 CHECK_QUARTER_MV(1, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
477 CHECK_QUARTER_MV(0, 3, mx , my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
478 CHECK_QUARTER_MV(3, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
479 CHECK_QUARTER_MV(2, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
480 CHECK_QUARTER_MV(1, 3, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
481 CHECK_QUARTER_MV(1, 2, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
482 CHECK_QUARTER_MV(1, 1, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
483 CHECK_QUARTER_MV(1, 0, mx-1, my )
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
484 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
485 assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
486
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
487 *mx_ptr = bx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
488 *my_ptr = by;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
489 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
490 *mx_ptr =4*mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
491 *my_ptr =4*my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
492 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
493
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
494 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
495 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
496
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
497
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
498 #define CHECK_MV(x,y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
499 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
500 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
501 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
2072
c200977cdf78 clip input motion vectors
michael
parents: 2015
diff changeset
502 assert((x) >= xmin);\
c200977cdf78 clip input motion vectors
michael
parents: 2015
diff changeset
503 assert((x) <= xmax);\
c200977cdf78 clip input motion vectors
michael
parents: 2015
diff changeset
504 assert((y) >= ymin);\
c200977cdf78 clip input motion vectors
michael
parents: 2015
diff changeset
505 assert((y) <= ymax);\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
506 /*printf("check_mv %d %d\n", x, y);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
507 if(map[index]!=key){\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
508 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
509 map[index]= key;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
510 score_map[index]= d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
511 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
512 /*printf("score:%d\n", d);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
513 COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
514 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
515 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
516
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
517 #define CHECK_CLIPPED_MV(ax,ay)\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
518 {\
4248
4be0e20c0eeb cosmetic (prevent name clashes of variables in a macro with surrounding code)
michael
parents: 4246
diff changeset
519 const int Lx= ax;\
4be0e20c0eeb cosmetic (prevent name clashes of variables in a macro with surrounding code)
michael
parents: 4246
diff changeset
520 const int Ly= ay;\
4be0e20c0eeb cosmetic (prevent name clashes of variables in a macro with surrounding code)
michael
parents: 4246
diff changeset
521 const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
4be0e20c0eeb cosmetic (prevent name clashes of variables in a macro with surrounding code)
michael
parents: 4246
diff changeset
522 const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
4be0e20c0eeb cosmetic (prevent name clashes of variables in a macro with surrounding code)
michael
parents: 4246
diff changeset
523 CHECK_MV(Lx2, Ly2)\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
524 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
525
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
526 #define CHECK_MV_DIR(x,y,new_dir)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
527 {\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
528 const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
529 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
530 /*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
531 if(map[index]!=key){\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
532 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
533 map[index]= key;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
534 score_map[index]= d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
535 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
536 /*printf("score:%d\n", d);*/\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
537 if(d<dmin){\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
538 best[0]=x;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
539 best[1]=y;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
540 dmin=d;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
541 next_dir= new_dir;\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
542 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
543 }\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
544 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
545
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
546 #define check(x,y,S,v)\
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
547 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
548 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
549 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
550 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
551
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
552 #define LOAD_COMMON2\
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
553 uint32_t *map= c->map;\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
554 const int qpel= flags&FLAG_QPEL;\
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
555 const int shift= 1+qpel;\
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
556
4283
d6f83e2f8804 rename always_inline to av_always_inline and move to common.h
mru
parents: 4266
diff changeset
557 static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
558 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
559 int size, int h, int flags)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
560 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
561 MotionEstContext * const c= &s->me;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
562 me_cmp_func cmpf, chroma_cmpf;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
563 int next_dir=-1;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
564 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
565 LOAD_COMMON2
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
566 int map_generation= c->map_generation;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
567
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
568 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
569 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
570
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
571 { /* 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
572 const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
573 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
574 if(map[index]!=key){ //this will be executed only very rarey
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
575 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
576 map[index]= key;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
577 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
578 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
579
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
580 for(;;){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
581 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
582 const int dir= next_dir;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
583 const int x= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
584 const int y= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
585 next_dir=-1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
586
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
587 //printf("%d", dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
588 if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
589 if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
590 if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
591 if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
592
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
593 if(next_dir==-1){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
594 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
595 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
596 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
597 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
598
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
599 static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
600 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
601 int size, int h, int flags)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
602 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
603 MotionEstContext * const c= &s->me;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
604 me_cmp_func cmpf, chroma_cmpf;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
605 int dia_size;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
606 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
607 LOAD_COMMON2
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
608 int map_generation= c->map_generation;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
609
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
610 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
611 chroma_cmpf= s->dsp.me_cmp[size+1];
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
612
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
613 for(dia_size=1; dia_size<=4; dia_size++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
614 int dir;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
615 const int x= best[0];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
616 const int y= best[1];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
617
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
618 if(dia_size&(dia_size-1)) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
619
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
620 if( x + dia_size > xmax
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
621 || x - dia_size < xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
622 || y + dia_size > ymax
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
623 || y - dia_size < ymin)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
624 continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
625
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
626 for(dir= 0; dir<dia_size; dir+=2){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
627 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
628
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
629 CHECK_MV(x + dir , y + dia_size - dir);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
630 CHECK_MV(x + dia_size - dir, y - dir );
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
631 CHECK_MV(x - dir , y - dia_size + dir);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
632 CHECK_MV(x - dia_size + dir, y + dir );
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
633 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
634
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
635 if(x!=best[0] || y!=best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
636 dia_size=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
637 #if 0
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
638 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
639 int dx, dy, i;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
640 static int stats[8*8];
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3959
diff changeset
641 dx= FFABS(x-best[0]);
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3959
diff changeset
642 dy= FFABS(y-best[1]);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
643 if(dy>dx){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
644 dx^=dy; dy^=dx; dx^=dy;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
645 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
646 stats[dy*8 + dx] ++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
647 if(256*256*256*64 % (stats[0]+1)==0){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
648 for(i=0; i<64; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
649 if((i&7)==0) printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
650 printf("%8d ", stats[i]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
651 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
652 printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
653 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
654 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
655 #endif
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
656 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
657 return dmin;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
658 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
659
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
660 static int hex_search(MpegEncContext * s, int *best, int dmin,
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
661 int src_index, int ref_index, int const penalty_factor,
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
662 int size, int h, int flags, int dia_size)
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
663 {
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
664 MotionEstContext * const c= &s->me;
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
665 me_cmp_func cmpf, chroma_cmpf;
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
666 LOAD_COMMON
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
667 LOAD_COMMON2
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
668 int map_generation= c->map_generation;
4265
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
669 int x,y,d;
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
670 const int dec= dia_size & (dia_size-1);
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
671
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
672 cmpf= s->dsp.me_cmp[size];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
673 chroma_cmpf= s->dsp.me_cmp[size+1];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
674
4265
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
675 for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
676 do{
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
677 x= best[0];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
678 y= best[1];
4265
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
679
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
680 CHECK_CLIPPED_MV(x -dia_size , y);
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
681 CHECK_CLIPPED_MV(x+ dia_size , y);
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
682 CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
683 CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
684 if(dia_size>1){
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
685 CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
686 CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
687 }
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
688 }while(best[0] != x || best[1] != y);
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
689 }
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
690
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
691 return dmin;
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
692 }
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
693
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
694 static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
695 int src_index, int ref_index, int const penalty_factor,
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
696 int size, int h, int flags)
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
697 {
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
698 MotionEstContext * const c= &s->me;
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
699 me_cmp_func cmpf, chroma_cmpf;
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
700 LOAD_COMMON
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
701 LOAD_COMMON2
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
702 int map_generation= c->map_generation;
4265
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
703 int x,y,i,d;
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
704 int dia_size= c->dia_size&0xFF;
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
705 const int dec= dia_size & (dia_size-1);
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
706 static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
707 { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
708
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
709 cmpf= s->dsp.me_cmp[size];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
710 chroma_cmpf= s->dsp.me_cmp[size+1];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
711
4265
4241e92fb0c7 make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2
michael
parents: 4259
diff changeset
712 for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
713 do{
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
714 x= best[0];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
715 y= best[1];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
716 for(i=0; i<8; i++){
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
717 CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
718 }
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
719 }while(best[0] != x || best[1] != y);
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
720 }
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
721
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
722 x= best[0];
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
723 y= best[1];
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
724 CHECK_CLIPPED_MV(x+1, y);
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
725 CHECK_CLIPPED_MV(x, y+1);
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
726 CHECK_CLIPPED_MV(x-1, y);
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
727 CHECK_CLIPPED_MV(x, y-1);
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
728
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
729 return dmin;
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
730 }
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
731
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
732 static int umh_search(MpegEncContext * s, int *best, int dmin,
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
733 int src_index, int ref_index, int const penalty_factor,
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
734 int size, int h, int flags)
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
735 {
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
736 MotionEstContext * const c= &s->me;
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
737 me_cmp_func cmpf, chroma_cmpf;
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
738 LOAD_COMMON
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
739 LOAD_COMMON2
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
740 int map_generation= c->map_generation;
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
741 int x,y,x2,y2, i, j, d;
4256
b3e17d30dde2 dia_size=-1 -> funny_diamond_search()
michael
parents: 4255
diff changeset
742 const int dia_size= c->dia_size&0xFE;
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
743 static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
744 { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
745 {-2, 3}, { 0, 4}, { 2, 3},
4250
507ba4483ffc typo in umh
michael
parents: 4249
diff changeset
746 {-2,-3}, { 0,-4}, { 2,-3},};
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
747
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
748 cmpf= s->dsp.me_cmp[size];
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
749 chroma_cmpf= s->dsp.me_cmp[size+1];
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
750
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
751 x= best[0];
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
752 y= best[1];
4256
b3e17d30dde2 dia_size=-1 -> funny_diamond_search()
michael
parents: 4255
diff changeset
753 for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
754 CHECK_MV(x2, y);
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
755 }
4256
b3e17d30dde2 dia_size=-1 -> funny_diamond_search()
michael
parents: 4255
diff changeset
756 for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
757 CHECK_MV(x, y2);
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
758 }
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
759
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
760 x= best[0];
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
761 y= best[1];
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
762 for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
763 for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
764 CHECK_MV(x2, y2);
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
765 }
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
766 }
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
767
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
768 //FIXME prevent the CLIP stuff
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
769
4256
b3e17d30dde2 dia_size=-1 -> funny_diamond_search()
michael
parents: 4255
diff changeset
770 for(j=1; j<=dia_size/4; j++){
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
771 for(i=0; i<16; i++){
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
772 CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
773 }
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
774 }
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
775
4266
8a50de4eafca 10l umh search needs hex size 2 now after the last change
michael
parents: 4265
diff changeset
776 return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);
4249
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
777 }
17e04bdf8d69 UMH support (dia_size=-1 activates it)
michael
parents: 4248
diff changeset
778
7229
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
779 static int full_search(MpegEncContext * s, int *best, int dmin,
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
780 int src_index, int ref_index, int const penalty_factor,
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
781 int size, int h, int flags)
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
782 {
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
783 MotionEstContext * const c= &s->me;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
784 me_cmp_func cmpf, chroma_cmpf;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
785 LOAD_COMMON
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
786 LOAD_COMMON2
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
787 int map_generation= c->map_generation;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
788 int x,y, d;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
789 const int dia_size= c->dia_size&0xFF;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
790
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
791 cmpf= s->dsp.me_cmp[size];
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
792 chroma_cmpf= s->dsp.me_cmp[size+1];
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
793
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
794 for(y=FFMAX(-dia_size, ymin); y<=FFMIN(dia_size,ymax); y++){
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
795 for(x=FFMAX(-dia_size, xmin); x<=FFMIN(dia_size,xmax); x++){
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
796 CHECK_MV(x, y);
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
797 }
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
798 }
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
799
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
800 x= best[0];
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
801 y= best[1];
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
802 d= dmin;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
803 CHECK_CLIPPED_MV(x , y);
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
804 CHECK_CLIPPED_MV(x+1, y);
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
805 CHECK_CLIPPED_MV(x, y+1);
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
806 CHECK_CLIPPED_MV(x-1, y);
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
807 CHECK_CLIPPED_MV(x, y-1);
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
808 best[0]= x;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
809 best[1]= y;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
810
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
811 return d;
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
812 }
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
813
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
814 #define SAB_CHECK_MV(ax,ay)\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
815 {\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
816 const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
817 const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
818 /*printf("sab check %d %d\n", ax, ay);*/\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
819 if(map[index]!=key){\
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
820 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
821 map[index]= key;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
822 score_map[index]= d;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
823 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
824 /*printf("score: %d\n", d);*/\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
825 if(d < minima[minima_count-1].height){\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
826 int j=0;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
827 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
828 while(d >= minima[j].height) j++;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
829 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
830 memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
831 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
832 minima[j].checked= 0;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
833 minima[j].height= d;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
834 minima[j].x= ax;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
835 minima[j].y= ay;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
836 \
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
837 i=-1;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
838 continue;\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
839 }\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
840 }\
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
841 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
842
2113
07a663d46be2 shape-adaptive diamond + prediction crash patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents: 2079
diff changeset
843 #define MAX_SAB_SIZE ME_MAP_SIZE
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
844 static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
845 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
846 int size, int h, int flags)
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
847 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
848 MotionEstContext * const c= &s->me;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
849 me_cmp_func cmpf, chroma_cmpf;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
850 Minima minima[MAX_SAB_SIZE];
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3959
diff changeset
851 const int minima_count= FFABS(c->dia_size);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
852 int i, j;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
853 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
854 LOAD_COMMON2
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
855 int map_generation= c->map_generation;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
856
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
857 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
858 chroma_cmpf= s->dsp.me_cmp[size+1];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
859
4298
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
860 /*Note j<MAX_SAB_SIZE is needed if MAX_SAB_SIZE < ME_MAP_SIZE as j can
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
861 become larger due to MVs overflowing their ME_MAP_MV_BITS bits space in map
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
862 */
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
863 for(j=i=0; i<ME_MAP_SIZE && j<MAX_SAB_SIZE; i++){
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
864 uint32_t key= map[i];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
865
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
866 key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
867
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
868 if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
869
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
870 minima[j].height= score_map[i];
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
871 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
872 minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
873 minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
874 minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
4298
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
875
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
876 // all entries in map should be in range except if the mv overflows their ME_MAP_MV_BITS bits space
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
877 if( minima[j].x > xmax || minima[j].x < xmin
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
878 || minima[j].y > ymax || minima[j].y < ymin)
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
879 continue;
bba6e75e026b mv overflow in map fix (untested except regression tests)
michael
parents: 4283
diff changeset
880
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
881 minima[j].checked=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
882 if(minima[j].x || minima[j].y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
883 minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
884
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
885 j++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
886 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
887
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
888 qsort(minima, j, sizeof(Minima), minima_cmp);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
889
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
890 for(; j<minima_count; j++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
891 minima[j].height=256*256*256*64;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
892 minima[j].checked=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
893 minima[j].x= minima[j].y=0;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
894 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
895
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
896 for(i=0; i<minima_count; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
897 const int x= minima[i].x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
898 const int y= minima[i].y;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
899 int d;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
900
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
901 if(minima[i].checked) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
902
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
903 if( x >= xmax || x <= xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
904 || y >= ymax || y <= ymin)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
905 continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
906
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
907 SAB_CHECK_MV(x-1, y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
908 SAB_CHECK_MV(x+1, y)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
909 SAB_CHECK_MV(x , y-1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
910 SAB_CHECK_MV(x , y+1)
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
911
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
912 minima[i].checked= 1;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
913 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
914
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
915 best[0]= minima[0].x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
916 best[1]= minima[0].y;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
917 dmin= minima[0].height;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
918
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
919 if( best[0] < xmax && best[0] > xmin
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
920 && best[1] < ymax && best[1] > ymin){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
921 int d;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
922 //ensure that the refernece samples for hpel refinement are in the map
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
923 CHECK_MV(best[0]-1, best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
924 CHECK_MV(best[0]+1, best[1])
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
925 CHECK_MV(best[0], best[1]-1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
926 CHECK_MV(best[0], best[1]+1)
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
927 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
928 return dmin;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
929 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
930
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
931 static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
932 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
933 int size, int h, int flags)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
934 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
935 MotionEstContext * const c= &s->me;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
936 me_cmp_func cmpf, chroma_cmpf;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
937 int dia_size;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
938 LOAD_COMMON
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
939 LOAD_COMMON2
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
940 int map_generation= c->map_generation;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
941
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
942 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
943 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
944
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
945 for(dia_size=1; dia_size<=c->dia_size; dia_size++){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
946 int dir, start, end;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
947 const int x= best[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
948 const int y= best[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
949
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
950 start= FFMAX(0, y + dia_size - ymax);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
951 end = FFMIN(dia_size, xmax - x + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
952 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
953 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
954
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
955 //check(x + dir,y + dia_size - dir,0, a0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
956 CHECK_MV(x + dir , y + dia_size - dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
957 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
958
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
959 start= FFMAX(0, x + dia_size - xmax);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
960 end = FFMIN(dia_size, y - ymin + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
961 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
962 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
963
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
964 //check(x + dia_size - dir, y - dir,0, a1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
965 CHECK_MV(x + dia_size - dir, y - dir );
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
966 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
967
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
968 start= FFMAX(0, -y + dia_size + ymin );
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
969 end = FFMIN(dia_size, x - xmin + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
970 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
971 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
972
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
973 //check(x - dir,y - dia_size + dir,0, a2)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
974 CHECK_MV(x - dir , y - dia_size + dir);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
975 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
976
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
977 start= FFMAX(0, -x + dia_size + xmin );
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
978 end = FFMIN(dia_size, ymax - y + 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
979 for(dir= start; dir<end; dir++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
980 int d;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
981
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
982 //check(x - dia_size + dir, y + dir,0, a3)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
983 CHECK_MV(x - dia_size + dir, y + dir );
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
984 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
985
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
986 if(x!=best[0] || y!=best[1])
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
987 dia_size=0;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
988 #if 0
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
989 {
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
990 int dx, dy, i;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
991 static int stats[8*8];
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3959
diff changeset
992 dx= FFABS(x-best[0]);
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3959
diff changeset
993 dy= FFABS(y-best[1]);
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
994 stats[dy*8 + dx] ++;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
995 if(256*256*256*64 % (stats[0]+1)==0){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
996 for(i=0; i<64; i++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
997 if((i&7)==0) printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
998 printf("%6d ", stats[i]);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
999 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1000 printf("\n");
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1001 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1002 }
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1003 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1004 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1005 return dmin;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1006 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1007
4283
d6f83e2f8804 rename always_inline to av_always_inline and move to common.h
mru
parents: 4266
diff changeset
1008 static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1009 int src_index, int ref_index, int const penalty_factor,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1010 int size, int h, int flags){
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1011 MotionEstContext * const c= &s->me;
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1012 if(c->dia_size==-1)
4256
b3e17d30dde2 dia_size=-1 -> funny_diamond_search()
michael
parents: 4255
diff changeset
1013 return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1014 else if(c->dia_size<-1)
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1015 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1016 else if(c->dia_size<2)
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1017 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
7229
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
1018 else if(c->dia_size>1024)
f03d29b6fefe New full search ME
michael
parents: 6481
diff changeset
1019 return full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
4256
b3e17d30dde2 dia_size=-1 -> funny_diamond_search()
michael
parents: 4255
diff changeset
1020 else if(c->dia_size>768)
b3e17d30dde2 dia_size=-1 -> funny_diamond_search()
michael
parents: 4255
diff changeset
1021 return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
4255
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
1022 else if(c->dia_size>512)
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
1023 return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
1024 else if(c->dia_size>256)
f775fd9f3b05 hexagon search
michael
parents: 4253
diff changeset
1025 return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1026 else
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1027 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
1028 }
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1029
4757
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1030 /*!
12113
495b13d86191 Restore array sizes in doxygen parameter names.
diego
parents: 12062
diff changeset
1031 \param P[10][2] a list of candidate mvs to check before starting the
4757
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1032 iterative search. If one of the candidates is close to the optimal mv, then
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1033 it takes fewer iterations. And it increases the chance that we find the
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1034 optimal mv.
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1035 */
4283
d6f83e2f8804 rename always_inline to av_always_inline and move to common.h
mru
parents: 4266
diff changeset
1036 static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1037 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
2184
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1038 int ref_mv_scale, int flags, int size, int h)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1039 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1040 MotionEstContext * const c= &s->me;
4757
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1041 int best[2]={0, 0}; /*!< x and y coordinates of the best motion vector.
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1042 i.e. the difference between the position of the
4758
efeca638ad20 doxy comment tweaks
lorenm
parents: 4757
diff changeset
1043 block currently being encoded and the position of
4757
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1044 the block chosen to predict it from. */
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1045 int d; ///< the score (cmp + penalty) of any given mv
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1046 int dmin; /*!< the best value of d, i.e. the score
e511820c4a97 Add doxy comments, based on Loren's explanations posted here:
gpoirier
parents: 4326
diff changeset
1047 corresponding to the mv stored in best[]. */
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1048 int map_generation;
2226
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1049 int penalty_factor;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1050 const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1051 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
1052 me_cmp_func cmpf, chroma_cmpf;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1053
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1054 LOAD_COMMON
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1055 LOAD_COMMON2
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1056
2226
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1057 if(c->pre_pass){
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1058 penalty_factor= c->pre_penalty_factor;
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1059 cmpf= s->dsp.me_pre_cmp[size];
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1060 chroma_cmpf= s->dsp.me_pre_cmp[size+1];
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1061 }else{
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1062 penalty_factor= c->penalty_factor;
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1063 cmpf= s->dsp.me_cmp[size];
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1064 chroma_cmpf= s->dsp.me_cmp[size+1];
4306aa6f8f16 pre_cmp fix
michael
parents: 2189
diff changeset
1065 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1066
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1067 map_generation= update_map_generation(c);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1068
2184
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1069 assert(cmpf);
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1070 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
1071 map[0]= map_generation;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1072 score_map[0]= dmin;
4313
13c897abcab3 fix special casing of the 0,0 MV for b frames (slight PSNR/bitrate gain)
michael
parents: 4312
diff changeset
1073
13c897abcab3 fix special casing of the 0,0 MV for b frames (slight PSNR/bitrate gain)
michael
parents: 4312
diff changeset
1074 //FIXME precalc first term below?
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 5215
diff changeset
1075 if((s->pict_type == FF_B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)
4312
eb0ae1ce40a5 dont favor the zero MV if mv0 is used (psnr per bitrate gains ranging from 0 to 0.14, most are <=0.04 though)
michael
parents: 4298
diff changeset
1076 dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1077
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1078 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1079 if (s->first_slice_line) {
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1080 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1081 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1082 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1083 }else{
3293
f1bcb9ae510b make zero motion vector threshold user setable
michael
parents: 3036
diff changeset
1084 if(dmin<((h*h*s->avctx->mv0_threshold)>>8)
f1bcb9ae510b make zero motion vector threshold user setable
michael
parents: 3036
diff changeset
1085 && ( P_LEFT[0] |P_LEFT[1]
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1086 |P_TOP[0] |P_TOP[1]
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1087 |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1088 *mx_ptr= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1089 *my_ptr= 0;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1090 c->skip=1;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1091 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1092 }
4246
a579dae361e2 1 step diamond search around the median MV predictor
michael
parents: 4001
diff changeset
1093 CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1094 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1095 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1096 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1097 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1098 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
4257
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1099 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1100 CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1101 CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1102 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1103 }
2184
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1104 if(dmin>h*h*4){
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1105 if(c->pre_pass){
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1106 CHECK_CLIPPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
952
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
1107 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1108 if(!s->first_slice_line)
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1109 CHECK_CLIPPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1110 (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
1111 }else{
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1112 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
952
f348d302a51e pre motion estimation cleanup/bugfix
michaelni
parents: 948
diff changeset
1113 (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
1114 if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1115 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1116 (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
1117 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1118 }
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1119
2015
3ab8f3e2ae6a moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents: 2014
diff changeset
1120 if(c->avctx->last_predictor_count){
3ab8f3e2ae6a moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents: 2014
diff changeset
1121 const int count= c->avctx->last_predictor_count;
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1122 const int xstart= FFMAX(0, s->mb_x - count);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1123 const int ystart= FFMAX(0, s->mb_y - count);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1124 const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1125 const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1126 int mb_y;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1127
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1128 for(mb_y=ystart; mb_y<yend; mb_y++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1129 int mb_x;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1130 for(mb_x=xstart; mb_x<xend; mb_x++){
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1131 const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1132 int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1133 int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1134
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1135 if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1136 CHECK_MV(mx,my)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1137 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1138 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1139 }
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1140
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1141 //check(best[0],best[1],0, b0)
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1142 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1143
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1144 //check(best[0],best[1],0, b1)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1145 *mx_ptr= best[0];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1146 *my_ptr= best[1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1147
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1148 // printf("%d %d %d \n", best[0], best[1], dmin);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1149 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1150 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1151
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1152 //this function is dedicated to the braindamaged gcc
2184
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1153 inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1154 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
2184
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1155 int ref_mv_scale, int size, int h)
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1156 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1157 MotionEstContext * const c= &s->me;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1158 //FIXME convert other functions in the same way if faster
2184
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1159 if(c->flags==0 && h==16 && size==0){
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1160 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1161 // case FLAG_QPEL:
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1162 // return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
2184
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1163 }else{
3378d0677903 4x4 SSE compare function
michael
parents: 2113
diff changeset
1164 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1165 }
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1166 }
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1167
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1168 static int epzs_motion_search4(MpegEncContext * s,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1169 int *mx_ptr, int *my_ptr, int P[10][2],
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1170 int src_index, int ref_index, int16_t (*last_mv)[2],
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1171 int ref_mv_scale)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1172 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1173 MotionEstContext * const c= &s->me;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1174 int best[2]={0, 0};
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1175 int d, dmin;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1176 int map_generation;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1177 const int penalty_factor= c->penalty_factor;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1178 const int size=1;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1179 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
1180 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
1181 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1182 me_cmp_func cmpf, chroma_cmpf;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1183 LOAD_COMMON
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1184 int flags= c->flags;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1185 LOAD_COMMON2
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1186
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1187 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1188 chroma_cmpf= s->dsp.me_cmp[size+1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1189
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1190 map_generation= update_map_generation(c);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1191
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1192 dmin = 1000000;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1193 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1194 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1195 if (s->first_slice_line) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
1196 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1197 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1198 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1199 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1200 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1201 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1202 //FIXME try some early stop
4257
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1203 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1204 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1205 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1206 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1207 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
4257
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1208 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1209 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1210 if(dmin>64*4){
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1211 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
948
371bc36a9c5c shape adaptive diamonds for EPZS
michaelni
parents: 936
diff changeset
1212 (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
1213 if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1214 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1215 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1216 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1217
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1218 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
1219
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1220 *mx_ptr= best[0];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1221 *my_ptr= best[1];
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1222
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1223 // printf("%d %d %d \n", best[0], best[1], dmin);
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1224 return dmin;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1225 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1226
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1227 //try to merge with above FIXME (needs PSNR test)
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1228 static int epzs_motion_search2(MpegEncContext * s,
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1229 int *mx_ptr, int *my_ptr, int P[10][2],
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1230 int src_index, int ref_index, int16_t (*last_mv)[2],
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1231 int ref_mv_scale)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1232 {
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1233 MotionEstContext * const c= &s->me;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1234 int best[2]={0, 0};
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1235 int d, dmin;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1236 int map_generation;
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1237 const int penalty_factor= c->penalty_factor;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1238 const int size=0; //FIXME pass as arg
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1239 const int h=8;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1240 const int ref_mv_stride= s->mb_stride;
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1241 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1242 me_cmp_func cmpf, chroma_cmpf;
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1243 LOAD_COMMON
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1244 int flags= c->flags;
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1245 LOAD_COMMON2
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1246
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1247 cmpf= s->dsp.me_cmp[size];
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1248 chroma_cmpf= s->dsp.me_cmp[size+1];
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1249
2014
15c885db82a8 reduce dependancy between motion estimation and MpegEncContext
michael
parents: 1950
diff changeset
1250 map_generation= update_map_generation(c);
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1251
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1252 dmin = 1000000;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1253 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1254 /* first line */
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1255 if (s->first_slice_line) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
1256 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1257 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1258 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1259 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1260 }else{
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1261 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1262 //FIXME try some early stop
4257
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1263 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1264 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1265 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1266 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1267 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
4257
ac98478e056d fix indention
michael
parents: 4256
diff changeset
1268 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1269 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1270 if(dmin>64*4){
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1271 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1272 (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
1273 if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
4259
9b74144471c5 spelling cosmetics: cliped --> clipped
diego
parents: 4257
diff changeset
1274 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1739
diff changeset
1275 (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
1276 }
dea5b2946999 interlaced motion estimation
michael
parents: 1419
diff changeset
1277
1950
a3c60fa850dc motion estimation cleanup
michael
parents: 1800
diff changeset
1278 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
1279
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1280 *mx_ptr= best[0];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
1281 *my_ptr= best[1];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1282
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1283 // printf("%d %d %d \n", best[0], best[1], dmin);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1284 return dmin;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1285 }