[svn] / trunk / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/encoder.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1406, Sun Apr 4 11:47:21 2004 UTC revision 1617, Mon May 23 09:29:43 2005 UTC
# Line 21  Line 21 
21   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23   *   *
24   * $Id: encoder.c,v 1.105 2004-04-04 11:47:21 syskin Exp $   * $Id: encoder.c,v 1.118 2005-05-23 09:29:43 Skal Exp $
25   *   *
26   ****************************************************************************/   ****************************************************************************/
27    
# Line 85  Line 85 
85  /*  /*
86   * Simplify the "fincr/fbase" fraction   * Simplify the "fincr/fbase" fraction
87  */  */
88    static int
89    gcd(int a, int b)
90    {
91            int r ;
92    
93            if (b > a) {
94                    r = a;
95                    a = b;
96                    b = r;
97            }
98    
99            while ((r = a % b)) {
100                    a = b;
101                    b = r;
102            }
103            return b;
104    }
105    
106  static void  static void
107  simplify_time(int *inc, int *base)  simplify_time(int *inc, int *base)
108  {  {
109          /* common factor */          /* common factor */
110          int i = *inc;          const int s = gcd(*inc, *base);
111          while (i > 1) {    *inc  /= s;
112                  if (*inc % i == 0 && *base % i == 0) {    *base /= s;
113                          *inc /= i;  
114                          *base /= i;          if (*base > 65535 || *inc > 65535) {
115                          i = *inc;                  int *biggest;
116                          continue;                  int *other;
117                  }                  float div;
118                  i--;  
119                    if (*base > *inc) {
120                            biggest = base;
121                            other = inc;
122                    } else {
123                            biggest = inc;
124                            other = base;
125          }          }
126    
127          /* if neccessary, round to 65535 accuracy */                  div = ((float)*biggest)/((float)65535);
128          if (*base > 65535) {                  *biggest = (unsigned int)(((float)*biggest)/div);
129                  float div = (float) *base / 65535;                  *other = (unsigned int)(((float)*other)/div);
                 *base = (int) (*base / div);  
                 *inc = (int) (*inc / div);  
130          }          }
131  }  }
132    
# Line 135  Line 157 
157    
158          /* global flags */          /* global flags */
159          pEnc->mbParam.global_flags = create->global;          pEnc->mbParam.global_flags = create->global;
160      if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED))
161        pEnc->mbParam.global_flags |= XVID_GLOBAL_DIVX5_USERDATA;
162    
163          /* width, height */          /* width, height */
164          pEnc->mbParam.width = create->width;          pEnc->mbParam.width = create->width;
# Line 148  Line 172 
172          pEnc->mbParam.fincr = MAX(create->fincr, 0);          pEnc->mbParam.fincr = MAX(create->fincr, 0);
173          pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase;          pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase;
174          if (pEnc->mbParam.fincr>0)          if (pEnc->mbParam.fincr>0)
175                  simplify_time(&pEnc->mbParam.fincr, &pEnc->mbParam.fbase);                  simplify_time((int*)&pEnc->mbParam.fincr, (int*)&pEnc->mbParam.fbase);
176    
177          /* zones */          /* zones */
178          if(create->num_zones > 0) {          if(create->num_zones > 0) {
# Line 861  Line 885 
885  #endif  #endif
886  }  }
887    
 static int  
 gcd(int a, int b)  
 {  
         int r ;  
   
         if (b > a) {  
                 r = a;  
                 a = b;  
                 b = r;  
         }  
   
         while ((r = a % b)) {  
                 a = b;  
                 b = r;  
         }  
         return b;  
 }  
   
888  static void  static void
889  simplify_par(int *par_width, int *par_height)  simplify_par(int *par_width, int *par_height)
890  {  {
# Line 1142  Line 1148 
1148          type = frame->type;          type = frame->type;
1149          pEnc->current->quant = frame->quant;          pEnc->current->quant = frame->quant;
1150    
1151          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, &pEnc->current->quant, stats);          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, (int*)&pEnc->current->quant, stats);
1152    
1153          if (type > 0){  /* XVID_TYPE_?VOP */          if (type > 0){  /* XVID_TYPE_?VOP */
1154                  type = type2coding(type);       /* convert XVID_TYPE_?VOP to bitstream coding type */                  type = type2coding(type);       /* convert XVID_TYPE_?VOP to bitstream coding type */
# Line 1245  Line 1251 
1251                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);                  SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]);
1252    
1253                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {                  if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) {
1254                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP");                          image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "CLOSED GOP BVOP->PVOP");
1255                  }                  }
1256    
1257                  /* convert B-VOP quant to P-VOP */                  /* convert B-VOP quant to P-VOP */
# Line 1306  Line 1312 
1312    
1313                  /* prevent vol/vop misuse */                  /* prevent vol/vop misuse */
1314    
                 if (!(pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE))  
                         pEnc->current->vop_flags &= ~XVID_VOP_REDUCED;  
   
1315                  if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING))                  if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING))
1316                          pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN);                          pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN);
1317    
# Line 1436  Line 1439 
1439    
1440          uint16_t x, y;          uint16_t x, y;
1441    
         if ((pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE))  
         {  
                 mb_width = (pEnc->mbParam.width + 31) / 32;  
                 mb_height = (pEnc->mbParam.height + 31) / 32;  
   
                 /* 16x16->8x8 downsample requires 1 additional edge pixel*/  
                 /* XXX: setedges is overkill */  
                 start_timer();  
                 image_setedges(&pEnc->current->image,  
                         pEnc->mbParam.edged_width, pEnc->mbParam.edged_height,  
                         pEnc->mbParam.width, pEnc->mbParam.height, 0);  
                 stop_edges_timer();  
         }  
   
1442          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
1443          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;          pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type;
1444          pEnc->current->coding_type = I_VOP;          pEnc->current->coding_type = I_VOP;
# Line 1485  Line 1474 
1474                          stop_prediction_timer();                          stop_prediction_timer();
1475    
1476                          start_timer();                          start_timer();
                         if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE)  
                         {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */  
                                 qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */  
                                 qcoeff[5*64+0]=0;  
                         }  
1477                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat);
1478                          stop_coding_timer();                          stop_coding_timer();
1479                  }                  }
1480    
         if ((pEnc->current->vop_flags & XVID_VOP_REDUCED))  
         {  
                 image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width,  
                         pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width,  
                         16, 0);  
         }  
1481          emms();          emms();
1482    
1483          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
# Line 1515  Line 1493 
1493          return 1;                                       /* intra */          return 1;                                       /* intra */
1494  }  }
1495    
1496    static __inline void
1497    updateFcode(Statistics * sStat, Encoder * pEnc)
1498    {
1499            float fSigma;
1500            int iSearchRange;
1501    
1502  #define INTRA_THRESHOLD 0.5          if (sStat->iMvCount == 0)
1503  #define BFRAME_SKIP_THRESHHOLD 30                  sStat->iMvCount = 1;
1504    
1505            fSigma = (float) sqrt((float) sStat->iMvSum / sStat->iMvCount);
1506    
1507            iSearchRange = 16 << pEnc->mbParam.m_fcode;
1508    
1509            if ((3.0 * fSigma > iSearchRange) && (pEnc->mbParam.m_fcode <= 5) )
1510                    pEnc->mbParam.m_fcode++;
1511    
1512            else if ((5.0 * fSigma < iSearchRange)
1513                               && (4.0 * pEnc->fMvPrevSigma < iSearchRange)
1514                               && (pEnc->mbParam.m_fcode >= 2) )
1515                    pEnc->mbParam.m_fcode--;
1516    
1517            pEnc->fMvPrevSigma = fSigma;
1518    }
1519    
1520    #define BFRAME_SKIP_THRESHHOLD 30
1521    
1522  /* FrameCodeP also handles S(GMC)-VOPs */  /* FrameCodeP also handles S(GMC)-VOPs */
1523  static int  static int
1524  FrameCodeP(Encoder * pEnc,  FrameCodeP(Encoder * pEnc,
1525                     Bitstream * bs)                     Bitstream * bs)
1526  {  {
         float fSigma;  
1527          int bits = BitstreamPos(bs);          int bits = BitstreamPos(bs);
1528    
1529          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE);
1530          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE);
1531    
1532          int x, y, k;          int x, y, k;
         int iSearchRange;  
         int skip_possible;  
1533          FRAMEINFO *const current = pEnc->current;          FRAMEINFO *const current = pEnc->current;
1534          FRAMEINFO *const reference = pEnc->reference;          FRAMEINFO *const reference = pEnc->reference;
1535          MBParam * const pParam = &pEnc->mbParam;          MBParam * const pParam = &pEnc->mbParam;
# Line 1541  Line 1537 
1537          int mb_height = pParam->mb_height;          int mb_height = pParam->mb_height;
1538          int coded = 1;          int coded = 1;
1539    
   
         /* IMAGE *pCurrent = &current->image; */  
1540          IMAGE *pRef = &reference->image;          IMAGE *pRef = &reference->image;
1541    
         if ((current->vop_flags & XVID_VOP_REDUCED))  
         {  
                 mb_width = (pParam->width + 31) / 32;  
                 mb_height = (pParam->height + 31) / 32;  
         }  
   
   
1542          if (!reference->is_edged) {          if (!reference->is_edged) {
1543                  start_timer();                  start_timer();
1544                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,
# Line 1577  Line 1564 
1564                  }                  }
1565          }          }
1566    
1567            current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =
1568                    current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;
1569    
1570          current->coding_type = P_VOP;          current->coding_type = P_VOP;
1571    
1572          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);          call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL);
# Line 1645  Line 1635 
1635    
1636          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);          BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant);
1637    
         current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount =  
                 current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0;  
   
   
1638          for (y = 0; y < mb_height; y++) {          for (y = 0; y < mb_height; y++) {
1639                  for (x = 0; x < mb_width; x++) {                  for (x = 0; x < mb_width; x++) {
1640                          MACROBLOCK *pMB =                          MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];
1641                                  &current->mbs[x + y * pParam->mb_width];                          int skip_possible;
   
                         int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q);  
1642    
1643                          if (bIntra) {                          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) {
1644                                  CodeIntraMB(pEnc, pMB);                                  CodeIntraMB(pEnc, pMB);
1645                                  MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y,                                  MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y,
1646                                                                    dct_codes, qcoeff);                                                                    dct_codes, qcoeff);
# Line 1667  Line 1651 
1651    
1652                                  current->sStat.kblks++;                                  current->sStat.kblks++;
1653    
                                 if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE)  
                                 {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */  
                                         qcoeff[4*64+0]=0;               /* zero, because for INTRA MBs DC value is saved */  
                                         qcoeff[5*64+0]=0;  
                                 }  
1654                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);
1655                                  stop_coding_timer();                                  stop_coding_timer();
1656                                  continue;                                  continue;
# Line 1686  Line 1665 
1665                                                                   pParam->height,                                                                   pParam->height,
1666                                                                   pParam->edged_width,                                                                   pParam->edged_width,
1667                                                                   (current->vol_flags & XVID_VOL_QUARTERPEL),                                                                   (current->vol_flags & XVID_VOL_QUARTERPEL),
                                                                  (current->vop_flags & XVID_VOP_REDUCED),  
1668                                                                   current->rounding_type);                                                                   current->rounding_type);
1669    
1670                          stop_comp_timer();                          stop_comp_timer();
1671    
1672                          pMB->field_pred = 0;                          pMB->field_pred = 0;
1673    
1674                          if (pMB->mode != MODE_NOT_CODED)                          if (pMB->cbp != 0) {
1675                          {       pMB->cbp =                                  pMB->cbp = MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y,
                                         MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y,  
1676                                                                            dct_codes, qcoeff);                                                                            dct_codes, qcoeff);
1677                          }                          }
1678    
# Line 1715  Line 1692 
1692    
1693                          /* Finished processing the MB, now check if to CODE or SKIP */                          /* Finished processing the MB, now check if to CODE or SKIP */
1694    
1695                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) &&                          skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER);
                                                         (pMB->dquant == 0);  
1696    
1697                          if (current->coding_type == S_VOP)                          if (current->coding_type == S_VOP)
1698                                  skip_possible &= (pMB->mcsel == 1);                                  skip_possible &= (pMB->mcsel == 1);
1699                          else if (current->coding_type == P_VOP) {                          else { /* PVOP */
1700                                  if ((pParam->vol_flags & XVID_VOL_QUARTERPEL))                                  const VECTOR * const mv = (pParam->vol_flags & XVID_VOL_QUARTERPEL) ?
1701                                          skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) );                                                                                  pMB->qmvs : pMB->mvs;
1702                                  else                                  skip_possible &= ((mv->x|mv->y) == 0);
                                         skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) );  
1703                          }                          }
1704    
1705                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {                          if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) {
   
1706  /* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */  /* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */
   
                                 if (current->coding_type == P_VOP)      /* special rule for P-VOP's SKIP */  
                                 {  
1707                                          int bSkip = 1;                                          int bSkip = 1;
1708    
1709                                          for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++)                                  if (current->coding_type == P_VOP) {    /* special rule for P-VOP's SKIP */
1710                                          {  
1711                                            for (k = pEnc->bframenum_head; k < pEnc->bframenum_tail; k++) {
1712                                                  int iSAD;                                                  int iSAD;
1713                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,                                                  iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x,
1714                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,                                                                          pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x,
1715                                                                  pParam->edged_width,BFRAME_SKIP_THRESHHOLD);                                                                                  pParam->edged_width, BFRAME_SKIP_THRESHHOLD * pMB->quant);
1716                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant)                                                  if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant) {
1717                                                  {       bSkip = 0;                                                          bSkip = 0; /* could not SKIP */
1718                                                          break;                                                          if (pParam->vol_flags & XVID_VOL_QUARTERPEL) {
                                                 }  
                                         }  
   
                                         if (!bSkip) {   /* no SKIP, but trivial block */  
                                                 if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
1719                                                          VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0);                                                          VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0);
1720                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1721                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1722                                                  }                                                          } else {
                                                 else {  
1723                                                          VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0);                                                          VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0);
1724                                                          pMB->pmvs[0].x = - predMV.x;                                                          pMB->pmvs[0].x = - predMV.x;
1725                                                          pMB->pmvs[0].y = - predMV.y;                                                          pMB->pmvs[0].y = - predMV.y;
1726                                                  }                                                  }
1727                                                  pMB->mode = MODE_INTER;                                                  pMB->mode = MODE_INTER;
1728                                                  pMB->cbp = 0;                                                  pMB->cbp = 0;
1729                                                  MBCoding(current, pMB, qcoeff, bs, &current->sStat);                                                          break;
1730                                                  stop_coding_timer();                                                  }
   
                                                 continue;       /* next MB */  
1731                                          }                                          }
1732                                  }                                  }
                                 /* do SKIP */  
1733    
1734                                    if (bSkip) {
1735                                            /* do SKIP */
1736                                  pMB->mode = MODE_NOT_CODED;                                  pMB->mode = MODE_NOT_CODED;
1737                                  MBSkip(bs);                                  MBSkip(bs);
1738                                  stop_coding_timer();                                  stop_coding_timer();
1739                                  continue;       /* next MB */                                  continue;       /* next MB */
1740                          }                          }
                         /* ordinary case: normal coded INTER/INTER4V block */  
   
                         if ((current->vop_flags & XVID_VOP_GREYSCALE))  
                         {       pMB->cbp &= 0x3C;               /* keep only bits 5-2 */  
                                 qcoeff[4*64+0]=0;               /* zero, because DC for INTRA MBs DC value is saved */  
                                 qcoeff[5*64+0]=0;  
                         }  
   
                         if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
                                 VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0);  
                                 pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x;  
                                 pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y);  
                         } else {  
                                 VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0);  
                                 pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x;  
                                 pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y);  
                         }  
   
   
                         if (pMB->mode == MODE_INTER4V)  
                         {       int k;  
                                 for (k=1;k<4;k++)  
                                 {  
                                         if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) {  
                                                 VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, k);  
                                                 pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x;  
                                                 pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y);  
                                         } else {  
                                                 VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, k);  
                                                 pMB->pmvs[k].x = pMB->mvs[k].x - predMV.x;  
                                                 pMB->pmvs[k].y = pMB->mvs[k].y - predMV.y;  
                                 DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y);  
                                         }  
   
                                 }  
1741                          }                          }
1742    
1743                            /* ordinary case: normal coded INTER/INTER4V block */
1744                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);                          MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat);
1745                          stop_coding_timer();                          stop_coding_timer();
   
1746                  }                  }
1747          }          }
1748    
         if ((current->vop_flags & XVID_VOP_REDUCED))  
         {  
                 image_deblock_rrv(&current->image, pParam->edged_width,  
                         current->mbs, mb_width, mb_height, pParam->mb_width,  
                         16, 0);  
         }  
   
1749          emms();          emms();
1750            updateFcode(&current->sStat, pEnc);
         if (current->sStat.iMvCount == 0)  
                 current->sStat.iMvCount = 1;  
   
         fSigma = (float) sqrt((float) current->sStat.iMvSum / current->sStat.iMvCount);  
   
         iSearchRange = 1 << (3 + pParam->m_fcode);  
   
         if ((fSigma > iSearchRange / 3)  
                 && (pParam->m_fcode <= (3 +  (pParam->vol_flags & XVID_VOL_QUARTERPEL?1:0)  ))) /* maximum search range 128 */  
         {  
                 pParam->m_fcode++;  
                 iSearchRange *= 2;  
         } else if ((fSigma < iSearchRange / 6)  
                            && (pEnc->fMvPrevSigma >= 0)  
                            && (pEnc->fMvPrevSigma < iSearchRange / 6)  
                            && (pParam->m_fcode >= (2 + (pParam->vol_flags & XVID_VOL_QUARTERPEL?1:0) )))        /* minimum search range 16 */  
         {  
                 pParam->m_fcode--;  
                 iSearchRange /= 2;  
         }  
   
         pEnc->fMvPrevSigma = fSigma;  
1751    
1752          /* frame drop code */          /* frame drop code */
1753  #if 0  #if 0
# Line 1934  Line 1832 
1832                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \                  fprintf(fp,"Y=%3d   X=%3d   MB=%2d   CBP=%02X\n",y,x,mb->mode,mb->cbp); \
1833          }          }
1834    
         /* XXX: pEnc->current->global_flags &= ~XVID_VOP_REDUCED;  reduced resoltion not yet supported */  
   
1835          if (!first){          if (!first){
1836                  fp=fopen("C:\\XVIDDBGE.TXT","w");                  fp=fopen("C:\\XVIDDBGE.TXT","w");
1837          }          }
# Line 2006  Line 1902 
1902                          if (mb->mode == MODE_NOT_CODED) {                          if (mb->mode == MODE_NOT_CODED) {
1903                                  if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {                                  if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {
1904                                          MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image,                                          MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image,
1905                                                                                          NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0);                                                                                          NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0);
1906                                  }                                  }
   
1907                                  continue;                                  continue;
1908                          }                          }
1909    
1910                          if (mb->mode != MODE_DIRECT_NONE_MV || pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {                          mb->quant = frame->quant;
1911    
1912                            if (mb->cbp != 0 || pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) {
1913                                    /* we have to motion-compensate, transfer etc,
1914                                            because there might be blocks to code */
1915    
1916                                  MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,                                  MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image,
1917                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,                                                                           f_ref, &pEnc->f_refh, &pEnc->f_refv,
1918                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,                                                                           &pEnc->f_refhv, b_ref, &pEnc->vInterH,
1919                                                                           &pEnc->vInterV, &pEnc->vInterHV,                                                                           &pEnc->vInterV, &pEnc->vInterHV,
1920                                                                           dct_codes);                                                                           dct_codes);
1921    
                                 if (mb->mode == MODE_DIRECT_NO4V) mb->mode = MODE_DIRECT;  
                                 mb->quant = frame->quant;  
   
                                 if (mb->mode != MODE_DIRECT_NONE_MV)  
1922                                          mb->cbp = MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, x, y,  dct_codes, qcoeff);                                          mb->cbp = MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, x, y,  dct_codes, qcoeff);
   
                                 if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)  
                                         && (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) {  
                                         mb->mode = MODE_DIRECT_NONE_MV; /* skipped */  
                                 }  
1923                          }                          }
1924    
1925                          /* keep only bits 5-2 -- Chroma blocks will just be skipped by the                          if (mb->mode == MODE_DIRECT_NO4V)
1926                           * coding function for BFrames, that's why we don't zero teh DC                                  mb->mode = MODE_DIRECT;
1927                           * coeffs */  
1928                          if ((frame->vop_flags & XVID_VOP_GREYSCALE))                          if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0)
1929                                    mb->mode = MODE_DIRECT_NONE_MV; /* skipped */
1930                            else
1931                                    if (frame->vop_flags & XVID_VOP_GREYSCALE)
1932                                            /* keep only bits 5-2 -- Chroma blocks will just be skipped by MBCodingBVOP */
1933                                  mb->cbp &= 0x3C;                                  mb->cbp &= 0x3C;
1934    
1935                          start_timer();                          start_timer();
# Line 2046  Line 1941 
1941    
1942          emms();          emms();
1943    
         /* TODO: dynamic fcode/bcode ??? */  
   
1944          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */          BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */
1945          frame->length = (BitstreamPos(bs) - bits) / 8;          frame->length = (BitstreamPos(bs) - bits) / 8;
1946    

Legend:
Removed from v.1406  
changed lines
  Added in v.1617

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4