annotate imgresample.c @ 52:1d796bdb2c2a libavcodec

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