char GetBoudaryStrenght_TI( short mv_cache_l0[][2], short mv_cache_l1[][2], short *ref_cache_l0, short *ref_cache_l1, 
					   short poc_l0[], short poc_l1[], int b_idx, int bn_idx, int slice_type, int mb_type, int mbm_type)
{

	short	ref_p1;
	short	ref_q1;
	short ref_p0 = ref_cache_l0[b_idx]  < 0 ? -1 : poc_l0[ref_cache_l0[b_idx]];
	short ref_q0 = ref_cache_l0[bn_idx] < 0 ? -1 : poc_l0[ref_cache_l0[bn_idx]];
	unsigned int p0q0,p1q1;

	char v = 1;
	char x,y;



	if(slice_type == SLICE_TYPE_B) {
		ref_p1 = ref_cache_l1[b_idx] < 0 ? -1 : poc_l1[ref_cache_l1[b_idx]];
		ref_q1 = ref_cache_l1[bn_idx] < 0 ? -1 : poc_l1[ref_cache_l1[bn_idx]];
	}else{
		ref_p1 = -1;
		ref_q1 = -1;
	}

//	ref_p1 = ((ref_cache_l1[b_idx] < 0)&&(slice_type != SLICE_TYPE_B)) ? -1 : poc_l1[ref_cache_l1[b_idx]];
//	ref_q1 = ((ref_cache_l1[bn_idx] < 0)&&(slice_type != SLICE_TYPE_B)) ? -1 : poc_l1[ref_cache_l1[bn_idx]];

	p0q0=_pack2(ref_q1,ref_q0);
	p1q1=_pack2(ref_p1,ref_p0);
	x =_cmpeq2(p0q0,p1q1);
	y = x | _cmpeq2(p0q0,_rotl(p1q1,16));


	//if ( ((ref_p0 == ref_q0) && (ref_p1 == ref_q1)) || ((ref_p0 == ref_q1) && (ref_p1 == ref_q0))) {
	if ( y==3) {
		char l0b_l0bn=bSCheckMvShort (mv_cache_l0[b_idx], mv_cache_l0[bn_idx]);
		char l1b_l1bn=bSCheckMvShort (mv_cache_l1[b_idx], mv_cache_l1[bn_idx]);
		char l0b_l1bn=bSCheckMvShort (mv_cache_l0[b_idx], mv_cache_l1[bn_idx]);
		char l1b_l0bn=bSCheckMvShort (mv_cache_l1[b_idx], mv_cache_l0[bn_idx]);
		if (ref_p0 != ref_p1) 	{ 
			// compare MV for the same reference picture
			if (ref_p0 == ref_q0)  {
				v =  l0b_l0bn || (l1b_l1bn && (!(IS_P(mb_type) || IS_P(mbm_type))));
			} else   {
				v =   (l0b_l1bn) ||  (l1b_l0bn);	
			}
		} else { // L0 and L1 reference pictures of p0 are the same; q0 as well
			v =  ( (l0b_l0bn) ||  (l1b_l1bn)) && ( (l0b_l1bn) ||  (l1b_l0bn));
		}
	}

	return v;

}
char GetBoudaryStrenght_C( short mv_cache_l0[][2], short mv_cache_l1[][2], short *ref_cache_l0, short *ref_cache_l1, 
					   short poc_l0[], short poc_l1[], int b_idx, int bn_idx, int slice_type, int mb_type, int mbm_type)
{

	int	ref_p1;
	int	ref_q1;
	int ref_p0 = ref_cache_l0[b_idx]  < 0 ? -1 : poc_l0[ref_cache_l0[b_idx]];
	int ref_q0 = ref_cache_l0[bn_idx] < 0 ? -1 : poc_l0[ref_cache_l0[bn_idx]];


	char v = 1;

	if(slice_type == SLICE_TYPE_B) {
		ref_p1 = ref_cache_l1[b_idx] < 0 ? -1 : poc_l1[ref_cache_l1[b_idx]];
		ref_q1 = ref_cache_l1[bn_idx] < 0 ? -1 : poc_l1[ref_cache_l1[bn_idx]];
	}else{
		ref_p1 = -1;
		ref_q1 = -1;
	}

	if ( ((ref_p0 == ref_q0) && (ref_p1 == ref_q1)) || ((ref_p0 == ref_q1) && (ref_p1 == ref_q0))) {
		if (ref_p0 != ref_p1) 	{ 
			// compare MV for the same reference picture
			if (ref_p0 == ref_q0)  {
				if (IS_P(mb_type) || IS_P(mbm_type)){
					v =  bSCheckMvShort (mv_cache_l0[b_idx], mv_cache_l0[bn_idx]);
				}else{
					v =  bSCheckMvShort (mv_cache_l0[b_idx], mv_cache_l0[bn_idx]) || bSCheckMvShort (mv_cache_l1[b_idx], mv_cache_l1[bn_idx]);
				}
			} else   {
				v =  bSCheckMvShort (mv_cache_l0[b_idx], mv_cache_l1[bn_idx]) || bSCheckMvShort (mv_cache_l1[b_idx], mv_cache_l0[bn_idx]);	
			}
		} else { // L0 and L1 reference pictures of p0 are the same; q0 as well
			v =  (bSCheckMvShort (mv_cache_l0[b_idx], mv_cache_l0[bn_idx]) || bSCheckMvShort (mv_cache_l1[b_idx], mv_cache_l1[bn_idx])) && 
				(bSCheckMvShort (mv_cache_l0[b_idx], mv_cache_l1[bn_idx]) || bSCheckMvShort (mv_cache_l1[b_idx], mv_cache_l0[bn_idx]));
		}
	}

	return v;
}
Exemple #3
0
int main(){
    int n; 
    int sum_p = 0;
    int sum_s = 0;
    scanf("%d",&n);
    int a[n][n];
    int a_i, a_j;
    for(a_i = 0; a_i < n; a_i++){
       for(a_j = 0; a_j < n; a_j++){ 
          scanf("%d",&a[a_i][a_j]);
           if (IS_P(a_i, a_j)) {
	       printf("Primary:%d:%d\n", a_i, a_j);
               sum_p += a[a_i][a_j];
	   }
           if (IS_S(a_i, a_j, n-1)) {
	       printf("Secondary:%d:%d\n", a_i, a_j);
               sum_s += a[a_i][a_j];
	  }
       }
    }
    printf("%d:%d", sum_p, sum_s);
    printf("%d", abs(sum_p - sum_s));
    return 0;
}
/**
This function permits to update the neighbourhood of the current macroblock.
This function stock in table the motion vector for the macroblock which belong to the neighbourhood of the current macroblock.

@param aio_pstSlice The aio_pstSlice strucutre.
@param ai_iB_stride The width of sample in the ai_tiMv table.
@param ai_iB8_stride The width of sample in the ai_tiRef table.
@param aio_tiRef_cache_l0 A cache table where the reference is stocked for each 4x4 block of the current macroblock.
@param aio_tiMv_cache_l0 A cache table where the motion vector are stocked for each 4x4 block of the current macroblock.
@param aio_pstSlice_table A table which resume in which aio_pstSlice each macroblock belongs to.
@param aio_tstBlock Contains all parameters of each macroblock of the current picture.
@param ai_tiMv A table where each motion vector calculated is stocked for each macroblock decoded.
@param ai_tiRef A table where each reference mode calculated is stocked for each macroblock decoded.
@param ai_iMb_x The x position of the macroblock in the picture.
@param ai_iMb_y The y position of the macroblock in the picture.
*/
void fill_caches_motion_vector( const SLICE *Slice, const int ai_iB_stride, const int ai_iB8_stride, 
							   short aio_tiRef_cache_l0 [ RESTRICT ], short aio_tiMv_cache_l0[ RESTRICT ][2], 
							   const unsigned char aio_pstSlice_table [ ], const RESIDU CurrResidu[], 
							   short ai_tiMv[ RESTRICT ], const short ai_tiRef[ ],  const int ai_iX, const int ai_iY)
{


	int    top_type = 0;
    int    topleft_type;
    int    topright_type;
    int    left_type;

	const int iCurrMbAddr = ai_iX + Slice -> mb_stride * ai_iY;
	const int top_xy = iCurrMbAddr - Slice -> mb_stride;
    const int topleft_xy = top_xy - 1 ;
    const int topright_xy = (top_xy >= 0)? top_xy + 1:-1 ;
    const int left_xy = iCurrMbAddr - 1;

	//Updating their availability according to the slice
	if ( top_xy >= 0 )  {
		top_type = aio_pstSlice_table [top_xy] == Slice -> slice_num ? CurrResidu [- Slice -> mb_stride] . MbType : 0 ;

		if ( topleft_xy >= 0 && ai_iX != 0 && aio_pstSlice_table [topleft_xy] == Slice -> slice_num){
			topleft_type = CurrResidu [- Slice -> mb_stride - 1] . MbType;
		}else{
			topleft_type = 0;
			aio_tiRef_cache_l0[3] = PART_NOT_AVAILABLE;
		}


		if ( topright_xy >= 0 && (ai_iX != Slice -> mb_stride - 1) && aio_pstSlice_table [topright_xy] == Slice -> slice_num){
			topright_type = CurrResidu [- Slice -> mb_stride + 1] . MbType;
		}else{
			topright_type = 0;
			aio_tiRef_cache_l0[8] = PART_NOT_AVAILABLE;
		}

	}else{
		top_type = 0;
		topleft_type = 0;
		topright_type = 0;

		//Update top right and top left reference
		 aio_tiRef_cache_l0[3] = PART_NOT_AVAILABLE;
		 aio_tiRef_cache_l0[8] = PART_NOT_AVAILABLE;
	}


    if ( left_xy >= 0 && ai_iX != 0 && aio_pstSlice_table [left_xy] == Slice -> slice_num){
		left_type = CurrResidu [-1] . MbType ;
	}else{
		left_type = 0;
		//Update left reference
		FillRefCacheLeftPosition(aio_tiRef_cache_l0, PART_NOT_AVAILABLE, PART_NOT_AVAILABLE);
	}


	//In case of a skipped or a P macroblock
    if(IS_P(top_type)){
        FillMvCacheTopPosition(aio_tiMv_cache_l0, &ai_tiMv[-ai_iB_stride]);
		FillRefCacheTopPosition(aio_tiRef_cache_l0, ai_tiRef [- ai_iB8_stride], ai_tiRef[1 - ai_iB8_stride]);
    }
	else if (!top_type){
        FillRefCacheTopPosition(aio_tiRef_cache_l0, PART_NOT_AVAILABLE, PART_NOT_AVAILABLE);
    }

	//In case of a skipped or a P macroblock
    if(IS_P(left_type)){
       FillMvCacheLeftPosition(aio_tiMv_cache_l0, &ai_tiMv[-2], ai_iB_stride);
	   FillRefCacheLeftPosition(aio_tiRef_cache_l0, ai_tiRef[-1], ai_tiRef[-1 + ai_iB8_stride]);
    }


	//In case of a skipped or a P macroblock
    if(IS_P(topleft_type ))	{
        aio_tiMv_cache_l0 [3][0] = ai_tiMv[-2 - ai_iB_stride];
		aio_tiMv_cache_l0 [3][1] = ai_tiMv[-1 - ai_iB_stride];
		aio_tiRef_cache_l0[3] = ai_tiRef[-1 - ai_iB8_stride];
    }

	//In case of a skipped or a P macroblock
    if(IS_P(topright_type ))  {
		aio_tiMv_cache_l0 [8][0] = ai_tiMv[8 - ai_iB_stride];
		aio_tiMv_cache_l0 [8][1] = ai_tiMv[9 - ai_iB_stride];
        aio_tiRef_cache_l0[8] =  ai_tiRef[2 - ai_iB8_stride];
    }

    aio_tiRef_cache_l0[14] = aio_tiRef_cache_l0[15 + 1] = aio_tiRef_cache_l0[23 + 1] =
	aio_tiRef_cache_l0[30] = aio_tiRef_cache_l0[31 + 1] = PART_NOT_AVAILABLE;
}