2 * AltiVec-enhanced yuv-to-yuv convertion routines.
4 * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
5 * based on the equivalent C code in swscale.c
7 * This file is part of Libav.
9 * Libav is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * Libav is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with Libav; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "libswscale/swscale.h"
27 #include "libswscale/swscale_internal.h"
28 #include "libavutil/cpu.h"
30 static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t* src[],
31 int srcStride[], int srcSliceY,
32 int srcSliceH, uint8_t* dstParam[],
35 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
36 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]);
37 const uint8_t *ysrc = src[0];
38 const uint8_t *usrc = src[1];
39 const uint8_t *vsrc = src[2];
40 const int width = c->srcW;
41 const int height = srcSliceH;
42 const int lumStride = srcStride[0];
43 const int chromStride = srcStride[1];
44 const int dstStride = dstStride_a[0];
45 const vector unsigned char yperm = vec_lvsl(0, ysrc);
46 const int vertLumPerChroma = 2;
47 register unsigned int y;
51 1) dst is 16 bytes-aligned
52 2) dstStride is a multiple of 16
53 3) width is a multiple of 16
54 4) lum & chrom stride are multiples of 8
57 for (y=0; y<height; y++) {
59 for (i = 0; i < width - 31; i+= 32) {
60 const unsigned int j = i >> 1;
61 vector unsigned char v_yA = vec_ld(i, ysrc);
62 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
63 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
64 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
65 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
66 vector unsigned char v_uA = vec_ld(j, usrc);
67 vector unsigned char v_uB = vec_ld(j + 16, usrc);
68 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
69 vector unsigned char v_vA = vec_ld(j, vsrc);
70 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
71 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
72 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
73 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
74 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
75 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
76 vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
77 vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
78 vec_st(v_yuy2_0, (i << 1), dst);
79 vec_st(v_yuy2_1, (i << 1) + 16, dst);
80 vec_st(v_yuy2_2, (i << 1) + 32, dst);
81 vec_st(v_yuy2_3, (i << 1) + 48, dst);
84 const unsigned int j = i >> 1;
85 vector unsigned char v_y1 = vec_ld(i, ysrc);
86 vector unsigned char v_u = vec_ld(j, usrc);
87 vector unsigned char v_v = vec_ld(j, vsrc);
88 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
89 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
90 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
91 vec_st(v_yuy2_0, (i << 1), dst);
92 vec_st(v_yuy2_1, (i << 1) + 16, dst);
94 if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
105 static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t* src[],
106 int srcStride[], int srcSliceY,
107 int srcSliceH, uint8_t* dstParam[],
110 uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
111 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]);
112 const uint8_t *ysrc = src[0];
113 const uint8_t *usrc = src[1];
114 const uint8_t *vsrc = src[2];
115 const int width = c->srcW;
116 const int height = srcSliceH;
117 const int lumStride = srcStride[0];
118 const int chromStride = srcStride[1];
119 const int dstStride = dstStride_a[0];
120 const int vertLumPerChroma = 2;
121 const vector unsigned char yperm = vec_lvsl(0, ysrc);
122 register unsigned int y;
124 /* This code assumes:
126 1) dst is 16 bytes-aligned
127 2) dstStride is a multiple of 16
128 3) width is a multiple of 16
129 4) lum & chrom stride are multiples of 8
132 for (y=0; y<height; y++) {
134 for (i = 0; i < width - 31; i+= 32) {
135 const unsigned int j = i >> 1;
136 vector unsigned char v_yA = vec_ld(i, ysrc);
137 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
138 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
139 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
140 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
141 vector unsigned char v_uA = vec_ld(j, usrc);
142 vector unsigned char v_uB = vec_ld(j + 16, usrc);
143 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
144 vector unsigned char v_vA = vec_ld(j, vsrc);
145 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
146 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
147 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
148 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
149 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
150 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
151 vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
152 vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
153 vec_st(v_uyvy_0, (i << 1), dst);
154 vec_st(v_uyvy_1, (i << 1) + 16, dst);
155 vec_st(v_uyvy_2, (i << 1) + 32, dst);
156 vec_st(v_uyvy_3, (i << 1) + 48, dst);
159 const unsigned int j = i >> 1;
160 vector unsigned char v_y1 = vec_ld(i, ysrc);
161 vector unsigned char v_u = vec_ld(j, usrc);
162 vector unsigned char v_v = vec_ld(j, vsrc);
163 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
164 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
165 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
166 vec_st(v_uyvy_0, (i << 1), dst);
167 vec_st(v_uyvy_1, (i << 1) + 16, dst);
169 if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
179 void ff_swscale_get_unscaled_altivec(SwsContext *c)
181 if ((av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) && !(c->srcW & 15) &&
182 !(c->flags & SWS_BITEXACT) && c->srcFormat == PIX_FMT_YUV420P) {
183 enum PixelFormat dstFormat = c->dstFormat;
185 // unscaled YV12 -> packed YUV, we want speed
186 if (dstFormat == PIX_FMT_YUYV422)
187 c->swScale= yv12toyuy2_unscaled_altivec;
188 else if (dstFormat == PIX_FMT_UYVY422)
189 c->swScale= yv12touyvy_unscaled_altivec;