--- trunk/xvidcore/src/prediction/mbprediction.c 2002/06/30 10:46:29 252 +++ trunk/xvidcore/src/prediction/mbprediction.c 2002/11/17 00:35:33 652 @@ -1,54 +1,59 @@ - /****************************************************************************** - * * - * This file is part of XviD, a free MPEG-4 video encoder/decoder * - * * - * XviD is an implementation of a part of one or more MPEG-4 Video tools * - * as specified in ISO/IEC 14496-2 standard. Those intending to use this * - * software module in hardware or software products are advised that its * - * use may infringe existing patents or copyrights, and any such use * - * would be at such party's own risk. The original developer of this * - * software module and his/her company, and subsequent editors and their * - * companies, will have no liability for use of this software or * - * modifications or derivatives thereof. * - * * - * XviD is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * XviD is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * 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 * - * Copyright (C) 2001 - Peter Ross * - * * - * 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 * - * * - ******************************************************************************/ +/***************************************************************************** + * + * XVID MPEG-4 VIDEO CODEC + * - Prediction functions - + * + * Copyright(C) 2001-2002 - Michael Militzer + * Copyright(C) 2001-2002 - Peter Ross + * + * This file is part of XviD, a free MPEG-4 video encoder/decoder + * + * XviD is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Under section 8 of the GNU General Public License, the copyright + * holders of XVID explicitly forbid distribution in the following + * countries: + * + * - Japan + * - United States of America + * + * Linking XviD statically or dynamically with other modules is making a + * combined work based on XviD. Thus, the terms and conditions of the + * GNU General Public License cover the whole combination. + * + * As a special exception, the copyright holders of XviD give you + * permission to link XviD with independent modules that communicate with + * XviD solely through the VFW1.1 and DShow interfaces, regardless of the + * license terms of these independent modules, and to copy and distribute + * the resulting combined work under terms of your choice, provided that + * every copy of the combined work is accompanied by a complete copy of + * the source code of XviD (the version of XviD used to produce the + * combined work), being distributed under the terms of the GNU General + * Public License plus this exception. An independent module is a module + * which is not derived from or based on XviD. + * + * Note that people who make modified versions of XviD are not obligated + * to grant this special exception for their modified versions; it is + * their choice whether to do so. The GNU General Public License gives + * permission to release a modified version without this exception; this + * exception also makes it possible to release a modified version which + * carries forward this exception. + * + * $Id: mbprediction.c,v 1.10 2002-11-17 00:35:33 edgomez Exp $ + * + ****************************************************************************/ #include "../encoder.h" #include "mbprediction.h" @@ -60,6 +65,10 @@ #define DIV_DIV(A,B) ( (A) > 0 ? ((A)+((B)>>1))/(B) : ((A)-((B)>>1))/(B) ) +/***************************************************************************** + * Local inlined function + ****************************************************************************/ + static int __inline rescale(int predict_quant, int current_quant, @@ -70,6 +79,10 @@ } +/***************************************************************************** + * Local data + ****************************************************************************/ + static const int16_t default_acdc_values[15] = { 1024, 0, 0, 0, 0, 0, 0, 0, @@ -77,6 +90,11 @@ }; +/***************************************************************************** + * Functions + ****************************************************************************/ + + /* get dc/ac prediction direction for a single block and place predictor values into MB->pred_values[j][..] */ @@ -408,182 +426,3 @@ } } - - - - -/* - get_pmvdata2: get_pmvdata with bounding -*/ -#define OFFSET(x,y,stride) ((x)+((y)*(stride))) - -int -get_pmvdata2(const MACROBLOCK * const pMBs, - const uint32_t x, - const uint32_t y, - const uint32_t x_dim, - const uint32_t block, - VECTOR * const pmv, - int32_t * const psad, - const int bound) -{ - const int mbpos = OFFSET(x, y ,x_dim); - - /* - * pmv are filled with: - * [0]: Median (or whatever is correct in a special case) - * [1]: left neighbour - * [2]: top neighbour - * [3]: topright neighbour - * psad are filled with: - * [0]: minimum of [1] to [3] - * [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed) - * [2]: top neighbour's SAD - * [3]: topright neighbour's SAD - */ - - int xin1, xin2, xin3; - int yin1, yin2, yin3; - int vec1, vec2, vec3; - - int pos1, pos2, pos3; - int num_cand = 0; // number of candidates - int last_cand; // last candidate - - uint32_t index = x + y * x_dim; - const VECTOR zeroMV = { 0, 0 }; - - /* - * MODE_INTER, vm18 page 48 - * MODE_INTER4V vm18 page 51 - * - * (x,y-1) (x+1,y-1) - * [ | ] [ | ] - * [ 2 | 3 ] [ 2 | ] - * - * (x-1,y) (x,y) (x+1,y) - * [ | 1 ] [ 0 | 1 ] [ 0 | ] - * [ | 3 ] [ 2 | 3 ] [ | ] - */ - - switch (block) { - case 0: - xin1 = x - 1; - yin1 = y; - vec1 = 1; /* left */ - xin2 = x; - yin2 = y - 1; - vec2 = 2; /* top */ - xin3 = x + 1; - yin3 = y - 1; - vec3 = 2; /* top right */ - break; - case 1: - xin1 = x; - yin1 = y; - vec1 = 0; - xin2 = x; - yin2 = y - 1; - vec2 = 3; - xin3 = x + 1; - yin3 = y - 1; - vec3 = 2; - break; - case 2: - xin1 = x - 1; - yin1 = y; - vec1 = 3; - xin2 = x; - yin2 = y; - vec2 = 0; - xin3 = x; - yin3 = y; - vec3 = 1; - break; - default: - xin1 = x; - yin1 = y; - vec1 = 2; - xin2 = x; - yin2 = y; - vec2 = 0; - xin3 = x; - yin3 = y; - vec3 = 1; - } - - pos1 = OFFSET(xin1, yin1, x_dim); - pos2 = OFFSET(xin2, yin2, x_dim); - pos3 = OFFSET(xin3, yin3, x_dim); - - // left - if (xin1 < 0 || pos1 < bound) { - pmv[1] = zeroMV; - psad[1] = MV_MAX_ERROR; - } else { - pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; - psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1]; - num_cand++; - last_cand = 1; - } - - // top - if (yin2 < 0 || pos2 < bound) { - pmv[2] = zeroMV; - psad[2] = MV_MAX_ERROR; - } else { - pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; - psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2]; - num_cand++; - last_cand = 2; - } - - - // top right - if (yin3 < 0 || pos3 < bound || xin3 >= (int)x_dim) { - pmv[3] = zeroMV; - psad[3] = MV_MAX_ERROR; - //DPRINTF(DPRINTF_MV, "top-right"); - } else { - pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; - psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3]; - num_cand++; - last_cand = 3; - } - - if (num_cand == 1) - { - /* DPRINTF(DPRINTF_MV,"cand0=(%i,%i), cand1=(%i,%i) cand2=(%i,%i) last=%i", - pmv[1].x, pmv[1].y, - pmv[2].x, pmv[2].y, - pmv[3].x, pmv[3].y, last_cand - 1); - */ - - pmv[0] = pmv[last_cand]; - psad[0] = psad[last_cand]; - return 0; - } - - /* DPRINTF(DPRINTF_MV,"cand0=(%i,%i), cand1=(%i,%i) cand2=(%i,%i)", - pmv[1].x, pmv[1].y, - pmv[2].x, pmv[2].y, - pmv[3].x, pmv[3].y);*/ - - if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { - pmv[0] = pmv[1]; - psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); - return 1; - } - - /* median,minimum */ - - pmv[0].x = - MIN(MAX(pmv[1].x, pmv[2].x), - MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); - pmv[0].y = - MIN(MAX(pmv[1].y, pmv[2].y), - MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); - psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); - - return 0; -}