motion_comp.cpp revision 59f566c4ec3dfc097ad8163523e522280b27e5c3
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#include "mp4lib_int.h" 1959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4enc_lib.h" 2059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 2159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//const static Int roundtab4[] = {0,1,1,1}; 2259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//const static Int roundtab8[] = {0,0,1,1,1,1,1,2}; 2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong//const static Int roundtab12[] = {0,0,0,1,1,1,1,1,1,1,2,2}; 2459f566c4ec3dfc097ad8163523e522280b27e5c3James Dongconst static Int roundtab16[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}; 2559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 2659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define FORWARD_MODE 1 2759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define BACKWARD_MODE 2 2859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define BIDIRECTION_MODE 3 2959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define DIRECT_MODE 4 3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus 3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dongextern "C" 3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*Function Prototype */ 3659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* no-edge padding */ 3759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int EncGetPredOutside(Int xpos, Int ypos, UChar *c_prev, UChar *rec, 3859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int width, Int height, Int rnd1); 3959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong void Copy_MB_from_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width); 4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong void Copy_B_from_Vop(UChar *comp, Int cChan[], Int width); 4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong void Copy_MB_into_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width); 4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong void Copy_B_into_Vop(UChar *comp, Int cChan[], Int width); 4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong void get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v, 4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Short mb[6][64], Int lx, Int lx_uv); 4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int GetPredAdvBy0x0( 4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_prev, /* i */ 4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *pred_block, /* i */ 5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd1 /* i */ 5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ); 5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int GetPredAdvBy0x1( 5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_prev, /* i */ 5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *pred_block, /* i */ 5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd1 /* i */ 5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ); 6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int GetPredAdvBy1x0( 6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_prev, /* i */ 6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *pred_block, /* i */ 6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd1 /* i */ 6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ); 6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int GetPredAdvBy1x1( 6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_prev, /* i */ 7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *pred_block, /* i */ 7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd1 /* i */ 7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ); 7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong static Int(*const GetPredAdvBTable[2][2])(UChar*, UChar*, Int, Int) = 7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong {&GetPredAdvBy0x0, &GetPredAdvBy0x1}, 7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong {&GetPredAdvBy1x0, &GetPredAdvBy1x1} 7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong }; 8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef __cplusplus 8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : getMotionCompensatedMB( ) */ 8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 4/17/2001 */ 9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Get the motion compensate block into video->predictionMB */ 9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* and generate video->predictionErrorMB */ 9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* modified from MBMotionComp() function in the decoder */ 9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 9759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 9859f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid getMotionCompensatedMB(VideoEncData *video, Int ind_x, Int ind_y, Int offset) 9959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 10059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vop *prevVop = video->forwardRefVop; //reference frame 10159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vop *currVop = video->currVop; 10259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int mbnum = video->mbnum; //mb index 10359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong MOT *mot = video->mot[mbnum]; 10459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int ypos, xpos; 10559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_prev, *cu_prev, *cv_prev; 10659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_rec, *cu_rec, *cv_rec; 10759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int height, pitch, pitch_uv, height_uv; 10859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int mode = video->headerInfo.Mode[mbnum]; /* get mode */ 10959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int dx, dy; 11059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int xpred, ypred; 11159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int xsum, ysum; 11259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int round1; 11359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(offset); 11559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong round1 = (Int)(1 - video->currVop->roundingType); 11759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pitch = currVop->pitch; 11959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong height = currVop->height; 12059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pitch_uv = pitch >> 1; 12159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong height_uv = height >> 1; 12259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 12359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypos = ind_y << 4 ; 12459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpos = ind_x << 4 ; 12559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 12659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec = video->predictedMB; 12759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cu_rec = video->predictedMB + 256; 12859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cv_rec = video->predictedMB + 264; 12959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (mode == MODE_INTER || mode == MODE_INTER_Q) 13159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 13259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Motion vector in x direction */ 13359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dx = mot[0].x; 13459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dy = mot[0].y; 13559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev = prevVop->yChan; 13759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpred = (xpos << 1) + dx ; 13959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred = (ypos << 1) + dy ; 14059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Call function that performs luminance prediction */ 14259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EncPrediction_INTER(xpred, ypred, c_prev, c_rec, 14359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pitch, round1); 14459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((dx & 3) == 0) dx = dx >> 1; 14659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else dx = (dx >> 1) | 1; 14759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((dy & 3) == 0) dy = dy >> 1; 14959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else dy = (dy >> 1) | 1; 15059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpred = xpos + dx; 15259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred = ypos + dy; 15359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cu_prev = prevVop->uChan; 15559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cv_prev = prevVop->vChan; 15659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec, 15859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pitch_uv, (currVop->width) >> 1, height_uv, round1); 15959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_INTER4V 16159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (mode == MODE_INTER4V) 16259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 16359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev = prevVop->yChan; 16459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cu_prev = prevVop->uChan; 16559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cv_prev = prevVop->vChan; 16659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 16759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EncPrediction_INTER4V(xpos, ypos, mot, c_prev, c_rec, 16859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pitch, round1); 16959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xsum = mot[1].x + mot[2].x + mot[3].x + mot[4].x; 17159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ysum = mot[1].y + mot[2].y + mot[3].y + mot[4].y; 17259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dx = PV_SIGN(xsum) * (roundtab16[(PV_ABS(xsum)) & 0xF] + 17459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (((PV_ABS(xsum)) >> 4) << 1)); 17559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dy = PV_SIGN(ysum) * (roundtab16[(PV_ABS(ysum)) & 0xF] + 17659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (((PV_ABS(ysum)) >> 4) << 1)); 17759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred = ypos + dy; 17959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpred = xpos + dx; 18059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 18159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec, 18259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pitch_uv, (currVop->width) >> 1, height_uv, round1); 18359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 18459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 18559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 18659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 18759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ;//printf("Error, MODE_SKIPPED is not decided yet!\n"); 18859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 18959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 19059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return ; 19159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 19259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 19359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*************************************************************************** 19459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: EncPrediction_INTER 19559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 04/17/2001 19659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Get predicted area for luminance and compensate with the residue. 19759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Modified from luminance_pred_mode_inter() in decoder. 19859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/ 19959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 20059f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid EncPrediction_INTER( 20159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int xpred, /* i */ 20259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int ypred, /* i */ 20359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_prev, /* i */ 20459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_rec, /* i */ 20559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 20659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int round1 /* i */ 20759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong) 20859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 20959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev += (xpred >> 1) + ((ypred >> 1) * lx); 21059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1); 21259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev += B_SIZE; 21459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec += B_SIZE; 21559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1); 21759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev += (lx << 3) - B_SIZE; 21959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec += (16 << 3) - B_SIZE; /* padding */ 22059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1); 22259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev += B_SIZE; 22459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec += B_SIZE; 22559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1); 22759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return; 22959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 23059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 23159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_INTER4V 23259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*************************************************************************** 23359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: EncPrediction_INTER4V 23459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 04/17/2001 23559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Get predicted area for luminance and compensate with the residue. 23659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Modified from luminance_pred_mode_inter4v() in decoder. 23759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/ 23859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 23959f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid EncPrediction_INTER4V( 24059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int xpos, /* i */ 24159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int ypos, /* i */ 24259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong MOT *mot, /* i */ 24359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_prev, /* i */ 24459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *c_rec, /* i */ 24559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 24659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int round1 /* i */ 24759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong) 24859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 24959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int ypred, xpred; 25059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpred = (Int)((xpos << 1) + mot[1].x); 25259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred = (Int)((ypos << 1) + mot[1].y); 25359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx), 25559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec, lx, round1); 25659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec += B_SIZE; 25859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpred = (Int)(((xpos + B_SIZE) << 1) + mot[2].x); 26059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred = (Int)((ypos << 1) + mot[2].y); 26159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx), 26359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec, lx, round1); 26459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec += (16 << 3) - B_SIZE; /* padding */ 26659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpred = (Int)((xpos << 1) + mot[3].x); 26859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred = (Int)(((ypos + B_SIZE) << 1) + mot[3].y); 26959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx), 27159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec, lx, round1); 27259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec += B_SIZE; 27459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xpred = (Int)(((xpos + B_SIZE) << 1) + mot[4].x); 27659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred = (Int)(((ypos + B_SIZE) << 1) + mot[4].y); 27759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx), 27959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_rec, lx, round1); 28059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return; 28259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 28359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* NO_INTER4V */ 28459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*************************************************************************** 28659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: EncPrediction_Chrom 28759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 04/17/2001 28859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Get predicted area for chrominance and compensate with the residue. 28959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Modified from chrominance_pred() in decoder. 29059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/ 29159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29259f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid EncPrediction_Chrom( 29359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int xpred, /* i */ 29459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int ypred, /* i */ 29559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *cu_prev, /* i */ 29659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *cv_prev, /* i */ 29759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *cu_rec, 29859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *cv_rec, 29959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, 30059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int width_uv, /* i */ 30159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int height_uv, /* i */ 30259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int round1 /* i */ 30359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong) 30459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 30559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* check whether the MV points outside the frame */ 30659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Compute prediction for Chrominance b block (block[4]) */ 30759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (xpred >= 0 && xpred <= ((width_uv << 1) - (2*B_SIZE)) && ypred >= 0 && 30859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ypred <= ((height_uv << 1) - (2*B_SIZE))) 30959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 31059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*****************************/ 31159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* (x,y) is inside the frame */ 31259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*****************************/ 31359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Compute prediction for Chrominance b (block[4]) */ 31559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](cu_prev + (xpred >> 1) + ((ypred >> 1)*lx), 31659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cu_rec, lx, round1); 31759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Compute prediction for Chrominance r (block[5]) */ 31959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypred&1][xpred&1](cv_prev + (xpred >> 1) + ((ypred >> 1)*lx), 32059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cv_rec, lx, round1); 32159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 32259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 32359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 32459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /******************************/ 32559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* (x,y) is outside the frame */ 32659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /******************************/ 32759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 32859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Compute prediction for Chrominance b (block[4]) */ 32959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EncGetPredOutside(xpred, ypred, 33059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cu_prev, cu_rec, 33159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong width_uv, height_uv, round1); 33259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 33359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Compute prediction for Chrominance r (block[5]) */ 33459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EncGetPredOutside(xpred, ypred, 33559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong cv_prev, cv_rec, 33659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong width_uv, height_uv, round1); 33759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 33859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 33959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return; 34059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 34159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*************************************************************************** 34259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: GetPredAdvancedB 34359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 04/17/2001 34459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: Get predicted area (block) and compensate with the residue. 34559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong - modified from GetPredAdvancedBAdd in decoder. 34659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Intput/Output: 34759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Modified: 34859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong***************************************************************************/ 34959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35059f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy0x0( 35159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *prev, /* i */ 35259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *rec, /* i */ 35359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 35459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd /* i */ 35559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong) 35659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 35759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i; /* loop variable */ 35859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong pred_word, word1, word2; 35959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int tmp; 36059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong OSCL_UNUSED_ARG(rnd); 36259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* initialize offset to adjust pixel counter */ 36459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* the next row; full-pel resolution */ 36559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (ULong)prev & 0x3; 36759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (tmp == 0) /* word-aligned */ 36959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 37059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec -= 16; /* preset */ 37159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= lx; 37259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 37359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 8; i > 0; i--) 37459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 37559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 16)) = *((ULong*)(prev += lx)); 37659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec + 4)) = *((ULong*)(prev + 4)); 37759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 37859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 37959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 38059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 1) /* first position */ 38159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 38259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev--; /* word-aligned */ 38359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec -= 16; /* preset */ 38459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= lx; 38559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 38659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 8; i > 0; i--) 38759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 38859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */ 38959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */ 39059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 8; /* 0 b4 b3 b2 */ 39159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pred_word = word1 | (word2 << 24); /* b5 b4 b3 b2 */ 39259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 16)) = pred_word; 39359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */ 39559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 8; /* 0 b8 b7 b6 */ 39659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pred_word = word2 | (word1 << 24); /* b9 b8 b7 b6 */ 39759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec + 4)) = pred_word; 39859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 39959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 40059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 40159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 40259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 2) /* second position */ 40359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 40459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 2; /* word1-aligned */ 40559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec -= 16; /* preset */ 40659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= lx; 40759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 40859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 8; i > 0; i--) 40959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 41059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */ 41159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */ 41259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 16; /* 0 0 b4 b3 */ 41359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pred_word = word1 | (word2 << 16); /* b6 b5 b4 b3 */ 41459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 16)) = pred_word; 41559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */ 41759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 16; /* 0 0 b8 b7 */ 41859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pred_word = word2 | (word1 << 16); /* b10 b9 b8 b7 */ 41959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec + 4)) = pred_word; 42059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 42159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 42259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 42359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 42459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* third position */ 42559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 42659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 3; /* word1-aligned */ 42759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec -= 16; /* preset */ 42859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= lx; 42959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 43059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 8; i > 0; i--) 43159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 43259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */ 43359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */ 43459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 24; /* 0 0 0 b4 */ 43559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pred_word = word1 | (word2 << 8); /* b7 b6 b5 b4 */ 43659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 16)) = pred_word; 43759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 43859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */ 43959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 24; /* 0 0 0 b8 */ 44059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong pred_word = word2 | (word1 << 8); /* b11 b10 b9 b8 */ 44159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec + 4)) = pred_word; 44259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 44359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 44459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 44559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 44659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 44759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 44859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/**************************************************************************/ 44959f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy0x1( 45059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *prev, /* i */ 45159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *rec, /* i */ 45259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 45359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd1 /* i */ 45459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong) 45559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 45659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i; /* loop variable */ 45759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset; 45859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong word1, word2, word3, word12; 45959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int tmp; 46059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong mask; 46159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 46259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* initialize offset to adjust pixel counter */ 46359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* the next row; full-pel resolution */ 46459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong offset = lx - B_SIZE; /* offset for prev */ 46559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 46659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Branch based on pixel location (half-pel or full-pel) for x and y */ 46759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec -= 12; /* preset */ 46859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 46959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (ULong)prev & 3; 47059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask = 254; 47159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask |= (mask << 8); 47259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask |= (mask << 16); /* 0xFEFEFEFE */ 47359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 47459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (tmp == 0) /* word-aligned */ 47559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 47659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 47759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 47859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 47959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 48059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b4 b3 b2 b1 */ 48159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */ 48259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 8); /* 0 b4 b3 b2 */ 48359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 24); /* b5 b4 b3 b2 */ 48459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12 48559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 48659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 48759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 48859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 48959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 49059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 49159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 49259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 49359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */ 49459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 8); /* 0 b8 b7 b6 */ 49559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 24); /* b9 b8 b7 b6 */ 49659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 | word12; 49759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 49859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 49959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 50059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 50159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 50259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 50359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 50459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 50559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 50659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 50759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 50859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 50959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* rnd1 == 0 */ 51059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 51159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 51259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 51359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b4 b3 b2 b1 */ 51459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 51559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */ 51659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 8); /* 0 b4 b3 b2 */ 51759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 24); /* b5 b4 b3 b2 */ 51859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12 51959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 52059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 52159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 52259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 52359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 52459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 52559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 52659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 52759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */ 52859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 8); /* 0 b8 b7 b6 */ 52959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 24); /* b9 b8 b7 b6 */ 53059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 & word12; 53159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 53259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 53359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 53459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 53559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 53659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 53759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 53859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 53959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 54059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 54159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 54259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } /* rnd1 */ 54359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 54459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 1) 54559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 54659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev--; /* word-aligned */ 54759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 54859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 54959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 55059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 55159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b3 b2 b1 b0 */ 55259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */ 55359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 8); /* 0 b3 b2 b1 */ 55459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 16; /* 0 0 b3 b2 */ 55559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 24); /* b4 b3 b2 b1 */ 55659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 |= (word2 << 16); /* b5 b4 b3 b2 */ 55759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12 55859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 55959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 56059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 56159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 56259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 56359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 56459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 56559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 56659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */ 56759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 8); /* 0 b7 b6 b5 */ 56859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 16; /* 0 0 b7 b6 */ 56959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 24); /* b8 b7 b6 b5 */ 57059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 |= (word1 << 16); /* b9 b8 b7 b6 */ 57159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word2&word12 57259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 57359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 57459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 57559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 57659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 57759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 57859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 57959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 58059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 58159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 58259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 58359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 58459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* rnd1 = 0 */ 58559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 58659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 58759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 58859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b3 b2 b1 b0 */ 58959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 59059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */ 59159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 8); /* 0 b3 b2 b1 */ 59259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 16; /* 0 0 b3 b2 */ 59359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 24); /* b4 b3 b2 b1 */ 59459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 |= (word2 << 16); /* b5 b4 b3 b2 */ 59559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word12; 59659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 59759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 59859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 59959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 60059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 60159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 60259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 60359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 60459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */ 60559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 8); /* 0 b7 b6 b5 */ 60659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 16; /* 0 0 b7 b6 */ 60759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 24); /* b8 b7 b6 b5 */ 60859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 |= (word1 << 16); /* b9 b8 b7 b6 */ 60959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 & word12; 61059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 61159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 61259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 61359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 61459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 61559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 61659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 61759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 61859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 61959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 62059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 62159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } /* rnd1 */ 62259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 62359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 2) 62459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 62559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 2; /* word-aligned */ 62659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 62759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 62859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 62959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 63059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */ 63159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */ 63259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 16); /* 0 0 b2 b1 */ 63359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 24; /* 0 0 0 b2 */ 63459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 16); /* b4 b3 b2 b1 */ 63559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 |= (word2 << 8); /* b5 b4 b3 b2 */ 63659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12 63759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 63859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 63959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 64059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 64159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 64259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 64359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 64459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 64559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */ 64659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 16); /* 0 0 b6 b5 */ 64759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 24; /* 0 0 0 b6 */ 64859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 16); /* b8 b7 b6 b5 */ 64959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 |= (word1 << 8); /* b9 b8 b7 b6 */ 65059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12 65159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 65259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 65359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 65459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 65559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 65659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 65759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 65859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 65959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 66059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 66159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 66259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* rnd1 == 0 */ 66359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 66459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 66559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 66659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */ 66759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */ 66859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 16); /* 0 0 b2 b1 */ 66959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 24; /* 0 0 0 b2 */ 67059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 16); /* b4 b3 b2 b1 */ 67159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 |= (word2 << 8); /* b5 b4 b3 b2 */ 67259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12 67359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 67459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 67559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 67659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 67759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 67859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 67959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 68059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 68159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */ 68259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 16); /* 0 0 b6 b5 */ 68359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 24; /* 0 0 0 b6 */ 68459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 16); /* b8 b7 b6 b5 */ 68559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 |= (word1 << 8); /* b9 b8 b7 b6 */ 68659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12 68759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 68859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 68959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 69059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 69159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 69259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 69359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 69459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 69559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 69659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 69759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 69859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 69959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* tmp = 3 */ 70059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 70159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 3; /* word-aligned */ 70259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 70359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 70459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 70559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 70659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */ 70759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */ 70859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 24); /* 0 0 0 b1 */ 70959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 8); /* b4 b3 b2 b1 */ 71059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word2; 71159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12 71259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 71359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 71459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 71559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 71659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 71759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 71859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 71959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 72059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */ 72159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 24); /* 0 0 0 b5 */ 72259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 8); /* b8 b7 b6 b5 */ 72359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word1; /* b9 b8 b7 b6 */ 72459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12 72559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 72659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 72759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 72859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 72959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 73059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 73159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 73259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 73359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 73459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 73559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 73659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 73759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 73859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 73959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 74059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */ 74159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */ 74259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word1 >> 24); /* 0 0 0 b1 */ 74359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word2 << 8); /* b4 b3 b2 b1 */ 74459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word2; 74559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12 74659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 74759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 74859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 74959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 75059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word12 >> 1); 75159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 75259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; /* write 4 pixels */ 75359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 75459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */ 75559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = (word2 >> 24); /* 0 0 0 b5 */ 75659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 |= (word1 << 8); /* b8 b7 b6 b5 */ 75759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word1; /* b9 b8 b7 b6 */ 75859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12 75959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 76059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 76159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 76259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 1; 76359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 + (word12 >> 1); 76459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 += word3; 76559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word2; /* write 4 pixels */ 76659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 76759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 76859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 76959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 77059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 77159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 77259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 77359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/**************************************************************************/ 77459f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy1x0( 77559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *prev, /* i */ 77659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *rec, /* i */ 77759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 77859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd1 /* i */ 77959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong) 78059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 78159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i; /* loop variable */ 78259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset; 78359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong word1, word2, word3, word12, word22; 78459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int tmp; 78559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong mask; 78659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 78759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* initialize offset to adjust pixel counter */ 78859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* the next row; full-pel resolution */ 78959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong offset = lx - B_SIZE; /* offset for prev */ 79059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 79159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Branch based on pixel location (half-pel or full-pel) for x and y */ 79259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec -= 12; /* preset */ 79359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 79459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (ULong)prev & 3; 79559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask = 254; 79659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask |= (mask << 8); 79759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask |= (mask << 16); /* 0xFEFEFEFE */ 79859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 79959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (tmp == 0) /* word-aligned */ 80059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 80159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 4; 80259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 80359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 80459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 80559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 80659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); 80759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 80859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2 80959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 81059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 81159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 81259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 81359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 81459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 81559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; 81659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); 81759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 81859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2 81959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 82059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 82159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 82259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 82359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 82459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 82559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 82659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 82759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 82859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 82959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 83059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 83159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* rnd1 = 0 */ 83259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 83359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 83459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 83559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); 83659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 83759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word2; /* rnd1 = 0; */ 83859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 83959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 84059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 84159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 84259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 84359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 84459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word1; 84559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); 84659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 84759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word2; /* rnd1 = 0; */ 84859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 84959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 85059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 85159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 85259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 85359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 85459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 85559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 85659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 85759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 85859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 85959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 86059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 86159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 1) 86259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 86359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev--; /* word-aligned */ 86459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 86559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 86659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 86759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 86859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */ 86959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 87059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 87159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */ 87259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 87359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 8; /* 0 b4 b3 b2 */ 87459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 >>= 8; 87559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */ 87659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = word22 | (word2 << 24); 87759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word12 | word22; 87859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 87959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 &= mask; 88059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 88159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 1; 88259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 + (word22 >> 1); 88359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 += word3; 88459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word12; 88559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 88659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */ 88759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 88859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 8; /* 0 b8 b7 b6 */ 88959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 8; 89059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */ 89159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 | (word22 << 24); 89259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word2; 89359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 89459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 89559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 89659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 89759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 89859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 89959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 90059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 90159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 90259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 90359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 90459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* rnd1 = 0 */ 90559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 90659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 90759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 90859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */ 90959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 91059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 91159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */ 91259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 91359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 8; /* 0 b4 b3 b2 */ 91459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 >>= 8; 91559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */ 91659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = word22 | (word2 << 24); 91759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word12 & word22; 91859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 91959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 &= mask; 92059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 92159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 1; 92259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 + (word22 >> 1); 92359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 += word3; 92459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word12; 92559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 92659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */ 92759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 92859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 8; /* 0 b8 b7 b6 */ 92959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 8; 93059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */ 93159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 | (word22 << 24); 93259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word2; 93359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 93459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 93559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 93659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 93759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 93859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 93959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 94059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 94159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 94259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 94359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 94459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 94559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 2) 94659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 94759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 2; /* word-aligned */ 94859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 94959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 95059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 95159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 95259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */ 95359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 95459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 95559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */ 95659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 95759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 16; /* 0 0 b4 b3 */ 95859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 >>= 16; 95959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */ 96059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = word22 | (word2 << 16); 96159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word12 | word22; 96259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 96359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 &= mask; 96459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 96559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 1; 96659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 + (word22 >> 1); 96759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 += word3; 96859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word12; 96959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 97059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */ 97159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 97259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 16; /* 0 0 b8 b7 */ 97359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 16; 97459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */ 97559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 | (word22 << 16); 97659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word2; 97759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 97859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 97959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 98059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 98159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 98259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 98359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 98459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 98559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 98659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 98759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 98859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* rnd1 = 0 */ 98959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 99059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 99159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 99259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */ 99359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 99459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 99559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */ 99659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 99759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 16; /* 0 0 b4 b3 */ 99859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 >>= 16; 99959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */ 100059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = word22 | (word2 << 16); 100159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word12 & word22; 100259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 100359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 &= mask; 100459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 100559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 1; 100659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 + (word22 >> 1); 100759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 += word3; 100859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word12; 100959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 101059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */ 101159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 101259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 16; /* 0 0 b8 b7 */ 101359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 16; 101459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */ 101559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 | (word22 << 16); 101659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word2; 101759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 101859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 101959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 102059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 102159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 102259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 102359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 102459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 102559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 102659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 102759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 102859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 102959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 103059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* tmp == 3 */ 103159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 103259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 3; /* word-aligned */ 103359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (rnd1 == 1) 103459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 103559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 103659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 103759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */ 103859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 103959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 104059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */ 104159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 104259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 24; /* 0 0 0 b4 */ 104359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 >>= 24; 104459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */ 104559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = word22 | (word2 << 8); 104659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word12 | word22; 104759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 104859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 &= mask; 104959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 105059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 1; 105159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 + (word22 >> 1); 105259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 += word3; 105359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word12; 105459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 105559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */ 105659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 105759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 24; /* 0 0 0 b8 */ 105859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 24; 105959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */ 106059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 | (word22 << 8); 106159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 | word2; 106259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 106359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 106459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 106559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 106659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 106759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 106859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 106959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 107059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 107159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 107259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 107359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* rnd1 = 0 */ 107459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 107559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 107659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 107759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */ 107859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 107959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 108059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */ 108159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = *((ULong*)(prev + lx)); 108259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 24; /* 0 0 0 b4 */ 108359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 >>= 24; 108459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */ 108559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = word22 | (word2 << 8); 108659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word12 & word22; 108759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 &= mask; 108859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 &= mask; 108959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 109059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 >>= 1; 109159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = word12 + (word22 >> 1); 109259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 += word3; 109359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 12)) = word12; 109459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 109559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */ 109659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word22 = *((ULong*)(prev + lx)); 109759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 24; /* 0 0 0 b8 */ 109859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 >>= 24; 109959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */ 110059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 = word2 | (word22 << 8); 110159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 = word1 & word2; 110259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 &= mask; 110359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word2 &= mask; 110459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word3 &= (~mask); /* 0x1010101, check last bit */ 110559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 >>= 1; 110659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 = word1 + (word2 >> 1); 110759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong word1 += word3; 110859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = word1; 110959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 111059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 111159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 111259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } /* rnd */ 111359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } /* tmp */ 111459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 111559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 111659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/**********************************************************************************/ 111759f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt GetPredAdvBy1x1( 111859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *prev, /* i */ 111959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *rec, /* i */ 112059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx, /* i */ 112159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd1 /* i */ 112259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong) 112359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 112459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i; /* loop variable */ 112559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset; 112659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong x1, x2, x1m, x2m, y1, y2, y1m, y2m; /* new way */ 112759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int tmp; 112859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int rnd2; 112959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong mask; 113059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 113159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* initialize offset to adjust pixel counter */ 113259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* the next row; full-pel resolution */ 113359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong offset = lx - B_SIZE; /* offset for prev */ 113459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 113559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rnd2 = rnd1 + 1; 113659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rnd2 |= (rnd2 << 8); 113759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rnd2 |= (rnd2 << 16); 113859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 113959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask = 0x3F; 114059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask |= (mask << 8); 114159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mask |= (mask << 16); /* 0x3f3f3f3f */ 114259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 114359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (ULong)prev & 3; 114459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 114559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec -= 4; /* preset */ 114659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 114759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (tmp == 0) /* word-aligned */ 114859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 114959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 115059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 115159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */ 115259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */ 115359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */ 115459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */ 115559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 115659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m = (x1 >> 2) & mask; /* zero out last 2 bits */ 115759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 115859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = x1 ^(x1m << 2); 115959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 116059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += x2m; 116159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += x2; 116259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 116359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 116459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m = (y1 >> 2) & mask; /* zero out last 2 bits */ 116559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 116659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = y1 ^(y1m << 2); 116759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 116859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += y2m; 116959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += y2; 117059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 117159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 117259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 117359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */ 117459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */ 117559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 117659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 117759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 117859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 117959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m += y2m; 118059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 += y2; 118159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 118259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 118359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* now operate on x1m, x1, y1m, y1, x2m, x2 */ 118459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */ 118559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */ 118659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */ 118759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1, y1, x2 */ 118859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 118959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = x1m >> 8; 119059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = x1 >> 8; 119159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */ 119259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 |= (y1 << 24); 119359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += y2m; /* a3+b3+a4+b4, ....., a0+b0+a1+b1 */ 119459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += y2; 119559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += rnd2; 119659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 &= (mask << 2); 119759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += (x1 >> 2); 119859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = x1m; /* save x1m */ 119959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 120059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = y1m >> 8; 120159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y1 >> 8; 120259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */ 120359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 |= (x2 << 24); 120459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += y2m; /* a7+b7+a8+b8, ....., a4+b4+a5+b5 */ 120559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += y2; 120659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += rnd2; 120759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 &= (mask << 2); 120859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += (y1 >> 2); 120959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = y1m; /* save y1m */ 121059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 121159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec += 8; 121259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 121359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 121459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 121559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 121659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 121759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 1) 121859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 121959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev--; /* to word-aligned */ 122059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 122159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 122259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */ 122359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */ 122459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */ 122559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */ 122659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 122759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m = (x1 >> 2) & mask; /* zero out last 2 bits */ 122859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 122959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = x1 ^(x1m << 2); 123059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 123159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += x2m; 123259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += x2; 123359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 123459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 123559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m = (y1 >> 2) & mask; /* zero out last 2 bits */ 123659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 123759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = y1 ^(y1m << 2); 123859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 123959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += y2m; 124059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += y2; 124159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 124259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 124359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 124459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */ 124559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */ 124659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 124759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 124859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 124959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 125059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m += y2m; 125159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 += y2; 125259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 125359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 125459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* now operate on x1m, x1, y1m, y1, x2m, x2 */ 125559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */ 125659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */ 125759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */ 125859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1, y1, x2 */ 125959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 126059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m >>= 8 ; 126159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 >>= 8; 126259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */ 126359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 |= (y1 << 24); 126459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y1m << 16); 126559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = (y1 << 16); 126659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m |= (x1m >> 8); /* a5+b5, a4+b4, a3+b3, a2+b2 */ 126759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 |= (x1 >> 8); 126859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += rnd2; 126959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += y2m; /* a4+b4+a5+b5, ....., a1+b1+a2+b2 */ 127059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += y2; 127159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 &= (mask << 2); 127259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += (x1 >> 2); 127359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = x1m; /* save x1m */ 127459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 127559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m >>= 8; 127659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 >>= 8; 127759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */ 127859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 |= (x2 << 24); 127959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (x2m << 16); 128059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = (x2 << 16); 128159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m |= (y1m >> 8); /* a9+b9, a8+b8, a7+b7, a6+b6,*/ 128259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 |= (y1 >> 8); 128359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += rnd2; 128459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += y2m; /* a8+b8+a9+b9, ....., a5+b5+a6+b6 */ 128559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += y2; 128659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 &= (mask << 2); 128759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += (y1 >> 2); 128859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = y1m; /* save y1m */ 128959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 129059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec += 8; 129159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 129259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 129359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 129459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 129559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (tmp == 2) 129659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 129759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 2; /* to word-aligned */ 129859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 129959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 130059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */ 130159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */ 130259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */ 130359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */ 130459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 130559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m = (x1 >> 2) & mask; /* zero out last 2 bits */ 130659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 130759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = x1 ^(x1m << 2); 130859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 130959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += x2m; 131059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += x2; 131159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 131259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 131359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m = (y1 >> 2) & mask; /* zero out last 2 bits */ 131459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 131559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = y1 ^(y1m << 2); 131659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 131759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += y2m; 131859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += y2; 131959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 132059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 132159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 132259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */ 132359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */ 132459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 132559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 132659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 132759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 132859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m += y2m; 132959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 += y2; 133059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 133159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 133259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* now operate on x1m, x1, y1m, y1, x2m, x2 */ 133359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */ 133459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */ 133559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */ 133659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1, y1, x2 */ 133759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 133859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m >>= 16 ; 133959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 >>= 16; 134059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m |= (y1m << 16); /* a5+b5, a4+b4, a3+b3, a2+b2 */ 134159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 |= (y1 << 16); 134259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y1m << 8); 134359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = (y1 << 8); 134459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m |= (x1m >> 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */ 134559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 |= (x1 >> 8); 134659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += rnd2; 134759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += y2m; /* a5+b5+a6+b6, ....., a2+b2+a3+b3 */ 134859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += y2; 134959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 &= (mask << 2); 135059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += (x1 >> 2); 135159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = x1m; /* save x1m */ 135259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 135359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m >>= 16; 135459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 >>= 16; 135559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m |= (x2m << 16); /* a9+b9, a8+b8, a7+b7, a6+b6 */ 135659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 |= (x2 << 16); 135759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (x2m << 8); 135859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = (x2 << 8); 135959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m |= (y1m >> 8); /* a10+b10, a9+b9, a8+b8, a7+b7,*/ 136059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 |= (y1 >> 8); 136159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += rnd2; 136259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += y2m; /* a9+b9+a10+b10, ....., a6+b6+a7+b7 */ 136359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += y2; 136459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 &= (mask << 2); 136559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += (y1 >> 2); 136659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = y1m; /* save y1m */ 136759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 136859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec += 8; 136959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 137059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 137159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 137259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 137359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* tmp == 3 */ 137459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 137559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev -= 3; /* to word-aligned */ 137659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = B_SIZE; i > 0; i--) 137759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 137859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */ 137959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */ 138059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */ 138159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */ 138259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 138359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m = (x1 >> 2) & mask; /* zero out last 2 bits */ 138459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 138559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 = x1 ^(x1m << 2); 138659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 138759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += x2m; 138859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += x2; 138959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 139059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 139159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m = (y1 >> 2) & mask; /* zero out last 2 bits */ 139259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 139359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 = y1 ^(y1m << 2); 139459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 139559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += y2m; 139659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += y2; 139759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 139859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 139959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m, x2 free */ 140059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */ 140159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */ 140259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m = (x2 >> 2) & mask; 140359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2m = (y2 >> 2) & mask; 140459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 = x2 ^(x2m << 2); 140559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y2 = y2 ^(y2m << 2); 140659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2m += y2m; 140759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x2 += y2; 140859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y2m, y2 free */ 140959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 141059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* now operate on x1m, x1, y1m, y1, x2m, x2 */ 141159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */ 141259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */ 141359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */ 141459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* x1, y1, x2 */ 141559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 141659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m >>= 24 ; 141759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 >>= 24; 141859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m |= (y1m << 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */ 141959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 |= (y1 << 8); 142059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 142159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += y1m; /* a6+b6+a7+b7, ....., a3+b3+a4+b4 */ 142259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += y1; 142359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 += rnd2; 142459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1 &= (mask << 2); 142559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong x1m += (x1 >> 2); 142659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = x1m; /* save x1m */ 142759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 142859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m >>= 24; 142959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 >>= 24; 143059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m |= (x2m << 8); /* a10+b10, a9+b9, a8+b8, a7+b7 */ 143159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 |= (x2 << 8); 143259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += x2m; /* a10+b10+a11+b11, ....., a7+b7+a8+b8 */ 143359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += x2; 143459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 += rnd2; 143559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1 &= (mask << 2); 143659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong y1m += (y1 >> 2); 143759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(rec += 4)) = y1m; /* save y1m */ 143859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 143959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec += 8; 144059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong prev += offset; 144159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 144259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 144359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 144459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 144559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 144659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 144759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*============================================================================= 144859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function: EncGetPredOutside 144959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date: 04/17/2001 145059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Purpose: - modified from GetPredOutside in the decoder. 145159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Modified: 09/24/05 145259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong use the existing non-initialized padded region 145359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong=============================================================================*/ 145459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// not really needed since padding is included 145559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define PAD_CORNER { temp = *src; \ 145659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (temp<<8); \ 145759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (temp<<16); \ 145859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)dst) = temp; \ 145959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 146059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 146159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 146259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 146359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 146459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 146559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 146659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 146759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 146859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 146959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 147059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 147159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 147259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 147359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; } 147459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 147559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define PAD_ROW { temp = *((ULong*)src); \ 147659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp2 = *((ULong*)(src+4)); \ 147759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)dst) = temp; \ 147859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; \ 147959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 148059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; \ 148159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 148259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; \ 148359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 148459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; \ 148559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 148659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; \ 148759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 148859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; \ 148959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 149059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; \ 149159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 149259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp2; } 149359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 149459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define PAD_COL { temp = *src; temp |= (temp<<8); temp |= (temp<<16); \ 149559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)dst) = temp; \ 149659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 149759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \ 149859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 149959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 150059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \ 150159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 150259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 150359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \ 150459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 150559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 150659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \ 150759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 150859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 150959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \ 151059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 151159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 151259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \ 151359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 151459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; \ 151559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \ 151659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+=lx)) = temp; \ 151759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst+4)) = temp; } 151859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 151959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 152059f566c4ec3dfc097ad8163523e522280b27e5c3James DongInt EncGetPredOutside(Int xpos, Int ypos, UChar *c_prev, UChar *rec, 152159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int width, Int height, Int rnd1) 152259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 152359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int lx; 152459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *src, *dst; 152559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong temp, temp2; 152659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int xoffset; 152759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 152859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong lx = width + 16; /* only works for chroma */ 152959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 153059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (xpos < 0) 153159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 153259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (ypos < 0) /* pad top-left */ 153359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 153459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad corner */ 153559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev; 153659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = c_prev - (lx << 3) - 8; 153759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_CORNER 153859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 153959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad top */ 154059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = c_prev - (lx << 3); 154159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_ROW 154259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 154359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad left */ 154459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = c_prev - 8; 154559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_COL 154659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 154759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 154859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 154959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 155059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 155159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 155259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if ((ypos >> 1) < (height - 8)) /* pad left of frame */ 155359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 155459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad left */ 155559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev + (ypos >> 1) * lx; 155659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src - 8; 155759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_COL 155859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad extra row */ 155959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src += lx); 156059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (temp << 8); 156159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (temp << 16); 156259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 156359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst + 4)) = temp; 156459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 156559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 156659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 156759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 156859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 156959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 157059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* pad bottom-left */ 157159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 157259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad corner */ 157359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev + (height - 1) * lx; 157459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + lx - 8; 157559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_CORNER 157659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 157759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad bottom */ 157859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + lx; 157959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_ROW 158059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 158159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad left */ 158259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src -= (lx << 3); 158359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src += lx; 158459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src - 8; 158559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_COL 158659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 158759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 158859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 158959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 159059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 159159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 159259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 159359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if ((xpos >> 1) < (width - 8)) 159459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 159559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (ypos < 0) /* pad top of frame */ 159659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 159759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xoffset = (xpos >> 1) & 0x3; 159859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev + (xpos >> 1) - xoffset; 159959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src - (lx << 3); 160059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_ROW 160159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (xoffset || (xpos&1)) 160259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 160359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *((ULong*)(src + 8)); 160459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src - (lx << 3) + 8; 160559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)dst) = temp; 160659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 160759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 160859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 160959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 161059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 161159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 161259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 161359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 161459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 161559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 161659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 161759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 161859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 161959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 162059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* pad bottom of frame */ 162159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 162259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong xoffset = (xpos >> 1) & 0x3; 162359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev + (xpos >> 1) - xoffset + (height - 1) * lx; 162459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + lx; 162559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_ROW 162659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (xoffset || (xpos&1)) 162759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 162859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *((ULong*)(src + 8)); 162959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + lx + 8; 163059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)dst) = temp; 163159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 163259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 163359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 163459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 163559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 163659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 163759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 163859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 163959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 164059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 164159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 164259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 164359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 164459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 164559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 164659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 164759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 164859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (ypos < 0) /* pad top-right */ 164959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 165059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad corner */ 165159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev + width - 1; 165259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src - (lx << 3) + 1; 165359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_CORNER 165459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 165559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad top */ 165659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src -= 7; 165759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src - (lx << 3); 165859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_ROW 165959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 166059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad left */ 166159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src += 7; 166259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + 1; 166359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_COL 166459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 166559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 166659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 166759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 166859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 166959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 167059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if ((ypos >> 1) < (height - B_SIZE)) /* pad right of frame */ 167159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 167259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad left */ 167359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev + (ypos >> 1) * lx + width - 1; 167459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + 1; 167559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_COL 167659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad extra row */ 167759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *(src += lx); 167859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (temp << 8); 167959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (temp << 16); 168059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst += lx)) = temp; 168159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)(dst + 4)) = temp; 168259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 168359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 168459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 168559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 168659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 168759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 168859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* pad bottom-right */ 168959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 169059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad left */ 169159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = c_prev + (height - 8) * lx + width - 1; 169259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + 1; 169359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_COL 169459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 169559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad corner */ 169659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + lx + 1; 169759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_CORNER 169859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 169959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* pad bottom */ 170059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src -= 7; 170159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = src + lx; 170259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PAD_ROW 170359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 170459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx), 170559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rec, lx, rnd1); 170659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 170759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return 1; 170859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 170959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 171059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 171159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 171259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ====================================================================== / 171359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function : Copy_MB_from_Vop() 171459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date : 04/17/2001 171559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ====================================================================== */ 171659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 171759f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid Copy_MB_from_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int pitch) 171859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 171959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int row, col, i; 172059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *src1, *src2; 172159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset = pitch - MB_SIZE; 172259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong temp; 172359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 172459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 4; i += 2) 172559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 172659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src1 = yChan[i]; 172759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src2 = yChan[i+1]; 172859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 172959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong row = B_SIZE; 173059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (row--) 173159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 173259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col = B_SIZE; 173359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (col) 173459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 173559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *((ULong*)comp); 173659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src1++ = (Int)(temp & 0xFF); 173759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src1++ = (Int)((temp >> 8) & 0xFF); 173859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src1++ = (Int)((temp >> 16) & 0xFF); 173959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src1++ = (Int)((temp >> 24) & 0xFF); 174059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += 4; 174159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col -= 4; 174259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 174359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col = B_SIZE; 174459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (col) 174559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 174659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *((ULong*)comp); 174759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src2++ = (Int)(temp & 0xFF); 174859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src2++ = (Int)((temp >> 8) & 0xFF); 174959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src2++ = (Int)((temp >> 16) & 0xFF); 175059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *src2++ = (Int)((temp >> 24) & 0xFF); 175159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += 4; 175259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col -= 4; 175359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 175459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += offset; 175559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 175659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 175759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return ; 175859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 175959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 176059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ====================================================================== / 176159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function : Copy_B_from_Vop() 176259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date : 04/17/2001 176359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/ ====================================================================== */ 176459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 176559f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid Copy_B_from_Vop(UChar *comp, Int cChan[], Int pitch) 176659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 176759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int row, col; 176859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset = pitch - B_SIZE; 176959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong temp; 177059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 177159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong row = B_SIZE; 177259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (row--) 177359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 177459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col = B_SIZE; 177559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (col) 177659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 177759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = *((ULong*)comp); 177859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *cChan++ = (Int)(temp & 0xFF); 177959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *cChan++ = (Int)((temp >> 8) & 0xFF); 178059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *cChan++ = (Int)((temp >> 16) & 0xFF); 178159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *cChan++ = (Int)((temp >> 24) & 0xFF); 178259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += 4; 178359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col -= 4; 178459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 178559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += offset; 178659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 178759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 178859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 178959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ====================================================================== / 179059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function : Copy_MB_into_Vop() 179159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date : 04/17/2001 179259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong History : From decoder 179359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/ ====================================================================== */ 179459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 179559f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid Copy_MB_into_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int pitch) 179659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 179759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int row, col, i; 179859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *src1, *src2; 179959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset = pitch - MB_SIZE; 180059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar mask = 0xFF; 180159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int tmp; 180259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong temp; 180359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 180459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < 4; i += 2) 180559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 180659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src1 = yChan[i]; 180759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src2 = yChan[i+1]; 180859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 180959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong row = B_SIZE; 181059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (row--) 181159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 181259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col = B_SIZE; 181359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (col) 181459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 181559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src1++); 181659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 181759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = tmp << 24; 181859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src1++); 181959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 182059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (tmp << 16); 182159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src1++); 182259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 182359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (tmp << 8); 182459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src1++); 182559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 182659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= tmp; 182759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)comp) = temp; 182859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += 4; 182959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col -= 4; 183059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 183159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col = B_SIZE; 183259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (col) 183359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 183459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src2++); 183559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 183659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = tmp << 24; 183759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src2++); 183859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 183959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (tmp << 16); 184059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src2++); 184159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 184259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (tmp << 8); 184359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*src2++); 184459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 184559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= tmp; 184659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)comp) = temp; 184759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += 4; 184859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col -= 4; 184959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 185059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += offset; 185159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 185259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 185359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return ; 185459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 185559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 185659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 185759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ====================================================================== / 185859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Function : Copy_B_into_Vop() 185959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Date : 04/17/2001 186059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong History : From decoder 186159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/ ====================================================================== */ 186259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 186359f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid Copy_B_into_Vop(UChar *comp, Int cChan[], Int pitch) 186459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 186559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int row, col; 186659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset = pitch - B_SIZE; 186759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int tmp; 186859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar mask = 0xFF; 186959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ULong temp; 187059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 187159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong row = B_SIZE; 187259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (row--) 187359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 187459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col = B_SIZE; 187559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (col) 187659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 187759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*cChan++); 187859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 187959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp = tmp << 24; 188059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*cChan++); 188159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 188259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (tmp << 16); 188359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*cChan++); 188459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 188559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= (tmp << 8); 188659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp = (*cChan++); 188759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31)); 188859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong temp |= tmp; 188959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *((ULong*)comp) = temp; 189059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += 4; 189159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong col -= 4; 189259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 189359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong comp += offset; 189459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 189559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 189659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 189759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 189859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : get_MB( ) */ 189959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 10/03/2000 */ 190059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Copy 4 Y to reference frame */ 190159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 190259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 190359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 190459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 190559f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v, 190659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Short mb[6][64], Int lx, Int lx_uv) 190759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 190859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 190959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int i, j, count = 0, count1 = 0; 191059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int k1 = lx - MB_SIZE, k2 = lx_uv - B_SIZE; 191159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 191259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < B_SIZE; i++) 191359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 191459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < B_SIZE; j++) 191559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 191659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mb[0][count] = (Int)(*c_prev++); 191759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mb[4][count] = (Int)(*c_prev_u++); 191859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mb[5][count++] = (Int)(*c_prev_v++); 191959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 192059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 192159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < B_SIZE; j++) 192259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mb[1][count1++] = (Int)(*c_prev++); 192359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 192459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev += k1; 192559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev_u += k2; 192659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev_v += k2; 192759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 192859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 192959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 193059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 193159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong count = count1 = 0; 193259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (i = 0; i < B_SIZE; i++) 193359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 193459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < B_SIZE; j++) 193559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mb[2][count++] = (Int)(*c_prev++); 193659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 193759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong for (j = 0; j < B_SIZE; j++) 193859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong mb[3][count1++] = (Int)(*c_prev++); 193959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 194059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong c_prev += k1; 194159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 194259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 194359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 194459f566c4ec3dfc097ad8163523e522280b27e5c3James Dongvoid PutSkippedBlock(UChar *rec, UChar *prev, Int lx) 194559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 194659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *end; 194759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int offset = (lx - 8) >> 2; 194859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int *src, *dst; 194959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 195059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst = (Int*)rec; 195159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src = (Int*)prev; 195259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 195359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong end = prev + (lx << 3); 195459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 195559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong do 195659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 195759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *dst++ = *src++; 195859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong *dst++ = *src++; 195959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dst += offset; 196059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong src += offset; 196159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 196259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while ((UInt)src < (UInt)end); 196359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 196459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return ; 196559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 1966