[cvs] / xvidcore / src / prediction / mbprediction.c Repository:
ViewVC logotype

Diff of /xvidcore/src/prediction/mbprediction.c

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

revision 1.13.2.7, Mon Jun 9 01:22:58 2003 UTC revision 1.13.2.10, Fri Oct 3 16:57:55 2003 UTC
# Line 1  Line 1 
1   /******************************************************************************  /*****************************************************************************
2    *                                                                            *   *
3    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *   *  XVID MPEG-4 VIDEO CODEC
4    *                                                                            *   *  - Prediction module -
5    *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *   *
6    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *   *  Copyright (C) 2001-2003 Michael Militzer <isibaar@xvid.org>
7    *  software module in hardware or software products are advised that its     *   *                2001-2003 Peter Ross <pross@xvid.org>
8    *  use may infringe existing patents or copyrights, and any such use         *   *
9    *  would be at such party's own risk.  The original developer of this        *   *  This program is free software ; you can redistribute it and/or modify
10    *  software module and his/her company, and subsequent editors and their     *   *  it under the terms of the GNU General Public License as published by
11    *  companies, will have no liability for use of this software or             *   *  the Free Software Foundation ; either version 2 of the License, or
12    *  modifications or derivatives thereof.                                     *   *  (at your option) any later version.
13    *                                                                            *   *
14    *  XviD is free software; you can redistribute it and/or modify it           *   *  This program is distributed in the hope that it will be useful,
15    *  under the terms of the GNU General Public License as published by         *   *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
16    *  the Free Software Foundation; either version 2 of the License, or         *   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    *  (at your option) any later version.                                       *   *  GNU General Public License for more details.
18    *                                                                            *   *
19    *  XviD is distributed in the hope that it will be useful, but               *   *  You should have received a copy of the GNU General Public License
20    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *   *  along with this program ; if not, write to the Free Software
21    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22    *  GNU General Public License for more details.                              *   *
23    *                                                                            *   * $Id$
24    *  You should have received a copy of the GNU General Public License         *   *
25    *  along with this program; if not, write to the Free Software               *   ****************************************************************************/
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  mbprediction.c                                                            *  
   *                                                                            *  
   *  Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>                  *  
   *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *  
   *                                                                            *  
   *  For more information visit the XviD homepage: http://www.xvid.org         *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  29.06.2002 predict_acdc() bounding                                        *  
   *  12.12.2001 improved calc_acdc_prediction; removed need for memcpy         *  
   *  15.12.2001 moved pmv displacement to motion estimation                    *  
   *  30.11.2001 mmx cbp support                                                *  
   *  17.11.2001 initial version                                                *  
   *                                                                            *  
   ******************************************************************************/  
26    
27  #include <stdlib.h>  #include <stdlib.h>
28    
# Line 373  Line 347 
347          qcoeff[0] = qcoeff[0] - predictors[0];          qcoeff[0] = qcoeff[0] - predictors[0];
348    
349          /* calc cost before ac prediction */          /* calc cost before ac prediction */
 #ifdef BIGLUT  
         Z2 = CodeCoeff_CalcBits(qcoeff, intra_table, scan_tables[0], 1);  
 #else  
350          Z2 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[0]);          Z2 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[0]);
 #endif  
351    
352          /* apply ac prediction & calc cost*/          /* apply ac prediction & calc cost*/
353          if (direction == 1) {          if (direction == 1) {
# Line 394  Line 364 
364                  }                  }
365          }          }
366    
 #ifdef BIGLUT  
         Z1 = CodeCoeff_CalcBits(qcoeff, intra_table, scan_tables[direction], 1);  
 #else  
367          Z1 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]);          Z1 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]);
 #endif  
368    
369          /* undo prediction */          /* undo prediction */
370          if (direction == 1) {          if (direction == 1) {
# Line 473  Line 439 
439    
440                  pMB->cbp = calc_cbp(qcoeff);                  pMB->cbp = calc_cbp(qcoeff);
441          }          }
442    }
443    
444    static const VECTOR zeroMV = { 0, 0 };
445    
446    VECTOR
447    get_pmv2(const MACROBLOCK * const mbs,
448                    const int mb_width,
449                    const int bound,
450                    const int x,
451                    const int y,
452                    const int block)
453    {
454            int lx, ly, lz;         /* left */
455            int tx, ty, tz;         /* top */
456            int rx, ry, rz;         /* top-right */
457            int lpos, tpos, rpos;
458            int num_cand = 0, last_cand = 1;
459    
460            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
461    
462            switch (block) {
463            case 0:
464                    lx = x - 1;     ly = y;         lz = 1;
465                    tx = x;         ty = y - 1;     tz = 2;
466                    rx = x + 1;     ry = y - 1;     rz = 2;
467                    break;
468            case 1:
469                    lx = x;         ly = y;         lz = 0;
470                    tx = x;         ty = y - 1;     tz = 3;
471                    rx = x + 1;     ry = y - 1;     rz = 2;
472                    break;
473            case 2:
474                    lx = x - 1;     ly = y;         lz = 3;
475                    tx = x;         ty = y;         tz = 0;
476                    rx = x;         ry = y;         rz = 1;
477                    break;
478            default:
479                    lx = x;         ly = y;         lz = 2;
480                    tx = x;         ty = y;         tz = 0;
481                    rx = x;         ry = y;         rz = 1;
482            }
483    
484            lpos = lx + ly * mb_width;
485            rpos = rx + ry * mb_width;
486            tpos = tx + ty * mb_width;
487    
488            if (lpos >= bound && lx >= 0) {
489                    num_cand++;
490                    pmv[1] = mbs[lpos].mvs[lz];
491            } else pmv[1] = zeroMV;
492    
493            if (tpos >= bound) {
494                    num_cand++;
495                    last_cand = 2;
496                    pmv[2] = mbs[tpos].mvs[tz];
497            } else pmv[2] = zeroMV;
498    
499            if (rpos >= bound && rx < mb_width) {
500                    num_cand++;
501                    last_cand = 3;
502                    pmv[3] = mbs[rpos].mvs[rz];
503            } else pmv[3] = zeroMV;
504    
505            /* If there're more than one candidate, we return the median vector */
506    
507            if (num_cand > 1) {
508                    /* set median */
509                    pmv[0].x =
510                            MIN(MAX(pmv[1].x, pmv[2].x),
511                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
512                    pmv[0].y =
513                            MIN(MAX(pmv[1].y, pmv[2].y),
514                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
515                    return pmv[0];
516            }
517    
518            return pmv[last_cand];  /* no point calculating median mv */
519    }
520    
521    VECTOR
522    get_qpmv2(const MACROBLOCK * const mbs,
523                    const int mb_width,
524                    const int bound,
525                    const int x,
526                    const int y,
527                    const int block)
528    {
529            int lx, ly, lz;         /* left */
530            int tx, ty, tz;         /* top */
531            int rx, ry, rz;         /* top-right */
532            int lpos, tpos, rpos;
533            int num_cand = 0, last_cand = 1;
534    
535            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
536    
537            switch (block) {
538            case 0:
539                    lx = x - 1;     ly = y;         lz = 1;
540                    tx = x;         ty = y - 1;     tz = 2;
541                    rx = x + 1;     ry = y - 1;     rz = 2;
542                    break;
543            case 1:
544                    lx = x;         ly = y;         lz = 0;
545                    tx = x;         ty = y - 1;     tz = 3;
546                    rx = x + 1;     ry = y - 1;     rz = 2;
547                    break;
548            case 2:
549                    lx = x - 1;     ly = y;         lz = 3;
550                    tx = x;         ty = y;         tz = 0;
551                    rx = x;         ry = y;         rz = 1;
552                    break;
553            default:
554                    lx = x;         ly = y;         lz = 2;
555                    tx = x;         ty = y;         tz = 0;
556                    rx = x;         ry = y;         rz = 1;
557            }
558    
559            lpos = lx + ly * mb_width;
560            rpos = rx + ry * mb_width;
561            tpos = tx + ty * mb_width;
562    
563            if (lpos >= bound && lx >= 0) {
564                    num_cand++;
565                    pmv[1] = mbs[lpos].qmvs[lz];
566            } else pmv[1] = zeroMV;
567    
568            if (tpos >= bound) {
569                    num_cand++;
570                    last_cand = 2;
571                    pmv[2] = mbs[tpos].qmvs[tz];
572            } else pmv[2] = zeroMV;
573    
574            if (rpos >= bound && rx < mb_width) {
575                    num_cand++;
576                    last_cand = 3;
577                    pmv[3] = mbs[rpos].qmvs[rz];
578            } else pmv[3] = zeroMV;
579    
580            /* If there're more than one candidate, we return the median vector */
581    
582            if (num_cand > 1) {
583                    /* set median */
584                    pmv[0].x =
585                            MIN(MAX(pmv[1].x, pmv[2].x),
586                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
587                    pmv[0].y =
588                            MIN(MAX(pmv[1].y, pmv[2].y),
589                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
590                    return pmv[0];
591            }
592    
593            return pmv[last_cand];  /* no point calculating median mv */
594  }  }

Legend:
Removed from v.1.13.2.7  
changed lines
  Added in v.1.13.2.10

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