00001 /* 00002 * software YUV to RGB converter 00003 * 00004 * Copyright (C) 2009 Konstantin Shishkov 00005 * 00006 * MMX/MMX2 template stuff (needed for fast movntq support), 00007 * 1,4,8bpp support and context / deglobalize stuff 00008 * by Michael Niedermayer (michaelni@gmx.at) 00009 * 00010 * This file is part of FFmpeg. 00011 * 00012 * FFmpeg is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Lesser General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2.1 of the License, or (at your option) any later version. 00016 * 00017 * FFmpeg is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Lesser General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with FFmpeg; if not, write to the Free Software 00024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00025 */ 00026 00027 #include <stdio.h> 00028 #include <stdlib.h> 00029 #include <inttypes.h> 00030 #include <assert.h> 00031 00032 #include "config.h" 00033 #include "libswscale/rgb2rgb.h" 00034 #include "libswscale/swscale.h" 00035 #include "libswscale/swscale_internal.h" 00036 #include "libavutil/x86_cpu.h" 00037 00038 #define DITHER1XBPP // only for MMX 00039 00040 /* hope these constant values are cache line aligned */ 00041 DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL; 00042 DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL; 00043 DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL; 00044 00045 //MMX versions 00046 #undef RENAME 00047 #undef HAVE_MMX2 00048 #undef HAVE_AMD3DNOW 00049 #define HAVE_MMX2 0 00050 #define HAVE_AMD3DNOW 0 00051 #define RENAME(a) a ## _MMX 00052 #if CONFIG_GPL 00053 #include "yuv2rgb_template.c" 00054 #else 00055 #include "yuv2rgb_template2.c" 00056 #endif 00057 00058 //MMX2 versions 00059 #undef RENAME 00060 #undef HAVE_MMX2 00061 #define HAVE_MMX2 1 00062 #define RENAME(a) a ## _MMX2 00063 #if CONFIG_GPL 00064 #include "yuv2rgb_template.c" 00065 #else 00066 #include "yuv2rgb_template2.c" 00067 #endif 00068 00069 SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) 00070 { 00071 if (c->flags & SWS_CPU_CAPS_MMX2) { 00072 switch (c->dstFormat) { 00073 case PIX_FMT_RGB32: 00074 if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { 00075 if (HAVE_7REGS) return yuva420_rgb32_MMX2; 00076 break; 00077 } else return yuv420_rgb32_MMX2; 00078 case PIX_FMT_BGR32: 00079 if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { 00080 if (HAVE_7REGS) return yuva420_bgr32_MMX2; 00081 break; 00082 } else return yuv420_bgr32_MMX2; 00083 case PIX_FMT_RGB24: return yuv420_rgb24_MMX2; 00084 case PIX_FMT_BGR24: return yuv420_bgr24_MMX2; 00085 case PIX_FMT_RGB565: return yuv420_rgb16_MMX2; 00086 case PIX_FMT_RGB555: return yuv420_rgb15_MMX2; 00087 } 00088 } 00089 if (c->flags & SWS_CPU_CAPS_MMX) { 00090 switch (c->dstFormat) { 00091 case PIX_FMT_RGB32: 00092 if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { 00093 if (HAVE_7REGS) return yuva420_rgb32_MMX; 00094 break; 00095 } else return yuv420_rgb32_MMX; 00096 case PIX_FMT_BGR32: 00097 if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { 00098 if (HAVE_7REGS) return yuva420_bgr32_MMX; 00099 break; 00100 } else return yuv420_bgr32_MMX; 00101 case PIX_FMT_RGB24: return yuv420_rgb24_MMX; 00102 case PIX_FMT_BGR24: return yuv420_bgr24_MMX; 00103 case PIX_FMT_RGB565: return yuv420_rgb16_MMX; 00104 case PIX_FMT_RGB555: return yuv420_rgb15_MMX; 00105 } 00106 } 00107 00108 return NULL; 00109 }