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 FFmpeg.
9 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "libswscale/swscale.h"
28 #include "libswscale/swscale_internal.h"
29 #include "libavutil/cpu.h"
31 static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t *src[],
32 int srcStride[], int srcSliceY,
33 int srcSliceH, uint8_t *dstParam[],
36 uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
37 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH,
38 // srcStride[0], srcStride[1], dstStride[0]);
39 const uint8_t *ysrc = src[0];
40 const uint8_t *usrc = src[1];
41 const uint8_t *vsrc = src[2];
42 const int width = c->srcW;
43 const int height = srcSliceH;
44 const int lumStride = srcStride[0];
45 const int chromStride = srcStride[1];
46 const int dstStride = dstStride_a[0];
47 const vector unsigned char yperm = vec_lvsl(0, ysrc);
48 const int vertLumPerChroma = 2;
49 register unsigned int y;
53 * 1) dst is 16 bytes-aligned
54 * 2) dstStride is a multiple of 16
55 * 3) width is a multiple of 16
56 * 4) lum & chrom stride are multiples of 8
59 for (y = 0; y < height; y++) {
61 for (i = 0; i < width - 31; i += 32) {
62 const unsigned int j = i >> 1;
63 vector unsigned char v_yA = vec_ld(i, ysrc);
64 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
65 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
66 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
67 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
68 vector unsigned char v_uA = vec_ld(j, usrc);
69 vector unsigned char v_uB = vec_ld(j + 16, usrc);
70 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
71 vector unsigned char v_vA = vec_ld(j, vsrc);
72 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
73 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
74 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
75 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
76 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
77 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
78 vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
79 vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
80 vec_st(v_yuy2_0, (i << 1), dst);
81 vec_st(v_yuy2_1, (i << 1) + 16, dst);
82 vec_st(v_yuy2_2, (i << 1) + 32, dst);
83 vec_st(v_yuy2_3, (i << 1) + 48, dst);
86 const unsigned int j = i >> 1;
87 vector unsigned char v_y1 = vec_ld(i, ysrc);
88 vector unsigned char v_u = vec_ld(j, usrc);
89 vector unsigned char v_v = vec_ld(j, vsrc);
90 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
91 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
92 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
93 vec_st(v_yuy2_0, (i << 1), dst);
94 vec_st(v_yuy2_1, (i << 1) + 16, dst);
96 if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
107 static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t *src[],
108 int srcStride[], int srcSliceY,
109 int srcSliceH, uint8_t *dstParam[],
112 uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
113 // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH,
114 // srcStride[0], srcStride[1], dstStride[0]);
115 const uint8_t *ysrc = src[0];
116 const uint8_t *usrc = src[1];
117 const uint8_t *vsrc = src[2];
118 const int width = c->srcW;
119 const int height = srcSliceH;
120 const int lumStride = srcStride[0];
121 const int chromStride = srcStride[1];
122 const int dstStride = dstStride_a[0];
123 const int vertLumPerChroma = 2;
124 const vector unsigned char yperm = vec_lvsl(0, ysrc);
125 register unsigned int y;
127 /* This code assumes:
129 * 1) dst is 16 bytes-aligned
130 * 2) dstStride is a multiple of 16
131 * 3) width is a multiple of 16
132 * 4) lum & chrom stride are multiples of 8
135 for (y = 0; y < height; y++) {
137 for (i = 0; i < width - 31; i += 32) {
138 const unsigned int j = i >> 1;
139 vector unsigned char v_yA = vec_ld(i, ysrc);
140 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
141 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
142 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
143 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
144 vector unsigned char v_uA = vec_ld(j, usrc);
145 vector unsigned char v_uB = vec_ld(j + 16, usrc);
146 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
147 vector unsigned char v_vA = vec_ld(j, vsrc);
148 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
149 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
150 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
151 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
152 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
153 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
154 vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
155 vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
156 vec_st(v_uyvy_0, (i << 1), dst);
157 vec_st(v_uyvy_1, (i << 1) + 16, dst);
158 vec_st(v_uyvy_2, (i << 1) + 32, dst);
159 vec_st(v_uyvy_3, (i << 1) + 48, dst);
162 const unsigned int j = i >> 1;
163 vector unsigned char v_y1 = vec_ld(i, ysrc);
164 vector unsigned char v_u = vec_ld(j, usrc);
165 vector unsigned char v_v = vec_ld(j, vsrc);
166 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
167 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
168 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
169 vec_st(v_uyvy_0, (i << 1), dst);
170 vec_st(v_uyvy_1, (i << 1) + 16, dst);
172 if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
182 void ff_swscale_get_unscaled_altivec(SwsContext *c)
184 if ((av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) && !(c->srcW & 15) &&
185 !(c->flags & SWS_BITEXACT) && c->srcFormat == PIX_FMT_YUV420P) {
186 enum PixelFormat dstFormat = c->dstFormat;
188 // unscaled YV12 -> packed YUV, we want speed
189 if (dstFormat == PIX_FMT_YUYV422)
190 c->swScale = yv12toyuy2_unscaled_altivec;
191 else if (dstFormat == PIX_FMT_UYVY422)
192 c->swScale = yv12touyvy_unscaled_altivec;