[MN-dev] [mndiff]: r53 - in trunk/2010: 2_crypt.cc 2_vc.cc

michael subversion at mplayerhq.hu
Wed Jul 4 09:30:32 CEST 2007


Author: michael
Date: Wed Jul  4 09:30:32 2007
New Revision: 53

Log:
next version from unknown date


Modified:
   trunk/2010/2_crypt.cc
   trunk/2010/2_vc.cc

Modified: trunk/2010/2_crypt.cc
==============================================================================
--- trunk/2010/2_crypt.cc	(original)
+++ trunk/2010/2_crypt.cc	Wed Jul  4 09:30:32 2007
@@ -53,9 +53,9 @@ static void decomb(int q){
  }
 
  if(q==1){
-   linep= stride*128;
+   linep= stride*256;
    if(o) linep+=vgax<<1;
-   for(line=128; line>=0; line--){
+   for(line=256; line>=0; line--){
      for(i=0; i<wndx; i++){
 
        j = char(actVid2MemBufp->b[linep  + (i<<1)]);

Modified: trunk/2010/2_vc.cc
==============================================================================
--- trunk/2010/2_vc.cc	(original)
+++ trunk/2010/2_vc.cc	Wed Jul  4 09:30:32 2007
@@ -24,11 +24,6 @@
  // ? POINT_LAND + NO_POINT_LAND(1|2) = 910   (FIFO SIZE)
  // ? NO_POINT_LAND + POINT_LAND = 1065       (PHASE ~+-60deg)
 
- // 142 142 16
- // 143 143 14
- // 144 144 12
- // 145 145 10
-
 #define NO_POINT_LAND  (NO_POINT_LAND1 + NO_POINT_LAND2 + NO_POINT_LAND3)
 #define PHASE_POINT    (fmod(FREQ_CHROM / (FREQ_SMP/3.0), 1.0) * PI * 2.0)
 #define PHASE_SMP      (fmod(FREQ_CHROM / (FREQ_SMP    ), 1.0) * PI * 2.0)
@@ -36,16 +31,24 @@
                           * (POINT_LAND + NO_POINT_LAND), 1.0) * PI * 2.0)
 
 
-#define FIX_POINT 10
 #define STEP_START 16
 #define STEP_END 2
-#define VC_DEAD 7.5
 #define DWN_SMP 1
 #define MAX_DRIFT 2
+#define DRIFT_TAB {1200, 400, 0, 400, 1200}
 #define PHASE_CMP_STEP 3
 #define BAD_THRESHOLD1 0.8
 #define BAD_THRESHOLD2 200
-#define PHASE_DIFF_TH 35
+#define EDGE_LIMIT 70
+#define MAX_EDGE 500
+#define EDGE_LOG_COEFF 10
+#define PHASE_EXP 4
+#define PHASE_LIMIT 40
+#define MAX_PHASE_PENALTY 1000
+#define AMP_THRESHOLD 200
+
+#define PHASE_COEFF (MAX_PHASE_PENALTY/pow(PHASE_LIMIT, PHASE_EXP))
+#define EDGE_COEFF (MAX_EDGE/log(EDGE_LIMIT*EDGE_LOG_COEFF))
 
 #define NUM_PHASE_SMP (vcDiff>>PHASE_CMP_STEP)
 
@@ -59,11 +62,9 @@ extern int yuvmode;
 extern int some;
 extern bool mmx;
 
-// FIX ABS ??
-
 static inline float atan3(const float f1, const float f2){
   float out;
-                     // ? don't know what atan2 does ( crashes )
+                     // ?! atan2 crashes 
   asm(//"int $3\n\t"
       "fpatan \n\t"
       : "=t"(out)
@@ -82,25 +83,10 @@ void vc_decrypt(void){
  long alg1=0, alg2=0, alg3=0;
  color c;
 
- int tempScore[2]={0 ,0};
-
- for(int i=0; i<360; i++){
-   double d=i;
-
-//   asm("int $3\n\t");
-   double a=atan2(cos(d/180*PI), sin(d/180*PI));
-   double a2=atan3(cos(d/180*PI), sin(d/180*PI));
-   if(a<0.0) a+=PI*2;
-   if(a2<0.0) a2+=PI*2;
-   printf("xyz %f %f\n",a,a2);
- }
-
  const int lowResSize= mmx ? DWN_SMP : (DWN_SMP-1);
 
  printf("xx%f %f %f\n", PHASE_POINT/PI*180, PHASE_SEG/PI*180, PHASE_SMP/PI*180);
 
- double temp[1000][2];
-
  int vScore=0;
 
 // showPoints=true;
@@ -113,7 +99,6 @@ void vc_decrypt(void){
 
  static int cutP2X[256];
  static int x2CutP[max_x];
-// static byte atanLut[ 1<< (ATAN_LUT_SIZE<<1) ]
 
  static int wndxBak= -1;
  if(wndx != wndxBak){
@@ -132,11 +117,12 @@ void vc_decrypt(void){
  }
  const int vcEndX= vcStartX + int( double(POINT_LAND + NO_POINT_LAND)
                                                * freqPix2 / FREQ_SMP + .5);
+
  printf("vcEndX %d\n",vcEndX);
  if(vcEndX>wndx) error(error_code(-123));
  const int vcDiff=vcEndX - vcStartX;
 
- const int minDist= cutP2X[0]-1;
+ const int minDist= cutP2X[0];
 
  cutPointX[0]=0;
 
@@ -152,28 +138,38 @@ void vc_decrypt(void){
  }
 
  static int edgeLut[512];
+ static int phaseLut[128];
  static bool first= true;
- static int score[40];
 
  static byte phasePerCutP[256];
+ static char sin1PerCutP[256];
+ static char cos1PerCutP[256];
+ static char sin2PerCutP[256];
+ static char cos2PerCutP[256];
 
  if(first){
    some=10;
 
-   edgeLut[0]=0;
-   for(int i=1; i<512; i++){
-     const int j= min(i, 70);
-     edgeLut[i]=int( log(j*10)*100.0 );
+   for(int i=0; i<512; i++){
+     const int j= min(i+1, EDGE_LIMIT);
+     edgeLut[i]=int( log(j*EDGE_LOG_COEFF)*EDGE_COEFF );
+   }
+
+   for(int i=0; i<128; i++){                           
+     const int j= max(min(i, PHASE_LIMIT), 1);
+     phaseLut[i]=int( pow(j, PHASE_EXP)*PHASE_COEFF );
    }
-   first=false;
 
    for(int cutP=0; cutP<256; cutP++){
-     const double phase= PHASE_SMP*(NO_POINT_LAND1 + NO_POINT_LAND3 + 1) + PHASE_POINT*cutP;
+     const double phase= PHASE_SMP*(NO_POINT_LAND1 + NO_POINT_LAND3) + PHASE_POINT*cutP;
      phasePerCutP[cutP]= (byte)( phase * 128 / PI );
-     printf("ppcp %d %d\n", cutP, phasePerCutP[cutP]*360/256);
+     sin1PerCutP[cutP]= char(sin( -phase + PHASE_SEG )*127);
+     cos1PerCutP[cutP]= char(cos( -phase + PHASE_SEG )*127);
+     sin2PerCutP[cutP]= char(sin( -phase )*127);
+     cos2PerCutP[cutP]= char(cos( -phase )*127);
    }
 
-   for(int i=0; i<40; i++) score[i]=0;
+   first=false;
 
  }
 
@@ -184,8 +180,6 @@ void vc_decrypt(void){
  const float cosSegPhase2= cos(PHASE_SEG*2);
 
  bool *black= new bool[wndy];
- int *phaseDiff= new int[(vcDiff*wndy)>>PHASE_CMP_STEP];
- int *chromAmp= new int[wndy];
 
  int llinep=-(vgax<<2);
  int linep=-(vgax<<1);
@@ -325,22 +319,23 @@ void vc_decrypt(void){
      firstPass=false;
    }
 
-   if( int( avgDiff*BAD_THRESHOLD1/double(avgDiffNum) ) - BAD_THRESHOLD2
+   if( int( avgDiff*BAD_THRESHOLD1/float(avgDiffNum) ) - BAD_THRESHOLD2
                                                                  < bestDiff )
        black[line]=true;
 
    if(line>2){
 
      int sumI=0;
-     for(int x=-4; x<0; x+=2){
+     for(int x=-2; x<2; x+=2){
        const int nx= x + (vcDiff & ~1);
        const int ul= char(actVid2MemBufp->b[ linep + (((vcStartX & ~1) +  x)<<1) + 0]);
        const int vl= char(actVid2MemBufp->b[ linep + (((vcStartX & ~1) +  x)<<1) + 2]);
        const int un= char(actVid2MemBufp->b[ linep + (((vcStartX & ~1) + nx)<<1) + 0]);
        const int vn= char(actVid2MemBufp->b[ linep + (((vcStartX & ~1) + nx)<<1) + 2]);
        sumI+= ul*vn - vl*un;
+//       actVid2MemBufp->b[linep + (((vcStartX & ~1) - x)<<1) + 1]=255;
+//       actVid2MemBufp->b[linep + (((vcStartX & ~1) - nx)<<1) + 1]=255;
      }
-//     actVid2MemBufp->b[linep + (((vcStartX & ~1) - 4)<<1) + 1]=255;
   
      if(line>10 && line<250){
        if(line & 1){
@@ -363,17 +358,21 @@ void vc_decrypt(void){
    }
  }
 
- delete [] convVec;
  deleteAlign(lowRes[0]);
  deleteAlign(lowRes[1]);
 
- int *dir=new int[257*(wndy + 1)];
+ byte *dir=new byte[257*(wndy + 1)];
 
- const int driftPenalty[MAX_DRIFT*2+1]={10000, 1000, 0, 1000, 10000};
+ const int driftPenalty[MAX_DRIFT*2+1]= DRIFT_TAB;
 
  int *newVal=new int[257], *lastVal=new int[257];
  memset(lastVal, 0, 257<<2);
 
+ byte *newPhaseErr=new byte[256], *lastPhaseErr=new byte[256];
+ memset(lastPhaseErr, 0, 256);
+
+ long tst1=0, tst2=0, tst3=0;
+
  llinep=-(vgax<<2);
  linep=-(vgax<<1);
  for(int line=0; line<wndy; line++){
@@ -381,16 +380,17 @@ void vc_decrypt(void){
    linep+=vgax<<1;
 
    memset(newVal, 0, 257<<2);
+   memset(newPhaseErr, 0, 256);
    bool noLeft=true;
 
-   dir[line*257 + 256]=-1;
+   dir[line*257 + 256]=0;
 
    if(line==0) continue;
 
    int relCutPX= cutPointX[line] - cutPointX[line-1];
    if(relCutPX<0) relCutPX+=vcDiff;
 
-   chromAmp[line]=0;
+   int chromAmp=1;
    for(int x=0; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
      int nx= x + (relCutPX & ~1);
      if(nx>=vcDiff) nx-= (vcDiff & ~1);
@@ -401,27 +401,36 @@ void vc_decrypt(void){
      const int p= x>>(PHASE_CMP_STEP-1);
      convVec[p  ]= ul*un + vl*vn;
      convVec[p+1]= ul*vn - vl*un;
-     chromAmp[line]+= un*un + vn*vn;
+     chromAmp+= mabs(un) + mabs(vn);
    }
-
+   
 //   actVid2MemBufp->b[linep + ((vcStartX +  0)<<1) + 1]=255;
 //   actVid2MemBufp->b[linep + ((vcStartX +  relCutPX)<<1) + 1]=200;
 
+   if(iState){
+     T2=uclock();
+     tst1+=T2-T1;
+     T1=T2;
+   }
+
    int sumR0=0, sumI0=0;
    int sumR1=0, sumI1=0;
-   for(int x=0; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
-     const int p= x>>(PHASE_CMP_STEP-1);
-     if(x+relCutPX<vcDiff){
+
+   {                 
+     int x=0;
+     for(; x<vcDiff-relCutPX; x+= 1<<PHASE_CMP_STEP){
+       const int p= x>>(PHASE_CMP_STEP-1);
        sumR0+= convVec[p  ];
        sumI0+= convVec[p+1];
      }
-     else{
+     for(; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
+       const int p= x>>(PHASE_CMP_STEP-1);
        sumR1+= convVec[p  ];
        sumI1+= convVec[p+1];
      }
    }
 
-   const float s= ( (line & 1) ^ ( vScore>0 ) ) ? 1 : -1;
+   const float s= ( (line & 1) ^ ( vScore>0 ) ) ? -1 : 1;
 
    int sumR0C= int( sumR0*cosSegPhase   + sumI0*sinSegPhase*s);
    int sumI0C= int(-sumR0*sinSegPhase*s + sumI0*cosSegPhase);
@@ -433,114 +442,131 @@ void vc_decrypt(void){
    int ssR0=sumR0, ssI0=sumI0;
    int ffR1=0    , ffI1=0;
    int ssR1=sumR1, ssI1=sumI1;
-   const int phaseP= line*vcDiff>>PHASE_CMP_STEP;
-   for(int x=0; x<vcDiff; x+= 1<<PHASE_CMP_STEP){
-     const int p= x>>(PHASE_CMP_STEP-1);
-     const int q= x>> PHASE_CMP_STEP;
-     if(x+relCutPX<vcDiff){
-       ssR0-=convVec[p  ];
-       ssI0-=convVec[p+1];
 
-       const int r= ffR0 + sumR1C;
-       const int i= ffI0 + sumI1C;
+   int lastPhasePos=0;
+            
+   byte ang=0;
+   if(!black[line]){
+     for(int lastCutP = 0; lastCutP < 256; lastCutP++){
+       if(lastVal[lastCutP]==0) continue;
 
-       phaseDiff[phaseP + q  ]= int( atan3(i, r)/PI*128 ) & 0xFF;
-/*
-       phaseDiff[phaseP + q  ]= ffR0 ;//+ sumR1C;
-       phaseDiff[phaseP + q+1]= ffI0 ;//+ sumI1C;
-       phaseDiff[phaseP + q+2]= ssR0;
-       phaseDiff[phaseP + q+3]= ssI0;
-  */
-       ffR0+=convVec[p  ];
-       ffI0+=convVec[p+1];
-     }
-     else{
-       ssR1-=convVec[p  ];
-       ssI1-=convVec[p+1];
+       const int newPhasePos= cutP2X[ lastCutP ] & ((-1) << PHASE_CMP_STEP);
 
-       const int r= ffR1 + sumR0C;
-       const int i= ffI1 + sumI0C;
+       if( newPhasePos >= lastPhasePos ){
 
-       phaseDiff[phaseP + q  ]= int( atan3(i, r)/PI*128 ) & 0xFF;
-/*
-       phaseDiff[phaseP + q  ]= ffR1 ;//+ sumR0C;
-       phaseDiff[phaseP + q+1]= ffI1 ;//+ sumI0C;
-       phaseDiff[phaseP + q+2]= ssR1;
-       phaseDiff[phaseP + q+3]= ssI1;
-  */
-       ffR1+=convVec[p  ];
-       ffI1+=convVec[p+1];
-     }
-   }     
+         for(; lastPhasePos <= newPhasePos; lastPhasePos += (1<<PHASE_CMP_STEP)){
+           const bool isLast= lastPhasePos == newPhasePos;
+
+           const int p= lastPhasePos>>(PHASE_CMP_STEP-1);
+
+           if(lastPhasePos+relCutPX<vcDiff){
+             ssR0-=convVec[p  ];
+             ssI0-=convVec[p+1];
+         
+             if(isLast){
+               const int r= ssR0 + sumR1C + int( ffR0*cosSegPhase2   + ffI0*sinSegPhase2*s);
+               const int i= ssI0 + sumI1C + int(-ffR0*sinSegPhase2*s + ffI0*cosSegPhase2);
             
-   for(int lastCutP = 0; lastCutP < 256; lastCutP++){
-     if(black[line] || lastVal[lastCutP]==0) continue;
+               ang= (byte)( atan3(i, r)/PI*128 );
+             }
 
-     int newXTemp= cutPointX[line] - cutPointX[line-1] + cutP2X[lastCutP];
-     if(newXTemp <  0     ) newXTemp+= vcDiff;
-     if(newXTemp >= vcDiff) newXTemp-= vcDiff;
-     if(newXTemp >= vcDiff) newXTemp-= vcDiff;
+             ffR0+=convVec[p  ];
+             ffI0+=convVec[p+1];
+           }
+           else{
+             ssR1-=convVec[p  ];
+             ssI1-=convVec[p+1];
+     
+             if(isLast){
+               const int r= ssR1 + sumR0C + int( ffR0*cosSegPhase2   + ffI0*sinSegPhase2*s);
+               const int i= ssI1 + sumI0C + int(-ffR0*sinSegPhase2*s + ffI0*cosSegPhase2);
 
-     const int newCutPStart= max(x2CutP[ newXTemp ] - MAX_DRIFT, 0);
-     const int newCutPEnd=   min(x2CutP[ newXTemp ] + MAX_DRIFT, 256);
+               ang= (byte)( atan3(i, r)/PI*128 );
+             }
 
-     int drift= newCutPStart - (x2CutP[ newXTemp ] - MAX_DRIFT);
+             ffR1+=convVec[p  ];
+             ffI1+=convVec[p+1];
+           }
 
-     const int p=  (line*vcDiff>>PHASE_CMP_STEP)
-                  +(cutP2X[ lastCutP ]>>PHASE_CMP_STEP);
+         }
+       }
 
-     int a= phaseDiff[p  ];
-     if( (line & 1) ^ ( vScore>0 ) ) a= -a;
+       int newXTemp= cutPointX[line] - cutPointX[line-1] + cutP2X[lastCutP];
+       if(newXTemp <  0     ) newXTemp+= vcDiff;
+       if(newXTemp >= vcDiff) newXTemp-= vcDiff;
+       if(newXTemp >= vcDiff) newXTemp-= vcDiff;
 
-     const int phase1= a + phasePerCutP[ lastCutP ];
+       const int newCutPStart= max(x2CutP[ newXTemp ] - MAX_DRIFT, 0);
+       const int newCutPEnd=   min(x2CutP[ newXTemp ] + MAX_DRIFT, 256);
+
+       int drift= newCutPStart - (x2CutP[ newXTemp ] - MAX_DRIFT);
+
+       const byte a= (line & 1) ^ ( vScore>0 ) ? -ang: ang;
+
+       const byte phase1= a + phasePerCutP[ lastCutP ];
    
-     for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
-       int val= lastVal[lastCutP] - driftPenalty[drift];
-       int phase= phase1 + phasePerCutP[ newCutP ];
-       phase&= 0xFF;
-       phase= mabs( phase - 128 );
-       if(chromAmp[line]>3000 && phase>=PHASE_DIFF_TH) val-=100000;
-       if(chromAmp[line]<=3000) 
-         actVid2MemBufp->b[linep + ((vcStartX -  1)<<1) + 1]=255;
-     
-       if(newVal[newCutP] < val){
-         newVal[newCutP]= val;
-         dir[line*257 + newCutP]= lastCutP;
+       for(int newCutP= newCutPStart; newCutP <= newCutPEnd; newCutP++){
+         int val= lastVal[lastCutP] - driftPenalty[drift];
+         const byte phaseErr= phase1 + phasePerCutP[ newCutP ];
 
-         noLeft=false;
+         if(chromAmp>AMP_THRESHOLD && line>4)
+           val-=  phaseLut[ mabs( char(phaseErr - 128) ) ]
+                + phaseLut[ mabs( char(phaseErr - lastPhaseErr[lastCutP]) ) ];// useless without phase errors from decomb-filter
+         else actVid2MemBufp->b[linep + ((vcStartX -  1)<<1) + 1]=255;
+     
+         if(newVal[newCutP] < val){
+           newVal[newCutP]= val;
+           dir[line*257 + newCutP]= lastCutP;
+           newPhaseErr[newCutP]= phaseErr;
+        
+           noLeft=false;
+         }
+         drift++;
        }
-       drift++;
+
      }
+   }
 
+   if(iState){
+     T2=uclock();
+     tst2+=T2-T1;
+     T1=T2;
    }
 
-   for(int newCutP = 0; newCutP < 256; newCutP++){
-     if(black[line]) continue;
-     if(!noLeft && newVal[newCutP]==0) continue;
+   if(!black[line]){
+     for(int newCutP = 0; newCutP < 256; newCutP++){
+       if(!noLeft && newVal[newCutP]==0) continue;
 
-     const int newX= cutP2X[ newCutP ];
+       const byte * const p= &actVid2MemBufp->b[ linep + ((cutP2X[ newCutP ] + vcStartX)<<1) + 1 - 4 ];
 
-     const int diff=edgeLut[ mabs(
-      +actVid2MemBufp->b[linep + ((vcStartX + newX - 2)<<1) + 1]
-      +actVid2MemBufp->b[linep + ((vcStartX + newX - 1)<<1) + 1]
-      -actVid2MemBufp->b[linep + ((vcStartX + newX    )<<1) + 1]
-      -actVid2MemBufp->b[linep + ((vcStartX + newX + 1)<<1) + 1] ) ];
+       const int diff=edgeLut[ mabs( + int(* p   ) + int(*(p+2))
+                                     - int(*(p+4)) - int(*(p+6)) ) ];
+  
+       if(newVal[newCutP]==0) newVal[newCutP] =  diff + 1000000000;
+       else                   newVal[newCutP] += diff;
 
-     if(newVal[newCutP]==0) newVal[newCutP] =  diff + 1000000000;
-     else                   newVal[newCutP] += diff;
+       if(newVal[256] < newVal[newCutP]){
+         newVal[256]= newVal[newCutP];
+         dir[line*257 + 256]= max(1, newCutP);        // FIX (QUICKHACK)
+       }
 
-     if(newVal[256] < newVal[newCutP]){
-       newVal[256]= newVal[newCutP];
-       dir[line*257 + 256]= newCutP;
      }
-
    }
    
+   if(iState){
+     T2=uclock();
+     tst3+=T2-T1;
+     T1=T2;
+   }
 
    int *tempVal=lastVal;
    lastVal=newVal;
    newVal=tempVal;
 
+   byte *tempErr=lastPhaseErr;
+   lastPhaseErr=newPhaseErr;
+   newPhaseErr=tempErr;
+
    if(iState){
      T2=uclock();
      alg2+=T2-T1;
@@ -549,23 +575,18 @@ void vc_decrypt(void){
 
  }
 
+ delete [] convVec;
+
  delete [] newVal;
  delete [] lastVal;
 
-
- if(iState){
-   T2=uclock();
-   sprintf(textbuf[0],"%f Corr", (float)(alg1)/UCLOCKS_PER_SEC);
-   sprintf(textbuf[1],"%f Edge-Search", (float)(alg2)/UCLOCKS_PER_SEC);
-   sprintf(textbuf[2],"%f ReSample", (float)(alg3)/UCLOCKS_PER_SEC);
-   T1=T2;
- }
-
+ delete [] newPhaseErr;
+ delete [] lastPhaseErr;
  
  if(showPoints){
    int bestCutP=-1;
    for(int line=wndy-1; line>0; line--){
-     if(dir[line*257 + 256]==-1){
+     if(dir[line*257 + 256]==0){
        bestCutP=-1;
        continue;
      }
@@ -597,8 +618,10 @@ void vc_decrypt(void){
 
  int bestCutP=-1;
  linep=(wndy-1) * (vgax<<1);
+ llinep=wndy    * (vgax<<1);
  for(int line=wndy-2; line>0; line--){
    linep-= vgax<<1;
+   llinep-= vgax<<1;
 
    cutpp[line]=0;
 
@@ -611,7 +634,7 @@ void vc_decrypt(void){
      actVid2MemBufp->b[linep+(vcStartX<<1)+1]=255;
      actVid2MemBufp->b[linep+(vcStartX<<1)+3]=0;
    }
-   if(dir[line*257 + 256]==-1){
+   if(dir[line*257 + 256]==0){
      bestCutP=-1;
      continue;
    }
@@ -627,47 +650,66 @@ void vc_decrypt(void){
 
    int cutX= (showPoints ? cutPointX[line] : bestX );
 
-/*
-   const int cutP= min(x2CutP[cutX], 0);          // fix ? ness, max?
+   const int cutP= max(x2CutP[cutX], 0);          // fix ? ness, min?
+ 
+   const char s1= sin1PerCutP[ cutP ];
+   const char c1= cos1PerCutP[ cutP ];
+   const char s2= sin2PerCutP[ cutP ];
+   const char c2= cos2PerCutP[ cutP ];
 
-   const float s1= sin( -float(phasePerCutP[ cutP ] + some)/128*PI + PHASE_SEG );
-   const float c1= cos( -float(phasePerCutP[ cutP ] + some)/128*PI + PHASE_SEG );
-   const float s2= sin( -float(phasePerCutP[ cutP ] + some)/128*PI             );
-   const float c2= cos( -float(phasePerCutP[ cutP ] + some)/128*PI             );
+   if( (line & 1) ^ ( vScore>0 ) ){
+     char *p= (char*)( &actVid2MemBufp->b[ linep+((vcStartX & ~1)<<1) ] );
+     int x=0;
+     for(; x<cutX; x+=4){
+       const char u= * p;
+       const char v= *(p+2);
 
-   for(int x=0; x<vcDiff; x+=2){
-     const char u=char(actVid2MemBufp->b[linep+((vcStartX + x)<<1)  ]);
-     const char v=char(actVid2MemBufp->b[linep+((vcStartX + x)<<1)+2]);
-     char u1, v1;
+       const char u1=(char)(( - v*c1 - u*s1)>>7);
+       const char v1=(char)(( + v*s1 - u*c1)>>7);
 
-     float s, c;
-     if(x<cutP){
-       s= s1;
-       c= c1;
-     }
-     else{
-       s= s2;
-       c= c2;
+       if( (vcDiff - cutX) & 1 ){
+         * p   = v1;
+         *(p+2)= u1;
+         *(p+4)= v1;
+         *(p+6)= u1;
+       }
+       else{
+         * p   = u1;
+         *(p+2)= v1;
+         *(p+4)= u1;
+         *(p+6)= v1;
+       }
+       p+=8;
      }
 
+     for(; x<vcDiff; x+=4){
+       const char u= * p;
+       const char v= *(p+2);
 
-     if( (line & 1) ^ ( vScore>0 ) ){
-       v1=(char)( -u*c - v*s );
-       u1=(char)( -v*c + u*s );
-     }
-     else{
-       v1=(char)( -u*c + v*s );
-       u1=(char)( -v*c - u*s );
+       const char u1=(char)(( - v*c2 - u*s2)>>7);
+       const char v1=(char)(( + v*s2 - u*c2)>>7);
+       
+       if( cutX & 1 ){
+         * p   = v1;
+         *(p+2)= u1;
+         *(p+4)= v1;
+         *(p+6)= u1;
+       }
+       else{
+         * p   = u1;
+         *(p+2)= v1;
+         *(p+4)= u1;
+         *(p+6)= v1;
+       }
+       p+=8;
      }
+   }
 
-     printf("uv %d %d  %d %d \n", u,v,u1,v1);
-     actVid2MemBufp->b[linep+((vcStartX + x)<<1)  ]= u1;
-     actVid2MemBufp->b[linep+((vcStartX + x)<<1)+2]= v1;
 
-   }
 
-   cutX&= ~1;
-   */
+ 
+//   actVid2MemBufp->b[linep+((vcStartX)<<1)+1]= 255;
+   
    memcpy(copy_buff, actVid2MemBufp->b + linep + (vcStartX<<1), vcDiff<<1);
 
    memcpy(actVid2MemBufp->b + linep + (vcStartX<<1), copy_buff + (cutX<<1),
@@ -676,67 +718,30 @@ void vc_decrypt(void){
                                                                    copy_buff,
                                                          cutX<<1);
 
+   if( (line & 1) ^ ( vScore>0 ) ^ 1 ){
+     char *pl= (char*)( &actVid2MemBufp->b[llinep+ ((vcStartX<<1) & ~3) ] );
+     char *pn= (char*)( &actVid2MemBufp->b[ linep+ ((vcStartX<<1) & ~3) ] );
+     for(int x=0; x<vcDiff; x+=4){
+       * pn   = *(pn+4)= * pl;
+       *(pn+2)= *(pn+6)= *(pl+2);
+       pn+=8;
+       pl+=8;
+     }
+   }
+
    cutpp[line]=cutX;
 
 
    bestCutP= dir[line*257 + bestCutP];
  }
 
- for(int line=80; line<200; line++){
-     if( (line & 1) ^ ( vScore>0 ) ) printf(" e");
-     else                            printf(" o");
-
-     const int p= (cutpp[line-1]>>PHASE_CMP_STEP)
-                + (line*vcDiff>>PHASE_CMP_STEP) ;
-     int a= phaseDiff[p  ];
-
-     int relCutp= cutpp[line-1] + cutpp[line];
-     if(relCutp>=vcDiff) relCutp-=vcDiff;
-
-     printf("c%03d %03d %03d %03d\n", relCutp, a*180/128, x2CutP[cutpp[line-1]], x2CutP[cutpp[line]]);
-        //SIGSEGV
-
-     const int cut1= x2CutP[ cutpp[line-1] ];
-     const int cut2= x2CutP[ cutpp[line  ] ];
-
-     if(cut1<30 || cut1>220) continue;
-     if(cut2<30 || cut2>220) continue;
-
-     for(int offset=-20; offset<20; offset++){
-         int diff;
-         if( (line & 1) ^ ( vScore>0 ) ){
-           diff=  phasePerCutP[ cut1 + offset ]
-                + phasePerCutP[ cut2 + offset ]
-                - a;
-         }
-         else{
-           diff=  phasePerCutP[ cut1 + offset ]
-                + phasePerCutP[ cut2 + offset ]
-                + a;
-         }
-
-         diff&= 0xFF;
-
-         diff=mabs( diff-128 );
-         if(diff<PHASE_DIFF_TH && chromAmp[line]>3000) diff=1;
-         else if(chromAmp[line]>3000) diff=100000;
-         else diff=0;
-         score[offset+20]+=diff;
-     }
-
-//     int cutP2=cutpp[line] - cutpp[line-2];
-//     if(cutP2<0) cutP2+= vcDiff;
- }
-
- for(int i=0; i<40; i++)
-   printf("score %d   %d\n", score[i], i-20);
-
- double avgCutP=0;
+ float avgCutP=0;
  for(int line=50; line<200; line++){
-   avgCutP+=double(cutpp[line]);
+   avgCutP+=float(cutpp[line]);
  }
+
  avgCutP/=(200.0-50.0);
- printf("avg%f\n", avgCutP-double(vcDiff)/2.0);
+ printf("avg%f\n", avgCutP-float(vcDiff)/2.0);
   
   
  printf("vScore %d\n", vScore);
@@ -744,21 +749,29 @@ void vc_decrypt(void){
 
  if(iState){
    T2=uclock();
+   sprintf(textbuf[0],"%f Corr", (float)(alg1)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[1],"%f Edge-Search", (float)(alg2)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[2],"%f ReSample", (float)(alg3)/UCLOCKS_PER_SEC);
    sprintf(textbuf[4],"%f Rotate", (float)(T2-T1)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[5],"%f tst1", (float)(tst1)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[6],"%f tst2", (float)(tst2)/UCLOCKS_PER_SEC);
+   sprintf(textbuf[7],"%f tst3", (float)(tst3)/UCLOCKS_PER_SEC);
    c.init(255, 0, 0, yuvmode);
    gprint(80,  80,  c.col, textbuf[0]);
    gprint(90,  90,  c.col, textbuf[1]);
    gprint(100, 100, c.col, textbuf[2]);
    gprint(110, 110, c.col, textbuf[3]);
    gprint(120, 120, c.col, textbuf[4]);
-   T1=T2;
+   gprint(130, 130, c.col, textbuf[5]);
+   gprint(140, 140, c.col, textbuf[6]);
+   gprint(150, 150, c.col, textbuf[7]);
+   T1=T2;                           
  }
 
 
   delete [] dir;
   delete [] black;
-  delete [] phaseDiff;
-  delete [] chromAmp;
+//  delete [] phaseDiff;
 }
 
 



More information about the Mndiff-dev mailing list