?? swscale.c.svn-base
字號(hào):
/* * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * FFmpeg 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * the C code (not assembly, mmx, ...) of this file can be used * under the LGPL license too *//* supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8/Y800, YVU9/IF09, PAL8 supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09 {BGR,RGB}{1,4,8,15,16} support dithering unscaled special converters (YV12=I420=IYUV, Y800=Y8) YV12 -> {BGR,RGB}{1,4,8,15,16,24,32} x -> x YUV9 -> YV12 YUV9/YV12 -> Y800 Y800 -> YUV9/YV12 BGR24 -> BGR32 & RGB24 -> RGB32 BGR32 -> BGR24 & RGB32 -> RGB24 BGR15 -> BGR16*//*tested special converters (most are tested actually, but I did not write it down ...) YV12 -> BGR16 YV12 -> YV12 BGR15 -> BGR16 BGR16 -> BGR16 YVU9 -> YV12untested special converters YV12/I420 -> BGR15/BGR24/BGR32 (it is the yuv2rgb stuff, so it should be ok) YV12/I420 -> YV12/I420 YUY2/BGR15/BGR24/BGR32/RGB24/RGB32 -> same format BGR24 -> BGR32 & RGB24 -> RGB32 BGR32 -> BGR24 & RGB32 -> RGB24 BGR24 -> YV12*/#include <inttypes.h>#include <string.h>#include <math.h>#include <stdio.h>#include <unistd.h>#include "config.h"#include <assert.h>#ifdef HAVE_SYS_MMAN_H#include <sys/mman.h>#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)#define MAP_ANONYMOUS MAP_ANON#endif#endif#include "swscale.h"#include "swscale_internal.h"#include "rgb2rgb.h"#include "libavutil/x86_cpu.h"#include "libavutil/bswap.h"#include "libavcodec/opt.h"#undef MOVNTQ#undef PAVGB//#undef HAVE_MMX2//#define HAVE_3DNOW//#undef HAVE_MMX//#undef ARCH_X86//#define WORDS_BIGENDIAN#define DITHER1XBPP#define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit#define RET 0xC3 //near return opcode for X86#ifdef M_PI#define PI M_PI#else#define PI 3.14159265358979323846#endif#define isSupportedIn(x) ( \ (x)==PIX_FMT_YUV420P \ || (x)==PIX_FMT_YUVA420P \ || (x)==PIX_FMT_YUYV422 \ || (x)==PIX_FMT_UYVY422 \ || (x)==PIX_FMT_RGB32 \ || (x)==PIX_FMT_BGR24 \ || (x)==PIX_FMT_BGR565 \ || (x)==PIX_FMT_BGR555 \ || (x)==PIX_FMT_BGR32 \ || (x)==PIX_FMT_RGB24 \ || (x)==PIX_FMT_RGB565 \ || (x)==PIX_FMT_RGB555 \ || (x)==PIX_FMT_GRAY8 \ || (x)==PIX_FMT_YUV410P \ || (x)==PIX_FMT_GRAY16BE \ || (x)==PIX_FMT_GRAY16LE \ || (x)==PIX_FMT_YUV444P \ || (x)==PIX_FMT_YUV422P \ || (x)==PIX_FMT_YUV411P \ || (x)==PIX_FMT_PAL8 \ || (x)==PIX_FMT_BGR8 \ || (x)==PIX_FMT_RGB8 \ || (x)==PIX_FMT_BGR4_BYTE \ || (x)==PIX_FMT_RGB4_BYTE \ || (x)==PIX_FMT_YUV440P \ )#define isSupportedOut(x) ( \ (x)==PIX_FMT_YUV420P \ || (x)==PIX_FMT_YUYV422 \ || (x)==PIX_FMT_UYVY422 \ || (x)==PIX_FMT_YUV444P \ || (x)==PIX_FMT_YUV422P \ || (x)==PIX_FMT_YUV411P \ || isRGB(x) \ || isBGR(x) \ || (x)==PIX_FMT_NV12 \ || (x)==PIX_FMT_NV21 \ || (x)==PIX_FMT_GRAY16BE \ || (x)==PIX_FMT_GRAY16LE \ || (x)==PIX_FMT_GRAY8 \ || (x)==PIX_FMT_YUV410P \ )#define isPacked(x) ( \ (x)==PIX_FMT_PAL8 \ || (x)==PIX_FMT_YUYV422 \ || (x)==PIX_FMT_UYVY422 \ || isRGB(x) \ || isBGR(x) \ )#define RGB2YUV_SHIFT 16#define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))#define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))#define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))#define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))#define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))#define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))#define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))#define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))#define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))extern const int32_t Inverse_Table_6_9[8][4];/*NOTESSpecial versions: fast Y 1:1 scaling (no interpolation in y direction)TODOmore intelligent misalignment avoidance for the horizontal scalerwrite special vertical cubic upscale versionOptimize C code (yv12 / minmax)add support for packed pixel yuv input & outputadd support for Y8 outputoptimize bgr24 & bgr32add BGR4 output supportwrite special BGR->BGR scaler*/#if defined(ARCH_X86) && defined (CONFIG_GPL)DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL;DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL;DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL;DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL;DECLARE_ASM_CONST(8, uint64_t, bm00001111)=0x00000000FFFFFFFFLL;DECLARE_ASM_CONST(8, uint64_t, bm00000111)=0x0000000000FFFFFFLL;DECLARE_ASM_CONST(8, uint64_t, bm11111000)=0xFFFFFFFFFF000000LL;DECLARE_ASM_CONST(8, uint64_t, bm01010101)=0x00FF00FF00FF00FFLL;static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither;static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither;static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither;static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither;const DECLARE_ALIGNED(8, uint64_t, ff_dither4[2]) = { 0x0103010301030103LL, 0x0200020002000200LL,};const DECLARE_ALIGNED(8, uint64_t, ff_dither8[2]) = { 0x0602060206020602LL, 0x0004000400040004LL,};DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL;DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL;DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL;DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL;DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL;DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL;DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL;DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL;DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL;#ifdef FAST_BGR2YV12DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL;DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL;DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL;#elseDECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL;DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL;DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL;#endif /* FAST_BGR2YV12 */DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL;DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL;DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL;#endif /* defined(ARCH_X86) */// clipping helper table for C implementations:static unsigned char clip_table[768];static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b);extern const uint8_t dither_2x2_4[2][8];extern const uint8_t dither_2x2_8[2][8];extern const uint8_t dither_8x8_32[8][8];extern const uint8_t dither_8x8_73[8][8];extern const uint8_t dither_8x8_220[8][8];static const char * sws_context_to_name(void * ptr) { return "swscaler";}#define OFFSET(x) offsetof(SwsContext, x)#define DEFAULT 0#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAMstatic const AVOption options[] = { { "sws_flags", "scaler/cpu flags", OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, 0, UINT_MAX, VE, "sws_flags" }, { "fast_bilinear", "fast bilinear", 0, FF_OPT_TYPE_CONST, SWS_FAST_BILINEAR, INT_MIN, INT_MAX, VE, "sws_flags" }, { "bilinear", "bilinear", 0, FF_OPT_TYPE_CONST, SWS_BILINEAR, INT_MIN, INT_MAX, VE, "sws_flags" }, { "bicubic", "bicubic", 0, FF_OPT_TYPE_CONST, SWS_BICUBIC, INT_MIN, INT_MAX, VE, "sws_flags" }, { "experimental", "experimental", 0, FF_OPT_TYPE_CONST, SWS_X, INT_MIN, INT_MAX, VE, "sws_flags" }, { "neighbor", "nearest neighbor", 0, FF_OPT_TYPE_CONST, SWS_POINT, INT_MIN, INT_MAX, VE, "sws_flags" }, { "area", "averaging area", 0, FF_OPT_TYPE_CONST, SWS_AREA, INT_MIN, INT_MAX, VE, "sws_flags" }, { "bicublin", "luma bicubic, chroma bilinear", 0, FF_OPT_TYPE_CONST, SWS_BICUBLIN, INT_MIN, INT_MAX, VE, "sws_flags" }, { "gauss", "gaussian", 0, FF_OPT_TYPE_CONST, SWS_GAUSS, INT_MIN, INT_MAX, VE, "sws_flags" }, { "sinc", "sinc", 0, FF_OPT_TYPE_CONST, SWS_SINC, INT_MIN, INT_MAX, VE, "sws_flags" }, { "lanczos", "lanczos", 0, FF_OPT_TYPE_CONST, SWS_LANCZOS, INT_MIN, INT_MAX, VE, "sws_flags" }, { "spline", "natural bicubic spline", 0, FF_OPT_TYPE_CONST, SWS_SPLINE, INT_MIN, INT_MAX, VE, "sws_flags" }, { "print_info", "print info", 0, FF_OPT_TYPE_CONST, SWS_PRINT_INFO, INT_MIN, INT_MAX, VE, "sws_flags" }, { "accurate_rnd", "accurate rounding", 0, FF_OPT_TYPE_CONST, SWS_ACCURATE_RND, INT_MIN, INT_MAX, VE, "sws_flags" }, { "mmx", "MMX SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_MMX, INT_MIN, INT_MAX, VE, "sws_flags" }, { "mmx2", "MMX2 SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_MMX2, INT_MIN, INT_MAX, VE, "sws_flags" }, { "3dnow", "3DNOW SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_3DNOW, INT_MIN, INT_MAX, VE, "sws_flags" }, { "altivec", "AltiVec SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_ALTIVEC, INT_MIN, INT_MAX, VE, "sws_flags" }, { "bfin", "Blackfin SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_BFIN, INT_MIN, INT_MAX, VE, "sws_flags" }, { "full_chroma_int", "full chroma interpolation", 0 , FF_OPT_TYPE_CONST, SWS_FULL_CHR_H_INT, INT_MIN, INT_MAX, VE, "sws_flags" }, { "full_chroma_inp", "full chroma input", 0 , FF_OPT_TYPE_CONST, SWS_FULL_CHR_H_INP, INT_MIN, INT_MAX, VE, "sws_flags" }, { NULL }};#undef VE#undef DEFAULTstatic const AVClass sws_context_class = { "SWScaler", sws_context_to_name, options };const char *sws_format_name(enum PixelFormat format){ switch (format) { case PIX_FMT_YUV420P: return "yuv420p"; case PIX_FMT_YUVA420P: return "yuva420p"; case PIX_FMT_YUYV422: return "yuyv422"; case PIX_FMT_RGB24: return "rgb24"; case PIX_FMT_BGR24: return "bgr24"; case PIX_FMT_YUV422P: return "yuv422p"; case PIX_FMT_YUV444P: return "yuv444p"; case PIX_FMT_RGB32: return "rgb32"; case PIX_FMT_YUV410P: return "yuv410p"; case PIX_FMT_YUV411P: return "yuv411p"; case PIX_FMT_RGB565: return "rgb565"; case PIX_FMT_RGB555: return "rgb555"; case PIX_FMT_GRAY16BE: return "gray16be"; case PIX_FMT_GRAY16LE: return "gray16le"; case PIX_FMT_GRAY8: return "gray8"; case PIX_FMT_MONOWHITE: return "mono white"; case PIX_FMT_MONOBLACK: return "mono black"; case PIX_FMT_PAL8: return "Palette"; case PIX_FMT_YUVJ420P: return "yuvj420p"; case PIX_FMT_YUVJ422P: return "yuvj422p"; case PIX_FMT_YUVJ444P: return "yuvj444p"; case PIX_FMT_XVMC_MPEG2_MC: return "xvmc_mpeg2_mc"; case PIX_FMT_XVMC_MPEG2_IDCT: return "xvmc_mpeg2_idct"; case PIX_FMT_UYVY422: return "uyvy422"; case PIX_FMT_UYYVYY411: return "uyyvyy411"; case PIX_FMT_RGB32_1: return "rgb32x"; case PIX_FMT_BGR32_1: return "bgr32x"; case PIX_FMT_BGR32: return "bgr32"; case PIX_FMT_BGR565: return "bgr565"; case PIX_FMT_BGR555: return "bgr555"; case PIX_FMT_BGR8: return "bgr8"; case PIX_FMT_BGR4: return "bgr4"; case PIX_FMT_BGR4_BYTE: return "bgr4 byte"; case PIX_FMT_RGB8: return "rgb8"; case PIX_FMT_RGB4: return "rgb4"; case PIX_FMT_RGB4_BYTE: return "rgb4 byte"; case PIX_FMT_NV12: return "nv12"; case PIX_FMT_NV21: return "nv21"; case PIX_FMT_YUV440P: return "yuv440p"; default: return "Unknown format"; }}static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW){ //FIXME Optimize (just quickly writen not opti..) int i; for (i=0; i<dstW; i++) { int val=1<<18; int j; for (j=0; j<lumFilterSize; j++) val += lumSrc[j][i] * lumFilter[j]; dest[i]= av_clip_uint8(val>>19); } if (uDest) for (i=0; i<chrDstW; i++) { int u=1<<18; int v=1<<18; int j; for (j=0; j<chrFilterSize; j++) { u += chrSrc[j][i] * chrFilter[j];
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -