📄 meutility.c
字号:
int blkHeight, int x, int y, int16 *blkSadsBuf){ int i, j; int blk[BLK_SIZE][BLK_SIZE]; int blkSad, totalSad; int16 *sadPtr; totalSad = 0; ref += (y >> 1) * w + (x >> 1); if (((x | y) & 1) == 0) { for (j = 0; j < blkHeight; j += BLK_SIZE) { sadPtr = blkSadsBuf; for (i = 0; i < blkWidth; i += BLK_SIZE) { halfPixelDiff(orig + i, ref + 2 * i, w, blk); blkSad = simpleSad4x4(blk); totalSad += blkSad; *sadPtr ++ = (int16) blkSad; } blkSadsBuf += BLK_PER_MB; orig += BLK_SIZE*MBK_SIZE; ref += BLK_SIZE*2*w; } } else { int dx, dy; u_int8 *ref2; dx = x & 3; dy = y & 3; ref2 = ref; ref += bufOffs[dy][dx][0]; ref2 += bufOffs[dy][dx][1]; for (j = 0; j < blkHeight; j += BLK_SIZE) { sadPtr = blkSadsBuf; for (i = 0; i < blkWidth; i += BLK_SIZE) { blkSad = quarterPixelDiffSAD4x4((u_int8 (*)[MBK_SIZE]) (orig + i), ref + 2 * i, ref2 + 2 * i, w); totalSad += blkSad; *sadPtr ++ = (int16) blkSad; } blkSadsBuf += BLK_PER_MB; orig += BLK_SIZE*MBK_SIZE; ref += BLK_SIZE*2*w; ref2 += BLK_SIZE*2*w; } } return totalSad;}/* * * findSATD4Blk: * * Parameters: * orig Pointer to the original pixels * ref Pointer to the reference pixels * w Width of the reference buffer * blkWidth Width of block * blkHeight Height of block * x Motion vector, x component * y Motion vector, y component * blkSadsBuf Store the SAD of 4x4 block * bufOffs Pointer offsets * * Function: * Calculate the sum of absolute coefficients from Hadamard transform * of differences between the original pixels and reference pixels. * SAD with Hadamard is calculated in 4x4 blocks. The SADs of each * 4x4 block are also return in the buffer. The buffer store the SADs * of 4x4 blocks in raster order. So when "j" moves to the next row, * the sad buffer pointer is incremented by 4. * * Returns: * Total SAD for the partition. * */int findSATD4Blk(u_int8 *orig, u_int8 *ref, int w, int blkWidth, int blkHeight, int x, int y, int16 *blkSadsBuf){ int i, j; int blk[BLK_SIZE][BLK_SIZE]; int blkSad, totalSad; int16 *sadPtr; totalSad = 0; ref += (y >> 1) * w + (x >> 1); if (((x | y) & 1) == 0) { for (j = 0; j < blkHeight; j += BLK_SIZE) { sadPtr = blkSadsBuf; for (i = 0; i < blkWidth; i += BLK_SIZE) { halfPixelDiff(orig + i, ref + 2 * i, w, blk); blkSad = traHadamard4x4(blk)>>1; totalSad += blkSad; *sadPtr ++ = (int16) blkSad; } blkSadsBuf += BLK_PER_MB; orig += BLK_SIZE*MBK_SIZE; ref += BLK_SIZE*2*w; } } else { int dx, dy; u_int8 *ref2; dx = x & 3; dy = y & 3; ref2 = ref; ref += bufOffs[dy][dx][0]; ref2 += bufOffs[dy][dx][1]; for (j = 0; j < blkHeight; j += BLK_SIZE) { sadPtr = blkSadsBuf; for (i = 0; i < blkWidth; i += BLK_SIZE) { blkSad = quarterPixelDiffSATD4x4((u_int8 (*)[MBK_SIZE]) (orig + i), ref + 2 * i, ref2 + 2 * i, w) >> 1; totalSad += blkSad; *sadPtr ++ = (int16) blkSad; } blkSadsBuf += BLK_PER_MB; orig += BLK_SIZE*MBK_SIZE; ref += BLK_SIZE*2*w; ref2 += BLK_SIZE*2*w; } } return totalSad;}int findSadPT(mbPart_s *mbPart, int vecX, int vecY, int bestSad){ int currSad; int lambda; lambda = mbPart->lambdaCoarse; currSad = lambda * (mbPart->vlcMvBitsX[vecX] + mbPart->vlcMvBitsY[vecY]); /* Favor 16x16 blocks that have zero motion */ if (mbPart->mode == MOT_16x16) { if ((vecY | vecX) == 0) currSad -= lambda * ZERO_VEC_SAD; } /* Take into account number of bits spent for motion vector */ if (currSad < bestSad) { currSad = findSAD2(mbPart->orig, mbPart->ref, mbPart->refWidth, mbPart->width, mbPart->height, vecX, vecY, currSad, bestSad); } return currSad;}///// LOW_COMPLEX_PROF3// : search pos for multi-step integer search// all must be multiple of 4 -> integer pos// {x,y}// use in 16x16static int8 step_array_16x16[NUM_POS_16x16_FastMot][2] = { {14*4,1*4}, {0*4,6*4}, {0*4,6*4}, {-14*4,0*4}, {0*4,-6*4}, {0*4,-6*4}, {7*4,2*4}, {4*4,4*4}, {-4*4,4*4}, {-4*4,-4*4}, {3*4,-1*4}, {2*4,0*4}, {-2*4,2*4}, {2*4,0*4}, {6*4,-3*4}, {0*4,4*4}, {-7*4,5*4}, {-7*4,-5*4}, {0*4,-4*4}, {7*4,-5*4}, {-4*4,3*4}, {8*4,0*4}, {0*4,8*4}, {-8*4,0*4},};// use in 8x16, 16x8, 8x8static int8 step_array_16x8[NUM_POS_16x8_FastMot][2] = { {2*4,2*4}, {2*4,0*4}, {-2*4,2*4}, {2*4,0*4}, {2*4,-4*4}, {0*4,6*4}, {-6*4,0*4}, {0*4,-6*4}, }; static int8 step_array_small[4][2] = { {0,0}, {8,0}, {-8,8}, {8,0}, };#define ABS(x) ( ( (x) >=0) ? (x): (-x) )void matchBlockLong_MultiStep(mbPart_s *mbPart, int startX, int stopX, int startY, int stopY, int step, motVec_s *bestVec, int *bestSad){ motVec_s lclBestVec; int j, vecX, vecY; int currSad; int lclBestSad; int overhead; int refW, blkH; int lambda; u_int8 *refLine, *refPtr, *orig; const int8 *vlcMvBitsX; int ii; int old_sad = 0; int small_search_win; int num_search_pos; char *pc; // *retSad should have the SAD of the best estimate already // could be INT_MAX if such an estimate is not available lclBestSad = *bestSad; lclBestVec = *bestVec; blkH = mbPart->height; orig = mbPart->orig; refW = mbPart->refWidth; lambda = mbPart->lambdaCoarse; vlcMvBitsX = mbPart->vlcMvBitsX; switch (mbPart->width) { case 4: /* Scan motion vectors within search area */ for (vecY = startY; vecY <= stopY; vecY += step) { refLine = & mbPart->ref[(vecY >> 1) * refW]; overhead = (int) mbPart->vlcMvBitsY[vecY] * lambda; for (vecX = startX; vecX <= stopX; vecX += step) { /* Take into account number fo bits spent for motion vector */ currSad = lambda * vlcMvBitsX[vecX] + overhead; /* Accumulate sad until no pels left or sad is worse than best so far */ if (currSad < lclBestSad) { refPtr = refLine + (vecX >> 1); findSAD2_4x(orig, refPtr, refW, blkH, currSad, lclBestSad, j); if (currSad < lclBestSad) { lclBestSad = currSad; lclBestVec.x = (int16)vecX; lclBestVec.y = (int16)vecY; } } } } break; case 8: small_search_win=0; if (stopX-startX == SMALL_SEARCH_WIN) { small_search_win=1; } if (small_search_win) { num_search_pos=4; pc = &step_array_small[0][0]; } else { if ( ( ABS( (startX - (ME_START_16x8)) ) >TH_FastMot_16x8 ) || ( ABS( (startY - (ME_START_16x8)) ) >TH_FastMot_16x8 ) ) { num_search_pos=NUM_POS_16x8_FastMot; } else num_search_pos=NUM_POS_16x8; pc = &step_array_16x8[0][0]; } vecX=startX; vecY=startY; /////////// for (ii=0;ii<num_search_pos; ii++) { vecX+=*pc++; vecY+=*pc++; refLine = & mbPart->ref[(vecY >> 1) * refW]; overhead = (int) mbPart->vlcMvBitsY[vecY] * lambda; /* Take into account number fo bits spent for motion vector */ currSad = lambda * vlcMvBitsX[vecX] + overhead; { refPtr = refLine + (vecX >> 1); currSad = findSad2_8x(orig, refPtr, refW, blkH, currSad, lclBestSad); if (currSad < lclBestSad) { lclBestSad = currSad; lclBestVec.x = (int16)vecX; lclBestVec.y = (int16)vecY; } } } break; default: // blk->width == 16 small_search_win=0; if (stopX-startX == SMALL_SEARCH_WIN) { small_search_win=1; } if (small_search_win) { num_search_pos=4; pc = &step_array_small[0][0]; } else { if (blkH ==16) { pc =&step_array_16x16[0][0]; if ( ( ABS( (startX - (ME_START_16x16)) ) >TH_FastMot ) || ( ABS( (startY - (ME_START_16x16)) ) >TH_FastMot ) ) { num_search_pos=NUM_POS_16x16_FastMot; } else { num_search_pos=NUM_POS_16x16; } } else { if ( ( ABS( (startX - (ME_START_16x8)) ) >TH_FastMot_16x8 ) || ( ABS( (startY - (ME_START_16x8)) ) >TH_FastMot_16x8 ) ) { num_search_pos=NUM_POS_16x8_FastMot; } else num_search_pos=NUM_POS_16x8; pc = &step_array_16x8[0][0]; } } // old_sad=lclBestSad; vecX=startX; vecY=startY; for (ii=0;ii<num_search_pos; ii++) { vecX+=*pc++; vecY+=*pc++; refLine = & mbPart->ref[(vecY >> 1) * refW]; overhead = (int) mbPart->vlcMvBitsY[vecY] * lambda; /* Take into account number fo bits spent for motion vector */ currSad = lambda * vlcMvBitsX[vecX] + overhead; if (mbPart->mode == MOT_16x16) { if ((vecY | vecX) == 0) currSad -= lambda * ZERO_VEC_SAD; } { refPtr = refLine + (vecX >> 1); currSad = findSad2_16x(orig, refPtr, refW, blkH, currSad, lclBestSad); if (currSad < lclBestSad) { lclBestSad = currSad; lclBestVec.x = (int16)vecX; lclBestVec.y = (int16)vecY; } } } break; } *bestSad = lclBestSad; *bestVec = lclBestVec; { LC3_s *plc3=mbPart->plc3; // if ( (plc3->qp<TH_QP1) && ((plc3->mode==MOT_16x8) && (plc3->old_cnt2!=plc3->cnt) ) ) { plc3->old_cnt2=plc3->cnt; if ( (old_sad-lclBestSad) <1 ) plc3->do_16x8=0; } }}////// LOW_COMPLEX_PROF3//////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -