diff options
Diffstat (limited to 'contrib/ffmpeg/libswscale')
-rw-r--r-- | contrib/ffmpeg/libswscale/Makefile | 14 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/cs_test.c | 29 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/rgb2rgb.c | 12 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/swscale.c | 240 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/swscale.h | 4 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/swscale_altivec_template.c | 10 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/swscale_internal.h | 24 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/swscale_template.c | 77 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/yuv2rgb.c | 31 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/yuv2rgb_altivec.c | 18 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/yuv2rgb_init.c | 412 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/yuv2rgb_mlib.c | 5 | ||||
-rw-r--r-- | contrib/ffmpeg/libswscale/yuv2rgb_template.c | 12 |
13 files changed, 676 insertions, 212 deletions
diff --git a/contrib/ffmpeg/libswscale/Makefile b/contrib/ffmpeg/libswscale/Makefile index 82e9bfc02..a1c25a76a 100644 --- a/contrib/ffmpeg/libswscale/Makefile +++ b/contrib/ffmpeg/libswscale/Makefile @@ -2,25 +2,23 @@ include ../config.mak NAME=swscale -ifeq ($(BUILD_SHARED),yes) LIBVERSION=$(SWSVERSION) LIBMAJOR=$(SWSMAJOR) -endif EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS) -OBJS= swscale.o rgb2rgb.o yuv2rgb.o -ifeq ($(TARGET_ALTIVEC),yes) -OBJS+= yuv2rgb_altivec.o -endif +OBJS= swscale.o rgb2rgb.o + +OBJS-$(TARGET_ALTIVEC) += yuv2rgb_altivec.o +OBJS-$(CONFIG_GPL) += yuv2rgb.o HEADERS = swscale.h rgb2rgb.h include ../common.mak -cs_test: cs_test.c $(LIB) +cs_test: cs_test.o $(LIB) -swscale-example: swscale-example.o $(LIB) +swscale-example: swscale-example.o $(LIB) -lm clean:: rm -f cs_test swscale-example diff --git a/contrib/ffmpeg/libswscale/cs_test.c b/contrib/ffmpeg/libswscale/cs_test.c index 6b2deab3e..cd0100618 100644 --- a/contrib/ffmpeg/libswscale/cs_test.c +++ b/contrib/ffmpeg/libswscale/cs_test.c @@ -23,7 +23,6 @@ #include <unistd.h> #include <stdlib.h> #include <inttypes.h> -#include <malloc.h> #include "swscale.h" #include "rgb2rgb.h" @@ -32,9 +31,6 @@ #define srcByte 0x55 #define dstByte 0xBB -#ifdef __APPLE_CC__ -#define memalign(x,y) malloc(y) -#endif static int cpu_caps; @@ -54,7 +50,7 @@ static char *args_parse(int argc, char *argv[]) cpu_caps |= SWS_CPU_CAPS_3DNOW; break; default: - fprintf(stderr, "Unknown option %c\n", o); + av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o); } } @@ -64,14 +60,14 @@ static char *args_parse(int argc, char *argv[]) int main(int argc, char **argv) { int i, funcNum; - uint8_t *srcBuffer= (uint8_t*)memalign(128, SIZE); - uint8_t *dstBuffer= (uint8_t*)memalign(128, SIZE); + uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE); + uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE); int failedNum=0; int passedNum=0; - printf("memory corruption test ...\n"); + av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n"); args_parse(argc, argv); - fprintf(stderr, "CPU capabilities forced to %x\n", cpu_caps); + av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps); sws_rgb2rgb_init(cpu_caps); for(funcNum=0; funcNum<100; funcNum++){ @@ -80,16 +76,16 @@ int main(int argc, char **argv) int srcBpp=0; int dstBpp=0; - printf("."); fflush(stdout); + av_log(NULL, AV_LOG_INFO,"."); memset(srcBuffer, srcByte, SIZE); for(width=32; width<64; width++){ int dstOffset; - for(dstOffset=128; dstOffset<196; dstOffset++){ + for(dstOffset=128; dstOffset<196; dstOffset+=4){ int srcOffset; memset(dstBuffer, dstByte, SIZE); - for(srcOffset=128; srcOffset<196; srcOffset++){ + for(srcOffset=128; srcOffset<196; srcOffset+=4){ uint8_t *src= srcBuffer+srcOffset; uint8_t *dst= dstBuffer+dstOffset; char *name=NULL; @@ -149,6 +145,7 @@ int main(int argc, char **argv) srcBpp=4; dstBpp=2; name="rgb32to15"; + //((*s++) << TGA_SHIFT32) | TGA_ALPHA32; rgb32to15(src, dst, width*srcBpp); break; case 9: @@ -272,7 +269,7 @@ int main(int argc, char **argv) for(i=0; i<SIZE; i++){ if(srcBuffer[i]!=srcByte){ - printf("src damaged at %d w:%d src:%d dst:%d %s\n", + av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n", i, width, srcOffset, dstOffset, name); failed=1; break; @@ -280,7 +277,7 @@ int main(int argc, char **argv) } for(i=0; i<dstOffset; i++){ if(dstBuffer[i]!=dstByte){ - printf("dst damaged at %d w:%d src:%d dst:%d %s\n", + av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n", i, width, srcOffset, dstOffset, name); failed=1; break; @@ -288,7 +285,7 @@ int main(int argc, char **argv) } for(i=dstOffset + width*dstBpp; i<SIZE; i++){ if(dstBuffer[i]!=dstByte){ - printf("dst damaged at %d w:%d src:%d dst:%d %s\n", + av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n", i, width, srcOffset, dstOffset, name); failed=1; break; @@ -301,6 +298,6 @@ int main(int argc, char **argv) else if(srcBpp) passedNum++; } - printf("%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum); + av_log(NULL, AV_LOG_INFO, "%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum); return failedNum; } diff --git a/contrib/ffmpeg/libswscale/rgb2rgb.c b/contrib/ffmpeg/libswscale/rgb2rgb.c index 2bb5d3355..a938abfc9 100644 --- a/contrib/ffmpeg/libswscale/rgb2rgb.c +++ b/contrib/ffmpeg/libswscale/rgb2rgb.c @@ -91,7 +91,7 @@ void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *sr long srcStride1, long srcStride2, long srcStride3, long dstStride); -#if defined(ARCH_X86) +#if defined(ARCH_X86) && defined(CONFIG_GPL) static const uint64_t mmx_null __attribute__((aligned(8))) = 0x0000000000000000ULL; static const uint64_t mmx_one __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL; static const uint64_t mask32b attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL; @@ -175,7 +175,7 @@ static uint64_t __attribute__((aligned(8))) dither8[2]={ #define RENAME(a) a ## _C #include "rgb2rgb_template.c" -#if defined(ARCH_X86) +#if defined(ARCH_X86) && defined(CONFIG_GPL) //MMX versions #undef RENAME @@ -214,7 +214,7 @@ static uint64_t __attribute__((aligned(8))) dither8[2]={ */ void sws_rgb2rgb_init(int flags){ -#if defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) +#if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)) && defined(CONFIG_GPL) if(flags & SWS_CPU_CAPS_MMX2){ rgb15to16= rgb15to16_MMX2; rgb15to24= rgb15to24_MMX2; @@ -341,7 +341,7 @@ void sws_rgb2rgb_init(int flags){ } /** - * Pallete is assumed to contain bgr32 + * Palette is assumed to contain BGR32. */ void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { @@ -391,7 +391,7 @@ void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const ui } /** - * Pallete is assumed to contain bgr32 + * Palette is assumed to contain BGR32. */ void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { @@ -446,7 +446,7 @@ void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const ui } /** - * Pallete is assumed to contain bgr15, see rgb32to15 to convert the palette + * Palette is assumed to contain BGR15, see rgb32to15 to convert the palette. */ void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { diff --git a/contrib/ffmpeg/libswscale/swscale.c b/contrib/ffmpeg/libswscale/swscale.c index eb9092c19..f6a23425b 100644 --- a/contrib/ffmpeg/libswscale/swscale.c +++ b/contrib/ffmpeg/libswscale/swscale.c @@ -22,7 +22,7 @@ */ /* - supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8/Y800, YVU9/IF09 + 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 @@ -61,11 +61,6 @@ untested special converters #include <unistd.h> #include "config.h" #include <assert.h> -#ifdef HAVE_MALLOC_H -#include <malloc.h> -#else -#include <stdlib.h> -#endif #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) @@ -112,14 +107,17 @@ untested special converters || (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_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) #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_YUYV422 || (x)==PIX_FMT_UYVY422 ||isRGB(x) || isBGR(x)) +#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)) @@ -149,7 +147,7 @@ add BGR4 output support write special BGR->BGR scaler */ -#if defined(ARCH_X86) +#if defined(ARCH_X86) && defined (CONFIG_GPL) static uint64_t attribute_used __attribute__((aligned(8))) bF8= 0xF8F8F8F8F8F8F8F8LL; static uint64_t attribute_used __attribute__((aligned(8))) bFC= 0xFCFCFCFCFCFCFCFCLL; static uint64_t __attribute__((aligned(8))) w10= 0x0010001000100010LL; @@ -208,6 +206,12 @@ 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"; +} + +static AVClass sws_context_class = { "SWScaler", sws_context_to_name, NULL }; + char *sws_format_name(enum PixelFormat format) { switch (format) { @@ -290,7 +294,7 @@ char *sws_format_name(enum PixelFormat format) } } -#if defined(ARCH_X86) +#if defined(ARCH_X86) && defined (CONFIG_GPL) void in_asm_used_var_warning_killer() { volatile int i= bF8+bFC+w10+ @@ -313,7 +317,7 @@ static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilt for(j=0; j<lumFilterSize; j++) val += lumSrc[j][i] * lumFilter[j]; - dest[i]= FFMIN(FFMAX(val>>19, 0), 255); + dest[i]= av_clip_uint8(val>>19); } if(uDest != NULL) @@ -328,8 +332,8 @@ static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilt v += chrSrc[j][i + 2048] * chrFilter[j]; } - uDest[i]= FFMIN(FFMAX(u>>19, 0), 255); - vDest[i]= FFMIN(FFMAX(v>>19, 0), 255); + uDest[i]= av_clip_uint8(u>>19); + vDest[i]= av_clip_uint8(v>>19); } } @@ -346,7 +350,7 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil for(j=0; j<lumFilterSize; j++) val += lumSrc[j][i] * lumFilter[j]; - dest[i]= FFMIN(FFMAX(val>>19, 0), 255); + dest[i]= av_clip_uint8(val>>19); } if(uDest == NULL) @@ -364,8 +368,8 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil v += chrSrc[j][i + 2048] * chrFilter[j]; } - uDest[2*i]= FFMIN(FFMAX(u>>19, 0), 255); - uDest[2*i+1]= FFMIN(FFMAX(v>>19, 0), 255); + uDest[2*i]= av_clip_uint8(u>>19); + uDest[2*i+1]= av_clip_uint8(v>>19); } else for(i=0; i<chrDstW; i++) @@ -379,8 +383,8 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil v += chrSrc[j][i + 2048] * chrFilter[j]; } - uDest[2*i]= FFMIN(FFMAX(v>>19, 0), 255); - uDest[2*i+1]= FFMIN(FFMAX(u>>19, 0), 255); + uDest[2*i]= av_clip_uint8(v>>19); + uDest[2*i+1]= av_clip_uint8(u>>19); } } @@ -391,7 +395,7 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil int Y2=1<<18;\ int U=1<<18;\ int V=1<<18;\ - type *r, *b, *g;\ + type attribute_unused *r, *b, *g;\ const int i2= 2*i;\ \ for(j=0; j<lumFilterSize; j++)\ @@ -422,9 +426,9 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil #define YSCALE_YUV_2_RGBX_C(type) \ YSCALE_YUV_2_PACKEDX_C(type)\ - r = c->table_rV[V];\ - g = c->table_gU[U] + c->table_gV[V];\ - b = c->table_bU[U];\ + r = (type *)c->table_rV[V];\ + g = (type *)(c->table_gU[U] + c->table_gV[V]);\ + b = (type *)c->table_bU[U];\ #define YSCALE_YUV_2_PACKED2_C \ for(i=0; i<(dstW>>1); i++){\ @@ -437,9 +441,9 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil #define YSCALE_YUV_2_RGB2_C(type) \ YSCALE_YUV_2_PACKED2_C\ type *r, *b, *g;\ - r = c->table_rV[V];\ - g = c->table_gU[U] + c->table_gV[V];\ - b = c->table_bU[U];\ + r = (type *)c->table_rV[V];\ + g = (type *)(c->table_gU[U] + c->table_gV[V]);\ + b = (type *)c->table_bU[U];\ #define YSCALE_YUV_2_PACKED1_C \ for(i=0; i<(dstW>>1); i++){\ @@ -452,9 +456,9 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil #define YSCALE_YUV_2_RGB1_C(type) \ YSCALE_YUV_2_PACKED1_C\ type *r, *b, *g;\ - r = c->table_rV[V];\ - g = c->table_gU[U] + c->table_gV[V];\ - b = c->table_bU[U];\ + r = (type *)c->table_rV[V];\ + g = (type *)(c->table_gU[U] + c->table_gV[V]);\ + b = (type *)c->table_bU[U];\ #define YSCALE_YUV_2_PACKED1B_C \ for(i=0; i<(dstW>>1); i++){\ @@ -467,9 +471,9 @@ static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFil #define YSCALE_YUV_2_RGB1B_C(type) \ YSCALE_YUV_2_PACKED1B_C\ type *r, *b, *g;\ - r = c->table_rV[V];\ - g = c->table_gU[U] + c->table_gV[V];\ - b = c->table_bU[U];\ + r = (type *)c->table_rV[V];\ + g = (type *)(c->table_gU[U] + c->table_gV[V]);\ + b = (type *)c->table_bU[U];\ #define YSCALE_YUV_2_ANYRGB_C(func, func2)\ switch(c->dstFormat)\ @@ -803,27 +807,27 @@ static inline void yuv2packedXinC(SwsContext *c, int16_t *lumFilter, int16_t **l //Note: we have C, X86, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one //Plain C versions -#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT) +#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT) || !defined(CONFIG_GPL) #define COMPILE_C #endif #ifdef ARCH_POWERPC -#if defined (HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT) +#if (defined (HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL) #define COMPILE_ALTIVEC #endif //HAVE_ALTIVEC #endif //ARCH_POWERPC #if defined(ARCH_X86) -#if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT) +#if ((defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL) #define COMPILE_MMX #endif -#if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT) +#if (defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL) #define COMPILE_MMX2 #endif -#if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT) +#if ((defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL) #define COMPILE_3DNOW #endif #endif //ARCH_X86 || ARCH_X86_64 @@ -1201,7 +1205,7 @@ static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outF *outFilterSize= filterSize; if(flags&SWS_PRINT_INFO) - MSG_V("SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); + av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); /* try to reduce the filter-size (step2 reduce it) */ for(i=0; i<dstW; i++) { @@ -1250,8 +1254,7 @@ static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outF // Note the +1 is for the MMXscaler which reads over the end /* align at 16 for AltiVec (needed by hScale_altivec_real) */ - *outFilter= av_malloc(*outFilterSize*(dstW+1)*sizeof(int16_t)); - memset(*outFilter, 0, *outFilterSize*(dstW+1)*sizeof(int16_t)); + *outFilter= av_mallocz(*outFilterSize*(dstW+1)*sizeof(int16_t)); /* Normalize & Store in outFilter */ for(i=0; i<dstW; i++) @@ -1463,14 +1466,14 @@ static void globalInit(void){ // generating tables: int i; for(i=0; i<768; i++){ - int c= FFMIN(FFMAX(i-256, 0), 255); + int c= av_clip_uint8(i-256); clip_table[i]=c; } } static SwsFunc getSwsFunc(int flags){ -#ifdef RUNTIME_CPUDETECT +#if defined(RUNTIME_CPUDETECT) && defined (CONFIG_GPL) #if defined(ARCH_X86) // ordered per speed fasterst first if(flags & SWS_CPU_CAPS_MMX2) @@ -1578,7 +1581,7 @@ static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int sr case 0x83: conv= rgb15to32; break; case 0x84: conv= rgb16to32; break; case 0x86: conv= rgb24to32; break; - default: MSG_ERR("swScaler: internal error %s -> %s converter\n", + default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", sws_format_name(srcFormat), sws_format_name(dstFormat)); break; } }else if( (isBGR(srcFormat) && isRGB(dstFormat)) @@ -1600,11 +1603,11 @@ static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int sr case 0x84: conv= rgb16tobgr32; break; case 0x86: conv= rgb24tobgr32; break; case 0x88: conv= rgb32tobgr32; break; - default: MSG_ERR("swScaler: internal error %s -> %s converter\n", + default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", sws_format_name(srcFormat), sws_format_name(dstFormat)); break; } }else{ - MSG_ERR("swScaler: internal error %s -> %s converter\n", + av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", sws_format_name(srcFormat), sws_format_name(dstFormat)); } @@ -1873,7 +1876,12 @@ int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange if(!srcRange){ cy= (cy*255) / 219; oy= 16<<16; - } + }else{ + crv= (crv*224) / 255; + cbu= (cbu*224) / 255; + cgu= (cgu*224) / 255; + cgv= (cgv*224) / 255; + } cy = (cy *contrast )>>16; crv= (crv*contrast * saturation)>>32; @@ -1948,7 +1956,7 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH asm volatile("emms\n\t"::: "memory"); #endif -#ifndef RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off +#if !defined(RUNTIME_CPUDETECT) || !defined (CONFIG_GPL) //ensure that the flags match the compiled variant if cpudetect is off flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC); #ifdef HAVE_MMX2 flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2; @@ -1973,19 +1981,19 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH if(!isSupportedIn(srcFormat)) { - MSG_ERR("swScaler: %s is not supported as input format\n", sws_format_name(srcFormat)); + av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input format\n", sws_format_name(srcFormat)); return NULL; } if(!isSupportedOut(dstFormat)) { - MSG_ERR("swScaler: %s is not supported as output format\n", sws_format_name(dstFormat)); + av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output format\n", sws_format_name(dstFormat)); return NULL; } /* sanity check */ if(srcW<4 || srcH<1 || dstW<8 || dstH<1) //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code { - MSG_ERR("swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", + av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", srcW, srcH, dstW, dstH); return NULL; } @@ -1993,9 +2001,9 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH if(!dstFilter) dstFilter= &dummyFilter; if(!srcFilter) srcFilter= &dummyFilter; - c= av_malloc(sizeof(SwsContext)); - memset(c, 0, sizeof(SwsContext)); + c= av_mallocz(sizeof(SwsContext)); + c->av_class = &sws_context_class; c->srcW= srcW; c->srcH= srcH; c->dstW= dstW; @@ -2058,11 +2066,13 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH { c->swScale= PlanarToNV12Wrapper; } +#ifdef CONFIG_GPL /* yuv2bgr */ if((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P) && (isBGR(dstFormat) || isRGB(dstFormat))) { c->swScale= yuv2rgb_get_func_ptr(c); } +#endif if( srcFormat==PIX_FMT_YUV410P && dstFormat==PIX_FMT_YUV420P ) { @@ -2135,7 +2145,7 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH if(c->swScale){ if(flags&SWS_PRINT_INFO) - MSG_INFO("SwScaler: using unscaled %s -> %s special converter\n", + av_log(c, AV_LOG_INFO, "SwScaler: using unscaled %s -> %s special converter\n", sws_format_name(srcFormat), sws_format_name(dstFormat)); return c; } @@ -2147,7 +2157,7 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH if(!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) { if(flags&SWS_PRINT_INFO) - MSG_INFO("SwScaler: output Width is not a multiple of 32 -> no MMX2 scaler\n"); + av_log(c, AV_LOG_INFO, "SwScaler: output Width is not a multiple of 32 -> no MMX2 scaler\n"); } if(usesHFilter) c->canMMX2BeUsed=0; } @@ -2279,12 +2289,11 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH //Note we need at least one pixel more at the end because of the mmx code (just in case someone wanna replace the 4000/8000) /* align at 16 bytes for AltiVec */ for(i=0; i<c->vLumBufSize; i++) - c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= av_malloc(4000); + c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= av_mallocz(4000); for(i=0; i<c->vChrBufSize; i++) c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= av_malloc(8000); //try to avoid drawing green stuff between the right end and the stride end - for(i=0; i<c->vLumBufSize; i++) memset(c->lumPixBuf[i], 0, 4000); for(i=0; i<c->vChrBufSize; i++) memset(c->chrPixBuf[i], 64, 8000); ASSERT(c->chrDstH <= dstH) @@ -2297,47 +2306,47 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH char *dither= ""; #endif if(flags&SWS_FAST_BILINEAR) - MSG_INFO("SwScaler: FAST_BILINEAR scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: FAST_BILINEAR scaler, "); else if(flags&SWS_BILINEAR) - MSG_INFO("SwScaler: BILINEAR scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: BILINEAR scaler, "); else if(flags&SWS_BICUBIC) - MSG_INFO("SwScaler: BICUBIC scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: BICUBIC scaler, "); else if(flags&SWS_X) - MSG_INFO("SwScaler: Experimental scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: Experimental scaler, "); else if(flags&SWS_POINT) - MSG_INFO("SwScaler: Nearest Neighbor / POINT scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: Nearest Neighbor / POINT scaler, "); else if(flags&SWS_AREA) - MSG_INFO("SwScaler: Area Averageing scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: Area Averageing scaler, "); else if(flags&SWS_BICUBLIN) - MSG_INFO("SwScaler: luma BICUBIC / chroma BILINEAR scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: luma BICUBIC / chroma BILINEAR scaler, "); else if(flags&SWS_GAUSS) - MSG_INFO("SwScaler: Gaussian scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: Gaussian scaler, "); else if(flags&SWS_SINC) - MSG_INFO("SwScaler: Sinc scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: Sinc scaler, "); else if(flags&SWS_LANCZOS) - MSG_INFO("SwScaler: Lanczos scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: Lanczos scaler, "); else if(flags&SWS_SPLINE) - MSG_INFO("SwScaler: Bicubic spline scaler, "); + av_log(c, AV_LOG_INFO, "SwScaler: Bicubic spline scaler, "); else - MSG_INFO("SwScaler: ehh flags invalid?! "); + av_log(c, AV_LOG_INFO, "SwScaler: ehh flags invalid?! "); if(dstFormat==PIX_FMT_BGR555 || dstFormat==PIX_FMT_BGR565) - MSG_INFO("from %s to%s %s ", + av_log(c, AV_LOG_INFO, "from %s to%s %s ", sws_format_name(srcFormat), dither, sws_format_name(dstFormat)); else - MSG_INFO("from %s to %s ", + av_log(c, AV_LOG_INFO, "from %s to %s ", sws_format_name(srcFormat), sws_format_name(dstFormat)); if(flags & SWS_CPU_CAPS_MMX2) - MSG_INFO("using MMX2\n"); + av_log(c, AV_LOG_INFO, "using MMX2\n"); else if(flags & SWS_CPU_CAPS_3DNOW) - MSG_INFO("using 3DNOW\n"); + av_log(c, AV_LOG_INFO, "using 3DNOW\n"); else if(flags & SWS_CPU_CAPS_MMX) - MSG_INFO("using MMX\n"); + av_log(c, AV_LOG_INFO, "using MMX\n"); else if(flags & SWS_CPU_CAPS_ALTIVEC) - MSG_INFO("using AltiVec\n"); + av_log(c, AV_LOG_INFO, "using AltiVec\n"); else - MSG_INFO("using C\n"); + av_log(c, AV_LOG_INFO, "using C\n"); } if(flags & SWS_PRINT_INFO) @@ -2345,70 +2354,70 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH if(flags & SWS_CPU_CAPS_MMX) { if(c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) - MSG_V("SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); else { if(c->hLumFilterSize==4) - MSG_V("SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n"); else if(c->hLumFilterSize==8) - MSG_V("SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n"); else - MSG_V("SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n"); if(c->hChrFilterSize==4) - MSG_V("SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n"); else if(c->hChrFilterSize==8) - MSG_V("SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n"); else - MSG_V("SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n"); } } else { #if defined(ARCH_X86) - MSG_V("SwScaler: using X86-Asm scaler for horizontal scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using X86-Asm scaler for horizontal scaling\n"); #else if(flags & SWS_FAST_BILINEAR) - MSG_V("SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n"); else - MSG_V("SwScaler: using C scaler for horizontal scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using C scaler for horizontal scaling\n"); #endif } if(isPlanarYUV(dstFormat)) { if(c->vLumFilterSize==1) - MSG_V("SwScaler: using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); else - MSG_V("SwScaler: using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); } else { if(c->vLumFilterSize==1 && c->vChrFilterSize==2) - MSG_V("SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" "SwScaler: 2-tap scaler for vertical chrominance scaling (BGR)\n",(flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); else if(c->vLumFilterSize==2 && c->vChrFilterSize==2) - MSG_V("SwScaler: using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); else - MSG_V("SwScaler: using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); } if(dstFormat==PIX_FMT_BGR24) - MSG_V("SwScaler: using %s YV12->BGR24 Converter\n", + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR24 Converter\n", (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); else if(dstFormat==PIX_FMT_RGB32) - MSG_V("SwScaler: using %s YV12->BGR32 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR32 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); else if(dstFormat==PIX_FMT_BGR565) - MSG_V("SwScaler: using %s YV12->BGR16 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR16 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); else if(dstFormat==PIX_FMT_BGR555) - MSG_V("SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - MSG_V("SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); + av_log(c, AV_LOG_VERBOSE, "SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); } if(flags & SWS_PRINT_INFO) { - MSG_DBG2("SwScaler:Lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", + av_log(c, AV_LOG_DEBUG, "SwScaler:Lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); - MSG_DBG2("SwScaler:Chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", + av_log(c, AV_LOG_DEBUG, "SwScaler:Chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); } @@ -2420,10 +2429,10 @@ SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH * swscale warper, so we don't need to export the SwsContext. * assumes planar YUV to be in YUV order instead of YVU */ -int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]){ if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { - MSG_ERR("swScaler: slices start in the middle!\n"); + av_log(c, AV_LOG_ERROR, "swScaler: slices start in the middle!\n"); return 0; } if (c->sliceDir == 0) { @@ -2432,21 +2441,22 @@ int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSli // copy strides, so they can safely be modified if (c->sliceDir == 1) { + uint8_t* src2[4]= {src[0], src[1], src[2]}; // slices go from top to bottom - int srcStride2[3]= {srcStride[0], srcStride[1], srcStride[2]}; - int dstStride2[3]= {dstStride[0], dstStride[1], dstStride[2]}; - return c->swScale(c, src, srcStride2, srcSliceY, srcSliceH, dst, dstStride2); + int srcStride2[4]= {srcStride[0], srcStride[1], srcStride[2]}; + int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2]}; + return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst, dstStride2); } else { // slices go from bottom to top => we flip the image internally - uint8_t* src2[3]= {src[0] + (srcSliceH-1)*srcStride[0], + uint8_t* src2[4]= {src[0] + (srcSliceH-1)*srcStride[0], src[1] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1], src[2] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2] }; - uint8_t* dst2[3]= {dst[0] + (c->dstH-1)*dstStride[0], + uint8_t* dst2[4]= {dst[0] + (c->dstH-1)*dstStride[0], dst[1] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1], dst[2] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]}; - int srcStride2[3]= {-srcStride[0], -srcStride[1], -srcStride[2]}; - int dstStride2[3]= {-dstStride[0], -dstStride[1], -dstStride[2]}; + int srcStride2[4]= {-srcStride[0], -srcStride[1], -srcStride[2]}; + int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2]}; return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); } @@ -2455,15 +2465,9 @@ int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSli /** * swscale warper, so we don't need to export the SwsContext */ -int sws_scale(SwsContext *c, uint8_t* srcParam[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dstParam[], int dstStride[]){ - uint8_t *src[3]; - uint8_t *dst[3]; - src[0] = srcParam[0]; src[1] = srcParam[1]; src[2] = srcParam[2]; - dst[0] = dstParam[0]; dst[1] = dstParam[1]; dst[2] = dstParam[2]; -//printf("sws: slice %d %d\n", srcSliceY, srcSliceH); - - return c->swScale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); +int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]){ + return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); } SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, @@ -2727,9 +2731,9 @@ void sws_printVec(SwsVector *a){ for(i=0; i<a->length; i++) { int x= (int)((a->coeff[i]-min)*60.0/range +0.5); - MSG_DBG2("%1.3f ", a->coeff[i]); - for(;x>0; x--) MSG_DBG2(" "); - MSG_DBG2("|\n"); + av_log(NULL, AV_LOG_DEBUG, "%1.3f ", a->coeff[i]); + for(;x>0; x--) av_log(NULL, AV_LOG_DEBUG, " "); + av_log(NULL, AV_LOG_DEBUG, "|\n"); } } @@ -2802,7 +2806,7 @@ void sws_freeContext(SwsContext *c){ av_free(c->hChrFilterPos); c->hChrFilterPos = NULL; -#if defined(ARCH_X86) +#if defined(ARCH_X86) && defined(CONFIG_GPL) #ifdef MAP_ANONYMOUS if(c->funnyYCode) munmap(c->funnyYCode, MAX_FUNNY_CODE_SIZE); if(c->funnyUVCode) munmap(c->funnyUVCode, MAX_FUNNY_CODE_SIZE); diff --git a/contrib/ffmpeg/libswscale/swscale.h b/contrib/ffmpeg/libswscale/swscale.h index 06088b8e4..27d1aa3ef 100644 --- a/contrib/ffmpeg/libswscale/swscale.h +++ b/contrib/ffmpeg/libswscale/swscale.h @@ -27,6 +27,8 @@ * external api for the swscale stuff */ +#include "avutil.h" + #ifdef __cplusplus extern "C" { #endif @@ -109,7 +111,7 @@ struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, i int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]); int sws_scale_ordered(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]); + int srcSliceH, uint8_t* dst[], int dstStride[]) attribute_deprecated; int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation); diff --git a/contrib/ffmpeg/libswscale/swscale_altivec_template.c b/contrib/ffmpeg/libswscale/swscale_altivec_template.c index d65c28538..251b38ca1 100644 --- a/contrib/ffmpeg/libswscale/swscale_altivec_template.c +++ b/contrib/ffmpeg/libswscale/swscale_altivec_template.c @@ -226,7 +226,7 @@ static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int for(j=0; j<filterSize; j++) { val += ((int)src[srcPos + j])*filter[filterSize*i + j]; } - dst[i] = FFMIN(FFMAX(0, val>>7), (1<<15)-1); + dst[i] = av_clip(val>>7, 0, (1<<15)-1); } } else @@ -265,7 +265,7 @@ static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int val_vEven = vec_mule(src_v, filter_v); val_s = vec_sums(val_vEven, vzero); vec_st(val_s, 0, tempo); - dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); } } break; @@ -292,7 +292,7 @@ static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int val_v = vec_msums(src_v, filter_v, (vector signed int)vzero); val_s = vec_sums(val_v, vzero); vec_st(val_s, 0, tempo); - dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); } } break; @@ -321,7 +321,7 @@ static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int vector signed int val_s = vec_sums(val_v, vzero); vec_st(val_s, 0, tempo); - dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); } } break; @@ -383,7 +383,7 @@ static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int val_s = vec_sums(val_v, vzero); vec_st(val_s, 0, tempo); - dst[i] = FFMIN(FFMAX(0, tempo[3]>>7), (1<<15)-1); + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); } } diff --git a/contrib/ffmpeg/libswscale/swscale_internal.h b/contrib/ffmpeg/libswscale/swscale_internal.h index 837b6eaf5..5b62ea065 100644 --- a/contrib/ffmpeg/libswscale/swscale_internal.h +++ b/contrib/ffmpeg/libswscale/swscale_internal.h @@ -33,13 +33,6 @@ #define AVV(x...) {x} #endif -#define MSG_WARN(args...) av_log(NULL, AV_LOG_DEBUG, ##args ) -#define MSG_FATAL(args...) av_log(NULL, AV_LOG_ERROR, ##args ) -#define MSG_ERR(args...) av_log(NULL, AV_LOG_ERROR, ##args ) -#define MSG_V(args...) av_log(NULL, AV_LOG_INFO, ##args ) -#define MSG_DBG2(args...) av_log(NULL, AV_LOG_DEBUG, ##args ) -#define MSG_INFO(args...) av_log(NULL, AV_LOG_INFO, ##args ) - #define MAX_FILTER_SIZE 256 typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY, @@ -47,6 +40,11 @@ typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride /* this struct should be aligned on at least 32-byte boundary */ typedef struct SwsContext{ + /** + * info on struct for av_log + */ + AVClass *av_class; + /** * * Note the src,dst,srcStride,dstStride will be copied, in the sws_scale() warper so they can freely be modified here @@ -76,7 +74,7 @@ typedef struct SwsContext{ int16_t *vChrFilter; int16_t *vChrFilterPos; - uint8_t formatConvBuffer[4000]; //FIXME dynamic alloc, but we have to change alot of code for this to be usefull + uint8_t formatConvBuffer[4000]; //FIXME dynamic alloc, but we have to change a lot of code for this to be useful int hLumFilterSize; int hChrFilterSize; @@ -101,10 +99,10 @@ typedef struct SwsContext{ int dstY; int flags; void * yuvTable; // pointer to the yuv->rgb table start so it can be freed() - void * table_rV[256]; - void * table_gU[256]; + uint8_t * table_rV[256]; + uint8_t * table_gU[256]; int table_gV[256]; - void * table_bU[256]; + uint8_t * table_bU[256]; //Colorspace stuff int contrast, brightness, saturation; // for sws_getColorspaceDetails @@ -182,11 +180,11 @@ char *sws_format_name(int format); #define isGray16(x) ((x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE) #define isRGB(x) ((x)==PIX_FMT_BGR32 || (x)==PIX_FMT_RGB24 \ || (x)==PIX_FMT_RGB565 || (x)==PIX_FMT_RGB555 \ - || (x)==PIX_FMT_RGB8 || (x)==PIX_FMT_RGB4 \ + || (x)==PIX_FMT_RGB8 || (x)==PIX_FMT_RGB4 || (x)==PIX_FMT_RGB4_BYTE \ || (x)==PIX_FMT_MONOBLACK) #define isBGR(x) ((x)==PIX_FMT_RGB32 || (x)==PIX_FMT_BGR24 \ || (x)==PIX_FMT_BGR565 || (x)==PIX_FMT_BGR555 \ - || (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_BGR4 \ + || (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_BGR4 || (x)==PIX_FMT_BGR4_BYTE \ || (x)==PIX_FMT_MONOBLACK) static inline int fmt_depth(int fmt) diff --git a/contrib/ffmpeg/libswscale/swscale_template.c b/contrib/ffmpeg/libswscale/swscale_template.c index e725a3bb0..ad46be127 100644 --- a/contrib/ffmpeg/libswscale/swscale_template.c +++ b/contrib/ffmpeg/libswscale/swscale_template.c @@ -1730,7 +1730,6 @@ static inline void RENAME(yuy2ToY)(uint8_t *dst, uint8_t *src, long width) static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width) { - assert(src1 == src2); #ifdef HAVE_MMX asm volatile( "movq "MANGLE(bm01010101)", %%mm4\n\t" @@ -1761,6 +1760,7 @@ static inline void RENAME(yuy2ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, dstV[i]= src1[4*i + 3]; } #endif + assert(src1 == src2); } //this is allmost identical to the previous, end exists only cuz yuy2ToY/UV)(dst, src+1, ...) would have 100% unaligned accesses @@ -1790,7 +1790,6 @@ static inline void RENAME(uyvyToY)(uint8_t *dst, uint8_t *src, long width) static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width) { - assert(src1 == src2); #ifdef HAVE_MMX asm volatile( "movq "MANGLE(bm01010101)", %%mm4\n\t" @@ -1821,6 +1820,7 @@ static inline void RENAME(uyvyToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, dstV[i]= src1[4*i + 2]; } #endif + assert(src1 == src2); } static inline void RENAME(bgr32ToY)(uint8_t *dst, uint8_t *src, int width) @@ -1942,7 +1942,6 @@ static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, long width) static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width) { - assert(src1 == src2); #ifdef HAVE_MMX asm volatile( "mov %3, %%"REG_a" \n\t" @@ -2072,6 +2071,7 @@ static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1 dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; } #endif + assert(src1 == src2); } static inline void RENAME(bgr16ToY)(uint8_t *dst, uint8_t *src, int width) @@ -2279,6 +2279,38 @@ static inline void RENAME(rgb15ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1 } } +static inline void RENAME(palToY)(uint8_t *dst, uint8_t *src, int width, uint32_t *pal) +{ + int i; + for(i=0; i<width; i++) + { + int d= src[i]; + int b= pal[d] &0xFF; + int g=(pal[d]>>8 )&0xFF; + int r= pal[d]>>16; + + dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; + } +} + +static inline void RENAME(palToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width, uint32_t *pal) +{ + int i; + assert(src1 == src2); + for(i=0; i<width; i++) + { + int d0= src1[2*i ]; + int d1= src1[2*i+1]; + int p = (pal[d0]&0xFF00FF) + (pal[d1]&0xFF00FF); + int g = (pal[d0]+pal[d1]-p)>>8; + int b= p&0x1FF; + int r= p>>16; + + dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128; + dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; + } +} + // Bilinear / Bicubic scaling static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, int16_t *filter, int16_t *filterPos, long filterSize) @@ -2456,7 +2488,7 @@ static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW val += ((int)src[srcPos + j])*filter[filterSize*i + j]; } // filter += hFilterSize; - dst[i] = FFMIN(FFMAX(0, val>>7), (1<<15)-1); // the cubic equation does overflow ... + dst[i] = av_clip(val>>7, 0, (1<<15)-1); // the cubic equation does overflow ... // dst[i] = val>>7; } #endif @@ -2467,7 +2499,7 @@ static inline void RENAME(hyscale)(uint16_t *dst, long dstWidth, uint8_t *src, i int flags, int canMMX2BeUsed, int16_t *hLumFilter, int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode, int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, - int32_t *mmx2FilterPos) + int32_t *mmx2FilterPos, uint8_t *pal) { if(srcFormat==PIX_FMT_YUYV422 || srcFormat==PIX_FMT_GRAY16BE) { @@ -2519,6 +2551,11 @@ static inline void RENAME(hyscale)(uint16_t *dst, long dstWidth, uint8_t *src, i RENAME(rgb15ToY)(formatConvBuffer, src, srcW); src= formatConvBuffer; } + else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE) + { + RENAME(palToY)(formatConvBuffer, src, srcW, pal); + src= formatConvBuffer; + } #ifdef HAVE_MMX // use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one) @@ -2664,7 +2701,7 @@ inline static void RENAME(hcscale)(uint16_t *dst, long dstWidth, uint8_t *src1, int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter, int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode, int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, - int32_t *mmx2FilterPos) + int32_t *mmx2FilterPos, uint8_t *pal) { if(srcFormat==PIX_FMT_YUYV422) { @@ -2730,6 +2767,12 @@ inline static void RENAME(hcscale)(uint16_t *dst, long dstWidth, uint8_t *src1, { return; } + else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE) + { + RENAME(palToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW, pal); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; + } #ifdef HAVE_MMX // use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one) @@ -2932,6 +2975,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample; const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample); int lastDstY; + uint8_t *pal=NULL; /* vars whch will change and which we need to storw back in the context */ int dstY= c->dstY; @@ -2941,6 +2985,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s int lastInChrBuf= c->lastInChrBuf; if(isPacked(c->srcFormat)){ + pal= src[1]; src[0]= src[1]= src[2]= src[0]; @@ -2972,7 +3017,7 @@ i--; static int firstTime=1; //FIXME move this into the context perhaps if(flags & SWS_PRINT_INFO && firstTime) { - MSG_WARN("SwScaler: Warning: dstStride is not aligned!\n" + av_log(c, AV_LOG_WARNING, "SwScaler: Warning: dstStride is not aligned!\n" "SwScaler: ->cannot do aligned memory acesses anymore\n"); firstTime=0; } @@ -3026,7 +3071,7 @@ i--; RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, funnyYCode, c->srcFormat, formatConvBuffer, - c->lumMmx2Filter, c->lumMmx2FilterPos); + c->lumMmx2Filter, c->lumMmx2FilterPos, pal); lastInLumBuf++; } while(lastInChrBuf < lastChrSrcY) @@ -3043,7 +3088,7 @@ i--; RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, funnyUVCode, c->srcFormat, formatConvBuffer, - c->chrMmx2Filter, c->chrMmx2FilterPos); + c->chrMmx2Filter, c->chrMmx2FilterPos, pal); lastInChrBuf++; } //wrap buf index around to stay inside the ring buffer @@ -3068,7 +3113,7 @@ i--; RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, funnyYCode, c->srcFormat, formatConvBuffer, - c->lumMmx2Filter, c->lumMmx2FilterPos); + c->lumMmx2Filter, c->lumMmx2FilterPos, pal); lastInLumBuf++; } while(lastInChrBuf+1 < (chrSrcSliceY + chrSrcSliceH)) @@ -3084,7 +3129,7 @@ i--; RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, funnyUVCode, c->srcFormat, formatConvBuffer, - c->chrMmx2Filter, c->chrMmx2FilterPos); + c->chrMmx2Filter, c->chrMmx2FilterPos, pal); lastInChrBuf++; } //wrap buf index around to stay inside the ring buffer @@ -3107,15 +3152,15 @@ i--; int i; if(flags & SWS_ACCURATE_RND){ for(i=0; i<vLumFilterSize; i+=2){ - lumMmxFilter[2*i+0]= lumSrcPtr[i ]; - lumMmxFilter[2*i+1]= lumSrcPtr[i+(vLumFilterSize>1)]; + lumMmxFilter[2*i+0]= (int32_t)lumSrcPtr[i ]; + lumMmxFilter[2*i+1]= (int32_t)lumSrcPtr[i+(vLumFilterSize>1)]; lumMmxFilter[2*i+2]= lumMmxFilter[2*i+3]= vLumFilter[dstY*vLumFilterSize + i ] + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); } for(i=0; i<vChrFilterSize; i+=2){ - chrMmxFilter[2*i+0]= chrSrcPtr[i ]; - chrMmxFilter[2*i+1]= chrSrcPtr[i+(vChrFilterSize>1)]; + chrMmxFilter[2*i+0]= (int32_t)chrSrcPtr[i ]; + chrMmxFilter[2*i+1]= (int32_t)chrSrcPtr[i+(vChrFilterSize>1)]; chrMmxFilter[2*i+2]= chrMmxFilter[2*i+3]= vChrFilter[chrDstY*vChrFilterSize + i ] + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); @@ -3124,6 +3169,7 @@ i--; for(i=0; i<vLumFilterSize; i++) { lumMmxFilter[4*i+0]= (int32_t)lumSrcPtr[i]; + lumMmxFilter[4*i+1]= (uint64_t)lumSrcPtr[i] >> 32; lumMmxFilter[4*i+2]= lumMmxFilter[4*i+3]= ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001; @@ -3131,6 +3177,7 @@ i--; for(i=0; i<vChrFilterSize; i++) { chrMmxFilter[4*i+0]= (int32_t)chrSrcPtr[i]; + chrMmxFilter[4*i+1]= (uint64_t)chrSrcPtr[i] >> 32; chrMmxFilter[4*i+2]= chrMmxFilter[4*i+3]= ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001; diff --git a/contrib/ffmpeg/libswscale/yuv2rgb.c b/contrib/ffmpeg/libswscale/yuv2rgb.c index 9066b68b2..af7f86f40 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb.c @@ -22,8 +22,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * along with mpeg2dec; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * MMX/MMX2 Template stuff from Michael Niedermayer (michaelni@gmx.at) (needed for fast movntq support) * 1,4,8bpp support by Michael Niedermayer (michaelni@gmx.at) @@ -213,9 +213,9 @@ const int32_t Inverse_Table_6_9[8][4] = { #define RGB(i) \ U = pu[i]; \ V = pv[i]; \ - r = c->table_rV[V]; \ - g = c->table_gU[U] + c->table_gV[V]; \ - b = c->table_bU[U]; + r = (void *)c->table_rV[V]; \ + g = (void *)(c->table_gU[U] + c->table_gV[V]); \ + b = (void *)c->table_bU[U]; #define DST1(i) \ Y = py_1[2*i]; \ @@ -265,14 +265,16 @@ static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSlic for(y=0; y<srcSliceH; y+=2){\ dst_type *dst_1= (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\ dst_type *dst_2= (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\ - dst_type *r, *g, *b;\ + dst_type attribute_unused *r, *b;\ + dst_type *g;\ uint8_t *py_1= src[0] + y*srcStride[0];\ uint8_t *py_2= py_1 + srcStride[0];\ uint8_t *pu= src[1] + (y>>1)*srcStride[1];\ uint8_t *pv= src[2] + (y>>1)*srcStride[2];\ unsigned int h_size= c->dstW>>3;\ while (h_size--) {\ - int U, V, Y;\ + int attribute_unused U, V;\ + int Y;\ #define EPILOG(dst_delta)\ pu += 4;\ @@ -609,7 +611,7 @@ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c) } #endif - MSG_WARN("No accelerated colorspace conversion found\n"); + av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found\n"); switch(c->dstFormat){ case PIX_FMT_BGR32: @@ -668,6 +670,11 @@ int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, if(!fullRange){ cy= (cy*255) / 219; oy= 16<<16; + }else{ + crv= (crv*224) / 255; + cbu= (cbu*224) / 255; + cgu= (cgu*224) / 255; + cgv= (cgv*224) / 255; } cy = (cy *contrast )>>16; @@ -826,16 +833,16 @@ int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, default: table_start= NULL; - MSG_ERR("%ibpp not supported by yuv2rgb\n", bpp); + av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); //free mem? return -1; } for (i = 0; i < 256; i++) { - c->table_rV[i] = table_r + entry_size * div_round (crv * (i-128), 76309); - c->table_gU[i] = table_g + entry_size * div_round (cgu * (i-128), 76309); + c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309); + c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309); c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309); - c->table_bU[i] = table_b + entry_size * div_round (cbu * (i-128), 76309); + c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309); } av_free(c->yuvTable); diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c b/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c index ca0680a49..72e418e8d 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c @@ -710,22 +710,22 @@ SwsFunc yuv2rgb_init_altivec (SwsContext *c) switch(c->dstFormat){ case PIX_FMT_RGB24: - MSG_WARN("ALTIVEC: Color Space RGB24\n"); + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n"); return altivec_yuv2_rgb24; case PIX_FMT_BGR24: - MSG_WARN("ALTIVEC: Color Space BGR24\n"); + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n"); return altivec_yuv2_bgr24; case PIX_FMT_ARGB: - MSG_WARN("ALTIVEC: Color Space ARGB\n"); + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n"); return altivec_yuv2_argb; case PIX_FMT_ABGR: - MSG_WARN("ALTIVEC: Color Space ABGR\n"); + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n"); return altivec_yuv2_abgr; case PIX_FMT_RGBA: - MSG_WARN("ALTIVEC: Color Space RGBA\n"); + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n"); return altivec_yuv2_rgba; case PIX_FMT_BGRA: - MSG_WARN("ALTIVEC: Color Space BGRA\n"); + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n"); return altivec_yuv2_bgra; default: return NULL; } @@ -734,7 +734,7 @@ SwsFunc yuv2rgb_init_altivec (SwsContext *c) case PIX_FMT_UYVY422: switch(c->dstFormat){ case PIX_FMT_BGR32: - MSG_WARN("ALTIVEC: Color Space UYVY -> RGB32\n"); + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n"); return altivec_uyvy_rgb32; default: return NULL; } @@ -877,7 +877,7 @@ altivec_yuv2packedX (SwsContext *c, instead. */ static int printed_error_message; if(!printed_error_message) { - MSG_ERR("altivec_yuv2packedX doesn't support %s output\n", + av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", sws_format_name(c->dstFormat)); printed_error_message=1; } @@ -952,7 +952,7 @@ altivec_yuv2packedX (SwsContext *c, case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break; default: /* Unreachable, I think. */ - MSG_ERR("altivec_yuv2packedX doesn't support %s output\n", + av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", sws_format_name(c->dstFormat)); return; } diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_init.c b/contrib/ffmpeg/libswscale/yuv2rgb_init.c new file mode 100644 index 000000000..371dce5da --- /dev/null +++ b/contrib/ffmpeg/libswscale/yuv2rgb_init.c @@ -0,0 +1,412 @@ +#include "avutil.h" +#include "swscale.h" +#include "swscale_internal.h" + +#define YTABLE_MIN 384 + +/** + * YUV -> RGB conversion matrixes (inverse of table 6.9 in MPEG2 standard) + * + * An YUV -> RGB conversion matrix is in the form + * | 1 0 Rv | + * | 1 Gu Gv | + * | 1 Bu 0 | + * + * Inverse_Table_6_9 stores | Rv Bu Gv Gu | * 255/224*2^16. + * \arg Maximum Rv value: 117570 + * \arg Maximum Bu value: 138420 + * \arg Maximum Gv + Gu value: 25642 + 53281 = 78923 + * + * These values are needed to allocate table_{r, g, b}. If you modify + * this table, please update allocate_tables() accordingly + */ +const int32_t Inverse_Table_6_9[8][4] = { + {0, 0, 0, 0}, /* no sequence_display_extension */ + {117500, 138420, -13985, -34933}, /* ITU-R Rec. 709 (1990) */ + {0, 0, 0, 0}, /* unspecified */ + {0, 0, 0, 0}, /* reserved */ + {104480, 132820, -24811, -53150}, /* FCC */ + {104570, 132210, -25642, -53281}, /* ITU-R Rec. 624-4 System B, G */ + {104570, 132210, -25642, -53281}, /* SMPTE 170M */ + {117570, 136230, -16892, -35552} /* SMPTE 240M (1987) */ +}; + + +/** + * Dithering matrixes (these are bayer ordered dither matrixes + * with some manual changes by Michael) + */ +const uint8_t __attribute__((aligned(8))) dither_2x2_4[2][8]={ +{ 1, 3, 1, 3, 1, 3, 1, 3, }, +{ 2, 0, 2, 0, 2, 0, 2, 0, }, +}; + +const uint8_t __attribute__((aligned(8))) dither_2x2_8[2][8]={ +{ 6, 2, 6, 2, 6, 2, 6, 2, }, +{ 0, 4, 0, 4, 0, 4, 0, 4, }, +}; + +const uint8_t __attribute__((aligned(8))) dither_8x8_32[8][8]={ +{ 17, 9, 23, 15, 16, 8, 22, 14, }, +{ 5, 29, 3, 27, 4, 28, 2, 26, }, +{ 21, 13, 19, 11, 20, 12, 18, 10, }, +{ 0, 24, 6, 30, 1, 25, 7, 31, }, +{ 16, 8, 22, 14, 17, 9, 23, 15, }, +{ 4, 28, 2, 26, 5, 29, 3, 27, }, +{ 20, 12, 18, 10, 21, 13, 19, 11, }, +{ 1, 25, 7, 31, 0, 24, 6, 30, }, +}; + +#if 0 +const uint8_t __attribute__((aligned(8))) dither_8x8_64[8][8]={ +{ 0, 48, 12, 60, 3, 51, 15, 63, }, +{ 32, 16, 44, 28, 35, 19, 47, 31, }, +{ 8, 56, 4, 52, 11, 59, 7, 55, }, +{ 40, 24, 36, 20, 43, 27, 39, 23, }, +{ 2, 50, 14, 62, 1, 49, 13, 61, }, +{ 34, 18, 46, 30, 33, 17, 45, 29, }, +{ 10, 58, 6, 54, 9, 57, 5, 53, }, +{ 42, 26, 38, 22, 41, 25, 37, 21, }, +}; +#endif + +const uint8_t __attribute__((aligned(8))) dither_8x8_73[8][8]={ +{ 0, 55, 14, 68, 3, 58, 17, 72, }, +{ 37, 18, 50, 32, 40, 22, 54, 35, }, +{ 9, 64, 5, 59, 13, 67, 8, 63, }, +{ 46, 27, 41, 23, 49, 31, 44, 26, }, +{ 2, 57, 16, 71, 1, 56, 15, 70, }, +{ 39, 21, 52, 34, 38, 19, 51, 33, }, +{ 11, 66, 7, 62, 10, 65, 6, 60, }, +{ 48, 30, 43, 25, 47, 29, 42, 24, }, +}; + +#if 0 +const uint8_t __attribute__((aligned(8))) dither_8x8_128[8][8]={ +{ 68, 36, 92, 60, 66, 34, 90, 58, }, +{ 20, 116, 12, 108, 18, 114, 10, 106, }, +{ 84, 52, 76, 44, 82, 50, 74, 42, }, +{ 0, 96, 24, 120, 6, 102, 30, 126, }, +{ 64, 32, 88, 56, 70, 38, 94, 62, }, +{ 16, 112, 8, 104, 22, 118, 14, 110, }, +{ 80, 48, 72, 40, 86, 54, 78, 46, }, +{ 4, 100, 28, 124, 2, 98, 26, 122, }, +}; +#endif + +#if 1 +const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ +{117, 62, 158, 103, 113, 58, 155, 100, }, +{ 34, 199, 21, 186, 31, 196, 17, 182, }, +{144, 89, 131, 76, 141, 86, 127, 72, }, +{ 0, 165, 41, 206, 10, 175, 52, 217, }, +{110, 55, 151, 96, 120, 65, 162, 107, }, +{ 28, 193, 14, 179, 38, 203, 24, 189, }, +{138, 83, 124, 69, 148, 93, 134, 79, }, +{ 7, 172, 48, 213, 3, 168, 45, 210, }, +}; +#elif 1 +// tries to correct a gamma of 1.5 +const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ +{ 0, 143, 18, 200, 2, 156, 25, 215, }, +{ 78, 28, 125, 64, 89, 36, 138, 74, }, +{ 10, 180, 3, 161, 16, 195, 8, 175, }, +{109, 51, 93, 38, 121, 60, 105, 47, }, +{ 1, 152, 23, 210, 0, 147, 20, 205, }, +{ 85, 33, 134, 71, 81, 30, 130, 67, }, +{ 14, 190, 6, 171, 12, 185, 5, 166, }, +{117, 57, 101, 44, 113, 54, 97, 41, }, +}; +#elif 1 +// tries to correct a gamma of 2.0 +const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ +{ 0, 124, 8, 193, 0, 140, 12, 213, }, +{ 55, 14, 104, 42, 66, 19, 119, 52, }, +{ 3, 168, 1, 145, 6, 187, 3, 162, }, +{ 86, 31, 70, 21, 99, 39, 82, 28, }, +{ 0, 134, 11, 206, 0, 129, 9, 200, }, +{ 62, 17, 114, 48, 58, 16, 109, 45, }, +{ 5, 181, 2, 157, 4, 175, 1, 151, }, +{ 95, 36, 78, 26, 90, 34, 74, 24, }, +}; +#else +// tries to correct a gamma of 2.5 +const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ +{ 0, 107, 3, 187, 0, 125, 6, 212, }, +{ 39, 7, 86, 28, 49, 11, 102, 36, }, +{ 1, 158, 0, 131, 3, 180, 1, 151, }, +{ 68, 19, 52, 12, 81, 25, 64, 17, }, +{ 0, 119, 5, 203, 0, 113, 4, 195, }, +{ 45, 9, 96, 33, 42, 8, 91, 30, }, +{ 2, 172, 1, 144, 2, 165, 0, 137, }, +{ 77, 23, 60, 15, 72, 21, 56, 14, }, +}; +#endif + +static int get_entry_size(int bpp) +{ + switch(bpp) { + case 32: + return 4; + case 16: + case 15: + return 2; + case 24: + case 8: + case 4: + case 1: + return 1; + default: + return -1; + } +} + +/** + * Allocate table_r, table_g, and table_b + * + * For cache efficency reasons, these three tables are allocated + * together, so that they are contiguous in memory + * + * table_r is indexed in the range + * [-128 * 117570 / 76309, 255 + 127 * 117570 / 76309] = + * [-197.21, 451.67] ---> [-198, 452] + * table_b is indexed in the range + * [-128 * 138420 / 76309, 255 + 127 * 138420 / 76309] = + * [232.18, 485.37] ---> [-233, 486] + * table_g is indexed in the range + * [-128 * 78923 / 76309, 255 + 127 * 78923 / 76309] = + * [-132.38, 386.35] ---> [-133, 387] + * + * Please look at the comments after Inverse_Table_6_9 to see where these + * numbers are coming from. + */ +static void *allocate_tables(uint8_t **table_r, uint8_t **table_g, uint8_t **table_b, int bpp) +{ + uint8_t *table; + int entry_size; + + entry_size = get_entry_size(bpp); + + /* First allocate the memory... */ + switch (bpp) { + case 32: + case 15: + case 16: + case 8: + case 4: + table = av_malloc((198 + 452 + 233 + 486 + 133 + 387) * entry_size); + break; + case 24: + table = av_malloc(256 + 2 * 233); + break; + case 1: + table = av_malloc (256 * 2); + break; + default: + table = NULL; + } + if (table == NULL) { + MSG_ERR("Cannot allocate memory for the YUV -> RGB tables!\n"); + + return NULL; + } + + /* ...and then, assign the table_* value */ + switch (bpp) { + case 32: + case 15: + case 16: + case 8: + case 4: + *table_r = table + 198 * entry_size; + *table_b = table + (198 + 452 + 133 + 387 + 233) * entry_size; + *table_g = table + (198 + 452 + 133) * entry_size; + break; + case 24: + *table_r = *table_g = *table_b = table + 233; + break; + case 1: + *table_g = table; + *table_r = *table_b = NULL; + break; + } + + return table; +} + +/** + * Initialize the table_rV, table_gU[i], table_gV, and table_bU fields + * in SwsContext + * + * @param inv_table the YUV -> RGB table (this is a line of Inverse_Table_6_9) + * @param fullRange 0->MPEG YUV space 1->JPEG YUV space +*/ +int yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation) +{ + int i; + static uint8_t ytable[1024]; + int64_t cy, oy; + int64_t crv, cbu, cgu, cgv; + int entry_size = 0; + uint8_t *table_r, *table_g, *table_b; + int value; + + if ((inv_table[0] == 0) || (inv_table[1] == 0) || (inv_table[2] == 0) || (inv_table[3] == 0)) { + MSG_ERR("Invalid YUV ---> RGB table!\n"); + + return -1; + } + crv = inv_table[0]; + cbu = inv_table[1]; + cgu = inv_table[2]; + cgv = inv_table[3]; + if (fullRange) { + cy = 1 << 16; + oy = 0; + crv= (crv*224) / 255; + cbu= (cbu*224) / 255; + cgu= (cgu*224) / 255; + cgv= (cgv*224) / 255; + //FIXME maybe its cleaner if the tables where based on full range (*244/255) + } else { + cy = ((1 << 16) * 255) / 219; + oy= 16 << 16; + } + + cy = (cy *contrast )>>16; + crv= (crv*contrast * saturation)>>32; + cbu= (cbu*contrast * saturation)>>32; + cgu= (cgu*contrast * saturation)>>32; + cgv= (cgv*contrast * saturation)>>32; + oy -= 256*brightness; + + for (i = 0; i < 1024; i++) { + value = (cy*(((i - YTABLE_MIN)<<16) - oy) + (1<<31))>>32; + ytable[i] = av_clip_uint8(value); + } + + entry_size = get_entry_size(fmt_depth(c->dstFormat)); + av_free(c->yuvTable); + c->yuvTable = allocate_tables(&table_r, &table_g, &table_b, fmt_depth(c->dstFormat)); + if (c->yuvTable == NULL) { + return -1; + } + + switch (fmt_depth(c->dstFormat)) { + case 32: + for (i = -198; i < 256 + 197; i++) { + value = ytable[i + YTABLE_MIN]; + if (isBGR(c->dstFormat)) { + value <<= 16; + } + ((uint32_t *)table_r)[i] = value; + } + for (i = -133; i < 256 + 132; i++) { + ((uint32_t *)table_g)[i] = ytable[i + YTABLE_MIN] << 8; + } + for (i = -233; i < 256 + 232; i++) { + value = ytable[i + YTABLE_MIN]; + if (!isBGR(c->dstFormat)) { + value <<= 16; + } + ((uint32_t *)table_b)[i] = value; + } + break; + + case 24: + for (i = -233; i < 256 + 232; i++) { + ((uint8_t * )table_b)[i] = ytable[i + YTABLE_MIN]; + } + break; + + case 15: + case 16: + for (i = -198; i < 256 + 197; i++) { + value = ytable[i + YTABLE_MIN] >> 3; + if (isBGR(c->dstFormat)) { + value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10); + } + ((uint16_t *)table_r)[i] = value; + } + for (i = -133; i < 256 + 132; i++) { + value = ytable[i + YTABLE_MIN]; + value >>= ((fmt_depth(c->dstFormat) == 16) ? 2 : 3); + ((uint16_t *)table_g)[i] = value << 5; + } + for (i = -233; i < 256 + 232; i++) { + value = ytable[i + YTABLE_MIN] >> 3; + if (!isBGR(c->dstFormat)) { + value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10); + } + ((uint16_t *)table_b)[i] = value; + } + break; + case 8: + for (i = -198; i < 256 + 197; i++) { + value = (ytable[i + YTABLE_MIN - 16] + 18) / 36; + if (isBGR(c->dstFormat)) { + value <<= 5; + } + ((uint8_t *)table_r)[i] = value; + } + for (i = -133; i < 256 + 132; i++) { + value = (ytable[i + YTABLE_MIN - 16] + 18) / 36; + if (!isBGR(c->dstFormat)) { + value <<= 1; + } + ((uint8_t *)table_g)[i] = value << 2; + } + for (i = -233; i < 256 + 232; i++) { + value = (ytable[i + YTABLE_MIN - 37] + 43) / 85; + if (!isBGR(c->dstFormat)) { + value <<= 6; + } + ((uint8_t *)table_b)[i] = value; + } + break; + case 4: + for (i = -198; i < 256 + 197; i++) { + value = ytable[i + YTABLE_MIN - 110] >> 7; + if (isBGR(c->dstFormat)) { + value <<= 3; + } + ((uint8_t *)table_r)[i] = value; + } + for (i = -133; i < 256 + 132; i++) { + value = (ytable[i + YTABLE_MIN - 37]+ 43) / 85; + ((uint8_t *)table_g)[i] = value << 1; + } + for (i = -233; i < 256 + 232; i++) { + value = ytable[i + YTABLE_MIN - 110] >> 7; + if (!isBGR(c->dstFormat)) { + value <<= 3; + } + ((uint8_t *)table_b)[i] = value; + } + break; + case 1: + for (i = 0; i < 256 + 256; i++) { + value = ytable[i + YTABLE_MIN - 110] >> 7; + ((uint8_t *)table_g)[i] = value; + } + break; + default: + MSG_ERR("%ibpp not supported by yuv2rgb\n", fmt_depth(c->dstFormat)); + av_free(c->yuvTable); + c->yuvTable = NULL; + + return -1; + } + + for (i = 0; i < 256; i++) { + c->table_rV[i] = table_r + + entry_size * ROUNDED_DIV(crv * (i - 128), 76309); + c->table_gU[i] = table_g + + entry_size * ROUNDED_DIV(cgu * (i - 128), 76309); + c->table_gV[i] = entry_size * ROUNDED_DIV(cgv * (i - 128), 76309); + c->table_bU[i] = table_b + + entry_size * ROUNDED_DIV(cbu * (i - 128), 76309); + } + + return 0; +} diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c b/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c index 824ee39d1..c99e019cd 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c @@ -17,9 +17,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * + * along with mpeg2dec; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <mlib_types.h> diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_template.c b/contrib/ffmpeg/libswscale/yuv2rgb_template.c index fd222350e..28ee24add 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb_template.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb_template.c @@ -20,8 +20,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * along with mpeg2dec; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * 15,24 bpp and dithering from Michael Niedermayer (michaelni@gmx.at) * MMX/MMX2 Template stuff from Michael Niedermayer (needed for fast movntq support) @@ -133,7 +133,7 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStr } h_size= (c->dstW+7)&~7; - if(h_size*2 > dstStride[0]) h_size-=8; + if(h_size*2 > FFABS(dstStride[0])) h_size-=8; __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0], @@ -228,7 +228,7 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStr } h_size= (c->dstW+7)&~7; - if(h_size*2 > dstStride[0]) h_size-=8; + if(h_size*2 > FFABS(dstStride[0])) h_size-=8; __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0], @@ -317,7 +317,7 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStr } h_size= (c->dstW+7)&~7; - if(h_size*3 > dstStride[0]) h_size-=8; + if(h_size*3 > FFABS(dstStride[0])) h_size-=8; __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); @@ -463,7 +463,7 @@ static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStr } h_size= (c->dstW+7)&~7; - if(h_size*4 > dstStride[0]) h_size-=8; + if(h_size*4 > FFABS(dstStride[0])) h_size-=8; __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); |