Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2007-2008 ARM Limited
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  *
     16  */
     17 /**
     18  *
     19  * File Name:  armVCM4P10_CompareMotionCostToMV.c
     20  * OpenMAX DL: v1.0.2
     21  * Revision:   9641
     22  * Date:       Thursday, February 7, 2008
     23  *
     24  *
     25  *
     26  *
     27  * Description:
     28  * Contains module for comparing motion vectors and SAD's to decide
     29  * the best MV and SAD
     30  *
     31  */
     32 
     33 #include "omxtypes.h"
     34 #include "armOMX.h"
     35 
     36 #include "armVC.h"
     37 #include "armCOMM.h"
     38 
     39 /**
     40  * Function: armVCM4P10_ExpGolBitsUsed
     41  *
     42  * Description:
     43  * Performs calculating Exp-Golomb code length for a given values
     44  *
     45  * Remarks:
     46  *
     47  * Parameters:
     48  * [in]	         val	Signed number for which Exp-Golomb code length has
     49  *                      to be calculated
     50  *
     51  * Return Value:
     52  *             Returns the length of the Exp-Golomb code for val
     53  */
     54 
     55 static OMX_U16 armVCM4P10_ExpGolBitsUsed (OMX_S16 val)
     56 {
     57     OMX_U16 sizeCodeNum, codeNum;
     58 
     59     /* Mapping val to codeNum */
     60     codeNum = armAbs (val);
     61     if (val > 0)
     62     {
     63         codeNum = (2 * codeNum) - 1;
     64     }
     65     else
     66     {
     67         codeNum = 2 * codeNum;
     68     }
     69 
     70     /* Size of the exp-golomb code */
     71     sizeCodeNum = (2 * armLogSize (codeNum + 1)) - 1;
     72 
     73     return sizeCodeNum;
     74 }
     75 
     76 
     77 /**
     78  * Function: armVCM4P10_CompareMotionCostToMV
     79  *
     80  * Description:
     81  * Performs comparision of motion vectors and Motion cost to decide the
     82  * best MV and best MC
     83  *
     84  * Remarks:
     85  *
     86  * Parameters:
     87  * [in]	         mvX	x coordinate of the candidate motion vector in 1/4 pel units
     88  * [in]	         mvY	y coordinate of the candidate motion vector in 1/4 pel units
     89  * [in]	      diffMV	differential MV
     90  * [in]	     candSAD	Candidate SAD
     91  * [in]	      bestMV	Best MV, contains best MV till the previous interation.
     92  * [in]       nLamda    Lamda factor; used to compute motion cost
     93  * [in]   *pBestCost    Contains the current best motion cost.
     94  * [out]  *pBestCost    pBestCost Motion cost will be associated with the best MV
     95  *                      after judgement;
     96  *                      computed as SAD+Lamda*BitsUsedByMV, if the candCost is less
     97  *                      than the best cost passed then the *pBestCost will be equal to candCost
     98  * [out]	  bestMV	Finally will have the best MV after the judgement.
     99  *
    100  * Return Value:
    101  * OMX_INT -- 1 to indicate that the current motion cost is the best
    102  *            0 to indicate that it is NOT the best motion cost
    103  */
    104 
    105 OMX_INT armVCM4P10_CompareMotionCostToMV (
    106     OMX_S16  mvX,
    107     OMX_S16  mvY,
    108     OMXVCMotionVector diffMV,
    109     OMX_INT candSAD,
    110     OMXVCMotionVector *bestMV,
    111     OMX_U32 nLamda,
    112     OMX_S32 *pBestCost
    113 )
    114 {
    115     OMX_S32 candCost;
    116     OMX_U16 sizeCodeNum;
    117 
    118     sizeCodeNum = armVCM4P10_ExpGolBitsUsed (diffMV.dx);
    119     sizeCodeNum += armVCM4P10_ExpGolBitsUsed (diffMV.dy);
    120 
    121     /* Motion cost = SAD +  lamda * ((bitsused(diffMVx) + (bitsused(diffMVy))*/
    122     candCost = candSAD + (nLamda * sizeCodeNum);
    123 
    124     /* Calculate candCost */
    125     if (candCost < *pBestCost)
    126     {
    127         *pBestCost = candCost;
    128         bestMV->dx = mvX;
    129         bestMV->dy = mvY;
    130         return 1;
    131     }
    132     if (candCost > *pBestCost)
    133     {
    134         return 0;
    135     }
    136     /* shorter motion vector */
    137     if ( (mvX * mvX + mvY * mvY) < ((bestMV->dx * bestMV->dx) + (bestMV->dy * bestMV->dy)) )
    138     {
    139         *pBestCost = candCost;
    140         bestMV->dx = mvX;
    141         bestMV->dy = mvY;
    142         return 1;
    143     }
    144 
    145     return 0;
    146 }
    147 
    148 /*End of File*/
    149