00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <inttypes.h>
00025
00026 #include "config.h"
00027 #include "libswscale/swscale.h"
00028 #include "libswscale/swscale_internal.h"
00029 #include "libavutil/cpu.h"
00030
00031 static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t *src[],
00032 int srcStride[], int srcSliceY,
00033 int srcSliceH, uint8_t *dstParam[],
00034 int dstStride_a[])
00035 {
00036 uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
00037
00038
00039 const uint8_t *ysrc = src[0];
00040 const uint8_t *usrc = src[1];
00041 const uint8_t *vsrc = src[2];
00042 const int width = c->srcW;
00043 const int height = srcSliceH;
00044 const int lumStride = srcStride[0];
00045 const int chromStride = srcStride[1];
00046 const int dstStride = dstStride_a[0];
00047 const vector unsigned char yperm = vec_lvsl(0, ysrc);
00048 const int vertLumPerChroma = 2;
00049 register unsigned int y;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 for (y = 0; y < height; y++) {
00060 int i;
00061 for (i = 0; i < width - 31; i += 32) {
00062 const unsigned int j = i >> 1;
00063 vector unsigned char v_yA = vec_ld(i, ysrc);
00064 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
00065 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
00066 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
00067 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
00068 vector unsigned char v_uA = vec_ld(j, usrc);
00069 vector unsigned char v_uB = vec_ld(j + 16, usrc);
00070 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
00071 vector unsigned char v_vA = vec_ld(j, vsrc);
00072 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
00073 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
00074 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00075 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
00076 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
00077 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
00078 vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
00079 vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
00080 vec_st(v_yuy2_0, (i << 1), dst);
00081 vec_st(v_yuy2_1, (i << 1) + 16, dst);
00082 vec_st(v_yuy2_2, (i << 1) + 32, dst);
00083 vec_st(v_yuy2_3, (i << 1) + 48, dst);
00084 }
00085 if (i < width) {
00086 const unsigned int j = i >> 1;
00087 vector unsigned char v_y1 = vec_ld(i, ysrc);
00088 vector unsigned char v_u = vec_ld(j, usrc);
00089 vector unsigned char v_v = vec_ld(j, vsrc);
00090 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00091 vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
00092 vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
00093 vec_st(v_yuy2_0, (i << 1), dst);
00094 vec_st(v_yuy2_1, (i << 1) + 16, dst);
00095 }
00096 if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
00097 usrc += chromStride;
00098 vsrc += chromStride;
00099 }
00100 ysrc += lumStride;
00101 dst += dstStride;
00102 }
00103
00104 return srcSliceH;
00105 }
00106
00107 static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t *src[],
00108 int srcStride[], int srcSliceY,
00109 int srcSliceH, uint8_t *dstParam[],
00110 int dstStride_a[])
00111 {
00112 uint8_t *dst = dstParam[0] + dstStride_a[0] * srcSliceY;
00113
00114
00115 const uint8_t *ysrc = src[0];
00116 const uint8_t *usrc = src[1];
00117 const uint8_t *vsrc = src[2];
00118 const int width = c->srcW;
00119 const int height = srcSliceH;
00120 const int lumStride = srcStride[0];
00121 const int chromStride = srcStride[1];
00122 const int dstStride = dstStride_a[0];
00123 const int vertLumPerChroma = 2;
00124 const vector unsigned char yperm = vec_lvsl(0, ysrc);
00125 register unsigned int y;
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 for (y = 0; y < height; y++) {
00136 int i;
00137 for (i = 0; i < width - 31; i += 32) {
00138 const unsigned int j = i >> 1;
00139 vector unsigned char v_yA = vec_ld(i, ysrc);
00140 vector unsigned char v_yB = vec_ld(i + 16, ysrc);
00141 vector unsigned char v_yC = vec_ld(i + 32, ysrc);
00142 vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
00143 vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
00144 vector unsigned char v_uA = vec_ld(j, usrc);
00145 vector unsigned char v_uB = vec_ld(j + 16, usrc);
00146 vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
00147 vector unsigned char v_vA = vec_ld(j, vsrc);
00148 vector unsigned char v_vB = vec_ld(j + 16, vsrc);
00149 vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
00150 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00151 vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
00152 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
00153 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
00154 vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
00155 vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
00156 vec_st(v_uyvy_0, (i << 1), dst);
00157 vec_st(v_uyvy_1, (i << 1) + 16, dst);
00158 vec_st(v_uyvy_2, (i << 1) + 32, dst);
00159 vec_st(v_uyvy_3, (i << 1) + 48, dst);
00160 }
00161 if (i < width) {
00162 const unsigned int j = i >> 1;
00163 vector unsigned char v_y1 = vec_ld(i, ysrc);
00164 vector unsigned char v_u = vec_ld(j, usrc);
00165 vector unsigned char v_v = vec_ld(j, vsrc);
00166 vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00167 vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
00168 vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
00169 vec_st(v_uyvy_0, (i << 1), dst);
00170 vec_st(v_uyvy_1, (i << 1) + 16, dst);
00171 }
00172 if ((y & (vertLumPerChroma - 1)) == vertLumPerChroma - 1) {
00173 usrc += chromStride;
00174 vsrc += chromStride;
00175 }
00176 ysrc += lumStride;
00177 dst += dstStride;
00178 }
00179 return srcSliceH;
00180 }
00181
00182 void ff_swscale_get_unscaled_altivec(SwsContext *c)
00183 {
00184 if ((av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) && !(c->srcW & 15) &&
00185 !(c->flags & SWS_BITEXACT) && c->srcFormat == PIX_FMT_YUV420P) {
00186 enum PixelFormat dstFormat = c->dstFormat;
00187
00188
00189 if (dstFormat == PIX_FMT_YUYV422)
00190 c->swScale = yv12toyuy2_unscaled_altivec;
00191 else if (dstFormat == PIX_FMT_UYVY422)
00192 c->swScale = yv12touyvy_unscaled_altivec;
00193 }
00194 }