Beispiel #1
0
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;
}
Beispiel #2
0
static const VSFrameRef *VS_CC mvsuperGetFrame(int32_t n, int32_t activationReason, void **instanceData, void **frameData, VSFrameContext *frameCtx, VSCore *core, const VSAPI *vsapi) {
	MVSuperData *d = reinterpret_cast<MVSuperData *>(*instanceData);
	if (activationReason == arInitial) {
		vsapi->requestFrameFilter(n, d->node, frameCtx);
		if (d->usePelClip)
			vsapi->requestFrameFilter(n, d->pelclip, frameCtx);
	}
	else if (activationReason == arAllFramesReady) {
		const VSFrameRef *src = vsapi->getFrameFilter(n, d->node, frameCtx);
		const uint8_t *pSrc[3] = { nullptr };
		uint8_t *pDst[3] = { nullptr };
		const uint8_t *pSrcPel[3] = { nullptr };
		int32_t nSrcPitch[3] = { 0 };
		int32_t nDstPitch[3] = { 0 };
		int32_t nSrcPelPitch[3] = { 0 };
		const VSFrameRef *srcPel = nullptr;
		if (d->usePelClip)
			srcPel = vsapi->getFrameFilter(n, d->pelclip, frameCtx);
		VSFrameRef *dst = vsapi->newVideoFrame(d->vi.format, d->vi.width, d->vi.height, src, core);
		for (int32_t plane = 0; plane < d->vi.format->numPlanes; ++plane) {
			pSrc[plane] = vsapi->getReadPtr(src, plane);
			nSrcPitch[plane] = vsapi->getStride(src, plane);
			pDst[plane] = vsapi->getWritePtr(dst, plane);
			nDstPitch[plane] = vsapi->getStride(dst, plane);
			memset(pDst[plane], 0, nDstPitch[plane] * vsapi->getFrameHeight(dst, plane));
		}
		MVGroupOfFrames *pSrcGOF = new MVGroupOfFrames(d->nLevels, d->nWidth, d->nHeight, d->nPel, d->nHPad, d->nVPad, d->nModeYUV, d->xRatioUV, d->yRatioUV);
		pSrcGOF->Update(d->nModeYUV, pDst[0], nDstPitch[0], pDst[1], nDstPitch[1], pDst[2], nDstPitch[2]);
		MVPlaneSet planes[3] = { YPLANE, UPLANE, VPLANE };
		for (int32_t plane = 0; plane < d->vi.format->numPlanes; ++plane)
			pSrcGOF->SetPlane(pSrc[plane], nSrcPitch[plane], planes[plane]);
		pSrcGOF->Reduce(d->nModeYUV, d->rfilter);
		pSrcGOF->Pad(d->nModeYUV);
		if (d->usePelClip) {
			MVFrame *srcFrames = pSrcGOF->GetFrame(0);
			for (int32_t plane = 0; plane < d->vi.format->numPlanes; ++plane) {
				pSrcPel[plane] = vsapi->getReadPtr(srcPel, plane);
				nSrcPelPitch[plane] = vsapi->getStride(srcPel, plane);
				MVPlane *srcPlane = srcFrames->GetPlane(planes[plane]);
				if (d->nModeYUV & planes[plane])
					srcPlane->RefineExt(pSrcPel[plane], nSrcPelPitch[plane], d->isPelClipPadded);
			}
		}
		else
			pSrcGOF->Refine(d->nModeYUV, d->sharp);
		vsapi->freeFrame(src);
		if (d->usePelClip)
			vsapi->freeFrame(srcPel);
		delete pSrcGOF;
		if (n == 0) {
			VSMap *props = vsapi->getFramePropsRW(dst);
			vsapi->propSetInt(props, "Super_height", d->nHeight, paReplace);
			vsapi->propSetInt(props, "Super_hpad", d->nHPad, paReplace);
			vsapi->propSetInt(props, "Super_vpad", d->nVPad, paReplace);
			vsapi->propSetInt(props, "Super_pel", d->nPel, paReplace);
			vsapi->propSetInt(props, "Super_modeyuv", d->nModeYUV, paReplace);
			vsapi->propSetInt(props, "Super_levels", d->nLevels, paReplace);
		}
		return dst;
	}
	return nullptr;
}