vf_divtc.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 705 行 · 第 1/2 页
C
705 行
#include <uclib.h>#include <uclib.h>#include <mplaylib.h>#include <math.h>#include "config.h"#include "mp_msg.h"#include "cpudetect.h"#include "libavutil/common.h"#include "mpbswap.h"#include "img_format.h"#include "mp_image.h"#include "vf.h"#include "libvo/fastmemcpy.h"#undef memcpy#define memcpy uc_memcpyvf_info_t vf_info_divtc;struct vf_priv_s { int deghost, pass, phase, window, fcount, bcount, frameno, misscount, ocount, sum[5]; double threshold; FILE *file; char *bdata; unsigned int *csdata; int *history; };/* * diff_MMX and diff_C stolen from vf_decimate.c */#ifdef HAVE_MMXstatic int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns) { volatile short out[4]; asm ( "movl $8, %%ecx \n\t" "pxor %%mm4, %%mm4 \n\t" "pxor %%mm7, %%mm7 \n\t" ASMALIGN(4) "1: \n\t" "movq (%%"REG_S"), %%mm0 \n\t" "movq (%%"REG_S"), %%mm2 \n\t" "add %%"REG_a", %%"REG_S" \n\t" "movq (%%"REG_D"), %%mm1 \n\t" "add %%"REG_b", %%"REG_D" \n\t" "psubusb %%mm1, %%mm2 \n\t" "psubusb %%mm0, %%mm1 \n\t" "movq %%mm2, %%mm0 \n\t" "movq %%mm1, %%mm3 \n\t" "punpcklbw %%mm7, %%mm0 \n\t" "punpcklbw %%mm7, %%mm1 \n\t" "punpckhbw %%mm7, %%mm2 \n\t" "punpckhbw %%mm7, %%mm3 \n\t" "paddw %%mm0, %%mm4 \n\t" "paddw %%mm1, %%mm4 \n\t" "paddw %%mm2, %%mm4 \n\t" "paddw %%mm3, %%mm4 \n\t" "decl %%ecx \n\t" "jnz 1b \n\t" "movq %%mm4, (%%"REG_d") \n\t" "emms \n\t" : : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out) : "memory" ); return out[0]+out[1]+out[2]+out[3]; }#endifstatic int diff_C(unsigned char *old, unsigned char *new, int os, int ns) { int x, y, d=0; for(y=8; y; y--, new+=ns, old+=os) for(x=8; x; x--) d+=abs(new[x]-old[x]); return d; }static int (*diff)(unsigned char *, unsigned char *, int, int);static int diff_plane(unsigned char *old, unsigned char *new, int w, int h, int os, int ns, int arg) { int x, y, d, max=0, sum=0, n=0; for(y=0; y<h-7; y+=8) { for(x=0; x<w-7; x+=8) { d=diff(old+x+y*os, new+x+y*ns, os, ns); if(d>max) max=d; sum+=d; n++; } } return (sum+n*max)/2; }/*static unsigned int checksum_plane(unsigned char *p, unsigned char *z, int w, int h, int s, int zs, int arg) { unsigned int shift, sum; unsigned char *e; for(sum=0; h; h--, p+=s-w) for(e=p+w, shift=32; p<e;) sum^=(*p++)<<(shift=(shift-8)&31); return sum; }*/static unsigned int checksum_plane(unsigned char *p, unsigned char *z, int w, int h, int s, int zs, int arg) { unsigned int shift; uint32_t sum, t; unsigned char *e, *e2;#if MP_WORDSIZE==64 typedef uint64_t wsum_t;#else typedef uint32_t wsum_t;#endif wsum_t wsum; for(sum=0; h; h--, p+=s-w) { for(shift=0, e=p+w; (int)p&(sizeof(wsum_t)-1) && p<e;) sum^=*p++<<(shift=(shift-8)&31); for(wsum=0, e2=e-sizeof(wsum_t)+1; p<e2; p+=sizeof(wsum_t)) wsum^=*(wsum_t *)p;#if MP_WORDSIZE==64 t=be2me_32((uint32_t)(wsum>>32^wsum));#else t=be2me_32(wsum);#endif for(sum^=(t<<shift|t>>(32-shift)); p<e;) sum^=*p++<<(shift=(shift-8)&31); } return sum; }static int deghost_plane(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss, int threshold) { int t; unsigned char *e; for(; h; h--, s+=ss-w, d+=ds-w) for(e=d+w; d<e; d++, s++) if(abs(*d-*s)>=threshold) *d=(t=(*d<<1)-*s)<0?0:t>255?255:t; return 0; }static int copyop(unsigned char *d, unsigned char *s, int bpl, int h, int dstride, int sstride, int dummy) { memcpy_pic(d, s, bpl, h, dstride, sstride); return 0;}static int imgop(int(*planeop)(unsigned char *, unsigned char *, int, int, int, int, int), mp_image_t *dst, mp_image_t *src, int arg) { if(dst->flags&MP_IMGFLAG_PLANAR) return planeop(dst->planes[0], src?src->planes[0]:0, dst->w, dst->h, dst->stride[0], src?src->stride[0]:0, arg)+ planeop(dst->planes[1], src?src->planes[1]:0, dst->chroma_width, dst->chroma_height, dst->stride[1], src?src->stride[1]:0, arg)+ planeop(dst->planes[2], src?src->planes[2]:0, dst->chroma_width, dst->chroma_height, dst->stride[2], src?src->stride[2]:0, arg); return planeop(dst->planes[0], src?src->planes[0]:0, dst->w*(dst->bpp/8), dst->h, dst->stride[0], src?src->stride[0]:0, arg); }/* * Find the phase in which the telecine pattern fits best to the * given 5 frame slice of frame difference measurements. * * If phase1 and phase2 are not negative, only the two specified * phases are tested. */static int match(struct vf_priv_s *p, int *diffs, int phase1, int phase2, double *strength) { static const int pattern1[]={ -4, 1, 1, 1, 1 }, pattern2[]={ -2, -3, 4, 4, -3 }, *pattern; int f, m, n, t[5]; pattern=p->deghost>0?pattern2:pattern1; for(f=0; f<5; f++) { if(phase1<0 || phase2<0 || f==phase1 || f==phase2) { for(n=t[f]=0; n<5; n++) t[f]+=diffs[n]*pattern[(n-f+5)%5]; } else t[f]=INT_MIN; } /* find the best match */ for(m=0, n=1; n<5; n++) if(t[n]>t[m]) m=n; if(strength) { /* the second best match */ for(f=m?0:1, n=f+1; n<5; n++) if(n!=m && t[n]>t[f]) f=n; *strength=(t[m]>0?(double)(t[m]-t[f])/t[m]:0.0); } return m; }static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts) { mp_image_t *dmpi, *tmpi=0; int n, m, f, newphase; struct vf_priv_s *p=vf->priv; unsigned int checksum; double d; dmpi=vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, mpi->width, mpi->height); vf_clone_mpi_attributes(dmpi, mpi); newphase=p->phase; switch(p->pass) { case 1: fprintf(p->file, "%08x %d\n", (unsigned int)imgop((void *)checksum_plane, mpi, 0, 0), p->frameno?imgop(diff_plane, dmpi, mpi, 0):0); break; case 2: if(p->frameno/5>p->bcount) { mp_msg(MSGT_VFILTER, MSGL_ERR, "\n%s: Log file ends prematurely! " "Switching to one pass mode.\n", vf->info->name); p->pass=0; break; } checksum=(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0); if(checksum!=p->csdata[p->frameno]) { for(f=0; f<100; f++) if(p->frameno+f<p->fcount && p->csdata[p->frameno+f]==checksum) break; else if(p->frameno-f>=0 && p->csdata[p->frameno-f]==checksum) { f=-f; break; } if(f<100) { mp_msg(MSGT_VFILTER, MSGL_INFO, "\n%s: Mismatch with pass-1: %+d frame(s).\n", vf->info->name, f); p->frameno+=f; p->misscount=0; } else if(p->misscount++>=30) { mp_msg(MSGT_VFILTER, MSGL_ERR, "\n%s: Sync with pass-1 lost! " "Switching to one pass mode.\n", vf->info->name); p->pass=0; break; } } n=(p->frameno)/5; if(n>=p->bcount) n=p->bcount-1; newphase=p->bdata[n]; break; default: if(p->frameno) { int *sump=p->sum+p->frameno%5, *histp=p->history+p->frameno%p->window; *sump-=*histp; *sump+=(*histp=imgop(diff_plane, dmpi, mpi, 0)); } m=match(p, p->sum, -1, -1, &d); if(d>=p->threshold) newphase=m; } n=p->ocount++%5; if(newphase!=p->phase && ((p->phase+4)%5<n)==((newphase+4)%5<n)) { p->phase=newphase; mp_msg(MSGT_VFILTER, MSGL_STATUS, "\n%s: Telecine phase %d.\n", vf->info->name, p->phase); } switch((p->frameno++-p->phase+10)%5) { case 0: imgop(copyop, dmpi, mpi, 0); return 0; case 4: if(p->deghost>0) { tmpi=vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, mpi->width, mpi->height); vf_clone_mpi_attributes(tmpi, mpi);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?