159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ------------------------------------------------------------------ 259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Copyright (C) 1998-2009 PacketVideo 359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Licensed under the Apache License, Version 2.0 (the "License"); 559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * you may not use this file except in compliance with the License. 659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * You may obtain a copy of the License at 759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * http://www.apache.org/licenses/LICENSE-2.0 959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 1059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Unless required by applicable law or agreed to in writing, software 1159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * distributed under the License is distributed on an "AS IS" BASIS, 1259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 1359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * express or implied. 1459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * See the License for the specific language governing permissions 1559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * and limitations under the License. 1659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * ------------------------------------------------------------------- 1759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong */ 1859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* contains 1959f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt HalfPel1_SAD_MB(UChar *ref,UChar *blk,Int dmin,Int width,Int ih,Int jh) 2059f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt HalfPel2_SAD_MB(UChar *ref,UChar *blk,Int dmin,Int width) 2159f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt HalfPel1_SAD_Blk(UChar *ref,UChar *blk,Int dmin,Int width,Int ih,Int jh) 2259f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt HalfPel2_SAD_Blk(UChar *ref,UChar *blk,Int dmin,Int width) 2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 2459f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt SAD_MB_HalfPel_C(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info) 2559f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt SAD_MB_HP_HTFM_Collect(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info) 2659f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt SAD_MB_HP_HTFM(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info) 2759f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt SAD_Blk_HalfPel_C(UChar *ref,UChar *blk,Int dmin,Int width,Int rx,Int xh,Int yh,void *extra_info) 2859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong*/ 2959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//#include <stdlib.h> /* for RAND_MAX */ 3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4def.h" 3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4lib_int.h" 3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "sad_halfpel_inline.h" 3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef _SAD_STAT 3659f566c4ec3dfc097ad8163523e522280b27e5c3James DongULong num_sad_HP_MB = 0; 3759f566c4ec3dfc097ad8163523e522280b27e5c3James DongULong num_sad_HP_Blk = 0; 3859f566c4ec3dfc097ad8163523e522280b27e5c3James DongULong num_sad_HP_MB_call = 0; 3959f566c4ec3dfc097ad8163523e522280b27e5c3James DongULong num_sad_HP_Blk_call = 0; 4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_MB_CALL() num_sad_HP_MB_call++ 4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_MB() num_sad_HP_MB++ 4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_BLK_CALL() num_sad_HP_Blk_call++ 4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_BLK() num_sad_HP_Blk++ 4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#else 4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_MB_CALL() 4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_MB() 4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_BLK_CALL() 4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define NUM_SAD_HP_BLK() 4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus 5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dongextern "C" 5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*================================================================== 5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: HalfPel1_SAD_MB 5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 03/27/2001 5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Compute SAD 16x16 between blk and ref in halfpel 6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong resolution, 6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Changes: 6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ==================================================================*/ 6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* One component is half-pel */ 6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int HalfPel1_SAD_MB(UChar *ref, UChar *blk, Int dmin, Int width, Int ih, Int jh) 6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1, *p2; 6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(jh); 7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (ih) p2 = ref + 1; 7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else p2 = ref + width; 7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) 7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 16; j++) 8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + 1) >> 1) - *kk++; 8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > dmin) 8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += width; 9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += width; 9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Two components need half-pel */ 9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int HalfPel2_SAD_MB(UChar *ref, UChar *blk, Int dmin, Int width) 9759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 9859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 9959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 10059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1, *p2, *p3, *p4; 10159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 10259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 10359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 10459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = ref + 1; 10559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 = ref + width; 10659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 = ref + width + 1; 10759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 10859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 10959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) 11059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 11159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 16; j++) 11259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 11359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - *kk++; 11559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 11659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 11759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > dmin) 11959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 12059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 12159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += width; 12259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 += width; 12359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += width; 12459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 += width; 12559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 12659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 12759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 12859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 12959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_INTER4V 13059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*================================================================== 13159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: HalfPel1_SAD_Blk 13259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 03/27/2001 13359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Compute SAD 8x8 between blk and ref in halfpel 13459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong resolution. 13559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Changes: 13659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ==================================================================*/ 13759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* One component needs half-pel */ 13859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int HalfPel1_SAD_Blk(UChar *ref, UChar *blk, Int dmin, Int width, Int ih, Int jh) 13959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 14059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 14159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 14259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1, *p2; 14359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 14459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(jh); 14659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 14859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (ih) p2 = ref + 1; 14959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else p2 = ref + width; 15059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 15159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 8; i++) 15359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 15459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 8; j++) 15559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 15659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + 1) >> 1) - *kk++; 15859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 15959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 16159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > dmin) 16259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 16359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += width; 16459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += width; 16559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk += 8; 16659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 16859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Two components need half-pel */ 17059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int HalfPel2_SAD_Blk(UChar *ref, UChar *blk, Int dmin, Int width) 17159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 17259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 17359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 17459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1, *p2, *p3, *p4; 17559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 17659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 17859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = ref + 1; 17959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 = ref + width; 18059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 = ref + width + 1; 18159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 18259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 18359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 8; i++) 18459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 18559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 8; j++) 18659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 18759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 18859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - *kk++; 18959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 19059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 19159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 19259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > dmin) 19359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 19459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 19559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += width; 19659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 += width; 19759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += width; 19859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 += width; 19959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk += 8; 20059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 20159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 20259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 20359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif // NO_INTER4V 20459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*=============================================================== 20559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: SAD_MB_HalfPel 20659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 09/17/2000 20759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Compute the SAD on the half-pel resolution 20859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Input/Output: hmem is assumed to be a pointer to the starting 20959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong point of the search in the 33x33 matrix search region 21059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Changes: 21159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11/7/00: implemented MMX 21259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ===============================================================*/ 21359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*================================================================== 21459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: SAD_MB_HalfPel_C 21559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 04/30/2001 21659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Compute SAD 16x16 between blk and ref in halfpel 21759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong resolution, 21859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Changes: 21959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ==================================================================*/ 22059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* One component is half-pel */ 22159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HalfPel_Cxhyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 22259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 22359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 22459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 22559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1, *p2, *p3, *p4; 22659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// Int sumref=0; 22759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 22859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 22959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 23059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(extra_info); 23159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 23259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 23359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 23459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 23559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = ref + 1; 23659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 = ref + rx; 23759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 = ref + rx + 1; 23859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 23959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 24059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) 24159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 24259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 16; j++) 24359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 24459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 24559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - *kk++; 24659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 24759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 24859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 24959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 25059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > (Int)((ULong)dmin_rx >> 16)) 25259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 25359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += rx; 25559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 += rx; 25659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += rx; 25759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 += rx; 25859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 25959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 26059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 26159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HalfPel_Cyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 26359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 26459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 26559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 26659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1, *p2; 26759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// Int sumref=0; 26859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 26959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 27059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(extra_info); 27259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 27459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 27659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = ref + rx; /* either left/right or top/bottom pixel */ 27759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 27859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) 28059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 28159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 16; j++) 28259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 28359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + 1) >> 1) - *kk++; 28559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 28659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 28759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 28959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > (Int)((ULong)dmin_rx >> 16)) 29159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 29259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += rx; 29359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += rx; 29459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 29559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 29659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 29759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HalfPel_Cxh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 29959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 30059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 30159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 30259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1; 30359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// Int sumref=0; 30459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 30559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 30659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(extra_info); 30859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 31059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 31259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 31359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) 31559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 31659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 16; j++) 31759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 31859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p1[j+1] + 1) >> 1) - *kk++; 32059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 32159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 32259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 32359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 32459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 32559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > (Int)((ULong)dmin_rx >> 16)) 32659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 32759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += rx; 32859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 32959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 33059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 33159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 33259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef HTFM /* HTFM with uniform subsampling implementation, 2/28/01 */ 33359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 33459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//Checheck here 33559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HP_HTFM_Collectxhyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 33659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 33759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 33859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 33959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *p1, *p2; 34059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 34159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int refwx4 = rx << 2; 34259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int saddata[16]; /* used when collecting flag (global) is on */ 34359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int difmad, tmp, tmp2; 34459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong HTFM_Stat *htfm_stat = (HTFM_Stat*) extra_info; 34559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *abs_dif_mad_avg = &(htfm_stat->abs_dif_mad_avg); 34659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UInt *countbreak = &(htfm_stat->countbreak); 34759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *offsetRef = htfm_stat->offsetRef; 34859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong cur_word; 34959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 35159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong blk -= 4; 35359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) /* 16 stages */ 35559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 35659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref + offsetRef[i]; 35759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = p1 + rx; 35859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong j = 4;/* 4 lines */ 36059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong do 36159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 36259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cur_word = *((ULong*)(blk += 4)); 36359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[12] + p2[12]; 36459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[13] + p2[13]; 36559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 36659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word >> 24) & 0xFF; 36759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 36859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 36959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[8] + p2[8]; 37059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[9] + p2[9]; 37159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 37259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word >> 16) & 0xFF; 37359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 37459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 37559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[4] + p2[4]; 37659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[5] + p2[5]; 37759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 37859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word >> 8) & 0xFF; 37959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 38059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 38159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[1] + p2[1]; 38259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[0] + p2[0]; 38359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += refwx4; 38459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += refwx4; 38559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 38659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word & 0xFF); 38759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 38859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 38959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 39059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (--j); 39159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 39359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong saddata[i] = sad; 39559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (i > 0) 39759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 39859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > (Int)((ULong)dmin_rx >> 16)) 39959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 40059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong difmad = saddata[0] - ((saddata[1] + 1) >> 1); 40159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad); 40259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*countbreak)++; 40359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 40459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 40559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 40659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 40759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong difmad = saddata[0] - ((saddata[1] + 1) >> 1); 40859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad); 40959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*countbreak)++; 41059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 41259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 41359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HP_HTFM_Collectyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 41559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 41659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 41759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 41859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *p1, *p2; 41959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 42059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int refwx4 = rx << 2; 42159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int saddata[16]; /* used when collecting flag (global) is on */ 42259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int difmad, tmp, tmp2; 42359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong HTFM_Stat *htfm_stat = (HTFM_Stat*) extra_info; 42459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *abs_dif_mad_avg = &(htfm_stat->abs_dif_mad_avg); 42559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UInt *countbreak = &(htfm_stat->countbreak); 42659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *offsetRef = htfm_stat->offsetRef; 42759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong cur_word; 42859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 42959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 43059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 43159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong blk -= 4; 43259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 43359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) /* 16 stages */ 43459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 43559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref + offsetRef[i]; 43659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = p1 + rx; 43759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong j = 4; 43859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong do 43959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 44059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cur_word = *((ULong*)(blk += 4)); 44159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[12]; 44259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[12]; 44359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 44459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 44559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 24) & 0xFF; 44659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 44759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[8]; 44859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[8]; 44959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 45059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 45159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 16) & 0xFF; 45259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 45359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[4]; 45459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[4]; 45559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 45659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 45759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 8) & 0xFF; 45859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 45959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[0]; 46059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += refwx4; 46159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[0]; 46259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += refwx4; 46359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 46459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 46559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word & 0xFF); 46659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 46759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 46859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (--j); 46959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 47059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 47159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 47259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong saddata[i] = sad; 47359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 47459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (i > 0) 47559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 47659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > (Int)((ULong)dmin_rx >> 16)) 47759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 47859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong difmad = saddata[0] - ((saddata[1] + 1) >> 1); 47959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad); 48059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*countbreak)++; 48159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 48259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 48359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 48459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 48559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong difmad = saddata[0] - ((saddata[1] + 1) >> 1); 48659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad); 48759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*countbreak)++; 48859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 48959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 49059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 49159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 49259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HP_HTFM_Collectxh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 49359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 49459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 49559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 49659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *p1; 49759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 49859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int refwx4 = rx << 2; 49959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int saddata[16]; /* used when collecting flag (global) is on */ 50059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int difmad, tmp, tmp2; 50159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong HTFM_Stat *htfm_stat = (HTFM_Stat*) extra_info; 50259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *abs_dif_mad_avg = &(htfm_stat->abs_dif_mad_avg); 50359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UInt *countbreak = &(htfm_stat->countbreak); 50459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *offsetRef = htfm_stat->offsetRef; 50559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong cur_word; 50659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 50759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 50859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 50959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong blk -= 4; 51059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 51159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) /* 16 stages */ 51259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 51359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref + offsetRef[i]; 51459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 51559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong j = 4; /* 4 lines */ 51659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong do 51759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 51859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cur_word = *((ULong*)(blk += 4)); 51959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[12]; 52059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[13]; 52159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 52259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 52359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 24) & 0xFF; 52459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 52559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[8]; 52659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[9]; 52759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 52859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 52959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 16) & 0xFF; 53059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 53159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[4]; 53259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[5]; 53359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 53459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 53559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 8) & 0xFF; 53659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 53759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[0]; 53859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[1]; 53959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += refwx4; 54059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 54159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 54259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word & 0xFF); 54359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 54459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 54559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (--j); 54659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 54759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 54859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 54959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong saddata[i] = sad; 55059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 55159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (i > 0) 55259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 55359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > (Int)((ULong)dmin_rx >> 16)) 55459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 55559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong difmad = saddata[0] - ((saddata[1] + 1) >> 1); 55659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad); 55759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*countbreak)++; 55859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 55959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 56059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 56159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 56259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong difmad = saddata[0] - ((saddata[1] + 1) >> 1); 56359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*abs_dif_mad_avg) += ((difmad > 0) ? difmad : -difmad); 56459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (*countbreak)++; 56559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 56659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 56759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 56859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 56959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HP_HTFMxhyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 57059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 57159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 57259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0, tmp, tmp2; 57359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *p1, *p2; 57459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 57559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int refwx4 = rx << 2; 57659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sadstar = 0, madstar; 57759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *nrmlz_th = (Int*) extra_info; 57859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *offsetRef = nrmlz_th + 32; 57959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong cur_word; 58059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 58159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong madstar = (ULong)dmin_rx >> 20; 58259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 58359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 58459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 58559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong blk -= 4; 58659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 58759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) /* 16 stages */ 58859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 58959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref + offsetRef[i]; 59059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = p1 + rx; 59159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 59259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong j = 4; /* 4 lines */ 59359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong do 59459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 59559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cur_word = *((ULong*)(blk += 4)); 59659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[12] + p2[12]; 59759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[13] + p2[13]; 59859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 59959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word >> 24) & 0xFF; 60059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 60159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 60259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[8] + p2[8]; 60359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[9] + p2[9]; 60459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 60559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word >> 16) & 0xFF; 60659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 60759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 60859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[4] + p2[4]; 60959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[5] + p2[5]; 61059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 61159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word >> 8) & 0xFF; 61259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 61359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 61459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[1] + p2[1]; 61559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[0] + p2[0]; 61659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += refwx4; 61759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += refwx4; 61859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += tmp2; 61959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = (cur_word & 0xFF); 62059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp += 2; 62159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP2_SUB_SAD(sad, tmp, tmp2);; 62259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 62359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (--j); 62459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 62559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 62659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 62759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sadstar += madstar; 62859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > sadstar - nrmlz_th[i] || sad > (Int)((ULong)dmin_rx >> 16)) 62959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 63059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 65536; 63159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 63259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 63359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 63459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 63559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 63659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 63759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HP_HTFMyh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 63859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 63959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 64059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0, tmp, tmp2; 64159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *p1, *p2; 64259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 64359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int refwx4 = rx << 2; 64459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sadstar = 0, madstar; 64559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *nrmlz_th = (Int*) extra_info; 64659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *offsetRef = nrmlz_th + 32; 64759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong cur_word; 64859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 64959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong madstar = (ULong)dmin_rx >> 20; 65059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 65159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 65259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 65359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong blk -= 4; 65459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 65559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) /* 16 stages */ 65659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 65759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref + offsetRef[i]; 65859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = p1 + rx; 65959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong j = 4; 66059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong do 66159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 66259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cur_word = *((ULong*)(blk += 4)); 66359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[12]; 66459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[12]; 66559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 66659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 66759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 24) & 0xFF; 66859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 66959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[8]; 67059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[8]; 67159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 67259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 67359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 16) & 0xFF; 67459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 67559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[4]; 67659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[4]; 67759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 67859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 67959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 8) & 0xFF; 68059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 68159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[0]; 68259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += refwx4; 68359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p2[0]; 68459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += refwx4; 68559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 68659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 68759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word & 0xFF); 68859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 68959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 69059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (--j); 69159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 69259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 69359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sadstar += madstar; 69459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > sadstar - nrmlz_th[i] || sad > (Int)((ULong)dmin_rx >> 16)) 69559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 69659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 65536; 69759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 69859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 69959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 70059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 70159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 70259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 70359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_MB_HP_HTFMxh(UChar *ref, UChar *blk, Int dmin_rx, void *extra_info) 70459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 70559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 70659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0, tmp, tmp2; 70759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *p1; 70859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rx = dmin_rx & 0xFFFF; 70959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int refwx4 = rx << 2; 71059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sadstar = 0, madstar; 71159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *nrmlz_th = (Int*) extra_info; 71259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *offsetRef = nrmlz_th + 32; 71359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong cur_word; 71459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 71559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong madstar = (ULong)dmin_rx >> 20; 71659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 71759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB_CALL(); 71859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 71959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong blk -= 4; 72059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 72159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 16; i++) /* 16 stages */ 72259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 72359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref + offsetRef[i]; 72459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 72559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong j = 4;/* 4 lines */ 72659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong do 72759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 72859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cur_word = *((ULong*)(blk += 4)); 72959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[12]; 73059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[13]; 73159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 73259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 73359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 24) & 0xFF; 73459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 73559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[8]; 73659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[9]; 73759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 73859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 73959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 16) & 0xFF; 74059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 74159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[4]; 74259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[5]; 74359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 74459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 74559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word >> 8) & 0xFF; 74659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 74759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = p1[0]; 74859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 = p1[1]; 74959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += refwx4; 75059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp++; 75159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp2 += tmp; 75259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (cur_word & 0xFF); 75359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad = INTERP1_SUB_SAD(sad, tmp, tmp2);; 75459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 75559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (--j); 75659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 75759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_MB(); 75859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 75959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sadstar += madstar; 76059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > sadstar - nrmlz_th[i] || sad > (Int)((ULong)dmin_rx >> 16)) 76159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 76259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 65536; 76359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 76459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 76559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 76659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 76759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 76859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 76959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* HTFM */ 77059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 77159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_INTER4V 77259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*================================================================== 77359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: SAD_Blk_HalfPel_C 77459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 04/30/2001 77559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Compute SAD 16x16 between blk and ref in halfpel 77659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong resolution, 77759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Changes: 77859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ==================================================================*/ 77959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* One component is half-pel */ 78059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int SAD_Blk_HalfPel_C(UChar *ref, UChar *blk, Int dmin, Int width, Int rx, Int xh, Int yh, void *extra_info) 78159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 78259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j; 78359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int sad = 0; 78459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *kk, *p1, *p2, *p3, *p4; 78559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int temp; 78659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 78759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(extra_info); 78859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 78959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_BLK_CALL(); 79059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 79159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (xh && yh) 79259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 79359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 79459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = ref + xh; 79559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 = ref + yh * rx; 79659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 = ref + yh * rx + xh; 79759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 79859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 79959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 8; i++) 80059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 80159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 8; j++) 80259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 80359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 80459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + p3[j] + p4[j] + 2) >> 2) - kk[j]; 80559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 80659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 80759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 80859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_BLK(); 80959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 81059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > dmin) 81159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 81259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 81359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += rx; 81459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p3 += rx; 81559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += rx; 81659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p4 += rx; 81759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk += width; 81859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 81959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 82059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 82159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 82259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 82359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 = ref; 82459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 = ref + xh + yh * rx; /* either left/right or top/bottom pixel */ 82559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 82659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk = blk; 82759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 82859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 8; i++) 82959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 83059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < 8; j++) 83159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 83259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 83359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = ((p1[j] + p2[j] + 1) >> 1) - kk[j]; 83459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong sad += PV_ABS(temp); 83559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 83659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 83759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong NUM_SAD_HP_BLK(); 83859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 83959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (sad > dmin) 84059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 84159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p1 += rx; 84259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong p2 += rx; 84359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong kk += width; 84459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 84559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return sad; 84659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 84759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 84859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* NO_INTER4V */ 84959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 85059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus 85159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 85259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 85359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 85459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 85559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 856