55 #if HAVE_MMX && HAVE_EBX_AVAILABLE 
   56 static int diff_MMX(
unsigned char *old, 
unsigned char *
new, 
int os, 
int ns)
 
   58    volatile short out[4];
 
   61         "pxor %%mm4, %%mm4 \n\t" 
   62         "pxor %%mm7, %%mm7 \n\t" 
   67         "movq (%%"REG_S
"), %%mm0 \n\t" 
   68         "movq (%%"REG_S
"), %%mm2 \n\t" 
   69         "add %%"REG_a
", %%"REG_S
" \n\t" 
   70         "movq (%%"REG_D
"), %%mm1 \n\t" 
   71         "add %%"REG_b
", %%"REG_D
" \n\t" 
   72         "psubusb %%mm1, %%mm2 \n\t" 
   73         "psubusb %%mm0, %%mm1 \n\t" 
   74         "movq %%mm2, %%mm0 \n\t" 
   75         "movq %%mm1, %%mm3 \n\t" 
   76         "punpcklbw %%mm7, %%mm0 \n\t" 
   77         "punpcklbw %%mm7, %%mm1 \n\t" 
   78         "punpckhbw %%mm7, %%mm2 \n\t" 
   79         "punpckhbw %%mm7, %%mm3 \n\t" 
   80         "paddw %%mm0, %%mm4 \n\t" 
   81         "paddw %%mm1, %%mm4 \n\t" 
   82         "paddw %%mm2, %%mm4 \n\t" 
   83         "paddw %%mm3, %%mm4 \n\t" 
   87         "movq %%mm4, (%%"REG_d
") \n\t" 
   90         : 
"S" (old), 
"D" (
new), 
"a" ((
long)os), 
"b" ((
long)ns), 
"d" (out)
 
   93    return out[0]+out[1]+out[2]+out[3];
 
   97 static int diff_C(
unsigned char *old, 
unsigned char *
new, 
int os, 
int ns)
 
  101    for(y=8; 
y; y--, 
new+=ns, old+=os)
 
  103          d+=abs(
new[x]-old[x]);
 
  108 static int (*
diff)(
unsigned char *, 
unsigned char *, int, int);
 
  110 static int diff_plane(
unsigned char *old, 
unsigned char *
new,
 
  111                       int w, 
int h, 
int os, 
int ns, 
int arg)
 
  113    int x, 
y, d, max=0, sum=0, n=0;
 
  115    for(y=0; y<h-7; y+=8)
 
  117       for(x=0; x<w-7; x+=8)
 
  119          d=
diff(old+x+y*os, 
new+x+y*ns, os, ns);
 
  126    return (sum+n*max)/2;
 
  145                                    int w, 
int h, 
int s, 
int zs, 
int arg)
 
  149    unsigned char *e, *e2;
 
  151    typedef uint64_t wsum_t;
 
  153    typedef uint32_t wsum_t;
 
  157    for(sum=0; h; h--, p+=s-w)
 
  159       for(shift=0, e=p+w; (int)p&(
sizeof(wsum_t)-1) && p<e;)
 
  160          sum^=*p++<<(shift=(shift-8)&31);
 
  162       for(wsum=0, e2=e-
sizeof(wsum_t)+1; p<e2; p+=
sizeof(wsum_t))
 
  166       t=
be2me_32((uint32_t)(wsum>>32^wsum));
 
  171       for(sum^=(t<<shift|t>>(32-shift)); p<e;)
 
  172          sum^=*p++<<(shift=(shift-8)&31);
 
  179                          int w, 
int h, 
int ds, 
int ss, 
int threshold)
 
  184    for(; h; h--, s+=ss-w, d+=ds-w)
 
  185       for(e=d+w; d<e; d++, s++)
 
  186          if(abs(*d-*s)>=threshold)
 
  187             *d=(t=(*d<<1)-*s)<0?0:t>255?255:
t;
 
  192 static int copyop(
unsigned char *d, 
unsigned char *s, 
int bpl, 
int h, 
int dstride, 
int sstride, 
int dummy) {
 
  197 static int imgop(
int(*planeop)(
unsigned char *, 
unsigned char *,
 
  198                                int, 
int, 
int, 
int, 
int),
 
  213                   dst->
w*(dst->
bpp/8), dst->
h,
 
  226                  int phase1, 
int phase2, 
double *strength)
 
  228    static const int pattern1[]={ -4,  1, 1, 1, 1 },
 
  229       pattern2[]={ -2, -3, 4, 4, -3 }, *pattern;
 
  232    pattern=p->
deghost>0?pattern2:pattern1;
 
  236       if(phase1<0 || phase2<0 || f==phase1 || f==phase2)
 
  238          for(n=t[f]=0; n<5; n++)
 
  239             t[f]+=diffs[n]*pattern[(n-f+5)%5];
 
  246    for(m=0, n=1; n<5; n++)
 
  252       for(f=m?0:1, n=f+1; n<5; n++)
 
  253          if(n!=m && t[n]>t[f]) f=n;
 
  255       *strength=(t[
m]>0?(double)(t[m]-t[f])/t[
m]:0.0);
 
  264    int n, 
m, f, newphase;
 
  266    unsigned int checksum;
 
  280          fprintf(p->
file, 
"%08x %d\n",
 
  289                    "\n%s: Log file ends prematurely! " 
  290                    "Switching to one pass mode.\n", vf->info->name);
 
  311                       "\n%s: Mismatch with pass-1: %+d frame(s).\n",
 
  320                       "\n%s: Sync with pass-1 lost! " 
  321                       "Switching to one pass mode.\n", vf->info->name);
 
  330          newphase=p->
bdata[n];
 
  351    if(newphase!=p->
phase && ((p->
phase+4)%5<n)==((newphase+4)%5<n))
 
  355              "\n%s: Telecine phase %d.\n", vf->info->name, p->
phase);
 
  386    int *
buf=0, *bp, bufsize=0, n, 
b, f, i, j, 
m, s;
 
  387    unsigned int *cbuf=0, *cp;
 
  396    while(fgets(lbuf, 256, p->
file))
 
  400          bufsize=bufsize?bufsize*2:30000;
 
  401          if((bp=realloc(buf, bufsize*
sizeof *buf))) buf=bp;
 
  402          if((cp=realloc(cbuf, bufsize*
sizeof *cbuf))) cbuf=cp;
 
  407                    ff_vf_info_divtc.
name);
 
  413       sscanf(lbuf, 
"%x %d", cbuf+n, buf+n);
 
  420              ff_vf_info_divtc.
name);
 
  431    memcpy(buf-15, buf, 15*
sizeof *buf);
 
  432    memset(cbuf-15, 0, 15*
sizeof *cbuf);
 
  435       buf[n]=buf[n-5], cbuf[n]=0, n++;
 
  437    memcpy(buf+n, buf+n-15, 15*
sizeof *buf);
 
  438    memset(cbuf+n, 0, 15*
sizeof *cbuf);
 
  446    memset(pbuf, 255, b);
 
  453       double s0=0.0, 
s1=0.0;
 
  464              "%s: Deghosting %-3s (relative pattern strength %+.2fdB).\n",
 
  465              ff_vf_info_divtc.
name,
 
  473       for(sum[f]=0, n=-15; n<20; n+=5)
 
  478       m=
match(p, sum, -1, -1, &d);
 
  485             sum[n]=sum[n]-buf[5*(f-3)+n]+buf[5*(f+4)+n];
 
  491    for(f=0; f<b && pbuf[f]==-1; f++);
 
  497              ff_vf_info_divtc.
name);
 
  501    for(n=0; n<f; pbuf[n++]=pbuf[f]);
 
  504    for(f=b-1; pbuf[f]==-1; f--);
 
  505    for(n=f+1; n<
b; pbuf[n++]=pbuf[f]);
 
  510       while(f<b && pbuf[f]!=-1) f++;
 
  512       for(n=f; pbuf[n]==-1; n++);
 
  514       if(pbuf[f-1]==pbuf[n])
 
  517          while(f<n) pbuf[f++]=pbuf[n];
 
  525             for(sum[i]=0, j=5*f-15; j<5*f; j+=5)
 
  530             pbuf[i]=
match(p, sum, pbuf[f-1], pbuf[n], 0);
 
  533                sum[j]=sum[j]-buf[5*(i-3)+j]+buf[5*(i+4)+j];
 
  539          for(i=f, m=f; i<n; i++)
 
  540             if(pbuf[i]==pbuf[f-1]) m++;
 
  548                if(pbuf[j-1]==pbuf[f-1] && pbuf[j]==pbuf[n]) 
break;
 
  550                if(pbuf[s-1]==pbuf[f-1] && pbuf[s]==pbuf[n]) 
break;
 
  587 static void uninit(
struct vf_instance *vf)
 
  591       if(vf->priv->file) fclose(vf->priv->file);
 
  592       if(vf->priv->csdata) free(vf->priv->csdata-15);
 
  593       free(vf->priv->bdata);
 
  594       free(vf->priv->history);
 
  602    const char *filename=
"framediff.log";
 
  605    if(args && !(args=strdup(args)))
 
  609              "%s: Not enough memory.\n", vf->
info->
name);
 
  631          if((ap=strchr(q, 
':'))) *ap++=0; 
else ap=q+strlen(q);
 
  632          if((a=strchr(q, 
'='))) *a++=0; 
else a=q+strlen(q);
 
  637             case 'f': filename=
a;                
break;
 
  639             case 'w': p->
window=5*(atoi(a)+4)/5; 
break;
 
  640             case 'd': p->
deghost=atoi(a);        
break;
 
  642                if(q[1]==
'h') p->
phase=atoi(a);
 
  643                else p->
pass=atoi(a);
 
  649                       "pass=1|2         - Use 2-pass mode.\n" 
  650                       "file=filename    - Set the 2-pass log file name " 
  652                       "threshold=value  - Set the pattern recognition " 
  653                       "sensitivity (default %g).\n" 
  654                       "deghost=value    - Select deghosting threshold " 
  656                       "window=numframes - Set the statistics window " 
  657                       "for 1-pass mode (default %d).\n" 
  658                       "phase=0|1|2|3|4  - Set the initial phase " 
  659                       "for 1-pass mode (default %d).\n\n" 
  660                       "The option names can be abbreviated to the shortest " 
  661                       "unique prefix.\n\n",
 
  668                       "%s: Unknown argument %s.\n", vf->
info->
name, q);
 
  676          if(!(p->
file=fopen(filename, 
"w")))
 
  679                    "%s: Can't create file %s.\n", vf->
info->
name, filename);
 
  686          if(!(p->
file=fopen(filename, 
"r")))
 
  689                    "%s: Can't open file %s.\n", vf->
info->
name, filename);
 
  706 #if HAVE_MMX && HAVE_EBX_AVAILABLE 
  716    "inverse telecine for deinterlaced video",