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: mbprediction.c,v 1.13.2.8 2003-09-10 22:19:00 edgomez Exp $ |
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 |
|
|
447 |
|
|
448 |
pMB->cbp = calc_cbp(qcoeff); |
pMB->cbp = calc_cbp(qcoeff); |
449 |
} |
} |
450 |
|
} |
451 |
|
|
452 |
|
static const VECTOR zeroMV = { 0, 0 }; |
453 |
|
|
454 |
|
VECTOR |
455 |
|
get_pmv2(const MACROBLOCK * const mbs, |
456 |
|
const int mb_width, |
457 |
|
const int bound, |
458 |
|
const int x, |
459 |
|
const int y, |
460 |
|
const int block) |
461 |
|
{ |
462 |
|
int lx, ly, lz; /* left */ |
463 |
|
int tx, ty, tz; /* top */ |
464 |
|
int rx, ry, rz; /* top-right */ |
465 |
|
int lpos, tpos, rpos; |
466 |
|
int num_cand = 0, last_cand = 1; |
467 |
|
|
468 |
|
VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ |
469 |
|
|
470 |
|
switch (block) { |
471 |
|
case 0: |
472 |
|
lx = x - 1; ly = y; lz = 1; |
473 |
|
tx = x; ty = y - 1; tz = 2; |
474 |
|
rx = x + 1; ry = y - 1; rz = 2; |
475 |
|
break; |
476 |
|
case 1: |
477 |
|
lx = x; ly = y; lz = 0; |
478 |
|
tx = x; ty = y - 1; tz = 3; |
479 |
|
rx = x + 1; ry = y - 1; rz = 2; |
480 |
|
break; |
481 |
|
case 2: |
482 |
|
lx = x - 1; ly = y; lz = 3; |
483 |
|
tx = x; ty = y; tz = 0; |
484 |
|
rx = x; ry = y; rz = 1; |
485 |
|
break; |
486 |
|
default: |
487 |
|
lx = x; ly = y; lz = 2; |
488 |
|
tx = x; ty = y; tz = 0; |
489 |
|
rx = x; ry = y; rz = 1; |
490 |
|
} |
491 |
|
|
492 |
|
lpos = lx + ly * mb_width; |
493 |
|
rpos = rx + ry * mb_width; |
494 |
|
tpos = tx + ty * mb_width; |
495 |
|
|
496 |
|
if (lpos >= bound && lx >= 0) { |
497 |
|
num_cand++; |
498 |
|
pmv[1] = mbs[lpos].mvs[lz]; |
499 |
|
} else pmv[1] = zeroMV; |
500 |
|
|
501 |
|
if (tpos >= bound) { |
502 |
|
num_cand++; |
503 |
|
last_cand = 2; |
504 |
|
pmv[2] = mbs[tpos].mvs[tz]; |
505 |
|
} else pmv[2] = zeroMV; |
506 |
|
|
507 |
|
if (rpos >= bound && rx < mb_width) { |
508 |
|
num_cand++; |
509 |
|
last_cand = 3; |
510 |
|
pmv[3] = mbs[rpos].mvs[rz]; |
511 |
|
} else pmv[3] = zeroMV; |
512 |
|
|
513 |
|
/* If there're more than one candidate, we return the median vector */ |
514 |
|
|
515 |
|
if (num_cand > 1) { |
516 |
|
/* set median */ |
517 |
|
pmv[0].x = |
518 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
519 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
520 |
|
pmv[0].y = |
521 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
522 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
523 |
|
return pmv[0]; |
524 |
|
} |
525 |
|
|
526 |
|
return pmv[last_cand]; /* no point calculating median mv */ |
527 |
|
} |
528 |
|
|
529 |
|
VECTOR |
530 |
|
get_qpmv2(const MACROBLOCK * const mbs, |
531 |
|
const int mb_width, |
532 |
|
const int bound, |
533 |
|
const int x, |
534 |
|
const int y, |
535 |
|
const int block) |
536 |
|
{ |
537 |
|
int lx, ly, lz; /* left */ |
538 |
|
int tx, ty, tz; /* top */ |
539 |
|
int rx, ry, rz; /* top-right */ |
540 |
|
int lpos, tpos, rpos; |
541 |
|
int num_cand = 0, last_cand = 1; |
542 |
|
|
543 |
|
VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ |
544 |
|
|
545 |
|
switch (block) { |
546 |
|
case 0: |
547 |
|
lx = x - 1; ly = y; lz = 1; |
548 |
|
tx = x; ty = y - 1; tz = 2; |
549 |
|
rx = x + 1; ry = y - 1; rz = 2; |
550 |
|
break; |
551 |
|
case 1: |
552 |
|
lx = x; ly = y; lz = 0; |
553 |
|
tx = x; ty = y - 1; tz = 3; |
554 |
|
rx = x + 1; ry = y - 1; rz = 2; |
555 |
|
break; |
556 |
|
case 2: |
557 |
|
lx = x - 1; ly = y; lz = 3; |
558 |
|
tx = x; ty = y; tz = 0; |
559 |
|
rx = x; ry = y; rz = 1; |
560 |
|
break; |
561 |
|
default: |
562 |
|
lx = x; ly = y; lz = 2; |
563 |
|
tx = x; ty = y; tz = 0; |
564 |
|
rx = x; ry = y; rz = 1; |
565 |
|
} |
566 |
|
|
567 |
|
lpos = lx + ly * mb_width; |
568 |
|
rpos = rx + ry * mb_width; |
569 |
|
tpos = tx + ty * mb_width; |
570 |
|
|
571 |
|
if (lpos >= bound && lx >= 0) { |
572 |
|
num_cand++; |
573 |
|
pmv[1] = mbs[lpos].qmvs[lz]; |
574 |
|
} else pmv[1] = zeroMV; |
575 |
|
|
576 |
|
if (tpos >= bound) { |
577 |
|
num_cand++; |
578 |
|
last_cand = 2; |
579 |
|
pmv[2] = mbs[tpos].qmvs[tz]; |
580 |
|
} else pmv[2] = zeroMV; |
581 |
|
|
582 |
|
if (rpos >= bound && rx < mb_width) { |
583 |
|
num_cand++; |
584 |
|
last_cand = 3; |
585 |
|
pmv[3] = mbs[rpos].qmvs[rz]; |
586 |
|
} else pmv[3] = zeroMV; |
587 |
|
|
588 |
|
/* If there're more than one candidate, we return the median vector */ |
589 |
|
|
590 |
|
if (num_cand > 1) { |
591 |
|
/* set median */ |
592 |
|
pmv[0].x = |
593 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
594 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
595 |
|
pmv[0].y = |
596 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
597 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
598 |
|
return pmv[0]; |
599 |
|
} |
600 |
|
|
601 |
|
return pmv[last_cand]; /* no point calculating median mv */ |
602 |
} |
} |