📄 vop.cpp
字号:
} Int val = (Int) ((beta + alpha - alpha * beta) * 255. + .5f); ppxlThisX -> pxlU.rgb.a = (U8) checkrange (val, 0, 255); ppxlThisX++; ppxlVop++; } ppxlThisY += widthCurr; }}Void CVideoObjectPlane::setPlane (const CFloatImage& fi, RGBA pxlCom){ if (!valid ()) return; assert (where () == fi.where ()); CPixel* ppxlVop = (CPixel*) pixels (); const PixelF* ppxlFi = fi.pixels (); UInt area = where ().area (); for (UInt ip = 0; ip < area; ip++) { Int value = checkrange ((Int) (*ppxlFi + .5), 0, 255); ppxlVop -> pxlU.color [pxlCom] = (U8) value; ppxlVop++; ppxlFi++; }}Void CVideoObjectPlane::setPlane (const CIntImage& ii, RGBA pxlCom){ if (!valid ()) return; assert (where () == ii.where ()); CPixel* ppxlVop = (CPixel*) pixels (); const PixelI* ppxli = ii.pixels (); UInt area = where ().area (); for (UInt ip = 0; ip < area; ip++) { Int value = checkrange (*ppxli, 0, 255); ppxlVop -> pxlU.color [pxlCom] = (U8) value; ppxlVop++; ppxli++; }}Void CVideoObjectPlane::setPlane (const CU8Image& ci, RGBA pxlCom){ if (!valid ()) return; assert (where () == ci.where ()); CPixel* ppxlVop = (CPixel*) pixels (); const PixelC* ppxlc = ci.pixels (); UInt area = where ().area (); for (UInt ip = 0; ip < area; ip++) { Int value = checkrange (*ppxlc, 0U, 255U); ppxlVop -> pxlU.color [pxlCom] = (U8) value; ppxlVop++; ppxlc++; }}Void CVideoObjectPlane::getDownSampledPlane(CFloatImage &fiDst,Int iPlane,Int iSx,Int iSy){ Int iDstWidth = fiDst.where().width; Int iDstHeight = fiDst.where().height(); Int iSrcWidth = where().width; Int iSrcHeight = where().height(); PixelF *ppxlfDst = (PixelF *)fiDst.pixels(); const CPixel *ppxlSrc = pixels(); assert(iDstWidth == iSrcWidth/iSx && iDstHeight == iSrcHeight/iSy); Int iSrcStep = iSrcWidth*iSy; Int iX,iY,iXX; for(iY=0;iY<iDstHeight;iY++,ppxlSrc+=iSrcStep) for(iX=0,iXX=0;iX<iDstWidth;iX++,iXX+=iSx) *ppxlfDst++ = ppxlSrc[iXX].pxlU.color[iPlane];}Void CVideoObjectPlane::setUpSampledPlane(const CFloatImage &fiSrc,Int iPlane,Int iSx,Int iSy){ Int iSrcWidth = fiSrc.where().width; Int iSrcHeight = fiSrc.where().height(); Int iDstWidth = where().width; Int iDstHeight = where().height(); const PixelF *ppxlfSrc = fiSrc.pixels(); CPixel *ppxlDst = (CPixel *)pixels(); assert(iSrcWidth == iDstWidth/iSx && iSrcHeight == iDstHeight/iSy); Int iCx,iCy,iXX,iX,iY; for(iCy=0,iY=0;iY<iDstHeight;iY++) { for(iCx=0,iXX=iX=0;iX<iDstWidth;iX++,ppxlDst++) { ppxlDst->pxlU.color[iPlane] = checkrange ((Int) (ppxlfSrc[iXX] + .5), 0, 255); iCx++; if(iCx==iSx) { iXX++; iCx=0; } } iCy++; if(iCy==iSy) { ppxlfSrc+=iSrcWidth; iCy=0; } }}Void CVideoObjectPlane::getDownSampledPlane(CIntImage &iiDst,Int iPlane,Int iSx,Int iSy){ Int iDstWidth = iiDst.where().width; Int iDstHeight = iiDst.where().height(); Int iSrcWidth = where().width; Int iSrcHeight = where().height(); PixelI *ppxliDst = (PixelI *)iiDst.pixels(); const CPixel *ppxlSrc = pixels(); assert(iDstWidth == iSrcWidth/iSx && iDstHeight == iSrcHeight/iSy); Int iSrcStep = iSrcWidth*iSy; Int iX,iY,iXX; for(iY=0;iY<iDstHeight;iY++,ppxlSrc+=iSrcStep) for(iX=0,iXX=0;iX<iDstWidth;iX++,iXX+=iSx) *ppxliDst++ = ppxlSrc[iXX].pxlU.color[iPlane];}Void CVideoObjectPlane::setUpSampledPlane(const CIntImage &iiSrc,Int iPlane,Int iSx,Int iSy){ Int iSrcWidth = iiSrc.where().width; Int iSrcHeight = iiSrc.where().height(); Int iDstWidth = where().width; Int iDstHeight = where().height(); const PixelI *ppxliSrc = iiSrc.pixels(); CPixel *ppxlDst = (CPixel *)pixels(); assert(iSrcWidth == iDstWidth/iSx && iSrcHeight == iDstHeight/iSy); Int iCx,iCy,iXX,iX,iY,iVal; for(iCy=0,iY=0;iY<iDstHeight;iY++) { for(iCx=0,iXX=iX=0;iX<iDstWidth;iX++,ppxlDst++) { iVal=ppxliSrc[iXX]; ppxlDst->pxlU.color[iPlane] = ( (iVal>255) ? 255 : ((iVal<0)?0:iVal) ); iCx++; if(iCx==iSx) { iXX++; iCx=0; } } iCy++; if(iCy==iSy) { ppxliSrc+=iSrcWidth; iCy=0; } }}Void CVideoObjectPlane::rgbToYUV () // transform from rgb to yuv{ if (!valid ()) return; CPixel* ppxl = (CPixel*) pixels (); UInt area = where ().area (); for (UInt ip = 0; ip < area; ip++) { Int y = (Int) ((Double) (0.257 * ppxl -> pxlU.rgb.r + 0.504 * ppxl -> pxlU.rgb.g + 0.098 * ppxl -> pxlU.rgb.b + 16) + .5); Int cb = (Int) ((Double) (0.439 * ppxl -> pxlU.rgb.r - 0.368 * ppxl -> pxlU.rgb.g - 0.071 * ppxl -> pxlU.rgb.b + 128) + .5); Int cr = (Int) ((Double) (-0.148 * ppxl -> pxlU.rgb.r - 0.291 * ppxl -> pxlU.rgb.g + 0.439 * ppxl -> pxlU.rgb.b + 128) + .5); ppxl -> pxlU.yuv.y = (U8) y; ppxl -> pxlU.yuv.u = (U8) cr; ppxl -> pxlU.yuv.v = (U8) cb; ppxl++; }}Void CVideoObjectPlane::yuvToRGB () // transform from yuv to rgb{ if (!valid ()) return; CPixel* ppxl = (CPixel*) pixels (); UInt area = where ().area (); for (UInt ip = 0; ip < area; ip++) { Double var = 1.164 * (ppxl -> pxlU.yuv.y - 16); Int r = (Int) ((Double) (var + 1.596 * (ppxl -> pxlU.yuv.v - 128)) + .5); Int g = (Int) ((Double) (var - 0.813 * (ppxl -> pxlU.yuv.v - 128) - 0.391 * (ppxl -> pxlU.yuv.u - 128)) + .5); Int b = (Int) ((Double) (var + 2.018 * (ppxl -> pxlU.yuv.u - 128)) + .5); ppxl -> pxlU.rgb.r = (U8) checkrange (r, 0, 255); ppxl -> pxlU.rgb.g = (U8) checkrange (g, 0, 255); ppxl -> pxlU.rgb.b = (U8) checkrange (b, 0, 255); ppxl++; }}own CVideoObjectPlane* CVideoObjectPlane::operator * (const CTransform& tf) const{ CVideoObjectPlane* pvopRet = tf.transform_apply (*this); return pvopRet; }own CVideoObjectPlane* CVideoObjectPlane::operator - (const CVideoObjectPlane& vop) const{ // make the difference in the intersection area if (!valid () || !vop.valid ()) return NULL; CRct rctSrc = vop.where (); CRct rctDes = where (); CRct rctInt = rctSrc; rctInt.clip (rctDes); CVideoObjectPlane* pvopDiff = new CVideoObjectPlane (rctInt); UInt offsetSrc = rctSrc.width - rctInt.width; UInt offsetDes = rctDes.width - rctInt.width; CPixel* ppxlRet = (CPixel*) pvopDiff -> pixels (); CPixel* ppxlDes = (CPixel*) pixels (rctInt.left, rctInt.top); CPixel* ppxlSrc = (CPixel*) vop.pixels (rctInt.left, rctInt.top); for (CoordI j = rctInt.top; j < rctInt.bottom; j++) { for (CoordI i = rctInt.left; i < rctInt.right; i++) { ppxlRet -> pxlU.rgb.r = (U8) checkrange (ppxlDes -> pxlU.rgb.r - ppxlSrc -> pxlU.rgb.r + 128, 0, 255); ppxlRet -> pxlU.rgb.g = (U8) checkrange (ppxlDes -> pxlU.rgb.g - ppxlSrc -> pxlU.rgb.g + 128, 0, 255); ppxlRet -> pxlU.rgb.b = (U8) checkrange (ppxlDes -> pxlU.rgb.b - ppxlSrc -> pxlU.rgb.b + 128, 0, 255); ppxlRet -> pxlU.rgb.a = (ppxlDes -> pxlU.rgb.a == ppxlSrc -> pxlU.rgb.a) ? opaqueValue : transpValue; ppxlRet++; ppxlDes++; ppxlSrc++; } ppxlDes += offsetDes; ppxlSrc += offsetSrc; } return pvopDiff;}Void CVideoObjectPlane::vdlDump (const Char* fileName, CPixel ppxlFalse) const{ if (!valid ()) return; FILE* pf = fopen (fileName, "wb"); // write overhead putc ('V', pf); putc ('M', pf); CoordI cord = (CoordI) where ().left; fwrite (&cord, sizeof (CoordI), 1, pf); cord = (CoordI) where ().top; fwrite (&cord, sizeof (CoordI), 1, pf); cord = (CoordI) where ().right; fwrite (&cord, sizeof (CoordI), 1, pf); cord = (CoordI) where ().bottom; fwrite (&cord, sizeof (CoordI), 1, pf); // dump the actual data UInt area = where ().area (); const CPixel* ppxl = pixels (); for (UInt ip = 0; ip < area; ip++, ppxl++) { CPixel pp = *ppxl; if (ppxl -> pxlU.rgb.a == transpValue) { pp.pxlU.rgb.r = ppxlFalse.pxlU.rgb.r; pp.pxlU.rgb.g = ppxlFalse.pxlU.rgb.g; pp.pxlU.rgb.b = ppxlFalse.pxlU.rgb.b; } fwrite (&pp, sizeof (CPixel), 1, pf); } fclose (pf);}Void CVideoObjectPlane::vdlByteDump (const Char* fileName, CPixel ppxlFalse) const{ if (!valid ()) return; FILE* pf = fopen (fileName, "wb"); // write overhead putc ('V', pf); putc ('B', pf); int left, top, right, bottom; left = where ().left; top = where ().top; right = where ().right; bottom = where ().bottom; U8 byte1, byte2; byte1 = (left>0)? 128:0; left = abs (left); byte1 += left / 256; byte2 = left % 256; putc (byte1,pf); putc (byte2,pf); byte1 = (top>0)? 128:0; top = abs (top); byte1 += top / 256; byte2 = top % 256; putc (byte1, pf); putc (byte2, pf); byte1 = (right>0)? 128:0; right = abs (right); byte1 += right / 256; byte2 = right % 256; putc(byte1,pf); putc(byte2,pf); byte1 = (bottom>0)? 128:0; bottom = abs (bottom); byte1 += bottom / 256; byte2 = bottom % 256; putc(byte1,pf); putc(byte2,pf); // dump the actual data UInt area = where ().area (); const CPixel* ppxl = pixels (); for (UInt ip = 0; ip < area; ip++, ppxl++) { CPixel pp = *ppxl; if (ppxl -> pxlU.rgb.a == transpValue) { pp.pxlU.rgb.r = ppxlFalse.pxlU.rgb.r; pp.pxlU.rgb.g = ppxlFalse.pxlU.rgb.g; pp.pxlU.rgb.b = ppxlFalse.pxlU.rgb.b; } fwrite (&pp, sizeof (CPixel), 1, pf); } fclose (pf);}Void CVideoObjectPlane::dump (FILE* pfFile, ChromType chrType) const{ if (!valid ()) return; Int iWidth = where ().width, iHeight = where ().height (); Int iUVWidth = iWidth, iUVHeight = iHeight; UInt uiXSubsample = 1, uiYSubsample = 1; if (chrType == FOUR_TWO_TWO) { uiXSubsample = 2; iUVWidth = (iWidth + 1) / uiXSubsample; } else if (chrType == FOUR_TWO_ZERO) { uiXSubsample = 2; uiYSubsample = 2; iUVWidth = (iWidth + 1) / uiXSubsample; iUVHeight = (iHeight + 1) / uiYSubsample; } UInt iUVArea = iUVWidth * iUVHeight; UInt area = where ().area (); // allocate mem for buffers U8* pchyBuffer = new U8 [area]; U8* pchuBuffer = new U8 [iUVArea]; U8* pchvBuffer = new U8 [iUVArea]; U8* pchyBuffer0 = pchyBuffer; U8* pchuBuffer0 = pchuBuffer; U8* pchvBuffer0 = pchvBuffer; // assign buffers to a vframe const CPixel* p = pixels (); for (CoordI y = 0; y < iHeight; y++) { if ((y % uiYSubsample) == 1) { pchuBuffer -= iUVWidth; pchvBuffer -= iUVWidth; } for (CoordI x = 0; x < iWidth; x++) { if ((x % uiXSubsample) == 0) { *pchuBuffer = p -> pxlU.yuv.u; *pchvBuffer = p -> pxlU.yuv.v; pchuBuffer++; pchvBuffer++; } *pchyBuffer++ = p -> pxlU.yuv.y; p++; } } // write data from a file Int size = fwrite (pchyBuffer0, sizeof (U8), area, pfFile); assert (size != 0); size = (Int) fwrite (pchuBuffer0, sizeof (U8), iUVArea, pfFile); assert (size != 0); size = (Int) fwrite (pchvBuffer0, sizeof (U8), iUVArea, pfFile); assert (size != 0); delete [] pchyBuffer0; delete [] pchuBuffer0; delete [] pchvBuffer0;}Void CVideoObjectPlane::dumpAlpha (FILE* pfFile) const{ if (!valid ()) return; UInt area = where ().area (); const CPixel* ppxl = pixels (); for (UInt ip = 0; ip < area; ip++, ppxl++) putc (ppxl -> pxlU.rgb.a, pfFile);}Void CVideoObjectPlane::dumpAbekas (FILE* pfFile) const{ //dump in YCbCr but interlaced as per Abekas machine assert (valid ()); Int iWidth = where ().width, iHeight = where ().height (); assert (iWidth == 720); assert (iHeight == 486); //ccir 601 UInt uiXSubsample = 2; //always has to be FOUR_TWO_TWO) const CPixel* p = pixels (); for (CoordI y = 0; y < iHeight; y++) { for (CoordI x = 0; x < iWidth; x++) { if (x % uiXSubsample == 0) { putc(p -> pxlU.yuv.u, pfFile); putc(p -> pxlU.yuv.y, pfFile); } else { putc(p -> pxlU.yuv.v, pfFile); putc(p -> pxlU.yuv.y, pfFile); } p++; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -