// this converts write only to YUY2 if needed; and returns pointers to planes and pitches void YUY2Planes::ConvertVideoFrameToPlanes(PVideoFrame *pVF, unsigned char *VFPtrs[3], int *VFPitches) { if ((bYUY2Type) ) { // fill the planes YUY2ToPlanes((*pVF)->GetReadPtr(), (*pVF)->GetPitch()); // return pointers and pitches VFPtrs[0] = GetPtr(); VFPtrs[1] = GetPtrU(); VFPtrs[2] = GetPtrV(); VFPitches[0] = GetPitch(); VFPitches[1] = GetPitchUV(); VFPitches[2] = GetPitchUV(); } else { // return pointers and pitches VFPtrs[0] = (*pVF)->GetWritePtr(); VFPtrs[1] = (*pVF)->GetWritePtr(PLANAR_U); VFPtrs[2] = (*pVF)->GetWritePtr(PLANAR_V); VFPitches[0] = (*pVF)->GetPitch(); VFPitches[1] = (*pVF)->GetPitch(PLANAR_U); VFPitches[2] = (*pVF)->GetPitch(PLANAR_V); } }
PVideoFrame __stdcall MVSuper::GetFrame(int n, IScriptEnvironment* env) { const unsigned char *pSrcY, *pSrcU, *pSrcV; unsigned char *pDstY, *pDstU, *pDstV; const unsigned char *pSrcPelY, *pSrcPelU, *pSrcPelV; // unsigned char *pDstYUY2; int nSrcPitchY, nSrcPitchUV; int nDstPitchY, nDstPitchUV; int nSrcPelPitchY, nSrcPelPitchUV; // int nDstPitchYUY2; DebugPrintf("MSuper: Get src frame %d clip %d",n,child); PVideoFrame src = child->GetFrame(n, env); PVideoFrame srcPel; if (usePelClip) srcPel = pelclip->GetFrame(n, env); PVideoFrame dst = env->NewVideoFrame(vi); PROFILE_START(MOTION_PROFILE_YUY2CONVERT); if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 ) { if (!planar) { pSrcY = SrcPlanes->GetPtr(); pSrcU = SrcPlanes->GetPtrU(); pSrcV = SrcPlanes->GetPtrV(); nSrcPitchY = SrcPlanes->GetPitch(); nSrcPitchUV = SrcPlanes->GetPitchUV(); YUY2ToPlanes(src->GetReadPtr(), src->GetPitch(), nWidth, nHeight, pSrcY, nSrcPitchY, pSrcU, pSrcV, nSrcPitchUV, isse); if (usePelClip) { pSrcPelY = SrcPelPlanes->GetPtr(); pSrcPelU = SrcPelPlanes->GetPtrU(); pSrcPelV = SrcPelPlanes->GetPtrV(); nSrcPelPitchY = SrcPelPlanes->GetPitch(); nSrcPelPitchUV = SrcPelPlanes->GetPitchUV(); YUY2ToPlanes(srcPel->GetReadPtr(), srcPel->GetPitch(), srcPel->GetRowSize()/2, srcPel->GetHeight(), pSrcPelY, nSrcPelPitchY, pSrcPelU, pSrcPelV, nSrcPelPitchUV, isse); } } else { pSrcY = src->GetReadPtr(); pSrcU = pSrcY + src->GetRowSize()/2; pSrcV = pSrcU + src->GetRowSize()/4; nSrcPitchY = src->GetPitch(); nSrcPitchUV = nSrcPitchY; if (usePelClip) { pSrcPelY = srcPel->GetReadPtr(); pSrcPelU = pSrcPelY + srcPel->GetRowSize()/2; pSrcPelV = pSrcPelU + srcPel->GetRowSize()/4; nSrcPelPitchY = srcPel->GetPitch(); nSrcPelPitchUV = nSrcPelPitchY; } } // pDstY = DstPlanes->GetPtr(); // pDstU = DstPlanes->GetPtrU(); // pDstV = DstPlanes->GetPtrV(); // nDstPitchY = DstPlanes->GetPitch(); // nDstPitchUV = DstPlanes->GetPitchUV(); // planer data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5 pDstY = dst->GetWritePtr(); pDstU = pDstY + nSuperWidth; pDstV = pDstU + nSuperWidth/2; nDstPitchY = dst->GetPitch(); nDstPitchUV = nDstPitchY; } else { pSrcY = src->GetReadPtr(PLANAR_Y); pSrcU = src->GetReadPtr(PLANAR_U); pSrcV = src->GetReadPtr(PLANAR_V); nSrcPitchY = src->GetPitch(PLANAR_Y); nSrcPitchUV = src->GetPitch(PLANAR_U); if (usePelClip) { pSrcPelY = srcPel->GetReadPtr(PLANAR_Y); pSrcPelU = srcPel->GetReadPtr(PLANAR_U); pSrcPelV = srcPel->GetReadPtr(PLANAR_V); nSrcPelPitchY = srcPel->GetPitch(PLANAR_Y); nSrcPelPitchUV = srcPel->GetPitch(PLANAR_U); } pDstY = dst->GetWritePtr(PLANAR_Y); pDstU = dst->GetWritePtr(PLANAR_U); pDstV = dst->GetWritePtr(PLANAR_V); nDstPitchY = dst->GetPitch(PLANAR_Y); nDstPitchUV = dst->GetPitch(PLANAR_U); } PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT); PROFILE_START(MOTION_PROFILE_INTERPOLATION); pSrcGOF->Update(YUVPLANES, pDstY, nDstPitchY, pDstU, nDstPitchUV, pDstV, nDstPitchUV); pSrcGOF->SetPlane(pSrcY, nSrcPitchY, YPLANE); pSrcGOF->SetPlane(pSrcU, nSrcPitchUV, UPLANE); pSrcGOF->SetPlane(pSrcV, nSrcPitchUV, VPLANE); pSrcGOF->Reduce(nModeYUV); pSrcGOF->Pad(nModeYUV); if (usePelClip) { MVFrame *srcFrames = pSrcGOF->GetFrame(0); MVPlane *srcPlaneY = srcFrames->GetPlane(YPLANE); if (nModeYUV & YPLANE) srcPlaneY->RefineExt(pSrcPelY, nSrcPelPitchY, isPelClipPadded); MVPlane *srcPlaneU = srcFrames->GetPlane(UPLANE); if (nModeYUV & UPLANE) srcPlaneU->RefineExt(pSrcPelU, nSrcPelPitchUV, isPelClipPadded); MVPlane *srcPlaneV = srcFrames->GetPlane(VPLANE); if (nModeYUV & VPLANE) srcPlaneV->RefineExt(pSrcPelV, nSrcPelPitchUV, isPelClipPadded); } else { pSrcGOF->Refine(nModeYUV); } PROFILE_STOP(MOTION_PROFILE_INTERPOLATION); /* PROFILE_START(MOTION_PROFILE_YUY2CONVERT); if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 ) { pDstYUY2 = dst->GetWritePtr(); nDstPitchYUY2 = dst->GetPitch(); YUY2FromPlanes(pDstYUY2, nDstPitchYUY2, nSuperWidth, nSuperHeight, pDstY, nDstPitchY, pDstU, pDstV, nDstPitchUV, isse); } PROFILE_STOP(MOTION_PROFILE_YUY2CONVERT); */ PROFILE_CUMULATE(); return dst; }
PVideoFrame __stdcall MVDegrain1::GetFrame(int n, IScriptEnvironment* env) { int nWidth_B = nBlkX*(nBlkSizeX - nOverlapX) + nOverlapX; int nHeight_B = nBlkY*(nBlkSizeY - nOverlapY) + nOverlapY; PVideoFrame src = child->GetFrame(n, env); PVideoFrame dst; BYTE *pDst[3], *pDstCur[3]; const BYTE *pSrcCur[3]; const BYTE *pSrc[3]; const BYTE *pRefB[3]; const BYTE *pRefF[3]; int nDstPitches[3], nSrcPitches[3]; int nRefBPitches[3], nRefFPitches[3]; unsigned char *pDstYUY2; const unsigned char *pSrcYUY2; int nDstPitchYUY2; int nSrcPitchYUY2; bool isUsableB, isUsableF; int tmpPitch = nBlkSizeX; int nLogPel = (nPel==4) ? 2 : (nPel==2) ? 1 : 0; // nLogPel=0 for nPel=1, 1 for nPel=2, 2 for nPel=4, i.e. (x*nPel) = (x<<nLogPel) PVideoFrame mvF = mvClipF.GetFrame(n, env); mvClipF.Update(mvF, env); isUsableF = mvClipF.IsUsable(); mvF = 0; // v2.0.9.2 - it seems, we do not need in vectors clip anymore when we finished copiing them to fakeblockdatas PVideoFrame mvB = mvClipB.GetFrame(n, env); mvClipB.Update(mvB, env); isUsableB = mvClipB.IsUsable(); mvB = 0; int lsb_offset_y = 0; int lsb_offset_u = 0; int lsb_offset_v = 0; // int sharp = mvClipB.GetSharp(); int ySubUV = (yRatioUV == 2) ? 1 : 0; // if ( mvClipB.IsUsable() && mvClipF.IsUsable() && mvClipB2.IsUsable() && mvClipF2.IsUsable() ) // { dst = env->NewVideoFrame(vi); if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 ) { if (!planar) { pDstYUY2 = dst->GetWritePtr(); nDstPitchYUY2 = dst->GetPitch(); pDst[0] = DstPlanes->GetPtr(); pDst[1] = DstPlanes->GetPtrU(); pDst[2] = DstPlanes->GetPtrV(); nDstPitches[0] = DstPlanes->GetPitch(); nDstPitches[1] = DstPlanes->GetPitchUV(); nDstPitches[2] = DstPlanes->GetPitchUV(); pSrcYUY2 = src->GetReadPtr(); nSrcPitchYUY2 = src->GetPitch(); pSrc[0] = SrcPlanes->GetPtr(); pSrc[1] = SrcPlanes->GetPtrU(); pSrc[2] = SrcPlanes->GetPtrV(); nSrcPitches[0] = SrcPlanes->GetPitch(); nSrcPitches[1] = SrcPlanes->GetPitchUV(); nSrcPitches[2] = SrcPlanes->GetPitchUV(); YUY2ToPlanes(pSrcYUY2, nSrcPitchYUY2, nWidth, nHeight, pSrc[0], nSrcPitches[0], pSrc[1], pSrc[2], nSrcPitches[1], isse); } else { pDst[0] = dst->GetWritePtr(); pDst[1] = pDst[0] + nWidth; pDst[2] = pDst[1] + nWidth/2; nDstPitches[0] = dst->GetPitch(); nDstPitches[1] = nDstPitches[0]; nDstPitches[2] = nDstPitches[0]; pSrc[0] = src->GetReadPtr(); pSrc[1] = pSrc[0] + nWidth; pSrc[2] = pSrc[1] + nWidth/2; nSrcPitches[0] = src->GetPitch(); nSrcPitches[1] = nSrcPitches[0]; nSrcPitches[2] = nSrcPitches[0]; } } else { pDst[0] = YWPLAN(dst); pDst[1] = UWPLAN(dst); pDst[2] = VWPLAN(dst); nDstPitches[0] = YPITCH(dst); nDstPitches[1] = UPITCH(dst); nDstPitches[2] = VPITCH(dst); pSrc[0] = YRPLAN(src); pSrc[1] = URPLAN(src); pSrc[2] = VRPLAN(src); nSrcPitches[0] = YPITCH(src); nSrcPitches[1] = UPITCH(src); nSrcPitches[2] = VPITCH(src); } lsb_offset_y = nDstPitches [0] * nHeight; lsb_offset_u = nDstPitches [1] * (nHeight / yRatioUV); lsb_offset_v = nDstPitches [2] * (nHeight / yRatioUV); if (lsb_flag) { memset (pDst [0] + lsb_offset_y, 0, lsb_offset_y); if (! planar) { memset (pDst [1] + lsb_offset_u, 0, lsb_offset_u); memset (pDst [2] + lsb_offset_v, 0, lsb_offset_v); } } // MVFrames *pFrames = mvCore->GetFrames(nIdx); PVideoFrame refB, refF; // PVideoFrame refB2x, refF2x; mvClipF.use_ref_frame (refF, isUsableF, super, n, env); mvClipB.use_ref_frame (refB, isUsableB, super, n, env); if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 ) { // planar data packed to interleaved format (same as interleved2planar by kassandro) - v2.0.0.5 if (isUsableF) { pRefF[0] = refF->GetReadPtr(); pRefF[1] = pRefF[0] + refF->GetRowSize()/2; pRefF[2] = pRefF[1] + refF->GetRowSize()/4; nRefFPitches[0] = refF->GetPitch(); nRefFPitches[1] = nRefFPitches[0]; nRefFPitches[2] = nRefFPitches[0]; } if (isUsableB) { pRefB[0] = refB->GetReadPtr(); pRefB[1] = pRefB[0] + refB->GetRowSize()/2; pRefB[2] = pRefB[1] + refB->GetRowSize()/4; nRefBPitches[0] = refB->GetPitch(); nRefBPitches[1] = nRefBPitches[0]; nRefBPitches[2] = nRefBPitches[0]; } } else { if (isUsableF) { pRefF[0] = YRPLAN(refF); pRefF[1] = URPLAN(refF); pRefF[2] = VRPLAN(refF); nRefFPitches[0] = YPITCH(refF); nRefFPitches[1] = UPITCH(refF); nRefFPitches[2] = VPITCH(refF); } if (isUsableB) { pRefB[0] = YRPLAN(refB); pRefB[1] = URPLAN(refB); pRefB[2] = VRPLAN(refB); nRefBPitches[0] = YPITCH(refB); nRefBPitches[1] = UPITCH(refB); nRefBPitches[2] = VPITCH(refB); } } MVPlane *pPlanesB[3] = { 0 }; MVPlane *pPlanesF[3] = { 0 }; if (isUsableF) { pRefFGOF->Update(YUVplanes, (BYTE*)pRefF[0], nRefFPitches[0], (BYTE*)pRefF[1], nRefFPitches[1], (BYTE*)pRefF[2], nRefFPitches[2]); if (YUVplanes & YPLANE) pPlanesF[0] = pRefFGOF->GetFrame(0)->GetPlane(YPLANE); if (YUVplanes & UPLANE) pPlanesF[1] = pRefFGOF->GetFrame(0)->GetPlane(UPLANE); if (YUVplanes & VPLANE) pPlanesF[2] = pRefFGOF->GetFrame(0)->GetPlane(VPLANE); } if (isUsableB) { pRefBGOF->Update(YUVplanes, (BYTE*)pRefB[0], nRefBPitches[0], (BYTE*)pRefB[1], nRefBPitches[1], (BYTE*)pRefB[2], nRefBPitches[2]);// v2.0 if (YUVplanes & YPLANE) pPlanesB[0] = pRefBGOF->GetFrame(0)->GetPlane(YPLANE); if (YUVplanes & UPLANE) pPlanesB[1] = pRefBGOF->GetFrame(0)->GetPlane(UPLANE); if (YUVplanes & VPLANE) pPlanesB[2] = pRefBGOF->GetFrame(0)->GetPlane(VPLANE); } PROFILE_START(MOTION_PROFILE_COMPENSATION); pDstCur[0] = pDst[0]; pDstCur[1] = pDst[1]; pDstCur[2] = pDst[2]; pSrcCur[0] = pSrc[0]; pSrcCur[1] = pSrc[1]; pSrcCur[2] = pSrc[2]; // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // LUMA plane Y if (!(YUVplanes & YPLANE)) { BitBlt(pDstCur[0], nDstPitches[0], pSrcCur[0], nSrcPitches[0], nWidth, nHeight, isse); } else { if (nOverlapX==0 && nOverlapY==0) { for (int by=0; by<nBlkY; by++) { int xx = 0; for (int bx=0; bx<nBlkX; bx++) { int i = by*nBlkX + bx; const BYTE * pB, *pF; int npB, npF; int WSrc, WRefB, WRefF; use_block_y (pB , npB , WRefB , isUsableB , mvClipB , i, pPlanesB [0], pSrcCur [0], xx, nSrcPitches [0]); use_block_y (pF , npF , WRefF , isUsableF , mvClipF , i, pPlanesF [0], pSrcCur [0], xx, nSrcPitches [0]); norm_weights (WSrc, WRefB, WRefF); // luma DEGRAINLUMA(pDstCur[0] + xx, pDstCur[0] + lsb_offset_y + xx, lsb_flag, nDstPitches[0], pSrcCur[0]+ xx, nSrcPitches[0], pB, npB, pF, npF, WSrc, WRefB, WRefF); xx += (nBlkSizeX); if (bx == nBlkX-1 && nWidth_B < nWidth) // right non-covered region { // luma BitBlt(pDstCur[0] + nWidth_B, nDstPitches[0], pSrcCur[0] + nWidth_B, nSrcPitches[0], nWidth-nWidth_B, nBlkSizeY, isse); } } // for bx pDstCur[0] += ( nBlkSizeY ) * (nDstPitches[0]); pSrcCur[0] += ( nBlkSizeY ) * (nSrcPitches[0]); if (by == nBlkY-1 && nHeight_B < nHeight) // bottom uncovered region { // luma BitBlt(pDstCur[0], nDstPitches[0], pSrcCur[0], nSrcPitches[0], nWidth, nHeight-nHeight_B, isse); } } // for by } // nOverlapX==0 && nOverlapY==0 // ----------------------------------------------------------------- else // overlap { unsigned short *pDstShort = DstShort; int *pDstInt = DstInt; const int tmpPitch = nBlkSizeX; if (lsb_flag) { MemZoneSet(reinterpret_cast<unsigned char*>(pDstInt), 0, nWidth_B*4, nHeight_B, 0, 0, dstIntPitch*4); } else { MemZoneSet(reinterpret_cast<unsigned char*>(pDstShort), 0, nWidth_B*2, nHeight_B, 0, 0, dstShortPitch*2); } for (int by=0; by<nBlkY; by++) { int wby = ((by + nBlkY - 3)/(nBlkY - 2))*3; int xx = 0; for (int bx=0; bx<nBlkX; bx++) { // select window int wbx = (bx + nBlkX - 3)/(nBlkX - 2); short * winOver = OverWins->GetWindow(wby + wbx); int i = by*nBlkX + bx; const BYTE * pB, *pF; int npB, npF; int WSrc, WRefB, WRefF; use_block_y (pB , npB , WRefB , isUsableB , mvClipB , i, pPlanesB [0], pSrcCur [0], xx, nSrcPitches [0]); use_block_y (pF , npF , WRefF , isUsableF , mvClipF , i, pPlanesF [0], pSrcCur [0], xx, nSrcPitches [0]); norm_weights (WSrc, WRefB, WRefF); // luma DEGRAINLUMA(tmpBlock, tmpBlockLsb, lsb_flag, tmpPitch, pSrcCur[0]+ xx, nSrcPitches[0], pB, npB, pF, npF, WSrc, WRefB, WRefF); if (lsb_flag) { OVERSLUMALSB(pDstInt + xx, dstIntPitch, tmpBlock, tmpBlockLsb, tmpPitch, winOver, nBlkSizeX); } else { OVERSLUMA(pDstShort + xx, dstShortPitch, tmpBlock, tmpPitch, winOver, nBlkSizeX); } xx += (nBlkSizeX - nOverlapX); } // for bx pSrcCur[0] += (nBlkSizeY - nOverlapY) * (nSrcPitches[0]); pDstShort += (nBlkSizeY - nOverlapY) * dstShortPitch; pDstInt += (nBlkSizeY - nOverlapY) * dstIntPitch; } // for by if (lsb_flag) { Short2BytesLsb(pDst[0], pDst[0] + lsb_offset_y, nDstPitches[0], DstInt, dstIntPitch, nWidth_B, nHeight_B); } else { Short2Bytes(pDst[0], nDstPitches[0], DstShort, dstShortPitch, nWidth_B, nHeight_B); } if (nWidth_B < nWidth) { BitBlt(pDst[0] + nWidth_B, nDstPitches[0], pSrc[0] + nWidth_B, nSrcPitches[0], nWidth-nWidth_B, nHeight_B, isse); } if (nHeight_B < nHeight) // bottom noncovered region { BitBlt(pDst[0] + nHeight_B*nDstPitches[0], nDstPitches[0], pSrc[0] + nHeight_B*nSrcPitches[0], nSrcPitches[0], nWidth, nHeight-nHeight_B, isse); } } // overlap - end if (nLimit < 255) { if (isse) { LimitChanges_sse2(pDst[0], nDstPitches[0], pSrc[0], nSrcPitches[0], nWidth, nHeight, nLimit); } else { LimitChanges_c(pDst[0], nDstPitches[0], pSrc[0], nSrcPitches[0], nWidth, nHeight, nLimit); } } } //---------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // CHROMA plane U process_chroma ( UPLANE & nSuperModeYUV, pDst [1], pDstCur [1], nDstPitches [1], pSrc [1], pSrcCur [1], nSrcPitches [1], isUsableB, isUsableF, pPlanesB [1], pPlanesF [1], lsb_offset_u, nWidth_B, nHeight_B ); //---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // CHROMA plane V process_chroma ( VPLANE & nSuperModeYUV, pDst [2], pDstCur [2], nDstPitches [2], pSrc [2], pSrcCur [2], nSrcPitches [2], isUsableB, isUsableF, pPlanesB [2], pPlanesF [2], lsb_offset_v, nWidth_B, nHeight_B ); //-------------------------------------------------------------------------------- _mm_empty (); // (we may use double-float somewhere) Fizick PROFILE_STOP(MOTION_PROFILE_COMPENSATION); if ( (pixelType & VideoInfo::CS_YUY2) == VideoInfo::CS_YUY2 && !planar) { YUY2FromPlanes(pDstYUY2, nDstPitchYUY2, nWidth, nHeight * height_lsb_mul, pDst[0], nDstPitches[0], pDst[1], pDst[2], nDstPitches[1], isse); } return dst; }