178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar/* 278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Copyright (C) 2007-2008 ARM Limited 378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License"); 578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * you may not use this file except in compliance with the License. 678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * You may obtain a copy of the License at 778e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 878e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * http://www.apache.org/licenses/LICENSE-2.0 978e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 1078e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Unless required by applicable law or agreed to in writing, software 1178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS, 1278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * See the License for the specific language governing permissions and 1478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * limitations under the License. 1578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 1678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar */ 170c1bc742181ded4930842b46e9507372f0b1b963James Dong/** 180c1bc742181ded4930842b46e9507372f0b1b963James Dong * 190c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name: armVCM4P10_CompareMotionCostToMV.c 200c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2 210c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision: 9641 220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date: Thursday, February 7, 2008 230c1bc742181ded4930842b46e9507372f0b1b963James Dong * 240c1bc742181ded4930842b46e9507372f0b1b963James Dong * 250c1bc742181ded4930842b46e9507372f0b1b963James Dong * 260c1bc742181ded4930842b46e9507372f0b1b963James Dong * 270c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: 280c1bc742181ded4930842b46e9507372f0b1b963James Dong * Contains module for comparing motion vectors and SAD's to decide 290c1bc742181ded4930842b46e9507372f0b1b963James Dong * the best MV and SAD 300c1bc742181ded4930842b46e9507372f0b1b963James Dong * 310c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 320c1bc742181ded4930842b46e9507372f0b1b963James Dong 330c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h" 340c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h" 350c1bc742181ded4930842b46e9507372f0b1b963James Dong 360c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h" 370c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h" 380c1bc742181ded4930842b46e9507372f0b1b963James Dong 390c1bc742181ded4930842b46e9507372f0b1b963James Dong/** 400c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armVCM4P10_ExpGolBitsUsed 410c1bc742181ded4930842b46e9507372f0b1b963James Dong * 420c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: 430c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs calculating Exp-Golomb code length for a given values 440c1bc742181ded4930842b46e9507372f0b1b963James Dong * 450c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks: 460c1bc742181ded4930842b46e9507372f0b1b963James Dong * 470c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters: 480c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] val Signed number for which Exp-Golomb code length has 490c1bc742181ded4930842b46e9507372f0b1b963James Dong * to be calculated 500c1bc742181ded4930842b46e9507372f0b1b963James Dong * 510c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value: 520c1bc742181ded4930842b46e9507372f0b1b963James Dong * Returns the length of the Exp-Golomb code for val 530c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 540c1bc742181ded4930842b46e9507372f0b1b963James Dong 550c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic OMX_U16 armVCM4P10_ExpGolBitsUsed (OMX_S16 val) 560c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 570c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U16 sizeCodeNum, codeNum; 580c1bc742181ded4930842b46e9507372f0b1b963James Dong 590c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Mapping val to codeNum */ 600c1bc742181ded4930842b46e9507372f0b1b963James Dong codeNum = armAbs (val); 610c1bc742181ded4930842b46e9507372f0b1b963James Dong if (val > 0) 620c1bc742181ded4930842b46e9507372f0b1b963James Dong { 630c1bc742181ded4930842b46e9507372f0b1b963James Dong codeNum = (2 * codeNum) - 1; 640c1bc742181ded4930842b46e9507372f0b1b963James Dong } 650c1bc742181ded4930842b46e9507372f0b1b963James Dong else 660c1bc742181ded4930842b46e9507372f0b1b963James Dong { 670c1bc742181ded4930842b46e9507372f0b1b963James Dong codeNum = 2 * codeNum; 680c1bc742181ded4930842b46e9507372f0b1b963James Dong } 690c1bc742181ded4930842b46e9507372f0b1b963James Dong 700c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Size of the exp-golomb code */ 710c1bc742181ded4930842b46e9507372f0b1b963James Dong sizeCodeNum = (2 * armLogSize (codeNum + 1)) - 1; 720c1bc742181ded4930842b46e9507372f0b1b963James Dong 730c1bc742181ded4930842b46e9507372f0b1b963James Dong return sizeCodeNum; 740c1bc742181ded4930842b46e9507372f0b1b963James Dong} 750c1bc742181ded4930842b46e9507372f0b1b963James Dong 760c1bc742181ded4930842b46e9507372f0b1b963James Dong 770c1bc742181ded4930842b46e9507372f0b1b963James Dong/** 780c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: armVCM4P10_CompareMotionCostToMV 790c1bc742181ded4930842b46e9507372f0b1b963James Dong * 800c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: 810c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs comparision of motion vectors and Motion cost to decide the 820c1bc742181ded4930842b46e9507372f0b1b963James Dong * best MV and best MC 830c1bc742181ded4930842b46e9507372f0b1b963James Dong * 840c1bc742181ded4930842b46e9507372f0b1b963James Dong * Remarks: 850c1bc742181ded4930842b46e9507372f0b1b963James Dong * 860c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters: 870c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] mvX x coordinate of the candidate motion vector in 1/4 pel units 880c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] mvY y coordinate of the candidate motion vector in 1/4 pel units 890c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] diffMV differential MV 900c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] candSAD Candidate SAD 910c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] bestMV Best MV, contains best MV till the previous interation. 920c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] nLamda Lamda factor; used to compute motion cost 930c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] *pBestCost Contains the current best motion cost. 940c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] *pBestCost pBestCost Motion cost will be associated with the best MV 950c1bc742181ded4930842b46e9507372f0b1b963James Dong * after judgement; 960c1bc742181ded4930842b46e9507372f0b1b963James Dong * computed as SAD+Lamda*BitsUsedByMV, if the candCost is less 970c1bc742181ded4930842b46e9507372f0b1b963James Dong * than the best cost passed then the *pBestCost will be equal to candCost 980c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] bestMV Finally will have the best MV after the judgement. 990c1bc742181ded4930842b46e9507372f0b1b963James Dong * 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value: 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_INT -- 1 to indicate that the current motion cost is the best 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong * 0 to indicate that it is NOT the best motion cost 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong 1050c1bc742181ded4930842b46e9507372f0b1b963James DongOMX_INT armVCM4P10_CompareMotionCostToMV ( 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S16 mvX, 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S16 mvY, 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXVCMotionVector diffMV, 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_INT candSAD, 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXVCMotionVector *bestMV, 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U32 nLamda, 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S32 *pBestCost 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong) 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S32 candCost; 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U16 sizeCodeNum; 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong sizeCodeNum = armVCM4P10_ExpGolBitsUsed (diffMV.dx); 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong sizeCodeNum += armVCM4P10_ExpGolBitsUsed (diffMV.dy); 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Motion cost = SAD + lamda * ((bitsused(diffMVx) + (bitsused(diffMVy))*/ 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong candCost = candSAD + (nLamda * sizeCodeNum); 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Calculate candCost */ 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong if (candCost < *pBestCost) 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong *pBestCost = candCost; 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong bestMV->dx = mvX; 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong bestMV->dy = mvY; 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong return 1; 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong if (candCost > *pBestCost) 1330c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong return 0; 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong /* shorter motion vector */ 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (mvX * mvX + mvY * mvY) < ((bestMV->dx * bestMV->dx) + (bestMV->dy * bestMV->dy)) ) 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong *pBestCost = candCost; 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong bestMV->dx = mvX; 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong bestMV->dy = mvY; 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong return 1; 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong return 0; 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong} 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong/*End of File*/ 149