• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libswscale/ppc/yuv2yuv_altivec.c

Go to the documentation of this file.
00001 /*
00002  * AltiVec-enhanced yuv-to-yuv convertion routines.
00003  *
00004  * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
00005  * based on the equivalent C code in swscale.c
00006  *
00007  * This file is part of FFmpeg.
00008  *
00009  * FFmpeg is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * FFmpeg is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with FFmpeg; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00022  */
00023 
00024 #include <inttypes.h>
00025 #include "config.h"
00026 #include "libswscale/swscale.h"
00027 #include "libswscale/swscale_internal.h"
00028 #include "libavutil/cpu.h"
00029 
00030 static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t* src[],
00031                                        int srcStride[], int srcSliceY,
00032                                        int srcSliceH, uint8_t* dstParam[],
00033                                        int dstStride_a[])
00034 {
00035     uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
00036     // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]);
00037     const uint8_t *ysrc = src[0];
00038     const uint8_t *usrc = src[1];
00039     const uint8_t *vsrc = src[2];
00040     const int width = c->srcW;
00041     const int height = srcSliceH;
00042     const int lumStride = srcStride[0];
00043     const int chromStride = srcStride[1];
00044     const int dstStride = dstStride_a[0];
00045     const vector unsigned char yperm = vec_lvsl(0, ysrc);
00046     const int vertLumPerChroma = 2;
00047     register unsigned int y;
00048 
00049     /* This code assumes:
00050 
00051     1) dst is 16 bytes-aligned
00052     2) dstStride is a multiple of 16
00053     3) width is a multiple of 16
00054     4) lum & chrom stride are multiples of 8
00055     */
00056 
00057     for (y=0; y<height; y++) {
00058         int i;
00059         for (i = 0; i < width - 31; i+= 32) {
00060             const unsigned int j = i >> 1;
00061             vector unsigned char v_yA = vec_ld(i, ysrc);
00062             vector unsigned char v_yB = vec_ld(i + 16, ysrc);
00063             vector unsigned char v_yC = vec_ld(i + 32, ysrc);
00064             vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
00065             vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
00066             vector unsigned char v_uA = vec_ld(j, usrc);
00067             vector unsigned char v_uB = vec_ld(j + 16, usrc);
00068             vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
00069             vector unsigned char v_vA = vec_ld(j, vsrc);
00070             vector unsigned char v_vB = vec_ld(j + 16, vsrc);
00071             vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
00072             vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00073             vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
00074             vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
00075             vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
00076             vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b);
00077             vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b);
00078             vec_st(v_yuy2_0, (i << 1), dst);
00079             vec_st(v_yuy2_1, (i << 1) + 16, dst);
00080             vec_st(v_yuy2_2, (i << 1) + 32, dst);
00081             vec_st(v_yuy2_3, (i << 1) + 48, dst);
00082         }
00083         if (i < width) {
00084             const unsigned int j = i >> 1;
00085             vector unsigned char v_y1 = vec_ld(i, ysrc);
00086             vector unsigned char v_u = vec_ld(j, usrc);
00087             vector unsigned char v_v = vec_ld(j, vsrc);
00088             vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00089             vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a);
00090             vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a);
00091             vec_st(v_yuy2_0, (i << 1), dst);
00092             vec_st(v_yuy2_1, (i << 1) + 16, dst);
00093         }
00094         if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
00095             usrc += chromStride;
00096             vsrc += chromStride;
00097         }
00098         ysrc += lumStride;
00099         dst += dstStride;
00100     }
00101 
00102     return srcSliceH;
00103 }
00104 
00105 static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t* src[],
00106                                        int srcStride[], int srcSliceY,
00107                                        int srcSliceH, uint8_t* dstParam[],
00108                                        int dstStride_a[])
00109 {
00110     uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY;
00111     // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]);
00112     const uint8_t *ysrc = src[0];
00113     const uint8_t *usrc = src[1];
00114     const uint8_t *vsrc = src[2];
00115     const int width = c->srcW;
00116     const int height = srcSliceH;
00117     const int lumStride = srcStride[0];
00118     const int chromStride = srcStride[1];
00119     const int dstStride = dstStride_a[0];
00120     const int vertLumPerChroma = 2;
00121     const vector unsigned char yperm = vec_lvsl(0, ysrc);
00122     register unsigned int y;
00123 
00124     /* This code assumes:
00125 
00126     1) dst is 16 bytes-aligned
00127     2) dstStride is a multiple of 16
00128     3) width is a multiple of 16
00129     4) lum & chrom stride are multiples of 8
00130     */
00131 
00132     for (y=0; y<height; y++) {
00133         int i;
00134         for (i = 0; i < width - 31; i+= 32) {
00135             const unsigned int j = i >> 1;
00136             vector unsigned char v_yA = vec_ld(i, ysrc);
00137             vector unsigned char v_yB = vec_ld(i + 16, ysrc);
00138             vector unsigned char v_yC = vec_ld(i + 32, ysrc);
00139             vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm);
00140             vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm);
00141             vector unsigned char v_uA = vec_ld(j, usrc);
00142             vector unsigned char v_uB = vec_ld(j + 16, usrc);
00143             vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc));
00144             vector unsigned char v_vA = vec_ld(j, vsrc);
00145             vector unsigned char v_vB = vec_ld(j + 16, vsrc);
00146             vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc));
00147             vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00148             vector unsigned char v_uv_b = vec_mergel(v_u, v_v);
00149             vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
00150             vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
00151             vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2);
00152             vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2);
00153             vec_st(v_uyvy_0, (i << 1), dst);
00154             vec_st(v_uyvy_1, (i << 1) + 16, dst);
00155             vec_st(v_uyvy_2, (i << 1) + 32, dst);
00156             vec_st(v_uyvy_3, (i << 1) + 48, dst);
00157         }
00158         if (i < width) {
00159             const unsigned int j = i >> 1;
00160             vector unsigned char v_y1 = vec_ld(i, ysrc);
00161             vector unsigned char v_u = vec_ld(j, usrc);
00162             vector unsigned char v_v = vec_ld(j, vsrc);
00163             vector unsigned char v_uv_a = vec_mergeh(v_u, v_v);
00164             vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1);
00165             vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1);
00166             vec_st(v_uyvy_0, (i << 1), dst);
00167             vec_st(v_uyvy_1, (i << 1) + 16, dst);
00168         }
00169         if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) {
00170             usrc += chromStride;
00171             vsrc += chromStride;
00172         }
00173         ysrc += lumStride;
00174         dst += dstStride;
00175     }
00176     return srcSliceH;
00177 }
00178 
00179 void ff_swscale_get_unscaled_altivec(SwsContext *c)
00180 {
00181     if ((av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) && !(c->srcW & 15) &&
00182         !(c->flags & SWS_BITEXACT) && c->srcFormat == PIX_FMT_YUV420P) {
00183         enum PixelFormat dstFormat = c->dstFormat;
00184 
00185         // unscaled YV12 -> packed YUV, we want speed
00186         if (dstFormat == PIX_FMT_YUYV422)
00187             c->swScale= yv12toyuy2_unscaled_altivec;
00188         else if (dstFormat == PIX_FMT_UYVY422)
00189             c->swScale= yv12touyvy_unscaled_altivec;
00190     }
00191 }
Generated on Fri Feb 1 2013 14:34:56 for FFmpeg by doxygen 1.7.1