PVideoFrame SkewRows::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n, env); PVideoFrame dst = env->NewVideoFrame(vi); const int srowsize = src->GetRowSize(); const int spitch = src->GetPitch(); const BYTE *sptr = src->GetReadPtr(); const int drowsize = dst->GetRowSize(); const int dpitch = dst->GetPitch(); BYTE *dptr = dst->GetWritePtr(); const int ssize = src->GetHeight()*srowsize; int s=0, d=0; for (int i=0; i < ssize; i++) { if (s >= srowsize) { s = 0; sptr += spitch; } if (d >= drowsize) { d = 0; dptr += dpitch; } dptr[d++] = sptr[s++]; } while (d < drowsize) dptr[d++] = 128; return dst; }
PVideoFrame PeculiarBlend::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame a = child->GetFrame(n, env); PVideoFrame b = child->GetFrame(n+1, env); env->MakeWritable(&a); BYTE* main = a->GetWritePtr(); const BYTE* other = b->GetReadPtr(); const int main_pitch = a->GetPitch(); const int other_pitch = b->GetPitch(); const int row_size = a->GetRowSize(); if (cutoff-31 > 0) { int copy_top = min(cutoff-31, vi.height); BitBlt(main, main_pitch, other, other_pitch, row_size, copy_top); main += main_pitch * copy_top; other += other_pitch * copy_top; } for (int y = max(0, cutoff-31); y < min(cutoff, vi.height-1); ++y) { int scale = cutoff - y; for (int x = 0; x < row_size; ++x) main[x] += ((other[x] - main[x]) * scale + 16) >> 5; main += main_pitch; other += other_pitch; } return a; }
static void BlitField(const FFMS_Frame *Frame, PVideoFrame &Dst, IScriptEnvironment *Env, int Plane, int Field) { int PlaneId = 1 << Plane; Env->BitBlt( Dst->GetWritePtr(PlaneId) + Dst->GetPitch(PlaneId) * Field, Dst->GetPitch(PlaneId) * 2, Frame->Data[Plane] + Frame->Linesize[Plane] * Field, Frame->Linesize[Plane] * 2, Dst->GetRowSize(PlaneId), Dst->GetHeight(PlaneId) / 2); }
PVideoFrame __stdcall MergeAll::GetFrame(int n, IScriptEnvironment* env) { if (weight<0.0039f) return child->GetFrame(n, env); if (weight>0.9961f) return clip->GetFrame(n, env); PVideoFrame src = child->GetFrame(n, env); PVideoFrame src2 = clip->GetFrame(n, env); env->MakeWritable(&src); BYTE* srcp = src->GetWritePtr(); const BYTE* srcp2 = src2->GetReadPtr(); const int src_pitch = src->GetPitch(); const int src_rowsize = src->GetRowSize(); merge_plane(srcp, srcp2, src_pitch, src2->GetPitch(), src_rowsize, src->GetHeight(), weight, env); if (vi.IsPlanar()) { BYTE* srcpU = (BYTE*)src->GetWritePtr(PLANAR_U); BYTE* srcpV = (BYTE*)src->GetWritePtr(PLANAR_V); BYTE* srcp2U = (BYTE*)src2->GetReadPtr(PLANAR_U); BYTE* srcp2V = (BYTE*)src2->GetReadPtr(PLANAR_V); int src_rowsize = src->GetRowSize(PLANAR_U); merge_plane(srcpU, srcp2U, src->GetPitch(PLANAR_U), src2->GetPitch(PLANAR_U), src_rowsize, src->GetHeight(PLANAR_U), weight, env); merge_plane(srcpV, srcp2V, src->GetPitch(PLANAR_V), src2->GetPitch(PLANAR_V), src_rowsize, src->GetHeight(PLANAR_V), weight, env); } return src; }
static void make_black_background_planar_yuv ( PVideoFrame &frame, int bitdepth_minus_8 ) { memset( frame->GetWritePtr( PLANAR_Y ), 0x00, frame->GetPitch( PLANAR_Y ) * frame->GetHeight( PLANAR_Y ) ); memset( frame->GetWritePtr( PLANAR_U ), 0x80, frame->GetPitch( PLANAR_U ) * frame->GetHeight( PLANAR_U ) ); memset( frame->GetWritePtr( PLANAR_V ), 0x80, frame->GetPitch( PLANAR_V ) * frame->GetHeight( PLANAR_V ) ); }
void AvisynthVideoSource::OutputFrame(const FFMS_Frame *Frame, PVideoFrame &Dst, IScriptEnvironment *Env) { if (VI.pixel_type == VideoInfo::CS_I420) { Env->BitBlt(Dst->GetWritePtr(PLANAR_Y), Dst->GetPitch(PLANAR_Y), Frame->Data[0], Frame->Linesize[0], Dst->GetRowSize(PLANAR_Y), Dst->GetHeight(PLANAR_Y)); Env->BitBlt(Dst->GetWritePtr(PLANAR_U), Dst->GetPitch(PLANAR_U), Frame->Data[1], Frame->Linesize[1], Dst->GetRowSize(PLANAR_U), Dst->GetHeight(PLANAR_U)); Env->BitBlt(Dst->GetWritePtr(PLANAR_V), Dst->GetPitch(PLANAR_V), Frame->Data[2], Frame->Linesize[2], Dst->GetRowSize(PLANAR_V), Dst->GetHeight(PLANAR_V)); } else if (VI.IsYUY2()) { Env->BitBlt(Dst->GetWritePtr(), Dst->GetPitch(), Frame->Data[0], Frame->Linesize[0], Dst->GetRowSize(), Dst->GetHeight()); } else { // RGB Env->BitBlt(Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1), -Dst->GetPitch(), Frame->Data[0], Frame->Linesize[0], Dst->GetRowSize(), Dst->GetHeight()); } }
PVideoFrame __stdcall AutoTraceFilter::GetFrame(int n, IScriptEnvironment* env) { // Grab the child frame PVideoFrame childFrame = child->GetFrame(n, env); // Create the bitmap - AutoTrace always wants a 24-bpp bitmap for some dumb reason at_bitmap_type *bitmap; bitmap = at_bitmap_new(srcWidth, srcHeight, 3); size_t bitmap_size = srcWidth * srcHeight * 3; // Pull the bitmap data // We can just blt lines const BYTE* srcBitmap = childFrame->GetReadPtr(); int pitch = childFrame->GetPitch(); int rowSize = childFrame->GetRowSize(); for (int y = 0; y < srcHeight; y++) { // Note that R and B are swapped in this. It doesn't really matter. memcpy_s(bitmap->bitmap + ((srcHeight - y - 1) * rowSize), bitmap_size, srcBitmap + (y * pitch), rowSize); } // This does the actual tracing: at_splines_type* splines = at_splines_new(bitmap, fitting_opts, exception_handler, NULL); // Now create the new frame. First, blank out the old frame graphics->Clear(*backgroundColor); at_real tx = ((at_real)destWidth) / ((at_real)srcWidth); at_real ty = ((at_real)destHeight) / ((at_real)srcHeight); for (unsigned int i = 0; i < splines->length; i++) { at_spline_list_type spline_list = splines->data[i]; Gdiplus::GraphicsPath path; for (unsigned int j = 0; j < spline_list.length; j++) { at_spline_type* spline = &(spline_list.data[j]); if (spline->degree == AT_LINEARTYPE) { path.AddLine((Gdiplus::REAL)(spline->v[0].x * tx), (Gdiplus::REAL)(spline->v[0].y * ty), (Gdiplus::REAL)(spline->v[3].x * tx), (Gdiplus::REAL)(spline->v[3].y * ty)); } else { path.AddBezier( (Gdiplus::REAL)(spline->v[0].x * tx), (Gdiplus::REAL)(spline->v[0].y * ty), (Gdiplus::REAL)(spline->v[1].x * tx), (Gdiplus::REAL)(spline->v[1].y * ty), (Gdiplus::REAL)(spline->v[2].x * tx), (Gdiplus::REAL)(spline->v[2].y * ty), (Gdiplus::REAL)(spline->v[3].x * tx), (Gdiplus::REAL)(spline->v[3].y * ty)); } } path.CloseFigure(); // Red and blue are swapped here, so swap them back. Gdiplus::Color color(spline_list.color.b, spline_list.color.g, spline_list.color.r); Gdiplus::SolidBrush brush(color); graphics->FillPath(&brush, &path); } at_splines_free(splines); at_bitmap_free(bitmap); // Now we need to create our result frame PVideoFrame outputFrame = env->NewVideoFrame(vi); BYTE* outputData = outputFrame->GetWritePtr(); env->BitBlt(outputData, outputFrame->GetPitch(), renderedFrameData, renderedFramePitch, destWidth*4, destHeight); return outputFrame; }
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; }
static int make_frame_packed_rgb ( lw_video_output_handler_t *vohp, int height, AVFrame *av_frame, PVideoFrame &as_frame ) { as_picture_t as_picture = { { { NULL } } }; as_picture.data [0] = as_frame->GetWritePtr() + as_frame->GetPitch() * (as_frame->GetHeight() - 1); as_picture.linesize[0] = -as_frame->GetPitch(); return convert_av_pixel_format( vohp->scaler.sws_ctx, height, av_frame, &as_picture ); }
static inline void as_assign_planar_yuv ( PVideoFrame &as_frame, as_picture_t *as_picture ) { as_picture->data [0] = as_frame->GetWritePtr( PLANAR_Y ); as_picture->data [1] = as_frame->GetWritePtr( PLANAR_U ); as_picture->data [2] = as_frame->GetWritePtr( PLANAR_V ); as_picture->linesize[0] = as_frame->GetPitch ( PLANAR_Y ); as_picture->linesize[1] = as_frame->GetPitch ( PLANAR_U ); as_picture->linesize[2] = as_frame->GetPitch ( PLANAR_V ); }
PVideoFrame __stdcall TEMmod::GetFrame(int n, IScriptEnvironment* env) { const int planes[3] = {PLANAR_Y, PLANAR_U, PLANAR_V}; PVideoFrame src = child->GetFrame(n, env); PVideoFrame dst = env->NewVideoFrame(vi); for (int i = 0; i < 3; i++) { if (process[i] == 0) { break; } int p = planes[i]; int dst_pitch = dst->GetPitch(p); uint8_t* dstp = dst->GetWritePtr(p); int height = src->GetHeight(p); if (process[i] == 2) { memset(dstp, 0, dst_pitch * height); continue; } int src_pitch = src->GetPitch(p); int width = src->GetRowSize(p); const uint8_t* srcp = src->GetReadPtr(p); if (((intptr_t)srcp & 15) && type > 2) { env->ThrowError("TEMmod: invalid memory alignment found!"); } calc_map(srcp, dstp, buff, src_pitch, dst_pitch, buff_pitch, width, height, threshold[i], scale); } if (link > 0) { link_planes(dst); } if (!invert) { return dst; } for (int i = 0; i < 3; i++) { if (process[i] == 0) { break; } invert_plane(dst->GetWritePtr(planes[i]), dst->GetPitch(planes[i]), dst->GetHeight(planes[i])); } return dst; }
void AvisynthVideoSource::OutputFrame(const FFMS_Frame *Frame, PVideoFrame &Dst, IScriptEnvironment *Env) { if (VI.pixel_type == VideoInfo::CS_I420) { BlitPlane(Frame, Dst, Env, 0); BlitPlane(Frame, Dst, Env, 1); BlitPlane(Frame, Dst, Env, 2); } else if (VI.IsYUY2()) { BlitPlane(Frame, Dst, Env, 0); } else { // RGB Env->BitBlt( Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1), -Dst->GetPitch(), Frame->Data[0], Frame->Linesize[0], Dst->GetRowSize(), Dst->GetHeight()); } }
void copyplane(PVideoFrame &result, const PVideoFrame &source, int plane, IScriptEnvironment *env) { // void __stdcall IScriptEnvironment::BitBlt //(BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height) = 0 unsigned char *resultpointer = result->GetWritePtr(plane); const unsigned char *sourcepointer = source->GetReadPtr(plane); const int width = source->GetRowSize(plane); const int height = source->GetHeight(plane); const int sourcepitch = source->GetPitch(plane); const int resultpitch = result->GetPitch(plane); env->BitBlt(resultpointer, resultpitch, sourcepointer, sourcepitch, width, height); }
PVideoFrame __stdcall ShapeMask::GetFrame(int n, IScriptEnvironment* env) { int colorspace; if (vi.IsRGB24()) colorspace = RGB24; else if (vi.IsRGB32()) colorspace = RGB32; else if (vi.IsYUY2()) colorspace = YUV2; else if (vi.IsYV12()) colorspace = YV12; else raiseError(env, "Unsupported color space, must be one of RGB24, RGB32, YUV2 or YV12"); PClip srcClip = toGrayScale(env, child); PVideoFrame src = srcClip->GetFrame(n, env); PVideoFrame dst = env->NewVideoFrame(vi); const uchar* srcp = src->GetReadPtr(); const int src_pitch = src->GetPitch(); const int bpp = vi.BitsPerPixel(); uchar* retp; // No change to the source pixels in the process steps, so ok to cast to non-const // returns a 1 channel gray scale image which needs to be converted to whatever format the source clip is in. retp = process_frame((uchar*)srcp, vi.width, vi.height, src_pitch, colorspace, threshold, minarea, rectonly); if (vi.IsPlanar()) copyPlanar(retp, dst, bpp); else if (vi.IsYUY2()) copyYUY2(retp, dst); else copyRGB(retp, dst, bpp); delete retp; return dst; }
void AvisynthVideoSource::OutputField(const FFMS_Frame *Frame, PVideoFrame &Dst, int Field, IScriptEnvironment *Env) { const FFMS_Frame *SrcPicture = (Frame); if (VI.pixel_type == VideoInfo::CS_I420) { BlitField(Frame, Dst, Env, 0, Field); BlitField(Frame, Dst, Env, 1, Field); BlitField(Frame, Dst, Env, 2, Field); } else if (VI.IsYUY2()) { BlitField(Frame, Dst, Env, 0, Field); } else { // RGB Env->BitBlt( Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1 - Field), -Dst->GetPitch() * 2, SrcPicture->Data[0] + SrcPicture->Linesize[0] * Field, SrcPicture->Linesize[0] * 2, Dst->GetRowSize(), Dst->GetHeight() / 2); } }
PVideoFrame __stdcall Padding::GetFrame(int n, IScriptEnvironment *env) { PVideoFrame src = child->GetFrame(n, env); PVideoFrame dst = env->NewVideoFrame(vi); // convert to frames unsigned char const *pSrc[3]; unsigned char *pDst[3]; int nDstPitches[3], nSrcPitches[3]; SrcPlanes->ConvertVideoFrameToPlanes(&src, pSrc, nSrcPitches); DstPlanes->ConvertVideoFrameToPlanes(&dst, pDst, nDstPitches); int yRatioUV = (vi.IsYV12()) ? 2 : 1; PlaneCopy(pDst[0] + horizontalPadding + verticalPadding * nDstPitches[0], nDstPitches[0], pSrc[0], nSrcPitches[0], width, height, isse); PadReferenceFrame(pDst[0], nDstPitches[0], horizontalPadding, verticalPadding, width, height); PlaneCopy(pDst[1] + horizontalPadding/2 + verticalPadding/yRatioUV * nDstPitches[1], nDstPitches[1], pSrc[1], nSrcPitches[1], width/2, height/yRatioUV, isse); PadReferenceFrame(pDst[1], nDstPitches[1], horizontalPadding/2, verticalPadding/yRatioUV, width/2, height/yRatioUV); PlaneCopy(pDst[2] + horizontalPadding/2 + verticalPadding/yRatioUV * nDstPitches[2], nDstPitches[2], pSrc[2], nSrcPitches[2], width/2, height/yRatioUV, isse); PadReferenceFrame(pDst[2], nDstPitches[2], horizontalPadding/2, verticalPadding/yRatioUV, width/2, height/yRatioUV); // convert back from planes unsigned char *pDstYUY2 = dst->GetWritePtr(); int nDstPitchYUY2 = dst->GetPitch(); DstPlanes->YUY2FromPlanes(pDstYUY2, nDstPitchYUY2); return dst; }
PVideoFrame __stdcall TurnsTile::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n, env), sht = 0, dst = env->NewVideoFrame(vi); const unsigned char * srcY = src->GetReadPtr(PLANAR_Y), * srcU = src->GetReadPtr(PLANAR_U), * srcV = src->GetReadPtr(PLANAR_V), * shtY = 0, * shtU = 0, * shtV = 0; unsigned char * dstY = dst->GetWritePtr(PLANAR_Y), * dstU = dst->GetWritePtr(PLANAR_U), * dstV = dst->GetWritePtr(PLANAR_V); int SRC_PITCH_SAMPLES_Y = src->GetPitch(PLANAR_Y), SRC_PITCH_SAMPLES_U = src->GetPitch(PLANAR_U), SHT_PITCH_SAMPLES_Y = 0, SHT_PITCH_SAMPLES_U = 0, DST_PITCH_SAMPLES_Y = dst->GetPitch(PLANAR_Y), DST_PITCH_SAMPLES_U = dst->GetPitch(PLANAR_U); if (tilesheet) { sht = tilesheet->GetFrame(n, env); shtY = sht->GetReadPtr(PLANAR_Y); shtU = sht->GetReadPtr(PLANAR_U); shtV = sht->GetReadPtr(PLANAR_V); SHT_PITCH_SAMPLES_Y = sht->GetPitch(PLANAR_Y); SHT_PITCH_SAMPLES_U = sht->GetPitch(PLANAR_U); } if (PLANAR) processFramePlanar( srcY, srcU, srcV, shtY, shtU, shtV, dstY, dstU, dstV, SRC_PITCH_SAMPLES_Y, SRC_PITCH_SAMPLES_U, SHT_PITCH_SAMPLES_Y, SHT_PITCH_SAMPLES_U, DST_PITCH_SAMPLES_Y, DST_PITCH_SAMPLES_U, env); else processFramePacked( srcY, shtY, dstY, SRC_PITCH_SAMPLES_Y, SHT_PITCH_SAMPLES_Y, DST_PITCH_SAMPLES_Y, env); return dst; }
static void make_black_background_packed_all_zero ( PVideoFrame &frame, int bitdepth_minus_8 ) { memset( frame->GetWritePtr(), 0x00, frame->GetPitch() * frame->GetHeight() ); }
PVideoFrame __stdcall VNoise :: GetFrame(int n, IScriptEnvironment* env) { // Destination PVideoFrame dest = env->NewVideoFrame(this->clipInfo); unsigned char* destPtr = dest->GetWritePtr(); int destPitch = dest->GetPitch(); // Get main source PVideoFrame sourceMain = this->clip->GetFrame(n, env); const unsigned char* sourceMainPtr = sourceMain->GetReadPtr(); int sourceMainPitch = sourceMain->GetPitch(); int rgba[4]; // Loop values int x, y, j; int width = this->clipInfo.width; int height = this->clipInfo.height; int rowSize = width * this->components; // Copy from main source for (y = 0; y < height; ++y) { // Loop over line for (x = 0; x < rowSize; x += this->components) { // Get old for (j = 0; j < this->components; ++j) { rgba[j] = *(sourceMainPtr + x + j); } // Modify this->randomChange(rgba); // Set new for (j = 0; j < this->components; ++j) { *(destPtr + x + j) = rgba[j]; } } // Next line sourceMainPtr += sourceMainPitch; destPtr += destPitch; } // Done return dest; }
PVideoFrame __stdcall AlignPlanar::GetFrame(int n, IScriptEnvironment* env) { int plane = (env->PlanarChromaAlignment(IScriptEnvironment::PlanarChromaAlignmentTest)) ? PLANAR_U_ALIGNED : PLANAR_Y_ALIGNED; PVideoFrame src = child->GetFrame(n, env); if (!(src->GetRowSize(plane)&(FRAME_ALIGN-1))) return src; PVideoFrame dst = env->NewVideoFrame(vi); if ((dst->GetRowSize(PLANAR_Y_ALIGNED)&(FRAME_ALIGN-1))) env->ThrowError("AlignPlanar: [internal error] Returned frame was not aligned!"); env->BitBlt(dst->GetWritePtr(), dst->GetPitch(), src->GetReadPtr(), src->GetPitch(), src->GetRowSize(), src->GetHeight()); 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)); 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)); return dst; }
PVideoFrame TMaskCleaner::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n,env); PVideoFrame dst = env->NewVideoFrame(child->GetVideoInfo()); memset(dst->GetWritePtr(PLANAR_Y), 0, dst->GetPitch(PLANAR_Y) * dst->GetHeight(PLANAR_Y)); memset(lookup, 0, child->GetVideoInfo().height * child->GetVideoInfo().width / 8); ClearMask(dst->GetWritePtr(PLANAR_Y), src->GetReadPtr(PLANAR_Y), dst->GetRowSize(PLANAR_Y), dst->GetHeight(PLANAR_Y),src->GetPitch(PLANAR_Y), dst->GetPitch(PLANAR_Y)); return dst; }
PVideoFrame __stdcall MVMultiExtract::GetFrame(int n, IScriptEnvironment* env) { // DebugPrintf("MVAnalyse: Get src frame %d",n); PVideoFrame src = child->GetFrame(n, env); const BYTE* srcPtr=src->GetReadPtr(); int SrcPitch=src->GetPitch(); PVideoFrame dst = env->NewVideoFrame(vi); unsigned char *pDst = dst->GetWritePtr(); int DstPitch = dst->GetPitch(); // extract the appropriate rows out of the frame RGB32 is 4 bytes per pixel for(int IndexNum=0; IndexNum<NumIndices; ++IndexNum) { memcpy(reinterpret_cast<void*>(pDst+DstPitch*IndexNum), reinterpret_cast<void const*>(srcPtr+SrcPitch*Index[IndexNum]), vi.width*4); } return dst; }
extern "C" HRESULT __stdcall read_data(VF_FileHandle in, DWORD stream, void *out) { if (stream == VF_STREAM_VIDEO) { LPVF_ReadData_Video data = (LPVF_ReadData_Video)out; unsigned char *dst = (unsigned char *)data->lpData; if (data == NULL) return VF_ERROR; if (data->dwSize != sizeof(VF_ReadData_Video)) return VF_ERROR; vfMI *i = (vfMI*)in; if (i->type == D2V_TYPE) { unsigned char *src = i->getRGBFrameMI(data->dwFrameNumberL, i->ident); int y, height = i->vi->height; for (y = 0; y < height; y++) memcpy(dst+y*data->lPitch, src+y*i->vi->width*3, i->vi->width*3); } else { PVideoFrame src = (*i->clip)->GetFrame(data->dwFrameNumberL, i->avsEnv); i->avsEnv->BitBlt(dst, data->lPitch, src->GetReadPtr(), src->GetPitch(), src->GetRowSize(), src->GetHeight()); } } else if (stream == VF_STREAM_AUDIO) { LPVF_ReadData_Audio data = (LPVF_ReadData_Audio)out; if (data == NULL) return VF_ERROR; if (data->dwSize != sizeof(VF_ReadData_Audio)) return VF_ERROR; vfMI *i = (vfMI*)in; if (i->type == D2V_TYPE) return VF_ERROR; else { if (!(*i->clip)->GetVideoInfo().HasAudio()) return VF_ERROR; (*i->clip)->GetAudio(data->lpBuf, data->dwSamplePosL, data->dwSampleCount, i->avsEnv); data->dwReadedSampleCount = (unsigned long) min(data->dwSampleCount, max((*i->clip)->GetVideoInfo().num_audio_samples-data->dwSamplePosL,0)); } } else return VF_ERROR; return VF_OK; }
PVideoFrame __stdcall Turn::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n, env); PVideoFrame dst = env->NewVideoFrame(vi); if (vi.IsPlanar()) TurnPlanFunc(src->GetReadPtr(PLANAR_Y), dst->GetWritePtr(PLANAR_Y), src->GetReadPtr(PLANAR_U), dst->GetWritePtr(PLANAR_U), src->GetReadPtr(PLANAR_V), dst->GetWritePtr(PLANAR_V), src->GetRowSize(PLANAR_Y), src->GetHeight(PLANAR_Y), src->GetRowSize(PLANAR_U), src->GetHeight(PLANAR_U), src->GetPitch(PLANAR_Y), dst->GetPitch(PLANAR_Y), src->GetPitch(PLANAR_U), dst->GetPitch(PLANAR_U), src->GetPitch(PLANAR_V), direction); else TurnFunc(src->GetReadPtr(),dst->GetWritePtr(),src->GetRowSize(), src->GetHeight(),src->GetPitch(),dst->GetPitch(),direction); return dst; }
static void make_black_background_packed_yuv422 ( PVideoFrame &frame, int bitdepth_minus_8 ) { uint32_t *dst = (uint32_t *)frame->GetWritePtr(); int num_loops = frame->GetPitch() * frame->GetHeight() / 4; for( int i = 0; i < num_loops; i++ ) *dst++ = 0x00800080; }
void AvisynthVideoSource::OutputFrame(const FFMS_Frame *Frame, PVideoFrame &Dst, IScriptEnvironment *Env) { if (VI.IsPlanar()) { BlitPlane(Frame, Dst, Env, 0, VI.IsRGB() ? PLANAR_G : PLANAR_Y); if (HighBitDepth ? !VI.IsY() : !VI.IsY8()) { BlitPlane(Frame, Dst, Env, 1, VI.IsRGB() ? PLANAR_B : PLANAR_U); BlitPlane(Frame, Dst, Env, 2, VI.IsRGB() ? PLANAR_R : PLANAR_V); } if (VI.IsYUVA() || VI.IsPlanarRGBA()) BlitPlane(Frame, Dst, Env, 3, PLANAR_A); } else if (VI.IsYUY2()) { BlitPlane(Frame, Dst, Env, 0, 0); } else if (VI.IsRGB24() || VI.IsRGB32()) { Env->BitBlt( Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1), -Dst->GetPitch(), Frame->Data[0], Frame->Linesize[0], Dst->GetRowSize(), Dst->GetHeight()); } else { assert(false); } }
PVideoFrame SeparateRows::GetFrame(int n, IScriptEnvironment* env) { const int m = vi.IsRGB() ? interval-1 - n%interval : n%interval; // RGB upsidedown const int f = n/interval; PVideoFrame frame = child->GetFrame(f, env); if (vi.IsPlanar() && !vi.IsY8()) { const int Ypitch = frame->GetPitch(PLANAR_Y); const int UVpitch = frame->GetPitch(PLANAR_U); const int Yoffset = Ypitch * m; const int UVoffset = UVpitch * m; return env->SubframePlanar(frame, Yoffset, Ypitch * interval, frame->GetRowSize(PLANAR_Y), vi.height, UVoffset, UVoffset, UVpitch * interval); } const int pitch = frame->GetPitch(); return env->Subframe(frame, pitch * m, pitch * interval, frame->GetRowSize(), vi.height); }
void AvisynthVideoSource::OutputField(const FFMS_Frame *Frame, PVideoFrame &Dst, int Field, IScriptEnvironment *Env) { const FFMS_Frame *SrcPicture = Frame; if (VI.IsPlanar()) { BlitField(Frame, Dst, Env, 0, VI.IsRGB() ? PLANAR_G : PLANAR_Y, Field); if (HighBitDepth ? !VI.IsY() : !VI.IsY8()) { BlitField(Frame, Dst, Env, 1, VI.IsRGB() ? PLANAR_B : PLANAR_U, Field); BlitField(Frame, Dst, Env, 2, VI.IsRGB() ? PLANAR_R : PLANAR_V, Field); } if (VI.IsYUVA() || VI.IsPlanarRGBA()) BlitField(Frame, Dst, Env, 3, PLANAR_A, Field); } else if (VI.IsYUY2()) { BlitField(Frame, Dst, Env, 0, 0, Field); } else if (VI.IsRGB24() || VI.IsRGB32()) { Env->BitBlt( Dst->GetWritePtr() + Dst->GetPitch() * (Dst->GetHeight() - 1 - Field), -Dst->GetPitch() * 2, SrcPicture->Data[0] + SrcPicture->Linesize[0] * Field, SrcPicture->Linesize[0] * 2, Dst->GetRowSize(), Dst->GetHeight() / 2); } else { assert(false); } }
static void make_black_background_planar_yuv_interleaved ( PVideoFrame &frame, int bitdepth_minus_8 ) { memset( frame->GetWritePtr( PLANAR_Y ), 0x00, frame->GetPitch( PLANAR_Y ) * frame->GetHeight( PLANAR_Y ) ); uint8_t msb = (uint8_t)((0x80U << bitdepth_minus_8) >> 8); int size = frame->GetPitch( PLANAR_U ) * frame->GetHeight( PLANAR_U ); for( int i = 0; i < size; i++ ) if( i & 1 ) { *(frame->GetWritePtr( PLANAR_U ) + i) = msb; *(frame->GetWritePtr( PLANAR_V ) + i) = msb; } else { *(frame->GetWritePtr( PLANAR_U ) + i) = 0x00; *(frame->GetWritePtr( PLANAR_V ) + i) = 0x00; } }
PVideoFrame AreaResize::GetFrame(int n, IScriptEnvironment* env) { PVideoFrame src = child->GetFrame(n, env); if (params[0].src_width == params[0].target_width && params[0].src_height == params[0].target_height) { return src; } PVideoFrame dst = env->NewVideoFrame(vi); int plane[] = {PLANAR_Y, PLANAR_U, PLANAR_V}; for (int i = 0, time = vi.IsInterleaved() ? 1 : 3; i < time; i++) { const BYTE* srcp = src->GetReadPtr(plane[i]); int src_pitch = src->GetPitch(plane[i]); const BYTE* resized_h; if (params[i].src_width == params[i].target_width) { resized_h = srcp; } else { if (!ResizeHorizontal(buff, srcp, src_pitch, ¶ms[i])) { return dst; } resized_h = buff; src_pitch = dst->GetRowSize(plane[i]); } BYTE* dstp = dst->GetWritePtr(plane[i]); int dst_pitch = dst->GetPitch(plane[i]); if (params[i].src_height == params[i].target_height) { env->BitBlt(dstp, dst_pitch, resized_h, src_pitch, dst->GetRowSize(plane[i]), dst->GetHeight(plane[i])); continue; } if (!ResizeVertical(dstp, dst_pitch, resized_h, src_pitch, ¶ms[i])) { return dst; } } return dst; }