From: Michael Niedermayer Date: Mon, 28 Oct 2002 19:31:04 +0000 (+0000) Subject: postprocessing cleanup: X-Git-Tag: v0.5~17163 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9c9e467d8d7febf7a1e87b16e8b66c2c6e861d83;p=platform%2Fupstream%2Flibav.git postprocessing cleanup: remove opendivx #ifdefs remove rk1 filter remove unused / obsolete stuff add -1,4,2,4,-1 deinterlacing filter (ffmpeg uses that) threadsafe / no more non-const globals some optimizations different strides for Y,U,V possible remove ebx usage (someone really should fix gcc, this is really lame) change the dering filter slightly (tell me if its worse for any files) Originally committed as revision 7947 to svn://svn.mplayerhq.hu/mplayer/trunk/postproc --- diff --git a/postproc/Makefile b/postproc/Makefile index cf2af02..1c2d244 100644 --- a/postproc/Makefile +++ b/postproc/Makefile @@ -1,10 +1,15 @@ include ../config.mak -LIBNAME = libpostproc.a +SWSLIB = libswscale.a +SPPLIB = libpostproc.so +SPPVERSION = 0.0.1 +PPLIB = libpostproc.a -SRCS=postprocess.c swscale.c rgb2rgb.c yuv2rgb.c -OBJS=$(SRCS:.c=.o) +SWSSRCS=swscale.c rgb2rgb.c yuv2rgb.c +SWSOBJS=$(SWSSRCS:.c=.o) +PPOBJS=postprocess.o +SPPOBJS=postprocess_pic.o CS_TEST_OBJS=cs_test.o rgb2rgb.o ../cpudetect.o ../mp_msg.o CFLAGS = $(OPTFLAGS) $(MLIB_INC) -I. -I.. $(EXTRA_INC) @@ -17,16 +22,16 @@ CFLAGS = $(OPTFLAGS) $(MLIB_INC) -I. -I.. $(EXTRA_INC) .c.o: $(CC) -c $(CFLAGS) -o $@ $< -$(LIBNAME): $(OBJS) - $(AR) r $(LIBNAME) $(OBJS) +all: $(SWSLIB) $(PPLIB) $(SPPLIB) -all: $(LIBNAME) +$(SWSLIB): $(SWSOBJS) + $(AR) r $(SWSLIB) $(SWSOBJS) clean: - rm -f *.o *.a *~ + rm -f *.o *.a *~ *.so distclean: - rm -f Makefile.bak *.o *.a *~ .depend + rm -f Makefile.bak *.o *.a *~ *.so .depend dep: depend @@ -36,6 +41,27 @@ depend: cs_test: $(CS_TEST_OBJS) $(CC) $(CS_TEST_OBJS) -o cs_test +postprocess_pic.o: postprocess.c + $(CC) -c $(CFLAGS) -fPIC -DPIC -o $@ $< + +$(SPPLIB): $(SPPOBJS) + $(CC) -shared -Wl,-soname,$(SPPLIB).0 \ + -o $(SPPLIB) $(SPPOBJS) + +$(PPLIB): $(PPOBJS) + $(AR) r $(PPLIB) $(PPOBJS) + +install: all +ifeq ($(SHARED_PP),yes) + install -d $(prefix)/lib + install -s -m 755 $(SPPLIB) $(prefix)/lib/$(SPPLIB).$(SPPVERSION) + ln -sf $(SPPLIB).$(SPPVERSION) $(prefix)/lib/$(SPPLIB) + ldconfig || true + mkdir -p $(prefix)/include/postproc + install -m 644 postprocess.h $(prefix)/include/postproc/postprocess.h +endif + + # # include dependency files if they exist # diff --git a/postproc/postprocess.c b/postproc/postprocess.c index 15399d4..a732d40 100644 --- a/postproc/postprocess.c +++ b/postproc/postprocess.c @@ -49,7 +49,6 @@ c = checked against the other implementations (-vo md5) TODO: remove global/static vars reduce the time wasted on the mem transfer -implement everything in C at least (done at the moment but ...) unroll stuff if instructions depend too much on the prior one we use 8x8 blocks for the horizontal filters, opendivx seems to use 8x4? move YScale thing to the end instead of fixing QP @@ -58,13 +57,9 @@ make the mainloop more flexible (variable number of blocks at once (the if/else stuff per block is slowing things down) compare the quality & speed of all filters split this huge file -border remover optimize c versions try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks -smart blur -commandline option for the deblock / dering thresholds put fastmemcpy back -dont use #ifdef ARCH_X86 for the asm stuff ... cross compilers? (note cpudetect uses ARCH_X86) ... */ @@ -84,7 +79,7 @@ dont use #ifdef ARCH_X86 for the asm stuff ... cross compilers? (note cpudetect //#undef HAVE_MMX //#undef ARCH_X86 //#define DEBUG_BRIGHTNESS -//#include "../libvo/fastmemcpy.h" +#include "../libvo/fastmemcpy.h" #include "postprocess.h" #include "../cpudetect.h" #include "../mangle.h" @@ -96,79 +91,83 @@ dont use #ifdef ARCH_X86 for the asm stuff ... cross compilers? (note cpudetect #define GET_MODE_BUFFER_SIZE 500 #define OPTIONS_ARRAY_SIZE 10 +#define BLOCK_SIZE 8 +#define TEMP_STRIDE 8 +//#define NUM_BLOCKS_AT_ONCE 16 //not used yet #ifdef ARCH_X86 -#define CAN_COMPILE_X86_ASM -#endif - -#ifdef CAN_COMPILE_X86_ASM -static volatile uint64_t __attribute__((aligned(8))) packedYOffset= 0x0000000000000000LL; -static volatile uint64_t __attribute__((aligned(8))) packedYScale= 0x0100010001000100LL; static uint64_t __attribute__((aligned(8))) w05= 0x0005000500050005LL; static uint64_t __attribute__((aligned(8))) w20= 0x0020002000200020LL; -static uint64_t __attribute__((aligned(8))) w1400= 0x1400140014001400LL; -static uint64_t __attribute__((aligned(8))) bm00000001= 0x00000000000000FFLL; -static uint64_t __attribute__((aligned(8))) bm00010000= 0x000000FF00000000LL; -static uint64_t __attribute__((aligned(8))) bm00001000= 0x00000000FF000000LL; -static uint64_t __attribute__((aligned(8))) bm10000000= 0xFF00000000000000LL; -static uint64_t __attribute__((aligned(8))) bm10000001= 0xFF000000000000FFLL; -static uint64_t __attribute__((aligned(8))) bm11000011= 0xFFFF00000000FFFFLL; -static uint64_t __attribute__((aligned(8))) bm00000011= 0x000000000000FFFFLL; -static uint64_t __attribute__((aligned(8))) bm11111110= 0xFFFFFFFFFFFFFF00LL; -static uint64_t __attribute__((aligned(8))) bm11000000= 0xFFFF000000000000LL; -static uint64_t __attribute__((aligned(8))) bm00011000= 0x000000FFFF000000LL; -static uint64_t __attribute__((aligned(8))) bm00110011= 0x0000FFFF0000FFFFLL; -static uint64_t __attribute__((aligned(8))) bm11001100= 0xFFFF0000FFFF0000LL; static uint64_t __attribute__((aligned(8))) b00= 0x0000000000000000LL; static uint64_t __attribute__((aligned(8))) b01= 0x0101010101010101LL; static uint64_t __attribute__((aligned(8))) b02= 0x0202020202020202LL; -static uint64_t __attribute__((aligned(8))) b0F= 0x0F0F0F0F0F0F0F0FLL; -static uint64_t __attribute__((aligned(8))) b04= 0x0404040404040404LL; static uint64_t __attribute__((aligned(8))) b08= 0x0808080808080808LL; -static uint64_t __attribute__((aligned(8))) bFF= 0xFFFFFFFFFFFFFFFFLL; -static uint64_t __attribute__((aligned(8))) b20= 0x2020202020202020LL; static uint64_t __attribute__((aligned(8))) b80= 0x8080808080808080LL; -static uint64_t __attribute__((aligned(8))) mmxDCOffset= 0x7E7E7E7E7E7E7E7ELL; -static uint64_t __attribute__((aligned(8))) mmxDCThreshold= 0x7C7C7C7C7C7C7C7CLL; -static uint64_t __attribute__((aligned(8))) b3F= 0x3F3F3F3F3F3F3F3FLL; -static uint64_t __attribute__((aligned(8))) temp0=0; -static uint64_t __attribute__((aligned(8))) temp1=0; -static uint64_t __attribute__((aligned(8))) temp2=0; -static uint64_t __attribute__((aligned(8))) temp3=0; -static uint64_t __attribute__((aligned(8))) temp4=0; -static uint64_t __attribute__((aligned(8))) temp5=0; -static uint64_t __attribute__((aligned(8))) pQPb=0; -static uint64_t __attribute__((aligned(8))) pQPb2=0; -static uint8_t __attribute__((aligned(8))) tempBlocks[8*16*2]; //used for the horizontal code -static uint32_t __attribute__((aligned(4))) maxTmpNoise[4]; -#else -static uint64_t packedYOffset= 0x0000000000000000LL; -static uint64_t packedYScale= 0x0100010001000100LL; #endif extern int divx_quality; -int newPPFlag=0; //is set if -npp is used -struct PPMode gPPMode[GET_PP_QUALITY_MAX+1]; -static int firstTime = 0, firstTime2 = 0; +static int firstTime2 = 0; extern int verbose; -int hFlatnessThreshold= 56 - 16; -int vFlatnessThreshold= 56 - 16; int deringThreshold= 20; -static int dcOffset; -static int dcThreshold; - //amount of "black" u r willing to loose to get a brightness corrected picture double maxClippedThreshold= 0.01; +struct PPFilter{ + char *shortName; + char *longName; + int chromDefault; // is chrominance filtering on by default if this filter is manually activated + int minLumQuality; // minimum quality to turn luminance filtering on + int minChromQuality; // minimum quality to turn chrominance filtering on + int mask; // Bitmask to turn this filter on +}; + +typedef struct PPContext{ + uint8_t *tempBlocks; //used for the horizontal code + + /* we need 64bit here otherwise we´ll going to have a problem + after watching a black picture for 5 hours*/ + uint64_t *yHistogram; + + uint64_t __attribute__((aligned(8))) packedYOffset; + uint64_t __attribute__((aligned(8))) packedYScale; + + /* Temporal noise reducing buffers */ + uint8_t *tempBlured[3]; + int32_t *tempBluredPast[3]; + + /* Temporary buffers for handling the last row(s) */ + uint8_t *tempDst; + uint8_t *tempSrc; + + /* Temporary buffers for handling the last block */ + uint8_t *tempDstBlock; + uint8_t *tempSrcBlock; + uint8_t *deintTemp; + + uint64_t __attribute__((aligned(8))) pQPb; + uint64_t __attribute__((aligned(8))) pQPb2; + + uint64_t __attribute__((aligned(8))) mmxDcOffset; + uint64_t __attribute__((aligned(8))) mmxDcThreshold; + + int QP; + int dcOffset; + int dcThreshold; + + int frameNum; + + PPMode ppMode; +} PPContext; + static struct PPFilter filters[]= { {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK}, {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK}, - {"hr", "rkhdeblock", 1, 1, 3, H_RK1_FILTER}, - {"vr", "rkvdeblock", 1, 2, 4, V_RK1_FILTER}, +/* {"hr", "rkhdeblock", 1, 1, 3, H_RK1_FILTER}, + {"vr", "rkvdeblock", 1, 2, 4, V_RK1_FILTER},*/ {"h1", "x1hdeblock", 1, 1, 3, H_X1_FILTER}, {"v1", "x1vdeblock", 1, 2, 4, V_X1_FILTER}, {"dr", "dering", 1, 5, 6, DERING}, @@ -177,6 +176,7 @@ static struct PPFilter filters[]= {"li", "linipoldeint", 1, 1, 4, LINEAR_IPOL_DEINT_FILTER}, {"ci", "cubicipoldeint", 1, 1, 4, CUBIC_IPOL_DEINT_FILTER}, {"md", "mediandeint", 1, 1, 4, MEDIAN_DEINT_FILTER}, + {"fd", "ffmpegdeint", 1, 1, 4, FFMPEG_DEINT_FILTER}, {"tn", "tmpnoise", 1, 7, 8, TEMP_NOISE_FILTER}, {"fq", "forcequant", 1, 0, 0, FORCE_QUANT}, {NULL, NULL,0,0,0,0} //End Marker @@ -191,19 +191,13 @@ static char *replaceTable[]= NULL //End Marker }; -#ifdef CAN_COMPILE_X86_ASM +#ifdef ARCH_X86 static inline void unusedVariableWarningFixer() { -if( - packedYOffset + packedYScale + w05 + w20 + w1400 + bm00000001 + bm00010000 - + bm00001000 + bm10000000 + bm10000001 + bm11000011 + bm00000011 + bm11111110 - + bm11000000 + bm00011000 + bm00110011 + bm11001100 + b00 + b01 + b02 + b0F - + bFF + b20 + b04+ b08 + pQPb2 + b80 + mmxDCOffset + mmxDCThreshold + b3F + temp0 + temp1 + temp2 + temp3 + temp4 - + temp5 + pQPb== 0) b00=0; + if(w05 + w20 + b00 + b01 + b02 + b08 + b80 == 0) b00=0; } #endif -#ifdef TIMING static inline long long rdtsc() { long long l; @@ -213,9 +207,8 @@ static inline long long rdtsc() // printf("%d\n", int(l/1000)); return l; } -#endif -#ifdef CAN_COMPILE_X86_ASM +#ifdef ARCH_X86 static inline void prefetchnta(void *p) { asm volatile( "prefetchnta (%0)\n\t" @@ -250,22 +243,48 @@ static inline void prefetcht2(void *p) /** * Check if the given 8x8 Block is mostly "flat" */ -static inline int isHorizDC(uint8_t src[], int stride) +static inline int isHorizDC(uint8_t src[], int stride, PPContext *c) { int numEq= 0; int y; + const int dcOffset= c->dcOffset; + const int dcThreshold= c->dcThreshold; for(y=0; y c->ppMode.flatnessThreshold; +} + +/** + * Check if the middle 8x8 Block in the given 8x16 block is flat + */ +static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c){ + int numEq= 0; + int y; + const int dcOffset= c->dcOffset; + const int dcThreshold= c->dcThreshold; + src+= stride*4; // src points to begin of the 8x8 Block + for(y=0; y hFlatnessThreshold; + return numEq > c->ppMode.flatnessThreshold; } static inline int isHorizMinMaxOk(uint8_t src[], int stride, int QP) @@ -422,7 +441,7 @@ static inline void horizX1Filter(uint8_t *src, int stride, int QP) #define COMPILE_C #endif -#ifdef CAN_COMPILE_X86_ASM +#ifdef ARCH_X86 #if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT) #define COMPILE_MMX @@ -435,7 +454,7 @@ static inline void horizX1Filter(uint8_t *src, int stride, int QP) #if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT) #define COMPILE_3DNOW #endif -#endif //CAN_COMPILE_X86_ASM +#endif //ARCH_X86 #undef HAVE_MMX #undef HAVE_MMX2 @@ -487,50 +506,47 @@ static inline void horizX1Filter(uint8_t *src, int stride, int QP) // minor note: the HAVE_xyz is messed up after that line so dont use it static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, - QP_STORE_T QPs[], int QPStride, int isColor, struct PPMode *ppMode) + QP_STORE_T QPs[], int QPStride, int isColor, PPMode *ppMode, void *vc) { + PPContext *c= (PPContext *)vc; + c->ppMode= *ppMode; //FIXME + // useing ifs here as they are faster than function pointers allthough the // difference wouldnt be messureable here but its much better because // someone might exchange the cpu whithout restarting mplayer ;) #ifdef RUNTIME_CPUDETECT -#ifdef CAN_COMPILE_X86_ASM +#ifdef ARCH_X86 // ordered per speed fasterst first if(gCpuCaps.hasMMX2) - postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); else if(gCpuCaps.has3DNow) - postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); else if(gCpuCaps.hasMMX) - postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); else - postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); #else - postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); #endif #else //RUNTIME_CPUDETECT #ifdef HAVE_MMX2 - postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); #elif defined (HAVE_3DNOW) - postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); #elif defined (HAVE_MMX) - postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); #else - postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, ppMode); + postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); #endif #endif //!RUNTIME_CPUDETECT } -#ifdef HAVE_ODIVX_POSTPROCESS -#include "../opendivx/postprocess.h" -int use_old_pp=0; -#endif - //static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, // QP_STORE_T QPs[], int QPStride, int isColor, struct PPMode *ppMode); /* -pp Command line Help -NOTE/FIXME: put this at an appropriate place (--help, html docs, man mplayer)? */ -char *help= +char *postproc_help= "-npp [: