SDL_yuv_mmx.rar

  • PUDN用户
    了解作者
  • Unix_Linux
    开发工具
  • 4KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2013-05-31 11:44
    上传日期
This MMX assembler is my first assembler/MMX program ever.
SDL_yuv_mmx.rar
  • SDL_yuv_mmx.c
    18.7KB
内容介绍
/* SDL - Simple DirectMedia Layer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Sam Lantinga slouken@libsdl.org */ #include "SDL_config.h" #if (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES #include "SDL_stdinc.h" #include "mmx.h" /* *INDENT-OFF* */ static mmx_t MMX_0080w = { .ud = {0x00800080, 0x00800080} }; static mmx_t MMX_00FFw = { .ud = {0x00ff00ff, 0x00ff00ff} }; static mmx_t MMX_FF00w = { .ud = {0xff00ff00, 0xff00ff00} }; static mmx_t MMX_Ycoeff = { .uw = {0x004a, 0x004a, 0x004a, 0x004a} }; static mmx_t MMX_UbluRGB = { .uw = {0x0072, 0x0072, 0x0072, 0x0072} }; static mmx_t MMX_VredRGB = { .uw = {0x0059, 0x0059, 0x0059, 0x0059} }; static mmx_t MMX_UgrnRGB = { .uw = {0xffea, 0xffea, 0xffea, 0xffea} }; static mmx_t MMX_VgrnRGB = { .uw = {0xffd2, 0xffd2, 0xffd2, 0xffd2} }; static mmx_t MMX_Ublu5x5 = { .uw = {0x0081, 0x0081, 0x0081, 0x0081} }; static mmx_t MMX_Vred5x5 = { .uw = {0x0066, 0x0066, 0x0066, 0x0066} }; static mmx_t MMX_Ugrn565 = { .uw = {0xffe8, 0xffe8, 0xffe8, 0xffe8} }; static mmx_t MMX_Vgrn565 = { .uw = {0xffcd, 0xffcd, 0xffcd, 0xffcd} }; static mmx_t MMX_red565 = { .uw = {0xf800, 0xf800, 0xf800, 0xf800} }; static mmx_t MMX_grn565 = { .uw = {0x07e0, 0x07e0, 0x07e0, 0x07e0} }; /** This MMX assembler is my first assembler/MMX program ever. Thus it maybe buggy. Send patches to: mvogt@rhrk.uni-kl.de After it worked fine I have "obfuscated" the code a bit to have more parallism in the MMX units. This means I moved initilisation around and delayed other instruction. Performance measurement did not show that this brought any advantage but in theory it _should_ be faster this way. The overall performanve gain to the C based dither was 30%-40%. The MMX routine calculates 256bit=8RGB values in each cycle (4 for row1 & 4 for row2) The red/green/blue.. coefficents are taken from the mpeg_play player. They look nice, but I dont know if you can have better values, to avoid integer rounding errors. IMPORTANT: ========== It is a requirement that the cr/cb/lum are 8 byte aligned and the out are 16byte aligned or you will/may get segfaults */ void ColorRGBDitherYV12MMX1X( int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod ) { Uint32 *row1; Uint32 *row2; unsigned char* y = lum +cols*rows; // Pointer to the end int x = 0; row1 = (Uint32 *)out; // 32 bit target row2 = (Uint32 *)out+cols+mod; // start of second row mod = (mod+cols+mod)*4; // increment for row1 in byte __asm__ __volatile__ ( // tap dance to workaround the inability to use %%ebx at will... // move one thing to the stack... "pushl $0\n" // save a slot on the stack. "pushl %%ebx\n" // save %%ebx. "movl %0, %%ebx\n" // put the thing in ebx. "movl %%ebx,4(%%esp)\n" // put the thing in the stack slot. "popl %%ebx\n" // get back %%ebx (the PIC register). ".align 8\n" "1:\n" // create Cr (result in mm1) "pushl %%ebx\n" "movl 4(%%esp),%%ebx\n" "movd (%%ebx),%%mm1\n" // 0 0 0 0 v3 v2 v1 v0 "popl %%ebx\n" "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 "movd (%2), %%mm2\n" // 0 0 0 0 l3 l2 l1 l0 "punpcklbw %%mm7,%%mm1\n" // 0 v3 0 v2 00 v1 00 v0 "punpckldq %%mm1,%%mm1\n" // 00 v1 00 v0 00 v1 00 v0 "psubw %9,%%mm1\n" // mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 // create Cr_g (result in mm0) "movq %%mm1,%%mm0\n" // r1 r1 r0 r0 r1 r1 r0 r0 "pmullw %10,%%mm0\n" // red*-46dec=0.7136*64 "pmullw %11,%%mm1\n" // red*89dec=1.4013*64 "psraw $6, %%mm0\n" // red=red/64 "psraw $6, %%mm1\n" // red=red/64 // create L1 L2 (result in mm2,mm4) // L2=lum+cols "movq (%2,%4),%%mm3\n" // 0 0 0 0 L3 L2 L1 L0 "punpckldq %%mm3,%%mm2\n" // L3 L2 L1 L0 l3 l2 l1 l0 "movq %%mm2,%%mm4\n" // L3 L2 L1 L0 l3 l2 l1 l0 "pand %12,%%mm2\n" // L3 0 L1 0 l3 0 l1 0 "pand %13,%%mm4\n" // 0 L2 0 L0 0 l2 0 l0 "psrlw $8,%%mm2\n" // 0 L3 0 L1 0 l3 0 l1 // create R (result in mm6) "movq %%mm2,%%mm5\n" // 0 L3 0 L1 0 l3 0 l1 "movq %%mm4,%%mm6\n" // 0 L2 0 L0 0 l2 0 l0 "paddsw %%mm1, %%mm5\n" // lum1+red:x R3 x R1 x r3 x r1 "paddsw %%mm1, %%mm6\n" // lum1+red:x R2 x R0 x r2 x r0 "packuswb %%mm5,%%mm5\n" // R3 R1 r3 r1 R3 R1 r3 r1 "packuswb %%mm6,%%mm6\n" // R2 R0 r2 r0 R2 R0 r2 r0 "pxor %%mm7,%%mm7\n" // 00 00 00 00 00 00 00 00 "punpcklbw %%mm5,%%mm6\n" // R3 R2 R1 R0 r3 r2 r1 r0 // create Cb (result in mm1) "movd (%1), %%mm1\n" // 0 0 0 0 u3 u2 u1 u0 "punpcklbw %%mm7,%%mm1\n" // 0 u3 0 u2 00 u1 00 u0 "punpckldq %%mm1,%%mm1\n" // 00 u1 00 u0 00 u1 00 u0 "psubw %9,%%mm1\n" // mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 // create Cb_g (result in mm5) "movq %%mm1,%%mm5\n" // u1 u1 u0 u0 u1 u1 u0 u0 "pmullw %14,%%mm5\n" // blue*-109dec=1.7129*64 "pmullw %15,%%mm1\n" // blue*114dec=1.78125*64 "psraw $6, %%mm5\n" // blue=red/64 "psraw $6, %%mm1\n" // blue=blue/64 // create G (result in mm7) "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 "movq %%mm4,%%mm7\n" // 0 L2 0 L0 0 l2 0 l1 "paddsw %%mm5, %%mm3\n" // lum1+Cb_g:x G3t x G1t x g3t x g1t "paddsw %%mm5, %%mm7\n" // lum1+Cb_g:x G2t x G0t x g2t x g0t "paddsw %%mm0, %%mm3\n" // lum1+Cr_g:x G3 x G1 x g3 x g1 "paddsw %%mm0, %%mm7\n" // lum1+blue:x G2 x G0 x g2 x g0 "packuswb %%mm3,%%mm3\n" // G3 G1 g3 g1 G3 G1 g3 g1 "packuswb %%mm7,%%mm7\n" // G2 G0 g2 g0 G2 G0 g2 g0 "punpcklbw %%mm3,%%mm7\n" // G3 G2 G1 G0 g3 g2 g1 g0 // create B (result in mm5) "movq %%mm2,%%mm3\n" // 0 L3 0 L1 0 l3 0 l1 "movq %%mm4,%%mm5\n" // 0 L2 0 L0 0 l2 0 l1 "paddsw %%mm1, %%mm3\n" // lum1+blue:x B3 x B1 x b3 x b1 "paddsw %%mm1, %%mm5\n" // lum1+blue:x B2 x B0 x b2 x b0 "packuswb %%mm3,%%mm3\n" // B3 B1 b3 b1 B3 B1 b3 b1 "packuswb %%mm5,%%mm5\n" // B2 B0 b2 b0 B2 B0 b2 b0 "punpcklbw %%mm3,%%mm5\n" // B3 B2 B1 B0 b3 b2 b1 b0 // fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 "pxor %%mm4,%%mm4\n" // 0 0 0 0 0 0 0 0 "movq %%mm6,%%mm1\n" // R3 R2 R1 R0 r3 r2 r1 r0 "movq %%mm5,%%mm3\n" // B3 B2 B1 B0 b3 b2 b1 b0 // process lower lum "punpcklbw %%mm4,%%mm1\n" // 0 r3 0 r2 0 r1 0 r0 "punpcklbw %%mm4,%%mm3\n" // 0 b3 0 b2 0 b1 0 b0 "movq %%mm1,%%mm2\n" // 0 r3 0 r2 0 r1 0 r0 "movq %%mm3,%%mm0\n" // 0 b3 0 b2 0 b1 0 b0 "punpcklwd %%mm1,%%mm3\n" // 0 r1 0 b1 0 r0 0 b0 "punpckhwd %%mm2,%%mm0\n" // 0 r3 0 b3 0 r2 0 b2 "pxor %%mm2,%%mm2\n" // 0 0 0 0 0 0 0 0 "movq %%mm7,%%mm1\n"
评论
    相关推荐
    • yuv420ToArgb_MMX(2.0).zip
      yuv420(yuv12) to ARGB using MMX assembly with VC and test successfully in direct draw ARGB mode by Jesse stone 100% work
    • RGB2YUV.rar
      采用intel奔腾2以后处理器支持的mmx指令集,宽位处理,将一张BMP图像转换成YUV420,大大提高i在pc上的运行速度。
    • yuv2rgb.rar
      yuv转rgb的MMX优化代码,主要包含yuv转rgb的优化实现部分。
    • FFMPEG_H264.rar
      视频解码器。对yuv文件进行解码操作。输入输出文件路径在main中。可以在vs2005直接运行
    • ActiveYUVTORGB.rar
      图像处理中,把YUV格式转换成RGB格式,通过MMX指令实现。
    • SDL_yuv_sw.rar
      This is the software implementation of the YUV video overlay support.
    • X264-32位.rar
      x264编码,利用opencv操作x264库对yuv格式的视频进行编码,进行压缩,以便于传输,保真率高
    • yuvasm.rar
      YUV to RGB coverter with Intel MMX technology *
    • Visual C++音频视频处理技术及工程实践(含源码1/2)
      14.3.1 YUV原始视频数据及其显示 559 14.3.2 VC平台下编译和运行XviD CODEC 559 14.3.3 CODEC在DSP下软仿真和硬仿真 562 14.4 系统效果展示 562 14.5 本章小结 563 第15章 X264实现H.264/AVC视频编码 565 15.1...
    • NS2example.rar
      在ns2下实现无线传感器网络仿真,多个节点进行网络活动