Recon.cpp
上传用户:szklck
上传日期:2007-01-22
资源大小:925k
文件大小:19k
源码类别:

图形图像处理

开发平台:

Visual C++

  1. // Recon.cpp: implementation of the CRecon class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "视频编解码器.h"
  6. #include "Recon.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. #define sign(a)         ((a) < 0 ? -1 : 1)
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. extern  int MV[2][5][MBR_MAX+1][MBC_MAX+2];
  17. extern int mv_outside_frame,adv_pred_mode,pb_frame,trd,trb;
  18. extern int modemap[MBR_MAX+1][MBC_MAX+2];
  19. extern int mb_width,coded_picture_width;
  20. extern  unsigned char *edgeframe[3],*newframe[3], *bframe[3],*oldrefframe[3];
  21. CRecon::CRecon()
  22. {
  23. }
  24. CRecon::~CRecon()
  25. {
  26. }
  27. void CRecon::reconstruct(int bx, int by, int P, int bdx, int bdy)
  28. {
  29.   int w,h,lx,lx2,dx,dy,xp,yp,comp,sum;
  30.   int x,y,mode,xvec,yvec;
  31.   unsigned char *src[3];
  32.   x = bx/16+1; 
  33.   y = by/16+1;
  34.   lx = coded_picture_width;
  35.   if (mv_outside_frame) //
  36.   {
  37.     lx2 = coded_picture_width + 64;
  38.     src[0] = edgeframe[0];
  39.     src[1] = edgeframe[1];
  40.     src[2] = edgeframe[2];
  41.   }
  42.   else 
  43.   {
  44.     lx2 = coded_picture_width;
  45.     src[0] = oldrefframe[0];
  46.     src[1] = oldrefframe[1];
  47.     src[2] = oldrefframe[2];
  48.   }
  49.   mode = modemap[y][x];
  50.   if (P) // P 预测模式
  51.   {
  52.     /* P prediction */
  53.     if (adv_pred_mode) 
  54. {
  55.       w = 8; h = 8;
  56.       /* Y*/
  57.       for (comp = 0; comp < 4; comp++) 
  58.   {
  59.       xp = bx + ((comp&1)<<3);
  60.       yp = by + ((comp&2)<<2);
  61.       recon_comp_obmc(src[0],newframe[0], lx,lx2,comp,w,h,xp,yp);
  62.       }
  63.       if (mode == MODE_INTER4V)
  64.   {
  65.     sum = MV[0][1][y][x]+MV[0][2][y][x]+ MV[0][3][y][x]+MV[0][4][y][x];
  66.     dx = sign(sum)*(roundtab[abs(sum)%16] + (abs(sum)/16)*2);
  67.     sum = MV[1][1][y][x]+MV[1][2][y][x]+ MV[1][3][y][x]+MV[1][4][y][x];
  68.     dy = sign(sum)*(roundtab[abs(sum)%16] + (abs(sum)/16)*2);
  69.       }
  70.       else 
  71.   {
  72.     dx = MV[0][0][y][x];
  73.     dy = MV[1][0][y][x];
  74.     // chroma rounding 
  75.     dx = ( dx % 4 == 0 ? dx >> 1 : (dx>>1)|1 );
  76.     dy = ( dy % 4 == 0 ? dy >> 1 : (dy>>1)|1 );
  77.       }
  78.       lx>>=1;bx>>=1; 
  79.   lx2>>=1; by>>=1;
  80.       // Chroma 
  81.       recon_comp(src[1],newframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  82.       recon_comp(src[2],newframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  83.     }
  84.     else 
  85. { // normal prediction mode 
  86.       // P prediction 
  87.       w = 16; h = 16;
  88.       dx = MV[0][0][y][x];
  89.       dy = MV[1][0][y][x];
  90.       
  91.       // Y image
  92.       recon_comp(src[0],newframe[0], lx,lx2,w,h,bx,by,dx,dy,0);
  93.       //src[0]->newframe[0]  
  94.       lx>>=1; w>>=1; 
  95.   bx>>=1; lx2>>=1; 
  96.       h>>=1; by>>=1;  
  97.       // chroma rounding 
  98.       dx = ( dx % 4 == 0 ? dx >> 1 : (dx>>1)|1 );
  99.       dy = ( dy % 4 == 0 ? dy >> 1 : (dy>>1)|1 );
  100.       // Chroma image
  101.       recon_comp(src[1],newframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  102.       recon_comp(src[2],newframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  103.   //src[]->newframe[]
  104.     }
  105.   }//end of(P)
  106.   else 
  107.   {
  108.     // B forward prediction 
  109.     if (adv_pred_mode) 
  110. {
  111.       if (mode == MODE_INTER4V) 
  112.   {
  113.      w = 8; h = 8;
  114.      // Y Image
  115.      xvec = yvec = 0;
  116.      for (comp = 0; comp < 4; comp++) 
  117.  {
  118.         xvec += dx = (trb)*MV[0][comp+1][y][x]/trd + bdx;
  119.         yvec += dy = (trb)*MV[1][comp+1][y][x]/trd + bdy;
  120.         xp = bx + ((comp&1)<<3);
  121.         yp = by + ((comp&2)<<2);
  122.         recon_comp(src[0],bframe[0], lx,lx2,w,h,xp,yp,dx,dy,0);
  123.  } 
  124.      // chroma rounding (table 16/H.263) 
  125.      dx = sign(xvec)*(roundtab[abs(xvec)%16] + (abs(xvec)/16)*2);
  126.      dy = sign(yvec)*(roundtab[abs(yvec)%16] + (abs(yvec)/16)*2);
  127.      lx>>=1; bx>>=1; 
  128.  lx2>>=1;by>>=1;
  129.      // Chroma  U V image 
  130.      recon_comp(src[1],bframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  131.      recon_comp(src[2],bframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  132.       } 
  133.       else
  134.   {  // adv_pred_mode but 16x16 vector 
  135.      w = 16; h = 16;
  136.      dx = (trb)*MV[0][0][y][x]/trd + bdx;
  137.      dy = (trb)*MV[1][0][y][x]/trd + bdy;
  138.      // Y image
  139.      recon_comp(src[0],bframe[0], lx,lx2,w,h,bx,by,dx,dy,0);
  140.      lx>>=1; w>>=1; bx>>=1; lx2>>=1;
  141.      h>>=1; by>>=1;  
  142.      xvec = 4*dx;
  143.      yvec = 4*dy;
  144.      // chroma rounding (table 16/H.263) 
  145.      dx = sign(xvec)*(roundtab[abs(xvec)%16] + (abs(xvec)/16)*2);
  146.      dy = sign(yvec)*(roundtab[abs(yvec)%16] + (abs(yvec)/16)*2);
  147.      // Chroma  U V image
  148.      recon_comp(src[1],bframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  149.      recon_comp(src[2],bframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  150.       }
  151.     }//end of(adv_pred_mode)
  152.     else 
  153. { // normal B forward prediction 
  154.       w = 16; h = 16;
  155.       dx = (trb)*MV[0][0][y][x]/trd + bdx;
  156.       dy = (trb)*MV[1][0][y][x]/trd + bdy;
  157.       /* Y */
  158.       recon_comp(src[0],bframe[0], lx,lx2,w,h,bx,by,dx,dy,0);
  159.       lx>>=1; w>>=1; bx>>=1; lx2>>=1;
  160.       h>>=1; by>>=1;  
  161.       xvec = 4*dx;
  162.       yvec = 4*dy;
  163.       // chroma rounding (table 16/H.263)
  164.       dx = sign(xvec)*(roundtab[abs(xvec)%16] + (abs(xvec)/16)*2);
  165.       dy = sign(yvec)*(roundtab[abs(yvec)%16] + (abs(yvec)/16)*2);
  166.       // Chroma U V image
  167.       recon_comp(src[1],bframe[1], lx,lx2,w,h,bx,by,dx,dy,1);
  168.       recon_comp(src[2],bframe[2], lx,lx2,w,h,bx,by,dx,dy,2);
  169.     }
  170.   }
  171. }
  172. void CRecon::recon_comp(unsigned char *src, unsigned char *dst, 
  173.     int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int flag)
  174. {
  175.  int xint, xh, yint, yh;
  176.   unsigned char *s, *d;
  177.   xint = dx>>1;
  178.   xh = dx & 1;
  179.   yint = dy>>1;
  180.   yh = dy & 1;
  181.   /* origins */
  182.   s = src + lx2*(y+yint) + x + xint;
  183.   d = dst + lx*y + x;
  184.   if (!xh && !yh)
  185.     if (w!=8)
  186.       rec(s,d,lx,lx2,h);
  187.     else
  188.       recc(s,d,lx,lx2,h);
  189.   else if (!xh && yh)
  190.     if (w!=8)
  191.       recv(s,d,lx,lx2,h);
  192.     else 
  193.       recvc(s,d,lx,lx2,h);
  194.   else if (xh && !yh)
  195.     if (w!=8)
  196.       rech(s,d,lx,lx2,h);
  197.     else
  198.       rechc(s,d,lx,lx2,h);
  199.   else /* if (xh && yh) */
  200.     if (w!=8)
  201.       rec4(s,d,lx,lx2,h);
  202.     else
  203.       rec4c(s,d,lx,lx2,h);
  204. }
  205. void CRecon::recon_comp_obmc(unsigned char *src, unsigned char *dst, int lx, int lx2, int comp, int w, int h, int x, int y)
  206. {
  207. int j,k;
  208.   int xmb,ymb;
  209.   int c8,t8,l8,r8;
  210.   int xit,xib,xir,xil;
  211.   int yit,yib,yir,yil;
  212.   int vect,vecb,vecr,vecl;
  213.   int nx[5],ny[5],xint[5],yint[5],xh[5],yh[5];
  214.   int p[64],*pd;
  215.   unsigned char *d,*s[5];
  216.   xmb = (x>>4)+1;
  217.   ymb = (y>>4)+1;
  218.   c8 = (modemap[ymb][xmb] == MODE_INTER4V ? 1 : 0);
  219.   t8 = (modemap[ymb-1][xmb] == MODE_INTER4V ? 1 : 0);
  220.   l8 = (modemap[ymb][xmb-1] == MODE_INTER4V ? 1 : 0);
  221.   r8 = (modemap[ymb][xmb+1] == MODE_INTER4V ? 1 : 0);
  222.   switch (comp+1) {
  223.   case 1:
  224.     vect = (t8 ? 3 : 0) ; yit = ymb-1 ; xit = xmb;
  225.     vecb = (c8 ? 3 : 0) ; yib = ymb   ; xib = xmb;
  226.     vecl = (l8 ? 2 : 0) ; yil = ymb   ; xil = xmb-1;
  227.     vecr = (c8 ? 2 : 0) ; yir = ymb   ; xir = xmb;
  228.     if (ymb == 1) {
  229.       yit = ymb;
  230.       vect = (c8 ? 1 : 0);
  231.     }
  232.     if (xmb == 1) {
  233.       xil = xmb;
  234.       vecl = (c8 ? 1 : 0);
  235.     }
  236.     break;
  237.   case 2:
  238.     vect = (t8 ? 4 : 0) ; yit = ymb-1 ; xit = xmb;
  239.     vecb = (c8 ? 4 : 0) ; yib = ymb   ; xib = xmb;
  240.     vecl = (c8 ? 1 : 0) ; yil = ymb   ; xil = xmb;
  241.     vecr = (r8 ? 1 : 0) ; yir = ymb   ; xir = xmb+1;
  242.     if (ymb == 1) {
  243.       yit = ymb;
  244.       vect = (c8 ? 2 : 0);
  245.     }
  246.     if (xmb == mb_width) {
  247.       xir = xmb;
  248.       vecr = (c8 ? 2 : 0);
  249.     }
  250.     break;
  251.   case 3:
  252.     vect = (c8 ? 1 : 0) ; yit = ymb  ; xit = xmb;
  253.     vecb = (c8 ? 3 : 0) ; yib = ymb  ; xib = xmb;
  254.     vecl = (l8 ? 4 : 0) ; yil = ymb  ; xil = xmb-1;
  255.     vecr = (c8 ? 4 : 0) ; yir = ymb  ; xir = xmb;
  256.     if (xmb == 1) {
  257.       xil = xmb;
  258.       vecl = (c8 ? 3 : 0);
  259.     }
  260.     break;
  261.   case 4:
  262.     vect = (c8 ? 2 : 0) ; yit = ymb  ; xit = xmb;
  263.     vecb = (c8 ? 4 : 0) ; yib = ymb  ; xib = xmb;
  264.     vecl = (c8 ? 3 : 0) ; yil = ymb  ; xil = xmb;
  265.     vecr = (r8 ? 3 : 0) ; yir = ymb  ; xir = xmb+1;
  266.     if (xmb == mb_width) {
  267.       xir = xmb;
  268.       vecr = (c8 ? 4 : 0);
  269.     }
  270.     break;
  271.   default:
  272.     fprintf(stderr,"Illegal block number in recon_comp_obmc (recon.c)n");
  273.     exit(1);
  274.     break;
  275.   }
  276.   nx[0] = MV[0][c8 ? comp + 1 : 0][ymb][xmb];
  277.   ny[0] = MV[1][c8 ? comp + 1 : 0][ymb][xmb];
  278.   
  279.   nx[1] = MV[0][vect][yit][xit]; ny[1] = MV[1][vect][yit][xit];
  280.   nx[2] = MV[0][vecb][yib][xib]; ny[2] = MV[1][vecb][yib][xib];
  281.   nx[3] = MV[0][vecr][yir][xir]; ny[3] = MV[1][vecr][yir][xir];
  282.   nx[4] = MV[0][vecl][yil][xil]; ny[4] = MV[1][vecl][yil][xil];
  283.   for (k = 0; k < 5; k++) {
  284.     xint[k] = nx[k]>>1;
  285.     xh[k] = nx[k] & 1;
  286.     yint[k] = ny[k]>>1;
  287.     yh[k] = ny[k] & 1;
  288.     s[k] = src + lx2*(y+yint[k]) + x + xint[k];
  289.   }
  290.   
  291.   d = dst + lx*y + x;
  292.   if (!xh[0] && !yh[0])
  293.     reco(s[0],&p[0],8,lx2,0,0,0,8,0,8);
  294.   else if (!xh[0] && yh[0])
  295.     recvo(s[0],&p[0],8,lx2,0,0,0,8,0,8);
  296.   else if (xh[0] && !yh[0])
  297.     recho(s[0],&p[0],8,lx2,0,0,0,8,0,8);
  298.   else /* if (xh[] && yh[]) */
  299.     rec4o(s[0],&p[0],8,lx2,0,0,0,8,0,8);
  300.   if (!xh[1] && !yh[1])
  301.     reco(s[1],&p[0],8,lx2,1,1,0,8,0,4);
  302.   else if (!xh[1] && yh[1])
  303.     recvo(s[1],&p[0],8,lx2,1,1,0,8,0,4);
  304.   else if (xh[1] && !yh[1])
  305.     recho(s[1],&p[0],8,lx2,1,1,0,8,0,4);
  306.   else /* if (xh[] && yh[]) */
  307.     rec4o(s[1],&p[0],8,lx2,1,1,0,8,0,4);
  308.   if (!xh[2] && !yh[2])
  309.     reco(s[2]+(lx2<<2),&p[32],8,lx2,1,2,0,8,4,8);
  310.   else if (!xh[2] && yh[2])
  311.     recvo(s[2]+(lx2<<2),&p[32],8,lx2,1,2,0,8,4,8);
  312.   else if (xh[2] && !yh[2])
  313.     recho(s[2]+(lx2<<2),&p[32],8,lx2,1,2,0,8,4,8);
  314.   else /* if (xh[] && yh[]) */
  315.     rec4o(s[2]+(lx2<<2),&p[32],8,lx2,1,2,0,8,4,8);
  316.   if (!xh[3] && !yh[3])
  317.     reco(s[3],&p[0],8,lx2,1,3,4,8,0,8);
  318.   else if (!xh[3] && yh[3])
  319.     recvo(s[3],&p[0],8,lx2,1,3,4,8,0,8);
  320.   else if (xh[3] && !yh[3])
  321.     recho(s[3],&p[0],8,lx2,1,3,4,8,0,8);
  322.   else /* if (xh[] && yh[]) */
  323.     rec4o(s[3],&p[0],8,lx2,1,3,4,8,0,8);
  324.   if (!xh[4] && !yh[4])
  325.     reco(s[4],&p[0],8,lx2,1,4,0,4,0,8);
  326.   else if (!xh[4] && yh[4])
  327.     recvo(s[4],&p[0],8,lx2,1,4,0,4,0,8);
  328.   else if (xh[4] && !yh[4])
  329.     recho(s[4],&p[0],8,lx2,1,4,0,4,0,8);
  330.   else /* if (xh[] && yh[]) */
  331.     rec4o(s[4],&p[0],8,lx2,1,4,0,4,0,8);
  332.   pd = &p[0];
  333.   for (j = 0; j < 8; j++) {
  334.     d[0] = (pd[0] + 4 )>>3;
  335.     d[1] = (pd[1] + 4 )>>3;
  336.     d[2] = (pd[2] + 4 )>>3;
  337.     d[3] = (pd[3] + 4 )>>3;
  338.     d[4] = (pd[4] + 4 )>>3;
  339.     d[5] = (pd[5] + 4 )>>3;
  340.     d[6] = (pd[6] + 4 )>>3;
  341.     d[7] = (pd[7] + 4 )>>3;
  342.     d += lx;
  343.     pd += 8;
  344.   }
  345. }
  346. void CRecon::rec(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  347. {
  348.  int j;
  349.   for (j=0; j<h; j++)
  350.   {
  351.     d[0] = s[0];
  352.     d[1] = s[1];
  353.     d[2] = s[2];
  354.     d[3] = s[3];
  355.     d[4] = s[4];
  356.     d[5] = s[5];
  357.     d[6] = s[6];
  358.     d[7] = s[7];
  359.     d[8] = s[8];
  360.     d[9] = s[9];
  361.     d[10] = s[10];
  362.     d[11] = s[11];
  363.     d[12] = s[12];
  364.     d[13] = s[13];
  365.     d[14] = s[14];
  366.     d[15] = s[15];
  367.     s+= lx2;
  368.     d+= lx;
  369.   }
  370. }
  371. void CRecon::recc(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  372. {
  373.  int j;
  374.   for (j=0; j<h; j++)
  375.   {
  376.     d[0] = s[0];
  377.     d[1] = s[1];
  378.     d[2] = s[2];
  379.     d[3] = s[3];
  380.     d[4] = s[4];
  381.     d[5] = s[5];
  382.     d[6] = s[6];
  383.     d[7] = s[7];
  384.     s+= lx2;
  385.     d+= lx;
  386.   }
  387. }
  388. void CRecon::reco(unsigned char *s, int *d, int lx, int lx2, int addflag, int c, int xa, int xb, int ya, int yb)
  389. {
  390.   int i,j;
  391.   int *om;
  392.   om = &OM[c][ya][0];
  393.   if (!addflag) {
  394.     for (j = ya; j < yb; j++) {
  395.       for (i = xa; i < xb; i++) {
  396. d[i] = s[i] * om[i];
  397.       }
  398.       s+= lx2;
  399.       d+= lx;
  400.       om+= 8;
  401.     }
  402.   }
  403.   else {
  404.     for (j = ya; j < yb; j++) {
  405.       for (i = xa; i < xb; i++) {
  406. d[i] += s[i] * om[i];
  407.       }
  408.       s+= lx2;
  409.       d+= lx;
  410.       om+= 8;
  411.     }
  412.   }
  413. }
  414. void CRecon::rech(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  415. {
  416.   unsigned char *dp,*sp;
  417.   int j;
  418.   unsigned int s1,s2;
  419.   sp = s;
  420.   dp = d;
  421.   for (j=0; j<h; j++)
  422.   {
  423.     s1=sp[0];
  424.     dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
  425.     dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
  426.     dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
  427.     dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
  428.     dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
  429.     dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
  430.     dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
  431.     dp[7] = (unsigned int)(s2+(s1=sp[8])+1)>>1;
  432.     dp[8] = (unsigned int)(s1+(s2=sp[9])+1)>>1;
  433.     dp[9] = (unsigned int)(s2+(s1=sp[10])+1)>>1;
  434.     dp[10] = (unsigned int)(s1+(s2=sp[11])+1)>>1;
  435.     dp[11] = (unsigned int)(s2+(s1=sp[12])+1)>>1;
  436.     dp[12] = (unsigned int)(s1+(s2=sp[13])+1)>>1;
  437.     dp[13] = (unsigned int)(s2+(s1=sp[14])+1)>>1;
  438.     dp[14] = (unsigned int)(s1+(s2=sp[15])+1)>>1;
  439.     dp[15] = (unsigned int)(s2+sp[16]+1)>>1;
  440.     sp+= lx2;
  441.     dp+= lx;
  442.   }
  443. }
  444. void CRecon::rechc(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  445. {
  446.   unsigned char *dp,*sp;
  447.   int j;
  448.   unsigned int s1,s2;
  449.   sp = s;
  450.   dp = d;
  451.   for (j=0; j<h; j++)
  452.   {
  453.     s1=sp[0];
  454.     dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
  455.     dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
  456.     dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
  457.     dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
  458.     dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
  459.     dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
  460.     dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
  461.     dp[7] = (unsigned int)(s2+sp[8]+1)>>1;
  462.     sp+= lx2;
  463.     dp+= lx;
  464.   }
  465. }
  466. void CRecon::recho(unsigned char *s, int *d, int lx, int lx2, int addflag, int c, int xa, int xb, int ya, int yb)
  467. {
  468.  int *dp,*om;
  469.   unsigned char *sp;
  470.   int i,j;
  471.   sp = s;
  472.   dp = d;
  473.   om = &OM[c][ya][0];
  474.   if (!addflag) {
  475.     for (j = ya; j < yb; j++) {
  476.       for (i = xa; i < xb; i++) {
  477. dp[i] = (((unsigned int)(sp[i] + sp[i+1]+1))>>1)*om[i];
  478.       }
  479.       sp+= lx2;
  480.       dp+= lx;
  481.       om+= 8;
  482.     }
  483.   }
  484.   else {
  485.     for (j = ya; j < yb; j++) {
  486.       for (i = xa; i < xb; i++) {
  487. dp[i] += (((unsigned int)(sp[i] + sp[i+1]+1))>>1)*OM[c][j][i];
  488.       }
  489.       sp+= lx2;
  490.       dp+= lx;
  491.       om+= 8;
  492.     }
  493.   }
  494. }
  495. void CRecon::recv(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  496. {
  497.   unsigned char *dp,*sp,*sp2;
  498.   int j;
  499.   sp = s;
  500.   sp2 = s+lx2;
  501.   dp = d;
  502.   for (j=0; j<h; j++)
  503.   {
  504.     dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
  505.     dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
  506.     dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
  507.     dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
  508.     dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
  509.     dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
  510.     dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
  511.     dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
  512.     dp[8] = (unsigned int)(sp[8]+sp2[8]+1)>>1;
  513.     dp[9] = (unsigned int)(sp[9]+sp2[9]+1)>>1;
  514.     dp[10] = (unsigned int)(sp[10]+sp2[10]+1)>>1;
  515.     dp[11] = (unsigned int)(sp[11]+sp2[11]+1)>>1;
  516.     dp[12] = (unsigned int)(sp[12]+sp2[12]+1)>>1;
  517.     dp[13] = (unsigned int)(sp[13]+sp2[13]+1)>>1;
  518.     dp[14] = (unsigned int)(sp[14]+sp2[14]+1)>>1;
  519.     dp[15] = (unsigned int)(sp[15]+sp2[15]+1)>>1;
  520.     sp+= lx2;
  521.     sp2+= lx2;
  522.     dp+= lx;
  523.   }
  524. }
  525. void CRecon::recvc(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  526. {
  527.  unsigned char *dp,*sp,*sp2;
  528.   int j;
  529.   sp = s;
  530.   sp2 = s+lx2;
  531.   dp = d;
  532.   for (j=0; j<h; j++)
  533.   {
  534.     dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
  535.     dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
  536.     dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
  537.     dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
  538.     dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
  539.     dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
  540.     dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
  541.     dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
  542.     sp+= lx2;
  543.     sp2+= lx2;
  544.     dp+= lx;
  545.   }
  546. }
  547. void CRecon::recvo(unsigned char *s, int *d, int lx, int lx2, int addflag, int c, int xa, int xb, int ya, int yb)
  548. {
  549.  int *dp,*om;
  550.   unsigned char *sp,*sp2;
  551.   int i,j;
  552.   sp = s;
  553.   sp2 = s+lx2;
  554.   dp = d;
  555.   om = &OM[c][ya][0];
  556.   if (!addflag) {
  557.     for (j = ya; j < yb; j++) {
  558.       for (i = xa; i < xb; i++) {
  559. dp[i] = (((unsigned int)(sp[i] + sp2[i]+1))>>1)*om[i];
  560.       }
  561.       sp+= lx2;
  562.       sp2+= lx2;
  563.       dp+= lx;
  564.       om+= 8;
  565.     }
  566.   }
  567.   else {
  568.     for (j = ya; j < yb; j++) {
  569.       for (i = xa; i < xb; i++) {
  570. dp[i] += (((unsigned int)(sp[i] + sp2[i]+1))>>1)*om[i];
  571.       }
  572.       sp+= lx2;
  573.       sp2+= lx2;
  574.       dp+= lx;
  575.       om+= 8;
  576.     }
  577.   }
  578. }
  579. void CRecon::rec4(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  580. {
  581.   unsigned char *dp,*sp,*sp2;
  582.   int j;
  583.   unsigned int s1,s2,s3,s4;
  584.   sp = s;
  585.   sp2 = s+lx2;
  586.   dp = d;
  587.   for (j=0; j<h; j++)
  588.   {
  589.     s1=sp[0]; s3=sp2[0];
  590.     dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
  591.     dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
  592.     dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
  593.     dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
  594.     dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
  595.     dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
  596.     dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
  597.     dp[7] = (unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2;
  598.     dp[8] = (unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2;
  599.     dp[9] = (unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2;
  600.     dp[10] = (unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2;
  601.     dp[11] = (unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2;
  602.     dp[12] = (unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2;
  603.     dp[13] = (unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2;
  604.     dp[14] = (unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2;
  605.     dp[15] = (unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2;
  606.     sp+= lx2;
  607.     sp2+= lx2;
  608.     dp+= lx;
  609.   }
  610. }
  611. void CRecon::rec4c(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
  612. {
  613.  unsigned char *dp,*sp,*sp2;
  614.   int j;
  615.   unsigned int s1,s2,s3,s4;
  616.   sp = s;
  617.   sp2 = s+lx2;
  618.   dp = d;
  619.   for (j=0; j<h; j++)
  620.   {
  621.     s1=sp[0]; s3=sp2[0];
  622.     dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
  623.     dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
  624.     dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
  625.     dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
  626.     dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
  627.     dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
  628.     dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
  629.     dp[7] = (unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2;
  630.     sp+= lx2;
  631.     sp2+= lx2;
  632.     dp+= lx;
  633.   }
  634. }
  635. void CRecon::rec4o(unsigned char *s, int *d, int lx, int lx2, int addflag, int c, int xa, int xb, int ya, int yb)
  636. {
  637.   int *dp,*om;
  638.   unsigned char *sp,*sp2;
  639.   int i,j;
  640.   sp = s;
  641.   sp2 = s+lx2;
  642.   dp = d;
  643.   om = &OM[c][ya][0];
  644.   if (!addflag) {
  645.     for (j = ya; j < yb; j++) {
  646.       for (i = xa; i < xb; i++) {
  647. dp[i] = (((unsigned int)(sp[i]+sp2[i]+sp[i+1]+sp2[i+1]+2))>>2)*om[i];
  648.       }
  649.       sp+= lx2;
  650.       sp2+= lx2;
  651.       dp+= lx;
  652.       om+= 8;
  653.     }
  654.   }
  655.   else {
  656.     for (j = ya; j < yb; j++) {
  657.       for (i = xa; i < xb; i++) {
  658. dp[i] += (((unsigned int)(sp[i]+sp2[i]+sp[i+1]+sp2[i+1]+2))>>2)*om[i];
  659.       }
  660.       sp+= lx2;
  661.       sp2+= lx2;
  662.       dp+= lx;
  663.       om += 8;
  664.     }
  665.   }
  666. }