PVideoFrame __stdcall Null::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n, env); BYTE * foo = new BYTE[256]; BYTE * bar = new BYTE[256]; MemDebug md; md.randomFill(foo, 8, 8, 8); BitBlt(bar, 8, foo, 8, 8, 8); md.reset(); int i = md.randomCheck(bar, 9, 8, 8); if (i) env->ThrowError("bug found"); delete [] foo; delete [] bar; if (!lstrcmpi(copy, "makewritable")) { env->MakeWritable(&src); return src; } // TODO: no support for planar formats! if (!lstrcmpi(copy, "memcopy")) { PVideoFrame dst = env->NewVideoFrame(child->GetVideoInfo(), 16); if (dst->IsWritable() == false) env->ThrowError("new frame not writable"); // honestly don't know whether to expect this condition memcpy( dst->GetWritePtr(), src->GetReadPtr(), src->GetPitch() * src->GetHeight() ); return dst; } if (!lstrcmpi(copy, "bitblt")) { PVideoFrame dst = env->NewVideoFrame(child->GetVideoInfo(), 16); if (dst->IsWritable() == false) env->ThrowError("new frame not writable"); // honestly don't know whether to expect this condition BitBlt( dst->GetWritePtr(), src->GetPitch(), src->GetReadPtr(), src->GetPitch(), src->GetRowSize(), src->GetHeight() ); return dst; } //if (!lstrcmpi(copy, "none")) // do nothing return src; }
PVideoFrame SafeNewVideoFrame(IScriptEnvironment* env, const VideoInfo& vi, int align) { ensure_initialized(); { CSLockAcquire lock(*_lock); PVideoFrame frame = env->NewVideoFrame(vi, align); assert(frame->IsWritable()); return frame; } }
PVideoFrame __stdcall MergeLuma::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n, env); if (weight<0.0039f) return src; PVideoFrame luma = clip->GetFrame(n, env); if (vi.IsYUY2()) { env->MakeWritable(&src); BYTE* srcp = src->GetWritePtr(); const BYTE* lumap = luma->GetReadPtr(); int isrc_pitch = src->GetPitch(); int iluma_pitch = luma->GetPitch(); int h = src->GetHeight(); int w = src->GetRowSize(); if (weight<0.9961f) { if ((env->GetCPUFlags() & CPUF_SSE2) && IsPtrAligned(srcp, 16) && IsPtrAligned(lumap, 16)) { weighted_merge_luma_yuy2_sse2(srcp, lumap, isrc_pitch, iluma_pitch, w, h, (int)(weight*32768.0f), 32768-(int)(weight*32768.0f)); } else #ifdef X86_32 if (env->GetCPUFlags() & CPUF_MMX) { weighted_merge_luma_yuy2_mmx(srcp, lumap, isrc_pitch, iluma_pitch, w, h, (int)(weight*32768.0f), 32768-(int)(weight*32768.0f)); } else #endif { weighted_merge_luma_yuy2_c(srcp, lumap, isrc_pitch, iluma_pitch, w, h, (int)(weight*32768.0f), 32768-(int)(weight*32768.0f)); } } else { if ((env->GetCPUFlags() & CPUF_SSE2) && IsPtrAligned(srcp, 16) && IsPtrAligned(lumap, 16)) { replace_luma_yuy2_sse2(srcp,lumap,isrc_pitch,iluma_pitch,w,h); } else #ifdef X86_32 if (env->GetCPUFlags() & CPUF_MMX) { replace_luma_yuy2_mmx(srcp,lumap,isrc_pitch,iluma_pitch,w,h); } else #endif { replace_luma_yuy2_c(srcp,lumap,isrc_pitch,iluma_pitch,w,h); } } return src; } // Planar if (weight>0.9961f) { const VideoInfo& vi2 = clip->GetVideoInfo(); if (luma->IsWritable() && vi.IsSameColorspace(vi2)) { if (luma->GetRowSize(PLANAR_U)) { luma->GetWritePtr(PLANAR_Y); //Must be requested BUT only if we actually do something env->BitBlt(luma->GetWritePtr(PLANAR_U),luma->GetPitch(PLANAR_U),src->GetReadPtr(PLANAR_U),src->GetPitch(PLANAR_U),src->GetRowSize(PLANAR_U),src->GetHeight(PLANAR_U)); env->BitBlt(luma->GetWritePtr(PLANAR_V),luma->GetPitch(PLANAR_V),src->GetReadPtr(PLANAR_V),src->GetPitch(PLANAR_V),src->GetRowSize(PLANAR_V),src->GetHeight(PLANAR_V)); } return luma; } else { // avoid the cost of 2 chroma blits PVideoFrame dst = env->NewVideoFrame(vi); env->BitBlt(dst->GetWritePtr(PLANAR_Y),dst->GetPitch(PLANAR_Y),luma->GetReadPtr(PLANAR_Y),luma->GetPitch(PLANAR_Y),luma->GetRowSize(PLANAR_Y),luma->GetHeight(PLANAR_Y)); if (src->GetRowSize(PLANAR_U) && dst->GetRowSize(PLANAR_U)) { env->BitBlt(dst->GetWritePtr(PLANAR_U),dst->GetPitch(PLANAR_U),src->GetReadPtr(PLANAR_U),src->GetPitch(PLANAR_U),src->GetRowSize(PLANAR_U),src->GetHeight(PLANAR_U)); env->BitBlt(dst->GetWritePtr(PLANAR_V),dst->GetPitch(PLANAR_V),src->GetReadPtr(PLANAR_V),src->GetPitch(PLANAR_V),src->GetRowSize(PLANAR_V),src->GetHeight(PLANAR_V)); } return dst; } } else { // weight <= 0.9961f env->MakeWritable(&src); BYTE* srcpY = (BYTE*)src->GetWritePtr(PLANAR_Y); BYTE* lumapY = (BYTE*)luma->GetReadPtr(PLANAR_Y); int src_pitch = src->GetPitch(PLANAR_Y); int luma_pitch = luma->GetPitch(PLANAR_Y); int src_width = src->GetRowSize(PLANAR_Y); int src_height = src->GetHeight(PLANAR_Y); merge_plane(srcpY, lumapY, src_pitch, luma_pitch, src_width, src_height, weight, env); } return src; }
PVideoFrame __stdcall MergeChroma::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n, env); if (weight<0.0039f) return src; PVideoFrame chroma = clip->GetFrame(n, env); int h = src->GetHeight(); int w = src->GetRowSize(); // width in pixels if (weight<0.9961f) { if (vi.IsYUY2()) { env->MakeWritable(&src); BYTE* srcp = src->GetWritePtr(); const BYTE* chromap = chroma->GetReadPtr(); int src_pitch = src->GetPitch(); int chroma_pitch = chroma->GetPitch(); if ((env->GetCPUFlags() & CPUF_SSE2) && IsPtrAligned(srcp, 16) && IsPtrAligned(chromap, 16)) { weighted_merge_chroma_yuy2_sse2(srcp,chromap,src_pitch,chroma_pitch,w,h,(int)(weight*32768.0f),32768-(int)(weight*32768.0f)); } else #ifdef X86_32 if (env->GetCPUFlags() & CPUF_MMX) { weighted_merge_chroma_yuy2_mmx(srcp,chromap,src_pitch,chroma_pitch,w,h,(int)(weight*32768.0f),32768-(int)(weight*32768.0f)); } else #endif { weighted_merge_chroma_yuy2_c(srcp,chromap,src_pitch,chroma_pitch,w,h,(int)(weight*32768.0f),32768-(int)(weight*32768.0f)); } } else { // Planar env->MakeWritable(&src); src->GetWritePtr(PLANAR_Y); //Must be requested BYTE* srcpU = (BYTE*)src->GetWritePtr(PLANAR_U); BYTE* chromapU = (BYTE*)chroma->GetReadPtr(PLANAR_U); BYTE* srcpV = (BYTE*)src->GetWritePtr(PLANAR_V); BYTE* chromapV = (BYTE*)chroma->GetReadPtr(PLANAR_V); int src_pitch_uv = src->GetPitch(PLANAR_U); int chroma_pitch_uv = chroma->GetPitch(PLANAR_U); int src_width_u = src->GetRowSize(PLANAR_U_ALIGNED); int src_width_v = src->GetRowSize(PLANAR_V_ALIGNED); int src_height_uv = src->GetHeight(PLANAR_U); merge_plane(srcpU, chromapU, src_pitch_uv, chroma_pitch_uv, src_width_u, src_height_uv, weight, env); merge_plane(srcpV, chromapV, src_pitch_uv, chroma_pitch_uv, src_width_v, src_height_uv, weight, env); } } else { // weight == 1.0 if (vi.IsYUY2()) { const BYTE* srcp = src->GetReadPtr(); env->MakeWritable(&chroma); BYTE* chromap = chroma->GetWritePtr(); int src_pitch = src->GetPitch(); int chroma_pitch = chroma->GetPitch(); if ((env->GetCPUFlags() & CPUF_SSE2) && IsPtrAligned(chromap, 16) && IsPtrAligned(srcp, 16)) { replace_luma_yuy2_sse2(chromap,srcp,chroma_pitch,src_pitch,w,h); // Just swap luma/chroma } else #ifdef X86_32 if (env->GetCPUFlags() & CPUF_MMX) { replace_luma_yuy2_mmx(chromap,srcp,chroma_pitch,src_pitch,w,h); // Just swap luma/chroma } else #endif { replace_luma_yuy2_c(chromap,srcp,chroma_pitch,src_pitch,w,h); // Just swap luma/chroma } return chroma; } else { if (src->IsWritable()) { src->GetWritePtr(PLANAR_Y); //Must be requested env->BitBlt(src->GetWritePtr(PLANAR_U),src->GetPitch(PLANAR_U),chroma->GetReadPtr(PLANAR_U),chroma->GetPitch(PLANAR_U),chroma->GetRowSize(PLANAR_U),chroma->GetHeight(PLANAR_U)); env->BitBlt(src->GetWritePtr(PLANAR_V),src->GetPitch(PLANAR_V),chroma->GetReadPtr(PLANAR_V),chroma->GetPitch(PLANAR_V),chroma->GetRowSize(PLANAR_V),chroma->GetHeight(PLANAR_V)); } else { // avoid the cost of 2 chroma blits PVideoFrame dst = env->NewVideoFrame(vi); env->BitBlt(dst->GetWritePtr(PLANAR_Y),dst->GetPitch(PLANAR_Y),src->GetReadPtr(PLANAR_Y),src->GetPitch(PLANAR_Y),src->GetRowSize(PLANAR_Y),src->GetHeight(PLANAR_Y)); env->BitBlt(dst->GetWritePtr(PLANAR_U),dst->GetPitch(PLANAR_U),chroma->GetReadPtr(PLANAR_U),chroma->GetPitch(PLANAR_U),chroma->GetRowSize(PLANAR_U),chroma->GetHeight(PLANAR_U)); env->BitBlt(dst->GetWritePtr(PLANAR_V),dst->GetPitch(PLANAR_V),chroma->GetReadPtr(PLANAR_V),chroma->GetPitch(PLANAR_V),chroma->GetRowSize(PLANAR_V),chroma->GetHeight(PLANAR_V)); return dst; } } } return src; }