From c6075b912800621f652c20ce675920995c3329e4 Mon Sep 17 00:00:00 2001 From: OKA Motofumi Date: Tue, 5 Jul 2016 18:09:45 +0900 Subject: [PATCH] support HBD formats of Avisynth+MT. --- readme.rst | 32 ++++++++++++----- src/VapourSource.cpp | 78 +++++++++++++++++++++++----------------- src/VapourSource.vcxproj | 10 ++++-- 3 files changed, 77 insertions(+), 43 deletions(-) diff --git a/readme.rst b/readme.rst index 633dcf4..c54f9d3 100644 --- a/readme.rst +++ b/readme.rst @@ -5,15 +5,15 @@ VapourSynth Script Importer for Avisynth2.6/Avisynth+ version: --------- -0.0.4 +0.1.0 requirement: ------------ VapourSynth r30 or later -AviSynth2.60/Avisynth+r1569 or greater +AviSynth2.60 / Avisynth+MT r2005 or greater -WindowsVista sp2 or later +Windows Vista sp2 or later Microsoft Visual C++ 2015 Redistributable Package @@ -35,12 +35,32 @@ as follows.:: source - vapoursynth script. stacked and index are same as VSImport. +Measurement table of formats: +------------------------------ + + VapourSynth Avisynth2.6 Avisynth+MT + GRAY8 Y8 Y8 + GRAY16/H Y8(x2 width) Y16 + GRAYS Y8(x4 width) Y32 + YUV444P8 YV24 YV24 + YUV444P9/10/16/H YV24(x2 width) YUV444P16 + YUV444PS YV24(x4 width) YUV444PS + YUV422P8 YV16 YV16 + YUV422P9/10/16 YV16(x2 width) YUV422P16 + YUV420P8 YV12 YV12 + YUV420P9/10/16 YV12(x2 width) YUV420P16 + COMPATBGR32 RGB32 RGB32 + COMPATYUY2 YUY2 YUY2 + +Others are not supported. + + examples: --------- VSImport example:: LoadPlugin("c:/avisynth/plugins/VapourSource.dll") - VSImport("d:/my_scripts/10bits_yuv_clip.vpy", stacked=true) + VSImport("d:/my_scripts/16bits_yuv_clip.vpy", stacked=false) VSEval example:: @@ -57,10 +77,6 @@ VSEval example:: note: ----- -Supported formats are YUV420P8/9/10/16, YUV422P8/9/10/16, YUV444P8/9/10/16, -YUV411P8, GRAY8/16, RGB24, COMPATBGR32 and COMPATYUY2. -Others are not. - Not constant format/resolution/framerate clips are unsupported. source code: diff --git a/src/VapourSource.cpp b/src/VapourSource.cpp index 5e51cd5..10270e7 100644 --- a/src/VapourSource.cpp +++ b/src/VapourSource.cpp @@ -38,7 +38,7 @@ #pragma warning(disable:4996) -#define VS_VERSION "0.0.5" +#define VS_VERSION "0.1.0" typedef IScriptEnvironment ise_t; @@ -60,31 +60,35 @@ convert_ansi_to_utf8(const char* ansi_string, std::vector& buff) } -static int get_avs_pixel_type(int in) noexcept +static int get_avs_pixel_type(int in, bool is_plus) noexcept { struct { int vs_format; int avs_pixel_type; } table[] = { - {pfGray8, VideoInfo::CS_Y8 }, - {pfGray16, VideoInfo::CS_Y8 }, - {pfYUV420P8, VideoInfo::CS_I420 }, - {pfYUV420P9, VideoInfo::CS_I420 }, - {pfYUV420P10, VideoInfo::CS_I420 }, - {pfYUV420P16, VideoInfo::CS_I420 }, - {pfYUV422P8, VideoInfo::CS_YV16 }, - {pfYUV422P9, VideoInfo::CS_YV16 }, - {pfYUV422P10, VideoInfo::CS_YV16 }, - {pfYUV422P16, VideoInfo::CS_YV16 }, - {pfYUV444P8, VideoInfo::CS_YV24 }, - {pfYUV444P9, VideoInfo::CS_YV24 }, - {pfYUV444P10, VideoInfo::CS_YV24 }, - {pfYUV444P16, VideoInfo::CS_YV24 }, - {pfYUV411P8, VideoInfo::CS_YV411 }, - {pfRGB24, VideoInfo::CS_BGR24 }, - {pfCompatBGR32, VideoInfo::CS_BGR32 }, - {pfCompatYUY2, VideoInfo::CS_YUY2 }, - {in, VideoInfo::CS_UNKNOWN} + {pfGray8, VideoInfo::CS_Y8 }, + {pfGray16, is_plus ? VideoInfo::CS_Y16 : VideoInfo::CS_Y8 }, + {pfGrayH, is_plus ? VideoInfo::CS_Y16 : VideoInfo::CS_Y8 }, + {pfGrayS, is_plus ? VideoInfo::CS_Y32 : VideoInfo::CS_Y8 }, + {pfYUV420P8, VideoInfo::CS_I420 }, + {pfYUV420P9, is_plus ? VideoInfo::CS_YUV420P16 : VideoInfo::CS_I420 }, + {pfYUV420P10, is_plus ? VideoInfo::CS_YUV420P16 : VideoInfo::CS_I420 }, + {pfYUV420P16, is_plus ? VideoInfo::CS_YUV420P16 : VideoInfo::CS_I420 }, + {pfYUV422P8, VideoInfo::CS_YV16 }, + {pfYUV422P9, is_plus ? VideoInfo::CS_YUV422P16 : VideoInfo::CS_YV16 }, + {pfYUV422P10, is_plus ? VideoInfo::CS_YUV422P16 : VideoInfo::CS_YV16 }, + {pfYUV422P16, is_plus ? VideoInfo::CS_YUV422P16 : VideoInfo::CS_YV16 }, + {pfYUV444P8, VideoInfo::CS_YV24 }, + {pfYUV444P9, is_plus ? VideoInfo::CS_YUV444P16 : VideoInfo::CS_YV24 }, + {pfYUV444P10, is_plus ? VideoInfo::CS_YUV444P16 : VideoInfo::CS_YV24 }, + {pfYUV444P16, is_plus ? VideoInfo::CS_YUV444P16 : VideoInfo::CS_YV24 }, + {pfYUV444PH, is_plus ? VideoInfo::CS_YUV444P16 : VideoInfo::CS_YV24 }, + {pfYUV444PS, is_plus ? VideoInfo::CS_YUV444PS : VideoInfo::CS_YV24 }, + {pfYUV411P8, VideoInfo::CS_YV411 }, + {pfRGB24, VideoInfo::CS_BGR24 }, + {pfCompatBGR32, VideoInfo::CS_BGR32 }, + {pfCompatYUY2, VideoInfo::CS_YUY2 }, + {in, VideoInfo::CS_UNKNOWN } }; int i = 0; @@ -103,7 +107,7 @@ write_interleaved_frame(const VSAPI* vsapi, const VSFrameRef* src, int dstp_adjust = 0; if ((vsapi->getFrameFormat(src))->id == pfCompatBGR32) { pitch_mul = -1; - dstp_adjust = 1; + dstp_adjust = -1; } for (int p = 0; p < num_planes; p++) { @@ -112,7 +116,7 @@ write_interleaved_frame(const VSAPI* vsapi, const VSFrameRef* src, int dst_pitch = dst->GetPitch(plane) * pitch_mul; int height = dst->GetHeight(plane); uint8_t *dstp = dst->GetWritePtr(plane) + - dstp_adjust * (-dst_pitch * (height - 1)); + dstp_adjust * (dst_pitch * (height - 1)); env->BitBlt(dstp, dst_pitch, vsapi->getReadPtr(src, p), vsapi->getStride(src, p), dst->GetRowSize(plane), height); @@ -295,20 +299,30 @@ VapourSource(const char* source, bool stacked, int index, const char* m, validate(vsvi->fpsNum > UINT_MAX, "clip has over" + umax + "fpsnum."); validate(vsvi->fpsDen > UINT_MAX, "clip has over " + umax + "fpsden."); - vi.pixel_type = get_avs_pixel_type(vsvi->format->id); + bool is_plus = env->FunctionExists("SetFilterMTMode") && !stacked; + + vi.pixel_type = get_avs_pixel_type(vsvi->format->id, is_plus); validate(vi.pixel_type == vi.CS_UNKNOWN, "input clip is unsupported format."); - int over_8bit = vi.IsPlanar() ? vsvi->format->bytesPerSample - 1 : 0; - vi.width = vsvi->width << (over_8bit * (stacked ? 0 : 1)); - vi.height = vsvi->height << (over_8bit * (stacked ? 1 : 0)); + vi.width = vsvi->width; + vi.height = vsvi->height; vi.fps_numerator = (unsigned)vsvi->fpsNum; vi.fps_denominator = (unsigned)vsvi->fpsDen; vi.num_frames = vsvi->numFrames; vi.SetFieldBased(false); - func_write_frame = vi.IsRGB24() ? write_bgr24_frame : - over_8bit && stacked ? write_stacked_frame : - write_interleaved_frame; + int bytes = vi.IsPlanar() ? vsvi->format->bytesPerSample : 1; + if (!is_plus && bytes > 1) { + vi.width *= bytes; + } + if (stacked && bytes > 1) { + vi.width /= 2; + vi.height *= 2; + } + + func_write_frame = vi.IsRGB24() ? write_bgr24_frame : + stacked && bytes > 1 ? write_stacked_frame : + write_interleaved_frame; } @@ -364,12 +378,12 @@ AvisynthPluginInit3(ise_t* env, const AVS_Linkage* const vectors) create_vapoursource, "VSImport"); env->AddFunction("VSEval", "[source]s[stacked]b[index]i", create_vapoursource, "VSEval"); - +#if 0 if (env->FunctionExists("SetFilterMTMode")) { auto env2 = static_cast(env); env2->SetFilterMTMode("VSImport", MT_SERIALIZED, true); env2->SetFilterMTMode("VSEval", MT_SERIALIZED, true); } - +#endif return "VapourSynth Script importer ver." VS_VERSION " by Oka Motofumi"; } diff --git a/src/VapourSource.vcxproj b/src/VapourSource.vcxproj index 4a24787..79f1eae 100644 --- a/src/VapourSource.vcxproj +++ b/src/VapourSource.vcxproj @@ -119,7 +119,7 @@ MultiThreadedDLL Level3 ProgramDatabase - Full + MaxSpeed true true true @@ -128,6 +128,8 @@ C:\Program Files %28x86%29\VapourSynth\sdk\include\vapoursynth;C:\my_projects\AviSynthPlus\avs_core\include;%(AdditionalIncludeDirectories) AnySuitable Fast + Speed + true MachineX86 @@ -146,15 +148,17 @@ MultiThreadedDLL Level3 ProgramDatabase - Full + MaxSpeed true true true - StreamingSIMDExtensions2 + NotSet StdCall C:\Program Files %28x86%29\VapourSynth\sdk\include\vapoursynth;C:\my_projects\AviSynthPlus\avs_core\include;%(AdditionalIncludeDirectories) AnySuitable Fast + true + Speed false