home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Multimedia / AVStoDVD / AVStoDVD_280_Install.exe / AVSMeter / source / avisynth26.h < prev    next >
C/C++ Source or Header  |  2014-03-15  |  47KB  |  1,132 lines

  1. // Avisynth v2.5.  Copyright 2002, 2005 Ben Rudiak-Gould et al.
  2. // Avisynth v2.6.  Copyright 2006 Klaus Post.
  3. // Avisynth v2.6.  Copyright 2009 Ian Brabham.
  4. // http://www.avisynth.org
  5.  
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
  19. // http://www.gnu.org/copyleft/gpl.html .
  20. //
  21. // Linking Avisynth statically or dynamically with other modules is making a
  22. // combined work based on Avisynth.  Thus, the terms and conditions of the GNU
  23. // General Public License cover the whole combination.
  24.  
  25.  
  26. /*
  27. Please NOTE! This version of avisynth.h DOES NOT have any special exemption!
  28.  
  29.          While this version is under development you are fully
  30.        constrained by the terms of the GNU General Public License.
  31.  
  32.  Any derivative software you may publish MUST include the full source code.
  33.  
  34.     Normal licence conditions will be reapplied in a future version.
  35. */
  36.  
  37.  
  38.  
  39.  
  40. #ifndef __AVISYNTH_H__
  41. #define __AVISYNTH_H__
  42.  
  43. #include "avs/config.h"
  44. #include "avs/capi.h"
  45. #include "avs/types.h"
  46.  
  47.  
  48. enum { AVISYNTH_INTERFACE_VERSION = 5 };
  49.  
  50.  
  51. /* Compiler-specific crap */
  52.  
  53. // Tell MSVC to stop precompiling here
  54. #ifdef _MSC_VER
  55.   #pragma hdrstop
  56. #endif
  57.  
  58. // Set up debugging macros for MS compilers; for others, step down to the
  59. // standard <assert.h> interface
  60. #ifdef _MSC_VER
  61.   #include <crtdbg.h>
  62. #else
  63.   #define _RPT0(a,b) ((void)0)
  64.   #define _RPT1(a,b,c) ((void)0)
  65.   #define _RPT2(a,b,c,d) ((void)0)
  66.   #define _RPT3(a,b,c,d,e) ((void)0)
  67.   #define _RPT4(a,b,c,d,e,f) ((void)0)
  68.  
  69.   #define _ASSERTE(x) assert(x)
  70.   #include <assert.h>
  71. #endif
  72.  
  73.  
  74.  
  75. // I had problems with Premiere wanting 1-byte alignment for its structures,
  76. // so I now set the Avisynth struct alignment explicitly here.
  77. #pragma pack(push,8)
  78.  
  79. // The VideoInfo struct holds global information about a clip (i.e.
  80. // information that does not depend on the frame number).  The GetVideoInfo
  81. // method in IClip returns this struct.
  82.  
  83. enum {SAMPLE_INT8  = 1<<0,
  84.       SAMPLE_INT16 = 1<<1,
  85.       SAMPLE_INT24 = 1<<2,    // Int24 is a very stupid thing to code, but it's supported by some hardware.
  86.       SAMPLE_INT32 = 1<<3,
  87.       SAMPLE_FLOAT = 1<<4};
  88.  
  89. enum {
  90.    PLANAR_Y=1<<0,
  91.    PLANAR_U=1<<1,
  92.    PLANAR_V=1<<2,
  93.    PLANAR_ALIGNED=1<<3,
  94.    PLANAR_Y_ALIGNED=PLANAR_Y|PLANAR_ALIGNED,
  95.    PLANAR_U_ALIGNED=PLANAR_U|PLANAR_ALIGNED,
  96.    PLANAR_V_ALIGNED=PLANAR_V|PLANAR_ALIGNED,
  97.    PLANAR_A=1<<4,
  98.    PLANAR_R=1<<5,
  99.    PLANAR_G=1<<6,
  100.    PLANAR_B=1<<7,
  101.    PLANAR_A_ALIGNED=PLANAR_A|PLANAR_ALIGNED,
  102.    PLANAR_R_ALIGNED=PLANAR_R|PLANAR_ALIGNED,
  103.    PLANAR_G_ALIGNED=PLANAR_G|PLANAR_ALIGNED,
  104.    PLANAR_B_ALIGNED=PLANAR_B|PLANAR_ALIGNED,
  105.   };
  106.  
  107. class AvisynthError /* exception */ {
  108. public:
  109.   const char* const msg;
  110.   AvisynthError(const char* _msg) : msg(_msg) {}
  111. }; // end class AvisynthError
  112.  
  113.  
  114. /* Forward references */
  115. struct __single_inheritance VideoInfo;
  116. class __single_inheritance VideoFrameBuffer;
  117. class __single_inheritance VideoFrame;
  118. class IClip;
  119. class __single_inheritance PClip;
  120. class __single_inheritance PVideoFrame;
  121. class IScriptEnvironment;
  122. class __single_inheritance AVSValue;
  123.  
  124.  
  125. /*
  126.  * Avisynth C++ plugin API code function pointers.
  127.  *
  128.  * In order to maintain binary compatibility with
  129.  * future version do not change the order of the
  130.  * existing function pointers. It will be baked
  131.  * into all existing plugins.
  132.  *
  133.  * Add new function pointers to the end of the
  134.  * structure. The linkage macros generate some
  135.  * protection code to ensure newer plugin do not
  136.  * call non-existing functions in an older host.
  137.  */
  138.  
  139. struct AVS_Linkage {
  140.  
  141.   int Size;
  142.  
  143. /**********************************************************************/
  144.  
  145. // struct VideoInfo
  146.   bool    (VideoInfo::*HasVideo)() const;
  147.   bool    (VideoInfo::*HasAudio)() const;
  148.   bool    (VideoInfo::*IsRGB)() const;
  149.   bool    (VideoInfo::*IsRGB24)() const;
  150.   bool    (VideoInfo::*IsRGB32)() const;
  151.   bool    (VideoInfo::*IsYUV)() const;
  152.   bool    (VideoInfo::*IsYUY2)() const;
  153.   bool    (VideoInfo::*IsYV24)() const;
  154.   bool    (VideoInfo::*IsYV16)() const;
  155.   bool    (VideoInfo::*IsYV12)() const;
  156.   bool    (VideoInfo::*IsYV411)() const;
  157.   bool    (VideoInfo::*IsY8)() const;
  158.   bool    (VideoInfo::*IsColorSpace)(int c_space) const;
  159.   bool    (VideoInfo::*Is)(int property) const;
  160.   bool    (VideoInfo::*IsPlanar)() const;
  161.   bool    (VideoInfo::*IsFieldBased)() const;
  162.   bool    (VideoInfo::*IsParityKnown)() const;
  163.   bool    (VideoInfo::*IsBFF)() const;
  164.   bool    (VideoInfo::*IsTFF)() const;
  165.   bool    (VideoInfo::*IsVPlaneFirst)() const;
  166.   int     (VideoInfo::*BytesFromPixels)(int pixels) const;
  167.   int     (VideoInfo::*RowSize)(int plane) const;
  168.   int     (VideoInfo::*BMPSize)() const;
  169.   __int64 (VideoInfo::*AudioSamplesFromFrames)(int frames) const;
  170.   int     (VideoInfo::*FramesFromAudioSamples)(__int64 samples) const;
  171.   __int64 (VideoInfo::*AudioSamplesFromBytes)(__int64 bytes) const;
  172.   __int64 (VideoInfo::*BytesFromAudioSamples)(__int64 samples) const;
  173.   int     (VideoInfo::*AudioChannels)() const;
  174.   int     (VideoInfo::*SampleType)() const;
  175.   bool    (VideoInfo::*IsSampleType)(int testtype) const;
  176.   int     (VideoInfo::*SamplesPerSecond)() const;
  177.   int     (VideoInfo::*BytesPerAudioSample)() const;
  178.   void    (VideoInfo::*SetFieldBased)(bool isfieldbased);
  179.   void    (VideoInfo::*Set)(int property);
  180.   void    (VideoInfo::*Clear)(int property);
  181.   int     (VideoInfo::*GetPlaneWidthSubsampling)(int plane) const;
  182.   int     (VideoInfo::*GetPlaneHeightSubsampling)(int plane) const;
  183.   int     (VideoInfo::*BitsPerPixel)() const;
  184.   int     (VideoInfo::*BytesPerChannelSample)() const;
  185.   void    (VideoInfo::*SetFPS)(unsigned numerator, unsigned denominator);
  186.   void    (VideoInfo::*MulDivFPS)(unsigned multiplier, unsigned divisor);
  187.   bool    (VideoInfo::*IsSameColorspace)(const VideoInfo& vi) const;
  188. // end struct VideoInfo
  189.  
  190. /**********************************************************************/
  191.  
  192. // class VideoFrameBuffer
  193.   const BYTE* (VideoFrameBuffer::*VFBGetReadPtr)() const;
  194.   BYTE*       (VideoFrameBuffer::*VFBGetWritePtr)();
  195.   int         (VideoFrameBuffer::*GetDataSize)() const;
  196.   int         (VideoFrameBuffer::*GetSequenceNumber)() const;
  197.   int         (VideoFrameBuffer::*GetRefcount)() const;
  198. // end class VideoFrameBuffer
  199.  
  200. /**********************************************************************/
  201.  
  202. // class VideoFrame
  203.   int               (VideoFrame::*GetPitch)(int plane) const;
  204.   int               (VideoFrame::*GetRowSize)(int plane) const;
  205.   int               (VideoFrame::*GetHeight)(int plane) const;
  206.   VideoFrameBuffer* (VideoFrame::*GetFrameBuffer)() const;
  207.   int               (VideoFrame::*GetOffset)(int plane) const;
  208.   const BYTE*       (VideoFrame::*VFGetReadPtr)(int plane) const;
  209.   bool              (VideoFrame::*IsWritable)() const;
  210.   BYTE*             (VideoFrame::*VFGetWritePtr)(int plane) const;
  211.   void              (VideoFrame::*VideoFrame_DESTRUCTOR)();
  212. // end class VideoFrame
  213.  
  214. /**********************************************************************/
  215.  
  216. // class IClip
  217.   /* nothing */
  218. // end class IClip
  219.  
  220. /**********************************************************************/
  221.  
  222. // class PClip
  223.   void (PClip::*PClip_CONSTRUCTOR0)();
  224.   void (PClip::*PClip_CONSTRUCTOR1)(const PClip& x);
  225.   void (PClip::*PClip_CONSTRUCTOR2)(IClip* x);
  226.   void (PClip::*PClip_OPERATOR_ASSIGN0)(IClip* x);
  227.   void (PClip::*PClip_OPERATOR_ASSIGN1)(const PClip& x);
  228.   void (PClip::*PClip_DESTRUCTOR)();
  229. // end class PClip
  230.  
  231. /**********************************************************************/
  232.  
  233. // class PVideoFrame
  234.   void (PVideoFrame::*PVideoFrame_CONSTRUCTOR0)();
  235.   void (PVideoFrame::*PVideoFrame_CONSTRUCTOR1)(const PVideoFrame& x);
  236.   void (PVideoFrame::*PVideoFrame_CONSTRUCTOR2)(VideoFrame* x);
  237.   void (PVideoFrame::*PVideoFrame_OPERATOR_ASSIGN0)(VideoFrame* x);
  238.   void (PVideoFrame::*PVideoFrame_OPERATOR_ASSIGN1)(const PVideoFrame& x);
  239.   void (PVideoFrame::*PVideoFrame_DESTRUCTOR)();
  240. // end class PVideoFrame
  241.  
  242. /**********************************************************************/
  243.  
  244. // class AVSValue
  245.   void            (AVSValue::*AVSValue_CONSTRUCTOR0)();
  246.   void            (AVSValue::*AVSValue_CONSTRUCTOR1)(IClip* c);
  247.   void            (AVSValue::*AVSValue_CONSTRUCTOR2)(const PClip& c);
  248.   void            (AVSValue::*AVSValue_CONSTRUCTOR3)(bool b);
  249.   void            (AVSValue::*AVSValue_CONSTRUCTOR4)(int i);
  250.   void            (AVSValue::*AVSValue_CONSTRUCTOR5)(float f);
  251.   void            (AVSValue::*AVSValue_CONSTRUCTOR6)(double f);
  252.   void            (AVSValue::*AVSValue_CONSTRUCTOR7)(const char* s);
  253.   void            (AVSValue::*AVSValue_CONSTRUCTOR8)(const AVSValue* a, int size);
  254.   void            (AVSValue::*AVSValue_CONSTRUCTOR9)(const AVSValue& v);
  255.   void            (AVSValue::*AVSValue_DESTRUCTOR)();
  256.   AVSValue&       (AVSValue::*AVSValue_OPERATOR_ASSIGN)(const AVSValue& v);
  257.   const AVSValue& (AVSValue::*AVSValue_OPERATOR_INDEX)(int index) const;
  258.   bool            (AVSValue::*Defined)() const;
  259.   bool            (AVSValue::*IsClip)() const;
  260.   bool            (AVSValue::*IsBool)() const;
  261.   bool            (AVSValue::*IsInt)() const;
  262.   bool            (AVSValue::*IsFloat)() const;
  263.   bool            (AVSValue::*IsString)() const;
  264.   bool            (AVSValue::*IsArray)() const;
  265.   PClip           (AVSValue::*AsClip)() const;
  266.   bool            (AVSValue::*AsBool1)() const;
  267.   int             (AVSValue::*AsInt1)() const;
  268.   const char*     (AVSValue::*AsString1)() const;
  269.   double          (AVSValue::*AsFloat1)() const;
  270.   bool            (AVSValue::*AsBool2)(bool def) const;
  271.   int             (AVSValue::*AsInt2)(int def) const;
  272.   double          (AVSValue::*AsDblDef)(double def) const;
  273.   double          (AVSValue::*AsFloat2)(float def) const;
  274.   const char*     (AVSValue::*AsString2)(const char* def) const;
  275.   int             (AVSValue::*ArraySize)() const;
  276. // end class AVSValue
  277.  
  278. /**********************************************************************/
  279. };
  280.  
  281. #ifdef BUILDING_AVSCORE
  282. /* Macro resolution for code inside Avisynth.dll */
  283. # define AVS_BakedCode(arg) ;
  284. # define AVS_LinkCall(arg)
  285. # define AVS_LinkCallV(arg)
  286.  
  287. #else
  288. /* Macro resolution for code inside user plugin */
  289. # ifdef AVS_LINKAGE_DLLIMPORT
  290. extern __declspec(dllimport) const AVS_Linkage* const AVS_linkage;
  291. # else
  292. extern const AVS_Linkage* AVS_linkage;
  293. # endif
  294.  
  295. # ifndef offsetof
  296. #  include <stddef.h>
  297. # endif
  298.  
  299. # define AVS_BakedCode(arg) { arg ; }
  300. # define AVS_LinkCall(arg)  !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ?     0 : (this->*(AVS_linkage->arg))
  301. # define AVS_LinkCallV(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? *this : (this->*(AVS_linkage->arg))
  302.  
  303. #endif
  304.  
  305. struct VideoInfo {
  306.   int width, height;    // width=0 means no video
  307.   unsigned fps_numerator, fps_denominator;
  308.   int num_frames;
  309.   // This is more extensible than previous versions. More properties can be added seeminglesly.
  310.  
  311.   // Colorspace properties.
  312. /*
  313. 7<<0  Planar Width Subsampling bits
  314.       Use (X+1) & 3 for GetPlaneWidthSubsampling
  315.         000 => 1        YV12, YV16
  316.         001 => 2        YV411, YUV9
  317.         010 => reserved
  318.         011 => 0        YV24
  319.         1xx => reserved
  320.  
  321. 1<<3  VPlaneFirst YV12, YV16, YV24, YV411, YUV9
  322. 1<<4  UPlaneFirst I420
  323.  
  324. 7<<8  Planar Height Subsampling bits
  325.       Use ((X>>8)+1) & 3 for GetPlaneHeightSubsampling
  326.         000 => 1        YV12
  327.         001 => 2        YUV9
  328.         010 => reserved
  329.         011 => 0        YV16, YV24, YV411
  330.         1xx => reserved
  331.  
  332. 7<<16 Sample resolution bits
  333.         000 => 8
  334.         001 => 16
  335.         010 => 32
  336.         011 => reserved
  337.         1xx => reserved
  338.  
  339. Planar match mask  1111.0000.0000.0111.0000.0111.0000.0111
  340. Planar signature   10xx.0000.0000.00xx.0000.00xx.00xx.00xx
  341. Planar filter mask 1111.1111.1111.1111.1111.1111.1100.1111
  342. */
  343.   enum {
  344.     CS_BGR = 1<<28,
  345.     CS_YUV = 1<<29,
  346.     CS_INTERLEAVED = 1<<30,
  347.     CS_PLANAR = 1<<31,
  348.  
  349.     CS_Shift_Sub_Width   =  0,
  350.     CS_Shift_Sub_Height  =  8,
  351.     CS_Shift_Sample_Bits = 16,
  352.  
  353.     CS_Sub_Width_Mask    = 7 << CS_Shift_Sub_Width,
  354.     CS_Sub_Width_1       = 3 << CS_Shift_Sub_Width, // YV24
  355.     CS_Sub_Width_2       = 0 << CS_Shift_Sub_Width, // YV12, I420, YV16
  356.     CS_Sub_Width_4       = 1 << CS_Shift_Sub_Width, // YUV9, YV411
  357.  
  358.     CS_VPlaneFirst       = 1 << 3, // YV12, YV16, YV24, YV411, YUV9
  359.     CS_UPlaneFirst       = 1 << 4, // I420
  360.  
  361.     CS_Sub_Height_Mask   = 7 << CS_Shift_Sub_Height,
  362.     CS_Sub_Height_1      = 3 << CS_Shift_Sub_Height, // YV16, YV24, YV411
  363.     CS_Sub_Height_2      = 0 << CS_Shift_Sub_Height, // YV12, I420
  364.     CS_Sub_Height_4      = 1 << CS_Shift_Sub_Height, // YUV9
  365.  
  366.     CS_Sample_Bits_Mask  = 7 << CS_Shift_Sample_Bits,
  367.     CS_Sample_Bits_8     = 0 << CS_Shift_Sample_Bits,
  368.     CS_Sample_Bits_16    = 1 << CS_Shift_Sample_Bits,
  369.     CS_Sample_Bits_32    = 2 << CS_Shift_Sample_Bits,
  370.  
  371.     CS_PLANAR_MASK       = CS_PLANAR | CS_INTERLEAVED | CS_YUV | CS_BGR | CS_Sample_Bits_Mask | CS_Sub_Height_Mask | CS_Sub_Width_Mask,
  372.     CS_PLANAR_FILTER     = ~( CS_VPlaneFirst | CS_UPlaneFirst ),
  373.  
  374.   // Specific colorformats
  375.     CS_UNKNOWN = 0,
  376.     CS_BGR24 = 1<<0 | CS_BGR | CS_INTERLEAVED,
  377.     CS_BGR32 = 1<<1 | CS_BGR | CS_INTERLEAVED,
  378.     CS_YUY2  = 1<<2 | CS_YUV | CS_INTERLEAVED,
  379. //  CS_YV12  = 1<<3  Reserved
  380. //  CS_I420  = 1<<4  Reserved
  381.     CS_RAW32 = 1<<5 | CS_INTERLEAVED,
  382.  
  383. //  YV12 must be 0xA000008 2.5 Baked API will see all new planar as YV12
  384. //  I420 must be 0xA000010
  385.  
  386.     CS_YV24  = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_1,  // YUV 4:4:4 planar
  387.     CS_YV16  = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_2,  // YUV 4:2:2 planar
  388.     CS_YV12  = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2,  // y-v-u, 4:2:0 planar
  389.     CS_I420  = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_UPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2,  // y-u-v, 4:2:0 planar
  390.     CS_IYUV  = CS_I420,
  391.     CS_YUV9  = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_4 | CS_Sub_Width_4,  // YUV 4:1:0 planar
  392.     CS_YV411 = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_4,  // YUV 4:1:1 planar
  393.  
  394.     CS_Y8    = CS_PLANAR | CS_INTERLEAVED | CS_YUV | CS_Sample_Bits_8,                                     // Y   4:0:0 planar
  395. /*
  396.     CS_YV48  = CS_PLANAR | CS_YUV | CS_Sample_Bits_16 | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_1, // YUV 4:4:4 16bit samples
  397.     CS_Y16   = CS_PLANAR | CS_INTERLEAVED | CS_YUV | CS_Sample_Bits_16,                                    // Y   4:0:0 16bit samples
  398.  
  399.     CS_YV96  = CS_PLANAR | CS_YUV | CS_Sample_Bits_32 | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_1, // YUV 4:4:4 32bit samples
  400.     CS_Y32   = CS_PLANAR | CS_INTERLEAVED | CS_YUV | CS_Sample_Bits_32,                                    // Y   4:0:0 32bit samples
  401.  
  402.     CS_PRGB  = CS_PLANAR | CS_RGB | CS_Sample_Bits_8,                                                      // Planar RGB
  403.     CS_RGB48 = CS_PLANAR | CS_RGB | CS_Sample_Bits_16,                                                     // Planar RGB 16bit samples
  404.     CS_RGB96 = CS_PLANAR | CS_RGB | CS_Sample_Bits_32,                                                     // Planar RGB 32bit samples
  405. */
  406.   };
  407.  
  408.   int pixel_type;                // changed to int as of 2.5
  409.  
  410.  
  411.   int audio_samples_per_second;   // 0 means no audio
  412.   int sample_type;                // as of 2.5
  413.   __int64 num_audio_samples;      // changed as of 2.5
  414.   int nchannels;                  // as of 2.5
  415.  
  416.   // Imagetype properties
  417.  
  418.   int image_type;
  419.  
  420.   enum {
  421.     IT_BFF = 1<<0,
  422.     IT_TFF = 1<<1,
  423.     IT_FIELDBASED = 1<<2
  424.   };
  425.  
  426.   // Chroma placement bits 20 -> 23  ::FIXME:: Really want a Class to support this
  427.   enum {
  428.     CS_UNKNOWN_CHROMA_PLACEMENT = 0 << 20,
  429.     CS_MPEG1_CHROMA_PLACEMENT   = 1 << 20,
  430.     CS_MPEG2_CHROMA_PLACEMENT   = 2 << 20,
  431.     CS_YUY2_CHROMA_PLACEMENT    = 3 << 20,
  432.     CS_TOPLEFT_CHROMA_PLACEMENT = 4 << 20
  433.   };
  434.  
  435.   // useful functions of the above
  436.   bool HasVideo() const AVS_BakedCode( return AVS_LinkCall(HasVideo)() )
  437.   bool HasAudio() const AVS_BakedCode( return AVS_LinkCall(HasAudio)() )
  438.   bool IsRGB() const AVS_BakedCode( return AVS_LinkCall(IsRGB)() )
  439.   bool IsRGB24() const AVS_BakedCode( return AVS_LinkCall(IsRGB24)() )
  440.   bool IsRGB32() const AVS_BakedCode( return AVS_LinkCall(IsRGB32)() )
  441.   bool IsYUV() const AVS_BakedCode( return AVS_LinkCall(IsYUV)() )
  442.   bool IsYUY2() const AVS_BakedCode( return AVS_LinkCall(IsYUY2)() )
  443.  
  444.   bool IsYV24()  const AVS_BakedCode( return AVS_LinkCall(IsYV24)() )
  445.   bool IsYV16()  const AVS_BakedCode( return AVS_LinkCall(IsYV16)() )
  446.   bool IsYV12()  const AVS_BakedCode( return AVS_LinkCall(IsYV12)() )
  447.   bool IsYV411() const AVS_BakedCode( return AVS_LinkCall(IsYV411)() )
  448. //bool IsYUV9()  const;
  449.   bool IsY8()    const AVS_BakedCode( return AVS_LinkCall(IsY8)() )
  450.  
  451.   bool IsColorSpace(int c_space) const AVS_BakedCode( return AVS_LinkCall(IsColorSpace)(c_space) )
  452.  
  453.   bool Is(int property) const AVS_BakedCode( return AVS_LinkCall(Is)(property) )
  454.   bool IsPlanar() const AVS_BakedCode( return AVS_LinkCall(IsPlanar)() )
  455.   bool IsFieldBased() const AVS_BakedCode( return AVS_LinkCall(IsFieldBased)() )
  456.   bool IsParityKnown() const AVS_BakedCode( return AVS_LinkCall(IsParityKnown)() )
  457.   bool IsBFF() const AVS_BakedCode( return AVS_LinkCall(IsBFF)() )
  458.   bool IsTFF() const AVS_BakedCode( return AVS_LinkCall(IsTFF)() )
  459.  
  460.   bool IsVPlaneFirst() const AVS_BakedCode( return AVS_LinkCall(IsVPlaneFirst)() )  // Don't use this
  461.   int BytesFromPixels(int pixels) const AVS_BakedCode( return AVS_LinkCall(BytesFromPixels)(pixels) )   // Will not work on planar images, but will return only luma planes
  462.   int RowSize(int plane=0) const AVS_BakedCode( return AVS_LinkCall(RowSize)(plane) )
  463.   int BMPSize() const AVS_BakedCode( return AVS_LinkCall(BMPSize)() )
  464.  
  465.   __int64 AudioSamplesFromFrames(int frames) const AVS_BakedCode( return AVS_LinkCall(AudioSamplesFromFrames)(frames) )
  466.   int FramesFromAudioSamples(__int64 samples) const AVS_BakedCode( return AVS_LinkCall(FramesFromAudioSamples)(samples) )
  467.   __int64 AudioSamplesFromBytes(__int64 bytes) const AVS_BakedCode( return AVS_LinkCall(AudioSamplesFromBytes)(bytes) )
  468.   __int64 BytesFromAudioSamples(__int64 samples) const AVS_BakedCode( return AVS_LinkCall(BytesFromAudioSamples)(samples) )
  469.   int AudioChannels() const AVS_BakedCode( return AVS_LinkCall(AudioChannels)() )
  470.   int SampleType() const AVS_BakedCode( return AVS_LinkCall(SampleType)() )
  471.   bool IsSampleType(int testtype) const AVS_BakedCode( return AVS_LinkCall(IsSampleType)(testtype) )
  472.   int SamplesPerSecond() const AVS_BakedCode( return AVS_LinkCall(SamplesPerSecond)() )
  473.   int BytesPerAudioSample() const AVS_BakedCode( return AVS_LinkCall(BytesPerAudioSample)() )
  474.   void SetFieldBased(bool isfieldbased) AVS_BakedCode( AVS_LinkCall(SetFieldBased)(isfieldbased) )
  475.   void Set(int property) AVS_BakedCode( AVS_LinkCall(Set)(property) )
  476.   void Clear(int property) AVS_BakedCode( AVS_LinkCall(Clear)(property) )
  477.  
  478.   int GetPlaneWidthSubsampling(int plane) const AVS_BakedCode( return AVS_LinkCall(GetPlaneWidthSubsampling)(plane) )   // Subsampling in bitshifts!
  479.   int GetPlaneHeightSubsampling(int plane) const AVS_BakedCode( return AVS_LinkCall(GetPlaneHeightSubsampling)(plane) )   // Subsampling in bitshifts!
  480.   int BitsPerPixel() const AVS_BakedCode( return AVS_LinkCall(BitsPerPixel)() )
  481.  
  482.   int BytesPerChannelSample() const AVS_BakedCode( return AVS_LinkCall(BytesPerChannelSample)() )
  483.  
  484.   // useful mutator
  485.   void SetFPS(unsigned numerator, unsigned denominator) AVS_BakedCode( AVS_LinkCall(SetFPS)(numerator, denominator) )
  486.  
  487.   // Range protected multiply-divide of FPS
  488.   void MulDivFPS(unsigned multiplier, unsigned divisor) AVS_BakedCode( AVS_LinkCall(MulDivFPS)(multiplier, divisor) )
  489.  
  490.   // Test for same colorspace
  491.   bool IsSameColorspace(const VideoInfo& vi) const AVS_BakedCode( return AVS_LinkCall(IsSameColorspace)(vi) )
  492.  
  493. }; // end struct VideoInfo
  494.  
  495.  
  496.  
  497.  
  498. // VideoFrameBuffer holds information about a memory block which is used
  499. // for video data.  For efficiency, instances of this class are not deleted
  500. // when the refcount reaches zero; instead they're stored in a linked list
  501. // to be reused.  The instances are deleted when the corresponding AVS
  502. // file is closed.
  503.  
  504. class VideoFrameBuffer {
  505.   BYTE* const data;
  506.   const int data_size;
  507.   // sequence_number is incremented every time the buffer is changed, so
  508.   // that stale views can tell they're no longer valid.
  509.   volatile long sequence_number;
  510.  
  511.   friend class VideoFrame;
  512.   friend class Cache;
  513.   friend class ScriptEnvironment;
  514.   volatile long refcount;
  515.  
  516. protected:
  517.   VideoFrameBuffer(int size);
  518.   VideoFrameBuffer();
  519.   ~VideoFrameBuffer();
  520.  
  521. public:
  522.   const BYTE* GetReadPtr() const AVS_BakedCode( return AVS_LinkCall(VFBGetReadPtr)() )
  523.   BYTE* GetWritePtr() AVS_BakedCode( return AVS_LinkCall(VFBGetWritePtr)() )
  524.   int GetDataSize() const AVS_BakedCode( return AVS_LinkCall(GetDataSize)() )
  525.   int GetSequenceNumber() const AVS_BakedCode( return AVS_LinkCall(GetSequenceNumber)() )
  526.   int GetRefcount() const AVS_BakedCode( return AVS_LinkCall(GetRefcount)() )
  527. }; // end class VideoFrameBuffer
  528.  
  529.  
  530. // VideoFrame holds a "window" into a VideoFrameBuffer.  Operator new
  531. // is overloaded to recycle class instances.
  532.  
  533. class VideoFrame {
  534.   volatile long refcount;
  535.   VideoFrameBuffer* const vfb;
  536.  
  537.   // Due to technical reasons these members are not const, but should be treated as such.
  538.   // That means do not modify them once the class has been constructed.
  539.   int offset, pitch, row_size, height, offsetU, offsetV, pitchUV;  // U&V offsets are from top of picture.
  540.   int row_sizeUV, heightUV;
  541.  
  542.   friend class PVideoFrame;
  543.   void AddRef();
  544.   void Release();
  545.  
  546.   friend class ScriptEnvironment;
  547.   friend class Cache;
  548.  
  549.   VideoFrame(VideoFrameBuffer* _vfb, int _offset, int _pitch, int _row_size, int _height);
  550.   VideoFrame(VideoFrameBuffer* _vfb, int _offset, int _pitch, int _row_size, int _height, int _offsetU, int _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV);
  551.  
  552.   void* operator new(size_t size);
  553. // TESTME: OFFSET U/V may be switched to what could be expected from AVI standard!
  554. public:
  555.   int GetPitch(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetPitch)(plane) )
  556.   int GetRowSize(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetRowSize)(plane) )
  557.   int GetHeight(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetHeight)(plane) )
  558.  
  559.   // generally you shouldn't use these three
  560.   VideoFrameBuffer* GetFrameBuffer() const AVS_BakedCode( return AVS_LinkCall(GetFrameBuffer)() )
  561.   int GetOffset(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetOffset)(plane) )
  562.  
  563.   // in plugins use env->SubFrame() -- because implementation code is only available inside avisynth.dll. Doh!
  564.   VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height) const;
  565.   VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int pitchUV) const;
  566.  
  567.   const BYTE* GetReadPtr(int plane=0) const AVS_BakedCode( return AVS_LinkCall(VFGetReadPtr)(plane) )
  568.   bool IsWritable() const AVS_BakedCode( return AVS_LinkCall(IsWritable)() )
  569.   BYTE* GetWritePtr(int plane=0) const AVS_BakedCode( return AVS_LinkCall(VFGetWritePtr)(plane) )
  570.  
  571.   ~VideoFrame() AVS_BakedCode( AVS_LinkCall(VideoFrame_DESTRUCTOR)() )
  572. #ifdef BUILDING_AVSCORE
  573. public:
  574.   void DESTRUCTOR();  /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */
  575. #endif
  576. }; // end class VideoFrame
  577.  
  578. enum CachePolicyHint {
  579.   // Old 2.5 poorly defined cache hints.
  580.   // Reserve values used by 2.5 API
  581.   // Do not use in new filters
  582.   CACHE_25_NOTHING=0, 
  583.   CACHE_25_RANGE=1,
  584.   CACHE_25_ALL=2,
  585.   CACHE_25_AUDIO=3,
  586.   CACHE_25_AUDIO_NONE=4,
  587.   CACHE_25_AUDIO_AUTO=5,
  588.  
  589.   // New 2.6 explicitly defined cache hints.
  590.   CACHE_NOTHING=10, // Do not cache video.
  591.   CACHE_WINDOW=11, // Hard protect upto X frames within a range of X from the current frame N.
  592.   CACHE_GENERIC=12, // LRU cache upto X frames.
  593.   CACHE_FORCE_GENERIC=13, // LRU cache upto X frames, override any previous CACHE_WINDOW.
  594.  
  595.   CACHE_GET_POLICY=30, // Get the current policy.
  596.   CACHE_GET_WINDOW=31, // Get the current window h_span.
  597.   CACHE_GET_RANGE=32, // Get the current generic frame range.
  598.  
  599.   CACHE_AUDIO=50, // Explicitly do cache audio, X byte cache.
  600.   CACHE_AUDIO_NOTHING=51, // Explicitly do not cache audio.
  601.   CACHE_AUDIO_NONE=52, // Audio cache off (auto mode), X byte intial cache.
  602.   CACHE_AUDIO_AUTO=53, // Audio cache on (auto mode), X byte intial cache.
  603.  
  604.   CACHE_GET_AUDIO_POLICY=70, // Get the current audio policy.
  605.   CACHE_GET_AUDIO_SIZE=71, // Get the current audio cache size.
  606.  
  607.   CACHE_PREFETCH_FRAME=100, // Queue request to prefetch frame N.
  608.   CACHE_PREFETCH_GO=101, // Action video prefetches.
  609.  
  610.   CACHE_PREFETCH_AUDIO_BEGIN=120, // Begin queue request transaction to prefetch audio (take critical section).
  611.   CACHE_PREFETCH_AUDIO_STARTLO=121, // Set low 32 bits of start.
  612.   CACHE_PREFETCH_AUDIO_STARTHI=122, // Set high 32 bits of start.
  613.   CACHE_PREFETCH_AUDIO_COUNT=123, // Set low 32 bits of length.
  614.   CACHE_PREFETCH_AUDIO_COMMIT=124, // Enqueue request transaction to prefetch audio (release critical section).
  615.   CACHE_PREFETCH_AUDIO_GO=125, // Action audio prefetches.
  616.  
  617.   CACHE_GETCHILD_CACHE_MODE=200, // Cache ask Child for desired video cache mode.
  618.   CACHE_GETCHILD_CACHE_SIZE=201, // Cache ask Child for desired video cache size.
  619.   CACHE_GETCHILD_AUDIO_MODE=202, // Cache ask Child for desired audio cache mode.
  620.   CACHE_GETCHILD_AUDIO_SIZE=203, // Cache ask Child for desired audio cache size.
  621.  
  622.   CACHE_GETCHILD_COST=220, // Cache ask Child for estimated processing cost.
  623.     CACHE_COST_ZERO=221, // Child response of zero cost (ptr arithmetic only).
  624.     CACHE_COST_UNIT=222, // Child response of unit cost (less than or equal 1 full frame blit).
  625.     CACHE_COST_LOW=223, // Child response of light cost. (Fast)
  626.     CACHE_COST_MED=224, // Child response of medium cost. (Real time)
  627.     CACHE_COST_HI=225, // Child response of heavy cost. (Slow)
  628.  
  629.   CACHE_GETCHILD_THREAD_MODE=240, // Cache ask Child for thread safetyness.
  630.     CACHE_THREAD_UNSAFE=241, // Only 1 thread allowed for all instances. 2.5 filters default!
  631.     CACHE_THREAD_CLASS=242, // Only 1 thread allowed for each instance. 2.6 filters default!
  632.     CACHE_THREAD_SAFE=243, //  Allow all threads in any instance.
  633.     CACHE_THREAD_OWN=244, // Safe but limit to 1 thread, internally threaded.
  634.  
  635.   CACHE_GETCHILD_ACCESS_COST=260, // Cache ask Child for preferred access pattern.
  636.     CACHE_ACCESS_RAND=261, // Filter is access order agnostic.
  637.     CACHE_ACCESS_SEQ0=262, // Filter prefers sequential access (low cost)
  638.     CACHE_ACCESS_SEQ1=263, // Filter needs sequential access (high cost)
  639.  
  640.   CACHE_AVSPLUS_CONSTANTS = 500,    // Smaller values are reserved for classic Avisynth
  641.  
  642.   CACHE_DONT_CACHE_ME,              // Filters that don't need caching (eg. trim, cache etc.) should return 1 to this request
  643.   CACHE_SET_MIN_CAPACITY,
  644.   CACHE_SET_MAX_CAPACITY,
  645.   CACHE_GET_MIN_CAPACITY,
  646.   CACHE_GET_MAX_CAPACITY,
  647.   CACHE_GET_SIZE,
  648.   CACHE_GET_REQUESTED_CAP,
  649.   CACHE_GET_CAPACITY,
  650.   CACHE_GET_MTMODE,
  651.  
  652.   CACHE_IS_CACHE_REQ,
  653.   CACHE_IS_CACHE_ANS,
  654.   CACHE_IS_MTGUARD_REQ,
  655.   CACHE_IS_MTGUARD_ANS,
  656.  
  657.   CACHE_USER_CONSTANTS = 1000       // Smaller values are reserved for the core
  658.  
  659. };
  660.  
  661. // Base class for all filters.
  662. class IClip {
  663.   friend class PClip;
  664.   friend class AVSValue;
  665.   volatile long refcnt;
  666.   void AddRef();
  667.   void Release();
  668. public:
  669.   IClip() : refcnt(0) {}
  670.   virtual int __stdcall GetVersion() { return AVISYNTH_INTERFACE_VERSION; }
  671.   virtual PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) = 0;
  672.   virtual bool __stdcall GetParity(int n) = 0;  // return field parity if field_based, else parity of first field in frame
  673.   virtual void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) = 0;  // start and count are in samples
  674.   /* Need to check GetVersion first, pre v5 will return random crap from EAX reg. */
  675.   virtual int __stdcall SetCacheHints(int cachehints,int frame_range) = 0 ;  // We do not pass cache requests upwards, only to the next filter.
  676.   virtual const VideoInfo& __stdcall GetVideoInfo() = 0;
  677.   virtual __stdcall ~IClip() {}
  678. }; // end class IClip
  679.  
  680.  
  681. // smart pointer to IClip
  682. class PClip {
  683.  
  684.   IClip* p;
  685.  
  686.   IClip* GetPointerWithAddRef() const;
  687.   friend class AVSValue;
  688.   friend class VideoFrame;
  689.  
  690.   void Init(IClip* x);
  691.   void Set(IClip* x);
  692.  
  693. public:
  694.   PClip() AVS_BakedCode( AVS_LinkCall(PClip_CONSTRUCTOR0)() )
  695.   PClip(const PClip& x) AVS_BakedCode( AVS_LinkCall(PClip_CONSTRUCTOR1)(x) )
  696.   PClip(IClip* x) AVS_BakedCode( AVS_LinkCall(PClip_CONSTRUCTOR2)(x) )
  697.   void operator=(IClip* x) AVS_BakedCode( AVS_LinkCall(PClip_OPERATOR_ASSIGN0)(x) )
  698.   void operator=(const PClip& x) AVS_BakedCode( AVS_LinkCall(PClip_OPERATOR_ASSIGN1)(x) )
  699.  
  700.   IClip* operator->() const { return p; }
  701.  
  702.   // useful in conditional expressions
  703.   operator void*() const { return p; }
  704.   bool operator!() const { return !p; }
  705.  
  706.   ~PClip() AVS_BakedCode( AVS_LinkCall(PClip_DESTRUCTOR)() )
  707. #ifdef BUILDING_AVSCORE
  708. public:
  709.   void CONSTRUCTOR0();  /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */
  710.   void CONSTRUCTOR1(const PClip& x);
  711.   void CONSTRUCTOR2(IClip* x);
  712.   void OPERATOR_ASSIGN0(IClip* x);
  713.   void OPERATOR_ASSIGN1(const PClip& x);
  714.   void DESTRUCTOR();
  715. #endif
  716. }; // end class PClip
  717.  
  718.  
  719. // smart pointer to VideoFrame
  720. class PVideoFrame {
  721.  
  722.   VideoFrame* p;
  723.  
  724.   void Init(VideoFrame* x);
  725.   void Set(VideoFrame* x);
  726.  
  727. public:
  728.   PVideoFrame() AVS_BakedCode( AVS_LinkCall(PVideoFrame_CONSTRUCTOR0)() )
  729.   PVideoFrame(const PVideoFrame& x) AVS_BakedCode( AVS_LinkCall(PVideoFrame_CONSTRUCTOR1)(x) )
  730.   PVideoFrame(VideoFrame* x) AVS_BakedCode( AVS_LinkCall(PVideoFrame_CONSTRUCTOR2)(x) )
  731.   void operator=(VideoFrame* x) AVS_BakedCode( AVS_LinkCall(PVideoFrame_OPERATOR_ASSIGN0)(x) )
  732.   void operator=(const PVideoFrame& x) AVS_BakedCode( AVS_LinkCall(PVideoFrame_OPERATOR_ASSIGN1)(x) )
  733.  
  734.   VideoFrame* operator->() const { return p; }
  735.  
  736.   // for conditional expressions
  737.   operator void*() const { return p; }
  738.   bool operator!() const { return !p; }
  739.  
  740.   ~PVideoFrame() AVS_BakedCode( AVS_LinkCall(PVideoFrame_DESTRUCTOR)() )
  741. #ifdef BUILDING_AVSCORE
  742. public:
  743.   void CONSTRUCTOR0();  /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */
  744.   void CONSTRUCTOR1(const PVideoFrame& x);
  745.   void CONSTRUCTOR2(VideoFrame* x);
  746.   void OPERATOR_ASSIGN0(VideoFrame* x);
  747.   void OPERATOR_ASSIGN1(const PVideoFrame& x);
  748.   void DESTRUCTOR();
  749. #endif
  750. }; // end class PVideoFrame
  751.  
  752.  
  753. class AVSValue {
  754. public:
  755.  
  756.   AVSValue() AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR0)() )
  757.   AVSValue(IClip* c) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR1)(c) )
  758.   AVSValue(const PClip& c) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR2)(c) )
  759.   AVSValue(bool b) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR3)(b) )
  760.   AVSValue(int i) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR4)(i) )
  761. //  AVSValue(__int64 l);
  762.   AVSValue(float f) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR5)(f) )
  763.   AVSValue(double f) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR6)(f) )
  764.   AVSValue(const char* s) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR7)(s) )
  765.   AVSValue(const AVSValue* a, int size) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR8)(a, size) )
  766.   AVSValue(const AVSValue& v) AVS_BakedCode( AVS_LinkCall(AVSValue_CONSTRUCTOR9)(v) )
  767.  
  768.   ~AVSValue() AVS_BakedCode( AVS_LinkCall(AVSValue_DESTRUCTOR)() )
  769.   AVSValue& operator=(const AVSValue& v) AVS_BakedCode( return AVS_LinkCallV(AVSValue_OPERATOR_ASSIGN)(v) )
  770.  
  771.   // Note that we transparently allow 'int' to be treated as 'float'.
  772.   // There are no int<->bool conversions, though.
  773.  
  774.   bool Defined() const AVS_BakedCode( return AVS_LinkCall(Defined)() )
  775.   bool IsClip() const AVS_BakedCode( return AVS_LinkCall(IsClip)() )
  776.   bool IsBool() const AVS_BakedCode( return AVS_LinkCall(IsBool)() )
  777.   bool IsInt() const AVS_BakedCode( return AVS_LinkCall(IsInt)() )
  778. //  bool IsLong() const;
  779.   bool IsFloat() const AVS_BakedCode( return AVS_LinkCall(IsFloat)() )
  780.   bool IsString() const AVS_BakedCode( return AVS_LinkCall(IsString)() )
  781.   bool IsArray() const AVS_BakedCode( return AVS_LinkCall(IsArray)() )
  782.  
  783.   PClip AsClip() const AVS_BakedCode( return AVS_LinkCall(AsClip)() )
  784.   bool AsBool() const AVS_BakedCode( return AVS_LinkCall(AsBool1)() )
  785.   int AsInt() const AVS_BakedCode( return AVS_LinkCall(AsInt1)() )
  786. //  int AsLong() const;
  787.   const char* AsString() const AVS_BakedCode( return AVS_LinkCall(AsString1)() )
  788.   double AsFloat() const AVS_BakedCode( return AVS_LinkCall(AsFloat1)() )
  789.  
  790.   bool AsBool(bool def) const AVS_BakedCode( return AVS_LinkCall(AsBool2)(def) )
  791.   int AsInt(int def) const AVS_BakedCode( return AVS_LinkCall(AsInt2)(def) )
  792.   double AsDblDef(double def) const AVS_BakedCode( return AVS_LinkCall(AsDblDef)(def) ) // Value is still a float
  793. //float AsFloat(double def) const; // def demoted to a float
  794.   double AsFloat(float def) const AVS_BakedCode( return AVS_LinkCall(AsFloat2)(def) )
  795.   const char* AsString(const char* def) const AVS_BakedCode( return AVS_LinkCall(AsString2)(def) )
  796.  
  797.   int ArraySize() const AVS_BakedCode( return AVS_LinkCall(ArraySize)() )
  798.  
  799.   const AVSValue& operator[](int index) const AVS_BakedCode( return AVS_LinkCallV(AVSValue_OPERATOR_INDEX)(index) )
  800.  
  801. private:
  802.  
  803.   short type;  // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
  804.   short array_size;
  805.   union {
  806.     IClip* clip;
  807.     bool boolean;
  808.     int integer;
  809.     float floating_pt;
  810.     const char* string;
  811.     const AVSValue* array;
  812. //    __int64 longlong;
  813.   };
  814.  
  815.   void Assign(const AVSValue* src, bool init);
  816. #ifdef BUILDING_AVSCORE
  817. public:
  818.   void            CONSTRUCTOR0();  /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */
  819.   void            CONSTRUCTOR1(IClip* c);
  820.   void            CONSTRUCTOR2(const PClip& c);
  821.   void            CONSTRUCTOR3(bool b);
  822.   void            CONSTRUCTOR4(int i);
  823.   void            CONSTRUCTOR5(float f);
  824.   void            CONSTRUCTOR6(double f);
  825.   void            CONSTRUCTOR7(const char* s);
  826.   void            CONSTRUCTOR8(const AVSValue* a, int size);
  827.   void            CONSTRUCTOR9(const AVSValue& v);
  828.   void            DESTRUCTOR();
  829.   AVSValue&       OPERATOR_ASSIGN(const AVSValue& v);
  830.   const AVSValue& OPERATOR_INDEX(int index) const;
  831.  
  832.   bool            AsBool1() const;
  833.   int             AsInt1() const;
  834.   const char*     AsString1() const;
  835.   double          AsFloat1() const;
  836.  
  837.   bool            AsBool2(bool def) const;
  838.   int             AsInt2(int def) const;
  839.   double          AsFloat2(float def) const;
  840.   const char*     AsString2(const char* def) const;
  841. #endif
  842. }; // end class AVSValue
  843.  
  844. #undef AVS_LinkCallV
  845. #undef AVS_LinkCall
  846. #undef AVS_BakedCode
  847.  
  848. // instantiable null filter
  849. class GenericVideoFilter : public IClip {
  850. protected:
  851.   PClip child;
  852.   VideoInfo vi;
  853. public:
  854.   GenericVideoFilter(PClip _child) : child(_child) { vi = child->GetVideoInfo(); }
  855.   PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) { return child->GetFrame(n, env); }
  856.   void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) { child->GetAudio(buf, start, count, env); }
  857.   const VideoInfo& __stdcall GetVideoInfo() { return vi; }
  858.   bool __stdcall GetParity(int n) { return child->GetParity(n); }
  859.   int __stdcall SetCacheHints(int cachehints,int frame_range) { return 0; } ;  // We do not pass cache requests upwards, only to the next filter.
  860. };
  861.  
  862.  
  863.  
  864.  
  865. #if 0
  866. /* Helper classes useful to plugin authors */ // But we don't export the entry points, Doh!
  867.  
  868. class AlignPlanar : public GenericVideoFilter
  869. {
  870. public:
  871.   AlignPlanar(PClip _clip);
  872.   static PClip Create(PClip clip);
  873.   PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
  874. };
  875.  
  876.  
  877.  
  878. class FillBorder : public GenericVideoFilter
  879. {
  880. public:
  881.   FillBorder(PClip _clip);
  882.   static PClip Create(PClip clip);
  883.   PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
  884. };
  885.  
  886.  
  887.  
  888. class ConvertAudio : public GenericVideoFilter
  889. /**
  890.   * Helper class to convert audio to any format
  891.  **/
  892. {
  893. public:
  894.   ConvertAudio(PClip _clip, int prefered_format);
  895.   void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env);
  896.   int __stdcall SetCacheHints(int cachehints,int frame_range);  // We do pass cache requests upwards, to the cache!
  897.  
  898.   static PClip Create(PClip clip, int sample_type, int prefered_type);
  899.   static AVSValue __cdecl Create_float(AVSValue args, void*, IScriptEnvironment*);
  900.   static AVSValue __cdecl Create_32bit(AVSValue args, void*, IScriptEnvironment*);
  901.   static AVSValue __cdecl Create_24bit(AVSValue args, void*, IScriptEnvironment*);
  902.   static AVSValue __cdecl Create_16bit(AVSValue args, void*, IScriptEnvironment*);
  903.   static AVSValue __cdecl Create_8bit (AVSValue args, void*, IScriptEnvironment*);
  904.   static AVSValue __cdecl Create_Any  (AVSValue args, void*, IScriptEnvironment*);
  905.   virtual ~ConvertAudio();
  906.  
  907. private:
  908.   void convertToFloat(char* inbuf, float* outbuf, char sample_type, int count);
  909.   void convertToFloat_3DN(char* inbuf, float* outbuf, char sample_type, int count);
  910.   void convertToFloat_SSE(char* inbuf, float* outbuf, char sample_type, int count);
  911.   void convertToFloat_SSE2(char* inbuf, float* outbuf, char sample_type, int count);
  912.   void convertFromFloat(float* inbuf, void* outbuf, char sample_type, int count);
  913.   void convertFromFloat_3DN(float* inbuf, void* outbuf, char sample_type, int count);
  914.   void convertFromFloat_SSE(float* inbuf, void* outbuf, char sample_type, int count);
  915.   void convertFromFloat_SSE2(float* inbuf, void* outbuf, char sample_type, int count);
  916.  
  917.   __inline int Saturate_int8(float n);
  918.   __inline short Saturate_int16(float n);
  919.   __inline int Saturate_int24(float n);
  920.   __inline int Saturate_int32(float n);
  921.  
  922.   char src_format;
  923.   char dst_format;
  924.   int src_bps;
  925.   char *tempbuffer;
  926.   SFLOAT *floatbuffer;
  927.   int tempbuffer_size;
  928. };
  929. #endif
  930.  
  931. #include "avs/cpuid.h"
  932.  
  933. #if 0
  934. #define MAX_INT 0x7fffffff
  935. #define MIN_INT -0x7fffffff  // ::FIXME:: research why this is not 0x80000000
  936. #endif
  937.  
  938.  
  939.  
  940. class IScriptEnvironment {
  941. public:
  942.   virtual __stdcall ~IScriptEnvironment() {}
  943.  
  944.   virtual /*static*/ int __stdcall GetCPUFlags() = 0;
  945.  
  946.   virtual char* __stdcall SaveString(const char* s, int length = -1) = 0;
  947.   virtual char* __stdcall Sprintf(const char* fmt, ...) = 0;
  948.   // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
  949.   virtual char* __stdcall VSprintf(const char* fmt, void* val) = 0;
  950.  
  951.   __declspec(noreturn) virtual void __stdcall ThrowError(const char* fmt, ...) = 0;
  952.  
  953.   class NotFound /*exception*/ {};  // thrown by Invoke and GetVar
  954.  
  955.   typedef AVSValue (__cdecl *ApplyFunc)(AVSValue args, void* user_data, IScriptEnvironment* env);
  956.  
  957.   virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data) = 0;
  958.   virtual bool __stdcall FunctionExists(const char* name) = 0;
  959.   virtual AVSValue __stdcall Invoke(const char* name, const AVSValue args, const char* const* arg_names=0) = 0;
  960.  
  961.   virtual AVSValue __stdcall GetVar(const char* name) = 0;
  962.   virtual bool __stdcall SetVar(const char* name, const AVSValue& val) = 0;
  963.   virtual bool __stdcall SetGlobalVar(const char* name, const AVSValue& val) = 0;
  964.  
  965.   virtual void __stdcall PushContext(int level=0) = 0;
  966.   virtual void __stdcall PopContext() = 0;
  967.  
  968.   // align should be 4 or 8
  969.   virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, int align=FRAME_ALIGN) = 0;
  970.  
  971.   virtual bool __stdcall MakeWritable(PVideoFrame* pvf) = 0;
  972.  
  973.   virtual /*static*/ void __stdcall BitBlt(BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height) = 0;
  974.  
  975.   typedef void (__cdecl *ShutdownFunc)(void* user_data, IScriptEnvironment* env);
  976.   virtual void __stdcall AtExit(ShutdownFunc function, void* user_data) = 0;
  977.  
  978.   virtual void __stdcall CheckVersion(int version = AVISYNTH_INTERFACE_VERSION) = 0;
  979.  
  980.   virtual PVideoFrame __stdcall Subframe(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, int new_height) = 0;
  981.  
  982.   virtual int __stdcall SetMemoryMax(int mem) = 0;
  983.  
  984.   virtual int __stdcall SetWorkingDir(const char * newdir) = 0;
  985.  
  986.   virtual void* __stdcall ManageCache(int key, void* data) = 0;
  987.  
  988.   enum PlanarChromaAlignmentMode {
  989.             PlanarChromaAlignmentOff,
  990.             PlanarChromaAlignmentOn,
  991.             PlanarChromaAlignmentTest };
  992.  
  993.   virtual bool __stdcall PlanarChromaAlignment(PlanarChromaAlignmentMode key) = 0;
  994.  
  995.   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;
  996.  
  997.   virtual void __stdcall DeleteScriptEnvironment() = 0;
  998.  
  999.   virtual void _stdcall ApplyMessage(PVideoFrame* frame, const VideoInfo& vi, const char* message, int size, int textcolor, int halocolor, int bgcolor) = 0;
  1000.  
  1001.   virtual const AVS_Linkage* const __stdcall GetAVSLinkage() = 0;
  1002.  
  1003. }; // end class IScriptEnvironment
  1004.  
  1005.  
  1006. enum MtMode
  1007. {
  1008.   MT_INVALID = 0,
  1009.   MT_NICE_FILTER = 1,
  1010.   MT_MULTI_INSTANCE = 2,
  1011.   MT_SERIALIZED = 3,
  1012.   MT_MODE_COUNT = 4
  1013. };
  1014.  
  1015. class IJobCompletion
  1016. {
  1017. public:
  1018.  
  1019.   virtual __stdcall ~IJobCompletion() {}
  1020.   virtual void __stdcall Wait() = 0;
  1021.   virtual AVSValue __stdcall Get(size_t i) = 0;
  1022.   virtual size_t __stdcall Size() const = 0;
  1023.   virtual size_t __stdcall Capacity() const = 0;
  1024.   virtual void __stdcall Reset() = 0;
  1025.   virtual void __stdcall Destroy() = 0;
  1026. };
  1027.  
  1028. class IScriptEnvironment2;
  1029. class Prefetcher;
  1030. typedef AVSValue (*ThreadWorkerFuncPtr)(IScriptEnvironment2* env, void* data);
  1031.  
  1032. enum AvsEnvProperty
  1033. {
  1034.   AEP_PHYSICAL_CPUS = 1,
  1035.   AEP_LOGICAL_CPUS = 2,
  1036.   AEP_THREADPOOL_THREADS = 3,
  1037.   AEP_FILTERCHAIN_THREADS = 4,
  1038.   AEP_THREAD_ID = 5,
  1039.   AEP_VERSION = 6
  1040. };
  1041.  
  1042. enum AvsAllocType
  1043. {
  1044.   AVS_NORMAL_ALLOC  = 1,
  1045.   AVS_POOLED_ALLOC  = 2
  1046. };
  1047.  
  1048. /* -----------------------------------------------------------------------------
  1049.    Note to plugin authors: The interface in IScriptEnvironment2 is 
  1050.       preliminary / under construction / only for testing / non-final etc.!
  1051.       As long as you see this note here, IScriptEnvironment2 might still change, 
  1052.       in which case your plugin WILL break. This also means that you are welcome
  1053.       to test it and give your feedback about any ideas, improvements, or issues
  1054.       you might have.
  1055.    ----------------------------------------------------------------------------- */
  1056. class IScriptEnvironment2 : public IScriptEnvironment{
  1057. public:
  1058.   virtual __stdcall ~IScriptEnvironment2() {}
  1059.  
  1060.   // Generic system to ask for various properties
  1061.   virtual size_t  __stdcall GetProperty(AvsEnvProperty prop) = 0;
  1062.  
  1063.   // Returns TRUE and the requested variable. If the method fails, returns FALSE and does not touch 'val'.
  1064.   virtual bool  __stdcall GetVar(const char* name, AVSValue *val) const = 0;
  1065.  
  1066.   // Return the value of the requested variable.
  1067.   // If the variable was not found or had the wrong type,
  1068.   // return the supplied default value.
  1069.   virtual bool __stdcall GetVar(const char* name, bool def) const = 0;
  1070.   virtual int  __stdcall GetVar(const char* name, int def) const = 0;
  1071.   virtual double  __stdcall GetVar(const char* name, double def) const = 0;
  1072.   virtual const char*  __stdcall GetVar(const char* name, const char* def) const = 0;
  1073.  
  1074.   // Plugin functions
  1075.   virtual bool __stdcall LoadPlugin(const char* filePath, bool throwOnError, AVSValue *result) = 0;
  1076.   virtual void __stdcall AddAutoloadDir(const char* dirPath, bool toFront) = 0;
  1077.   virtual void __stdcall ClearAutoloadDirs() = 0;
  1078.   virtual void __stdcall AutoloadPlugins() = 0;
  1079.   virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data, const char *exportVar) = 0;
  1080.   virtual bool __stdcall InternalFunctionExists(const char* name) = 0;
  1081.  
  1082.   // Threading
  1083.   virtual void __stdcall SetFilterMTMode(const char* filter, MtMode mode, bool force) = 0; // If filter is "", sets the default MT mode
  1084.   virtual MtMode __stdcall GetFilterMTMode(const char* filter, bool* is_forced) const = 0; // If filter is "", gets the default MT mode
  1085.   virtual IJobCompletion* __stdcall NewCompletion(size_t capacity) = 0;
  1086.   virtual void __stdcall ParallelJob(ThreadWorkerFuncPtr jobFunc, void* jobData, IJobCompletion* completion) = 0;
  1087.  
  1088.   // This version of Invoke will return false instead of throwing NotFound().
  1089.   virtual bool __stdcall Invoke(AVSValue *result, const char* name, const AVSValue& args, const char* const* arg_names=0) = 0;
  1090.  
  1091.   // Support functions
  1092.   virtual void* __stdcall Allocate(size_t nBytes, size_t alignment, AvsAllocType type) = 0;
  1093.   virtual void __stdcall Free(void* ptr) = 0;
  1094.  
  1095.   // Strictly for Avisynth core only.
  1096.   // Neither host applications nor plugins should use
  1097.   // these interfaces.
  1098.   virtual int __stdcall IncrImportDepth() = 0;
  1099.   virtual int __stdcall DecrImportDepth() = 0;
  1100.   virtual void __stdcall AdjustMemoryConsumption(size_t amount, bool minus) = 0;
  1101.   virtual void __stdcall SetPrefetcher(Prefetcher *p) = 0;
  1102.  
  1103.   // These lines are needed so that we can overload the older functions from IScriptEnvironment.
  1104.   using IScriptEnvironment::Invoke;
  1105.   using IScriptEnvironment::AddFunction;
  1106.   using IScriptEnvironment::GetVar;
  1107.  
  1108. }; // end class IScriptEnvironment2
  1109.  
  1110.  
  1111. // avisynth.dll exports this; it's a way to use it as a library, without
  1112. // writing an AVS script or without going through AVIFile.
  1113. IScriptEnvironment* __stdcall CreateScriptEnvironment(int version = AVISYNTH_INTERFACE_VERSION);
  1114.  
  1115.  
  1116. // These are some global variables you can set in your script to change AviSynth's behavior.
  1117. #define VARNAME_AllowFloatAudio   "OPT_AllowFloatAudio"   // Allow WAVE_FORMAT_IEEE_FLOAT audio output
  1118. #define VARNAME_VDubPlanarHack    "OPT_VDubPlanarHack"    // Hack YV16 and YV24 chroma plane order for old VDub's
  1119. #define VARNAME_AVIPadScanlines   "OPT_AVIPadScanlines"   // Have scanlines mod4 padded in all pixel formats
  1120. #define VARNAME_UseWaveExtensible "OPT_UseWaveExtensible" // Use WAVEFORMATEXTENSIBLE when describing audio to Windows
  1121. #define VARNAME_dwChannelMask     "OPT_dwChannelMask"     // Integer audio channel mask. See description of WAVEFORMATEXTENSIBLE for more info.
  1122.  
  1123.  
  1124. // C exports
  1125. #include "avs/capi.h"
  1126. AVSC_API(IScriptEnvironment2*, CreateScriptEnvironment2)(int version = AVISYNTH_INTERFACE_VERSION);
  1127.  
  1128.  
  1129. #pragma pack(pop)
  1130.  
  1131. #endif //__AVISYNTH_H__
  1132.