1 // Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al.
2 // http://www.avisynth.org
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // http://www.gnu.org/copyleft/gpl.html .
19 // Linking Avisynth statically or dynamically with other modules is making a
20 // combined work based on Avisynth. Thus, the terms and conditions of the GNU
21 // General Public License cover the whole combination.
23 // As a special exception, the copyright holders of Avisynth give you
24 // permission to link Avisynth with independent modules that communicate with
25 // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
26 // terms of these independent modules, and to copy and distribute the
27 // resulting combined work under terms of your choice, provided that
28 // every copy of the combined work is accompanied by a complete copy of
29 // the source code of Avisynth (the version of Avisynth used to produce the
30 // combined work), being distributed under the terms of the GNU General
31 // Public License plus this exception. An independent module is a module
32 // which is not derived from or based on Avisynth, such as 3rd-party filters,
33 // import and export plugins, or graphical user interfaces.
38 #ifndef __AVISYNTH_H__
39 #define __AVISYNTH_H__
41 enum { AVISYNTH_INTERFACE_VERSION
= 3 };
44 /* Define all types necessary for interfacing with avisynth.dll
45 Moved from internal.h */
47 // Win32 API macros, notably the types BYTE, DWORD, ULONG, etc.
50 #if (_MSC_VER >= 1400)
51 extern "C" LONG __cdecl
_InterlockedIncrement(LONG
volatile * pn
);
52 extern "C" LONG __cdecl
_InterlockedDecrement(LONG
volatile * pn
);
53 #pragma intrinsic(_InterlockedIncrement)
54 #pragma intrinsic(_InterlockedDecrement)
55 #define InterlockedIncrement _InterlockedIncrement
56 #define InterlockedDecrement _InterlockedDecrement
59 // COM interface macros
63 // Raster types used by VirtualDub & Avisynth
64 #define in64 (__int64)(unsigned short)
65 typedef unsigned long Pixel
; // this will break on 64-bit machines!
66 typedef unsigned long Pixel32
;
67 typedef unsigned char Pixel8
;
68 typedef long PixCoord
;
70 typedef long PixOffset
;
73 /* Compiler-specific crap */
75 // Tell MSVC to stop precompiling here
80 // Set up debugging macros for MS compilers; for others, step down to the
81 // standard <assert.h> interface
85 #define _RPT0(a,b) ((void)0)
86 #define _RPT1(a,b,c) ((void)0)
87 #define _RPT2(a,b,c,d) ((void)0)
88 #define _RPT3(a,b,c,d,e) ((void)0)
89 #define _RPT4(a,b,c,d,e,f) ((void)0)
91 #define _ASSERTE(x) assert(x)
97 // I had problems with Premiere wanting 1-byte alignment for its structures,
98 // so I now set the Avisynth struct alignment explicitly here.
101 #define FRAME_ALIGN 16
102 // Default frame alignment is 16 bytes, to help P4, when using SSE2
104 // The VideoInfo struct holds global information about a clip (i.e.
105 // information that does not depend on the frame number). The GetVideoInfo
106 // method in IClip returns this struct.
108 // Audio Sample information
109 typedef float SFLOAT
;
111 enum {SAMPLE_INT8
= 1<<0,
113 SAMPLE_INT24
= 1<<2, // Int24 is a very stupid thing to code, but it's supported by some hardware.
115 SAMPLE_FLOAT
= 1<<4};
122 PLANAR_Y_ALIGNED
=PLANAR_Y
|PLANAR_ALIGNED
,
123 PLANAR_U_ALIGNED
=PLANAR_U
|PLANAR_ALIGNED
,
124 PLANAR_V_ALIGNED
=PLANAR_V
|PLANAR_ALIGNED
127 class AvisynthError
/* exception */ {
129 const char* const msg
;
130 AvisynthError(const char* _msg
) : msg(_msg
) {}
134 int width
, height
; // width=0 means no video
135 unsigned fps_numerator
, fps_denominator
;
137 // This is more extensible than previous versions. More properties can be added seeminglesly.
139 // Colorspace properties.
143 CS_INTERLEAVED
= 1<<30,
147 // Specific colorformats
148 enum { CS_UNKNOWN
= 0,
149 CS_BGR24
= 1<<0 | CS_BGR
| CS_INTERLEAVED
,
150 CS_BGR32
= 1<<1 | CS_BGR
| CS_INTERLEAVED
,
151 CS_YUY2
= 1<<2 | CS_YUV
| CS_INTERLEAVED
,
152 CS_YV12
= 1<<3 | CS_YUV
| CS_PLANAR
, // y-v-u, 4:2:0 planar
153 CS_I420
= 1<<4 | CS_YUV
| CS_PLANAR
, // y-u-v, 4:2:0 planar
154 CS_IYUV
= 1<<4 | CS_YUV
| CS_PLANAR
// same as above
156 int pixel_type
; // changed to int as of 2.5
159 int audio_samples_per_second
; // 0 means no audio
160 int sample_type
; // as of 2.5
161 __int64 num_audio_samples
; // changed as of 2.5
162 int nchannels
; // as of 2.5
164 // Imagetype properties
174 // useful functions of the above
175 bool HasVideo() const { return (width
!=0); }
176 bool HasAudio() const { return (audio_samples_per_second
!=0); }
177 bool IsRGB() const { return !!(pixel_type
&CS_BGR
); }
178 bool IsRGB24() const { return (pixel_type
&CS_BGR24
)==CS_BGR24
; } // Clear out additional properties
179 bool IsRGB32() const { return (pixel_type
& CS_BGR32
) == CS_BGR32
; }
180 bool IsYUV() const { return !!(pixel_type
&CS_YUV
); }
181 bool IsYUY2() const { return (pixel_type
& CS_YUY2
) == CS_YUY2
; }
182 bool IsYV12() const { return ((pixel_type
& CS_YV12
) == CS_YV12
)||((pixel_type
& CS_I420
) == CS_I420
); }
183 bool IsColorSpace(int c_space
) const { return ((pixel_type
& c_space
) == c_space
); }
184 bool Is(int property
) const { return ((pixel_type
& property
)==property
); }
185 bool IsPlanar() const { return !!(pixel_type
& CS_PLANAR
); }
186 bool IsFieldBased() const { return !!(image_type
& IT_FIELDBASED
); }
187 bool IsParityKnown() const { return ((image_type
& IT_FIELDBASED
)&&(image_type
& (IT_BFF
|IT_TFF
))); }
188 bool IsBFF() const { return !!(image_type
& IT_BFF
); }
189 bool IsTFF() const { return !!(image_type
& IT_TFF
); }
191 bool IsVPlaneFirst() const {return ((pixel_type
& CS_YV12
) == CS_YV12
); } // Don't use this
192 int BytesFromPixels(int pixels
) const { return pixels
* (BitsPerPixel()>>3); } // Will not work on planar images, but will return only luma planes
193 int RowSize() const { return BytesFromPixels(width
); } // Also only returns first plane on planar images
194 int BMPSize() const { if (IsPlanar()) {int p
= height
* ((RowSize()+3) & ~3); p
+=p
>>1; return p
; } return height
* ((RowSize()+3) & ~3); }
195 __int64
AudioSamplesFromFrames(__int64 frames
) const { return (fps_numerator
&& HasVideo()) ? ((__int64
)(frames
) * audio_samples_per_second
* fps_denominator
/ fps_numerator
) : 0; }
196 int FramesFromAudioSamples(__int64 samples
) const { return (fps_denominator
&& HasAudio()) ? (int)((samples
* (__int64
)fps_numerator
)/((__int64
)fps_denominator
* (__int64
)audio_samples_per_second
)) : 0; }
197 __int64
AudioSamplesFromBytes(__int64 bytes
) const { return HasAudio() ? bytes
/ BytesPerAudioSample() : 0; }
198 __int64
BytesFromAudioSamples(__int64 samples
) const { return samples
* BytesPerAudioSample(); }
199 int AudioChannels() const { return HasAudio() ? nchannels
: 0; }
200 int SampleType() const{ return sample_type
;}
201 bool IsSampleType(int testtype
) const{ return !!(sample_type
&testtype
);}
202 int SamplesPerSecond() const { return audio_samples_per_second
; }
203 int BytesPerAudioSample() const { return nchannels
*BytesPerChannelSample();}
204 void SetFieldBased(bool isfieldbased
) { if (isfieldbased
) image_type
|=IT_FIELDBASED
; else image_type
&=~IT_FIELDBASED
; }
205 void Set(int property
) { image_type
|=property
; }
206 void Clear(int property
) { image_type
&=~property
; }
208 int BitsPerPixel() const {
209 switch (pixel_type
) {
224 int BytesPerChannelSample() const {
225 switch (sample_type
) {
227 return sizeof(signed char);
229 return sizeof(signed short);
233 return sizeof(signed int);
235 return sizeof(SFLOAT
);
237 _ASSERTE("Sample type not recognized!");
243 void SetFPS(unsigned numerator
, unsigned denominator
) {
244 if ((numerator
== 0) || (denominator
== 0)) {
249 unsigned x
=numerator
, y
=denominator
;
250 while (y
) { // find gcd
251 unsigned t
= x
%y
; x
= y
; y
= t
;
253 fps_numerator
= numerator
/x
;
254 fps_denominator
= denominator
/x
;
258 // Range protected multiply-divide of FPS
259 void MulDivFPS(unsigned multiplier
, unsigned divisor
) {
260 unsigned __int64 numerator
= UInt32x32To64(fps_numerator
, multiplier
);
261 unsigned __int64 denominator
= UInt32x32To64(fps_denominator
, divisor
);
263 unsigned __int64 x
=numerator
, y
=denominator
;
264 while (y
) { // find gcd
265 unsigned __int64 t
= x
%y
; x
= y
; y
= t
;
267 numerator
/= x
; // normalize
270 unsigned __int64 temp
= numerator
| denominator
; // Just looking top bit
272 while (temp
& 0xffffffff80000000ull
) { // or perhaps > 16777216*2
273 temp
= Int64ShrlMod32(temp
, 1);
276 if (u
) { // Scale to fit
277 const unsigned round
= 1 << (u
-1);
278 SetFPS( (unsigned)Int64ShrlMod32(numerator
+ round
, u
),
279 (unsigned)Int64ShrlMod32(denominator
+ round
, u
) );
282 fps_numerator
= (unsigned)numerator
;
283 fps_denominator
= (unsigned)denominator
;
287 // Test for same colorspace
288 bool IsSameColorspace(const VideoInfo
& vi
) const {
289 if (vi
.pixel_type
== pixel_type
) return TRUE
;
290 if (IsYV12() && vi
.IsYV12()) return TRUE
;
299 // VideoFrameBuffer holds information about a memory block which is used
300 // for video data. For efficiency, instances of this class are not deleted
301 // when the refcount reaches zero; instead they're stored in a linked list
302 // to be reused. The instances are deleted when the corresponding AVS
305 class VideoFrameBuffer
{
308 // sequence_number is incremented every time the buffer is changed, so
309 // that stale views can tell they're no longer valid.
310 volatile long sequence_number
;
312 friend class VideoFrame
;
314 friend class CacheMT
;
315 friend class ScriptEnvironment
;
316 volatile long refcount
;
319 VideoFrameBuffer(int size
);
323 const BYTE
* GetReadPtr() const { return data
; }
324 BYTE
* GetWritePtr() { InterlockedIncrement(&sequence_number
); return data
; }
325 int GetDataSize() { return data_size
; }
326 int GetSequenceNumber() { return sequence_number
; }
327 int GetRefcount() { return refcount
; }
334 class IScriptEnvironment
;
338 // VideoFrame holds a "window" into a VideoFrameBuffer. Operator new
339 // is overloaded to recycle class instances.
342 volatile long refcount
;
343 VideoFrameBuffer
* const vfb
;
344 const int offset
, pitch
, row_size
, height
, offsetU
, offsetV
, pitchUV
; // U&V offsets are from top of picture.
346 friend class PVideoFrame
;
347 void AddRef() { InterlockedIncrement(&refcount
); }
348 void Release() { VideoFrameBuffer
* vfb_local
= vfb
; if (!InterlockedDecrement(&refcount
)) InterlockedDecrement(&vfb_local
->refcount
); }
351 friend class CacheMT
;
352 friend class ScriptEnvironment
;
354 VideoFrame(VideoFrameBuffer
* _vfb
, int _offset
, int _pitch
, int _row_size
, int _height
);
355 VideoFrame(VideoFrameBuffer
* _vfb
, int _offset
, int _pitch
, int _row_size
, int _height
, int _offsetU
, int _offsetV
, int _pitchUV
);
358 void* operator new(unsigned size
);
360 void* operator new(size_t size
);
362 // TESTME: OFFSET U/V may be switched to what could be expected from AVI standard!
364 int GetPitch() const { return pitch
; }
365 int GetPitch(int plane
) const { switch (plane
) {case PLANAR_U
: case PLANAR_V
: return pitchUV
;} return pitch
; }
366 int GetRowSize() const { return row_size
; }
367 __declspec(noinline
) int GetRowSize(int plane
) const {
369 case PLANAR_U
: case PLANAR_V
: if (pitchUV
) return row_size
>>1; else return 0;
370 case PLANAR_U_ALIGNED
: case PLANAR_V_ALIGNED
:
372 int r
= ((row_size
+FRAME_ALIGN
-1)&(~(FRAME_ALIGN
-1)) )>>1; // Aligned rowsize
377 case PLANAR_Y_ALIGNED
:
378 int r
= (row_size
+FRAME_ALIGN
-1)&(~(FRAME_ALIGN
-1)); // Aligned rowsize
384 int GetHeight() const { return height
; }
385 int GetHeight(int plane
) const { switch (plane
) {case PLANAR_U
: case PLANAR_V
: if (pitchUV
) return height
>>1; return 0;} return height
; }
387 // generally you shouldn't use these three
388 VideoFrameBuffer
* GetFrameBuffer() const { return vfb
; }
389 int GetOffset() const { return offset
; }
390 int GetOffset(int plane
) const { switch (plane
) {case PLANAR_U
: return offsetU
;case PLANAR_V
: return offsetV
;default: return offset
;}; }
392 // in plugins use env->SubFrame()
393 //If you really want to use these remember to increase vfb->refcount before calling and decrement it afterwards.
394 VideoFrame
* Subframe(int rel_offset
, int new_pitch
, int new_row_size
, int new_height
) const;
395 VideoFrame
* Subframe(int rel_offset
, int new_pitch
, int new_row_size
, int new_height
, int rel_offsetU
, int rel_offsetV
, int pitchUV
) const;
398 const BYTE
* GetReadPtr() const { return vfb
->GetReadPtr() + offset
; }
399 const BYTE
* GetReadPtr(int plane
) const { return vfb
->GetReadPtr() + GetOffset(plane
); }
401 bool IsWritable() const { return (refcount
== 1 && vfb
->refcount
== 1); }
403 BYTE
* GetWritePtr() const {
404 if (vfb
->GetRefcount()>1) {
406 //throw AvisynthError("Internal Error - refcount was more than one!");
408 return IsWritable() ? (vfb
->GetWritePtr() + offset
) : 0;
411 BYTE
* GetWritePtr(int plane
) const {
412 if (plane
==PLANAR_Y
) {
413 if (vfb
->GetRefcount()>1) {
415 // throw AvisynthError("Internal Error - refcount was more than one!");
417 return IsWritable() ? vfb
->GetWritePtr() + GetOffset(plane
) : 0;
419 return vfb
->data
+ GetOffset(plane
);
422 ~VideoFrame() { VideoFrameBuffer
* vfb_local
= vfb
; if (InterlockedDecrement(&refcount
) >= 0) InterlockedDecrement(&vfb_local
->refcount
); }
434 // Base class for all filters.
437 friend class AVSValue
;
438 volatile long refcnt
;
439 void AddRef() { InterlockedIncrement(&refcnt
); }
440 void Release() { if (!InterlockedDecrement(&refcnt
)) delete this; }
442 IClip() : refcnt(0) {}
444 virtual int __stdcall
GetVersion() { return AVISYNTH_INTERFACE_VERSION
; }
446 virtual PVideoFrame __stdcall
GetFrame(int n
, IScriptEnvironment
* env
) = 0;
447 virtual bool __stdcall
GetParity(int n
) = 0; // return field parity if field_based, else parity of first field in frame
448 virtual void __stdcall
GetAudio(void* buf
, __int64 start
, __int64 count
, IScriptEnvironment
* env
) = 0; // start and count are in samples
449 virtual void __stdcall
SetCacheHints(int cachehints
,int frame_range
) = 0 ; // We do not pass cache requests upwards, only to the next filter.
450 virtual const VideoInfo
& __stdcall
GetVideoInfo() = 0;
451 #if defined(__INTEL_COMPILER)
454 virtual __stdcall
~IClip() {}
459 // smart pointer to IClip
464 IClip
* GetPointerWithAddRef() const { if (p
) p
->AddRef(); return p
; }
465 friend class AVSValue
;
466 friend class VideoFrame
;
468 void Init(IClip
* x
) {
480 PClip(const PClip
& x
) { Init(x
.p
); }
481 PClip(IClip
* x
) { Init(x
); }
482 void operator=(IClip
* x
) { Set(x
); }
483 void operator=(const PClip
& x
) { Set(x
.p
); }
485 IClip
* operator->() const { return p
; }
487 // useful in conditional expressions
488 operator void*() const { return p
; }
489 bool operator!() const { return !p
; }
491 ~PClip() { if (p
) p
->Release(); }
495 // smart pointer to VideoFrame
500 void Init(VideoFrame
* x
) {
504 void Set(VideoFrame
* x
) {
511 PVideoFrame() { p
= 0; }
512 PVideoFrame(const PVideoFrame
& x
) { Init(x
.p
); }
513 PVideoFrame(VideoFrame
* x
) { Init(x
); }
514 void operator=(VideoFrame
* x
) { Set(x
); }
515 void operator=(const PVideoFrame
& x
) { Set(x
.p
); }
517 VideoFrame
* operator->() const { return p
; }
519 // for conditional expressions
520 operator void*() const { return p
; }
521 bool operator!() const { return !p
; }
523 ~PVideoFrame() { if (p
) p
->Release();}
530 AVSValue() { type
= 'v'; }
531 AVSValue(IClip
* c
) { type
= 'c'; clip
= c
; if (c
) c
->AddRef(); }
532 AVSValue(const PClip
& c
) { type
= 'c'; clip
= c
.GetPointerWithAddRef(); }
533 AVSValue(bool b
) { type
= 'b'; boolean
= b
; }
534 AVSValue(int i
) { type
= 'i'; integer
= i
; }
535 // AVSValue(__int64 l) { type = 'l'; longlong = l; }
536 AVSValue(float f
) { type
= 'f'; floating_pt
= f
; }
537 AVSValue(double f
) { type
= 'f'; floating_pt
= float(f
); }
538 AVSValue(const char* s
) { type
= 's'; string
= s
; }
539 AVSValue(const AVSValue
* a
, int size
) { type
= 'a'; array
= a
; array_size
= size
; }
540 AVSValue(const AVSValue
& v
) { Assign(&v
, true); }
542 ~AVSValue() { if (IsClip() && clip
) clip
->Release(); }
543 AVSValue
& operator=(const AVSValue
& v
) { Assign(&v
, false); return *this; }
545 // Note that we transparently allow 'int' to be treated as 'float'.
546 // There are no int<->bool conversions, though.
548 bool Defined() const { return type
!= 'v'; }
549 bool IsClip() const { return type
== 'c'; }
550 bool IsBool() const { return type
== 'b'; }
551 bool IsInt() const { return type
== 'i'; }
552 // bool IsLong() const { return (type == 'l'|| type == 'i'); }
553 bool IsFloat() const { return type
== 'f' || type
== 'i'; }
554 bool IsString() const { return type
== 's'; }
555 bool IsArray() const { return type
== 'a'; }
557 PClip
AsClip() const { _ASSERTE(IsClip()); return IsClip()?clip
:0; }
558 bool AsBool() const { _ASSERTE(IsBool()); return boolean
; }
559 int AsInt() const { _ASSERTE(IsInt()); return integer
; }
560 // int AsLong() const { _ASSERTE(IsLong()); return longlong; }
561 const char* AsString() const { _ASSERTE(IsString()); return IsString()?string
:0; }
562 double AsFloat() const { _ASSERTE(IsFloat()); return IsInt()?integer
:floating_pt
; }
564 bool AsBool(bool def
) const { _ASSERTE(IsBool()||!Defined()); return IsBool() ? boolean
: def
; }
565 int AsInt(int def
) const { _ASSERTE(IsInt()||!Defined()); return IsInt() ? integer
: def
; }
566 double AsFloat(double def
) const { _ASSERTE(IsFloat()||!Defined()); return IsInt() ? integer
: type
=='f' ? floating_pt
: def
; }
567 const char* AsString(const char* def
) const { _ASSERTE(IsString()||!Defined()); return IsString() ? string
: def
; }
569 int ArraySize() const { _ASSERTE(IsArray()); return IsArray()?array_size
:1; }
571 const AVSValue
& operator[](int index
) const {
572 _ASSERTE(IsArray() && index
>=0 && index
<array_size
);
573 return (IsArray() && index
>=0 && index
<array_size
) ? array
[index
] : *this;
578 short type
; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
586 const AVSValue
* array
;
590 void Assign(const AVSValue
* src
, bool init
) {
591 if (src
->IsClip() && src
->clip
)
593 if (!init
&& IsClip() && clip
)
595 // make sure this copies the whole struct!
597 ((__int32*)this)[0] = ((__int32*)src)[0];
598 ((__int32*)this)[1] = ((__int32*)src)[1];
600 this->clip
= src
->clip
;
601 this->type
= src
->type
;
602 this->array_size
= src
->array_size
;
607 // instantiable null filter
608 class GenericVideoFilter
: public IClip
{
613 GenericVideoFilter(PClip _child
) : child(_child
) { vi
= child
->GetVideoInfo(); }
614 PVideoFrame __stdcall
GetFrame(int n
, IScriptEnvironment
* env
) { return child
->GetFrame(n
, env
); }
615 void __stdcall
GetAudio(void* buf
, __int64 start
, __int64 count
, IScriptEnvironment
* env
) { child
->GetAudio(buf
, start
, count
, env
); }
616 const VideoInfo
& __stdcall
GetVideoInfo() { return vi
; }
617 bool __stdcall
GetParity(int n
) { return child
->GetParity(n
); }
618 void __stdcall
SetCacheHints(int cachehints
,int frame_range
) { } ; // We do not pass cache requests upwards, only to the next filter.
625 /* Helper classes useful to plugin authors */
627 class AlignPlanar
: public GenericVideoFilter
630 AlignPlanar(PClip _clip
);
631 static PClip
Create(PClip clip
);
632 PVideoFrame __stdcall
GetFrame(int n
, IScriptEnvironment
* env
);
637 class FillBorder
: public GenericVideoFilter
640 FillBorder(PClip _clip
);
641 static PClip
Create(PClip clip
);
642 PVideoFrame __stdcall
GetFrame(int n
, IScriptEnvironment
* env
);
647 class ConvertAudio
: public GenericVideoFilter
649 * Helper class to convert audio to any format
653 ConvertAudio(PClip _clip
, int prefered_format
);
654 void __stdcall
GetAudio(void* buf
, __int64 start
, __int64 count
, IScriptEnvironment
* env
);
655 void __stdcall
SetCacheHints(int cachehints
,int frame_range
); // We do pass cache requests upwards, to the cache!
657 static PClip
Create(PClip clip
, int sample_type
, int prefered_type
);
658 static AVSValue __cdecl
Create_float(AVSValue args
, void*, IScriptEnvironment
*);
659 static AVSValue __cdecl
Create_32bit(AVSValue args
, void*, IScriptEnvironment
*);
660 static AVSValue __cdecl
Create_24bit(AVSValue args
, void*, IScriptEnvironment
*);
661 static AVSValue __cdecl
Create_16bit(AVSValue args
, void*, IScriptEnvironment
*);
662 static AVSValue __cdecl
Create_8bit (AVSValue args
, void*, IScriptEnvironment
*);
663 static AVSValue __cdecl
Create_Any (AVSValue args
, void*, IScriptEnvironment
*);
664 virtual ~ConvertAudio();
667 void convertToFloat(char* inbuf
, float* outbuf
, char sample_type
, int count
);
668 void convertToFloat_3DN(char* inbuf
, float* outbuf
, char sample_type
, int count
);
669 void convertToFloat_SSE(char* inbuf
, float* outbuf
, char sample_type
, int count
);
670 void convertToFloat_SSE2(char* inbuf
, float* outbuf
, char sample_type
, int count
);
671 void convertFromFloat(float* inbuf
, void* outbuf
, char sample_type
, int count
);
672 void convertFromFloat_3DN(float* inbuf
, void* outbuf
, char sample_type
, int count
);
673 void convertFromFloat_SSE(float* inbuf
, void* outbuf
, char sample_type
, int count
);
674 void convertFromFloat_SSE2(float* inbuf
, void* outbuf
, char sample_type
, int count
);
676 __inline
int Saturate_int8(float n
);
677 __inline
short Saturate_int16(float n
);
678 __inline
int Saturate_int24(float n
);
679 __inline
int Saturate_int32(float n
);
690 // For GetCPUFlags. These are backwards-compatible with those in VirtualDub.
692 /* slowest CPU to support extension */
693 CPUF_FORCE
= 0x01, // N/A
694 CPUF_FPU
= 0x02, // 386/486DX
695 CPUF_MMX
= 0x04, // P55C, K6, PII
696 CPUF_INTEGER_SSE
= 0x08, // PIII, Athlon
697 CPUF_SSE
= 0x10, // PIII, Athlon XP/MP
698 CPUF_SSE2
= 0x20, // PIV, Hammer
699 CPUF_3DNOW
= 0x40, // K6-2
700 CPUF_3DNOW_EXT
= 0x80, // Athlon
701 CPUF_X86_64
= 0xA0, // Hammer (note: equiv. to 3DNow + SSE2, which
702 // only Hammer will have anyway)
703 CPUF_SSE3
= 0x100, // PIV+, Hammer
704 CPUF_SSSE3
= 0x200, // prescott?
705 CPUF_SSE4
= 0x400, // penryn
706 CPUF_SSE4_2
= 0x800 // Core iX
709 //josh: changed these just bc winsdk defines them in BaseTsd.h
710 #define MAX_INT MAXINT32
711 #define MIN_INT MININT32 // ::FIXME:: research why this is not 0x80000000
715 class IClipLocalStorage
;
717 class IScriptEnvironment
{
719 #if defined(__INTEL_COMPILER)
720 virtual ~IScriptEnvironment() {}
722 virtual __stdcall
~IScriptEnvironment() {}
725 virtual /*static*/ long __stdcall
GetCPUFlags() = 0;
727 virtual char* __stdcall
SaveString(const char* s
, int length
= -1) = 0;
728 virtual char* __stdcall
Sprintf(const char* fmt
, ...) = 0;
729 // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
730 virtual char* __stdcall
VSprintf(const char* fmt
, void* val
) = 0;
732 __declspec(noreturn
) virtual void __stdcall
ThrowError(const char* fmt
, ...) = 0;
734 class NotFound
/*exception*/ {}; // thrown by Invoke and GetVar
736 typedef AVSValue (__cdecl
*ApplyFunc
)(AVSValue args
, void* user_data
, IScriptEnvironment
* env
);
738 virtual void __stdcall
AddFunction(const char* name
, const char* params
, ApplyFunc apply
, void* user_data
) = 0;
739 virtual bool __stdcall
FunctionExists(const char* name
) = 0;
740 virtual AVSValue __stdcall
Invoke(const char* name
, const AVSValue args
, const char** arg_names
=0) = 0;
742 virtual AVSValue __stdcall
GetVar(const char* name
) = 0;
743 virtual bool __stdcall
SetVar(const char* name
, const AVSValue
& val
) = 0;
744 virtual bool __stdcall
SetGlobalVar(const char* name
, const AVSValue
& val
) = 0;
746 virtual void __stdcall
PushContext(int level
=0) = 0;
747 virtual void __stdcall
PopContext() = 0;
749 // align should be 4 or 8
750 virtual PVideoFrame __stdcall
NewVideoFrame(const VideoInfo
& vi
, int align
=FRAME_ALIGN
) = 0;
752 virtual bool __stdcall
MakeWritable(PVideoFrame
* pvf
) = 0;
754 virtual /*static*/ void __stdcall
BitBlt(BYTE
* dstp
, int dst_pitch
, const BYTE
* srcp
, int src_pitch
, int row_size
, int height
) = 0;
756 typedef void (__cdecl
*ShutdownFunc
)(void* user_data
, IScriptEnvironment
* env
);
757 virtual void __stdcall
AtExit(ShutdownFunc function
, void* user_data
) = 0;
759 virtual void __stdcall
CheckVersion(int version
= AVISYNTH_INTERFACE_VERSION
) = 0;
761 virtual PVideoFrame __stdcall
Subframe(PVideoFrame src
, int rel_offset
, int new_pitch
, int new_row_size
, int new_height
) = 0;
763 virtual int __stdcall
SetMemoryMax(int mem
) = 0;
765 virtual int __stdcall
SetWorkingDir(const char * newdir
) = 0;
767 virtual void* __stdcall
ManageCache(int key
, void* data
) = 0;
769 enum PlanarChromaAlignmentMode
{
770 PlanarChromaAlignmentOff
,
771 PlanarChromaAlignmentOn
,
772 PlanarChromaAlignmentTest
};
774 virtual bool __stdcall
PlanarChromaAlignment(PlanarChromaAlignmentMode key
) = 0;
776 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;
778 virtual void __stdcall
SetMTMode(int mode
,int threads
,bool temporary
)=0;
779 virtual int __stdcall
GetMTMode(bool return_nthreads
)=0;
781 virtual IClipLocalStorage
* __stdcall
AllocClipLocalStorage()=0;
783 virtual void __stdcall
SaveClipLocalStorage()=0;
784 virtual void __stdcall
RestoreClipLocalStorage()=0;
788 // avisynth.dll exports this; it's a way to use it as a library, without
789 // writing an AVS script or without going through AVIFile.
790 IScriptEnvironment
* __stdcall
CreateScriptEnvironment(int version
= AVISYNTH_INTERFACE_VERSION
);
795 #endif //__AVISYNTH_H__