[svn] / branches / dev-api-3 / xvidcore / src / prediction / mbprediction.h Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/prediction/mbprediction.h

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

revision 392, Wed Sep 4 18:44:41 2002 UTC revision 579, Sat Oct 5 21:37:44 2002 UTC
# Line 26  Line 26 
26   *  along with this program; if not, write to the xvid_free Software   *  along with this program; if not, write to the xvid_free Software
27   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28   *   *
29   *  $Id: mbprediction.h,v 1.13 2002-07-10 19:17:49 chl Exp $   *  $Id: mbprediction.h,v 1.13.2.1 2002-10-05 21:32:48 Isibaar Exp $
30   *   *
31   *************************************************************************/   *************************************************************************/
32    
# Line 208  Line 208 
208  }  }
209    
210    
211    static __inline VECTOR
212    get_qpmv(const MACROBLOCK * const pMBs,
213                    const uint32_t x,
214                    const uint32_t y,
215                    const uint32_t x_dim,
216                    const uint32_t block)
217    {
218    
219            int xin1, xin2, xin3;
220            int yin1, yin2, yin3;
221            int vec1, vec2, vec3;
222            VECTOR lneigh, tneigh, trneigh; /* left neighbour, top neighbour, topright neighbour */
223            VECTOR median;
224    
225            static VECTOR zeroMV = { 0, 0 };
226            uint32_t index = x + y * x_dim;
227    
228            /* first row (special case) */
229            if (y == 0 && (block == 0 || block == 1)) {
230                    if ((x == 0) && (block == 0))   // first column, first block
231                    {
232                            return zeroMV;
233                    }
234                    if (block == 1)                 // second block; has only a left neighbour
235                    {
236                            return pMBs[index].qmvs[0];
237                    } else {                                /* block==0, but x!=0, so again, there is a left neighbour */
238    
239                            return pMBs[index - 1].qmvs[1];
240                    }
241            }
242    
243            /*
244             * MODE_INTER, vm18 page 48
245             * MODE_INTER4V vm18 page 51
246             *
247             *   (x,y-1)      (x+1,y-1)
248             *   [   |   ]    [   |   ]
249             *   [ 2 | 3 ]    [ 2 |   ]
250             *
251             *   (x-1,y)       (x,y)        (x+1,y)
252             *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
253             *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
254             */
255    
256            switch (block) {
257            case 0:
258                    xin1 = x - 1;
259                    yin1 = y;
260                    vec1 = 1;                               /* left */
261                    xin2 = x;
262                    yin2 = y - 1;
263                    vec2 = 2;                               /* top */
264                    xin3 = x + 1;
265                    yin3 = y - 1;
266                    vec3 = 2;                               /* top right */
267                    break;
268            case 1:
269                    xin1 = x;
270                    yin1 = y;
271                    vec1 = 0;
272                    xin2 = x;
273                    yin2 = y - 1;
274                    vec2 = 3;
275                    xin3 = x + 1;
276                    yin3 = y - 1;
277                    vec3 = 2;
278                    break;
279            case 2:
280                    xin1 = x - 1;
281                    yin1 = y;
282                    vec1 = 3;
283                    xin2 = x;
284                    yin2 = y;
285                    vec2 = 0;
286                    xin3 = x;
287                    yin3 = y;
288                    vec3 = 1;
289                    break;
290            default:
291                    xin1 = x;
292                    yin1 = y;
293                    vec1 = 2;
294                    xin2 = x;
295                    yin2 = y;
296                    vec2 = 0;
297                    xin3 = x;
298                    yin3 = y;
299                    vec3 = 1;
300            }
301    
302    
303            if (xin1 < 0 || /* yin1 < 0  || */ xin1 >= (int32_t) x_dim) {
304                    lneigh = zeroMV;
305            } else {
306                    lneigh = pMBs[xin1 + yin1 * x_dim].qmvs[vec1];
307            }
308    
309            if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) {
310                    tneigh = zeroMV;
311            } else {
312                    tneigh = pMBs[xin2 + yin2 * x_dim].qmvs[vec2];
313            }
314    
315            if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) {
316                    trneigh = zeroMV;
317            } else {
318                    trneigh = pMBs[xin3 + yin3 * x_dim].qmvs[vec3];
319            }
320    
321            /* median,minimum */
322    
323            median.x =
324                    MIN(MAX(lneigh.x, tneigh.x),
325                            MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x)));
326            median.y =
327                    MIN(MAX(lneigh.y, tneigh.y),
328                            MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y)));
329            return median;
330    }
331    
332  /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD  /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD
333     instead of only Median MV */     instead of only Median MV */
334    
# Line 473  Line 594 
594    
595    
596          /*          /*
597             * MODE_INTER, vm18 page 48
598             * MODE_INTER4V vm18 page 51
599             *
600             *   (x,y-1)      (x+1,y-1)
601             *   [   |   ]    [   |   ]
602             *   [ 2 | 3 ]    [ 2 |   ]
603             *
604             *   (x-1,y)       (x,y)        (x+1,y)
605             *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
606             *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
607             */
608    
609    static __inline VECTOR
610    get_qpmv2(const MACROBLOCK * const mbs,
611             const int mb_width,
612             const int bound,
613             const int x,
614             const int y,
615             const int block)
616    {
617            static const VECTOR zeroMV = { 0, 0 };
618    
619        int lx, ly, lz;         /* left */
620        int tx, ty, tz;         /* top */
621        int rx, ry, rz;         /* top-right */
622        int lpos, tpos, rpos;
623        int num_cand, last_cand;
624    
625            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
626    
627            switch (block) {
628            case 0:
629                    lx = x - 1;     ly = y;         lz = 1;
630                    tx = x;         ty = y - 1;     tz = 2;
631                    rx = x + 1;     ry = y - 1;     rz = 2;
632                    break;
633            case 1:
634                    lx = x;         ly = y;         lz = 0;
635                    tx = x;         ty = y - 1;     tz = 3;
636                    rx = x + 1;     ry = y - 1;     rz = 2;
637                    break;
638            case 2:
639                    lx = x - 1;     ly = y;         lz = 3;
640                    tx = x;         ty = y;         tz = 0;
641                    rx = x;         ry = y;         rz = 1;
642                    break;
643            default:
644                    lx = x;         ly = y;         lz = 2;
645                    tx = x;         ty = y;         tz = 0;
646                    rx = x;         ry = y;         rz = 1;
647            }
648    
649        lpos = lx + ly * mb_width;
650        rpos = rx + ry * mb_width;
651        tpos = tx + ty * mb_width;
652        num_cand = 0;
653    
654        if (lpos >= bound && lx >= 0) {
655            num_cand++;
656            last_cand = 1;
657            pmv[1] = mbs[lpos].qmvs[lz];
658        } else {
659            pmv[1] = zeroMV;
660        }
661    
662        if (tpos >= bound) {
663            num_cand++;
664            last_cand = 2;
665            pmv[2] = mbs[tpos].qmvs[tz];
666        } else {
667            pmv[2] = zeroMV;
668        }
669    
670        if (rpos >= bound && rx < mb_width) {
671            num_cand++;
672            last_cand = 3;
673            pmv[3] = mbs[rpos].qmvs[rz];
674        } else {
675            pmv[3] = zeroMV;
676        }
677    
678        /* if only one valid candidate predictor, the invalid candiates are set to the canidate */
679            if (num_cand != 1) {
680                    /* set median */
681    
682                    pmv[0].x =
683                            MIN(MAX(pmv[1].x, pmv[2].x),
684                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
685                    pmv[0].y =
686                            MIN(MAX(pmv[1].y, pmv[2].y),
687                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
688                    return pmv[0];
689             }
690    
691             return pmv[last_cand];  /* no point calculating median mv */
692    }
693    
694    
695            /*
696           * pmv are filled with:           * pmv are filled with:
697           *  [0]: Median (or whatever is correct in a special case)           *  [0]: Median (or whatever is correct in a special case)
698           *  [1]: left neighbour           *  [1]: left neighbour

Legend:
Removed from v.392  
changed lines
  Added in v.579

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