📄 sesenc.cpp
字号:
sprintf (pchTrace, ENHN_SUB_TRCFILE, m_pchOutStrFiles, iobj, m_pchPrefix); rgpostrm [ENHN_LAYER] = new ofstream (pchCmp, IOS_BINARY | ios::out); rgpostrmTrace [ENHN_LAYER] = NULL; if (volmd_enhn.bTrace) // modified by Sharp (98/2/12) rgpostrmTrace [ENHN_LAYER] = new ofstream (pchTrace);// begin: added by Sharp (98/10/26) if ( volmd_enhn.bTemporalScalability == TRUE ){ rgpfReconYUV [ENHN_LAYER] = rgpfReconYUV[BASE_LAYER]; if (volmd_enhn.fAUsage != RECTANGLE) { if ( volmd_enhn.iEnhnType == 0 ) rgpfReconSeg [ENHN_LAYER] = rgpfReconSeg[BASE_LAYER]; else{ sprintf (pchSeg, ENHN_SUB_SEGFILE, m_pchReconYUVDir, iobj, m_pchPrefix); rgpfReconSeg [ENHN_LAYER] = fopen (pchSeg, "wb"); // reconstructed seg file } } } else {// end: added by Sharp (98/10/26) sprintf (pchYUV, ENHN_SUB_YUVFILE, m_pchReconYUVDir, iobj, m_pchPrefix); sprintf (pchSeg, ENHN_SUB_SEGFILE, m_pchReconYUVDir, iobj, m_pchPrefix); rgpfReconYUV [ENHN_LAYER] = fopen (pchYUV, "wb"); // reconstructed YUV file if (volmd_enhn.fAUsage != RECTANGLE) { // modified by Sharp (98/2/12) rgpfReconSeg [ENHN_LAYER] = fopen (pchSeg, "wb"); // reconstructed seg file// deleted by Sharp (98/10/26) // begin: added by Sharp (98/2/10) // if ( volmd.bTemporalScalability == TRUE ) // assert (rgpfReconSeg [ENHN_LAYER] != NULL); // else // end: added by Sharp (98/2/10)// end: deleted by Sharp (98/10/26) assert (FALSE); // no spatial scalability for shape } } // added by Sharp (98/10/26) if ( volmd_enhn.bTemporalScalability == FALSE ){ // added by Sharp (98/2/10) if (!m_bTexturePerVOP) { fprintf (stderr,"m_bTexturePerVOP != 0 is not applyed for spatial scalable coding\n"); } else sprintf (pchYUV, ENHN_SUB_YUVFILE, m_pchBmpFiles, iobj, m_pchPrefix); pfYuvSrcSpatialEnhn = fopen (pchYUV, "rb"); if (pfYuvSrcSpatialEnhn == NULL){ fprintf (stderr,"can't open %s\n", pchYUV); exit(1); } } // added by Sharp (98/2/10) } if (volmd.fAUsage != RECTANGLE || m_rgbSpatialScalability [iobj - m_iFirstVO] == TRUE && volmd_enhn.fAUsage != RECTANGLE) { // load Alpha // modified by Sharp (98/2/12) if (!m_bAlphaPerVOP) { pxlcObjColor = iobj; sprintf (pchSeg, ROOT_SEGFILE, m_pchBmpFiles, m_pchPrefix); } else { pxlcObjColor = opaqueValue; // out data notation sprintf (pchSeg, SUB_SEGFILE, m_pchBmpFiles, iobj, m_pchPrefix); } pfAlpSrc = fopen (pchSeg, "rb"); if (pfAlpSrc == NULL) { fprintf (stderr, "can't open %s\n", pchSeg); exit (1); } }// begin: deleted by Sharp (98/10/26) // begin: added by Sharp (98/2/10) // #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; // sprintf (pchYUV, "%s/%2.2d/%s_bgc.yuv", m_pchReconYUVDir, iobj, m_pchPrefix); // pfTemp = fopen (pchYUV, "wb"); // clear file pointer for background composition // fclose(pfTemp); // } // #endif // end: added by Sharp (98/2/10)// end: deleted by Sharp (98/10/26)}Void CSessionEncoder::initVOEncoder (CVideoObjectEncoder** rgpvoenc, Int iobj, ofstream* rgpostrmTrace []){ Int iVOidx = iobj - m_iFirstVO; Bool bTemporalScalability = m_rgvolmd[BASE_LAYER][iVOidx].bTemporalScalability; // added by Sharp (98/2/10)// Bool bTemporalScalability = TRUE; // added by Sharp (98/2/10) if (m_rgbSpatialScalability [iVOidx] == TRUE) { rgpvoenc [BASE_LAYER] = new CVideoObjectEncoder ( iobj, m_rgvolmd [BASE_LAYER] [iVOidx], m_rgvopmd [BASE_LAYER] [iVOidx], m_iFirstFrame, m_iLastFrame, m_rctOrg.width, m_rctOrg.height(), m_rguiRateControl [BASE_LAYER] [iVOidx], m_rguiBudget [BASE_LAYER] [iVOidx], rgpostrmTrace [BASE_LAYER], m_rguiWarpingAccuracy [iVOidx], m_rgNumOfPnts [iVOidx], m_pppstDst [iVOidx], m_SptMode, m_rctFrame, m_rctOrg, m_rgiMVFileUsage [BASE_LAYER][iVOidx], m_pchMVFileName [BASE_LAYER][iVOidx]);// begin: added by Sharp (98/2/10) if ( bTemporalScalability ) rgpvoenc [ENHN_LAYER] = new CVideoObjectEncoder ( iobj, m_rgvolmd [ENHN_LAYER] [iVOidx], m_rgvopmd [ENHN_LAYER] [iVOidx], m_iFirstFrame, m_iLastFrame, m_rctOrg.width, m_rctOrg.height(), m_rguiRateControl [ENHN_LAYER] [iVOidx], m_rguiBudget [ENHN_LAYER] [iVOidx], rgpostrmTrace [ENHN_LAYER], 0, -1, m_pppstDst [iVOidx], m_SptMode, m_rctFrame, m_rctOrgSpatialEnhn, m_rgiMVFileUsage [ENHN_LAYER][iVOidx], m_pchMVFileName [ENHN_LAYER][iVOidx]); else// end: added by Sharp (98/2/10) rgpvoenc [ENHN_LAYER] = new CVideoObjectEncoder ( iobj, m_rgvolmd [ENHN_LAYER] [iVOidx], m_rgvopmd [ENHN_LAYER] [iVOidx], m_iFirstFrame, m_iLastFrame, m_rctOrgSpatialEnhn.width, m_rctOrgSpatialEnhn.height (), m_rguiRateControl [ENHN_LAYER] [iVOidx], m_rguiBudget [ENHN_LAYER] [iVOidx], rgpostrmTrace [ENHN_LAYER], 0, -1, m_pppstDst [iVOidx], m_SptMode, m_rctFrame, m_rctOrgSpatialEnhn, m_rgiMVFileUsage [ENHN_LAYER][iVOidx], m_pchMVFileName [ENHN_LAYER][iVOidx]); } else { rgpvoenc [BASE_LAYER] = new CVideoObjectEncoder ( iobj, m_rgvolmd [BASE_LAYER] [iVOidx], m_rgvopmd [BASE_LAYER] [iVOidx], m_iFirstFrame, m_iLastFrame, m_rctOrg.width, m_rctOrg.height (), m_rguiRateControl [BASE_LAYER] [iVOidx], m_rguiBudget [BASE_LAYER] [iVOidx], rgpostrmTrace [BASE_LAYER], m_rguiWarpingAccuracy [iVOidx], m_rgNumOfPnts [iVOidx], m_pppstDst [iVOidx], m_SptMode, m_rctFrame, m_rctOrg, m_rgiMVFileUsage [BASE_LAYER][iVOidx], m_pchMVFileName [BASE_LAYER][iVOidx]); }}Bool CSessionEncoder::loadData (UInt iFrame, FILE* pfYuvSrc, FILE* pfSegSrc, PixelC pxlcObjColor, CVOPU8YUVBA* pvopcDst, CRct& rctOrg, const VOLMode& volmd){ Int iLeadingPixels = iFrame * rctOrg.area (); if (volmd.nBits<=8) { fseek (pfYuvSrc, iLeadingPixels + iLeadingPixels / 2, SEEK_SET); //4:2:0 } else { // NBIT: 2 bytes per pixel, Y component plus UV fseek (pfYuvSrc, iLeadingPixels * 3, SEEK_SET); } if (volmd.fAUsage != RECTANGLE) fseek (pfSegSrc, iLeadingPixels, SEEK_SET); Int iYDataHeight = rctOrg.height (); Int iUVDataHeight = rctOrg.height () / 2; Int iYFrmWidth = pvopcDst->whereY ().width; Int iUvFrmWidth = pvopcDst->whereUV ().width; Int nSkipYPixel = iYFrmWidth * EXPANDY_REF_FRAME + EXPANDY_REF_FRAME; Int nSkipUvPixel = iUvFrmWidth * EXPANDUV_REF_FRAME + EXPANDUV_REF_FRAME; PixelC* ppxlcY = (PixelC*) pvopcDst->pixelsY () + nSkipYPixel; PixelC* ppxlcU = (PixelC*) pvopcDst->pixelsU () + nSkipUvPixel; PixelC* ppxlcV = (PixelC*) pvopcDst->pixelsV () + nSkipUvPixel; CoordI y,x; for (y = 0; y < iYDataHeight; y++) { Int size = (Int) fread (ppxlcY, sizeof (PixelC), rctOrg.width, pfYuvSrc); if (size == 0) fprintf (stderr, "Unexpected end of file\n"); ppxlcY += iYFrmWidth; } /* modified by Rockwell (98/05/08) if (volmd.nBits<=8) {*/ for (y = 0; y < iUVDataHeight; y++) { Int size = (Int) fread (ppxlcU, sizeof (PixelC), rctOrg.width / 2, pfYuvSrc); if (size == 0) fprintf (stderr, "Unexpected end of file\n"); ppxlcU += iUvFrmWidth; } for (y = 0; y < iUVDataHeight; y++) { Int size = (Int) fread (ppxlcV, sizeof (PixelC), rctOrg.width / 2, pfYuvSrc); if (size == 0) fprintf (stderr, "Unexpected end of file\n"); ppxlcV += iUvFrmWidth; } /* modified by Rockwell (98/05/08) } else { // NBIT: fill UV space with default pixel value Int iDefval = 1<<(volmd.nBits-1); Int iUVDataWidth = rctOrg.width / 2; for (y = 0; y < iUVDataHeight; y++) { for (x = 0; x < iUVDataWidth; x++) { ppxlcU[x] = iDefval; ppxlcV[x] = iDefval; } ppxlcU += iUvFrmWidth; ppxlcV += iUvFrmWidth; } } */ PixelC* ppxlcBY = (PixelC*) pvopcDst->pixelsBY () + nSkipYPixel; Int iObjectExist = 0; if (volmd.fAUsage == ONE_BIT) { // load Alpha //binary for (y = 0; y < iYDataHeight; y++) { for (x = 0; x < rctOrg.width; x++) { PixelC pxlcCurr = getc (pfSegSrc); ppxlcBY [x] = (pxlcCurr == pxlcObjColor) ? opaqueValue : transpValue; iObjectExist += ppxlcBY [x]; } ppxlcBY += iYFrmWidth; } ((CU8Image*) pvopcDst->getPlane (BUV_PLANE))->decimateBinaryShapeFrom (*(pvopcDst->getPlane (BY_PLANE))); } else if (volmd.fAUsage == EIGHT_BIT) { // load Alpha //gray PixelC* ppxlcA = (PixelC*) pvopcDst->pixelsA () + nSkipYPixel; for (y = 0; y < iYDataHeight; y++) { for (x = 0; x < rctOrg.width; x++) { PixelC pxlcCurr = getc (pfSegSrc); ppxlcA [x] = (pxlcCurr >= GRAY_ALPHA_THRESHOLD) ? pxlcCurr : transpValue; ppxlcBY [x] = (pxlcCurr >= GRAY_ALPHA_THRESHOLD) ? opaqueValue : transpValue; iObjectExist += ppxlcBY [x]; } ppxlcBY += iYFrmWidth; ppxlcA += iYFrmWidth; } ((CU8Image*) pvopcDst->getPlane (BUV_PLANE))->decimateBinaryShapeFrom (*(pvopcDst->getPlane (BY_PLANE))); } else //rectangle iObjectExist = 1;/* static int ini = 0; if(ini = 0) { srand(123421); ini = 1; } int k = rand(); if((k%4)==0) iObjectExist = 0;*/ return (iObjectExist != 0);}CRct CSessionEncoder::findBoundBoxInAlpha (UInt ifr, UInt iobj){ CIntImage* pfiARet = NULL; Char pchSeg [100]; if (m_rgvolmd [BASE_LAYER] [iobj].fAUsage != RECTANGLE) { // load Alpha if (!m_bAlphaPerVOP) { sprintf (pchSeg, ROOT_SEGFILE, m_pchBmpFiles, m_pchPrefix); pfiARet = alphaFromCompFile (pchSeg, ifr, iobj, m_rctOrg); } else { sprintf (pchSeg, SUB_SEGFILE, m_pchBmpFiles, iobj, m_pchPrefix); pfiARet = new CIntImage (pchSeg, ifr, m_rctOrg); pfiARet -> threshold (64); } CRct rctBoundingBox = pfiARet -> whereVisible (); if (rctBoundingBox.left % 2 != 0) rctBoundingBox.left--; if (rctBoundingBox.top % 2 != 0) rctBoundingBox.top--; if (rctBoundingBox.right % 2 != 0) rctBoundingBox.right++; if (rctBoundingBox.bottom % 2 != 0) rctBoundingBox.bottom++; rctBoundingBox.width = rctBoundingBox.right - rctBoundingBox.left; delete pfiARet; return rctBoundingBox; } else return m_rctOrg;}CRct CSessionEncoder::findSptRct (UInt iobj){ CRct rctSpt; Char pchSpt [100]; sprintf (pchSpt, SUB_VDLFILE, m_pchSptDir, iobj, m_pchPrefix); FILE* pf = fopen (pchSpt, "rb"); // read overhead Int c0 = getc (pf); Int c1 = getc (pf); Int c2 = getc (pf); assert (c0 == 'S' && (c1 == 'P' || c2 == 'T') ); fread (&rctSpt.left, sizeof (CoordI), 1, pf); fread (&rctSpt.top, sizeof (CoordI), 1, pf); fread (&rctSpt.right, sizeof (CoordI), 1, pf); fread (&rctSpt.bottom, sizeof (CoordI), 1, pf); assert (rctSpt.left % 2 == 0); assert (rctSpt.top % 2 == 0); rctSpt.width = rctSpt.right - rc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -