-----------------------------------------------------------------
April 1st 1998 FCD Version 0.0a
-----------------------------------------------------------------

INTEGRATORS:

Sharp/Sony
Contact: norio@imgsl.mkhar.sharp.co.jp

-----------------------------------------------------------------
REASON FOR UPDATE:

Update scalability code.

-----------------------------------------------------------------
FILES CHANGED:

app/encoder/encoder.cpp
sys/encoder/sesenc.cpp
sys/encoder/vopseenc.cpp
sys/decoder/vopsedec.cpp
sys/tps_bfshape.cpp
sys/vopses.hpp

-----------------------------------------------------------------
COMMENTS:

Sharp and Sony finished the DFCD integration based on the
microsoft-vcd-v10-980312. We have also confirmed the four checklist
items (from 2.7.1 to 2.7.4) and bistream verification are completely
done. Attached please find a detail modification list. We have
changed 6 files and the changed parts are specified by 'modified by
Sharp' or 'modified by SONY'. 

-----------------------------------------------------------------
OPTIONAL DETAILS:

(1) app/encoder/encoder.cpp: line 315
	nextValidLine (pfPara, pnLine);
	Int* rgiEnhancementType = new Int [nVO];
	for (iObj = 0; iObj < nVO; iObj++)  {
		if (fscanf (pfPara, "%d", &rgiEnhancementType [iObj]) != 1) {
		fprintf(stderr, "wrong parameter file format on line %d\n", *pnLine);
		exit (1);
	}
	assert (rgiEnhancementType [iObj] == 0 || //  entire region of the base layer is enhanced
// begin: modified by Sharp (98/3/24)
      rgiEnhancementType [iObj] == 1 ||  // partial region of the base layer is enhanced (with background composition)
			rgiEnhancementType [iObj] == 2);  // partial region of the base layer is enhanced (without background composition)
// end: modified by Sharp (98/3/24)

(2) sys/encoder/sesenc.cpp
	(2-1) line 382
	m_rgvolmd [iLayer][iVO].bTemporalScalability = TRUE;
	m_rgvolmd [iLayer][iVO].iEnhnType = rgiEnhancementType [iVO];
	if ( rgiEnhancementType[iVO] != 0 ) // modified by Sharp (98/3/24)
		m_rgvolmd [BASE_LAYER][iVO].fAUsage = RECTANGLE;

	(2-2) line 1145
#ifndef __OUT_ONE_FRAME_
	if (m_rgbSpatialScalability [iobj - m_iFirstVO] == TRUE && volmd_enhn.bTemporalScalability == TRUE && volmd_enhn.iEnhnType != 0) { // modified by Sharp (98/3/24)
		    FILE *pfTemp;

	(2-3) line 1696
		if(rgpvoenc -> m_vopmd.iLoadForShape){
			rgpvoenc -> m_vopmd.iLoadForShape = loadData (ieFramefShape, pfYuvSrc, pfSegSrc, pxlcObjColor,
			rgpvoenc ->rgpbfShape [1]->m_pvopcOrig, m_rctOrg, rgpvoenc ->rgpbfShape[1]->m_volmd);
			if ( !rgpvoenc -> m_vopmd.iLoadForShape )
			cout << "Load_forward_shape was ON, but turned off because of no shape\n";
		}
	}
	// begin: added by Sharp (98/3/24)
	else if ( rgpvoenc -> m_volmd.iEnhnType == 2 ) {
		rgpvoenc -> m_vopmd.iLoadBakShape = 0;
		rgpvoenc -> m_vopmd.iLoadForShape = 0;
	}
	// end: added by Sharp (98/3/24)

	(2-4) line 1714
// for background composition
	if(rgpvoenc -> m_volmd.iEnhnType != 0){ // should be changed to background_composition flag later. // modified by Sharp (98/3/24)
	//      printf("Performing B.C. ... Time = (%d, %d, %d)\n", iFrame, ieFramefShape, ieFramebShape);


	(2-5) line:714 The following part is modified.
//modified by SONY (98/03/30)
				rgpvoenc [BASE_LAYER] -> codeGOVHead (iRefFrame - m_iFirstFrame + iDT);
//modified by SONY (98/03/30) End
/*				rgpvoenc [BASE_LAYER] -> codeGOVHead (iSearchFrame - m_iFirstFrame);
		Original*/


	(2-6) line:803 The following part is modified.
/* (98/3/30) modified by SONY*/
                                  if (iPCount == volmd.iPbetweenI)        {
/* (98/3/20) modified by SONY(end)*/
/*            ORIGINAL
                                  if (iPCount == 0)       {
*/

(3) sys/encoder/vopseenc.cpp
	(3-1) line 1048
    m_pbitstrmOut -> putBits (m_volmd.ihor_sampling_factor_n, 5, "VOL_Vertical_Sampling_Factor");     //The vm is not very clear about this.
		m_pbitstrmOut -> putBits (m_volmd.ihor_sampling_factor_m, 5, "VOL_Vertical_Sampling_Factor_Ref");   //Always 1
		m_pbitstrmOut -> putBits (m_volmd.iEnhnType!=0?1:0, 1, "VOL_Ehnancement_Type"); // enhancement_type for scalability // modified by Sharp (98/3/24)
		m_statsVOL.nBitsHead += 2 + 20 + 1;
	
	(3-2) line 1200
    if ( m_volmd.volType == ENHN_LAYER && m_volmd.iEnhnType == 1 ) {
			m_pbitstrmOut->putBits (1, 1, "Background Composition");
			m_statsVOP.nBitsHead++;
		}
// begin: added by Sharp (98/3/24)
		else if ( m_volmd.volType == ENHN_LAYER && m_volmd.iEnhnType == 2 ) {
			m_pbitstrmOut->putBits (0, 1, "Background Composition");
			m_statsVOP.nBitsHead++;
		}
// end: added by Sharp (98/3/24)

	(3-3) line 1312
		if( m_volmd.iEnhnType != 0 ){ // modified by Sharp (98/3/24)
			m_pbitstrmOut->putBits (m_vopmd.iLoadBakShape, 1, "load_backward_shape");
	
	(3-4) line 1917
		pvopc->m_pvopcRefQ0 = new CVOPU8YUVBA ( *m_pvopcBuf );
	  pvopc->m_tPastRef = m_t;

		if ( pvopc->m_volmd.iEnhnType != 0  && //modified by Sharp (98/3/24)
			(((pvopc->m_vopmd.iRefSelectCode == 1 || pvopc->m_vopmd.iRefSelectCode == 2) && pvopc->m_vopmd.vopPredType == PVOP) ||
	
	(3-5) line 1941
	    for (Int iMB=0; iMB<m_iNumMBRef; iMB++ ) {
				*pmbmdRef = *pmbmdRefSrc;

			if ( pvopc->m_volmd.iEnhnType != 0  && // modified by Sharp (98/3/24)
				(((pvopc->m_vopmd.iRefSelectCode == 1 || pvopc->m_vopmd.iRefSelectCode == 2) && pvopc->m_vopmd.vopPredType == PVOP) ||
	
	(3-6) line 1987
	  pvopc->m_pvopcRefQ1 = new CVOPU8YUVBA ( *m_pvopcBuf );
		pvopc->m_tFutureRef = m_t;
		if ( pvopc->m_volmd.iEnhnType != 0  && // modified by Sharp (98/3/24)
			(((pvopc->m_vopmd.iRefSelectCode == 1 || pvopc->m_vopmd.iRefSelectCode == 2) && pvopc->m_vopmd.vopPredType == PVOP) ||
	
	(3-7) line 2016
	  for (Int iMB=0; iMB<m_iNumMBRef; iMB++ ) {
			*pmbmdRef = *pmbmdRefSrc;
			if ( pvopc->m_volmd.iEnhnType != 0 ) { // modified by Sharp (98/3/24)
				pmbmdRef->m_shpmd = ALL_OPAQUE;
			}
	
	(3-8) line 2103
	    Void bg_comp_each(PixelC* curr, PixelC* prev, PixelC* next, PixelC* mask_curr, PixelC* mask_prev, PixelC* mask_next, 
					      Int curr_t, Int prev_t, Int next_t, Int width, Int height, Int CoreMode); // modified by Sharp (98/3/24)
			Void inv_convertYuv(const CVOPU8YUVBA* pvopcSrc, PixelC* destY, PixelC* destU, PixelC* destV, Int width, Int height);
	
	(3-9) line 2164
	// begin: modified by Sharp (98/3/24)
	    bg_comp_each(currY, prevY, nextY, currBY,  prevBY,  nextBY,  iFrame, iPrev, iNext, width,   height, m_volmd.iEnhnType == 2);
			bg_comp_each(currU, prevU, nextU, currBUV, prevBUV, nextBUV, iFrame, iPrev, iNext, width/2, height/2, m_volmd.iEnhnType == 2);
			bg_comp_each(currV, prevV, nextV, currBUV, prevBUV, nextBUV, iFrame, iPrev, iNext, width/2, height/2, m_volmd.iEnhnType == 2);
	// end: modified by Sharp (98/3/24)

	(3-10) line:1069 The following part is modified.

	// Time code
        /*modified by SONY (98/03/30) */
        Time tGOVCode = ((Int)(t * m_volmd.iClockRate / m_volmd.dFrameHz)) / m_volmd.iClockRate;
        /*modified by SONY (98/03/30) End*/
        /*              ORIGINAL
        Time tGOVCode = ((Int)(t * m_volmd.iClockRate / m_volmd.dFrameHz) - m_volmd.iBbetweenP)
			/ m_volmd.iClockRate;
        */

(4) sys/decoder/vopsedec.cpp
	(4-1) line 755
Int BGComposition; // added by Sharp (98/3/24)

Bool CVideoObjectDecoder::decodeVOPHead ()
{

	(4-2) line 871
		m_rctCurrVOPY = CRct (left, top, left + width, top + height);
		m_rctCurrVOPUV = m_rctCurrVOPY.downSampleBy2 ();

		if ( m_volmd.volType == ENHN_LAYER && m_volmd.iEnhnType == 1 ){
			BGComposition = m_pbitstrmIn -> getBits (1); // modified by Sharp (98/3/24)
//      assert(BackgroundComposition==1); // modified by Sharp (98/3/24)
		}
	
	(4-3) line 1330
	    Void bg_comp_each(PixelC* curr, PixelC* prev, PixelC* next, PixelC* mask_curr, PixelC* mask_prev, PixelC* mask_next, 
					      Int curr_t, Int prev_t, Int next_t, Int width, Int height, Int CoreMode); // modified by Sharp (98/3/24)
			Void inv_convertYuv(const CVOPU8YUVBA* pvopcSrc, PixelC* destY, PixelC* destU, PixelC* destV, Int width, Int height);

	(4-4) line 1390
	// begin: modified by Sharp (98/3/24)
	    bg_comp_each(currY, prevY, nextY, currBY,  prevBY,  nextBY,  iFrame, iPrev, iNext, width,   height, BGComposition == 0);
			bg_comp_each(currU, prevU, nextU, currBUV, prevBUV, nextBUV, iFrame, iPrev, iNext, width/2, height/2, BGComposition == 0);
			bg_comp_each(currV, prevV, nextV, currBUV, prevBUV, nextBUV, iFrame, iPrev, iNext, width/2, height/2, BGComposition == 0);
	// end: modified by Sharp (98/3/24)

	(4-5) line :107 The following lines are added.
/* (98/03/30 added by SONY)*/
	m_bLinkisBroken = FALSE;
	m_bUseGOV = FALSE;
/* (98/03/30 added by SONY)*/



	(4-6) line:278 The following part is modified.
/* (98/03/30) modified by SONY */
                if(m_vopmd.vopPredType == BVOP && m_vopmd.iRefSelectCode == 0) {
                        m_tPastRef = m_tFutureRef;
                        m_tFutureRef = m_t;
                        m_iBCount = 0;
                } if(m_vopmd.vopPredType == PVOP && m_vopmd.iRefSelectCode == 3) {
                        m_tPastRef = m_t;
                        m_tFutureRef = m_t;
                        m_iBCount = 0;
                }
/* (98/03/30) modified by SONY */
/*              ORIGINAL 
                if(m_vopmd.vopPredType==IVOP || m_vopmd.vopPredType==PVOP ||
                  (m_vopmd.vopPredType == BVOP && m_vopmd.iRefSelectCode == 0)) {
                        m_tPastRef = m_tFutureRef;
                        m_tFutureRef = m_t;
                        m_iBCount = 0;
                }
                ORIGINAL end*/

	(4-7) line:307 The follow line is added.

	switch(m_vopmd.vopPredType)
        {
        case IVOP:
                cout << "\tIVOP";
/*Added by SONY (98/03/30)*/
                if(m_bLinkisBroken == TRUE && m_bUseGOV == TRUE)        m_bLinkisBroken = FALSE;
/*Added by SONY (98/03/30) END*/
                break;
        case PVOP:

	(4-8) line:321 The following lines are added.

        cout.flush ();
/* Added by SONY (98/03/30)*/
        if(m_bLinkisBroken == TRUE && m_bUseGOV == TRUE)
                fprintf(stderr,"WARNING: broken_link = 1  --- Output image must be broken.\n");
/*Added by SONY (98/03/30) End*/
        if (m_volmd.fAUsage != RECTANGLE)
                resetBYPlane ();

	(4-9) line:735 The following lines are added.
        if (uiVopStartCode == GOV_START_CODE) {

/*Added by SONY (98/03/30)*/
                m_bUseGOV = TRUE;
                m_bLinkisBroken = FALSE;
/*Added by SONY (98/03/30) End */

                Int timecode;


	(4-10) line:746 The following part is modified.

                Int broken_link = m_pbitstrmIn -> getBits (1);
/*modified by SONY (98/03/30)*/
                if ((closed_gov == 0)&&(broken_link == 1))
                        m_bLinkisBroken = TRUE;
/*modified by SONY (98/03/30) End*/
/*              ORIGINAL
                if ((closed_gov == 0)&&(broken_link == 1))
                        {
                        fprintf(stderr,"closed_gov = 0\nbroken_link = 1\n");
                        exit(0);
                        }
*/

	(4-11) line 1237
	  m_bUseGOV = TRUE; // added by Sharp (98/3/31)
		m_bLinkisBroken = FALSE; // added by Sharp (98/3/31)
		Int timecode;
		timecode = m_pbitstrmIn -> getBits (5) * 3600;
		timecode += m_pbitstrmIn -> getBits (6) * 60;
		m_pbitstrmIn -> getBits (1);
		timecode += m_pbitstrmIn -> getBits (6);
		m_tModuloBaseDecd = timecode;
		m_tModuloBaseDisp = timecode;

		//    cout << "GOV Header (t=" << timecode << ")\n\n";
		Int closed_gov = m_pbitstrmIn -> getBits (1);
		Int broken_link = m_pbitstrmIn -> getBits (1);
		if ((closed_gov == 0)&&(broken_link == 1)) // modified by Sharp (98/3/31)
			m_bLinkisBroken = TRUE; // modified by Sharp (98/3/31)
		// begin: deleted by Sharp (98/3/31)
		// if ((closed_gov == 0)&&(broken_link == 1))
		// {
		// 	fprintf(stderr,"closed_gov = 0\nbroken_link = 1\n");
		// 	exit(0);
    // }
		// end: deleted by Sharp (98/3/31)


(5) sys/tps_bfshape.cpp
	(5-1) line 153
	Void bg_comp_each(PixelC* f_curr, PixelC* f_prev, PixelC* f_next, PixelC* mask_curr, PixelC* mask_prev, PixelC* mask_next, Int curr_t, Int prev_t, Int next_t, Int width, Int height, Int CoreMode) // modified by Sharp (98/3/24)
	{

	(5-2) line 163
	// begin: added by Sharp (98/3/24)
		if ( CoreMode ){
			for(i=0; i<width*height; i++)
				if(mask_curr[i] == 0 )         // should be used after Type 1 is implemented 
					f_curr[i] = f_prev[i];
		}
		else {
	// end: added by Sharp (98/3/24)

	(5-4) line 197
	  for(i=0; i<width*height; i++)
		  if(mask_curr[i] == 0 )         // should be used after Type 1 is implemented 
			f_curr[i] = out_image[i];
	} // added by Sharp (98/3/24)


(6) sys/vopses.hpp  
line :370 The following lines are added.

/*Added by SONY (98/03/30)*/
	Bool m_bUseGOV ;
	Bool m_bLinkisBroken;
/*Added by SONY (98/03/30)*/
