0
|
1 /*
|
|
2 * High quality image resampling with polyphase filters
|
|
3 * Copyright (c) 2001 Gerard Lantau.
|
|
4 *
|
|
5 * This program is free software; you can redistribute it and/or modify
|
|
6 * it under the terms of the GNU General Public License as published by
|
|
7 * the Free Software Foundation; either version 2 of the License, or
|
|
8 * (at your option) any later version.
|
|
9 *
|
|
10 * This program is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 * GNU General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License
|
|
16 * along with this program; if not, write to the Free Software
|
|
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
18 */
|
|
19 #include <stdlib.h>
|
|
20 #include <stdio.h>
|
|
21 #include <string.h>
|
|
22 #include <math.h>
|
|
23 #include "dsputil.h"
|
|
24 #include "avcodec.h"
|
|
25
|
17
|
26 /* Stuff below is useful only for mplayer project */
|
|
27 #ifdef HAVE_CONFIG_H
|
|
28 #include "../config.h"
|
|
29 #endif
|
|
30
|
|
31 #ifdef USE_FASTMEMCPY
|
|
32 #include "fastmemcpy.h"
|
|
33 #endif
|
|
34
|
|
35
|
0
|
36 #define NB_COMPONENTS 3
|
|
37
|
|
38 #define PHASE_BITS 4
|
|
39 #define NB_PHASES (1 << PHASE_BITS)
|
|
40 #define NB_TAPS 4
|
|
41 #define FCENTER 1 /* index of the center of the filter */
|
|
42
|
|
43 #define POS_FRAC_BITS 16
|
|
44 #define POS_FRAC (1 << POS_FRAC_BITS)
|
|
45 /* 6 bits precision is needed for MMX */
|
|
46 #define FILTER_BITS 8
|
|
47
|
|
48 #define LINE_BUF_HEIGHT (NB_TAPS * 4)
|
|
49
|
|
50 struct ImgReSampleContext {
|
|
51 int iwidth, iheight, owidth, oheight;
|
|
52 int h_incr, v_incr;
|
|
53 INT16 h_filters[NB_PHASES][NB_TAPS] __align8; /* horizontal filters */
|
|
54 INT16 v_filters[NB_PHASES][NB_TAPS] __align8; /* vertical filters */
|
|
55 UINT8 *line_buf;
|
|
56 };
|
|
57
|
|
58 static inline int get_phase(int pos)
|
|
59 {
|
|
60 return ((pos) >> (POS_FRAC_BITS - PHASE_BITS)) & ((1 << PHASE_BITS) - 1);
|
|
61 }
|
|
62
|
|
63 /* This function must be optimized */
|
|
64 static void h_resample_fast(UINT8 *dst, int dst_width, UINT8 *src, int src_width,
|
|
65 int src_start, int src_incr, INT16 *filters)
|
|
66 {
|
|
67 int src_pos, phase, sum, i;
|
|
68 UINT8 *s;
|
|
69 INT16 *filter;
|
|
70
|
|
71 src_pos = src_start;
|
|
72 for(i=0;i<dst_width;i++) {
|
|
73 #ifdef TEST
|
|
74 /* test */
|
|
75 if ((src_pos >> POS_FRAC_BITS) < 0 ||
|
|
76 (src_pos >> POS_FRAC_BITS) > (src_width - NB_TAPS))
|
|
77 abort();
|
|
78 #endif
|
|
79 s = src + (src_pos >> POS_FRAC_BITS);
|
|
80 phase = get_phase(src_pos);
|
|
81 filter = filters + phase * NB_TAPS;
|
|
82 #if NB_TAPS == 4
|
|
83 sum = s[0] * filter[0] +
|
|
84 s[1] * filter[1] +
|
|
85 s[2] * filter[2] +
|
|
86 s[3] * filter[3];
|
|
87 #else
|
|
88 {
|
|
89 int j;
|
|
90 sum = 0;
|
|
91 for(j=0;j<NB_TAPS;j++)
|
|
92 sum += s[j] * filter[j];
|
|
93 }
|
|
94 #endif
|
|
95 sum = sum >> FILTER_BITS;
|
|
96 if (sum < 0)
|
|
97 sum = 0;
|
|
98 else if (sum > 255)
|
|
99 sum = 255;
|
|
100 dst[0] = sum;
|
|
101 src_pos += src_incr;
|
|
102 dst++;
|
|
103 }
|
|
104 }
|
|
105
|
|
106 /* This function must be optimized */
|
|
107 static void v_resample(UINT8 *dst, int dst_width, UINT8 *src, int wrap,
|
|
108 INT16 *filter)
|
|
109 {
|
|
110 int sum, i;
|
|
111 UINT8 *s;
|
|
112
|
|
113 s = src;
|
|
114 for(i=0;i<dst_width;i++) {
|
|
115 #if NB_TAPS == 4
|
|
116 sum = s[0 * wrap] * filter[0] +
|
|
117 s[1 * wrap] * filter[1] +
|
|
118 s[2 * wrap] * filter[2] +
|
|
119 s[3 * wrap] * filter[3];
|
|
120 #else
|
|
121 {
|
|
122 int j;
|
|
123 UINT8 *s1 = s;
|
|
124
|
|
125 sum = 0;
|
|
126 for(j=0;j<NB_TAPS;j++) {
|
|
127 sum += s1[0] * filter[j];
|
|
128 s1 += wrap;
|
|
129 }
|
|
130 }
|
|
131 #endif
|
|
132 sum = sum >> FILTER_BITS;
|
|
133 if (sum < 0)
|
|
134 sum = 0;
|
|
135 else if (sum > 255)
|
|
136 sum = 255;
|
|
137 dst[0] = sum;
|
|
138 dst++;
|
|
139 s++;
|
|
140 }
|
|
141 }
|
|
142
|
2
|
143 #ifdef HAVE_MMX
|
0
|
144
|
|
145 #include "i386/mmx.h"
|
|
146
|
|
147 #define FILTER4(reg) \
|
|
148 {\
|
|
149 s = src + (src_pos >> POS_FRAC_BITS);\
|
|
150 phase = get_phase(src_pos);\
|
|
151 filter = filters + phase * NB_TAPS;\
|
|
152 movq_m2r(*s, reg);\
|
|
153 punpcklbw_r2r(mm7, reg);\
|
|
154 movq_m2r(*filter, mm6);\
|
|
155 pmaddwd_r2r(reg, mm6);\
|
|
156 movq_r2r(mm6, reg);\
|
|
157 psrlq_i2r(32, reg);\
|
|
158 paddd_r2r(mm6, reg);\
|
|
159 psrad_i2r(FILTER_BITS, reg);\
|
|
160 src_pos += src_incr;\
|
|
161 }
|
|
162
|
|
163 #define DUMP(reg) movq_r2m(reg, tmp); printf(#reg "=%016Lx\n", tmp.uq);
|
|
164
|
|
165 /* XXX: do four pixels at a time */
|
|
166 static void h_resample_fast4_mmx(UINT8 *dst, int dst_width, UINT8 *src, int src_width,
|
|
167 int src_start, int src_incr, INT16 *filters)
|
|
168 {
|
|
169 int src_pos, phase;
|
|
170 UINT8 *s;
|
|
171 INT16 *filter;
|
|
172 mmx_t tmp;
|
|
173
|
|
174 src_pos = src_start;
|
|
175 pxor_r2r(mm7, mm7);
|
|
176
|
|
177 while (dst_width >= 4) {
|
|
178
|
|
179 FILTER4(mm0);
|
|
180 FILTER4(mm1);
|
|
181 FILTER4(mm2);
|
|
182 FILTER4(mm3);
|
|
183
|
|
184 packuswb_r2r(mm7, mm0);
|
|
185 packuswb_r2r(mm7, mm1);
|
|
186 packuswb_r2r(mm7, mm3);
|
|
187 packuswb_r2r(mm7, mm2);
|
|
188 movq_r2m(mm0, tmp);
|
|
189 dst[0] = tmp.ub[0];
|
|
190 movq_r2m(mm1, tmp);
|
|
191 dst[1] = tmp.ub[0];
|
|
192 movq_r2m(mm2, tmp);
|
|
193 dst[2] = tmp.ub[0];
|
|
194 movq_r2m(mm3, tmp);
|
|
195 dst[3] = tmp.ub[0];
|
|
196 dst += 4;
|
|
197 dst_width -= 4;
|
|
198 }
|
|
199 while (dst_width > 0) {
|
|
200 FILTER4(mm0);
|
|
201 packuswb_r2r(mm7, mm0);
|
|
202 movq_r2m(mm0, tmp);
|
|
203 dst[0] = tmp.ub[0];
|
|
204 dst++;
|
|
205 dst_width--;
|
|
206 }
|
|
207 emms();
|
|
208 }
|
|
209
|
|
210 static void v_resample4_mmx(UINT8 *dst, int dst_width, UINT8 *src, int wrap,
|
|
211 INT16 *filter)
|
|
212 {
|
|
213 int sum, i, v;
|
|
214 UINT8 *s;
|
|
215 mmx_t tmp;
|
|
216 mmx_t coefs[4];
|
|
217
|
|
218 for(i=0;i<4;i++) {
|
|
219 v = filter[i];
|
|
220 coefs[i].uw[0] = v;
|
|
221 coefs[i].uw[1] = v;
|
|
222 coefs[i].uw[2] = v;
|
|
223 coefs[i].uw[3] = v;
|
|
224 }
|
|
225
|
|
226 pxor_r2r(mm7, mm7);
|
|
227 s = src;
|
|
228 while (dst_width >= 4) {
|
|
229 movq_m2r(s[0 * wrap], mm0);
|
|
230 punpcklbw_r2r(mm7, mm0);
|
|
231 movq_m2r(s[1 * wrap], mm1);
|
|
232 punpcklbw_r2r(mm7, mm1);
|
|
233 movq_m2r(s[2 * wrap], mm2);
|
|
234 punpcklbw_r2r(mm7, mm2);
|
|
235 movq_m2r(s[3 * wrap], mm3);
|
|
236 punpcklbw_r2r(mm7, mm3);
|
|
237
|
|
238 pmullw_m2r(coefs[0], mm0);
|
|
239 pmullw_m2r(coefs[1], mm1);
|
|
240 pmullw_m2r(coefs[2], mm2);
|
|
241 pmullw_m2r(coefs[3], mm3);
|
|
242
|
|
243 paddw_r2r(mm1, mm0);
|
|
244 paddw_r2r(mm3, mm2);
|
|
245 paddw_r2r(mm2, mm0);
|
|
246 psraw_i2r(FILTER_BITS, mm0);
|
|
247
|
|
248 packuswb_r2r(mm7, mm0);
|
|
249 movq_r2m(mm0, tmp);
|
|
250
|
|
251 *(UINT32 *)dst = tmp.ud[0];
|
|
252 dst += 4;
|
|
253 s += 4;
|
|
254 dst_width -= 4;
|
|
255 }
|
|
256 while (dst_width > 0) {
|
|
257 sum = s[0 * wrap] * filter[0] +
|
|
258 s[1 * wrap] * filter[1] +
|
|
259 s[2 * wrap] * filter[2] +
|
|
260 s[3 * wrap] * filter[3];
|
|
261 sum = sum >> FILTER_BITS;
|
|
262 if (sum < 0)
|
|
263 sum = 0;
|
|
264 else if (sum > 255)
|
|
265 sum = 255;
|
|
266 dst[0] = sum;
|
|
267 dst++;
|
|
268 s++;
|
|
269 dst_width--;
|
|
270 }
|
|
271 emms();
|
|
272 }
|
|
273 #endif
|
|
274
|
|
275 /* slow version to handle limit cases. Does not need optimisation */
|
|
276 static void h_resample_slow(UINT8 *dst, int dst_width, UINT8 *src, int src_width,
|
|
277 int src_start, int src_incr, INT16 *filters)
|
|
278 {
|
|
279 int src_pos, phase, sum, j, v, i;
|
|
280 UINT8 *s, *src_end;
|
|
281 INT16 *filter;
|
|
282
|
|
283 src_end = src + src_width;
|
|
284 src_pos = src_start;
|
|
285 for(i=0;i<dst_width;i++) {
|
|
286 s = src + (src_pos >> POS_FRAC_BITS);
|
|
287 phase = get_phase(src_pos);
|
|
288 filter = filters + phase * NB_TAPS;
|
|
289 sum = 0;
|
|
290 for(j=0;j<NB_TAPS;j++) {
|
|
291 if (s < src)
|
|
292 v = src[0];
|
|
293 else if (s >= src_end)
|
|
294 v = src_end[-1];
|
|
295 else
|
|
296 v = s[0];
|
|
297 sum += v * filter[j];
|
|
298 s++;
|
|
299 }
|
|
300 sum = sum >> FILTER_BITS;
|
|
301 if (sum < 0)
|
|
302 sum = 0;
|
|
303 else if (sum > 255)
|
|
304 sum = 255;
|
|
305 dst[0] = sum;
|
|
306 src_pos += src_incr;
|
|
307 dst++;
|
|
308 }
|
|
309 }
|
|
310
|
|
311 static void h_resample(UINT8 *dst, int dst_width, UINT8 *src, int src_width,
|
|
312 int src_start, int src_incr, INT16 *filters)
|
|
313 {
|
|
314 int n, src_end;
|
|
315
|
|
316 if (src_start < 0) {
|
|
317 n = (0 - src_start + src_incr - 1) / src_incr;
|
|
318 h_resample_slow(dst, n, src, src_width, src_start, src_incr, filters);
|
|
319 dst += n;
|
|
320 dst_width -= n;
|
|
321 src_start += n * src_incr;
|
|
322 }
|
|
323 src_end = src_start + dst_width * src_incr;
|
|
324 if (src_end > ((src_width - NB_TAPS) << POS_FRAC_BITS)) {
|
|
325 n = (((src_width - NB_TAPS + 1) << POS_FRAC_BITS) - 1 - src_start) /
|
|
326 src_incr;
|
|
327 } else {
|
|
328 n = dst_width;
|
|
329 }
|
2
|
330 #ifdef HAVE_MMX
|
0
|
331 if ((mm_flags & MM_MMX) && NB_TAPS == 4)
|
|
332 h_resample_fast4_mmx(dst, n,
|
|
333 src, src_width, src_start, src_incr, filters);
|
|
334 else
|
|
335 #endif
|
|
336 h_resample_fast(dst, n,
|
|
337 src, src_width, src_start, src_incr, filters);
|
|
338 if (n < dst_width) {
|
|
339 dst += n;
|
|
340 dst_width -= n;
|
|
341 src_start += n * src_incr;
|
|
342 h_resample_slow(dst, dst_width,
|
|
343 src, src_width, src_start, src_incr, filters);
|
|
344 }
|
|
345 }
|
|
346
|
|
347 static void component_resample(ImgReSampleContext *s,
|
|
348 UINT8 *output, int owrap, int owidth, int oheight,
|
|
349 UINT8 *input, int iwrap, int iwidth, int iheight)
|
|
350 {
|
|
351 int src_y, src_y1, last_src_y, ring_y, phase_y, y1, y;
|
|
352 UINT8 *new_line, *src_line;
|
|
353
|
|
354 last_src_y = - FCENTER - 1;
|
|
355 /* position of the bottom of the filter in the source image */
|
|
356 src_y = (last_src_y + NB_TAPS) * POS_FRAC;
|
|
357 ring_y = NB_TAPS; /* position in ring buffer */
|
|
358 for(y=0;y<oheight;y++) {
|
|
359 /* apply horizontal filter on new lines from input if needed */
|
|
360 src_y1 = src_y >> POS_FRAC_BITS;
|
|
361 while (last_src_y < src_y1) {
|
|
362 if (++ring_y >= LINE_BUF_HEIGHT + NB_TAPS)
|
|
363 ring_y = NB_TAPS;
|
|
364 last_src_y++;
|
|
365 /* handle limit conditions : replicate line (slighly
|
|
366 inefficient because we filter multiple times */
|
|
367 y1 = last_src_y;
|
|
368 if (y1 < 0) {
|
|
369 y1 = 0;
|
|
370 } else if (y1 >= iheight) {
|
|
371 y1 = iheight - 1;
|
|
372 }
|
|
373 src_line = input + y1 * iwrap;
|
|
374 new_line = s->line_buf + ring_y * owidth;
|
|
375 /* apply filter and handle limit cases correctly */
|
|
376 h_resample(new_line, owidth,
|
|
377 src_line, iwidth, - FCENTER * POS_FRAC, s->h_incr,
|
|
378 &s->h_filters[0][0]);
|
|
379 /* handle ring buffer wraping */
|
|
380 if (ring_y >= LINE_BUF_HEIGHT) {
|
|
381 memcpy(s->line_buf + (ring_y - LINE_BUF_HEIGHT) * owidth,
|
|
382 new_line, owidth);
|
|
383 }
|
|
384 }
|
|
385 /* apply vertical filter */
|
|
386 phase_y = get_phase(src_y);
|
2
|
387 #ifdef HAVE_MMX
|
0
|
388 /* desactivated MMX because loss of precision */
|
|
389 if ((mm_flags & MM_MMX) && NB_TAPS == 4 && 0)
|
|
390 v_resample4_mmx(output, owidth,
|
|
391 s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
|
|
392 &s->v_filters[phase_y][0]);
|
|
393 else
|
|
394 #endif
|
|
395 v_resample(output, owidth,
|
|
396 s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
|
|
397 &s->v_filters[phase_y][0]);
|
|
398
|
|
399 src_y += s->v_incr;
|
|
400 output += owrap;
|
|
401 }
|
|
402 }
|
|
403
|
|
404 /* XXX: the following filter is quite naive, but it seems to suffice
|
|
405 for 4 taps */
|
|
406 static void build_filter(INT16 *filter, float factor)
|
|
407 {
|
|
408 int ph, i, v;
|
|
409 float x, y, tab[NB_TAPS], norm, mult;
|
|
410
|
|
411 /* if upsampling, only need to interpolate, no filter */
|
|
412 if (factor > 1.0)
|
|
413 factor = 1.0;
|
|
414
|
|
415 for(ph=0;ph<NB_PHASES;ph++) {
|
|
416 norm = 0;
|
|
417 for(i=0;i<NB_TAPS;i++) {
|
|
418
|
|
419 x = M_PI * ((float)(i - FCENTER) - (float)ph / NB_PHASES) * factor;
|
|
420 if (x == 0)
|
|
421 y = 1.0;
|
|
422 else
|
|
423 y = sin(x) / x;
|
|
424 tab[i] = y;
|
|
425 norm += y;
|
|
426 }
|
|
427
|
|
428 /* normalize so that an uniform color remains the same */
|
|
429 mult = (float)(1 << FILTER_BITS) / norm;
|
|
430 for(i=0;i<NB_TAPS;i++) {
|
|
431 v = (int)(tab[i] * mult);
|
|
432 filter[ph * NB_TAPS + i] = v;
|
|
433 }
|
|
434 }
|
|
435 }
|
|
436
|
|
437 ImgReSampleContext *img_resample_init(int owidth, int oheight,
|
|
438 int iwidth, int iheight)
|
|
439 {
|
|
440 ImgReSampleContext *s;
|
|
441
|
|
442 s = av_mallocz(sizeof(ImgReSampleContext));
|
|
443 if (!s)
|
|
444 return NULL;
|
|
445 s->line_buf = av_mallocz(owidth * (LINE_BUF_HEIGHT + NB_TAPS));
|
|
446 if (!s->line_buf)
|
|
447 goto fail;
|
|
448
|
|
449 s->owidth = owidth;
|
|
450 s->oheight = oheight;
|
|
451 s->iwidth = iwidth;
|
|
452 s->iheight = iheight;
|
|
453
|
|
454 s->h_incr = (iwidth * POS_FRAC) / owidth;
|
|
455 s->v_incr = (iheight * POS_FRAC) / oheight;
|
|
456
|
|
457 build_filter(&s->h_filters[0][0], (float)owidth / (float)iwidth);
|
|
458 build_filter(&s->v_filters[0][0], (float)oheight / (float)iheight);
|
|
459
|
|
460 return s;
|
|
461 fail:
|
|
462 free(s);
|
|
463 return NULL;
|
|
464 }
|
|
465
|
|
466 void img_resample(ImgReSampleContext *s,
|
|
467 AVPicture *output, AVPicture *input)
|
|
468 {
|
|
469 int i, shift;
|
|
470
|
|
471 for(i=0;i<3;i++) {
|
|
472 shift = (i == 0) ? 0 : 1;
|
|
473 component_resample(s, output->data[i], output->linesize[i],
|
|
474 s->owidth >> shift, s->oheight >> shift,
|
|
475 input->data[i], input->linesize[i],
|
|
476 s->iwidth >> shift, s->iheight >> shift);
|
|
477 }
|
|
478 }
|
|
479
|
|
480 void img_resample_close(ImgReSampleContext *s)
|
|
481 {
|
|
482 free(s->line_buf);
|
|
483 free(s);
|
|
484 }
|
|
485
|
|
486 #ifdef TEST
|
|
487
|
|
488 void *av_mallocz(int size)
|
|
489 {
|
|
490 void *ptr;
|
|
491 ptr = malloc(size);
|
|
492 memset(ptr, 0, size);
|
|
493 return ptr;
|
|
494 }
|
|
495
|
|
496 /* input */
|
|
497 #define XSIZE 256
|
|
498 #define YSIZE 256
|
|
499 UINT8 img[XSIZE * YSIZE];
|
|
500
|
|
501 /* output */
|
|
502 #define XSIZE1 512
|
|
503 #define YSIZE1 512
|
|
504 UINT8 img1[XSIZE1 * YSIZE1];
|
|
505 UINT8 img2[XSIZE1 * YSIZE1];
|
|
506
|
|
507 void save_pgm(const char *filename, UINT8 *img, int xsize, int ysize)
|
|
508 {
|
|
509 FILE *f;
|
|
510 f=fopen(filename,"w");
|
|
511 fprintf(f,"P5\n%d %d\n%d\n", xsize, ysize, 255);
|
|
512 fwrite(img,1, xsize * ysize,f);
|
|
513 fclose(f);
|
|
514 }
|
|
515
|
|
516 static void dump_filter(INT16 *filter)
|
|
517 {
|
|
518 int i, ph;
|
|
519
|
|
520 for(ph=0;ph<NB_PHASES;ph++) {
|
|
521 printf("%2d: ", ph);
|
|
522 for(i=0;i<NB_TAPS;i++) {
|
|
523 printf(" %5.2f", filter[ph * NB_TAPS + i] / 256.0);
|
|
524 }
|
|
525 printf("\n");
|
|
526 }
|
|
527 }
|
|
528
|
2
|
529 #ifdef HAVE_MMX
|
0
|
530 int mm_flags;
|
|
531 #endif
|
|
532
|
|
533 int main(int argc, char **argv)
|
|
534 {
|
|
535 int x, y, v, i, xsize, ysize;
|
|
536 ImgReSampleContext *s;
|
|
537 float fact, factors[] = { 1/2.0, 3.0/4.0, 1.0, 4.0/3.0, 16.0/9.0, 2.0 };
|
|
538 char buf[256];
|
|
539
|
|
540 /* build test image */
|
|
541 for(y=0;y<YSIZE;y++) {
|
|
542 for(x=0;x<XSIZE;x++) {
|
|
543 if (x < XSIZE/2 && y < YSIZE/2) {
|
|
544 if (x < XSIZE/4 && y < YSIZE/4) {
|
|
545 if ((x % 10) <= 6 &&
|
|
546 (y % 10) <= 6)
|
|
547 v = 0xff;
|
|
548 else
|
|
549 v = 0x00;
|
|
550 } else if (x < XSIZE/4) {
|
|
551 if (x & 1)
|
|
552 v = 0xff;
|
|
553 else
|
|
554 v = 0;
|
|
555 } else if (y < XSIZE/4) {
|
|
556 if (y & 1)
|
|
557 v = 0xff;
|
|
558 else
|
|
559 v = 0;
|
|
560 } else {
|
|
561 if (y < YSIZE*3/8) {
|
|
562 if ((y+x) & 1)
|
|
563 v = 0xff;
|
|
564 else
|
|
565 v = 0;
|
|
566 } else {
|
|
567 if (((x+3) % 4) <= 1 &&
|
|
568 ((y+3) % 4) <= 1)
|
|
569 v = 0xff;
|
|
570 else
|
|
571 v = 0x00;
|
|
572 }
|
|
573 }
|
|
574 } else if (x < XSIZE/2) {
|
|
575 v = ((x - (XSIZE/2)) * 255) / (XSIZE/2);
|
|
576 } else if (y < XSIZE/2) {
|
|
577 v = ((y - (XSIZE/2)) * 255) / (XSIZE/2);
|
|
578 } else {
|
|
579 v = ((x + y - XSIZE) * 255) / XSIZE;
|
|
580 }
|
|
581 img[y * XSIZE + x] = v;
|
|
582 }
|
|
583 }
|
|
584 save_pgm("/tmp/in.pgm", img, XSIZE, YSIZE);
|
|
585 for(i=0;i<sizeof(factors)/sizeof(float);i++) {
|
|
586 fact = factors[i];
|
|
587 xsize = (int)(XSIZE * fact);
|
|
588 ysize = (int)(YSIZE * fact);
|
|
589 s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
|
|
590 printf("Factor=%0.2f\n", fact);
|
|
591 dump_filter(&s->h_filters[0][0]);
|
|
592 component_resample(s, img1, xsize, xsize, ysize,
|
|
593 img, XSIZE, XSIZE, YSIZE);
|
|
594 img_resample_close(s);
|
|
595
|
|
596 sprintf(buf, "/tmp/out%d.pgm", i);
|
|
597 save_pgm(buf, img1, xsize, ysize);
|
|
598 }
|
|
599
|
|
600 /* mmx test */
|
2
|
601 #ifdef HAVE_MMX
|
0
|
602 printf("MMX test\n");
|
|
603 fact = 0.72;
|
|
604 xsize = (int)(XSIZE * fact);
|
|
605 ysize = (int)(YSIZE * fact);
|
|
606 mm_flags = MM_MMX;
|
|
607 s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
|
|
608 component_resample(s, img1, xsize, xsize, ysize,
|
|
609 img, XSIZE, XSIZE, YSIZE);
|
|
610
|
|
611 mm_flags = 0;
|
|
612 s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
|
|
613 component_resample(s, img2, xsize, xsize, ysize,
|
|
614 img, XSIZE, XSIZE, YSIZE);
|
|
615 if (memcmp(img1, img2, xsize * ysize) != 0) {
|
|
616 fprintf(stderr, "mmx error\n");
|
|
617 exit(1);
|
|
618 }
|
|
619 printf("MMX OK\n");
|
|
620 #endif
|
|
621 return 0;
|
|
622 }
|
|
623
|
|
624 #endif
|