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

libswscale/yuv2rgb_vis.c

Go to the documentation of this file.
00001 /*
00002  * VIS optimized software YUV to RGB converter
00003  * Copyright (c) 2007 Denes Balatoni <dbalatoni@programozo.hu>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include <inttypes.h>
00023 #include <stdlib.h>
00024 
00025 #include "swscale.h"
00026 #include "swscale_internal.h"
00027 
00028 #define YUV2RGB_INIT \
00029     "wr %%g0, 0x10, %%gsr \n\t" \
00030     "ldd [%5], %%f32      \n\t" \
00031     "ldd [%5+8], %%f34    \n\t" \
00032     "ldd [%5+16], %%f36   \n\t" \
00033     "ldd [%5+24], %%f38   \n\t" \
00034     "ldd [%5+32], %%f40   \n\t" \
00035     "ldd [%5+40], %%f42   \n\t" \
00036     "ldd [%5+48], %%f44   \n\t" \
00037     "ldd [%5+56], %%f46   \n\t" \
00038     "ldd [%5+64], %%f48   \n\t" \
00039     "ldd [%5+72], %%f50   \n\t"
00040 
00041 #define YUV2RGB_KERNEL \
00042     /* ^^^^ f0=Y f3=u f5=v */ \
00043     "fmul8x16 %%f3, %%f48, %%f6   \n\t" \
00044     "fmul8x16 %%f19, %%f48, %%f22 \n\t" \
00045     "fmul8x16 %%f5, %%f44, %%f8   \n\t" \
00046     "fmul8x16 %%f21, %%f44, %%f24 \n\t" \
00047     "fmul8x16 %%f0, %%f42, %%f0   \n\t" \
00048     "fmul8x16 %%f16, %%f42, %%f16 \n\t" \
00049     "fmul8x16 %%f3, %%f50, %%f2   \n\t" \
00050     "fmul8x16 %%f19, %%f50, %%f18 \n\t" \
00051     "fmul8x16 %%f5, %%f46, %%f4   \n\t" \
00052     "fmul8x16 %%f21, %%f46, %%f20 \n\t" \
00053     \
00054     "fpsub16 %%f6, %%f34, %%f6   \n\t" /* 1 */ \
00055     "fpsub16 %%f22, %%f34, %%f22 \n\t" /* 1 */ \
00056     "fpsub16 %%f8, %%f38, %%f8   \n\t" /* 3 */ \
00057     "fpsub16 %%f24, %%f38, %%f24 \n\t" /* 3 */ \
00058     "fpsub16 %%f0, %%f32, %%f0   \n\t" /* 0 */ \
00059     "fpsub16 %%f16, %%f32, %%f16 \n\t" /* 0 */ \
00060     "fpsub16 %%f2, %%f36, %%f2   \n\t" /* 2 */ \
00061     "fpsub16 %%f18, %%f36, %%f18 \n\t" /* 2 */ \
00062     "fpsub16 %%f4, %%f40, %%f4   \n\t" /* 4 */ \
00063     "fpsub16 %%f20, %%f40, %%f20 \n\t" /* 4 */ \
00064     \
00065     "fpadd16 %%f0, %%f8, %%f8    \n\t" /* Gt */ \
00066     "fpadd16 %%f16, %%f24, %%f24 \n\t" /* Gt */ \
00067     "fpadd16 %%f0, %%f4, %%f4    \n\t" /* R */ \
00068     "fpadd16 %%f16, %%f20, %%f20 \n\t" /* R */ \
00069     "fpadd16 %%f0, %%f6, %%f6    \n\t" /* B */ \
00070     "fpadd16 %%f16, %%f22, %%f22 \n\t" /* B */ \
00071     "fpadd16 %%f8, %%f2, %%f2    \n\t" /* G */ \
00072     "fpadd16 %%f24, %%f18, %%f18 \n\t" /* G */ \
00073     \
00074     "fpack16 %%f4, %%f4    \n\t" \
00075     "fpack16 %%f20, %%f20  \n\t" \
00076     "fpack16 %%f6, %%f6    \n\t" \
00077     "fpack16 %%f22, %%f22  \n\t" \
00078     "fpack16 %%f2, %%f2    \n\t" \
00079     "fpack16 %%f18, %%f18  \n\t"
00080 
00081 
00082 
00083 // FIXME: must be changed to set alpha to 255 instead of 0
00084 static int vis_420P_ARGB32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00085                            int srcSliceH, uint8_t* dst[], int dstStride[]){
00086   int y, out1, out2, out3, out4, out5, out6;
00087 
00088   for(y=0;y < srcSliceH;++y) {
00089       __asm__ volatile (
00090           YUV2RGB_INIT
00091           "wr %%g0, 0xd2, %%asi        \n\t" /* ASI_FL16_P */
00092           "1:                          \n\t"
00093           "ldda [%1] %%asi, %%f2       \n\t"
00094           "ldda [%1+2] %%asi, %%f18    \n\t"
00095           "ldda [%2] %%asi, %%f4       \n\t"
00096           "ldda [%2+2] %%asi, %%f20    \n\t"
00097           "ld [%0], %%f0               \n\t"
00098           "ld [%0+4], %%f16            \n\t"
00099           "fpmerge %%f3, %%f3, %%f2    \n\t"
00100           "fpmerge %%f19, %%f19, %%f18 \n\t"
00101           "fpmerge %%f5, %%f5, %%f4    \n\t"
00102           "fpmerge %%f21, %%f21, %%f20 \n\t"
00103           YUV2RGB_KERNEL
00104           "fzero %%f0                  \n\t"
00105           "fpmerge %%f4, %%f6, %%f8    \n\t"  // r,b,t1
00106           "fpmerge %%f20, %%f22, %%f24 \n\t"  // r,b,t1
00107           "fpmerge %%f0, %%f2, %%f10   \n\t"  // 0,g,t2
00108           "fpmerge %%f0, %%f18, %%f26  \n\t"  // 0,g,t2
00109           "fpmerge %%f10, %%f8, %%f4   \n\t"  // t2,t1,msb
00110           "fpmerge %%f26, %%f24, %%f20 \n\t"  // t2,t1,msb
00111           "fpmerge %%f11, %%f9, %%f6   \n\t"  // t2,t1,lsb
00112           "fpmerge %%f27, %%f25, %%f22 \n\t"  // t2,t1,lsb
00113           "std %%f4, [%3]              \n\t"
00114           "std %%f20, [%3+16]          \n\t"
00115           "std %%f6, [%3+8]            \n\t"
00116           "std %%f22, [%3+24]          \n\t"
00117 
00118           "add %0, 8, %0   \n\t"
00119           "add %1, 4, %1   \n\t"
00120           "add %2, 4, %2   \n\t"
00121           "subcc %4, 8, %4 \n\t"
00122           "bne 1b          \n\t"
00123           "add %3, 32, %3  \n\t" //delay slot
00124           : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), "=r" (out6)
00125           : "0" (src[0]+(y+srcSliceY)*srcStride[0]), "1" (src[1]+((y+srcSliceY)>>1)*srcStride[1]),
00126             "2" (src[2]+((y+srcSliceY)>>1)*srcStride[2]), "3" (dst[0]+(y+srcSliceY)*dstStride[0]),
00127             "4" (c->dstW),
00128             "5" (c->sparc_coeffs)
00129       );
00130   }
00131 
00132   return srcSliceH;
00133 }
00134 
00135 // FIXME: must be changed to set alpha to 255 instead of 0
00136 static int vis_422P_ARGB32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00137                            int srcSliceH, uint8_t* dst[], int dstStride[]){
00138   int y, out1, out2, out3, out4, out5, out6;
00139 
00140   for(y=0;y < srcSliceH;++y) {
00141       __asm__ volatile (
00142           YUV2RGB_INIT
00143           "wr %%g0, 0xd2, %%asi        \n\t" /* ASI_FL16_P */
00144           "1:                          \n\t"
00145           "ldda [%1] %%asi, %%f2       \n\t"
00146           "ldda [%1+2] %%asi, %%f18    \n\t"
00147           "ldda [%2] %%asi, %%f4       \n\t"
00148           "ldda [%2+2] %%asi, %%f20    \n\t"
00149           "ld [%0], %%f0               \n\t"
00150           "ld [%0+4], %%f16            \n\t"
00151           "fpmerge %%f3, %%f3, %%f2    \n\t"
00152           "fpmerge %%f19, %%f19, %%f18 \n\t"
00153           "fpmerge %%f5, %%f5, %%f4    \n\t"
00154           "fpmerge %%f21, %%f21, %%f20 \n\t"
00155           YUV2RGB_KERNEL
00156           "fzero %%f0 \n\t"
00157           "fpmerge %%f4, %%f6, %%f8    \n\t"  // r,b,t1
00158           "fpmerge %%f20, %%f22, %%f24 \n\t"  // r,b,t1
00159           "fpmerge %%f0, %%f2, %%f10   \n\t"  // 0,g,t2
00160           "fpmerge %%f0, %%f18, %%f26  \n\t"  // 0,g,t2
00161           "fpmerge %%f10, %%f8, %%f4   \n\t"  // t2,t1,msb
00162           "fpmerge %%f26, %%f24, %%f20 \n\t"  // t2,t1,msb
00163           "fpmerge %%f11, %%f9, %%f6   \n\t"  // t2,t1,lsb
00164           "fpmerge %%f27, %%f25, %%f22 \n\t"  // t2,t1,lsb
00165           "std %%f4, [%3]              \n\t"
00166           "std %%f20, [%3+16]          \n\t"
00167           "std %%f6, [%3+8]            \n\t"
00168           "std %%f22, [%3+24]          \n\t"
00169 
00170           "add %0, 8, %0   \n\t"
00171           "add %1, 4, %1   \n\t"
00172           "add %2, 4, %2   \n\t"
00173           "subcc %4, 8, %4 \n\t"
00174           "bne 1b          \n\t"
00175           "add %3, 32, %3  \n\t" //delay slot
00176           : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), "=r" (out6)
00177           : "0" (src[0]+(y+srcSliceY)*srcStride[0]), "1" (src[1]+(y+srcSliceY)*srcStride[1]),
00178             "2" (src[2]+(y+srcSliceY)*srcStride[2]), "3" (dst[0]+(y+srcSliceY)*dstStride[0]),
00179             "4" (c->dstW),
00180             "5" (c->sparc_coeffs)
00181       );
00182   }
00183 
00184   return srcSliceH;
00185 }
00186 
00187 SwsFunc sws_yuv2rgb_init_vis(SwsContext *c) {
00188     c->sparc_coeffs[5]=c->yCoeff;
00189     c->sparc_coeffs[6]=c->vgCoeff;
00190     c->sparc_coeffs[7]=c->vrCoeff;
00191     c->sparc_coeffs[8]=c->ubCoeff;
00192     c->sparc_coeffs[9]=c->ugCoeff;
00193 
00194     c->sparc_coeffs[0]=(((int16_t)c->yOffset*(int16_t)c->yCoeff >>11) & 0xffff) * 0x0001000100010001ULL;
00195     c->sparc_coeffs[1]=(((int16_t)c->uOffset*(int16_t)c->ubCoeff>>11) & 0xffff) * 0x0001000100010001ULL;
00196     c->sparc_coeffs[2]=(((int16_t)c->uOffset*(int16_t)c->ugCoeff>>11) & 0xffff) * 0x0001000100010001ULL;
00197     c->sparc_coeffs[3]=(((int16_t)c->vOffset*(int16_t)c->vgCoeff>>11) & 0xffff) * 0x0001000100010001ULL;
00198     c->sparc_coeffs[4]=(((int16_t)c->vOffset*(int16_t)c->vrCoeff>>11) & 0xffff) * 0x0001000100010001ULL;
00199 
00200     if (c->dstFormat == PIX_FMT_RGB32 && c->srcFormat == PIX_FMT_YUV422P && (c->dstW & 7)==0) {
00201         av_log(c, AV_LOG_INFO, "SPARC VIS accelerated YUV422P -> RGB32 (WARNING: alpha value is wrong)\n");
00202         return vis_422P_ARGB32;
00203     }
00204     else if (c->dstFormat == PIX_FMT_RGB32 && c->srcFormat == PIX_FMT_YUV420P && (c->dstW & 7)==0) {
00205         av_log(c, AV_LOG_INFO, "SPARC VIS accelerated YUV420P -> RGB32 (WARNING: alpha value is wrong)\n");
00206         return vis_420P_ARGB32;
00207     }
00208     return NULL;
00209 }

Generated on Tue Nov 4 2014 12:59:24 for ffmpeg by  doxygen 1.7.1