annotate motion_est.c @ 230:ba9cd6fb6f0e libavcodec

PATCH by Rik Snel <rsnel@cube.dyndns.org> this includes the range for quantized dct coefficients in dct_quantize() (-1023...1023)
author arpi_esp
date Sat, 09 Feb 2002 01:25:06 +0000
parents 9df2d13e64b2
children b640ec5948b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * Motion estimation
986e461dc072 Initial revision
glantau
parents:
diff changeset
3 * Copyright (c) 2000,2001 Gerard Lantau.
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
5 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
986e461dc072 Initial revision
glantau
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
986e461dc072 Initial revision
glantau
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 * (at your option) any later version.
986e461dc072 Initial revision
glantau
parents:
diff changeset
10 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
986e461dc072 Initial revision
glantau
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 * GNU General Public License for more details.
986e461dc072 Initial revision
glantau
parents:
diff changeset
15 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
986e461dc072 Initial revision
glantau
parents:
diff changeset
19 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 #include <stdlib.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 #include <stdio.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 #include "avcodec.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 #include "dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
24 #include "mpegvideo.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
25
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 static void halfpel_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 int *mx_ptr, int *my_ptr, int dmin,
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 int xmin, int ymin, int xmax, int ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
29
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 /* config it to test motion vector encoding (send random vectors) */
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 //#define CONFIG_TEST_MV_ENCODE
986e461dc072 Initial revision
glantau
parents:
diff changeset
32
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 static int pix_sum(UINT8 * pix, int line_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 int s, i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
36
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 s = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 for (i = 0; i < 16; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 for (j = 0; j < 16; j += 8) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 s += pix[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 s += pix[1];
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 s += pix[2];
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 s += pix[3];
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 s += pix[4];
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 s += pix[5];
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 s += pix[6];
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 s += pix[7];
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 pix += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 pix += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 return s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
54
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 static int pix_norm1(UINT8 * pix, int line_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 int s, i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 UINT32 *sq = squareTbl + 256;
986e461dc072 Initial revision
glantau
parents:
diff changeset
59
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 s = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 for (i = 0; i < 16; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
62 for (j = 0; j < 16; j += 8) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 s += sq[pix[0]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 s += sq[pix[1]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 s += sq[pix[2]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 s += sq[pix[3]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 s += sq[pix[4]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
68 s += sq[pix[5]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 s += sq[pix[6]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
70 s += sq[pix[7]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
71 pix += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 pix += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 return s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
77
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 static int pix_norm(UINT8 * pix1, UINT8 * pix2, int line_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 int s, i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 UINT32 *sq = squareTbl + 256;
986e461dc072 Initial revision
glantau
parents:
diff changeset
82
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 s = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 for (i = 0; i < 16; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 for (j = 0; j < 16; j += 8) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 s += sq[pix1[0] - pix2[0]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 s += sq[pix1[1] - pix2[1]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 s += sq[pix1[2] - pix2[2]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 s += sq[pix1[3] - pix2[3]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 s += sq[pix1[4] - pix2[4]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 s += sq[pix1[5] - pix2[5]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 s += sq[pix1[6] - pix2[6]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 s += sq[pix1[7] - pix2[7]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 pix1 += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 pix2 += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 pix1 += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 pix2 += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 return s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
102
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 static void no_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 int *mx_ptr, int *my_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 *mx_ptr = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 *my_ptr = 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
109
986e461dc072 Initial revision
glantau
parents:
diff changeset
110 static int full_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 int *mx_ptr, int *my_ptr, int range,
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 int xmin, int ymin, int xmax, int ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 int x1, y1, x2, y2, xx, yy, x, y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 int mx, my, dmin, d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
116 UINT8 *pix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
117
986e461dc072 Initial revision
glantau
parents:
diff changeset
118 xx = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 yy = 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
120 x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */
986e461dc072 Initial revision
glantau
parents:
diff changeset
121 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
122 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
123 x2 = xx + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
124 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
125 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
126 y1 = yy - range + 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
127 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
128 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
129 y2 = yy + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
130 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
131 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
132 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
133 dmin = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 mx = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
135 my = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
136 for (y = y1; y <= y2; y++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
137 for (x = x1; x <= x2; x++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
138 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x,
986e461dc072 Initial revision
glantau
parents:
diff changeset
139 s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
140 if (d < dmin ||
986e461dc072 Initial revision
glantau
parents:
diff changeset
141 (d == dmin &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
142 (abs(x - xx) + abs(y - yy)) <
986e461dc072 Initial revision
glantau
parents:
diff changeset
143 (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
144 dmin = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
145 mx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
146 my = y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
147 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
148 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
149 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
150
986e461dc072 Initial revision
glantau
parents:
diff changeset
151 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
152 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
153
986e461dc072 Initial revision
glantau
parents:
diff changeset
154 #if 0
986e461dc072 Initial revision
glantau
parents:
diff changeset
155 if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) ||
986e461dc072 Initial revision
glantau
parents:
diff changeset
156 *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
157 fprintf(stderr, "error %d %d\n", *mx_ptr, *my_ptr);
986e461dc072 Initial revision
glantau
parents:
diff changeset
158 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
159 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
160 return dmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
161 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
162
986e461dc072 Initial revision
glantau
parents:
diff changeset
163
986e461dc072 Initial revision
glantau
parents:
diff changeset
164 static int log_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
165 int *mx_ptr, int *my_ptr, int range,
986e461dc072 Initial revision
glantau
parents:
diff changeset
166 int xmin, int ymin, int xmax, int ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
167 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
168 int x1, y1, x2, y2, xx, yy, x, y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
169 int mx, my, dmin, d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
170 UINT8 *pix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
171
986e461dc072 Initial revision
glantau
parents:
diff changeset
172 xx = s->mb_x << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
173 yy = s->mb_y << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
174
986e461dc072 Initial revision
glantau
parents:
diff changeset
175 /* Left limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
176 x1 = xx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
177 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
178 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
179
986e461dc072 Initial revision
glantau
parents:
diff changeset
180 /* Right limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
181 x2 = xx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
182 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
183 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
184
986e461dc072 Initial revision
glantau
parents:
diff changeset
185 /* Upper limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
186 y1 = yy - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
187 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
188 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
189
986e461dc072 Initial revision
glantau
parents:
diff changeset
190 /* Lower limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
191 y2 = yy + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
192 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
193 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
194
986e461dc072 Initial revision
glantau
parents:
diff changeset
195 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
196 dmin = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
197 mx = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
198 my = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
199
986e461dc072 Initial revision
glantau
parents:
diff changeset
200 do {
986e461dc072 Initial revision
glantau
parents:
diff changeset
201 for (y = y1; y <= y2; y += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
202 for (x = x1; x <= x2; x += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
203 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
204 if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
205 dmin = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
206 mx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
207 my = y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
208 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
209 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
210 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
211
986e461dc072 Initial revision
glantau
parents:
diff changeset
212 range = range >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
213
986e461dc072 Initial revision
glantau
parents:
diff changeset
214 x1 = mx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
215 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
216 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
217
986e461dc072 Initial revision
glantau
parents:
diff changeset
218 x2 = mx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
219 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
220 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
221
986e461dc072 Initial revision
glantau
parents:
diff changeset
222 y1 = my - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
223 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
224 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
225
986e461dc072 Initial revision
glantau
parents:
diff changeset
226 y2 = my + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
227 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
228 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
229
986e461dc072 Initial revision
glantau
parents:
diff changeset
230 } while (range >= 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
231
986e461dc072 Initial revision
glantau
parents:
diff changeset
232 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
233 fprintf(stderr, "log - MX: %d\tMY: %d\n", mx, my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
234 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
235 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
236 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
237 return dmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
238 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
239
986e461dc072 Initial revision
glantau
parents:
diff changeset
240 static int phods_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
241 int *mx_ptr, int *my_ptr, int range,
986e461dc072 Initial revision
glantau
parents:
diff changeset
242 int xmin, int ymin, int xmax, int ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
243 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
244 int x1, y1, x2, y2, xx, yy, x, y, lastx, d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
245 int mx, my, dminx, dminy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
246 UINT8 *pix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
247
986e461dc072 Initial revision
glantau
parents:
diff changeset
248 xx = s->mb_x << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
249 yy = s->mb_y << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
250
986e461dc072 Initial revision
glantau
parents:
diff changeset
251 /* Left limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
252 x1 = xx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
253 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
254 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
255
986e461dc072 Initial revision
glantau
parents:
diff changeset
256 /* Right limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
257 x2 = xx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
258 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
259 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
260
986e461dc072 Initial revision
glantau
parents:
diff changeset
261 /* Upper limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
262 y1 = yy - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
263 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
264 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
265
986e461dc072 Initial revision
glantau
parents:
diff changeset
266 /* Lower limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
267 y2 = yy + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
268 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
269 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
270
986e461dc072 Initial revision
glantau
parents:
diff changeset
271 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
272 mx = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
273 my = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
274
986e461dc072 Initial revision
glantau
parents:
diff changeset
275 x = xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
276 y = yy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
277 do {
986e461dc072 Initial revision
glantau
parents:
diff changeset
278 dminx = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
279 dminy = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
280
986e461dc072 Initial revision
glantau
parents:
diff changeset
281 lastx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
282 for (x = x1; x <= x2; x += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
283 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
284 if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
285 dminx = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
286 mx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
287 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
288 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
289
986e461dc072 Initial revision
glantau
parents:
diff changeset
290 x = lastx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
291 for (y = y1; y <= y2; y += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
292 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
293 if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
294 dminy = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
295 my = y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
296 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
297 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
298
986e461dc072 Initial revision
glantau
parents:
diff changeset
299 range = range >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
300
986e461dc072 Initial revision
glantau
parents:
diff changeset
301 x = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
302 y = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
303 x1 = mx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
304 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
305 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
306
986e461dc072 Initial revision
glantau
parents:
diff changeset
307 x2 = mx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
308 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
309 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
310
986e461dc072 Initial revision
glantau
parents:
diff changeset
311 y1 = my - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
312 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
313 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
314
986e461dc072 Initial revision
glantau
parents:
diff changeset
315 y2 = my + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
316 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
317 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
318
986e461dc072 Initial revision
glantau
parents:
diff changeset
319 } while (range >= 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
320
986e461dc072 Initial revision
glantau
parents:
diff changeset
321 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
322 fprintf(stderr, "phods - MX: %d\tMY: %d\n", mx, my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
323 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
324
986e461dc072 Initial revision
glantau
parents:
diff changeset
325 /* half pixel search */
986e461dc072 Initial revision
glantau
parents:
diff changeset
326 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
327 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
328 return dminy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
329 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
330
986e461dc072 Initial revision
glantau
parents:
diff changeset
331 /* The idea would be to make half pel ME after Inter/Intra decision to
986e461dc072 Initial revision
glantau
parents:
diff changeset
332 save time. */
986e461dc072 Initial revision
glantau
parents:
diff changeset
333 static void halfpel_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
334 int *mx_ptr, int *my_ptr, int dmin,
986e461dc072 Initial revision
glantau
parents:
diff changeset
335 int xmin, int ymin, int xmax, int ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
336 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
337 int mx, my, mx1, my1, d, xx, yy, dminh;
986e461dc072 Initial revision
glantau
parents:
diff changeset
338 UINT8 *pix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
339
986e461dc072 Initial revision
glantau
parents:
diff changeset
340 mx = *mx_ptr << 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
341 my = *my_ptr << 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
342
986e461dc072 Initial revision
glantau
parents:
diff changeset
343 xx = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
344 yy = 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
345
986e461dc072 Initial revision
glantau
parents:
diff changeset
346 dminh = dmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
347
986e461dc072 Initial revision
glantau
parents:
diff changeset
348 /* Half pixel search */
986e461dc072 Initial revision
glantau
parents:
diff changeset
349 mx1 = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
350 my1 = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
351
986e461dc072 Initial revision
glantau
parents:
diff changeset
352 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
353
986e461dc072 Initial revision
glantau
parents:
diff changeset
354 if ((mx > (xmin << 1)) && mx < (xmax << 1) &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
355 (my > (ymin << 1)) && my < (ymax << 1)) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
356 int dx, dy, px, py;
986e461dc072 Initial revision
glantau
parents:
diff changeset
357 UINT8 *ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
358 for (dy = -1; dy <= 1; dy++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
359 for (dx = -1; dx <= 1; dx++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
360 if (dx != 0 || dy != 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
361 px = mx1 + dx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
362 py = my1 + dy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
363 ptr = s->last_picture[0] + ((py >> 1) * s->linesize) + (px >> 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
364 switch (((py & 1) << 1) | (px & 1)) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
365 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
366 case 0:
986e461dc072 Initial revision
glantau
parents:
diff changeset
367 d = pix_abs16x16(pix, ptr, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
368 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
369 case 1:
986e461dc072 Initial revision
glantau
parents:
diff changeset
370 d = pix_abs16x16_x2(pix, ptr, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
371 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
372 case 2:
986e461dc072 Initial revision
glantau
parents:
diff changeset
373 d = pix_abs16x16_y2(pix, ptr, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
374 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
375 case 3:
986e461dc072 Initial revision
glantau
parents:
diff changeset
376 d = pix_abs16x16_xy2(pix, ptr, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
377 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
378 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
379 if (d < dminh) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
380 dminh = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
381 mx = px;
986e461dc072 Initial revision
glantau
parents:
diff changeset
382 my = py;
986e461dc072 Initial revision
glantau
parents:
diff changeset
383 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
384 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
385 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
386 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
387 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
388
986e461dc072 Initial revision
glantau
parents:
diff changeset
389 *mx_ptr = mx - (xx << 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
390 *my_ptr = my - (yy << 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
391 //fprintf(stderr,"half - MX: %d\tMY: %d\n",*mx_ptr ,*my_ptr);
986e461dc072 Initial revision
glantau
parents:
diff changeset
392 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
393
986e461dc072 Initial revision
glantau
parents:
diff changeset
394 #ifndef CONFIG_TEST_MV_ENCODE
986e461dc072 Initial revision
glantau
parents:
diff changeset
395
986e461dc072 Initial revision
glantau
parents:
diff changeset
396 int estimate_motion(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
397 int mb_x, int mb_y,
986e461dc072 Initial revision
glantau
parents:
diff changeset
398 int *mx_ptr, int *my_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
399 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
400 UINT8 *pix, *ppix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
401 int sum, varc, vard, mx, my, range, dmin, xx, yy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
402 int xmin, ymin, xmax, ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
403
986e461dc072 Initial revision
glantau
parents:
diff changeset
404 range = 8 * (1 << (s->f_code - 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
405 /* XXX: temporary kludge to avoid overflow for msmpeg4 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
406 if (s->out_format == FMT_H263 && !s->h263_msmpeg4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
407 range = range * 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
408
986e461dc072 Initial revision
glantau
parents:
diff changeset
409 if (s->unrestricted_mv) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
410 xmin = -16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
411 ymin = -16;
218
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
412 if(s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MPEG4){
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
413 xmax = s->mb_width*16;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
414 ymax = s->mb_height*16;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
415 }else {
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
416 /* XXX: dunno if this is correct but ffmpeg4 decoder wont like it otherwise
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
417 (cuz the drawn edge isnt large enough))*/
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
418 xmax = s->width;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
419 ymax = s->height;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
420 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
421 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
422 xmin = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
423 ymin = 0;
218
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
424 xmax = s->mb_width*16 - 16;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
425 ymax = s->mb_height*16 - 16;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
426 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
427
986e461dc072 Initial revision
glantau
parents:
diff changeset
428 switch(s->full_search) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
429 case ME_ZERO:
986e461dc072 Initial revision
glantau
parents:
diff changeset
430 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
431 no_motion_search(s, &mx, &my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
432 dmin = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
433 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
434 case ME_FULL:
986e461dc072 Initial revision
glantau
parents:
diff changeset
435 dmin = full_motion_search(s, &mx, &my, range, xmin, ymin, xmax, ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
436 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
437 case ME_LOG:
986e461dc072 Initial revision
glantau
parents:
diff changeset
438 dmin = log_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
439 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
440 case ME_PHODS:
986e461dc072 Initial revision
glantau
parents:
diff changeset
441 dmin = phods_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
442 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
443 }
6
ec4642daa6fe added emms_c() macro which should can used in c code in both mmx/non mmx cases
glantau
parents: 2
diff changeset
444 emms_c();
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
445
986e461dc072 Initial revision
glantau
parents:
diff changeset
446 /* intra / predictive decision */
986e461dc072 Initial revision
glantau
parents:
diff changeset
447 xx = mb_x * 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
448 yy = mb_y * 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
449
986e461dc072 Initial revision
glantau
parents:
diff changeset
450 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
451 /* At this point (mx,my) are full-pell and the absolute displacement */
986e461dc072 Initial revision
glantau
parents:
diff changeset
452 ppix = s->last_picture[0] + (my * s->linesize) + mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
453
986e461dc072 Initial revision
glantau
parents:
diff changeset
454 sum = pix_sum(pix, s->linesize);
986e461dc072 Initial revision
glantau
parents:
diff changeset
455 varc = pix_norm1(pix, s->linesize);
986e461dc072 Initial revision
glantau
parents:
diff changeset
456 vard = pix_norm(pix, ppix, s->linesize);
986e461dc072 Initial revision
glantau
parents:
diff changeset
457
986e461dc072 Initial revision
glantau
parents:
diff changeset
458 vard = vard >> 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
459 sum = sum >> 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
460 varc = (varc >> 8) - (sum * sum);
986e461dc072 Initial revision
glantau
parents:
diff changeset
461 #if 0
986e461dc072 Initial revision
glantau
parents:
diff changeset
462 printf("varc=%d (sum=%d) vard=%d mx=%d my=%d\n",
986e461dc072 Initial revision
glantau
parents:
diff changeset
463 varc, sum, vard, mx - xx, my - yy);
986e461dc072 Initial revision
glantau
parents:
diff changeset
464 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
465 if (vard <= 64 || vard < varc) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
466 if (s->full_search != ME_ZERO) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
467 halfpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
468 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
469 mx -= 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
470 my -= 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
471 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
472 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
473 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
474 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
475 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
476 *mx_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
477 *my_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
478 return 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
479 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
480 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
481
986e461dc072 Initial revision
glantau
parents:
diff changeset
482 #else
986e461dc072 Initial revision
glantau
parents:
diff changeset
483
986e461dc072 Initial revision
glantau
parents:
diff changeset
484 /* test version which generates valid random vectors */
986e461dc072 Initial revision
glantau
parents:
diff changeset
485 int estimate_motion(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
486 int mb_x, int mb_y,
986e461dc072 Initial revision
glantau
parents:
diff changeset
487 int *mx_ptr, int *my_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
488 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
489 int xx, yy, x1, y1, x2, y2, range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
490
986e461dc072 Initial revision
glantau
parents:
diff changeset
491 if ((random() % 10) >= 5) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
492 range = 8 * (1 << (s->f_code - 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
493 if (s->out_format == FMT_H263 && !s->h263_msmpeg4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
494 range = range * 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
495
986e461dc072 Initial revision
glantau
parents:
diff changeset
496 xx = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
497 yy = 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
498 x1 = xx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
499 if (x1 < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
500 x1 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
501 x2 = xx + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
502 if (x2 > (s->width - 16))
986e461dc072 Initial revision
glantau
parents:
diff changeset
503 x2 = s->width - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
504 y1 = yy - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
505 if (y1 < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
506 y1 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
507 y2 = yy + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
508 if (y2 > (s->height - 16))
986e461dc072 Initial revision
glantau
parents:
diff changeset
509 y2 = s->height - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
510
986e461dc072 Initial revision
glantau
parents:
diff changeset
511 *mx_ptr = (random() % (2 * (x2 - x1 + 1))) + 2 * (x1 - xx);
986e461dc072 Initial revision
glantau
parents:
diff changeset
512 *my_ptr = (random() % (2 * (y2 - y1 + 1))) + 2 * (y1 - yy);
986e461dc072 Initial revision
glantau
parents:
diff changeset
513 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
514 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
515 *mx_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
516 *my_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
517 return 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
518 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
519 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
520
986e461dc072 Initial revision
glantau
parents:
diff changeset
521 #endif