annotate imgresample.c @ 800:52ac8213387e libavcodec

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