Mercurial > libavcodec.hg
comparison imgresample.c @ 1064:b32afefe7d33 libavcodec
* UINTX -> uintx_t INTX -> intx_t
author | kabi |
---|---|
date | Tue, 11 Feb 2003 16:35:48 +0000 |
parents | bb5de8a59da8 |
children | 1e39f273ecd6 |
comparison
equal
deleted
inserted
replaced
1063:fdeac9642346 | 1064:b32afefe7d33 |
---|---|
39 #define LINE_BUF_HEIGHT (NB_TAPS * 4) | 39 #define LINE_BUF_HEIGHT (NB_TAPS * 4) |
40 | 40 |
41 struct ImgReSampleContext { | 41 struct ImgReSampleContext { |
42 int iwidth, iheight, owidth, oheight, topBand, bottomBand, leftBand, rightBand; | 42 int iwidth, iheight, owidth, oheight, topBand, bottomBand, leftBand, rightBand; |
43 int h_incr, v_incr; | 43 int h_incr, v_incr; |
44 INT16 h_filters[NB_PHASES][NB_TAPS] __align8; /* horizontal filters */ | 44 int16_t h_filters[NB_PHASES][NB_TAPS] __align8; /* horizontal filters */ |
45 INT16 v_filters[NB_PHASES][NB_TAPS] __align8; /* vertical filters */ | 45 int16_t v_filters[NB_PHASES][NB_TAPS] __align8; /* vertical filters */ |
46 UINT8 *line_buf; | 46 uint8_t *line_buf; |
47 }; | 47 }; |
48 | 48 |
49 static inline int get_phase(int pos) | 49 static inline int get_phase(int pos) |
50 { | 50 { |
51 return ((pos) >> (POS_FRAC_BITS - PHASE_BITS)) & ((1 << PHASE_BITS) - 1); | 51 return ((pos) >> (POS_FRAC_BITS - PHASE_BITS)) & ((1 << PHASE_BITS) - 1); |
52 } | 52 } |
53 | 53 |
54 /* This function must be optimized */ | 54 /* This function must be optimized */ |
55 static void h_resample_fast(UINT8 *dst, int dst_width, UINT8 *src, int src_width, | 55 static void h_resample_fast(uint8_t *dst, int dst_width, uint8_t *src, int src_width, |
56 int src_start, int src_incr, INT16 *filters) | 56 int src_start, int src_incr, int16_t *filters) |
57 { | 57 { |
58 int src_pos, phase, sum, i; | 58 int src_pos, phase, sum, i; |
59 UINT8 *s; | 59 uint8_t *s; |
60 INT16 *filter; | 60 int16_t *filter; |
61 | 61 |
62 src_pos = src_start; | 62 src_pos = src_start; |
63 for(i=0;i<dst_width;i++) { | 63 for(i=0;i<dst_width;i++) { |
64 #ifdef TEST | 64 #ifdef TEST |
65 /* test */ | 65 /* test */ |
93 dst++; | 93 dst++; |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 /* This function must be optimized */ | 97 /* This function must be optimized */ |
98 static void v_resample(UINT8 *dst, int dst_width, UINT8 *src, int wrap, | 98 static void v_resample(uint8_t *dst, int dst_width, uint8_t *src, int wrap, |
99 INT16 *filter) | 99 int16_t *filter) |
100 { | 100 { |
101 int sum, i; | 101 int sum, i; |
102 UINT8 *s; | 102 uint8_t *s; |
103 | 103 |
104 s = src; | 104 s = src; |
105 for(i=0;i<dst_width;i++) { | 105 for(i=0;i<dst_width;i++) { |
106 #if NB_TAPS == 4 | 106 #if NB_TAPS == 4 |
107 sum = s[0 * wrap] * filter[0] + | 107 sum = s[0 * wrap] * filter[0] + |
109 s[2 * wrap] * filter[2] + | 109 s[2 * wrap] * filter[2] + |
110 s[3 * wrap] * filter[3]; | 110 s[3 * wrap] * filter[3]; |
111 #else | 111 #else |
112 { | 112 { |
113 int j; | 113 int j; |
114 UINT8 *s1 = s; | 114 uint8_t *s1 = s; |
115 | 115 |
116 sum = 0; | 116 sum = 0; |
117 for(j=0;j<NB_TAPS;j++) { | 117 for(j=0;j<NB_TAPS;j++) { |
118 sum += s1[0] * filter[j]; | 118 sum += s1[0] * filter[j]; |
119 s1 += wrap; | 119 s1 += wrap; |
152 } | 152 } |
153 | 153 |
154 #define DUMP(reg) movq_r2m(reg, tmp); printf(#reg "=%016Lx\n", tmp.uq); | 154 #define DUMP(reg) movq_r2m(reg, tmp); printf(#reg "=%016Lx\n", tmp.uq); |
155 | 155 |
156 /* XXX: do four pixels at a time */ | 156 /* XXX: do four pixels at a time */ |
157 static void h_resample_fast4_mmx(UINT8 *dst, int dst_width, UINT8 *src, int src_width, | 157 static void h_resample_fast4_mmx(uint8_t *dst, int dst_width, uint8_t *src, int src_width, |
158 int src_start, int src_incr, INT16 *filters) | 158 int src_start, int src_incr, int16_t *filters) |
159 { | 159 { |
160 int src_pos, phase; | 160 int src_pos, phase; |
161 UINT8 *s; | 161 uint8_t *s; |
162 INT16 *filter; | 162 int16_t *filter; |
163 mmx_t tmp; | 163 mmx_t tmp; |
164 | 164 |
165 src_pos = src_start; | 165 src_pos = src_start; |
166 pxor_r2r(mm7, mm7); | 166 pxor_r2r(mm7, mm7); |
167 | 167 |
196 dst_width--; | 196 dst_width--; |
197 } | 197 } |
198 emms(); | 198 emms(); |
199 } | 199 } |
200 | 200 |
201 static void v_resample4_mmx(UINT8 *dst, int dst_width, UINT8 *src, int wrap, | 201 static void v_resample4_mmx(uint8_t *dst, int dst_width, uint8_t *src, int wrap, |
202 INT16 *filter) | 202 int16_t *filter) |
203 { | 203 { |
204 int sum, i, v; | 204 int sum, i, v; |
205 UINT8 *s; | 205 uint8_t *s; |
206 mmx_t tmp; | 206 mmx_t tmp; |
207 mmx_t coefs[4]; | 207 mmx_t coefs[4]; |
208 | 208 |
209 for(i=0;i<4;i++) { | 209 for(i=0;i<4;i++) { |
210 v = filter[i]; | 210 v = filter[i]; |
237 psraw_i2r(FILTER_BITS, mm0); | 237 psraw_i2r(FILTER_BITS, mm0); |
238 | 238 |
239 packuswb_r2r(mm7, mm0); | 239 packuswb_r2r(mm7, mm0); |
240 movq_r2m(mm0, tmp); | 240 movq_r2m(mm0, tmp); |
241 | 241 |
242 *(UINT32 *)dst = tmp.ud[0]; | 242 *(uint32_t *)dst = tmp.ud[0]; |
243 dst += 4; | 243 dst += 4; |
244 s += 4; | 244 s += 4; |
245 dst_width -= 4; | 245 dst_width -= 4; |
246 } | 246 } |
247 while (dst_width > 0) { | 247 while (dst_width > 0) { |
272 typedef union { | 272 typedef union { |
273 vector signed short v; | 273 vector signed short v; |
274 signed short s[8]; | 274 signed short s[8]; |
275 } vec_ss_t; | 275 } vec_ss_t; |
276 | 276 |
277 void v_resample16_altivec(UINT8 *dst, int dst_width, UINT8 *src, int wrap, | 277 void v_resample16_altivec(uint8_t *dst, int dst_width, uint8_t *src, int wrap, |
278 INT16 *filter) | 278 int16_t *filter) |
279 { | 279 { |
280 int sum, i; | 280 int sum, i; |
281 uint8_t *s; | 281 uint8_t *s; |
282 vector unsigned char *tv, tmp, dstv, zero; | 282 vector unsigned char *tv, tmp, dstv, zero; |
283 vec_ss_t srchv[4], srclv[4], fv[4]; | 283 vec_ss_t srchv[4], srclv[4], fv[4]; |
389 } | 389 } |
390 } | 390 } |
391 #endif | 391 #endif |
392 | 392 |
393 /* slow version to handle limit cases. Does not need optimisation */ | 393 /* slow version to handle limit cases. Does not need optimisation */ |
394 static void h_resample_slow(UINT8 *dst, int dst_width, UINT8 *src, int src_width, | 394 static void h_resample_slow(uint8_t *dst, int dst_width, uint8_t *src, int src_width, |
395 int src_start, int src_incr, INT16 *filters) | 395 int src_start, int src_incr, int16_t *filters) |
396 { | 396 { |
397 int src_pos, phase, sum, j, v, i; | 397 int src_pos, phase, sum, j, v, i; |
398 UINT8 *s, *src_end; | 398 uint8_t *s, *src_end; |
399 INT16 *filter; | 399 int16_t *filter; |
400 | 400 |
401 src_end = src + src_width; | 401 src_end = src + src_width; |
402 src_pos = src_start; | 402 src_pos = src_start; |
403 for(i=0;i<dst_width;i++) { | 403 for(i=0;i<dst_width;i++) { |
404 s = src + (src_pos >> POS_FRAC_BITS); | 404 s = src + (src_pos >> POS_FRAC_BITS); |
424 src_pos += src_incr; | 424 src_pos += src_incr; |
425 dst++; | 425 dst++; |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 static void h_resample(UINT8 *dst, int dst_width, UINT8 *src, int src_width, | 429 static void h_resample(uint8_t *dst, int dst_width, uint8_t *src, int src_width, |
430 int src_start, int src_incr, INT16 *filters) | 430 int src_start, int src_incr, int16_t *filters) |
431 { | 431 { |
432 int n, src_end; | 432 int n, src_end; |
433 | 433 |
434 if (src_start < 0) { | 434 if (src_start < 0) { |
435 n = (0 - src_start + src_incr - 1) / src_incr; | 435 n = (0 - src_start + src_incr - 1) / src_incr; |
461 src, src_width, src_start, src_incr, filters); | 461 src, src_width, src_start, src_incr, filters); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 static void component_resample(ImgReSampleContext *s, | 465 static void component_resample(ImgReSampleContext *s, |
466 UINT8 *output, int owrap, int owidth, int oheight, | 466 uint8_t *output, int owrap, int owidth, int oheight, |
467 UINT8 *input, int iwrap, int iwidth, int iheight) | 467 uint8_t *input, int iwrap, int iwidth, int iheight) |
468 { | 468 { |
469 int src_y, src_y1, last_src_y, ring_y, phase_y, y1, y; | 469 int src_y, src_y1, last_src_y, ring_y, phase_y, y1, y; |
470 UINT8 *new_line, *src_line; | 470 uint8_t *new_line, *src_line; |
471 | 471 |
472 last_src_y = - FCENTER - 1; | 472 last_src_y = - FCENTER - 1; |
473 /* position of the bottom of the filter in the source image */ | 473 /* position of the bottom of the filter in the source image */ |
474 src_y = (last_src_y + NB_TAPS) * POS_FRAC; | 474 src_y = (last_src_y + NB_TAPS) * POS_FRAC; |
475 ring_y = NB_TAPS; /* position in ring buffer */ | 475 ring_y = NB_TAPS; /* position in ring buffer */ |
526 } | 526 } |
527 } | 527 } |
528 | 528 |
529 /* XXX: the following filter is quite naive, but it seems to suffice | 529 /* XXX: the following filter is quite naive, but it seems to suffice |
530 for 4 taps */ | 530 for 4 taps */ |
531 static void build_filter(INT16 *filter, float factor) | 531 static void build_filter(int16_t *filter, float factor) |
532 { | 532 { |
533 int ph, i, v; | 533 int ph, i, v; |
534 float x, y, tab[NB_TAPS], norm, mult; | 534 float x, y, tab[NB_TAPS], norm, mult; |
535 | 535 |
536 /* if upsampling, only need to interpolate, no filter */ | 536 /* if upsampling, only need to interpolate, no filter */ |
639 } | 639 } |
640 | 640 |
641 /* input */ | 641 /* input */ |
642 #define XSIZE 256 | 642 #define XSIZE 256 |
643 #define YSIZE 256 | 643 #define YSIZE 256 |
644 UINT8 img[XSIZE * YSIZE]; | 644 uint8_t img[XSIZE * YSIZE]; |
645 | 645 |
646 /* output */ | 646 /* output */ |
647 #define XSIZE1 512 | 647 #define XSIZE1 512 |
648 #define YSIZE1 512 | 648 #define YSIZE1 512 |
649 UINT8 img1[XSIZE1 * YSIZE1]; | 649 uint8_t img1[XSIZE1 * YSIZE1]; |
650 UINT8 img2[XSIZE1 * YSIZE1]; | 650 uint8_t img2[XSIZE1 * YSIZE1]; |
651 | 651 |
652 void save_pgm(const char *filename, UINT8 *img, int xsize, int ysize) | 652 void save_pgm(const char *filename, uint8_t *img, int xsize, int ysize) |
653 { | 653 { |
654 FILE *f; | 654 FILE *f; |
655 f=fopen(filename,"w"); | 655 f=fopen(filename,"w"); |
656 fprintf(f,"P5\n%d %d\n%d\n", xsize, ysize, 255); | 656 fprintf(f,"P5\n%d %d\n%d\n", xsize, ysize, 255); |
657 fwrite(img,1, xsize * ysize,f); | 657 fwrite(img,1, xsize * ysize,f); |
658 fclose(f); | 658 fclose(f); |
659 } | 659 } |
660 | 660 |
661 static void dump_filter(INT16 *filter) | 661 static void dump_filter(int16_t *filter) |
662 { | 662 { |
663 int i, ph; | 663 int i, ph; |
664 | 664 |
665 for(ph=0;ph<NB_PHASES;ph++) { | 665 for(ph=0;ph<NB_PHASES;ph++) { |
666 printf("%2d: ", ph); | 666 printf("%2d: ", ph); |