Skip to content

Commit f2ecd52

Browse files
authored
Merge pull request #53 from v0lt/fix_check_video_format
Fixed a crash of the AviSynth filter if the video format is not supported by xy-VSFilter
2 parents 053d932 + 05a6ee5 commit f2ecd52

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

src/filters/transform/vsfilter/plugins.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -938,14 +938,42 @@ class CTextSubFilter : virtual public CFilter
938938

939939
class CAvisynthFilter : public GenericVideoFilter, virtual public CFilter
940940
{
941-
public:
941+
int msp_type;
942942
bool has_at_least_v8; // avs interface version check
943943
bool useRGBAwhenRGB32; // instead of old method: bool "RGBA" Avisynth variable. default false for TextSub, true for MaskSub
944+
bool YV16asYUY2;
945+
public:
944946

945947
VFRTranslator* vfr;
946948

947-
CAvisynthFilter(PClip c, IScriptEnvironment* env, bool _useRGBAwhenRGB32, VFRTranslator* _vfr = 0) : GenericVideoFilter(c), useRGBAwhenRGB32(_useRGBAwhenRGB32), vfr(_vfr)
949+
CAvisynthFilter(PClip c, IScriptEnvironment* env, bool _useRGBAwhenRGB32, VFRTranslator* _vfr = 0)
950+
: GenericVideoFilter(c)
951+
, useRGBAwhenRGB32(_useRGBAwhenRGB32)
952+
, vfr(_vfr)
948953
{
954+
const bool doYV16asYUY2 = false; // hey, we have native YV16 now
955+
YV16asYUY2 = doYV16asYUY2 && vi.IsYV16(); // must use single YUY2 buffer internally
956+
957+
msp_type =
958+
vi.IsRGB32() ? (useRGBAwhenRGB32 ? MSP_RGBA : MSP_RGB32) :
959+
vi.IsRGB24() ? MSP_RGB24 :
960+
vi.IsYUY2() ? MSP_YUY2 :
961+
doYV16asYUY2 && vi.IsYV16() ? MSP_YUY2 :
962+
/*vi.IsYV12()*/ vi.pixel_type == VideoInfo::CS_YV12 ? (s_fSwapUV ? MSP_IYUV : MSP_YV12) :
963+
/*vi.IsIYUV()*/ vi.pixel_type == VideoInfo::CS_IYUV ? (s_fSwapUV ? MSP_YV12 : MSP_IYUV) :
964+
vi.pixel_type == VideoInfo::CS_YUV420P10 ? MSP_P010 : // P.F. 180224 10 bit support
965+
vi.pixel_type == VideoInfo::CS_YUV420P16 ? MSP_P016 : // P.F. 180224 16 bit support
966+
// 20210305
967+
vi.pixel_type == VideoInfo::CS_YUV422P10 ? MSP_P210 :
968+
vi.pixel_type == VideoInfo::CS_YUV422P16 ? MSP_P216 :
969+
vi.IsYV16() ? MSP_YV16 : // not natively yet. converted to YUY2 on the fly
970+
vi.IsYV24() ? MSP_YV24 :
971+
-1;
972+
973+
if (msp_type == -1) {
974+
env->ThrowError("Format not supported. Use RGB24,RGB32,YUY2,YV12,YV16,YV24,YUV420P10/P16,YUV422P10/P16.");
975+
}
976+
949977
has_at_least_v8 = true;
950978
try { env->CheckVersion(8); }
951979
catch (const AvisynthError&) { has_at_least_v8 = false; }
@@ -1253,33 +1281,12 @@ class CTextSubFilter : virtual public CFilter
12531281
const bool sse2 = (env->GetCPUFlags() & CPUF_SSE2) != 0;
12541282
const bool sse41 = (env->GetCPUFlags() & CPUF_SSE4_1) != 0;
12551283

1256-
const bool doYV16asYUY2 = false; // hey, we have native YV16 now
1257-
12581284
SubPicDesc dst;
12591285
// dst pointers: later
12601286
dst.w = vi.width;
12611287
dst.h = vi.height;
12621288

1263-
dst.type =
1264-
vi.IsRGB32() ? (useRGBAwhenRGB32 ? MSP_RGBA : MSP_RGB32) :
1265-
vi.IsRGB24() ? MSP_RGB24 :
1266-
vi.IsYUY2() ? MSP_YUY2 :
1267-
doYV16asYUY2 && vi.IsYV16() ? MSP_YUY2 :
1268-
/*vi.IsYV12()*/ vi.pixel_type == VideoInfo::CS_YV12 ? (s_fSwapUV ? MSP_IYUV : MSP_YV12) :
1269-
/*vi.IsIYUV()*/ vi.pixel_type == VideoInfo::CS_IYUV ? (s_fSwapUV ? MSP_YV12 : MSP_IYUV) :
1270-
vi.pixel_type == VideoInfo::CS_YUV420P10 ? MSP_P010 : // P.F. 180224 10 bit support
1271-
vi.pixel_type == VideoInfo::CS_YUV420P16 ? MSP_P016 : // P.F. 180224 16 bit support
1272-
// 20210305
1273-
vi.pixel_type == VideoInfo::CS_YUV422P10 ? MSP_P210 :
1274-
vi.pixel_type == VideoInfo::CS_YUV422P16 ? MSP_P216 :
1275-
vi.IsYV16() ? MSP_YV16 : // not natively yet. converted to YUY2 on the fly
1276-
vi.IsYV24() ? MSP_YV24 :
1277-
-1;
1278-
1279-
if (dst.type == -1)
1280-
env->ThrowError("Format not supported. Use RGB24,RGB32,YUY2,YV12,YV16,YV24,YUV420P10/P16,YUV422P10/P16.");
1281-
1282-
bool YV16asYUY2 = doYV16asYUY2 && vi.IsYV16(); // must use single YUY2 buffer internally
1289+
dst.type = msp_type;
12831290

12841291
bool semi_packed_p10 = (vi.pixel_type == VideoInfo::CS_YUV420P10) || (vi.pixel_type == VideoInfo::CS_YUV422P10);
12851292
bool semi_packed_p16 = (vi.pixel_type == VideoInfo::CS_YUV420P16) || (vi.pixel_type == VideoInfo::CS_YUV422P16);

0 commit comments

Comments
 (0)