Mercurial > mplayer.hg
annotate libswscale/swscale_altivec_template.c @ 21062:be83543ce2d0
add a link to Michael's de-interlacing filters, and replace the crappy
pp=fd video filter with yadif as it's soooo much better
author | gpoirier |
---|---|
date | Sun, 19 Nov 2006 21:47:45 +0000 |
parents | 200ec2faa4e1 |
children | 18da248c2020 |
rev | line source |
---|---|
19200
07769a1d06a9
Fix compile error due to extra "FF" at beginning of file in the FF{MIN,MAX}
pacman
parents:
19181
diff
changeset
|
1 /* |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
2 * AltiVec-enhanced yuv2yuvX |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
3 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
4 * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org> |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
5 * based on the equivalent C code in "postproc/swscale.c" |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
6 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
7 * This file is part of FFmpeg. |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
8 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
9 * FFmpeg is free software; you can redistribute it and/or modify |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
12 * (at your option) any later version. |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
13 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
14 * FFmpeg is distributed in the hope that it will be useful, |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
17 * GNU General Public License for more details. |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
18 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
20 * along with FFmpeg; if not, write to the Free Software |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
20006
diff
changeset
|
22 */ |
18861 | 23 |
24 #ifdef CONFIG_DARWIN | |
25 #define AVV(x...) (x) | |
26 #else | |
27 #define AVV(x...) {x} | |
28 #endif | |
29 | |
30 #define vzero vec_splat_s32(0) | |
31 | |
32 static inline void | |
33 altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) { | |
34 register int i; | |
35 vector unsigned int altivec_vectorShiftInt19 = | |
36 vec_add(vec_splat_u32(10),vec_splat_u32(9)); | |
37 if ((unsigned long)dest % 16) { | |
38 /* badly aligned store, we force store alignement */ | |
39 /* and will handle load misalignement on val w/ vec_perm */ | |
20584 | 40 vector unsigned char perm1; |
41 vector signed int v1; | |
18861 | 42 for (i = 0 ; (i < dstW) && |
43 (((unsigned long)dest + i) % 16) ; i++) { | |
44 int t = val[i] >> 19; | |
45 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); | |
46 } | |
20584 | 47 perm1 = vec_lvsl(i << 2, val); |
48 v1 = vec_ld(i << 2, val); | |
18861 | 49 for ( ; i < (dstW - 15); i+=16) { |
50 int offset = i << 2; | |
51 vector signed int v2 = vec_ld(offset + 16, val); | |
52 vector signed int v3 = vec_ld(offset + 32, val); | |
53 vector signed int v4 = vec_ld(offset + 48, val); | |
54 vector signed int v5 = vec_ld(offset + 64, val); | |
55 vector signed int v12 = vec_perm(v1,v2,perm1); | |
56 vector signed int v23 = vec_perm(v2,v3,perm1); | |
57 vector signed int v34 = vec_perm(v3,v4,perm1); | |
58 vector signed int v45 = vec_perm(v4,v5,perm1); | |
59 | |
60 vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19); | |
61 vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19); | |
62 vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19); | |
63 vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19); | |
64 vector unsigned short vs1 = vec_packsu(vA, vB); | |
65 vector unsigned short vs2 = vec_packsu(vC, vD); | |
66 vector unsigned char vf = vec_packsu(vs1, vs2); | |
67 vec_st(vf, i, dest); | |
68 v1 = v5; | |
69 } | |
70 } else { // dest is properly aligned, great | |
71 for (i = 0; i < (dstW - 15); i+=16) { | |
72 int offset = i << 2; | |
73 vector signed int v1 = vec_ld(offset, val); | |
74 vector signed int v2 = vec_ld(offset + 16, val); | |
75 vector signed int v3 = vec_ld(offset + 32, val); | |
76 vector signed int v4 = vec_ld(offset + 48, val); | |
77 vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19); | |
78 vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19); | |
79 vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19); | |
80 vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19); | |
81 vector unsigned short vs1 = vec_packsu(v5, v6); | |
82 vector unsigned short vs2 = vec_packsu(v7, v8); | |
83 vector unsigned char vf = vec_packsu(vs1, vs2); | |
84 vec_st(vf, i, dest); | |
85 } | |
86 } | |
87 for ( ; i < dstW ; i++) { | |
88 int t = val[i] >> 19; | |
89 dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); | |
90 } | |
91 } | |
92 | |
93 static inline void | |
94 yuv2yuvX_altivec_real(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, | |
95 int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, | |
96 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) | |
97 { | |
98 const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)}; | |
99 register int i, j; | |
100 { | |
101 int __attribute__ ((aligned (16))) val[dstW]; | |
102 | |
103 for (i = 0; i < (dstW -7); i+=4) { | |
104 vec_st(vini, i << 2, val); | |
105 } | |
106 for (; i < dstW; i++) { | |
107 val[i] = (1 << 18); | |
108 } | |
109 | |
110 for (j = 0; j < lumFilterSize; j++) { | |
20584 | 111 vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter); |
112 vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter); | |
18861 | 113 vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0); |
114 vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter | |
115 | |
20584 | 116 perm = vec_lvsl(0, lumSrc[j]); |
117 l1 = vec_ld(0, lumSrc[j]); | |
18861 | 118 |
119 for (i = 0; i < (dstW - 7); i+=8) { | |
120 int offset = i << 2; | |
121 vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]); | |
122 | |
123 vector signed int v1 = vec_ld(offset, val); | |
124 vector signed int v2 = vec_ld(offset + 16, val); | |
125 | |
126 vector signed short ls = vec_perm(l1, l2, perm); // lumSrc[j][i] ... lumSrc[j][i+7] | |
127 | |
128 vector signed int i1 = vec_mule(vLumFilter, ls); | |
129 vector signed int i2 = vec_mulo(vLumFilter, ls); | |
130 | |
131 vector signed int vf1 = vec_mergeh(i1, i2); | |
132 vector signed int vf2 = vec_mergel(i1, i2); // lumSrc[j][i] * lumFilter[j] ... lumSrc[j][i+7] * lumFilter[j] | |
133 | |
134 vector signed int vo1 = vec_add(v1, vf1); | |
135 vector signed int vo2 = vec_add(v2, vf2); | |
136 | |
137 vec_st(vo1, offset, val); | |
138 vec_st(vo2, offset + 16, val); | |
139 | |
140 l1 = l2; | |
141 } | |
142 for ( ; i < dstW; i++) { | |
143 val[i] += lumSrc[j][i] * lumFilter[j]; | |
144 } | |
145 } | |
146 altivec_packIntArrayToCharArray(val,dest,dstW); | |
147 } | |
148 if (uDest != 0) { | |
149 int __attribute__ ((aligned (16))) u[chrDstW]; | |
150 int __attribute__ ((aligned (16))) v[chrDstW]; | |
151 | |
152 for (i = 0; i < (chrDstW -7); i+=4) { | |
153 vec_st(vini, i << 2, u); | |
154 vec_st(vini, i << 2, v); | |
155 } | |
156 for (; i < chrDstW; i++) { | |
157 u[i] = (1 << 18); | |
158 v[i] = (1 << 18); | |
159 } | |
160 | |
161 for (j = 0; j < chrFilterSize; j++) { | |
20584 | 162 vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter); |
163 vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter); | |
18861 | 164 vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0); |
165 vChrFilter = vec_splat(vChrFilter, 0); // chrFilter[j] is loaded 8 times in vChrFilter | |
166 | |
20584 | 167 perm = vec_lvsl(0, chrSrc[j]); |
168 l1 = vec_ld(0, chrSrc[j]); | |
169 l1_V = vec_ld(2048 << 1, chrSrc[j]); | |
18861 | 170 |
171 for (i = 0; i < (chrDstW - 7); i+=8) { | |
172 int offset = i << 2; | |
173 vector signed short l2 = vec_ld((i << 1) + 16, chrSrc[j]); | |
174 vector signed short l2_V = vec_ld(((i + 2048) << 1) + 16, chrSrc[j]); | |
175 | |
176 vector signed int v1 = vec_ld(offset, u); | |
177 vector signed int v2 = vec_ld(offset + 16, u); | |
178 vector signed int v1_V = vec_ld(offset, v); | |
179 vector signed int v2_V = vec_ld(offset + 16, v); | |
180 | |
181 vector signed short ls = vec_perm(l1, l2, perm); // chrSrc[j][i] ... chrSrc[j][i+7] | |
182 vector signed short ls_V = vec_perm(l1_V, l2_V, perm); // chrSrc[j][i+2048] ... chrSrc[j][i+2055] | |
183 | |
184 vector signed int i1 = vec_mule(vChrFilter, ls); | |
185 vector signed int i2 = vec_mulo(vChrFilter, ls); | |
186 vector signed int i1_V = vec_mule(vChrFilter, ls_V); | |
187 vector signed int i2_V = vec_mulo(vChrFilter, ls_V); | |
188 | |
189 vector signed int vf1 = vec_mergeh(i1, i2); | |
190 vector signed int vf2 = vec_mergel(i1, i2); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] | |
191 vector signed int vf1_V = vec_mergeh(i1_V, i2_V); | |
192 vector signed int vf2_V = vec_mergel(i1_V, i2_V); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] | |
193 | |
194 vector signed int vo1 = vec_add(v1, vf1); | |
195 vector signed int vo2 = vec_add(v2, vf2); | |
196 vector signed int vo1_V = vec_add(v1_V, vf1_V); | |
197 vector signed int vo2_V = vec_add(v2_V, vf2_V); | |
198 | |
199 vec_st(vo1, offset, u); | |
200 vec_st(vo2, offset + 16, u); | |
201 vec_st(vo1_V, offset, v); | |
202 vec_st(vo2_V, offset + 16, v); | |
203 | |
204 l1 = l2; | |
205 l1_V = l2_V; | |
206 } | |
207 for ( ; i < chrDstW; i++) { | |
208 u[i] += chrSrc[j][i] * chrFilter[j]; | |
209 v[i] += chrSrc[j][i + 2048] * chrFilter[j]; | |
210 } | |
211 } | |
212 altivec_packIntArrayToCharArray(u,uDest,chrDstW); | |
213 altivec_packIntArrayToCharArray(v,vDest,chrDstW); | |
214 } | |
215 } | |
216 | |
217 static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, int16_t *filter, int16_t *filterPos, int filterSize) { | |
218 register int i; | |
219 int __attribute__ ((aligned (16))) tempo[4]; | |
220 | |
221 if (filterSize % 4) { | |
222 for(i=0; i<dstW; i++) { | |
223 register int j; | |
224 register int srcPos = filterPos[i]; | |
225 register int val = 0; | |
226 for(j=0; j<filterSize; j++) { | |
227 val += ((int)src[srcPos + j])*filter[filterSize*i + j]; | |
228 } | |
19181 | 229 dst[i] = FFMIN(FFMAX(0, val>>7), (1<<15)-1); |
18861 | 230 } |
231 } | |
232 else | |
233 switch (filterSize) { | |
234 case 4: | |
235 { | |
236 for(i=0; i<dstW; i++) { | |
237 register int srcPos = filterPos[i]; | |
238 | |
239 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
20584 | 240 vector unsigned char src_v1, src_vF; |
241 vector signed short src_v, filter_v; | |
242 vector signed int val_vEven, val_s; | |
18861 | 243 if ((((int)src + srcPos)% 16) > 12) { |
244 src_v1 = vec_ld(srcPos + 16, src); | |
245 } | |
20584 | 246 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); |
18861 | 247 |
20584 | 248 src_v = // vec_unpackh sign-extends... |
18861 | 249 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); |
250 // now put our elements in the even slots | |
251 src_v = vec_mergeh(src_v, (vector signed short)vzero); | |
252 | |
20584 | 253 filter_v = vec_ld(i << 3, filter); |
18861 | 254 // the 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2) |
255 | |
256 // the neat trick : we only care for half the elements, | |
257 // high or low depending on (i<<3)%16 (it's 0 or 8 here), | |
258 // and we're going to use vec_mule, so we chose | |
259 // carefully how to "unpack" the elements into the even slots | |
260 if ((i << 3) % 16) | |
261 filter_v = vec_mergel(filter_v,(vector signed short)vzero); | |
262 else | |
263 filter_v = vec_mergeh(filter_v,(vector signed short)vzero); | |
264 | |
20584 | 265 val_vEven = vec_mule(src_v, filter_v); |
266 val_s = vec_sums(val_vEven, vzero); | |
18861 | 267 vec_st(val_s, 0, tempo); |
19181 | 268 dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); |
18861 | 269 } |
270 } | |
271 break; | |
272 | |
273 case 8: | |
274 { | |
275 for(i=0; i<dstW; i++) { | |
276 register int srcPos = filterPos[i]; | |
277 | |
278 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
20584 | 279 vector unsigned char src_v1, src_vF; |
280 vector signed short src_v, filter_v; | |
281 vector signed int val_v, val_s; | |
18861 | 282 if ((((int)src + srcPos)% 16) > 8) { |
283 src_v1 = vec_ld(srcPos + 16, src); | |
284 } | |
20584 | 285 src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); |
18861 | 286 |
20584 | 287 src_v = // vec_unpackh sign-extends... |
18861 | 288 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); |
20584 | 289 filter_v = vec_ld(i << 4, filter); |
18861 | 290 // the 4 above is 3 (filterSize == 8) + 1 (sizeof(short) == 2) |
291 | |
20584 | 292 val_v = vec_msums(src_v, filter_v, (vector signed int)vzero); |
293 val_s = vec_sums(val_v, vzero); | |
18861 | 294 vec_st(val_s, 0, tempo); |
19181 | 295 dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); |
18861 | 296 } |
297 } | |
298 break; | |
299 | |
300 case 16: | |
301 { | |
302 for(i=0; i<dstW; i++) { | |
303 register int srcPos = filterPos[i]; | |
304 | |
305 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
306 vector unsigned char src_v1 = vec_ld(srcPos + 16, src); | |
307 vector unsigned char src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); | |
308 | |
309 vector signed short src_vA = // vec_unpackh sign-extends... | |
310 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); | |
311 vector signed short src_vB = // vec_unpackh sign-extends... | |
312 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF)); | |
313 | |
314 vector signed short filter_v0 = vec_ld(i << 5, filter); | |
315 vector signed short filter_v1 = vec_ld((i << 5) + 16, filter); | |
316 // the 5 above are 4 (filterSize == 16) + 1 (sizeof(short) == 2) | |
317 | |
318 vector signed int val_acc = vec_msums(src_vA, filter_v0, (vector signed int)vzero); | |
319 vector signed int val_v = vec_msums(src_vB, filter_v1, val_acc); | |
320 | |
321 vector signed int val_s = vec_sums(val_v, vzero); | |
322 | |
323 vec_st(val_s, 0, tempo); | |
19181 | 324 dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); |
18861 | 325 } |
326 } | |
327 break; | |
328 | |
329 default: | |
330 { | |
331 for(i=0; i<dstW; i++) { | |
332 register int j; | |
333 register int srcPos = filterPos[i]; | |
334 | |
20584 | 335 vector signed int val_s, val_v = (vector signed int)vzero; |
18861 | 336 vector signed short filter_v0R = vec_ld(i * 2 * filterSize, filter); |
337 vector unsigned char permF = vec_lvsl((i * 2 * filterSize), filter); | |
338 | |
339 vector unsigned char src_v0 = vec_ld(srcPos, src); | |
340 vector unsigned char permS = vec_lvsl(srcPos, src); | |
341 | |
342 for (j = 0 ; j < filterSize - 15; j += 16) { | |
343 vector unsigned char src_v1 = vec_ld(srcPos + j + 16, src); | |
344 vector unsigned char src_vF = vec_perm(src_v0, src_v1, permS); | |
345 | |
346 vector signed short src_vA = // vec_unpackh sign-extends... | |
347 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); | |
348 vector signed short src_vB = // vec_unpackh sign-extends... | |
349 (vector signed short)(vec_mergel((vector unsigned char)vzero, src_vF)); | |
350 | |
351 vector signed short filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); | |
352 vector signed short filter_v2R = vec_ld((i * 2 * filterSize) + (j * 2) + 32, filter); | |
353 vector signed short filter_v0 = vec_perm(filter_v0R, filter_v1R, permF); | |
354 vector signed short filter_v1 = vec_perm(filter_v1R, filter_v2R, permF); | |
355 | |
356 vector signed int val_acc = vec_msums(src_vA, filter_v0, val_v); | |
357 val_v = vec_msums(src_vB, filter_v1, val_acc); | |
358 | |
359 filter_v0R = filter_v2R; | |
360 src_v0 = src_v1; | |
361 } | |
362 | |
363 if (j < (filterSize-7)) { | |
364 // loading src_v0 is useless, it's already done above | |
365 //vector unsigned char src_v0 = vec_ld(srcPos + j, src); | |
20584 | 366 vector unsigned char src_v1, src_vF; |
367 vector signed short src_v, filter_v1R, filter_v; | |
18861 | 368 if ((((int)src + srcPos)% 16) > 8) { |
369 src_v1 = vec_ld(srcPos + j + 16, src); | |
370 } | |
20584 | 371 src_vF = vec_perm(src_v0, src_v1, permS); |
18861 | 372 |
20584 | 373 src_v = // vec_unpackh sign-extends... |
18861 | 374 (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); |
375 // loading filter_v0R is useless, it's already done above | |
376 //vector signed short filter_v0R = vec_ld((i * 2 * filterSize) + j, filter); | |
20584 | 377 filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); |
378 filter_v = vec_perm(filter_v0R, filter_v1R, permF); | |
18861 | 379 |
380 val_v = vec_msums(src_v, filter_v, val_v); | |
381 } | |
382 | |
20584 | 383 val_s = vec_sums(val_v, vzero); |
18861 | 384 |
385 vec_st(val_s, 0, tempo); | |
19181 | 386 dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); |
18861 | 387 } |
388 | |
389 } | |
390 } | |
391 } | |
392 | |
393 static inline int yv12toyuy2_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
394 int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { | |
395 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; | |
396 // yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); | |
397 uint8_t *ysrc = src[0]; | |
398 uint8_t *usrc = src[1]; | |
399 uint8_t *vsrc = src[2]; | |
400 const int width = c->srcW; | |
401 const int height = srcSliceH; | |
402 const int lumStride = srcStride[0]; | |
403 const int chromStride = srcStride[1]; | |
404 const int dstStride = dstStride_a[0]; | |
405 const vector unsigned char yperm = vec_lvsl(0, ysrc); | |
406 const int vertLumPerChroma = 2; | |
407 register unsigned int y; | |
408 | |
409 if(width&15){ | |
410 yv12toyuy2( ysrc, usrc, vsrc, dst,c->srcW,srcSliceH, lumStride, chromStride, dstStride); | |
411 return srcSliceH; | |
412 } | |
413 | |
414 /* this code assume: | |
415 | |
416 1) dst is 16 bytes-aligned | |
417 2) dstStride is a multiple of 16 | |
418 3) width is a multiple of 16 | |
419 4) lum&chrom stride are multiple of 8 | |
420 */ | |
421 | |
422 for(y=0; y<height; y++) | |
423 { | |
424 int i; | |
425 for (i = 0; i < width - 31; i+= 32) { | |
426 const unsigned int j = i >> 1; | |
427 vector unsigned char v_yA = vec_ld(i, ysrc); | |
428 vector unsigned char v_yB = vec_ld(i + 16, ysrc); | |
429 vector unsigned char v_yC = vec_ld(i + 32, ysrc); | |
430 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); | |
431 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); | |
432 vector unsigned char v_uA = vec_ld(j, usrc); | |
433 vector unsigned char v_uB = vec_ld(j + 16, usrc); | |
434 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); | |
435 vector unsigned char v_vA = vec_ld(j, vsrc); | |
436 vector unsigned char v_vB = vec_ld(j + 16, vsrc); | |
437 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); | |
438 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
439 vector unsigned char v_uv_b = vec_mergel(v_u, v_v); | |
440 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); | |
441 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); | |
442 vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b); | |
443 vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b); | |
444 vec_st(v_yuy2_0, (i << 1), dst); | |
445 vec_st(v_yuy2_1, (i << 1) + 16, dst); | |
446 vec_st(v_yuy2_2, (i << 1) + 32, dst); | |
447 vec_st(v_yuy2_3, (i << 1) + 48, dst); | |
448 } | |
449 if (i < width) { | |
450 const unsigned int j = i >> 1; | |
451 vector unsigned char v_y1 = vec_ld(i, ysrc); | |
452 vector unsigned char v_u = vec_ld(j, usrc); | |
453 vector unsigned char v_v = vec_ld(j, vsrc); | |
454 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
455 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); | |
456 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); | |
457 vec_st(v_yuy2_0, (i << 1), dst); | |
458 vec_st(v_yuy2_1, (i << 1) + 16, dst); | |
459 } | |
460 if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) ) | |
461 { | |
462 usrc += chromStride; | |
463 vsrc += chromStride; | |
464 } | |
465 ysrc += lumStride; | |
466 dst += dstStride; | |
467 } | |
468 | |
469 return srcSliceH; | |
470 } | |
471 | |
472 static inline int yv12touyvy_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, | |
473 int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { | |
474 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; | |
475 // yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); | |
476 uint8_t *ysrc = src[0]; | |
477 uint8_t *usrc = src[1]; | |
478 uint8_t *vsrc = src[2]; | |
479 const int width = c->srcW; | |
480 const int height = srcSliceH; | |
481 const int lumStride = srcStride[0]; | |
482 const int chromStride = srcStride[1]; | |
483 const int dstStride = dstStride_a[0]; | |
484 const int vertLumPerChroma = 2; | |
485 const vector unsigned char yperm = vec_lvsl(0, ysrc); | |
486 register unsigned int y; | |
487 | |
488 if(width&15){ | |
489 yv12touyvy( ysrc, usrc, vsrc, dst,c->srcW,srcSliceH, lumStride, chromStride, dstStride); | |
490 return srcSliceH; | |
491 } | |
492 | |
493 /* this code assume: | |
494 | |
495 1) dst is 16 bytes-aligned | |
496 2) dstStride is a multiple of 16 | |
497 3) width is a multiple of 16 | |
498 4) lum&chrom stride are multiple of 8 | |
499 */ | |
500 | |
501 for(y=0; y<height; y++) | |
502 { | |
503 int i; | |
504 for (i = 0; i < width - 31; i+= 32) { | |
505 const unsigned int j = i >> 1; | |
506 vector unsigned char v_yA = vec_ld(i, ysrc); | |
507 vector unsigned char v_yB = vec_ld(i + 16, ysrc); | |
508 vector unsigned char v_yC = vec_ld(i + 32, ysrc); | |
509 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); | |
510 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); | |
511 vector unsigned char v_uA = vec_ld(j, usrc); | |
512 vector unsigned char v_uB = vec_ld(j + 16, usrc); | |
513 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); | |
514 vector unsigned char v_vA = vec_ld(j, vsrc); | |
515 vector unsigned char v_vB = vec_ld(j + 16, vsrc); | |
516 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); | |
517 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
518 vector unsigned char v_uv_b = vec_mergel(v_u, v_v); | |
519 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); | |
520 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); | |
521 vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2); | |
522 vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2); | |
523 vec_st(v_uyvy_0, (i << 1), dst); | |
524 vec_st(v_uyvy_1, (i << 1) + 16, dst); | |
525 vec_st(v_uyvy_2, (i << 1) + 32, dst); | |
526 vec_st(v_uyvy_3, (i << 1) + 48, dst); | |
527 } | |
528 if (i < width) { | |
529 const unsigned int j = i >> 1; | |
530 vector unsigned char v_y1 = vec_ld(i, ysrc); | |
531 vector unsigned char v_u = vec_ld(j, usrc); | |
532 vector unsigned char v_v = vec_ld(j, vsrc); | |
533 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); | |
534 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); | |
535 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); | |
536 vec_st(v_uyvy_0, (i << 1), dst); | |
537 vec_st(v_uyvy_1, (i << 1) + 16, dst); | |
538 } | |
539 if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) ) | |
540 { | |
541 usrc += chromStride; | |
542 vsrc += chromStride; | |
543 } | |
544 ysrc += lumStride; | |
545 dst += dstStride; | |
546 } | |
547 return srcSliceH; | |
548 } |