/**
This function calculates the Scoeff residual of the current macroblock.
Here, base macroblock coefficents are rescaled, when base layer was a AVC one,
and added to the current macroblock coefficient. The sum is stored in the current macroblock,
in order to be used for upper SNR layer.
The residual is also calculated in a short picture in order to be used for upper spatial enhancement, or to add to the prediction.
*/
void SCoeffResidualAddRes(const NAL *Nal, RESIDU *CurrResidu, RESIDU *BaseResidu, const PPS *Pps, const short PicWidthInPix, const W_TABLES *Quantif
						 , short *Residu_Luma, short *Residu_Cb, short *Residu_Cr)
{



	//We have to keep base and current layer rescale coefficient for Scoeff prediction
	//For upper layer
	if( CurrResidu -> Cbp){
		// In case of new SNR enhancement based on this one
		RescaleCurrentCoeff(CurrResidu, BaseResidu, Pps, Quantif);
	}else if ( CurrResidu -> ResidualPredictionFlag){
		//===== modify QP values (as specified in G.8.1.5.1.2) =====
		//cbp == 0 && (Scoeff || Tcoeff) && (I_BL || ResidualPredictionFlag)
		CurrResidu -> Qp = BaseResidu -> Qp;
		CurrResidu -> Transform8x8 = BaseResidu -> Transform8x8;
	}


	//Test if cbp != 0 and if we are in the first enhancement layer in MGS or CGS
	if( (!IS_I(CurrResidu -> MbType)) && CurrResidu -> ResidualPredictionFlag && (!IS_I(BaseResidu -> MbType))){
		ComputeCurrentCoeff(Nal, CurrResidu, BaseResidu, Pps, Quantif);
	}

	if (Nal -> PicToDecode){
		if ( !CurrResidu -> Transform8x8){
			SCoeff4x4AddRes(Residu_Luma, CurrResidu, PicWidthInPix);
		} else {
			SCoeff8x8AddRes(Residu_Luma, CurrResidu, PicWidthInPix);
		}

		//Decode the chrominance
		SCoeffChromaAddRes(Residu_Cb, Residu_Cr, CurrResidu, PicWidthInPix >> 1);
	}
}
void SCoeffResidualAddPic(const NAL *Nal, RESIDU *CurrResidu, RESIDU *BaseResidu, const PPS *Pps, const short PicWidthInPix, const W_TABLES *Quantif
					   , unsigned char *Y, unsigned char *U, unsigned char *V)
{



	//We have to keep base and current layer rescale coefficient for Scoeff prediction
	//For upper layer
	if( CurrResidu -> Cbp){
		// In case of new SNR enhancement based on this one
		RescaleCurrentCoeff(CurrResidu, BaseResidu, Pps, Quantif);
	}


	ComputeCurrentCoeff(Nal, CurrResidu, BaseResidu, Pps, Quantif);

	if (Nal -> PicToDecode){
		if ( !CurrResidu -> Transform8x8){
			SCoeff4x4AddPic(Y, CurrResidu, PicWidthInPix);
		} else {
			SCoeff8x8AddPic(Y, CurrResidu, PicWidthInPix);
		}

		//Decode the chrominance
		SCoeffChromaAddPic(U, V, CurrResidu, PicWidthInPix >> 1);
	}
}
Exemplo n.º 3
0
/**
Decode a I_BL marcoblock using SNR prediction.
*/
void MbISnr (const PPS *Pps, const NAL* Nal, const W_TABLES *Quantif, const STRUCT_PF *BaselineVectors, 
			 RESIDU *CurrResidu, RESIDU *BaseResidu, const short PicWidthInPix, 
			 unsigned char *Y, unsigned char *U, unsigned char *V,
			 unsigned char *BaseY, unsigned char *BaseU, unsigned char *BaseV)
{

	//Construction process for one macroblock
	if (IS_I(CurrResidu -> MbType)){
		//I type macroblock decoding process
		decode_MB_I(Y, U, V, Pps, CurrResidu, PicWidthInPix, Quantif, BaselineVectors);
	}else if (Nal -> TCoeffPrediction){
		//Decoding proces of the macroblock, as an INTRA_BL
		DecodeITCoeff(CurrResidu, BaseResidu, Pps, PicWidthInPix, Quantif, BaselineVectors, Y, U, V);
	}else if (Nal -> SCoeffPrediction){
		if ((CurrResidu -> Cbp & 0x0f) == 0){
			//===== modify QP values (as specified in G.8.1.5.1.2) =====
			//cbp == 0 && (Scoeff || Tcoeff) && (I_BL || ResidualPredictionFlag)
			CurrResidu -> Transform8x8 = BaseResidu -> Transform8x8;
			if (!CurrResidu -> Cbp){
				CurrResidu -> Qp = BaseResidu -> Qp;
			}
		}

		//Bring back base layeer sample into current layer
		GetBaseSample(Y, U, V, BaseY, BaseU, BaseV, PicWidthInPix);


		if ( IS_BL (BaseResidu -> MbType)){
			//In case of two SNR enchancement
			//We have to get the zero quality prediction
			//And to add to this all Scoeff 
			SCoeffResidualAddPic(Nal, CurrResidu, BaseResidu, Pps, PicWidthInPix, Quantif, Y, U, V);
		}else if (Nal -> PicToDecode){
			//We have only one layer prediction, so we can just add the residual to it.
			ComputeResidual(Pps, CurrResidu, PicWidthInPix, Y, U, V, Quantif);
		}else{
			if( CurrResidu -> Cbp){
				// In case of new SNR enhancement based on this one
				RescaleCurrentCoeff(CurrResidu, BaseResidu, Pps, Quantif, Nal -> SpatialScalability);
			}
		}
	}
}