📄 avisynth.h
字号:
// smart pointer to VideoFrameclass PVideoFrame { VideoFrame* p; void Init(VideoFrame* x) { if (x) x->AddRef(); p=x; } void Set(VideoFrame* x) { if (x) x->AddRef(); if (p) p->Release(); p=x; }public: PVideoFrame() { p = 0; } PVideoFrame(const PVideoFrame& x) { Init(x.p); } PVideoFrame(VideoFrame* x) { Init(x); } void operator=(VideoFrame* x) { Set(x); } void operator=(const PVideoFrame& x) { Set(x.p); } VideoFrame* operator->() const { return p; } // for conditional expressions operator void*() const { return p; } bool operator!() const { return !p; } ~PVideoFrame() { if (p) p->Release();}};class AVSValue {public: AVSValue() { type = 'v'; } AVSValue(IClip* c) { type = 'c'; clip = c; if (c) c->AddRef(); } AVSValue(const PClip& c) { type = 'c'; clip = c.GetPointerWithAddRef(); } AVSValue(bool b) { type = 'b'; boolean = b; } AVSValue(int i) { type = 'i'; integer = i; }// AVSValue(__int64 l) { type = 'l'; longlong = l; } AVSValue(float f) { type = 'f'; floating_pt = f; } AVSValue(double f) { type = 'f'; floating_pt = float(f); } AVSValue(const char* s) { type = 's'; string = s; } AVSValue(const AVSValue* a, int size) { type = 'a'; array = a; array_size = (short)size; } AVSValue(const AVSValue& v) { Assign(&v, true); } ~AVSValue() { if (IsClip() && clip) clip->Release(); } AVSValue& operator=(const AVSValue& v) { Assign(&v, false); return *this; } // Note that we transparently allow 'int' to be treated as 'float'. // There are no int<->bool conversions, though. bool Defined() const { return type != 'v'; } bool IsClip() const { return type == 'c'; } bool IsBool() const { return type == 'b'; } bool IsInt() const { return type == 'i'; }// bool IsLong() const { return (type == 'l'|| type == 'i'); } bool IsFloat() const { return type == 'f' || type == 'i'; } bool IsString() const { return type == 's'; } bool IsArray() const { return type == 'a'; } PClip AsClip() const { _ASSERTE(IsClip()); return IsClip()?clip:0; } bool AsBool() const { _ASSERTE(IsBool()); return boolean; } int AsInt() const { _ASSERTE(IsInt()); return integer; }// int AsLong() const { _ASSERTE(IsLong()); return longlong; } const char* AsString() const { _ASSERTE(IsString()); return IsString()?string:0; } double AsFloat() const { _ASSERTE(IsFloat()); return IsInt()?integer:floating_pt; } bool AsBool(bool def) const { _ASSERTE(IsBool()||!Defined()); return IsBool() ? boolean : def; } int AsInt(int def) const { _ASSERTE(IsInt()||!Defined()); return IsInt() ? integer : def; } double AsFloat(double def) const { _ASSERTE(IsFloat()||!Defined()); return IsInt() ? integer : type=='f' ? floating_pt : def; } const char* AsString(const char* def) const { _ASSERTE(IsString()||!Defined()); return IsString() ? string : def; } int ArraySize() const { _ASSERTE(IsArray()); return IsArray()?array_size:1; } const AVSValue& operator[](int index) const { _ASSERTE(IsArray() && index>=0 && index<array_size); return (IsArray() && index>=0 && index<array_size) ? array[index] : *this; }private: short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong short array_size; union { IClip* clip; bool boolean; int integer; float floating_pt; const char* string; const AVSValue* array;// __int64 longlong; }; void Assign(const AVSValue* src, bool init) { if (src->IsClip() && src->clip) src->clip->AddRef(); if (!init && IsClip() && clip) clip->Release(); // make sure this copies the whole struct! //((__int32*)this)[0] = ((__int32*)src)[0]; //((__int32*)this)[1] = ((__int32*)src)[1]; memcpy(this,src,sizeof(this)); }};// instantiable null filterclass GenericVideoFilter : public IClip {protected: PClip child; VideoInfo vi;public: GenericVideoFilter(PClip _child) : child(_child) { vi = child->GetVideoInfo(); } PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) { return child->GetFrame(n, env); } void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) { child->GetAudio(buf, start, count, env); } const VideoInfo& __stdcall GetVideoInfo() { return vi; } bool __stdcall GetParity(int n) { return child->GetParity(n); } void __stdcall SetCacheHints(int cachehints,int frame_range) { } ; // We do not pass cache requests upwards, only to the next filter.};/* Helper classes useful to plugin authors */class AlignPlanar : public GenericVideoFilter{public: AlignPlanar(PClip _clip); static PClip Create(PClip clip); PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);};class FillBorder : public GenericVideoFilter{public: FillBorder(PClip _clip); static PClip Create(PClip clip); PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);};class ConvertAudio : public GenericVideoFilter/** * Helper class to convert audio to any format **/{public: ConvertAudio(PClip _clip, int prefered_format); void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env); void __stdcall SetCacheHints(int cachehints,int frame_range); // We do pass cache requests upwards, to the cache! static PClip Create(PClip clip, int sample_type, int prefered_type); static AVSValue __cdecl Create_float(AVSValue args, void*, IScriptEnvironment*); static AVSValue __cdecl Create_32bit(AVSValue args, void*, IScriptEnvironment*); static AVSValue __cdecl Create_24bit(AVSValue args, void*, IScriptEnvironment*); static AVSValue __cdecl Create_16bit(AVSValue args, void*, IScriptEnvironment*); static AVSValue __cdecl Create_8bit(AVSValue args, void*, IScriptEnvironment*); virtual ~ConvertAudio();private: void convertToFloat(char* inbuf, float* outbuf, char sample_type, int count); void convertToFloat_3DN(char* inbuf, float* outbuf, char sample_type, int count); void convertToFloat_SSE(char* inbuf, float* outbuf, char sample_type, int count); void convertToFloat_SSE2(char* inbuf, float* outbuf, char sample_type, int count); void convertFromFloat(float* inbuf, void* outbuf, char sample_type, int count); void convertFromFloat_3DN(float* inbuf, void* outbuf, char sample_type, int count); void convertFromFloat_SSE(float* inbuf, void* outbuf, char sample_type, int count); void convertFromFloat_SSE2(float* inbuf, void* outbuf, char sample_type, int count); __inline int Saturate_int8(float n); __inline short Saturate_int16(float n); __inline int Saturate_int24(float n); __inline int Saturate_int32(float n); char src_format; char dst_format; int src_bps; char *tempbuffer; SFLOAT *floatbuffer; int tempbuffer_size;};// For GetCPUFlags. These are backwards-compatible with those in VirtualDub.enum { /* slowest CPU to support extension */ CPUF_FORCE = 0x01, // N/A CPUF_FPU = 0x02, // 386/486DX CPUF_MMX = 0x04, // P55C, K6, PII CPUF_INTEGER_SSE = 0x08, // PIII, Athlon CPUF_SSE = 0x10, // PIII, Athlon XP/MP CPUF_SSE2 = 0x20, // PIV, Hammer CPUF_3DNOW = 0x40, // K6-2 CPUF_3DNOW_EXT = 0x80, // Athlon CPUF_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2, which // only Hammer will have anyway) CPUF_SSE3 = 0x100, // PIV+, Hammer};#define MAX_INT 0x7fffffff#define MIN_INT -0x7fffffff // ::FIXME:: research why this is not 0x80000000#ifdef AVS26class IClipLocalStorage;#endifclass IScriptEnvironment {public: virtual __stdcall ~IScriptEnvironment() {} virtual /*static*/ long __stdcall GetCPUFlags() = 0; virtual char* __stdcall SaveString(const char* s, int length = -1) = 0; virtual char* __stdcall Sprintf(const char* fmt, ...) = 0; // note: val is really a va_list; I hope everyone typedefs va_list to a pointer virtual char* __stdcall VSprintf(const char* fmt, void* val) = 0; __declspec(noreturn) virtual void __stdcall ThrowError(const char* fmt, ...) = 0; class NotFound /*exception*/ {}; // thrown by Invoke and GetVar typedef AVSValue (__cdecl *ApplyFunc)(AVSValue args, void* user_data, IScriptEnvironment* env); virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data) = 0; virtual bool __stdcall FunctionExists(const char* name) = 0; virtual AVSValue __stdcall Invoke(const char* name, const AVSValue args, const char** arg_names=0) = 0; virtual AVSValue __stdcall GetVar(const char* name) = 0; virtual bool __stdcall SetVar(const char* name, const AVSValue& val) = 0; virtual bool __stdcall SetGlobalVar(const char* name, const AVSValue& val) = 0; virtual void __stdcall PushContext(int level=0) = 0; virtual void __stdcall PopContext() = 0; // align should be 4 or 8 virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, int align=FRAME_ALIGN) = 0; virtual bool __stdcall MakeWritable(PVideoFrame* pvf) = 0; virtual /*static*/ void __stdcall BitBlt(BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height) = 0; typedef void (__cdecl *ShutdownFunc)(void* user_data, IScriptEnvironment* env); virtual void __stdcall AtExit(ShutdownFunc function, void* user_data) = 0; virtual void __stdcall CheckVersion(int version = AVISYNTH_INTERFACE_VERSION) = 0; virtual PVideoFrame __stdcall Subframe(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, int new_height) = 0; virtual int __stdcall SetMemoryMax(int mem) = 0; virtual int __stdcall SetWorkingDir(const char * newdir) = 0; virtual void* __stdcall ManageCache(int key, void* data) = 0; enum PlanarChromaAlignmentMode { PlanarChromaAlignmentOff, PlanarChromaAlignmentOn, PlanarChromaAlignmentTest }; virtual bool __stdcall PlanarChromaAlignment(PlanarChromaAlignmentMode key) = 0;#ifdef AVS26 virtual PVideoFrame __stdcall SubframePlanar(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV) = 0; virtual void __stdcall SetMTMode(int mode,int threads,bool temporary)=0; virtual int __stdcall GetMTMode(bool return_nthreads)=0; virtual IClipLocalStorage* __stdcall AllocClipLocalStorage()=0; virtual void __stdcall SaveClipLocalStorage()=0; virtual void __stdcall RestoreClipLocalStorage()=0;#endif};// avisynth.dll exports this; it's a way to use it as a library, without// writing an AVS script or without going through AVIFile.IScriptEnvironment* __stdcall CreateScriptEnvironment(int version = AVISYNTH_INTERFACE_VERSION);#pragma pack(pop)#endif //__AVISYNTH_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -