www.pudn.com > wm2.5.zip > IREG.c
#include#include #include "IREG.h" #include "global.h" #include "define.h" void UpdateIREGMap() { int j, i; int mb_width, mb_heihgt; mb_width = pgImage->img_width / MB_BLOCK_SIZE; mb_heihgt = pgImage->img_height / MB_BLOCK_SIZE; for (j = 0; j < mb_heihgt; j++) { for (i = 0; i < mb_width; i++) { pCurrFrmIREGMap[j][i] = 0; } } if (iIREGState == mb_width * mb_heihgt) { iIREGState = 0; } //if(pgImage->type==INTRA_IMG)return; for (j = 0; j < iIREGState; j++) { pCurrFrmIREGMap[j / mb_width][j % mb_width] = 1; } if ((iIREGState + input.IREGRate) > (mb_width * mb_heihgt) && pgImage->type!=INTRA_IMG) { for (j = iIREGState; j < mb_heihgt * mb_width; j++) { pCurrFrmIREGMap[j / mb_width][j % mb_width] = 2; } iIREGState = mb_heihgt * mb_width; } else //if (pgImage->type!=INTRA_IMG) { for (j = iIREGState; j < iIREGState + input.IREGRate; j++) { pCurrFrmIREGMap[j / mb_width][j % mb_width] = 2; //n_refreshed_mb++; } iIREGState += input.IREGRate; } } void IniIREG() { int j, i; for (j = 0; j < pgImage->img_height / MB_BLOCK_SIZE; j++) { for (i = 0; i < pgImage->img_width / MB_BLOCK_SIZE; i++) { IREGMap[0][j][i] = 0; IREGMap[1][j][i] = 0; IREGMap[2][j][i] = 0; } } pCurrFrmIREGMap = IREGMap[2]; iIREGState = 0; iIREGReliableFrmFlag = 0; iIntegerPixFlag = 0; } int AffectedByLeftover(int x_pos, int y_pos, int ref) { int refx, refy; int dx, dy; int x, y; int i, j; int maxold_x,maxold_y; int result; //int tmp_res[26][26]; //int tmp_res_2[26][26]; /* static const int COEF_HALF[6] = { 1, -5, 20, 20, -5, 1 }; static const int COEF_QUART[4] = { 0, 64, 63, 1 }; const iWeight1_2 = 32; const iWeight1_4 = 128; */ // A a 1 b B // c d e f // 2 h 3 i // j k l m // C D dx = x_pos & 3; dy = y_pos & 3; x_pos = ( x_pos - dx ) / 4; y_pos = ( y_pos - dy ) / 4; maxold_x = pgImage->img_width - 1; maxold_y = pgImage->img_height - 1; if (dx == 0 && dy == 0) { //fullpel position: A refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } else { // other positions // if ( (dx == 2) && (dy == 0)) { //horizonal 1/2 position: 1 for (result = 0, x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } else if ( ( (dx == 1) || (dx == 3) ) && (dy == 0) ) { //horizonal 1/4 position: a and b if (dx == 1)//a { for (i = -1; i < 1; i++) { for (x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + i + x)); refy = max(0, min(maxold_y, y_pos)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } refx = max(0, min(maxold_x, x_pos + i + 1)); refy = max(0, min(maxold_y, y_pos)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } else//b { for (i = 0; i < 2; i++) { for (x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + i + x)); refy = max(0, min(maxold_y, y_pos )); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } for (i = -1; i < 1; i++) { refx = max(0, min(maxold_x, x_pos + i + 1)); refy = max(0, min(maxold_y, y_pos)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } }//else if ( ( (dx == 1) || (dx == 3) ) && (dy == 0) ) else if ( (dy == 2) && (dx == 0) ) { //vertical 1/2 position: 2 for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } }//else if ( (dy == 2) && (dx == 0) ) else if( ( (dy == 1) || (dy == 3)) && (dx == 0) ) { //vertical 1/4 position: c and j if (dy == 1)//c { for (j = -1; j < 1; j++) { for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos + j + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos + j + 1)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } else//j { for (j = 0; j < 2; j++) { for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos + j + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } for (j = -1; j < 1; j++) { refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos + j + 1)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } }//else if( ( (dy == 1) || (dy == 3)) && (dx == 0) ) else if ( (dx == 2) && (dy == 2) ) { //horizonal and vertical 1/2 position: 3 for (j = -2; j < 4; j++) { for (x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos + j)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } } else if( ( (dx == 1) || (dx == 3) ) && (dy == 2) ) { //horizonal and vertical 1/4 position: h and i if (dx == 1)//h { for (i = -3; i < 4; i++) { for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos + i)); refy = max(0, min(maxold_y, y_pos + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } } else//i { for (i = -2; i < 5; i++) { for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos + i)); refy = max(0, min(maxold_y, y_pos + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } } } else if( ( (dy == 1) || (dy == 3) ) && (dx == 2) ) { //vertical and horizonal 1/4 position: e and l if(dy == 1)//e { for (j = -3; j < 4; j++) { for (x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos + j)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } } else//l { for (j = -2; j < 5; j++) { for (x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos + j)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } } } else { //Diagonal 1/4 position : d, f, k and m if( (dx == 1) && (dy == 1) )//d { for(x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } else if( (dx == 3) && (dy == 1) )//f { for(x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos + 1)); refy = max(0, min(maxold_y, y_pos + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } else if ((dx == 1) && (dy == 3))//k { for(x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos + 1)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos)); refy = max(0, min(maxold_y, y_pos + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } else if((dx == 3) && (dy == 3))//m { for(x = -2; x < 4; x++) { refx = max(0, min(maxold_x, x_pos + x)); refy = max(0, min(maxold_y, y_pos + 1)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } for (y = -2; y < 4; y++) { refx = max(0, min(maxold_x, x_pos + 1)); refy = max(0, min(maxold_y, y_pos + y)); if (IREGMap[ref][refy>>4][refx>>4] == 0) { return 1; } } } } }//if (dx == 0 && dy == 0) else return 0; }