annotate imgresample.c @ 429:718a22dc121f libavcodec

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